7 from TestNode import TestNode
8 from TestUser import TestUser
9 from TestKey import TestKey
13 def __init__ (self,test_plc,site_spec):
14 self.test_plc=test_plc
15 self.site_spec=site_spec
18 return self.site_spec['site_fields']['login_base']
20 def create_site (self):
21 print self.test_plc.auth_root()
22 self.test_plc.server.AddSite(self.test_plc.auth_root(),
23 self.site_spec['site_fields'])
24 self.test_plc.server.AddSiteAddress(self.test_plc.auth_root(),self.name(),
25 self.site_spec['address_fields'])
27 def create_users (self):
28 for user_spec in self.site_spec['users']:
29 test_user=TestUser(self.test_plc,self,user_spec)
30 test_user.create_user()
33 def delete_site (self):
34 print self.test_plc.auth_root()
35 self.test_plc.server.DeleteSite(self.test_plc.auth_root(),self.name())
38 def delete_users(self):
39 for user_spec in self.site_spec['users']:
40 test_user=TestUser(self.test_plc,self,user_spec)
41 test_user.delete_user()
43 def locate_user (self,username):
44 for user in self.site_spec['users']:
45 if user['name'] == username:
47 if user['user_fields']['email'] == username:
49 raise Exception,"Cannot locate user %s"%username
51 def locate_node (self,nodename):
52 for node in self.site_spec['nodes']:
53 if node['node_fields']['hostname'] == nodename:
55 raise Exception,"Cannot locate node %s"%nodename
57 # left as-is, i.e. crappy
58 def check_nodes(self):
59 # should filter out nodes not under vmware not qemu
60 node_specs=self.site_spec['nodes']
65 bt={'boot_state':'boot'}
66 dbg={'boot_state':'dbg'}
68 start_time = datetime.datetime.now() ##geting the current time
69 dead_time=datetime.datetime.now()+ datetime.timedelta(minutes=5)
70 utils.header("Starting checking for nodes in site %s"%self.name())
72 for node_spec in node_specs :
73 hostname=node_spec['node_fields']['hostname']
75 node_status=self.test_plc.server.GetNodes(self.test_plc.auth_root(),hostname, filter)
76 utils.header('Actual status for node %s is [%s]'%(hostname,node_status))
78 if (node_status[0] == bt):
79 utils.header('%s has reached boot state'%hostname)
81 elif (node_status[0] ==dbg):
82 utils.header('%s has reached debug state'%hostname)
85 elif ( start_time <= dead_time ) :
86 start_time=datetime.datetime.now()+ datetime.timedelta(minutes=2)
93 utils.header("Node %s correctly installed and booted"%hostname)
95 utils.header("Node %s not fully booted"%hostname)
98 utils.header("End checking for nodes in site %s"%self.name())
101 traceback.print_exc()
102 utils.header("will kill vmware in 10 seconds")
104 self.tst_plc.kill_all_vmwares()
107 def start_nodes (self,options):
108 for node_spec in self.site_spec['nodes']:
109 TestNode(self.test_plc, self, node_spec).start_node(options)
112 def delete_known_hosts(self):
113 utils.header("Messing with known_hosts (cleaning hostnames starting with 'test[0-9]')")
114 sed_command="sed -i -e '/^test[0-9]/d' /root/.ssh/known_hosts"
115 utils.system(sed_command)
117 # xxx should be attached to TestPlc
118 def check_slices(self):
123 self.delete_known_hosts()
124 start_time = datetime.datetime.now()
125 dead_time=start_time + datetime.timedelta(minutes=3)##adding 3minutes
126 for slice_spec in self.test_plc.plc_spec['slices']:
127 for hostname in slice_spec['nodenames']:
128 slicename=slice_spec['slice_fields']['name']
129 # locate the first avail. key
131 for username in slice_spec['usernames']:
132 user_spec=self.locate_user(username)
133 for keyname in user_spec['keynames']:
134 key_spec=self.test_plc.locate_key(keyname)
135 publickey=TestKey(self.test_plc,key_spec).publicpath()
136 privatekey=TestKey(self.test_plc,key_spec).privatepath()
137 if os.path.isfile(publickey) and os.path.isfile(privatekey):
141 raise Exception,"Cannot find a valid key for slice %s"%slicename
144 utils.header('restarting nm on %s'%hostname)
145 access=utils.system('ssh -i /etc/planetlab/root_ssh_key.rsa root@%s service nm restart'%hostname )
147 utils.header('nm restarted on %s'%hostname)
149 utils.header('trying to connect to %s@%s'%(slicename,hostname))
150 ### should use saved keys instead of this hard-coded stuff
151 Date=utils.system('ssh -i %s %s@%s date'%(privatekey,slicename,hostname))
154 elif ( start_time <= dead_time ) :
155 start_time=datetime.datetime.now()+ datetime.timedelta(seconds=30)
160 utils.header('connected to %s@%s -->'%(slicename,hostname))
162 utils.header('%s@%s : last chance - restarting nm on %s'%(slicename,hostname,hostname))
163 access=utils.system('ssh -i /etc/planetlab/root_ssh_key.rsa root@%s service nm restart'%hostname)
165 utils.header('trying to connect (2) to %s@%s'%(slicename,hostname))
166 Date=utils.system('ssh -i ~/.ssh/slices.rsa %s@%s date'%(slicename,hostname))
168 utils.header('connected to %s@%s -->'%(slicename,hostname))
170 utils.header('giving up with to %s@%s -->'%(slicename,hostname))
173 utils.header('Last chance failed on %s@%s -->'%(slicename,hostname))
175 elif ( start_time <= dead_time ) :
176 start_time=datetime.datetime.now()+ datetime.timedelta(minutes=1)