예제 #1
0
 def test_validate_missing_required(self):
     """Missing 'sources_for_koji_build_id' and
     `sources_for_koji_build_nvr` params"""
     kwargs = {
         "build_from": "image:buildroot:latest",
         'user': TEST_USER,
     }
     with pytest.raises(OsbsValidationException):
         SourceContainerUserParams.make_params(**kwargs)
예제 #2
0
    def create_source_container_pipeline_run(self,
                                             component=None,
                                             koji_task_id=None,
                                             target=None,
                                             **kwargs):
        """
        Take input args, create source pipeline run

        :return: instance of PiplelineRun
        """
        error_messages = []
        # most likely can be removed, source build should get component name
        # from binary build OSBS2 TBD
        if not component:
            error_messages.append(
                "required argument 'component' can't be empty")
        if error_messages:
            raise OsbsValidationException(", ".join(error_messages))

        pipeline_run_name, pipeline_run_data = self._get_source_container_pipeline_data(
        )

        build_json_store = self.os_conf.get_build_json_store()
        user_params = SourceContainerUserParams.make_params(
            build_json_dir=build_json_store,
            build_conf=self.os_conf,
            component=component,
            koji_target=target,
            koji_task_id=koji_task_id,
            pipeline_run_name=pipeline_run_name,
            **kwargs)

        self._set_source_container_pipeline_data(pipeline_run_name,
                                                 pipeline_run_data,
                                                 user_params)

        logger.info("creating source container image pipeline run: %s",
                    pipeline_run_name)

        pipeline_run = PipelineRun(self.os, pipeline_run_name,
                                   pipeline_run_data)

        try:
            logger.info("pipeline run created: %s",
                        pipeline_run.start_pipeline_run())
        except OsbsResponseException:
            logger.error("failed to create pipeline run %s", pipeline_run_name)
            raise

        return pipeline_run
예제 #3
0
 def get_plugins_from_buildrequest(self, build_request, template):
     conf_args = {
         "build_from": "image:buildroot:latest",
         'orchestrator_max_run_hours': 5,
         'reactor_config_map': 'reactor-config-map-scratch',
         'scratch': True,
         'worker_max_run_hours': 3,
     }
     param_kwargs = {
         'build_json_dir': INPUTS_PATH,
         'build_conf': Configuration(**conf_args),
         'user': TEST_USER,
         'component': TEST_COMPONENT,
         "koji_target": "tothepoint",
         "platform": "x86_64",
         "signing_intent": "test-signing-intent",
         'sources_for_koji_build_nvr': TEST_KOJI_BUILD_NVR,
         'kind': USER_PARAMS_KIND_SOURCE_CONTAINER_BUILDS,
     }
     user_params = SourceContainerUserParams.make_params(**param_kwargs)
     build_request.set_params(user_params)
     return SourceContainerPluginsConfiguration(build_request.user_params).pt.template
예제 #4
0
def source_container_user_params(build_args=None, extra_args=None):
    sample_params = get_sample_source_container_params(build_args, extra_args)
    user_params = SourceContainerUserParams.make_params(**sample_params)
    return user_params
예제 #5
0
    def test_all_values_and_json(self, origin_nvr, origin_id):
        conf_args = {
            "build_from": "image:buildroot:latest",
            'orchestrator_max_run_hours': 5,
            'reactor_config_map': 'reactor-config-map-scratch',
            'scratch': True,
            'worker_max_run_hours': 3,
        }
        param_kwargs = self.get_minimal_kwargs(origin_nvr, conf_args=conf_args)
        param_kwargs.update({
            'component': TEST_COMPONENT,
            "koji_target": "tothepoint",
            "platform": "x86_64",
            "signing_intent": "test-signing-intent",
            "sources_for_koji_build_id": origin_id,
        })

        rand = '12345'
        timestr = '20170731111111'
        (flexmock(sys.modules['osbs.build.user_params']).should_receive(
            'utcnow').once().and_return(
                datetime.datetime.strptime(timestr, '%Y%m%d%H%M%S')))

        (flexmock(random).should_receive('randrange').once().with_args(
            10**(len(rand) - 1), 10**len(rand)).and_return(int(rand)))

        spec = SourceContainerUserParams.make_params(**param_kwargs)

        expected_json = {
            "arrangement_version":
            REACTOR_CONFIG_ARRANGEMENT_VERSION,
            "build_from":
            "image:buildroot:latest",
            "build_image":
            "buildroot:latest",
            "build_json_dir":
            INPUTS_PATH,
            'component':
            TEST_COMPONENT,
            "image_tag":
            "{}/{}:tothepoint-{}-{}-x86_64".format(TEST_USER, TEST_COMPONENT,
                                                   rand, timestr),
            "kind":
            "source_containers_user_params",
            "signing_intent":
            "test-signing-intent",
            "sources_for_koji_build_nvr":
            origin_nvr,
            "koji_target":
            "tothepoint",
            "orchestrator_deadline":
            5,
            "platform":
            "x86_64",
            'reactor_config_map':
            'reactor-config-map-scratch',
            'scratch':
            True,
            "user":
            TEST_USER,
            "worker_deadline":
            3,
        }
        if origin_id:
            expected_json['sources_for_koji_build_id'] = origin_id
        assert spec.to_json() == json.dumps(expected_json, sort_keys=True)

        spec2 = SourceContainerUserParams.from_json(spec.to_json())
        assert spec2.to_json() == json.dumps(expected_json, sort_keys=True)
예제 #6
0
    def test_all_values_and_json(self, scratch, origin_nvr, origin_id):
        conf_args = {
            'namespace': TEST_OCP_NAMESPACE,
            'reactor_config_map_scratch': 'reactor-config-map-scratch',
            'reactor_config_map': 'reactor-config-map',
            'scratch': scratch,
        }
        userdata = {'custom': 'userdata'}
        param_kwargs = self.get_minimal_kwargs(origin_nvr, conf_args=conf_args)
        param_kwargs.update({
            'component': TEST_COMPONENT,
            "koji_target": "tothepoint",
            "platform": "x86_64",
            "signing_intent": "test-signing-intent",
            "sources_for_koji_build_id": origin_id,
            "userdata": userdata,
        })

        rand = '12345'
        timestr = '20170731111111'
        (flexmock(sys.modules['osbs.build.user_params']).should_receive(
            'utcnow').once().and_return(
                datetime.datetime.strptime(timestr, '%Y%m%d%H%M%S')))

        (flexmock(random).should_receive('randrange').once().with_args(
            10**(len(rand) - 1), 10**len(rand)).and_return(int(rand)))

        spec = SourceContainerUserParams.make_params(**param_kwargs)

        expected_json = {
            "build_json_dir":
            INPUTS_PATH,
            'component':
            TEST_COMPONENT,
            "image_tag":
            "{}/{}:tothepoint-{}-{}-x86_64".format(TEST_USER, TEST_COMPONENT,
                                                   rand, timestr),
            "kind":
            "source_containers_user_params",
            "signing_intent":
            "test-signing-intent",
            "sources_for_koji_build_nvr":
            origin_nvr,
            "koji_target":
            "tothepoint",
            "namespace":
            TEST_OCP_NAMESPACE,
            "platform":
            "x86_64",
            'reactor_config_map':
            'reactor-config-map',
            "user":
            TEST_USER,
            "userdata":
            userdata,
        }
        if scratch:
            expected_json['reactor_config_map'] = 'reactor-config-map-scratch'
            expected_json['scratch'] = scratch

        if origin_id:
            expected_json['sources_for_koji_build_id'] = origin_id

        assert spec.to_json() == json.dumps(expected_json, sort_keys=True)

        spec2 = SourceContainerUserParams.from_json(spec.to_json())
        assert spec2.to_json() == json.dumps(expected_json, sort_keys=True)