Skip to content

Commit

Permalink
Also check release label aliases for autorebuild
Browse files Browse the repository at this point in the history
Signed-off-by: Luiz Carvalho <lucarval@redhat.com>
  • Loading branch information
lcarva committed Jul 25, 2017
1 parent ab62455 commit 8214e82
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
15 changes: 11 additions & 4 deletions osbs/build/build_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from osbs.constants import (SECRETS_PATH, DEFAULT_OUTER_TEMPLATE, DEFAULT_INNER_TEMPLATE,
DEFAULT_CUSTOMIZE_CONF)
from osbs.exceptions import OsbsException, OsbsValidationException
from osbs.utils import git_repo_humanish_part_from_uri, sanitize_version
from osbs.utils import git_repo_humanish_part_from_uri, sanitize_version, Labels
from osbs import __version__ as client_version


Expand Down Expand Up @@ -572,9 +572,16 @@ def adjust_for_repo_info(self):
logger.info('autorebuild is disabled in repo configuration, removing triggers')
self.template['spec'].pop('triggers', None)

elif 'release' in self._repo_info.dockerfile_parser.labels:
raise RuntimeError('when autorebuild is enabled in repo configuration, '
'"release" label must not be set in Dockerfile')
else:
labels = Labels(self._repo_info.dockerfile_parser.labels)
try:
labels.get_name_and_value(Labels.LABEL_TYPE_RELEASE)
except KeyError:
# As expected, release label not set in Dockerfile
pass
else:
raise RuntimeError('when autorebuild is enabled in repo configuration, '
'"release" label must not be set in Dockerfile')

def render_add_filesystem(self):
phase = 'prebuild_plugins'
Expand Down
14 changes: 8 additions & 6 deletions tests/build_/test_build_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -1650,17 +1650,19 @@ def test_render_custom_base_image_with_trigger(self, tmpdir, registry_uri,
use_auth=use_auth,
insecure_registry=insecure_registry)

@pytest.mark.parametrize(('autorebuild_enabled', 'set_release', 'expected'), (
(True, False, True),
(True, True, RuntimeError),
(False, True, False),
@pytest.mark.parametrize(('autorebuild_enabled', 'release_label', 'expected'), (
(True, None, True),
(True, 'release', RuntimeError),
(True, 'Release', RuntimeError),
(False, 'release', False),
(False, 'Release', False),
))
def test_render_prod_request_with_repo_info(self, tmpdir, autorebuild_enabled, set_release,
def test_render_prod_request_with_repo_info(self, tmpdir, autorebuild_enabled, release_label,
expected):
self.create_image_change_trigger_json(str(tmpdir))

class MockDfParser(object):
labels = {'release': '13'} if set_release else {}
labels = {release_label: '13'} if release_label else {}

(flexmock(RepoConfiguration)
.should_receive('is_autorebuild_enabled')
Expand Down

0 comments on commit 8214e82

Please sign in to comment.