Skip to content

Commit

Permalink
Remove platform from scratch build name
Browse files Browse the repository at this point in the history
Signed-off-by: Luiz Carvalho <lucarval@redhat.com>
  • Loading branch information
lcarva committed Aug 4, 2017
1 parent cf9d12a commit e3be0f7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
6 changes: 0 additions & 6 deletions osbs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,6 @@ def _create_scratch_build(self, build_request):
builder_img['kind'] = 'DockerImage'
builder_img['name'] = ref

output_image_name = build_json['spec']['output']['to']['name']
# Reuse random string and timestamp values.
build_config_name = 'scratch-%s-%s' % tuple(
output_image_name.rsplit('-', 2)[-2:])
logger.debug('starting scratch build %s', build_config_name)
build_json['metadata']['name'] = build_config_name
return BuildResponse(self.os.create_build(build_json).json())

def _get_image_stream_info_for_build_request(self, build_request):
Expand Down
25 changes: 22 additions & 3 deletions osbs/build/build_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,15 +1138,34 @@ def render_customizations(self):
def render_version(self):
self.dj.dock_json_set_param('client_version', client_version)

def render_name(self):
"""Sets the Build/BuildConfig object name"""
name = self.spec.name.value

if self.scratch:
name = self.spec.image_tag.value
platform = self.spec.platform.value
# Platform name may contain characters not allowed by OpenShift.
if platform:
platform_suffix = '-{0}'.format(platform)
if name.endswith(platform_suffix):
name = name[:-len(platform_suffix)]

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

name = 'scratch-{0}-{1}'.format(salt, timestamp)

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

def render(self, validate=True):
if validate:
self.spec.validate()

self.render_customizations()

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

self.template['spec']['source']['git']['uri'] = self.spec.git_uri.value
self.template['spec']['source']['git']['ref'] = self.spec.git_ref.value

Expand Down
12 changes: 9 additions & 3 deletions tests/build_/test_build_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from tests.constants import (INPUTS_PATH, TEST_BUILD_CONFIG, TEST_BUILD_JSON,
TEST_COMPONENT, TEST_GIT_BRANCH, TEST_GIT_REF,
TEST_GIT_URI, TEST_GIT_URI_HUMAN_NAME,
TEST_FILESYSTEM_KOJI_TASK_ID)
TEST_FILESYSTEM_KOJI_TASK_ID, TEST_SCRATCH_BUILD_NAME)

USE_DEFAULT_TRIGGERS = object()

Expand Down Expand Up @@ -923,8 +923,11 @@ def test_render_prod_request_requires_newer(self):
['v1', 'v2'],
['v2'],
])
@pytest.mark.parametrize('platform', [None, 'x86_64'])
@pytest.mark.parametrize('arrangement_version', [3, 4])
@pytest.mark.parametrize('scratch', [False, True])
def test_render_prod_request_v1_v2(self, registry_api_versions, scratch):
def test_render_prod_request_v1_v2(self, registry_api_versions, platform, arrangement_version,
scratch):
build_request = BuildRequest(INPUTS_PATH)
name_label = "fedora/resultingimage"
pulp_env = 'v1pulp'
Expand Down Expand Up @@ -966,11 +969,14 @@ def test_render_prod_request_v1_v2(self, registry_api_versions, scratch):
'distribution_scope': "authoritative-source-only",
'registry_api_versions': registry_api_versions,
'scratch': scratch,
'platform': platform,
'arrangement_version': arrangement_version,
})
build_request.set_params(**kwargs)
build_json = build_request.render()

assert fnmatch.fnmatch(build_json["metadata"]["name"], TEST_BUILD_CONFIG)
expected_name = TEST_SCRATCH_BUILD_NAME if scratch else TEST_BUILD_CONFIG
assert fnmatch.fnmatch(build_json["metadata"]["name"], expected_name)
assert "triggers" not in build_json["spec"]
assert build_json["spec"]["source"]["git"]["uri"] == TEST_GIT_URI
assert build_json["spec"]["source"]["git"]["ref"] == TEST_GIT_REF
Expand Down
1 change: 1 addition & 0 deletions tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
TEST_BUILD = "test-build-123"
TEST_CANCELLED_BUILD = "test-build-cancel-123"
TEST_BUILD_CONFIG = "path-master-?????"
TEST_SCRATCH_BUILD_NAME = "scratch-?????-??????????????"
TEST_IMAGESTREAM = "test_imagestream"
TEST_GIT_URI = "git://hostname/path"
TEST_GIT_URI_HUMAN_NAME = "path"
Expand Down
3 changes: 1 addition & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,7 @@ def test_scratch_build_config(self, kind, expect_name):
'git-repo-name': 'reponame',
'git-branch': 'branch',
},
'name': 'scratch-12345-20001010112233'
},

'spec': {
Expand Down Expand Up @@ -1574,8 +1575,6 @@ def test_scratch_build_config(self, kind, expect_name):
img = updated_build_json['spec']['strategy']['customStrategy']['from']
img['kind'] = 'DockerImage'
img['name'] = expect_name
updated_build_json['metadata']['name'] = 'scratch-%s' % (
build_json['spec']['output']['to']['name'][-20:])

if kind == 'ImageStreamTag':
(flexmock(osbs_obj.os)
Expand Down

0 comments on commit e3be0f7

Please sign in to comment.