コード例 #1
0
def setup_conf(options):

    conf = options.conf

    config = ConfigParser.SafeConfigParser()
    config.read(conf)

    ci_msg = CI_MSG()
    t = ci_msg.get_ci_msg_value('tag')
    if t:
        tag = t['name']
        config.set('brew', 'brew_tag', tag)
        logger.log.info("brew tag name is %s" % tag)
    else:
        logger.log.warn("tag not found in CI_MESSAGE")

    workspace = os.environ.get("WORKSPACE")
    if not workspace:
        logger.log.warn("Unable to find WORKSPACE env variable")
    else:
        logger.log.info("WORKSPACE env variable is %s" % workspace)
        config.set('jenkins', 'workspace', workspace)

    job_name = os.environ.get("JOB_NAME")
    if not job_name:
        logger.log.warn("Unable to find JOB_NAME env variable")
    else:
        logger.log.info("JOB_NAME from env variable is %s" % job_name)
        config.set('jenkins', 'job_name', job_name)

    existing_nodes = os.environ.get("EXISTING_NODES")
    if not existing_nodes:
        logger.log.warn("Unable to find EXISTING_NODES env variable")
    else:
        logger.log.info("EXISTING_NODES from env variable is %s" % existing_nodes)
        config.set('jenkins', 'existing_nodes', existing_nodes)

    with open(conf, 'wb') as confini:
        config.write(confini)

    if os.path.isfile(conf):
        f = factory.Conf_ini()
        f.read(conf)
        logger.log.info("Writing environment details to %s" % conf)
        conf_dict = f.conf_to_dict()
        return conf_dict
コード例 #2
0
ファイル: pytests.py プロジェクト: mrniranjan/nexus
    def run_pytest(self, options, conf_dict):
        """ Run pytest command using the marker if provided """

        threads = Threader()

        threads.gather_results([threads.get_item(self.deploy_ssh_keys, \
                                host, conf_dict) for host in \
                                self.existing_nodes])

        threads.gather_results([threads.get_item(self.install_prereqs, \
                                host, conf_dict) for host in \
                                self.existing_nodes])

        threads.gather_results([threads.get_item(self.copy_extras_repo, \
                                host, conf_dict) for host in \
                                self.existing_nodes])

        threads.gather_results([threads.get_item(self.install_prereqs, \
                                host, conf_dict) for host in \
                                self.existing_nodes])

        logger.log.info("Updating %s with existing_nodes information" % self.tests_cfg)

        node = 0
        host_num = 1
        host_recipe = []
        while node < len(self.existing_nodes):
            host_num = str(host_num)
            hostname = ("hostname" + host_num);
            host_num = int(host_num)
            j = open(self.tests_cfg, 'r').read()
            m = j.replace(hostname, (self.existing_nodes[node]))
            f = open(self.tests_cfg, 'w')
            f.write(m)
            f.close()

            node = node + 1
            host_num = host_num + 1

        threads.gather_results([threads.get_item(self.pytest_setup, \
                                host, conf_dict) for host in \
                                self.existing_nodes])

        if options.coverage is True:
            coverage = Testcoverage(options, conf_dict)
            coverage.run_coverage(options, conf_dict)
            logger.log.info("Coverage option set.")
        else:
            logger.log.info("Coverage option not set.")

        self.tests_to_run = conf_dict['pytest']['tests_to_run']
        self.tests_cfg = conf_dict['pytest']['tests_cfg']
        self.pytest_junit_loc = conf_dict['pytest']['pytest_junit_loc']

        ci_msg = CI_MSG()
        try:
            ttypes = ci_msg.get_ci_msg_value('testtypes')
        except Exception:
            pass
            ttypes = None

        try:
            ttiers = ci_msg.get_ci_msg_value('testtiers')
        except Exception:
            pass
            ttiers = None

        patterns = []

        if ttypes is None and ttiers is None:
            logger.log.info("Both test-tier and test-type options are none in CI_MESSAGE")

            pytest_cmd = "py.test -v --color=yes --junit-xml=" + self.pytest_junit_loc + \
                " --multihost-config=" + self.tests_cfg + " " + self.tests_to_run
            logger.log.info(pytest_cmd)

        else:
            pytest_cmd = "py.test --junit-xml=" + self.pytest_junit_loc + \
                " --multihost-config=" + self.tests_cfg + " " + self.tests_to_run
            logger.log.info(pytest_cmd)

            if ttypes is None:
                logger.log.info("test-type is none in CI_MESSAGE")
            else:
                for item in ttypes:
                    mystr = "-m" + " " + item
                    patterns.append(mystr)

            if ttiers is None:
                logger.log.info("test-tier is none in CI_MESSAGE")
            else:
                for item in ttiers:
                    mystr = "-m" + " " + item
                    patterns.append(mystr)

            pytest_patterns = " ".join(patterns)
            pytest_cmd = pytest_cmd + " " + pytest_patterns
            logger.log.info(pytest_cmd)

        host = self.existing_nodes[0]

        ssh_c = SSHClient(hostname = host, username = \
                        self.username, password = self.password)
        stdout,stderr,exit_status = ssh_c.ExecuteScript(pytest_cmd)
        output = stdout.getvalue()
        error = stderr.getvalue()

        if error:
            print "error running script: ", error
            print "Exit status : ", exit_status
        else:
            print "Script Output: ", output

        stdout.close()
        stderr.close()

        try:
            self.copy_testout_junit(options, conf_dict)
        except IOError:
            logger.log.info("Junit xml file not found.")
            pass
コード例 #3
0
ファイル: dogtag.py プロジェクト: mrniranjan/nexus
    def run_pytest(self, multihost_yaml_file):
        """ Run pytest command using the marker if provided """
        ssh_c = SSHClient(
                hostname=self.pytest_node,
                username = self.username,
                password = self.password)
        ssh_c.CopyFiles(multihost_yaml_file, multihost_yaml_file)
        try:
            tests_to_run = self.conf_dict['pytest']['tests_to_run']
        except KeyError as Err:
            logger.log.info("No parameter %s found in nexus configuration"%(Err.message))
            return False
        try:
            pytest_junit_loc = self.conf_dict['pytest']['pytest_junit_loc']
        except KeyError as Err:
            logger.log.info("No parameter %s found in nexus configuration"%(Err.message))
            return False

        ci_msg = CI_MSG()
        try:
            ttypes = ci_msg.get_ci_msg_value('testtypes')
        except Exception as Err:
            pass
            ttypes = None
        try:
            ttiers = ci_msg.get_ci_msg_value('testtiers')
        except Exception as Err:
            pass
            ttiers = None
        patterns = []
        if ttypes is None and ttiers is None:
            logger.log.info("Both test-tier and test-type options are none in CI_MESSAGE")
            pytest_cmd = "py.test -v -s --color=yes --debug --junit-xml=%s --multihost-config=%s %s"%(
                    pytest_junit_loc, multihost_yaml_file, tests_to_run)
        else:
            pytest_cmd = "py.test -v -s --junit-xml=%s --debug --multihost-config=%s %s"%(
                    pytest_junit_loc, multihost_yaml_file, tests_to_run)
        logger.log.info(pytest_cmd)

        if ttypes is None:
            logger.log.info("test-type is none in CI_MESSAGE")
        else:
            for item in ttypes:
                mystr = "-m" + " " + item
                patterns.append(mystr)

        if ttiers is None:
            logger.log.info("test-tier is none in CI_MESSAGE")
        else:
            for item in ttiers:
                mystr = "-m" + " " + item
                patterns.append(mystr)
        pytest_patterns = " ".join(patterns)
        pytest_cmd = pytest_cmd + " " + pytest_patterns
        logger.log.info(pytest_cmd)
        ssh_c = SSHClient(
                hostname=self.pytest_node,
                username = self.username,
                password = self.password)
        stdout,stderr,exit_status = ssh_c.ExecuteScript(pytest_cmd)
        output = stdout.getvalue()
        error = stderr.getvalue()
        if error:
            print("error running script: "), error
            print("Exit status: "), exit_status
        else:
            print("Script output: "), output

        
        try:
            self.copy_test_out_junit()
        except IOError:
            logger.log.info("Junit xml file not found")
            pass