X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=qaapi%2Fqa%2FPLCs.py;h=80221e87671e8e82fc669fc2b7983f9096bacc09;hb=2798b64de8bf90b6113d8807e1b6b75bb8815f1f;hp=dacee1bfcd8404c549a0c3df4612421966f7ead0;hpb=16c32382bc744ba4a1d49673887f85b3f49f46af;p=tests.git diff --git a/qaapi/qa/PLCs.py b/qaapi/qa/PLCs.py index dacee1b..80221e8 100644 --- a/qaapi/qa/PLCs.py +++ b/qaapi/qa/PLCs.py @@ -1,18 +1,20 @@ import os -import copy -import qa.utils +import re +import utils +import xmlrpclib from Remote import Remote from Table import Table +from logger import Logfile class PLC(dict, Remote): fields = { 'name': 'TestPLC', # PLC Name 'host': 'localhost', # Node Hostname 'ip': '127.0.0.1', # IP - 'chroot': None, + 'chroot': None, # Path to the chroot 'vserver': None, # Vserver where this PLC lives - 'rootkey': '/home/tmack/.ssh/plc-root', # Root Key - 'api_path': '/PLCAPI/', # PLCAPI path + 'host_rootkey': None, # Root Key + 'api_path': '/PLCAPI/', # PLCAPI path 'port': '443' # PLCAPI port } @@ -26,22 +28,42 @@ class PLC(dict, Remote): # init config self.config = config - self.config.update_api(self) + self.__init_logfile__() - def start_xmlrpc_server(self): - """ - PLCAPI comes with a SimpleServer script that allows you to run a - standalone http server that listens on the specified port. - This is useful for running multiple api servers on the same machine. - """ - if 'host' in self and not 'host' in ['localhost', None]: - server_script = "/usr/share/plc_api/Server.py" - self.commands("%s -p %s" % (server_script, self['port'])) - if self.config.verbose: - utils.header("Starting api server at %s on listening on port %s" % (self['host'], self['port'])) + def __init_logfile__(self, filename = None): + if not filename: + filename = '%s/qaapi.log' % (self.config.logdir) + self.logfile = Logfile(filename) -class PLCs(list, Table): + def update_ip(self): + try: + command = "/sbin/ifconfig eth0 | grep -v inet6 | grep inet | awk '{print$2;}'" + (status, output) = self.commands(command) + ip = re.findall(r'[0-9\.]+', output)[0] + except: + ip = "127.0.0.1" + self['ip'] = ip.strip() + return self['ip'] + + def update_api(self): + # Set up API acccess + # If plc is specified, find its configuration + # and use its API + self.update_ip() + name, ip, port, path = self['name'], self['ip'], self['port'], self['api_path'] + if self.config.verbose: + utils.header("Updating %(name)s's api to https://%(ip)s:%(port)s/%(path)s" % locals(), logfile = self.config.logfile) + api_server = "https://%(ip)s:%(port)s/%(path)s" % locals() + self.config.api = xmlrpclib.Server(api_server, allow_none = 1) + self.config.api_type = 'xmlrpc' + + def scp_to_webroot(self, localfiles, recursive = False): + if self.config.verbose: + utils.header("Copying %s to %s webroot" % (localfiles, self['name']), logfile = self.config.logfile) + self.scp_to("%(localfiles)s" % locals(), "/var/www/html/") + +class PLCs(Table): def __init__(self, config, plcs): plclist = [PLC(config, plc) for plc in plcs] - list.__init__(self, plclist) + Table.__init__(self, plclist)