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