7 class access_slice(Test):
9 Repeatedly attempt to use the specified users credentials to
10 access the specified node on the specified slice.
13 def call(self, email, slice_name, hostname, timeout=3):
15 auth = self.config.auth
16 email_parts = email.split("@")
17 keys_filename = email_parts[0]
18 keys_path = self.config.KEYS_PATH
19 private_key_path = keys_path + os.sep + keys_filename
20 public_key_path = private_key_path + ".pub"
23 slices = api.GetSlices(auth, [slice_name], ['name', 'slice_id', 'node_ids'])
25 raise Exception, "No such slice %(slice_name)s" % locals()
29 nodes = api.GetNodes(auth, [hostname], ['hostname', 'node_id', 'slice_ids'])
31 raise Exception, "No such node %(hostname)s" % locals()
33 if slice['slice_id'] not in node['slice_ids']:
34 raise Exception, "%(slice_name)s not on %(hostname)s" % locals()
37 persons = api.GetPersons(auth, ['email'], ['person_id', 'key_ids', 'slice_ids'])
39 raise Exception, "No such person %(email)s" % locals()
41 if slice['slice_id'] not in person['slice_ids']:
42 raise Exception, "%(email)s not in slice %(slice_name)s" % locals()
45 if not os.path.isfile(private_key_path) or \
46 not os.path.isfile(public_key_path):
47 # keys dont exist, call api.sync_user_key()
48 from qa.modules.api.sync_user_key import sync_user_key
49 sync_user_key()(email)
51 # attempt to access slice
52 start_time = time.time()
53 end_time = start_time + timeout*60
55 while time.time() < endtime:
56 if self.config.verbose:
57 utils.header("Trying to connect to %(slice_name)s@%(hostname)s" % locals())
58 ssh_command = "ssh -i %(private_key_path)s %(slice_name)s@%(hostname)s" % locals()
59 host_check = os.system(ssh_command + " hostname ")
61 if self.config.verbose:
62 utils.header("connecteed to %(slice_name)s@%(hostname)s" % locals())
65 if self.config.verbose:
66 utils.header("failed to connect to %(slice_name)s@%(hostname)s" % locals())
71 if __name__ == '__main__':
72 args = tuple(sys.argv[1:])