add date to log's filename by default
[tests.git] / qaapi / qa / Config.py
index 570957a..ba12682 100644 (file)
@@ -5,12 +5,15 @@ import re
 import socket
 import utils
 import copy
+from logger import logfile
 from PLCs import PLC, PLCs
 from Sites import Site, Sites  
 from Nodes import Node, Nodes
 from Slices import Slice, Slices
 from Persons import Person, Persons    
 
+path = os.path.dirname(os.path.abspath(__file__))
+
 class Config:
 
     path = os.path.dirname(os.path.abspath(__file__))
@@ -18,15 +21,17 @@ class Config:
     node_tests_path = tests_path + os.sep + 'node' + os.sep
     slice_tests_path = tests_path + os.sep + 'slice' + os.sep                          
     vserver_scripts_path = path + os.sep + 'vserver' + os.sep
-    qemu_scripts_path = path + os.sep + 'qemu' + os.sep        
-
+    log_filename = logfile.filename
+    
     def update_api(self, plc = None):
        # Set up API acccess
        # If plc is specified, find its configuration
        # and use its API
         if plc is not None:
-           host, path, port  = plc['host'], plc['api_path'], plc['port']
-           api_server = "https://%(host)s:%(port)s/%(path)s" % locals()
+           protocol, host, path, port  = 'http', plc['host'], plc['api_path'], plc['port']
+           if port in ['443']:
+               protocol = 'https'
+           api_server = "%(protocol)s://%(host)s:%(port)s/%(path)s" % locals()
            self.api = xmlrpclib.Server(api_server, allow_none = 1)
            self.api_type = 'xmlrpc'    
        else:
@@ -52,7 +57,8 @@ class Config:
             execfile(config_file, self.__dict__)
         except:
             raise "Could not find system config in %s" % config_file
-
+       
+       self.logfile = logfile
        self.auth = {}
        self.auth['Username'] = self.PLC_ROOT_USER
        self.auth['AuthString'] = self.PLC_ROOT_PASSWORD
@@ -62,10 +68,9 @@ class Config:
        # try setting hostname and ip
         self.hostname = socket.gethostname()
         try:
-           (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]
+            command = "/sbin/ifconfig eth0 | grep -v inet6 | grep inet | awk '{print$2;}'"
+            (status, output) = utils.commands(command)            
+           self.ip = re.findall(r'[0-9\.]+', output)[0]
        except:
            self.ip = '127.0.0.1'
        
@@ -80,6 +85,20 @@ class Config:
        node_test_files = os.listdir(self.node_tests_path)
        self.node_test_files = filter(valid_node_test_files, node_test_files) 
 
+    def get_plc(self, plc_name):
+       plc = PLC(self)
+       if hasattr(self, 'plcs')  and plc_name in self.plcs.keys():
+           plc.update(self.plcs[plc_name])
+           plc.update_api()
+       return plc
+
+    def get_node(self, hostname):
+       node = Node(self)
+       if hasattr(self, 'nodes') and hostname in self.nodes.keys():
+           node.update(self.nodes[hostname])
+           node.__init_logfile__()
+       return node                     
+
     def load(self, conffile):
        
        confdata = {}
@@ -92,14 +111,14 @@ class Config:
        config = Config()
        for loadable in loadables:
            if loadable in confdata and loadable in ['plcs']:
-               setattr(self, loadable, PLCs(config, confdata[loadable]))
+               setattr(self, loadable, PLCs(config, confdata[loadable]).dict('name'))
            elif loadable in confdata and loadable in ['nodes']:
-               setattr(self, loadable, Nodes(config, confdata[loadable]))              
+               setattr(self, loadable, Nodes(config, confdata[loadable]).dict('hostname'))     
            elif loadable in confdata and loadable in ['sites']:
-               setattr(self, loadable, Sites(confdata[loadable]))
+               setattr(self, loadable, Sites(confdata[loadable]).dict('login_base'))
            elif loadable in confdata and loadable in ['slices']:
-               setattr(self, loadable, Slices(confdata[loadable]))
+               setattr(self, loadable, Slices(confdata[loadable]).dict('name'))
            elif loadable in confdata and loadable in ['persons']:
-               setattr(self, loadable, Persons(confdata[loadable])) 
+               setattr(self, loadable, Persons(confdata[loadable]).dict('email')