def create_pyjob_runner(job_yaml, job_path, job_id, workspace, user):
    """create python job runner"""
    logger.debug('jobmodel - creating python job runner')

    # loading globals variables
    globals_file = '%s/%s/%s/globals.yml' % (settings.get_app_path(
    ), settings.cfg['paths']['workspaces'], workspace)
    globals_valid, yaml_globals = load_yamlfile(yaml_file=globals_file,
                                                workspace=workspace,
                                                user=user,
                                                repo=constant.REPO_WORKSPACES)
    if globals_valid != constant.OK:
        logger.error('jobmodel - invalid globals variables')
        return (constant.ERROR, {})

    script = []
    script.append("#!/usr/bin/python")
    script.append("# -*- coding: utf-8 -*-")
    script.append("")
    script.append("import sys")
    script.append("import os")
    script.append("import time")
    script.append("import json")
    script.append("import traceback")
    script.append("")
    script.append("p = os.path.dirname(os.path.abspath(__file__))")
    script.append("root_path = os.sep.join(p.split(os.sep)[:-5])")
    script.append("sys.path.insert(0, root_path)")
    script.append("")
    script.append("from ea.automateactions.joblibrary import jobtracer")
    script.append("from ea.automateactions.joblibrary import jobhandler")
    script.append("from ea.automateactions.joblibrary import jobsnippet")
    script.append("from ea.automateactions.joblibrary import datastore")
    script.append("")
    script.append("jobtracer.initialize(result_path=p)")
    script.append("")
    script.append("sys.stderr = jobtracer.StdWriter(mode_err=True)")
    script.append("sys.stdout = jobtracer.StdWriter()")
    script.append("")
    script.append("jobhandler.initialize(globals=%s)" % yaml_globals)
    script.append("datastore.initialize()")
    script.append("")
    script.append(write_snippets(job_path, job_yaml, job_id, workspace, user))
    script.append("")
    script.append("jobhandler.instance().start()")
    script.append("jobhandler.finalize()")
    script.append("ret_code = jobhandler.get_retcode()")
    script.append("sys.exit(ret_code)")

    with open(n("%s/jobrunner.py" % job_path), 'wb') as fd:
        fd.write('\n'.join(script).encode('utf-8'))

    return (constant.OK, "success")
Example #2
0
    def save_workspaces(self):
        """"save workspaces to file"""
        # checking if the file exists
        wrks_file = '%s/data/workspaces.yml' % (settings.get_app_path())
        if not os.path.isfile(n(wrks_file)):
            raise Exception("yaml workspaces file doesn't exist in data/")

        try:
            wrks_str = yaml.safe_dump(self.cache)
        except Exception as e:
            raise Exception("dump workspaces config error: %s" % e)

        with open(wrks_file, 'w') as fd:
            fd.write(wrks_str)
    def save_users(self):
        """save users to yaml file"""
        # checking if the file exists
        users_file = '%s/data/users.yml' % (settings.get_app_path())
        if not os.path.isfile(n(users_file)):
            raise Exception("yaml users file doesn't exist in data/")

        try:
            usrs_str = yaml.safe_dump(self.cache)
        except Exception as e:
            raise Exception("dump users error: %s" % e)

        with open(users_file, 'w') as fd:
            fd.write(usrs_str)
Example #4
0
    def load_workspaces(self):
        """load workspaces"""
        wrk_file = '%s/data/workspaces.yml' % (settings.get_app_path())
        if not os.path.isfile(n(wrk_file)):
            raise Exception("yaml workspaces file doesn't exist in data/")

        # load yaml
        with open(wrk_file, 'r') as fd:
            wrks_str = fd.read()

        try:
            self.cache = yaml.safe_load(wrks_str)
        except Exception as e:
            raise Exception("bad yaml workspaces file provided: %s" % e)

        logger.debug("workspacesmanager - workspaces cache "
                     "nb items: %s" % len(self.cache["workspaces"]))
    def load_users(self):
        """load users from yaml file"""
        users_file = '%s/data/users.yml' % (settings.get_app_path())
        if not os.path.isfile(n(users_file)):
            raise Exception("yaml users file doesn't exist in data/")

        # load yaml
        with open(users_file, 'r') as fd:
            usrs_str = fd.read()

        try:
            self.cache = yaml.safe_load(usrs_str)
        except Exception as e:
            raise Exception("bad yaml users file provided: %s" % e)

        logger.debug("usersmanager - users cache "
                     "nb items: %s" % len(self.cache["users"]) )
from ea.automateactions.serverengine import jobsmanager
from ea.automateactions.serverengine import workspacesmanager
from ea.automateactions.serverengine import globalsmanager
from ea.automateactions.serverengine import sessionsmanager
from ea.automateactions.serverengine import usersmanager
from ea.automateactions.servercontrol import cliserver
from ea.automateactions.servercontrol import restapi
from ea.automateactions.serverstorage import executionstorage
from ea.automateactions.serverstorage import actionstorage
from ea.automateactions.serverstorage import snippetstorage

n = os.path.normpath

settings.initialize()

path_backups = "%s/%s/" % (settings.get_app_path(),
                           settings.cfg['paths']['jobs-backups'])
path_results = '%s/%s/' % (settings.get_app_path(),
                           settings.cfg['paths']['jobs-executions'])
path_workspaces = "%s/%s/" % (settings.get_app_path(),
                              settings.cfg['paths']['workspaces'])
path_snippets = "%s/%%s/snippets/" % path_workspaces
path_actions = "%s/%%s/actions/" % path_workspaces
path_logs = "%s/%s/output.log" % (settings.get_app_path(),
                                  settings.cfg['paths']['server-logs'])
path_pid = "%s/%s/server.pid" % (settings.get_app_path(),
                                 settings.cfg['paths']['server-logs'])
app_name = settings.cfg['name']

logger.initialize(log_file=path_logs,
                  level=settings.cfg['log']['level'],