From d53e65c510eda5e0af07a14c906a6185f428cfbc Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Thu, 31 Jan 2008 20:06:58 +0000 Subject: [PATCH] define some helpful paths, define the list of acceptable node tests, try to import PLC.Shell for direct PLCAPI access before trying to use PLCAPI over xmlrpc --- qaapi/qa/Config.py | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/qaapi/qa/Config.py b/qaapi/qa/Config.py index d230d51..cccb4ae 100644 --- a/qaapi/qa/Config.py +++ b/qaapi/qa/Config.py @@ -1,20 +1,55 @@ import xmlrpclib import os +import sys +import re +import utils class Config: - path = os.path.dirname(os.path.abspath(__file__)) + path = os.path.dirname(os.path.abspath(__file__)) + tests_path = path + os.sep + 'tests' + node_tests_path = tests_path + os.sep + 'node' + slice_tests_path = tests_path + os.sep + 'slice' def __init__(self, config_file = path+os.sep+'qa_config'): + # Load config file try: execfile(config_file, self.__dict__) except: - print __file__ raise "Could not find system config in %s" % config_file self.auth = {} self.auth['Username'] = self.PLC_ROOT_USER self.auth['AuthString'] = self.PLC_ROOT_PASSWORD self.auth['AuthMethod'] = 'password' - self.api = xmlrpclib.Server('https://%s/PLCAPI/' % self.PLC_API_HOST) - self.verbose = True + self.verbose = self.VERBOSE + + # Set up API acccess + # Try importing the API shell for direct api access. + # If that fails fall back to using xmlrpm + try: + sys.path.append('/usr/share/plc_api') + from PLC.Shell import Shell + shell = Shell(globals = globals()) + + # test it + shell.GetRoles() + self.api = shell + self.api_type = 'direct' + except: + self.api = xmlrpclib.Server('https://%s/PLCAPI/' % self.PLC_API_HOST, allow_none = 1) + self.api_type = 'xmlrpc' + + # try setting hostname and ip + (stdout, stderr) = utils.popen("hostname") + self.hostname = stdout[0].strip() + (stdout, stderr) = utils.popen("/sbin/ifconfig eth0 | grep 'inet addr'") + inet_addr = re.findall('inet addr:[0-9\.^\w]*', stdout[0])[0] + parts = inet_addr.split(":") + self.ip = parts[1] + + # Load list of node tests + valid_node_test_files = lambda name: not name.startswith('__init__') \ + and not name.endswith('pyc') + node_test_files = os.listdir(self.node_tests_path) + self.node_test_files = filter(valid_node_test_files, node_test_files) -- 2.43.0