add ssh-slice-basics
[tests.git] / system / TestSite.py
1 # Thierry Parmentelat <thierry.parmentelat@inria.fr>
2 # Copyright (C) 2010 INRIA 
3 #
4 import os.path
5 import datetime
6 import time
7 import traceback
8
9 import utils
10 from TestNode import TestNode
11 from TestUser import TestUser
12 from TestKey import TestKey
13
14 class TestSite:
15
16     def __init__ (self,test_plc,site_spec):
17         self.test_plc=test_plc
18         self.site_spec=site_spec
19         
20     def name(self):
21         return self.site_spec['site_fields']['login_base']
22
23     def create_site (self):
24         print self.test_plc.auth_root()
25         self.test_plc.apiserver.AddSite(self.test_plc.auth_root(),
26                                         self.site_spec['site_fields'])
27         self.test_plc.apiserver.AddSiteAddress(self.test_plc.auth_root(),self.name(),
28                                                self.site_spec['address_fields'])
29             
30     def create_users (self):
31         for user_spec in self.site_spec['users']:
32             test_user=TestUser(self.test_plc,self,user_spec)
33             test_user.create_user()
34             test_user.add_keys()            
35
36     def delete_site (self):
37         print self.test_plc.auth_root()
38         self.test_plc.apiserver.DeleteSite(self.test_plc.auth_root(),self.name())
39         return True
40             
41     def delete_users(self):
42         for user_spec in self.site_spec['users']:
43             test_user=TestUser(self.test_plc,self,user_spec)
44             test_user.delete_user()
45
46     def locate_user (self,username):
47         for user in self.site_spec['users']:
48             if user['name'] == username:
49                 return user
50             if user['user_fields']['email'] == username:
51                 return user
52         raise Exception,"Cannot locate user %s"%username
53         
54     def locate_node (self,nodename):
55         for node in self.site_spec['nodes']:
56             if node['name'] == nodename:
57                 return node
58         raise Exception,"Cannot locate node %s"%nodename
59         
60            
61