Skip to content

Commit

Permalink
enforce version label
Browse files Browse the repository at this point in the history
  • Loading branch information
rcerven authored and lcarva committed Mar 6, 2017
1 parent e4bf011 commit d89da32
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 19 deletions.
24 changes: 18 additions & 6 deletions osbs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,22 +438,34 @@ def create_prod_build(self, git_uri, git_ref,
customize_conf=customize_conf)
labels = utils.Labels(df_parser.labels)

try:
_, name_value = labels.get_name_and_value(utils.Labels.LABEL_TYPE_NAME)
_, component = labels.get_name_and_value(utils.Labels.LABEL_TYPE_COMPONENT)
except KeyError:
required_missing = False
req_labels = {}
# version label isn't used here, but is required label in Dockerfile
# and is used and required for atomic reactor
# if we don't catch error here, it will fail in atomic reactor later
for label in [utils.Labels.LABEL_TYPE_NAME,
utils.Labels.LABEL_TYPE_COMPONENT,
utils.Labels.LABEL_TYPE_VERSION]:
try:
_, req_labels[label] = labels.get_name_and_value(label)
except KeyError:
required_missing = True
logger.error("required label missing from Dockerfile : %s",
labels.get_name(label))

if required_missing:
raise OsbsValidationException("required label missing from Dockerfile")

build_request.set_params(
git_uri=git_uri,
git_ref=git_ref,
git_branch=git_branch,
user=user,
component=component,
component=req_labels[utils.Labels.LABEL_TYPE_COMPONENT],
build_image=self.build_conf.get_build_image(),
build_imagestream=self.build_conf.get_build_imagestream(),
base_image=df_parser.baseimage,
name_label=name_value,
name_label=req_labels[utils.Labels.LABEL_TYPE_NAME],
registry_uris=self.build_conf.get_registry_uris(),
registry_secrets=self.build_conf.get_registry_secrets(),
source_registry_uri=self.build_conf.get_source_registry_uri(),
Expand Down
39 changes: 26 additions & 13 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def test_get_pod_for_build(self, osbs):

def test_create_build_with_deprecated_params(self, osbs):
class MockParser(object):
labels = {'Name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT}
labels = {'Name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT,
'version': 'version1.0'}
baseimage = 'fedora23/python'
(flexmock(utils)
.should_receive('get_df_parser')
Expand Down Expand Up @@ -125,7 +126,8 @@ class MockParser(object):
def test_create_prod_build(self, osbs, name_label_name):
# TODO: test situation when a buildconfig already exists
class MockParser(object):
labels = {name_label_name: 'fedora23/something', 'com.redhat.component': TEST_COMPONENT}
labels = {name_label_name: 'fedora23/something', 'com.redhat.component': TEST_COMPONENT,
'version': 'version1.0'}
baseimage = 'fedora23/python'
(flexmock(utils)
.should_receive('get_df_parser')
Expand All @@ -143,7 +145,8 @@ class MockParser(object):
def test_create_prod_build_build_request(self, osbs, inner_template,
outer_template, customize_conf):
class MockParser(object):
labels = {'name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT}
labels = {'name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT,
'version': 'test_version'}
baseimage = 'fedora23/python'

(flexmock(utils)
Expand Down Expand Up @@ -182,7 +185,8 @@ def test_create_worker_build(self, osbs, inner_template, outer_template,
customize_conf, platform, release,
raises_exception):
class MockParser(object):
labels = {'name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT}
labels = {'name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT,
'version' : 'test_version'}
baseimage = 'fedora23/python'

(flexmock(utils)
Expand Down Expand Up @@ -227,7 +231,8 @@ class MockParser(object):
@pytest.mark.parametrize('unique_tag_only', [True, False, None])
def test_create_prod_build_unique_tag_only(self, osbs, unique_tag_only):
class MockParser(object):
labels = {'Name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT}
labels = {'Name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT,
'version': 'version1.0'}
baseimage = 'fedora23/python'
(flexmock(utils)
.should_receive('get_df_parser')
Expand Down Expand Up @@ -319,7 +324,8 @@ def test_component_is_changed_from_label(self, osbs, component_label_name):
"""

class MockParser(object):
labels = {'Name': 'fedora23/something', component_label_name: TEST_COMPONENT}
labels = {'Name': 'fedora23/something', component_label_name: TEST_COMPONENT,
'version': 'version1.0'}
baseimage = 'fedora23/python'
(flexmock(utils)
.should_receive('get_df_parser')
Expand All @@ -334,7 +340,8 @@ class MockParser(object):

def test_missing_component_argument_doesnt_break_build(self, osbs):
class MockParser(object):
labels = {'Name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT}
labels = {'Name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT,
'version': 'version1.0'}
baseimage = 'fedora23/python'
(flexmock(utils)
.should_receive('get_df_parser')
Expand All @@ -346,7 +353,8 @@ class MockParser(object):

def test_create_prod_build_set_required_version(self, osbs106):
class MockParser(object):
labels = {'Name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT}
labels = {'Name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT,
'version': 'version1.0'}
baseimage = 'fedora23/python'
(flexmock(utils)
.should_receive('get_df_parser')
Expand All @@ -364,7 +372,8 @@ class MockParser(object):
def test_create_prod_with_secret_build(self, osbs):
# TODO: test situation when a buildconfig already exists
class MockParser(object):
labels = {'Name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT}
labels = {'Name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT,
'version': 'version1.0'}
baseimage = 'fedora23/python'
(flexmock(utils)
.should_receive('get_df_parser')
Expand All @@ -379,7 +388,8 @@ class MockParser(object):
def test_create_prod_without_koji_build(self, osbs):
# TODO: test situation when a buildconfig already exists
class MockParser(object):
labels = {'Name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT}
labels = {'Name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT,
'version': 'version1.0'}
baseimage = 'fedora23/python'
(flexmock(utils)
.should_receive('get_df_parser')
Expand Down Expand Up @@ -633,7 +643,8 @@ def test_build_image(self):
assert config.get_build_image() == build_image

class MockParser(object):
labels = {'Name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT}
labels = {'Name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT,
'version': 'version1.0'}
baseimage = 'fedora23/python'
(flexmock(utils)
.should_receive('get_df_parser')
Expand Down Expand Up @@ -1217,7 +1228,8 @@ def test_scratch_param_to_create_build(self):
osbs = OSBS(config, config)

class MockParser(object):
labels = {'Name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT}
labels = {'Name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT,
'version': 'version1.0'}
baseimage = 'fedora23/python'

kwargs = {
Expand Down Expand Up @@ -1312,7 +1324,8 @@ def test_reactor_config_secret(self):
osbs = OSBS(config, config)

class MockParser(object):
labels = {'Name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT}
labels = {'Name': 'fedora23/something', 'com.redhat.component': TEST_COMPONENT,
'version' : 'test_version'}
baseimage = 'fedora23/python'
(flexmock(utils)
.should_receive('get_df_parser')
Expand Down

0 comments on commit d89da32

Please sign in to comment.