def test_from_json_continue(self): spec = BuildUserParams() expected_json = { "arrangement_version": REACTOR_CONFIG_ARRANGEMENT_VERSION, "base_image": "buildroot:old", "build_image": "buildroot:latest", "build_json_dir": "build_dir", "build_type": "worker", "component": TEST_COMPONENT, "compose_ids": [1, 2], "customize_conf": "prod_customize.json", "filesystem_koji_task_id": TEST_FILESYSTEM_KOJI_TASK_ID, "git_branch": TEST_GIT_BRANCH, "git_ref": TEST_GIT_REF, "git_uri": TEST_GIT_URI, "image_tag": "latest", "imagestream_name": "name_label", "koji_parent_build": "fedora-26-9", "koji_target": "tothepoint", "name": "path-master-cd1e4", "orchestrator_deadline": 4, "platform": "x86_64", "platforms": ["x86_64"], "reactor_config_map": "reactor-config-map", "reactor_config_override": "reactor-config-override", "release": "29", "trigger_imagestreamtag": "buildroot:old", "this is not a valid key": "this is not a valid field", "user": TEST_USER, "worker_deadline": 3, "triggered_after_koji_task": 12345, } spec.from_json(json.dumps(expected_json))
def test_user_params_bad_json(self): required_json = json.dumps( { 'git_ref': 'master', 'kind': 'build_user_params', }, sort_keys=True) spec = BuildUserParams() spec.from_json(None) assert spec.to_json() == required_json spec.from_json("") assert spec.to_json() == required_json assert '{}'.format(spec)
def test_user_params_bad_json(self): required_json = json.dumps( { 'arrangement_version': 6, 'customize_conf': 'worker_customize.json', 'git_ref': 'master' }, sort_keys=True) spec = BuildUserParams() spec.from_json(None) assert spec.to_json() == required_json spec.from_json("") assert spec.to_json() == required_json assert '{}'.format(spec)
def test_from_json_failure(self, caplog): spec = BuildUserParams() with pytest.raises(ValueError): spec.from_json('{"this is not valid json": }') assert 'failed to convert {"this is not valid json": }' in caplog.text
def test_v2_all_values_and_json(self): repo_conf = RepoConfiguration(git_branch=TEST_GIT_BRANCH, git_ref=TEST_GIT_REF, git_uri=TEST_GIT_URI) repo_info = RepoInfo(configuration=repo_conf) build_conf = Configuration(conf_file=None, build_from='image:buildroot:latest', orchestrator_deadline=4, scratch=False, worker_deadline=3) # all values that BuildUserParams stores param_kwargs = { # 'arrangement_version': self.arrangement_version, # calculated value 'base_image': 'buildroot:old', # 'build_from': 'buildroot:old', # only one of build_* 'build_json_dir': INPUTS_PATH, # 'build_image': 'buildroot:latest', # 'build_imagestream': 'buildroot:name_label', 'build_type': BUILD_TYPE_WORKER, 'component': TEST_COMPONENT, 'compose_ids': [1, 2], 'filesystem_koji_task_id': TEST_FILESYSTEM_KOJI_TASK_ID, 'flatpak': False, # 'flatpak_base_image': self.flatpak_base_image, # not used with false flatpack # 'git_branch': TEST_GIT_BRANCH, # 'git_ref': TEST_GIT_REF, # 'git_uri': TEST_GIT_URI, 'image_tag': 'user/None:none-0-0', # 'imagestream_name': TEST_IMAGESTREAM, 'include_koji_repo': True, 'isolated': False, 'koji_parent_build': 'fedora-26-9', 'koji_target': 'tothepoint', 'operator_bundle_replacement_pullspecs': { 'foo/fedora:30': 'bar/fedora@sha256:deadbeef' }, # "orchestrator_deadline": 4, # set in config 'parent_images_digests': { 'registry.fedorahosted.org/fedora:29': { 'x86_64': 'registry.fedorahosted.org/fedora@sha256:8b96f2f9f88179a065738b2b37' '35e386efb2534438c2a2f45b74358c0f344c81' } }, # 'name': self.name, # calculated value 'platform': 'x86_64', 'platforms': [ 'x86_64', ], # 'reactor_config_map': 'reactor-config-map', # set in config 'reactor_config_override': 'reactor-config-override', 'release': '29', # 'scratch': True, # set in config 'signing_intent': False, 'task_id': TEST_KOJI_TASK_ID, # 'trigger_imagestreamtag': 'base_image:latest', # generated from base_image 'user': TEST_USER, # 'yum_repourls': , # not used with compose_ids # "worker_deadline": 3, # set in config } # additional values that BuildUserParams requires but stores under different names param_kwargs.update({ 'build_conf': build_conf, 'name_label': 'name_label', 'repo_info': repo_info, }) rand = '12345' timestr = '20170731111111' (flexmock(sys.modules['osbs.build.user_params']).should_receive( 'utcnow').once().and_return( datetime.datetime.strptime(timestr, '%Y%m%d%H%M%S'))) (flexmock(random).should_receive('randrange').once().with_args( 10**(len(rand) - 1), 10**len(rand)).and_return(int(rand))) spec = BuildUserParams.make_params(**param_kwargs) expected_json = { "arrangement_version": REACTOR_CONFIG_ARRANGEMENT_VERSION, "base_image": "buildroot:old", "build_from": "image:buildroot:latest", "build_image": "buildroot:latest", "build_json_dir": INPUTS_PATH, "build_type": "worker", "component": TEST_COMPONENT, "compose_ids": [1, 2], "customize_conf": "worker_customize.json", "filesystem_koji_task_id": TEST_FILESYSTEM_KOJI_TASK_ID, "include_koji_repo": True, "git_branch": TEST_GIT_BRANCH, "git_ref": TEST_GIT_REF, "git_uri": TEST_GIT_URI, "image_tag": "{}/{}:tothepoint-{}-{}-x86_64".format(TEST_USER, TEST_COMPONENT, rand, timestr), "imagestream_name": "name_label", "kind": "build_user_params", "koji_parent_build": "fedora-26-9", "koji_target": "tothepoint", "name": "path-master-cd1e4", 'operator_bundle_replacement_pullspecs': { 'foo/fedora:30': 'bar/fedora@sha256:deadbeef' }, "orchestrator_deadline": 4, 'parent_images_digests': { 'registry.fedorahosted.org/fedora:29': { 'x86_64': 'registry.fedorahosted.org/fedora@sha256:8b96f2f9f88179a065738b2b37' '35e386efb2534438c2a2f45b74358c0f344c81' } }, "platform": "x86_64", "platforms": ["x86_64"], "reactor_config_override": "reactor-config-override", "release": "29", "trigger_imagestreamtag": "buildroot:old", "user": TEST_USER, "worker_deadline": 3, } assert spec.to_json() == json.dumps(expected_json, sort_keys=True) spec2 = BuildUserParams.from_json(spec.to_json()) assert spec2.to_json() == json.dumps(expected_json, sort_keys=True)
def test_v2_all_values_and_json(self): # all values that BuildUserParams stores param_kwargs = { # 'arrangement_version': self.arrangement_version, # calculated value 'base_image': 'buildroot:old', # 'build_from': 'buildroot:old', # only one of build_* # 'build_json_dir': self.build_json_dir, # init paramater 'build_image': 'buildroot:latest', # 'build_imagestream': 'buildroot:name_label', 'build_type': BUILD_TYPE_WORKER, 'component': TEST_COMPONENT, 'compose_ids': [1, 2], 'filesystem_koji_task_id': TEST_FILESYSTEM_KOJI_TASK_ID, 'flatpak': False, # 'flatpak_base_image': self.flatpak_base_image, # not used with false flatpack 'git_branch': TEST_GIT_BRANCH, 'git_ref': TEST_GIT_REF, 'git_uri': TEST_GIT_URI, 'image_tag': 'user/None:none-0-0', 'imagestream_name': TEST_IMAGESTREAM, 'isolated': False, 'koji_parent_build': 'fedora-26-9', 'koji_target': 'tothepoint', # 'name': self.name, # calculated value 'platform': 'x86_64', 'platforms': [ 'x86_64', ], 'reactor_config_map': 'reactor-config-map', 'reactor_config_override': 'reactor-config-override', 'release': '29', 'scratch': False, 'signing_intent': False, 'task_id': TEST_KOJI_TASK_ID, 'trigger_imagestreamtag': 'base_image:latest', 'user': TEST_USER, # 'yum_repourls': , # not used with compose_ids } # additional values that BuildUserParams requires but stores under different names param_kwargs.update({ 'name_label': 'name_label', }) rand = '12345' timestr = '20170731111111' (flexmock(sys.modules['osbs.build.spec']).should_receive( 'utcnow').once().and_return( datetime.datetime.strptime(timestr, '%Y%m%d%H%M%S'))) (flexmock(random).should_receive('randrange').once().with_args( 10**(len(rand) - 1), 10**len(rand)).and_return(int(rand))) build_json_dir = 'inputs' spec = BuildUserParams(build_json_dir) spec.set_params(**param_kwargs) expected_json = { "arrangement_version": REACTOR_CONFIG_ARRANGEMENT_VERSION, "base_image": "buildroot:old", "build_image": "buildroot:latest", "build_json_dir": build_json_dir, "build_type": "worker", "component": TEST_COMPONENT, "compose_ids": [1, 2], "customize_conf": "prod_customize.json", "filesystem_koji_task_id": TEST_FILESYSTEM_KOJI_TASK_ID, "git_branch": TEST_GIT_BRANCH, "git_ref": TEST_GIT_REF, "git_uri": TEST_GIT_URI, "image_tag": "{0}/{1}:tothepoint-{2}-{3}-x86_64".format(TEST_USER, TEST_COMPONENT, rand, timestr), "imagestream_name": "name_label", "koji_parent_build": "fedora-26-9", "koji_target": "tothepoint", "name": "path-master-cd1e4", "platform": "x86_64", "platforms": ["x86_64"], "reactor_config_map": "reactor-config-map", "reactor_config_override": "reactor-config-override", "release": "29", "trigger_imagestreamtag": "buildroot:old", "user": TEST_USER } assert spec.to_json() == json.dumps(expected_json, sort_keys=True) spec2 = BuildUserParams() spec2.from_json(spec.to_json()) assert spec2.to_json() == json.dumps(expected_json, sort_keys=True)