Example #1
0
    def test_all_values_and_json(self, origin_nvr, origin_id):
        conf_args = {
            "build_from": "image:buildroot:latest",
            'orchestrator_max_run_hours': 5,
            'reactor_config_map': 'reactor-config-map-scratch',
            'scratch': True,
            'worker_max_run_hours': 3,
        }
        param_kwargs = self.get_minimal_kwargs(origin_nvr, conf_args=conf_args)
        param_kwargs.update({
            'component': TEST_COMPONENT,
            "koji_target": "tothepoint",
            "platform": "x86_64",
            "signing_intent": "test-signing-intent",
            "sources_for_koji_build_id": origin_id,
        })

        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 = SourceContainerUserParams.make_params(**param_kwargs)

        expected_json = {
            "arrangement_version":
            REACTOR_CONFIG_ARRANGEMENT_VERSION,
            "build_from":
            "image:buildroot:latest",
            "build_image":
            "buildroot:latest",
            "build_json_dir":
            INPUTS_PATH,
            'component':
            TEST_COMPONENT,
            "image_tag":
            "{}/{}:tothepoint-{}-{}-x86_64".format(TEST_USER, TEST_COMPONENT,
                                                   rand, timestr),
            "kind":
            "source_containers_user_params",
            "signing_intent":
            "test-signing-intent",
            "sources_for_koji_build_nvr":
            origin_nvr,
            "koji_target":
            "tothepoint",
            "orchestrator_deadline":
            5,
            "platform":
            "x86_64",
            'reactor_config_map':
            'reactor-config-map-scratch',
            'scratch':
            True,
            "user":
            TEST_USER,
            "worker_deadline":
            3,
        }
        if origin_id:
            expected_json['sources_for_koji_build_id'] = origin_id
        assert spec.to_json() == json.dumps(expected_json, sort_keys=True)

        spec2 = SourceContainerUserParams.from_json(spec.to_json())
        assert spec2.to_json() == json.dumps(expected_json, sort_keys=True)
Example #2
0
    def test_all_values_and_json(self, scratch, origin_nvr, origin_id):
        conf_args = {
            'namespace': TEST_OCP_NAMESPACE,
            'reactor_config_map_scratch': 'reactor-config-map-scratch',
            'reactor_config_map': 'reactor-config-map',
            'scratch': scratch,
        }
        userdata = {'custom': 'userdata'}
        param_kwargs = self.get_minimal_kwargs(origin_nvr, conf_args=conf_args)
        param_kwargs.update({
            'component': TEST_COMPONENT,
            "koji_target": "tothepoint",
            "platform": "x86_64",
            "signing_intent": "test-signing-intent",
            "sources_for_koji_build_id": origin_id,
            "userdata": userdata,
        })

        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 = SourceContainerUserParams.make_params(**param_kwargs)

        expected_json = {
            "build_json_dir":
            INPUTS_PATH,
            'component':
            TEST_COMPONENT,
            "image_tag":
            "{}/{}:tothepoint-{}-{}-x86_64".format(TEST_USER, TEST_COMPONENT,
                                                   rand, timestr),
            "kind":
            "source_containers_user_params",
            "signing_intent":
            "test-signing-intent",
            "sources_for_koji_build_nvr":
            origin_nvr,
            "koji_target":
            "tothepoint",
            "namespace":
            TEST_OCP_NAMESPACE,
            "platform":
            "x86_64",
            'reactor_config_map':
            'reactor-config-map',
            "user":
            TEST_USER,
            "userdata":
            userdata,
        }
        if scratch:
            expected_json['reactor_config_map'] = 'reactor-config-map-scratch'
            expected_json['scratch'] = scratch

        if origin_id:
            expected_json['sources_for_koji_build_id'] = origin_id

        assert spec.to_json() == json.dumps(expected_json, sort_keys=True)

        spec2 = SourceContainerUserParams.from_json(spec.to_json())
        assert spec2.to_json() == json.dumps(expected_json, sort_keys=True)