Пример #1
0
    def apply_config(self, yaml_configuration_path: str, restart: bool = True):
        # self.store_configuration()
        self.component.service = ServiceFakeArtemis(None, Executor())

        try:
            # Todo hacky way to turn off debug logging from amqcfg module
            amqcfg.LOG.setLevel(logging.WARN)
            if self.LOGGER.level != logging.DEBUG:
                amqcfg.LOG.setLevel(logging.WARN)
            amqcfg.generate(
                profile=yaml_configuration_path,
                output_path=self.local_config_dir,
                write_profile_data=True,
            )
            execution: Execution = self.copy_configuration_files()

            if execution.completed_successfully():
                self.load_configuration_yaml(yaml_configuration_path)
                self.load_configuration()
            else:
                self.LOGGER.error(execution.read_stderr())
                raise IQAConfigurationException(
                    'Unable to copy config files to node.')
        except Exception:
            self.restore_config()
            raise IQAConfigurationException(
                'Unable to apply new configuration. Original config kept.')
        finally:
            self.LOGGER.info('Configuration from "%s" successfully applied.' %
                             yaml_configuration_path)

        if restart and self.component.service is not None:
            self.component.service.restart(wait_for_messaging=True)
Пример #2
0
def test_true_template(*_):
    profile = 'profile.yaml'
    template = 'template/1.0.0'
    expected_result = 'generated data'

    amqcfg.amqcfg.generate_outputs.return_value = expected_result

    result = generate(
        profile=profile,
        template=template,
    )

    assert expected_result == result

    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.get_template_environment.assert_called()
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.get_main_template_list.assert_called()
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.filter_template_list.assert_not_called()
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.ensure_output_path.assert_not_called()
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.write_output.assert_not_called()
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.generate_outputs.assert_called()
Пример #3
0
def test_true_render_options(*_):
    profile = 'profile.yaml'
    template = 'template/1.0.0'
    render_options = 'Render options'
    expected_result = 'generated data'

    config_data, _ = fake_load_tuned_profile_no_defaults()

    amqcfg.amqcfg.generate_outputs.return_value = expected_result

    result = generate(profile=profile,
                      template=template,
                      render_options=render_options)

    assert expected_result == result

    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.add_render_config.assert_called_with(config_data,
                                                       render_options)
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.get_template_environment.assert_called()
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.get_main_template_list.assert_called()
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.filter_template_list.assert_not_called()
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.ensure_output_path.assert_not_called()
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.write_output.assert_not_called()
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.generate_outputs.assert_called()
Пример #4
0
def test_bad_profile_exception(*_):
    profile = 'bad_profile.yaml'

    with pytest.raises(ProfileError):
        generate(profile=profile)

    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.get_template_environment.assert_not_called()
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.get_main_template_list.assert_not_called()
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.filter_template_list.assert_not_called()
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.ensure_output_path.assert_not_called()
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.write_output.assert_not_called()
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.generate_outputs.assert_not_called()
Пример #5
0
def test_true_tuning_data(*_):
    profile = 'profile.yaml'
    template = 'template/1.0.0'
    tuning_data = [
        {
            'a': '1'
        },
        {
            'b': '2'
        },
    ]
    expected_result = 'generated data'

    amqcfg.amqcfg.get_tuned_profile.side_effect = \
        fake_load_tuned_profile_no_defaults
    amqcfg.amqcfg.generate_outputs.return_value = expected_result

    result = generate(
        profile=profile,
        template=template,
        tuning_data_list=tuning_data,
    )

    assert expected_result == result

    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.get_tuned_profile.assert_called_with(
        profile=profile,
        tuning_files_list=None,
        tuning_data_list=tuning_data,
    )
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.get_template_environment.assert_called()
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.get_main_template_list.assert_called()
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.filter_template_list.assert_not_called()
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.ensure_output_path.assert_not_called()
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.write_output.assert_not_called()
    # noinspection PyUnresolvedReferences
    amqcfg.amqcfg.generate_outputs.assert_called()