예제 #1
0
    def test_config_absent_test_opts(self):
        """ UT: nxos module:config_absent method - remove config """

        config_data = [
            "snmp-server community randomSNMPstringHERE group network-operator",
            "snmp-server community AnotherRandomSNMPSTring group network-admin",
        ]
        snmp_matches1 = [
            "snmp-server community randomSNMPstringHERE group network-operator"
        ]
        snmp_matches2 = [[
            "snmp-server community AnotherRandomSNMPSTring group network-admin"
        ]]

        side_effect = MagicMock(side_effect=[
            snmp_matches1,
            "remove_config",
            [],
            snmp_matches2,
            "remove_config",
            [],
        ])

        with patch.dict(nxos_state.__opts__, {"test": True}):
            with patch.dict(nxos_state.__salt__, {"nxos.cmd": side_effect}):

                result = nxos_state.config_absent(config_data)

                self.assertEqual(result["name"], config_data)
                self.assertEqual(result["result"], None)
                self.assertEqual(result["changes"]["new"], config_data)
                self.assertEqual(result["comment"], "Config will be removed")
예제 #2
0
파일: test_nxos.py 프로젝트: mcalmer/salt
def test_config_absent_test_opts():
    """
    config_absent method - remove config
    """

    config_data = [
        "snmp-server community randomSNMPstringHERE group network-operator",
        "snmp-server community AnotherRandomSNMPSTring group network-admin",
    ]
    snmp_matches1 = [
        "snmp-server community randomSNMPstringHERE group network-operator"
    ]
    snmp_matches2 = [[
        "snmp-server community AnotherRandomSNMPSTring group network-admin"
    ]]

    salt_mock = {
        "nxos.delete_config":
        MagicMock(side_effect=["remove_config", "remove_config"]),
        "nxos.find":
        MagicMock(side_effect=[snmp_matches1, [], snmp_matches2, []]),
    }

    with patch.dict(nxos_state.__opts__, {"test": True}):
        with patch.dict(nxos_state.__salt__, salt_mock):

            result = nxos_state.config_absent(config_data)

            assert result["name"] == config_data
            assert result["result"] is None
            assert result["changes"]["new"] == config_data
            assert result["comment"] == "Config will be removed"
예제 #3
0
def test_config_absent():
    """
    config_absent method - remove config
    """

    config_data = [
        "snmp-server community randomSNMPstringHERE group network-operator",
        "snmp-server community AnotherRandomSNMPSTring group network-admin",
    ]
    snmp_matches1 = [
        "snmp-server community randomSNMPstringHERE group network-operator"
    ]
    snmp_matches2 = [[
        "snmp-server community AnotherRandomSNMPSTring group network-admin"
    ]]

    side_effect = MagicMock(side_effect=[
        snmp_matches1,
        "remove_config",
        [],
        snmp_matches2,
        "remove_config",
        [],
    ])

    with patch.dict(nxos_state.__opts__, {"test": False}):
        with patch.dict(nxos_state.__salt__, {"nxos.cmd": side_effect}):

            result = nxos_state.config_absent(config_data)

            assert result["name"] == config_data
            assert result["result"]
            assert result["changes"]["new"] == config_data
            assert result["comment"] == "Successfully deleted config"
예제 #4
0
    def test_config_absent_already_configured(self):
        """ UT: nxos module:config_absent method - add config removed """

        config_data = [
            "snmp-server community randomSNMPstringHERE group network-operator",
            "snmp-server community AnotherRandomSNMPSTring group network-admin",
        ]

        side_effect = MagicMock(side_effect=[[], []])

        with patch.dict(nxos_state.__opts__, {"test": False}):
            with patch.dict(nxos_state.__salt__, {"nxos.cmd": side_effect}):

                result = nxos_state.config_absent(config_data)

                self.assertEqual(result["name"], config_data)
                self.assertTrue(result["result"])
                self.assertEqual(result["changes"], {})
                self.assertEqual(result["comment"], "Config is already absent")
예제 #5
0
파일: test_nxos.py 프로젝트: mcalmer/salt
def test_config_absent_already_configured():
    """
    config_absent method - add config removed
    """

    config_data = [
        "snmp-server community randomSNMPstringHERE group network-operator",
        "snmp-server community AnotherRandomSNMPSTring group network-admin",
    ]

    side_effect = MagicMock(side_effect=[[], []])

    with patch.dict(nxos_state.__opts__, {"test": False}):
        with patch.dict(nxos_state.__salt__, {"nxos.find": side_effect}):

            result = nxos_state.config_absent(config_data)

            assert result["name"] == config_data
            assert result["result"]
            assert result["changes"] == {}
            assert result["comment"] == "Config is already absent"