8 from PLCs import PLC, PLCs
9 from Sites import Site, Sites
10 from Nodes import Node, Nodes
11 from Slices import Slice, Slices
12 from Persons import Person, Persons
16 path = os.path.dirname(os.path.abspath(__file__))
17 tests_path = path + os.sep + 'tests' + os.sep
18 node_tests_path = tests_path + os.sep + 'node' + os.sep
19 slice_tests_path = tests_path + os.sep + 'slice' + os.sep
20 vserver_scripts_path = path + os.sep + 'vserver' + os.sep
21 qemu_scripts_path = path + os.sep + 'qemu' + os.sep
23 def update_api(self, plc = None):
25 # If plc is specified, find its configuration
28 host, path, port = plc['host'], plc['api_path'], plc['port']
29 api_server = "https://%(host)s:%(port)s/%(path)s" % locals()
30 self.api = xmlrpclib.Server(api_server, allow_none = 1)
31 self.api_type = 'xmlrpc'
34 # Try importing the API shell for direct api access.
35 # If that fails fall back to using xmlrpm
37 sys.path.append('/usr/share/plc_api')
38 from PLC.Shell import Shell
39 shell = Shell(globals = globals())
44 self.api_type = 'direct'
46 self.api = xmlrpclib.Server('https://%s/PLCAPI/' % self.PLC_API_HOST, allow_none = 1)
47 self.api_type = 'xmlrpc'
49 def __init__(self, config_file = path+os.sep+'qa_config'):
52 execfile(config_file, self.__dict__)
54 raise "Could not find system config in %s" % config_file
57 self.auth['Username'] = self.PLC_ROOT_USER
58 self.auth['AuthString'] = self.PLC_ROOT_PASSWORD
59 self.auth['AuthMethod'] = 'password'
60 self.verbose = self.VERBOSE
62 # try setting hostname and ip
63 self.hostname = socket.gethostname()
65 (stdout, stderr) = utils.popen("/sbin/ifconfig eth0 | grep 'inet addr'")
66 inet_addr = re.findall('inet addr:[0-9\.^\w]*', stdout[0])[0]
67 parts = inet_addr.split(":")
72 api_host = self.__dict__.get("PLC_API_HOST",self.ip)
73 self.PLC_API_HOST=api_host
77 # Load list of node tests
78 valid_node_test_files = lambda name: not name.startswith('__init__') \
79 and not name.endswith('pyc')
80 node_test_files = os.listdir(self.node_tests_path)
81 self.node_test_files = filter(valid_node_test_files, node_test_files)
83 def load(self, conffile):
86 try: execfile(conffile, confdata)
89 from Nodes import Nodes
91 loadables = ['plcs', 'sites', 'nodes', 'slices', 'persons']
93 for loadable in loadables:
94 if loadable in confdata and loadable in ['plcs']:
95 setattr(self, loadable, PLCs(config, confdata[loadable]))
96 elif loadable in confdata and loadable in ['nodes']:
97 setattr(self, loadable, Nodes(config, confdata[loadable]))
98 elif loadable in confdata and loadable in ['sites']:
99 setattr(self, loadable, Sites(confdata[loadable]))
100 elif loadable in confdata and loadable in ['slices']:
101 setattr(self, loadable, Slices(confdata[loadable]))
102 elif loadable in confdata and loadable in ['persons']:
103 setattr(self, loadable, Persons(confdata[loadable]))