Esempio n. 1
0
class HintTest(unittest.TestCase):
    def setUp(self):
        self.wrong_file = tempfile.NamedTemporaryFile('w', delete=False)
        self.wrong_file.write(BAD)
        self.wrong_file.close()

        self.good_file = tempfile.NamedTemporaryFile('w', delete=False)
        self.good_file.write(GOOD)
        self.good_file.close()

        self.wrong_hint = HintParser(self.wrong_file.name)
        self.good_hint = HintParser(self.good_file.name)

    def test_wrong_parser(self):
        with self.assertRaises(SettingsError) as context:
            self.wrong_hint.validate_kind_section('tap')
        self.assertTrue('Section tap is not defined' in str(context.exception))

    @skipUnlessPathExists('/bin/true')
    def test_types(self):
        res = self.good_hint.get_resolutions()
        self.assertEqual(len(res), 1)
        self.assertIsInstance(res[0], ReferenceResolution)

        resolutions = res[0].resolutions
        self.assertEqual(len(resolutions), 1)
        self.assertIsInstance(resolutions[0], Runnable)

    @skipUnlessPathExists('/bin/true')
    def test_reference_names(self):
        res = self.good_hint.get_resolutions()[0]
        self.assertEqual(res.reference, '/bin/true')
        self.assertEqual(res.resolutions[0].uri, '/bin/true')
Esempio n. 2
0
    def setUp(self):
        self.wrong_file = tempfile.NamedTemporaryFile('w', delete=False)
        self.wrong_file.write(BAD)
        self.wrong_file.close()

        self.good_file = tempfile.NamedTemporaryFile('w', delete=False)
        self.good_file.write(GOOD)
        self.good_file.close()

        self.wrong_hint = HintParser(self.wrong_file.name)
        self.good_hint = HintParser(self.good_file.name)
Esempio n. 3
0
    def run(self, config):
        hint_filepath = '.avocado.hint'
        hint = None
        if os.path.exists(hint_filepath):
            hint = HintParser(hint_filepath)
        resolutions = resolver.resolve(config.get('nrun.references'), hint)
        tasks = job.resolutions_to_tasks(resolutions, config)
        # pylint: disable=W0201
        self.pending_tasks, missing_requirements = nrunner.check_tasks_requirements(
            tasks)
        if missing_requirements:
            missing_tasks_msg = "\n".join(
                [str(t) for t in missing_requirements])
            LOG_UI.warning(
                'Tasks will not be run due to missing requirements: %s',
                missing_tasks_msg)

        if not self.pending_tasks:
            LOG_UI.error('No test to be executed, exiting...')
            sys.exit(exit_codes.AVOCADO_JOB_FAIL)

        if not config.get('nrun.disable_task_randomization'):
            random.shuffle(self.pending_tasks)

        self.spawned_tasks = []  # pylint: disable=W0201

        try:
            if config.get('nrun.spawners.podman.enabled'):
                if not os.path.exists(PodmanSpawner.PODMAN_BIN):
                    msg = ('Podman Spawner selected, but podman binary "%s" '
                           'is not available on the system.  Please install '
                           'podman before attempting to use this feature.')
                    msg %= PodmanSpawner.PODMAN_BIN
                    LOG_UI.error(msg)
                    sys.exit(exit_codes.AVOCADO_JOB_FAIL)
                self.spawner = PodmanSpawner()  # pylint: disable=W0201
            else:
                self.spawner = ProcessSpawner()  # pylint: disable=W0201
            listen = config.get('nrun.status_server.listen')
            verbose = config.get('core.verbose')
            self.status_server = nrunner.StatusServer(
                listen,  # pylint: disable=W0201
                [t.identifier for t in self.pending_tasks],
                verbose)
            self.status_server.start()
            parallel_tasks = config.get('nrun.parallel_tasks')
            loop = asyncio.get_event_loop()
            loop.run_until_complete(self.spawn_tasks(parallel_tasks))
            loop.run_until_complete(self.status_server.wait())
            self.report_results()
            exit_code = exit_codes.AVOCADO_ALL_OK
            if self.status_server.result.get('fail') is not None:
                exit_code |= exit_codes.AVOCADO_TESTS_FAIL
            elif self.status_server.result.get('error') is not None:
                exit_code |= exit_codes.AVOCADO_TESTS_FAIL
            return exit_code
        except Exception as e:  # pylint: disable=W0703
            LOG_UI.error(e)
            return exit_codes.AVOCADO_FAIL
Esempio n. 4
0
    def setUp(self):
        super().setUp()

        self.wrong_file = tempfile.NamedTemporaryFile("w",
                                                      dir=self.tmpdir.name,
                                                      delete=False)
        self.wrong_file.write(BAD)
        self.wrong_file.close()

        self.good_file = tempfile.NamedTemporaryFile("w",
                                                     dir=self.tmpdir.name,
                                                     delete=False)
        self.good_file.write(GOOD)
        self.good_file.close()

        self.wrong_hint = HintParser(self.wrong_file.name)
        self.good_hint = HintParser(self.good_file.name)
Esempio n. 5
0
    def _from_config_with_resolver(cls, config, name=None):
        ignore_missing = config.get("run.ignore_missing_references")
        references = config.get("resolver.references")
        try:
            hint = None
            hint_filepath = ".avocado.hint"
            if os.path.exists(hint_filepath):
                hint = HintParser(hint_filepath)
            resolutions = resolve(
                references, hint=hint, ignore_missing=ignore_missing, config=config
            )
        except JobTestSuiteReferenceResolutionError as details:
            raise TestSuiteError(details)

        runnables = resolutions_to_runnables(resolutions, config)

        if name is None:
            name = str(uuid4())
        return cls(name=name, config=config, tests=runnables, resolutions=resolutions)
Esempio n. 6
0
 def run(self, config):
     references = config.get('nlist.references')
     verbose = config.get('nlist.verbose')
     hint = None
     hint_filepath = '.avocado.hint'
     if os.path.exists(hint_filepath):
         hint = HintParser(hint_filepath)
     resolutions = resolver.resolve(references, hint)
     matrix, stats, tag_stats, resolution_matrix = self._get_resolution_matrix(
         config, resolutions, verbose)
     self._display(matrix, stats, tag_stats, resolution_matrix, verbose)
     recipes_directory = config.get('nlist.recipes.write_to_directory')
     if recipes_directory is not None:
         fmt = '%%0%uu.json' % len(str(len(matrix)))
         index = 1
         for resolution in resolutions:
             if resolution.result == resolver.ReferenceResolutionResult.SUCCESS:
                 for res in resolution.resolutions:
                     res.write_json(
                         os.path.join(recipes_directory, fmt % index))
                     index += 1