def prepareDaemon(self):
     """
     Prepare daemon
     """
     if not Settings.cfgFileIsPresent():
         sys.stdout.write(" (config file doesn't exist)")
         sys.exit(2)
     try:
         # Initialize
         Settings.initialize()
         Logger.initialize()
         CliFunctions.initialize(parent=self)
     except Exception as e:
         self.error("Unable to initialize settings: %s" % str(e))
     else:
         # config file exist so prepare the deamon
         self.prepare(
             pidfile="%s/%s/%s.pid" %
             (Settings.getDirExec(), Settings.get(
                 'Paths', 'run'), Settings.get('Server', 'acronym')),
             name=Settings.get('Server', 'name'),
             stdout="%s/%s/output.log" %
             (Settings.getDirExec(), Settings.get('Paths', 'logs')),
             stderr="%s/%s/output.log" %
             (Settings.getDirExec(), Settings.get('Paths', 'logs')),
             stdin="/dev/null",
             runningfile="%s/%s/%s.running" %
             (Settings.getDirExec(), Settings.get(
                 'Paths', 'run'), Settings.get('Server', 'acronym')),
         )
    def initialize(self,
                   ip,
                   port,
                   type,
                   name,
                   descr,
                   defaultTool,
                   supportProxy=False,
                   proxyIp=None,
                   proxyPort=None,
                   sslSupport=True,
                   isAgent=0,
                   fromCmd=False):
        """
        Initialize the tool

        @param ip:
        @type ip: 

        @param type:
        @type type: 

        @param name:
        @type name: 

        @param descr:
        @type descr: 
        """
        self.running = False
        self.defaultTool = defaultTool
        self.tool = None
        if not Settings.cfgFileIsPresent():
            sys.stdout.write(" (config file doesn't exist)")
            sys.exit(RETURN_CONFIG)

        try:
            Settings.initialize()
            Logger.initialize(
                logPathFile="%s/%s/%s.log" %
                (Settings.getDirExec(), Settings.get('Paths', 'logs'), name))
            if (isAgent, str(type)) in plugins:
                self.info("Initialize %s tool type=%s..." % (type, isAgent))

                if not len(ip): raise Exception("No controller ip specified!")
                if not len(name): raise Exception("No tool name specified!")

                self.tool = plugins[(isAgent, str(type))].initialize(
                    controllerIp=str(ip),
                    toolName=str(name),
                    toolDesc=str(descr),
                    defaultTool=defaultTool,
                    controllerPort=int(port),
                    supportProxy=supportProxy,
                    proxyIp=str(proxyIp),
                    proxyPort=proxyPort,
                    sslSupport=sslSupport)
                self.tool.setFromCmd()

                self.tool.onRegistrationSuccessful = self.onRegistrationSuccessful
                self.tool.onRegistrationFailed = self.onRegistrationFailed
                self.tool.onRegistrationRefused = self.onRegistrationRefused
                self.tool.onToolWarningCalled = self.onToolLogWarningCalled
                self.tool.onToolLogErrorCalled = self.onToolLogErrorCalled
                self.tool.onToolDisconnection = self.onToolDisconnection
                self.tool.onConnectionRefused = self.onConnectionRefused
                self.tool.onConnectionTimeout = self.onConnectionTimeout
                self.tool.onProxyConnectionTimeout = self.onProxyConnectionTimeout
                self.tool.onProxyConnectionRefused = self.onProxyConnectionRefused
                self.tool.onProxyConnectionError = self.onProxyConnectionError
                self.tool.checkPrerequisites()
                self.tool.startCA()
            else:
                self.error('tool type unknown: %s' % type)
                self.finalize(RETURN_TYPE_UNKNOWN)
        except Exception as e:
            self.error("unable to start tool: " + str(e))
            try:
                Settings.finalize()
            except:
                pass
            Logger.finalize()

        else:
            # run in loop
            self.running = True
            self.run()
Beispiel #3
0
    elif eval(check_syntax_sutlib_only):
        return_code = 0
        try:
            pkg = __import__("SutLibraries")
        except Exception as e:
            return_code = 1
            DocInspect.print_error('error to import sut libraries: %s' %
                                   str(e))
        sys.exit(return_code)

    else:
        return_code = 0
        # initialize settings
        try:
            Settings.initialize(path="../")
            if not Settings.cfgFileIsPresent(path="../"):
                raise Exception("config file is missing")
        except Exception as e:
            DocInspect.print_error("Unable to initialize settings: %s" % e)
            return_code = 1
        else:
            ret = []
            # construct testexecutorlib documentations
            try:
                docTestLib = generateTestExecutorLib()
                ret.extend(docTestLib)
            except Exception as e:
                DocInspect.print_error('Test Library: %s' % str(e))
                return_code = 1

            # construct testinteroplib documentations