Example #1
0
def test_replace_test_opts():
    """
    replace method - replace config
    """

    name = "randomSNMPstringHERE"
    repl = "NEWrandoSNMPstringHERE"
    matches_before = [
        "snmp-server community randomSNMPstringHERE group network-operator"
    ]
    match_after = []
    changes = {}
    changes["new"] = [
        "snmp-server community NEWrandoSNMPstringHERE group network-operator"
    ]
    changes["old"] = [
        "snmp-server community randomSNMPstringHERE group network-operator"
    ]

    salt_mock = {
        "nxos.find": MagicMock(side_effect=[matches_before, match_after]),
        "nxos.replace": MagicMock(side_effect=[changes]),
    }

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

            result = nxos_state.replace(name, repl)

            assert result["name"] == name
            assert result["result"] is None
            assert result["changes"]["new"] == changes["new"]
            assert result["changes"]["old"] == changes["old"]
            assert result["comment"] == "Configs will be changed"
Example #2
0
    def test_replace_test_opts(self):
        """ UT: nxos module:replace method - replace config """

        name = "randomSNMPstringHERE"
        repl = "NEWrandoSNMPstringHERE"
        matches_before = [
            "snmp-server community randomSNMPstringHERE group network-operator"
        ]
        match_after = []
        changes = {}
        changes["new"] = [
            "snmp-server community NEWrandoSNMPstringHERE group network-operator"
        ]
        changes["old"] = [
            "snmp-server community randomSNMPstringHERE group network-operator"
        ]

        side_effect = MagicMock(
            side_effect=[matches_before, changes, match_after])

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

                result = nxos_state.replace(name, repl)

                self.assertEqual(result["name"], name)
                self.assertEqual(result["result"], None)
                self.assertEqual(result["changes"]["new"], changes["new"])
                self.assertEqual(result["changes"]["old"], changes["old"])
                self.assertEqual(result["comment"], "Configs will be changed")
Example #3
0
def test_replace():
    """
    replace method - replace config
    """

    name = "randomSNMPstringHERE"
    repl = "NEWrandoSNMPstringHERE"
    matches_before = [
        "snmp-server community randomSNMPstringHERE group network-operator"
    ]
    match_after = []
    changes = {}
    changes["new"] = [
        "snmp-server community NEWrandoSNMPstringHERE group network-operator"
    ]
    changes["old"] = [
        "snmp-server community randomSNMPstringHERE group network-operator"
    ]

    side_effect = MagicMock(side_effect=[matches_before, changes, match_after])

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

            result = nxos_state.replace(name, repl)

            assert result["name"] == name
            assert result["result"]
            assert result["changes"]["new"] == changes["new"]
            assert result["changes"]["old"] == changes["old"]
            assert (
                result["comment"]
                == 'Successfully replaced all instances of "randomSNMPstringHERE" with'
                ' "NEWrandoSNMPstringHERE"'
            )