コード例 #1
0
    def setUp(self):
        self.tmp_dir = tempfile.TemporaryDirectory()
        self.meta_dir = os.path.join(self.tmp_dir.name, 'meta')
        os.mkdir(self.meta_dir)
        test_utils.populate_meta_dir(self.meta_dir)
        self.on_error_dir = os.path.join(self.tmp_dir.name, 'on_error_dir')
        os.mkdir(self.on_error_dir)

        self.job_step = PipelineStep(
            name='step1',
            is_synthetic=False,
            notification_policy=StepNotificationPolicy.NOTIFY_PULL_REQUESTS,
            script_type=ScriptType.BOURNE_SHELL,
            raw_dict={},
        )
        self.job_step._notifications_cfg = NotificationCfgSet('default', {})
        resource_registry = ResourceRegistry()
        meta_resource_identifier = ResourceIdentifier(type_name='meta',
                                                      base_name='a_job')
        meta_resource = Resource(resource_identifier=meta_resource_identifier,
                                 raw_dict={})
        resource_registry.add_resource(meta_resource)
        self.job_variant = JobVariant(name='a_job',
                                      raw_dict={},
                                      resource_registry=resource_registry)

        # Set a main repository manually
        test_repo_logical_name = 'test-repository'
        self.job_variant._repos_dict = {}
        self.job_variant._repos_dict[
            test_repo_logical_name] = RepositoryConfig(
                raw_dict={
                    'branch': 'master',
                    'hostname': 'github.foo.bar',
                    'path': 'test/repo'
                },
                logical_name=test_repo_logical_name,
                qualifier=None,
                is_main_repo=True)
        self.job_variant._main_repository_name = test_repo_logical_name

        self.job_variant._traits_dict = {}
        self.cfg_set = MagicMock()
        self.github_cfg = MagicMock()
        self.github_cfg.name = MagicMock(return_value='github_cfg')
        self.email_cfg = MagicMock()
        self.email_cfg.name = MagicMock(return_value='email_cfg')
        self.cfg_set.github = MagicMock(return_value=self.github_cfg)
        self.cfg_set.email = MagicMock(return_value=self.email_cfg)
        ctx_repo_mock = MagicMock(return_value='repo_url')
        ctx_repo_mock.base_url = MagicMock(return_value='repo_url')
        self.cfg_set.ctx_repository = MagicMock(return_value=ctx_repo_mock)

        self.render_step = step_def('notification')

        self.old_cwd = os.getcwd()
        os.chdir(self.tmp_dir.name)
コード例 #2
0
    def create_pipeline_definition(self) -> PipelineDefinition:
        merged_variants_dict = self._create_variants_dict(
            self.raw_definition_descriptor)

        resource_registry = ResourceRegistry()
        variants = {}

        for variant_name, variant_dict in merged_variants_dict.items():
            variant = self._create_variant(
                raw_dict=variant_dict,
                variant_name=variant_name,
                resource_registry=resource_registry,
            )
            self._apply_traits(variant)

            # collect repositories
            for repo in chain(variant._repos_dict.values(),
                              variant._publish_repos_dict.values()):
                if repo in resource_registry:
                    existing_repo = resource_registry.resource(repo)
                    # hack: patch-in should-trigger (the proper way to implement this
                    # would be to separate (effective) resource-definitions from additional
                    # resource-specialisations as contained in variants
                    existing_repo._trigger |= repo.should_trigger()
                else:
                    resource_registry.add_resource(deepcopy(repo),
                                                   discard_duplicates=False)

            variants[variant_name] = variant

            # add meta resources
            meta_resource_identifier = ResourceIdentifier(
                type_name='meta', base_name=variant_name)
            meta_resource = Resource(
                resource_identifier=meta_resource_identifier, raw_dict={})
            resource_registry.add_resource(meta_resource)

        pipeline_definition = PipelineDefinition()
        pipeline_definition._variants_dict = variants
        pipeline_definition._resource_registry = resource_registry

        validator = PipelineDefinitionValidator(
            pipeline_definition=pipeline_definition)
        validator.validate()

        return pipeline_definition
コード例 #3
0
ファイル: job.py プロジェクト: enrico-kaack-comp/cc-utils
 def meta_resource_name(self):
     meta_res = self._resource_registry.resource(
         ResourceIdentifier(type_name='meta', base_name=self.variant_name)
     )
     return meta_res.resource_identifier().name()