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
61 self.logfile = logfile
63 self.auth['Username'] = self.PLC_ROOT_USER
64 self.auth['AuthString'] = self.PLC_ROOT_PASSWORD
65 self.auth['AuthMethod'] = 'password'
66 self.verbose = self.VERBOSE
68 # try setting hostname and ip
69 self.hostname = socket.gethostname()
71 command = "/sbin/ifconfig eth0 | grep -v inet6 | grep inet | awk '{print$2;}'"
72 (status, output) = utils.commands(command)
73 self.ip = re.findall(r'[0-9\.]+', output)[0]
77 api_host = self.__dict__.get("PLC_API_HOST",self.ip)
78 self.PLC_API_HOST=api_host
82 # Load list of node tests
83 valid_node_test_files = lambda name: not name.startswith('__init__') \
84 and not name.endswith('pyc')
85 node_test_files = os.listdir(self.node_tests_path)
86 self.node_test_files = filter(valid_node_test_files, node_test_files)
88 def get_plc(self, plc_name):
90 if hasattr(self, 'plcs') and plc_name in self.plcs.keys():
91 plc.update(self.plcs[plc_name])
95 def get_node(self, hostname):
97 if hasattr(self, 'nodes') and hostname in self.nodes.keys():
98 node.update(self.nodes[hostname])
99 node.__init_logfile__()
102 def load(self, conffile):
105 try: execfile(conffile, confdata)
108 from Nodes import Nodes
109 from PLCs import PLCs
110 loadables = ['plcs', 'sites', 'nodes', 'slices', 'persons']
112 for loadable in loadables:
113 if loadable in confdata and loadable in ['plcs']:
114 setattr(self, loadable, PLCs(config, confdata[loadable]).dict('name'))
115 elif loadable in confdata and loadable in ['nodes']:
116 setattr(self, loadable, Nodes(config, confdata[loadable]).dict('hostname'))
117 elif loadable in confdata and loadable in ['sites']:
118 setattr(self, loadable, Sites(confdata[loadable]).dict('login_base'))
119 elif loadable in confdata and loadable in ['slices']:
120 setattr(self, loadable, Slices(confdata[loadable]).dict('name'))
121 elif loadable in confdata and loadable in ['persons']:
122 setattr(self, loadable, Persons(confdata[loadable]).dict('email'))