示例#1
0
def source_container_user_params(extra_args=None):
    sample_params = get_sample_source_container_params()
    if extra_args:
        sample_params.update(extra_args)
    user_params = SourceContainerUserParams(INPUTS_PATH)
    user_params.set_params(**sample_params)
    return user_params
示例#2
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)
示例#3
0
 def __init__(self, build_json_store, outer_template=None):
     """
     :param build_json_store: str, path to directory with JSON build files
     :param outer_template: str, path to outer template JSON
     """
     super(SourceBuildRequest, self).__init__(
         build_json_store,
         outer_template=outer_template or DEFAULT_SOURCES_OUTER_TEMPLATE
     )
     self.user_params = SourceContainerUserParams(self.build_json_store)
示例#4
0
class SourceBuildRequest(BaseBuildRequest):
    """Build request for source containers"""
    def __init__(self, build_json_store, outer_template=None):
        """
        :param build_json_store: str, path to directory with JSON build files
        :param outer_template: str, path to outer template JSON
        """
        super(SourceBuildRequest, self).__init__(
            build_json_store,
            outer_template=outer_template or DEFAULT_SOURCES_OUTER_TEMPLATE
        )
        self.user_params = SourceContainerUserParams(self.build_json_store)

    def render(self, validate=True):
        return super(SourceBuildRequest, self).render(validate=validate)

    def render_name(self):
        """Sets the Build/BuildConfig object name

        Source container builds must have unique names, because we are not
        using buildConfigs just regular builds
        """
        name = self.user_params.image_tag.value

        _, salt, timestamp = name.rsplit('-', 2)

        name = 'sources-{}-{}'.format(salt, timestamp)
        if self.scratch:
            name = 'scratch-{}'.format(name)

        # !IMPORTANT! can't be too long: https://github.com/openshift/origin/issues/733
        self.template['metadata']['name'] = name

    def set_params(self, **kwargs):
        super(SourceBuildRequest, self).set_params(**kwargs)

        logger.debug("now setting params '%s' for user_params", kwargs)
        self.user_params.set_params(**kwargs)
示例#5
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
示例#6
0
 def __init__(self, osbs_api, outer_template=None, user_params=None):
     """
     :param build_json_store: str, path to directory with JSON build files
     :param outer_template: str, path to outer template JSON
     """
     if user_params:
         assert isinstance(user_params, SourceContainerUserParams)
     else:
         user_params = SourceContainerUserParams()
     super(SourceBuildRequest, self).__init__(
         osbs_api,
         outer_template=outer_template or DEFAULT_SOURCES_OUTER_TEMPLATE,
         user_params=user_params,
     )
示例#7
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
示例#8
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
示例#9
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)
示例#10
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)