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
22 def update_api(self, plc = None):
24 # If plc is specified, find its configuration
27 protocol, host, path, port = 'http', plc['host'], plc['api_path'], plc['port']
30 api_server = "%(protocol)s://%(host)s:%(port)s/%(path)s" % locals()
31 self.api = xmlrpclib.Server(api_server, allow_none = 1)
32 self.api_type = 'xmlrpc'
35 # Try importing the API shell for direct api access.
36 # If that fails fall back to using xmlrpm
38 sys.path.append('/usr/share/plc_api')
39 from PLC.Shell import Shell
40 shell = Shell(globals = globals())
45 self.api_type = 'direct'
47 self.api = xmlrpclib.Server('https://%s/PLCAPI/' % self.PLC_API_HOST, allow_none = 1)
48 self.api_type = 'xmlrpc'
50 def __init__(self, config_file = path+os.sep+'qa_config'):
53 execfile(config_file, self.__dict__)
55 raise "Could not find system config in %s" % config_file
58 self.auth['Username'] = self.PLC_ROOT_USER
59 self.auth['AuthString'] = self.PLC_ROOT_PASSWORD
60 self.auth['AuthMethod'] = 'password'
61 self.verbose = self.VERBOSE
63 # try setting hostname and ip
64 self.hostname = socket.gethostname()
66 (stdout, stderr) = utils.popen("/sbin/ifconfig eth0 | grep 'inet addr'")
67 inet_addr = re.findall('inet addr:[0-9\.^\w]*', stdout[0])[0]
68 parts = inet_addr.split(":")
73 api_host = self.__dict__.get("PLC_API_HOST",self.ip)
74 self.PLC_API_HOST=api_host
78 # Load list of node tests
79 valid_node_test_files = lambda name: not name.startswith('__init__') \
80 and not name.endswith('pyc')
81 node_test_files = os.listdir(self.node_tests_path)
82 self.node_test_files = filter(valid_node_test_files, node_test_files)
84 def get_plc(self, plc_name):
86 if hasattr(self, 'plcs') and plc_name in self.plcs.keys():
87 plc.update(self.plcs[plc_name])
88 plc.config.update_api(plc)
91 def get_node(self, hostname):
93 if hasattr(self, 'nodes') and hostname in self.nodes.keys():
94 node.update(self.nodes[hostname])
97 def load(self, conffile):
100 try: execfile(conffile, confdata)
103 from Nodes import Nodes
104 from PLCs import PLCs
105 loadables = ['plcs', 'sites', 'nodes', 'slices', 'persons']
107 for loadable in loadables:
108 if loadable in confdata and loadable in ['plcs']:
109 setattr(self, loadable, PLCs(config, confdata[loadable]).dict('name'))
110 elif loadable in confdata and loadable in ['nodes']:
111 setattr(self, loadable, Nodes(config, confdata[loadable]).dict('hostname'))
112 elif loadable in confdata and loadable in ['sites']:
113 setattr(self, loadable, Sites(confdata[loadable]).dict('login_base'))
114 elif loadable in confdata and loadable in ['slices']:
115 setattr(self, loadable, Slices(confdata[loadable]).dict('name'))
116 elif loadable in confdata and loadable in ['persons']:
117 setattr(self, loadable, Persons(confdata[loadable]).dict('email'))