Skip to content

Commit

Permalink
consolidate unique_tag_only and scratch config
Browse files Browse the repository at this point in the history
Signed-off-by: Luiz Carvalho <lucarval@redhat.com>
  • Loading branch information
lcarva committed Mar 14, 2017
1 parent ccb158c commit 87a22d3
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 118 deletions.
1 change: 0 additions & 1 deletion osbs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ def _do_create_prod_build(self, git_uri, git_ref,
nfs_dest_dir=self.build_conf.get_nfs_destination_dir(),
builder_build_json_dir=self.build_conf.get_builder_build_json_store(),
scratch=self.build_conf.get_scratch(scratch),
unique_tag_only=self.build_conf.get_unique_tag_only(),
reactor_config_secret=self.build_conf.get_reactor_config_secret(),
client_config_secret=self.build_conf.get_client_config_secret(),
token_secrets=self.build_conf.get_token_secrets(),
Expand Down
22 changes: 6 additions & 16 deletions osbs/build/build_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,18 +281,6 @@ def render_store_metadata_in_osv3(self, use_auth=None):
"store_metadata_in_osv3",
"use_auth", use_auth)

def render_unique_tag_only(self):

if not self.spec.unique_tag_only.value:
return

if self.dj.dock_json_has_plugin_conf('postbuild_plugins',
'tag_by_labels'):
self.dj.dock_json_set_arg('postbuild_plugins', 'tag_by_labels',
'unique_tag_only', True)

self.dj.remove_plugin('postbuild_plugins', 'tag_from_config')

def set_secret_for_plugin(self, secret, plugin=None, mount_path=None):
"""
Sets secret for plugin, if no plugin specified
Expand Down Expand Up @@ -464,16 +452,20 @@ def adjust_for_scratch(self):
order to hadle the "scratch build" scenario
"""
if self.scratch:
# Note: only one for now, but left in a list like other adjust_for_
# functions in the event that this needs to be expanded
for when, which in [
("postbuild_plugins", "compress"),
("postbuild_plugins", "tag_from_config"),
("exit_plugins", "koji_promote"),
]:
logger.info("removing %s from scratch build request",
which)
self.dj.remove_plugin(when, which)

if self.dj.dock_json_has_plugin_conf('postbuild_plugins',
'tag_by_labels'):
self.dj.dock_json_set_arg('postbuild_plugins', 'tag_by_labels',
'unique_tag_only', True)

def adjust_for_custom_base_image(self):
"""
Disable plugins to handle builds depending on whether
Expand Down Expand Up @@ -860,8 +852,6 @@ def render(self, validate=True):

self.render_tag_and_push_registries()

self.render_unique_tag_only()

if 'triggers' in self.template['spec']:
imagechange = self.template['spec']['triggers'][0]['imageChange']
imagechange['from']['name'] = self.spec.trigger_imagestreamtag.value
Expand Down
4 changes: 1 addition & 3 deletions osbs/build/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ class BuildSpec(object):
nfs_server_path = BuildParam("nfs_server_path", allow_none=True)
nfs_dest_dir = BuildParam("nfs_dest_dir", allow_none=True)
builder_build_json_dir = BuildParam("builder_build_json_dir", allow_none=True)
unique_tag_only = BuildParam("unique_tag_only", allow_none=True)
platform = BuildParam("platform", allow_none=True)
platforms = BuildParam("platforms", allow_none=True)
release = BuildParam("release", allow_none=True)
Expand Down Expand Up @@ -210,7 +209,7 @@ def set_params(self, git_uri=None, git_ref=None,
nfs_dest_dir=None, git_branch=None, base_image=None,
name_label=None,
builder_build_json_dir=None, registry_api_versions=None,
unique_tag_only=None, platform=None, platforms=None, release=None,
platform=None, platforms=None, release=None,
reactor_config_secret=None, client_config_secret=None,
token_secrets=None, arrangement_version=None,
**kwargs):
Expand Down Expand Up @@ -295,7 +294,6 @@ def set_params(self, git_uri=None, git_ref=None,
timestamp
)

self.unique_tag_only.value = unique_tag_only
self.platform.value = platform
self.platforms.value = platforms
self.release.value = release
Expand Down
4 changes: 0 additions & 4 deletions osbs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,6 @@ def get_scratch(self, default_value):
return self._get_value("scratch", self.conf_section, "scratch",
default=default_value, is_bool_val=True)

def get_unique_tag_only(self):
return self._get_value("unique_tag_only", self.conf_section, "unique_tag_only",
default=False, is_bool_val=True)

def get_oauth2_token(self):
# token overrides token_file
# either in kwargs overrides cli args
Expand Down
43 changes: 8 additions & 35 deletions tests/build_/test_build_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,12 +876,20 @@ def test_render_prod_request_v1_v2(self, registry_api_versions, scratch):
with pytest.raises(NoSuchPluginException):
get_plugin(plugins, "postbuild_plugins", "compress")

with pytest.raises(NoSuchPluginException):
get_plugin(plugins, "postbuild_plugins", "tag_from_config")

with pytest.raises(NoSuchPluginException):
get_plugin(plugins, "exit_plugins", "koji_promote")

else:
assert get_plugin(plugins, "postbuild_plugins", "compress")
assert get_plugin(plugins, "postbuild_plugins", "tag_from_config")
assert get_plugin(plugins, "exit_plugins", "koji_promote")

assert (get_plugin(plugins, "postbuild_plugins", "tag_by_labels")
.get('args', {}).get('unique_tag_only', False) == scratch)

def test_render_with_yum_repourls(self):
kwargs = {
'git_uri': TEST_GIT_URI,
Expand Down Expand Up @@ -1077,41 +1085,6 @@ def test_render_orchestrate_build(self, platforms, secret, disabled,
'build_kwargs')
assert build_kwargs['arrangement_version'] == arrangement_version

@pytest.mark.parametrize('unique_tag_only', [False, None, True])
def test_render_unique_tag_only(self, unique_tag_only):
kwargs = {
'git_uri': TEST_GIT_URI,
'git_ref': TEST_GIT_REF,
'user': "john-foo",
'component': TEST_COMPONENT,
'base_image': 'fedora:latest',
'name_label': 'fedora/resultingimage',
'openshift_uri': "http://openshift/",
'registry_api_versions': ['v1', 'v2'],
}

if unique_tag_only is not None:
kwargs['unique_tag_only'] = unique_tag_only

build_request = BuildRequest(INPUTS_PATH)
build_request.set_params(**kwargs)
build_json = build_request.render()
strategy = build_json['spec']['strategy']['customStrategy']['env']
plugins = get_plugins_from_build_json(build_json)

if unique_tag_only:
assert plugin_value_get(plugins,
'postbuild_plugins',
'tag_by_labels',
'args',
'unique_tag_only') == True
assert not has_plugin(plugins, 'postbuild_plugins', 'tag_from_config')
else:
tag_and_push_args = get_plugin(plugins,
'postbuild_plugins',
'tag_and_push')['args']
assert 'unique_tag_only' not in tag_and_push_args
assert has_plugin(plugins, 'postbuild_plugins', 'tag_from_config')

def test_render_prod_with_pulp_no_auth(self):
"""
Expand Down
24 changes: 0 additions & 24 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,30 +418,6 @@ def test_create_orchestrator_build_invalid_arrangement_version(self, osbs):

assert 'arrangement_version' in ex.value.message

@pytest.mark.parametrize('unique_tag_only', [True, False, None])
def test_create_prod_build_unique_tag_only(self, osbs, unique_tag_only):
(flexmock(utils)
.should_receive('get_df_parser')
.with_args(TEST_GIT_URI, TEST_GIT_REF, git_branch=TEST_GIT_BRANCH)
.and_return(MockDfParser()))

original_create_build_config_and_build = osbs._create_build_config_and_build
def check_build_request(build_request):
assert build_request.spec.unique_tag_only.value == unique_tag_only
return original_create_build_config_and_build(build_request)

(flexmock(osbs)
.should_receive('_create_build_config_and_build')
.replace_with(check_build_request)
.once())
(flexmock(osbs.build_conf)
.should_receive('get_unique_tag_only')
.and_return(unique_tag_only))
response = osbs.create_prod_build(TEST_GIT_URI, TEST_GIT_REF,
TEST_GIT_BRANCH, TEST_USER,
TEST_COMPONENT, TEST_TARGET, TEST_ARCH)
assert isinstance(response, BuildResponse)

def test_create_prod_build_missing_name_label(self, osbs):
class MockParser(object):
labels = {}
Expand Down
35 changes: 0 additions & 35 deletions tests/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,41 +202,6 @@ def test_oauth2_token(self, config, kwargs, cli_args, login, expected):
assert conf.get_oauth2_token() == expected

@pytest.mark.parametrize(('config', 'kwargs', 'cli_args', 'expected'), [
({'default': {}},
{},
{},
{'get_unique_tag_only': False}),
({'default': {'unique_tag_only': 'true'}},
{},
{},
{'get_unique_tag_only': True}),
({'default': {}},
{'unique_tag_only': 'true'},
{},
{'get_unique_tag_only': True}),
({'default': {}},
{},
{'unique_tag_only': 'true'},
{'get_unique_tag_only': True}),
({'default': {'unique_tag_only': 'false'}},
{},
{},
{'get_unique_tag_only': False}),
({'default': {}},
{'unique_tag_only': 'false'},
{},
{'get_unique_tag_only': False}),
({'default': {}},
{},
{'unique_tag_only': 'false'},
{'get_unique_tag_only': False}),
({'default': {'client_config_secret': 'client_secret'}},
{},
{},
Expand Down

0 comments on commit 87a22d3

Please sign in to comment.