deleting
[tests.git] / qaapi / qa / Config.py
1 import xmlrpclib
2 import os
3 import sys
4 import re
5 import utils
6
7 class Config:
8
9     path = os.path.dirname(os.path.abspath(__file__))
10     tests_path = path + os.sep + 'tests'
11     node_tests_path = tests_path + os.sep + 'node'
12     slice_tests_path = tests_path + os.sep + 'slice'                            
13     def __init__(self, config_file = path+os.sep+'qa_config'):
14         # Load config file
15         try:
16             execfile(config_file, self.__dict__)
17         except:
18             raise "Could not find system config in %s" % config_file
19
20         self.auth = {}
21         self.auth['Username'] = self.PLC_ROOT_USER
22         self.auth['AuthString'] = self.PLC_ROOT_PASSWORD
23         self.auth['AuthMethod'] = 'password'
24         self.verbose = self.VERBOSE     
25         
26         # Set up API acccess
27         # Try importing the API shell for direct api access.
28         # If that fails fall back to using xmlrpm
29         try:
30             sys.path.append('/usr/share/plc_api')
31             from PLC.Shell import Shell
32             shell = Shell(globals = globals())
33             
34             # test it
35             shell.GetRoles()
36             self.api = shell
37             self.api_type = 'direct'
38         except:
39             self.api = xmlrpclib.Server('https://%s/PLCAPI/' % self.PLC_API_HOST, allow_none = 1)
40             self.api_type = 'xmlrpc'
41
42         # try setting hostname and ip
43         (stdout, stderr) = utils.popen("hostname")
44         self.hostname = stdout[0].strip()
45         (stdout, stderr) = utils.popen("/sbin/ifconfig eth0 | grep 'inet addr'")
46         inet_addr = re.findall('inet addr:[0-9\.^\w]*', stdout[0])[0]
47         parts = inet_addr.split(":")
48         self.ip = parts[1]
49         
50         # Load list of node tests
51         valid_node_test_files = lambda name: not name.startswith('__init__') \
52                                              and not name.endswith('pyc')
53         node_test_files = os.listdir(self.node_tests_path)
54         self.node_test_files = filter(valid_node_test_files, node_test_files) 
55