Ejemplo n.º 1
0
    def test_check_and_set_rebuild(self, tmpdir, osbs, triggers):

        imagechange = [
            {
                "type": "ImageChange",
                "imageChange": {
                    "from": {
                        "kind": "ImageStreamTag",
                        "name": "{{BASE_IMAGE_STREAM}}"
                    }
                }
            }
        ]

        if triggers:
            orch_outer_temp = ORCHESTRATOR_INNER_TEMPLATE.format(
                arrangement_version=self.ARRANGEMENT_VERSION
            )
            for basename in [ORCHESTRATOR_OUTER_TEMPLATE, orch_outer_temp]:
                shutil.copy(os.path.join(INPUTS_PATH, basename),
                            os.path.join(str(tmpdir), basename))

            with open(os.path.join(str(tmpdir), ORCHESTRATOR_OUTER_TEMPLATE), 'r+') as orch_json:
                build_json = json.load(orch_json)
                build_json['spec']['triggers'] = imagechange

                orch_json.seek(0)
                json.dump(build_json, orch_json)
                orch_json.truncate()

            flexmock(osbs.os_conf, get_build_json_store=lambda: str(tmpdir))
            (flexmock(BuildRequest)
                .should_receive('adjust_for_repo_info')
                .and_return(True))

        additional_params = {
            'base_image': 'fedora:latest',
        }
        params, build_json = self.get_orchestrator_build_request(osbs, additional_params)
        plugins = get_plugins_from_build_json(build_json)

        if not triggers:
            with pytest.raises(NoSuchPluginException):
                get_plugin(plugins, 'prebuild_plugins', 'check_and_set_rebuild')
            return

        args = plugin_value_get(plugins, 'prebuild_plugins',
                                         'check_and_set_rebuild', 'args')

        match_args = {
            "label_key": "is_autorebuild",
            "label_value": "true",
            "url": "/",
            "verify_ssl": False,
            'use_auth': False,
        }
        assert match_args == args
Ejemplo n.º 2
0
    def test_check_and_set_rebuild(self, tmpdir, osbs, triggers):

        imagechange = [{
            "type": "ImageChange",
            "imageChange": {
                "from": {
                    "kind": "ImageStreamTag",
                    "name": "{{BASE_IMAGE_STREAM}}"
                }
            }
        }]

        if triggers:
            orch_outer_temp = ORCHESTRATOR_INNER_TEMPLATE.format(
                arrangement_version=self.ARRANGEMENT_VERSION)
            for basename in [ORCHESTRATOR_OUTER_TEMPLATE, orch_outer_temp]:
                shutil.copy(os.path.join(INPUTS_PATH, basename),
                            os.path.join(str(tmpdir), basename))

            with open(os.path.join(str(tmpdir), ORCHESTRATOR_OUTER_TEMPLATE),
                      'r+') as orch_json:
                build_json = json.load(orch_json)
                build_json['spec']['triggers'] = imagechange

                orch_json.seek(0)
                json.dump(build_json, orch_json)
                orch_json.truncate()

            flexmock(osbs.os_conf, get_build_json_store=lambda: str(tmpdir))
            (flexmock(BuildRequest).should_receive(
                'adjust_for_repo_info').and_return(True))

        additional_params = {
            'base_image': 'fedora:latest',
        }
        params, build_json = self.get_orchestrator_build_request(
            osbs, additional_params)
        plugins = get_plugins_from_build_json(build_json)

        if not triggers:
            with pytest.raises(NoSuchPluginException):
                get_plugin(plugins, 'prebuild_plugins',
                           'check_and_set_rebuild')
            return

        args = plugin_value_get(plugins, 'prebuild_plugins',
                                'check_and_set_rebuild', 'args')

        match_args = {
            "label_key": "is_autorebuild",
            "label_value": "true",
            "url": "/",
            "verify_ssl": False,
            'use_auth': False,
        }
        assert match_args == args
Ejemplo n.º 3
0
    def create_orchestrator_build(self, **kwargs):
        """
        Create an orchestrator build

        Pass through method to create_prod_build with the following
        modifications:
            - platforms param is required
            - arrangement_version param may be used to select which
              orchestrator_inner:n.json template to use
            - inner template set to orchestrator_inner:n.json if not set
            - outer template set to orchestrator.json if not set
            - customize configuration set to orchestrator_customize.json if not set

        :return: BuildResponse instance
        """
        if not kwargs.get('platforms'):
            raise ValueError('Orchestrator build requires platforms param')

        if not self.can_orchestrate():
            raise OsbsValidationException("can't create orchestrate build "
                                          "when can_orchestrate isn't enabled")
        extra = [x for x in ('platform', ) if kwargs.get(x)]
        if extra:
            raise ValueError(
                "Orchestrator build called with unwanted parameters: %s" %
                extra)

        arrangement_version = kwargs.setdefault(
            'arrangement_version', self.build_conf.get_arrangement_version())

        kwargs.setdefault(
            'inner_template',
            ORCHESTRATOR_INNER_TEMPLATE.format(
                arrangement_version=arrangement_version))
        kwargs.setdefault('outer_template', ORCHESTRATOR_OUTER_TEMPLATE)
        kwargs.setdefault('customize_conf', ORCHESTRATOR_CUSTOMIZE_CONF)
        kwargs['build_type'] = BUILD_TYPE_ORCHESTRATOR
        try:
            return self._do_create_prod_build(**kwargs)
        except IOError as ex:
            if os.path.basename(ex.filename) == kwargs['inner_template']:
                raise OsbsValidationException(
                    "orchestrator invalid arrangement_version %s" %
                    arrangement_version)

            raise
Ejemplo n.º 4
0
    def create_orchestrator_build(self, **kwargs):
        """
        Create an orchestrator build

        Pass through method to create_prod_build with the following
        modifications:
            - platforms param is required
            - arrangement_version param may be used to select which
              orchestrator_inner:n.json template to use
            - inner template set to orchestrator_inner:n.json if not set
            - outer template set to orchestrator.json if not set
            - customize configuration set to orchestrator_customize.json if not set

        :return: BuildResponse instance
        """
        if not kwargs.get('platforms'):
            raise ValueError('Orchestrator build requires platforms param')

        if not self.can_orchestrate():
            raise OsbsOrchestratorNotEnabled("can't create orchestrate build "
                                             "when can_orchestrate isn't enabled")
        extra = [x for x in ('platform',) if kwargs.get(x)]
        if extra:
            raise ValueError("Orchestrator build called with unwanted parameters: %s" %
                             extra)

        arrangement_version = kwargs.setdefault('arrangement_version',
                                                self.build_conf.get_arrangement_version())

        kwargs.setdefault('inner_template', ORCHESTRATOR_INNER_TEMPLATE.format(
            arrangement_version=arrangement_version))
        kwargs.setdefault('outer_template', ORCHESTRATOR_OUTER_TEMPLATE)
        kwargs.setdefault('customize_conf', ORCHESTRATOR_CUSTOMIZE_CONF)
        kwargs['build_type'] = BUILD_TYPE_ORCHESTRATOR
        try:
            return self._do_create_prod_build(**kwargs)
        except IOError as ex:
            if os.path.basename(ex.filename) == kwargs['inner_template']:
                raise OsbsValidationException("orchestrator invalid arrangement_version %s" %
                                              arrangement_version)

            raise