def _check_version(self, tc_instance):
        if tc_instance.config.get("compatible") and tc_instance.config[
                'compatible']['framework']['name']:
            framework = tc_instance.config['compatible']['framework']
            # Check if version requirement is available
            # and that the testcase is meant for this framework
            if framework['version'] and framework['name'] == "Icetea":
                ver_str = framework['version']
                fw_version = get_fw_version()
                try:
                    if not self._check_major_version(fw_version, ver_str):
                        result = self._wrong_version(
                            tc_instance, ver_str,
                            "Testcase not suitable for version >1.0.0. "
                            "Please install Icetea {}".format(ver_str))
                        return result
                except ValueError:
                    # Unable to convert fw_version to integer, let's just proceed.
                    return None
                if ver_str[0].isdigit():
                    return self._wrong_version(
                        tc_instance,
                        ver_str) if fw_version != ver_str else None

                # Handle case where the version is a version number without comparison operators
                if not semver.match(fw_version, ver_str):
                    result = self._wrong_version(tc_instance, ver_str)
                    return result
            return None
        else:
            return None
Beispiel #2
0
    def test_get_fw_version(self):
        version = None
        try:
            setup_path = os.path.abspath(os.path.dirname(__file__) + '/..')
            with open(os.path.join(setup_path, 'setup.py')) as setup_file:
                lines = setup_file.readlines()
                for line in lines:
                    m = re.search(r"VERSION = \"([\S]{5,})\"", line)
                    if m:
                        version = m.group(1)
                        break
        except Exception as e:
            pass

        v = tools.get_fw_version()
        self.assertEqual(v, version)

        with mock.patch("icetea_lib.tools.tools.require") as mocked_require:
            mocked_require.side_effect = [DistributionNotFound]
            v = tools.get_fw_version()
            self.assertEqual(v, version)
Beispiel #3
0
    def __init__(self, kwargs=None):
        kwargs = {} if kwargs is None else kwargs
        self.__verdict = 'unknown'
        self.duration = kwargs.get("duration", 0)
        self.framework_info = {
            "name": kwargs.get("fw_name", get_fw_name()),
            "version": kwargs.get("fw_version", get_fw_version())
        }
        self.tc_git_info = {
            "url": kwargs.get("gitUrl", ''),
            "branch": kwargs.get("branch", ''),
            "commitId": kwargs.get("commitId", '')
        }
        self.job_id = kwargs.get("jobId", '')
        self.campaign = kwargs.get("campaign", '')
        self.retries_left = 0
        self.duration = kwargs.get("duration", 0)

        self.fail_reason = kwargs.get("reason", '')
        self.skip_reason = kwargs.get("skip_reason", '')
        self.dutinformation = DutInformationList()
        self.dut_type = ''
        self.dut_count = 0
        self.dut_vendor = []
        self.toolchain = 'unknown'
        self.logpath = None
        self.retcode = kwargs.get("retcode", -1)
        self.tester = Result.__get_username()
        self.component = []  # CUT - Component Under Test
        self.feature = []  # FUT - Feature Under Test
        self.logfiles = []
        self.tc_metadata = kwargs.get("tc_metadata", {
            'name': '',
            'purpose': ''
        })
        self.tc_metadata['name'] = kwargs.get("testcase", '')
        self.stdout = kwargs.get("stdout", '')
        self.stderr = kwargs.get("stderr", '')
        if "verdict" in kwargs:
            self.set_verdict(kwargs.get("verdict"))
        if 'retcode' in kwargs:
            self.retcode = kwargs.get("retcode")
            if self.retcode == 0:
                self.set_verdict("pass", self.retcode)
            else:
                self.set_verdict("fail", self.retcode)
        self.uploaded = False
Beispiel #4
0
    def _create(self, title, heads, refresh=None, path_start=None):
        """
        Internal create method, uses yattag to generate a html document with result data.

        :param title: Title of report
        :param heads: Headers for report
        :param refresh: If set to True, adds a HTTP-EQUIV="refresh" to the report
        :param path_start: path to file where this is report is to be stored.
        :return: yattag document.
        """
        # TODO: Refactor to make less complex
        doc, tag, text = Doc().tagtext()
        doc.asis('<!DOCTYPE html>')
        heads["Date"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        heads["Pass rate"] = self.results.pass_rate()
        heads["Pass rate excluding retries"] = self.results.pass_rate(include_retries=False)

        with tag('html'):
            with tag('head'):
                doc.asis(self.head)
                if refresh:
                    doc.asis('<META HTTP-EQUIV="refresh" CONTENT="' + str(refresh) + '">')
            with tag('body', id='body'):
                with tag('h1'):
                    text(title)
                with tag('table'):
                    for head in heads:
                        with tag('tr'):
                            with tag('th', width="100px"):
                                text(head)
                            with tag('td'):
                                text(heads[head])
                    with tag('tr'):
                        with tag('th'):
                            text('Executed')
                        with tag('td'):
                            text(str(self.summary["count"]))
                    with tag('tr'):
                        with tag('th'):
                            text('Pass:'******'td'):
                            text(str(self.summary["pass"]))
                    with tag('tr'):
                        with tag('th'):
                            text('Fails:')
                        with tag('td'):
                            text(str(self.summary["fail"]))
                    with tag('tr'):
                        with tag('th'):
                            text('inconclusive:')
                        with tag('td'):
                            text(str(self.summary["inconclusive"]))
                    with tag('tr'):
                        with tag('th'):
                            text('Skip:')
                        with tag('td'):
                            text(str(self.summary["skip"]))
                    with tag('tr'):
                        with tag('th'):
                            text('Duration:')
                        with tag('td'):
                            text(self.duration_to_string(self.summary["duration"]))
                    with tag('tr'):
                        with tag('th'):
                            text('{} version:'.format(get_fw_name()))
                        with tag('td'):
                            text(get_fw_version())

                with tag('table', style='border-collapse: collapse;'):
                    with tag('tr'):
                        with tag('th'):
                            text("Test Case")
                        with tag('th'):
                            text("Verdict")
                        with tag('th'):
                            text("Fail Reason")
                        with tag('th'):
                            text("Skip Reason")
                        with tag('th'):
                            text("Retried")
                        with tag('th'):
                            text("Duration")
                    for result in self.results:
                        if result.success:
                            klass = 'item_pass'
                        elif result.inconclusive:
                            klass = 'item_inconc'
                        else:
                            klass = 'item_fail'
                        with tag('tr', klass='item %s' % klass, onclick='showhide(this)'):
                            with tag('td', width="200px"):
                                text(result.get_tc_name())
                            with tag('td', width="100px"):
                                if result.success:
                                    color = 'green'
                                elif result.failure:
                                    color = 'red'
                                else:
                                    color = 'black'
                                with tag('font', color=color):
                                    text(result.get_verdict())
                            with tag('td', width="350px"):
                                text(hex_escape_str(result.fail_reason))
                            with tag('td', width="300px"):
                                text(result.skip_reason if result.skipped() else "")
                            with tag('td', width="50px"):
                                text("Yes" if result.retries_left != 0 else "No")
                            with tag('td', width="100px"):
                                text(str(result.duration))
                        with tag('tr', klass='info hidden'):
                            with tag('td', colspan="5"):
                                if hasattr(result, 'tc_git_info') and \
                                        result.tc_git_info and \
                                        "scm_link" in result.tc_git_info:
                                    # add tc git info only when available
                                    link = result.tc_git_info['scm_link']
                                    with tag('a', href=link):
                                        text(link)
                                    doc.stag('br')
                                for fil in result.logfiles:
                                    filepath = os.path.relpath(fil, path_start)
                                    with tag('a', href=filepath):
                                        text(filepath)
                                    doc.stag('br')

        return doc.getvalue()
Beispiel #5
0
    def run(self, args=None):
        """
        Runs the set of tests within the given path.
        """
        # Disable "Too many branches" and "Too many return statemets" warnings
        # pylint: disable=R0912,R0911
        retcodesummary = ExitCodes.EXIT_SUCCESS
        self.args = args if args else self.args

        if not self.check_args():
            return retcodesummary

        if self.args.clean:
            if not self.args.tc and not self.args.suite:
                return retcodesummary

        # If called with --version print version and exit
        version = get_fw_version()
        if self.args.version and version:
            print(version)
            return retcodesummary
        elif self.args.version and not version:
            print(
                "Unable to get version. Have you installed Icetea correctly?")
            return retcodesummary

        self.logger.info(
            "Using Icetea version {}".format(version) if version else
            "Unable to get Icetea version. Is Icetea installed?")

        # If cloud set, import cloud, get parameters from environment, initialize cloud
        cloud = self._init_cloud(self.args.cloud)

        # Check if called with listsuites. If so, print out suites either from cloud or from local
        if self.args.listsuites:
            table = self.list_suites(self.args.suitedir, cloud)
            if table is None:
                self.logger.error("No suites found!")
                retcodesummary = ExitCodes.EXIT_FAIL
            else:
                print(table)
            return retcodesummary

        try:
            testsuite = TestSuite(logger=self.logger,
                                  cloud_module=cloud,
                                  args=self.args)
        except SuiteException as error:
            self.logger.error(
                "Something went wrong in suite creation! {}".format(error))
            retcodesummary = ExitCodes.EXIT_INCONC
            return retcodesummary

        if self.args.list:
            if self.args.cloud:
                testsuite.update_testcases()
            testcases = testsuite.list_testcases()
            print(testcases)
            return retcodesummary

        results = self.runtestsuite(testsuite=testsuite)

        if not results:
            retcodesummary = ExitCodes.EXIT_SUCCESS
        elif results.failure_count(
        ) and self.args.failure_return_value is True:
            retcodesummary = ExitCodes.EXIT_FAIL
        elif results.inconclusive_count(
        ) and self.args.failure_return_value is True:
            retcodesummary = ExitCodes.EXIT_INCONC

        return retcodesummary