def test_create_prod_build_missing_name_label(self, osbs): class MockParser(object): labels = {} baseimage = 'fedora23/python' (flexmock(utils) .should_receive('get_df_parser') .with_args(TEST_GIT_URI, TEST_GIT_REF, git_branch=TEST_GIT_BRANCH) .and_return(MockParser())) with pytest.raises(OsbsValidationException): osbs.create_prod_build(TEST_GIT_URI, TEST_GIT_REF, TEST_GIT_BRANCH, TEST_USER, TEST_COMPONENT, TEST_TARGET, TEST_ARCH)
def test_create_prod_build_missing_name_label(self, osbs): class MockParser(object): labels = {} baseimage = 'fedora23/python' (flexmock(utils).should_receive('get_df_parser').with_args( TEST_GIT_URI, TEST_GIT_REF, git_branch=TEST_GIT_BRANCH).and_return(MockParser())) with pytest.raises(OsbsValidationException): osbs.create_prod_build(TEST_GIT_URI, TEST_GIT_REF, TEST_GIT_BRANCH, TEST_USER, TEST_COMPONENT, TEST_TARGET, TEST_ARCH)
def test_explicit_labels(self, osbs): class MockParser(object): labels = {'Name': 'fedora23/something'} baseimage = 'fedora23/python' (flexmock(utils).should_receive('get_df_parser').with_args( TEST_GIT_URI, TEST_GIT_REF, git_branch=TEST_GIT_BRANCH).and_return(MockParser())) flexmock(OSBS, _create_build_config_and_build=request_as_response) key = 'Release' value = '4' req = osbs.create_prod_build(TEST_GIT_URI, TEST_GIT_REF, TEST_GIT_BRANCH, TEST_USER, TEST_COMPONENT, TEST_TARGET, TEST_ARCH, labels={key: value}) env_vars = req.json['spec']['strategy']['customStrategy']['env'] plugins_var = [ env_var for env_var in env_vars if env_var['name'] == 'ATOMIC_REACTOR_PLUGINS' ] plugins = json.loads(plugins_var[0]['value']) add = [ plugin for plugin in plugins['prebuild_plugins'] if plugin['name'] == 'add_labels_in_dockerfile' ] add_labels = add[0]['args']['labels'] assert add_labels[key] == value
def test_explicit_labels(self, osbs): class MockParser(object): labels = {'Name': 'fedora23/something'} baseimage = 'fedora23/python' (flexmock(utils) .should_receive('get_df_parser') .with_args(TEST_GIT_URI, TEST_GIT_REF, git_branch=TEST_GIT_BRANCH) .and_return(MockParser())) flexmock(OSBS, _create_build_config_and_build=request_as_response) key = 'Release' value = '4' req = osbs.create_prod_build(TEST_GIT_URI, TEST_GIT_REF, TEST_GIT_BRANCH, TEST_USER, TEST_COMPONENT, TEST_TARGET, TEST_ARCH, labels={key: value}) env_vars = req.json['spec']['strategy']['customStrategy']['env'] plugins_var = [env_var for env_var in env_vars if env_var['name'] == 'ATOMIC_REACTOR_PLUGINS'] plugins = json.loads(plugins_var[0]['value']) add = [plugin for plugin in plugins['prebuild_plugins'] if plugin['name'] == 'add_labels_in_dockerfile'] add_labels = add[0]['args']['labels'] assert add_labels[key] == value
def test_create_prod_build(self, osbs): # TODO: test situation when a buildconfig already exists class MockParser(object): labels = {'Name': 'fedora23/something'} baseimage = 'fedora23/python' (flexmock(utils) .should_receive('get_df_parser') .with_args(TEST_GIT_URI, TEST_GIT_REF, git_branch=TEST_GIT_BRANCH) .and_return(MockParser())) 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(self, osbs): # TODO: test situation when a buildconfig already exists class MockParser(object): labels = {'Name': 'fedora23/something'} baseimage = 'fedora23/python' (flexmock(utils).should_receive('get_df_parser').with_args( TEST_GIT_URI, TEST_GIT_REF, git_branch=TEST_GIT_BRANCH).and_return(MockParser())) 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_build_image(self): build_image = 'registry.example.com/buildroot:2.0' with NamedTemporaryFile(mode='wt') as fp: fp.write(""" [general] build_json_dir = {build_json_dir} [default] openshift_url = / sources_command = /bin/true vendor = Example, Inc registry_uri = registry.example.com build_host = localhost authoritative_registry = localhost distribution_scope = private build_type = prod build_image = {build_image} """.format(build_json_dir='inputs', build_image=build_image)) fp.flush() config = Configuration(fp.name) osbs = OSBS(config, config) assert config.get_build_image() == build_image class MockParser(object): labels = {'Name': 'fedora23/something'} baseimage = 'fedora23/python' (flexmock(utils) .should_receive('get_df_parser') .with_args(TEST_GIT_URI, TEST_GIT_REF, git_branch=TEST_GIT_BRANCH) .and_return(MockParser())) # Return the request as the response so we can check it def request_as_response(request): request.json = request.render() return request flexmock(OSBS, _create_build_config_and_build=request_as_response) req = osbs.create_prod_build(TEST_GIT_URI, TEST_GIT_REF, TEST_GIT_BRANCH, TEST_USER, TEST_COMPONENT, TEST_TARGET, TEST_ARCH) img = req.json['spec']['strategy']['customStrategy']['from']['name'] assert img == build_image
def test_build_image(self): build_image = 'registry.example.com/buildroot:2.0' with NamedTemporaryFile(mode='wt') as fp: fp.write(""" [general] build_json_dir = {build_json_dir} [default] openshift_url = / sources_command = /bin/true vendor = Example, Inc registry_uri = registry.example.com build_host = localhost authoritative_registry = localhost distribution_scope = private build_type = prod build_image = {build_image} """.format(build_json_dir='inputs', build_image=build_image)) fp.flush() config = Configuration(fp.name) osbs = OSBS(config, config) assert config.get_build_image() == build_image class MockParser(object): labels = {'Name': 'fedora23/something'} baseimage = 'fedora23/python' (flexmock(utils).should_receive('get_df_parser').with_args( TEST_GIT_URI, TEST_GIT_REF, git_branch=TEST_GIT_BRANCH).and_return(MockParser())) # Return the request as the response so we can check it def request_as_response(request): request.json = request.render() return request flexmock(OSBS, _create_build_config_and_build=request_as_response) req = osbs.create_prod_build(TEST_GIT_URI, TEST_GIT_REF, TEST_GIT_BRANCH, TEST_USER, TEST_COMPONENT, TEST_TARGET, TEST_ARCH) img = req.json['spec']['strategy']['customStrategy']['from']['name'] assert img == build_image
def test_create_prod_build_unique_tag_only(self, osbs, unique_tag_only): class MockParser(object): labels = {'Name': 'fedora23/something'} baseimage = 'fedora23/python' (flexmock(utils).should_receive('get_df_parser').with_args( TEST_GIT_URI, TEST_GIT_REF, git_branch=TEST_GIT_BRANCH).and_return(MockParser())) 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)