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
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, } spec = SourceContainerUserParams() with pytest.raises(OsbsValidationException): spec.set_params(**kwargs)
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)
def test_all_values_and_json(self, origin_nvr, origin_id): param_kwargs = self.get_minimal_kwargs(origin_nvr) param_kwargs.update({ 'component': TEST_COMPONENT, "koji_target": "tothepoint", "orchestrator_deadline": 5, "platform": "x86_64", 'scratch': True, "signing_intent": "test-signing-intent", "worker_deadline": 3, "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))) build_json_dir = 'inputs' spec = SourceContainerUserParams(build_json_dir) spec.set_params(**param_kwargs) expected_json = { "arrangement_version": REACTOR_CONFIG_ARRANGEMENT_VERSION, "build_image": "buildroot:latest", "build_json_dir": build_json_dir, '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", '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() spec2.from_json(spec.to_json()) assert spec2.to_json() == json.dumps(expected_json, sort_keys=True)
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(INPUTS_PATH) user_params.set_params(**sample_params) return user_params