8 from logger import logfile
9 from PLCs import PLC, PLCs
10 from Sites import Site, Sites
11 from Nodes import Node, Nodes
12 from Slices import Slice, Slices
13 from Persons import Person, Persons
15 path = os.path.dirname(os.path.abspath(__file__))
19 path = os.path.dirname(os.path.abspath(__file__))
20 tests_path = path + os.sep + 'tests' + os.sep
21 node_tests_path = tests_path + os.sep + 'node' + os.sep
22 slice_tests_path = tests_path + os.sep + 'slice' + os.sep
23 vserver_scripts_path = path + os.sep + 'vserver' + os.sep
24 log_filename = logfile.filename
26 def update_api(self, plc = None):
28 # If plc is specified, find its configuration
31 protocol, host, path, port = 'http', plc['host'], plc['api_path'], plc['port']
34 api_server = "%(protocol)s://%(host)s:%(port)s/%(path)s" % locals()
35 self.api = xmlrpclib.Server(api_server, allow_none = 1)
36 self.api_type = 'xmlrpc'
39 # Try importing the API shell for direct api access.
40 # If that fails fall back to using xmlrpm
42 sys.path.append('/usr/share/plc_api')
43 from PLC.Shell import Shell
44 shell = Shell(globals = globals())
49 self.api_type = 'direct'
51 self.api = xmlrpclib.Server('https://%s/PLCAPI/' % self.PLC_API_HOST, allow_none = 1)
52 self.api_type = 'xmlrpc'
54 def __init__(self, config_file = path+os.sep+'qa_config'):
57 execfile(config_file, self.__dict__)
59 raise "Could not find system config in %s" % config_file
62 self.auth['Username'] = self.PLC_ROOT_USER
63 self.auth['AuthString'] = self.PLC_ROOT_PASSWORD
64 self.auth['AuthMethod'] = 'password'
65 self.verbose = self.VERBOSE
67 # try setting hostname and ip
68 self.hostname = socket.gethostname()
70 command = "/sbin/ifconfig eth0 | grep -v inet6 | grep inet | awk '{print$2;}'"
71 (status, output) = utils.commands(command)
72 self.ip = re.findall(r'[0-9\.]+', output)[0]
76 api_host = self.__dict__.get("PLC_API_HOST",self.ip)
77 self.PLC_API_HOST=api_host
81 # Load list of node tests
82 valid_node_test_files = lambda name: not name.startswith('__init__') \
83 and not name.endswith('pyc')
84 node_test_files = os.listdir(self.node_tests_path)
85 self.node_test_files = filter(valid_node_test_files, node_test_files)
87 def get_plc(self, plc_name):
89 if hasattr(self, 'plcs') and plc_name in self.plcs.keys():
90 plc.update(self.plcs[plc_name])
94 def get_node(self, hostname):
96 if hasattr(self, 'nodes') and hostname in self.nodes.keys():
97 node.update(self.nodes[hostname])
100 def load(self, conffile):
103 try: execfile(conffile, confdata)
106 from Nodes import Nodes
107 from PLCs import PLCs
108 loadables = ['plcs', 'sites', 'nodes', 'slices', 'persons']
110 for loadable in loadables:
111 if loadable in confdata and loadable in ['plcs']:
112 setattr(self, loadable, PLCs(config, confdata[loadable]).dict('name'))
113 elif loadable in confdata and loadable in ['nodes']:
114 setattr(self, loadable, Nodes(config, confdata[loadable]).dict('hostname'))
115 elif loadable in confdata and loadable in ['sites']:
116 setattr(self, loadable, Sites(confdata[loadable]).dict('login_base'))
117 elif loadable in confdata and loadable in ['slices']:
118 setattr(self, loadable, Slices(confdata[loadable]).dict('name'))
119 elif loadable in confdata and loadable in ['persons']:
120 setattr(self, loadable, Persons(confdata[loadable]).dict('email'))