Пример #1
0
    def test_config_file_error2(self):

        """ UT: nxos module:config method - Mandatory arg config_file not specified """

        config_file = None

        with patch(
            "salt.modules.nxos.show",
            autospec=True,
            side_effect=[initial_config_file, modified_config_file],
        ):
            mock_cmd = create_autospec(cp_module.get_file_str, return_value=False)
            with patch.dict(nxos_module.__salt__, {"cp.get_file_str": mock_cmd}):
                mock_cmd = create_autospec(
                    file_module.apply_template_on_contents,
                    return_value=template_engine_file_str_file,
                )
                with patch.dict(
                    nxos_module.__salt__, {"file.apply_template_on_contents": mock_cmd}
                ):
                    with patch(
                        "salt.modules.nxos._configure_device",
                        autospec=True,
                        return_value=config_result_file,
                    ):
                        with self.assertRaises(CommandExecutionError):
                            nxos_module.config(config_file=config_file)
Пример #2
0
    def test_config_nxos_error_ssh(self):

        """ UT: nxos module:config method - nxos device error over ssh transport """

        commands = ["feature bgp", "router bgp 57"]
        config_result = [
            ["feature bgp", "router bgp 57"],
            "bgp instance is already running; Tag is 55",
        ]
        expected_output = "COMMAND_LIST: feature bgp ; router bgp 57\nbgp instance is already running; Tag is 55\n--- \n+++ \n@@ -19,7 +19,6 @@\n feature bash-shell\n cfs eth distribute\n feature ngmvpn\n-feature ospf\n feature pim\n feature lldp\n \n"

        with patch(
            "salt.modules.nxos.show",
            autospec=True,
            side_effect=[initial_config[0], modified_config[0]],
        ):
            mock_cmd = create_autospec(
                file_module.apply_template_on_contents,
                return_value=template_engine_file_str,
            )
            with patch.dict(
                nxos_module.__salt__, {"file.apply_template_on_contents": mock_cmd}
            ):
                with patch(
                    "salt.modules.nxos._configure_device",
                    autospec=True,
                    return_value=config_result,
                ):
                    result = nxos_module.config(commands)
                    self.assertEqual(result, expected_output)
Пример #3
0
    def test_config_commands_string(self):

        """ UT: nxos module:config method - Using commands arg and output is string"""

        commands = "no feature ospf"
        expected_output = "COMMAND_LIST: no feature ospf\n\n--- \n+++ \n@@ -19,7 +19,6 @@\n feature bash-shell\n cfs eth distribute\n feature ngmvpn\n-feature ospf\n feature pim\n feature lldp\n \n"

        with patch(
            "salt.modules.nxos.show",
            autospec=True,
            side_effect=[initial_config[0], modified_config[0]],
        ):
            mock_cmd = create_autospec(
                file_module.apply_template_on_contents,
                return_value=template_engine_file_str,
            )
            with patch.dict(
                nxos_module.__salt__, {"file.apply_template_on_contents": mock_cmd}
            ):
                with patch(
                    "salt.modules.nxos._configure_device",
                    autospec=True,
                    return_value=config_result,
                ):
                    result = nxos_module.config(commands)
                    self.assertEqual(result, expected_output)
Пример #4
0
    def test_config_file(self):

        """ UT: nxos module:config method - Using config_file arg"""

        config_file = "salt://bgp_config.txt"
        expected_output = "COMMAND_LIST: feature bgp ; ! ; router bgp 55 ; address-family ipv4 unicast ; no client-to-client reflection ; additional-paths send\n\n--- \n+++ \n@@ -19,6 +19,7 @@\n feature bash-shell\n cfs eth distribute\n feature ngmvpn\n+feature bgp\n feature pim\n feature lldp\n \n@@ -233,6 +234,10 @@\n line console\n line vty\n boot nxos bootflash:/nxos.9.2.4.bin \n+router bgp 55\n+  address-family ipv4 unicast\n+    no client-to-client reflection\n+    additional-paths send\n \n no logging logfile\n no logging monitor\n"

        with patch(
            "salt.modules.nxos.show",
            autospec=True,
            side_effect=[initial_config_file, modified_config_file],
        ):
            mock_cmd = create_autospec(
                cp_module.get_file_str, return_value=config_input_file
            )
            with patch.dict(nxos_module.__salt__, {"cp.get_file_str": mock_cmd}):
                mock_cmd = create_autospec(
                    file_module.apply_template_on_contents,
                    return_value=template_engine_file_str_file,
                )
                with patch.dict(
                    nxos_module.__salt__, {"file.apply_template_on_contents": mock_cmd}
                ):
                    with patch(
                        "salt.modules.nxos._configure_device",
                        autospec=True,
                        return_value=config_result_file,
                    ):
                        result = nxos_module.config(config_file=config_file)
                        self.assertEqual(result, expected_output)
Пример #5
0
    def test_config_commands_template_none(self):
        """UT: nxos module:config method - Template engine is None"""

        commands = ["no feature ospf", ["no feature ospf"]]
        expected_output = (
            "COMMAND_LIST: no feature ospf\n\n--- \n+++ \n@@ -19,7 +19,6 @@\n feature"
            " bash-shell\n cfs eth distribute\n feature ngmvpn\n-feature ospf\n feature"
            " pim\n feature lldp\n \n")

        for cmd_set in commands:
            with patch(
                    "salt.modules.nxos.show",
                    autospec=True,
                    side_effect=[initial_config, modified_config],
            ):
                mock_cmd = create_autospec(
                    file_module.apply_template_on_contents,
                    return_value=template_engine_file_str,
                )
                with patch.dict(nxos_module.__salt__,
                                {"file.apply_template_on_contents": mock_cmd}):
                    with patch(
                            "salt.modules.nxos._configure_device",
                            autospec=True,
                            return_value=config_result,
                    ):
                        result = nxos_module.config(cmd_set,
                                                    template_engine=None)
                        self.assertEqual(result, expected_output)