8 class access_slice(Test):
10 Repeatedly attempt to use the specified users credentials to
11 access the specified node on the specified slice.
14 def call(self, email, slice_name, hostname, timeout=3):
16 auth = self.config.auth
17 email_parts = email.split("@")
18 keys_filename = email_parts[0]
19 keys_path = self.config.KEYS_PATH
20 private_key_path = keys_path + os.sep + keys_filename
21 public_key_path = private_key_path + ".pub"
24 slices = api.GetSlices(auth, [slice_name], ['name', 'slice_id', 'node_ids'])
26 raise Exception, "No such slice %(slice_name)s" % locals()
30 nodes = api.GetNodes(auth, [hostname], ['hostname', 'node_id', 'slice_ids'])
32 raise Exception, "No such node %(hostname)s" % locals()
34 if slice['slice_id'] not in node['slice_ids']:
35 raise Exception, "%(slice_name)s not on %(hostname)s" % locals()
38 persons = api.GetPersons(auth, ['email'], ['person_id', 'key_ids', 'slice_ids'])
40 raise Exception, "No such person %(email)s" % locals()
42 if slice['slice_id'] not in person['slice_ids']:
43 raise Exception, "%(email)s not in slice %(slice_name)s" % locals()
46 if not os.path.isfile(private_key_path) or \
47 not os.path.isfile(public_key_path):
48 # keys dont exist, call api.sync_user_key()
49 from qa.modules.api.sync_user_key import sync_user_key
50 sync_user_key()(email)
52 # attempt to access slice
53 start_time = time.time()
54 end_time = start_time + timeout*60
56 while time.time() < endtime:
57 if self.config.verbose:
58 utils.header("Trying to connect to %(slice_name)s@%(hostname)s" % locals())
59 ssh_command = "ssh -i %(private_key_path)s %(slice_name)s@%(hostname)s" % locals()
60 host_check = os.system(ssh_command + " hostname ")
62 if self.config.verbose:
63 utils.header("connecteed to %(slice_name)s@%(hostname)s" % locals())
66 if self.config.verbose:
67 utils.header("failed to connect to %(slice_name)s@%(hostname)s" % locals())
72 if __name__ == '__main__':
73 args = tuple(sys.argv[1:])