Beispiel #1
0
    def run(self, options, conf_dict):
        if self.provisioner == "beaker" and self.framework == "restraint":
            git = Git(options, conf_dict)
            git.get_archive()

            repo = Repos(options, conf_dict)
            repo.run_repo_setup(options, conf_dict)

            restraint = Restraint(options, conf_dict)

            """ This function actually runs restraint command and
            executed the job on beaker.
            """
            restraint.run_restraint(options, conf_dict)

        elif self.provisioner == "beaker" and self.framework == "pytest":

            repo = Repos(options, conf_dict)
            repo.run_repo_setup(options, conf_dict)

            pytest = Pytest(options, conf_dict)
            pytest.run_pytest(options, conf_dict)

            if options.coverage is True:
                logger.log.info("Get coverage report")
                coverage = Testcoverage(options, conf_dict)
                coverage.coverage_reports(options, conf_dict)
                coverage.get_reports(options, conf_dict)
            else:
                logger.log.info("No coverage report since option not set")

        elif self.provisioner == "openstack" and self.framework == "pytest":

            repo = Repos(options, conf_dict)
            repo.run_repo_setup(options, conf_dict)

            pytest = Pytest(options, conf_dict)
            pytest.run_pytest(options, conf_dict)

            if options.coverage is True:
                logger.log.info("Get coverage report")
                coverage = Testcoverage(options, conf_dict)
                coverage.coverage_reports(options, conf_dict)
                coverage.get_reports(options, conf_dict)
            else:
                logger.log.info("No coverage report since option not set")

        else:
            logger.log.error("Unknown provisioner or framework")
Beispiel #2
0
    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
Beispiel #3
0
    def run(self, options, conf_dict):
        if self.provisioner == "beaker" and self.framework == "restraint":
            git = Git(options, conf_dict)
            git.get_archive()

            repo = Repos(options, conf_dict)
            repo.run_repo_setup(options, conf_dict)

            restraint = Restraint(options, conf_dict)

            """ This function actually runs restraint command and
            executed the job on beaker.
            """
            restraint.run_restraint(options, conf_dict)

        elif self.provisioner == "beaker" and self.framework == "pytest":

            repo = Repos(options, conf_dict)
            repo.run_repo_setup(options, conf_dict)

            pytest = Pytest(options, conf_dict)
            pytest.run_pytest(options, conf_dict)

            if options.coverage is True:
                logger.log.info("Get coverage report")
                coverage = Testcoverage(options, conf_dict)
                coverage.coverage_reports(options, conf_dict)
                coverage.get_reports(options, conf_dict)
            else:
                logger.log.info("No coverage report since option not set")

        elif self.provisioner == "openstack" and self.framework == "pytest":

            repo = Repos(options, conf_dict)
            repo.run_repo_setup(options, conf_dict)

            pytest = Pytest(options, conf_dict)
            pytest.run_pytest(options, conf_dict)

            if options.coverage is True:
                logger.log.info("Get coverage report")
                coverage = Testcoverage(options, conf_dict)
                coverage.coverage_reports(options, conf_dict)
                coverage.get_reports(options, conf_dict)
            else:
                logger.log.info("No coverage report since option not set")

        elif self.provisioner == "openstack" and self.framework == "restraint":

            git = Git(options, conf_dict)
            git.get_archive()

            repo = Repos(options, conf_dict)
            repo.run_repo_setup(options, conf_dict)

            restraint = Restraint(options, conf_dict)
            restraint.run_restraint(options, conf_dict)

        elif self.provisioner == "openstack" and self.framework == "dogtag-pytest":
            repo = Repos(options, conf_dict)
            repo.run_repo_setup(options, conf_dict)
            pkitest = PkiTest(options, conf_dict)
            pkitest.set_hostnames()
            pkitest.update_etc_hosts()
            yaml_file = pkitest.create_yaml()
            logger.log.info("we completed creating yaml file")
            logger.log.info("Current working directory is: %s"%(os.environ.get('PWD')))
            pkitest.deploy_ssh_keys()
            if pkitest.copy_extras_repo():
                logger.log.info("Extra's repo configured successfull")
                if pkitest.install_prereqs():
                    logger.log.info("Pre-requisites to run pytest has been installed successfull")
                    pkitest.pytest_setup()
                    if pkitest.run_pytest(yaml_file):
                        logger.log.info("pytest ran successfully")
                    else:
                        logger.log.info("pytest failed")
                else:
                    logger.log.info("Pre-requisites to run pytest has not been installed")
            else:
                logger.log.info("Extras repo did not configure")

        elif self.provisioner == "beaker" and self.framework == "dogtag-pytest":
            repo = Repos(options, conf_dict)
            repo.run_repo_setup(options, conf_dict)
            pkitest = PkiTest(options, conf_dict)
            pkitest.update_etc_hosts()
            yaml_file = pkitest.create_yaml()
            pkitest.deploy_ssh_keys()
            if pkitest.copy_extras_repo():
                logger.log.info("Extra's repo configured successfull")
                if pkitest.install_prereqs():
                    logger.log.info("Pre-requisites to run pytest has been installed successfull")
                    if pkitest.run_pytest(yaml_file):
                        logger.log.info("pytest ran successfully")
                    else:
                        logger.log.info("pytest failed")
                else:
                    logger.log.info("Pre-requisites to run pytest has not been installed")
            else:
                logger.log.info("Extras repo did not configure")
        else:
            logger.log.error("Unknown provisioner or framework")