Beispiel #1
0
    def test_write_config(self):
        yaml_inputs = (SOURCE_2_CONFIG, SOURCE_1_CONFIG, FILTER_1_CONFIG,
                       TEMPLATE_1_CONFIG, REWRITE_1_CONFIG, LOG_1_CONFIG)
        expected_outputs = (SOURCE_2_EXPECTED, SOURCE_1_EXPECTED,
                            FILTER_1_EXPECTED, TEMPLATE_1_EXPECTED,
                            REWRITE_1_EXPECTED, LOG_1_EXPECTED)
        config_file_fd, config_file_name = tempfile.mkstemp()
        os.close(config_file_fd)

        with patch.dict(syslog_ng.__salt__, _SALT_VAR_WITH_MODULE_METHODS):
            syslog_ng_module.set_config_file(config_file_name)
            syslog_ng_module.write_version("3.6")
            syslog_ng_module.write_config(config='@include "scl.conf"')

            for i in yaml_inputs:
                parsed_yaml_config = yaml.load(i["config"])
                id = i["id"]
                got = syslog_ng.config(id,
                                       config=parsed_yaml_config,
                                       write=True)

            written_config = ""
            with salt.utils.fopen(config_file_name, "r") as f:
                written_config = f.read()

            config_without_whitespaces = remove_whitespaces(written_config)
            for i in expected_outputs:
                without_whitespaces = remove_whitespaces(i)
                self.assertIn(without_whitespaces, config_without_whitespaces)

            syslog_ng_module.set_config_file("")
            os.remove(config_file_name)
    def test_write_config(self):
        yaml_inputs = (
            SOURCE_2_CONFIG, SOURCE_1_CONFIG, FILTER_1_CONFIG, TEMPLATE_1_CONFIG, REWRITE_1_CONFIG, LOG_1_CONFIG
        )
        expected_outputs = (
            SOURCE_2_EXPECTED, SOURCE_1_EXPECTED, FILTER_1_EXPECTED, TEMPLATE_1_EXPECTED, REWRITE_1_EXPECTED,
            LOG_1_EXPECTED
        )
        config_file_fd, config_file_name = tempfile.mkstemp()
        os.close(config_file_fd)

        with patch.dict(syslog_ng.__salt__, _SALT_VAR_WITH_MODULE_METHODS):
            syslog_ng_module.set_config_file(config_file_name)
            syslog_ng.write_version("3.6")
            syslog_ng.write_config("", config='@include "scl.conf"')

            for i in yaml_inputs:
                parsed_yaml_config = yaml.load(i["config"])
                id = i["id"]
                got = syslog_ng.config(id, config=parsed_yaml_config, write=True)

            written_config = ""
            with open(config_file_name, "r") as f:
                written_config = f.read()

            config_without_whitespaces = remove_whitespaces(written_config)
            for i in expected_outputs:
                without_whitespaces = remove_whitespaces(i)
                self.assertIn(without_whitespaces, config_without_whitespaces)

            syslog_ng_module.set_config_file("")
            os.remove(config_file_name)
Beispiel #3
0
    def _config_generator_template(self, yaml_input, expected):
        parsed_yaml_config = yaml.load(yaml_input["config"])
        id = yaml_input["id"]

        with patch.dict(syslog_ng.__salt__, _SALT_VAR_WITH_MODULE_METHODS):
            got = syslog_ng.config(id, config=parsed_yaml_config, write=False)
            config = got["changes"]["new"]
            self.assertEqual(remove_whitespaces(expected), remove_whitespaces(config))
            self.assertEqual(False, got["result"])
Beispiel #4
0
    def _config_generator_template(self, yaml_input, expected):
        parsed_yaml_config = salt.utils.data.decode(salt.utils.yaml.safe_load(yaml_input["config"]))
        id = yaml_input["id"]

        with patch.dict(syslog_ng.__salt__, _SALT_VAR_WITH_MODULE_METHODS):
            got = syslog_ng.config(id, config=parsed_yaml_config, write=False)
            config = got["changes"]["new"]
            self.assertEqual(remove_whitespaces(expected), remove_whitespaces(config))
            self.assertEqual(False, got["result"])