Exemple #1
0
    def test_config_present_test_opts(self):
        """ UT: nxos module:config_present method - add 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=[
            [],
            "add_snmp_config1",
            snmp_matches1,
            "add_snmp_config2",
            snmp_matches2,
        ])

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

                result = nxos_state.config_present(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 added")
Exemple #2
0
    def test_config_present_fail_to_add(self):
        """ UT: nxos module:config_present method - add config fails"""

        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=[[], "add_snmp_config1", "", "add_snmp_config2", ""])

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

                result = nxos_state.config_present(config_data)

                self.assertEqual(result["name"], config_data)
                self.assertFalse(result["result"])
                self.assertEqual(result["changes"], {})
                self.assertEqual(result["comment"], "Failed to add config")
Exemple #3
0
def test_config_present_fail_to_add():
    """
    config_present method - add config fails
    """

    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.config":
        MagicMock(side_effect=["add_snmp_config1", "add_snmp_config2"]),
        "nxos.find":
        MagicMock(side_effect=[[], "", ""]),
    }

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

            result = nxos_state.config_present(config_data)

            assert result["name"] == config_data
            assert not result["result"]
            assert result["changes"] == {}
            assert result["comment"] == "Failed to add config"
Exemple #4
0
def test_config_present_test_opts():
    """
    config_present method - add 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.config":
        MagicMock(side_effect=["add_snmp_config1", "add_snmp_config2"]),
        "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_present(config_data)

            assert result["name"] == config_data
            assert result["result"] is None
            assert result["changes"]["new"] == config_data
            assert result["comment"] == "Config will be added"
Exemple #5
0
def test_config_present():
    """
    config_present method - add 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=[
            [],
            "add_snmp_config1",
            snmp_matches1,
            "add_snmp_config2",
            snmp_matches2,
        ]
    )

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

            result = nxos_state.config_present(config_data)

            assert result["name"] == config_data
            assert result["result"]
            assert result["changes"]["new"] == config_data
            assert result["comment"] == "Successfully added config"
Exemple #6
0
    def test_config_present_already_configured(self):
        """ UT: nxos module:config_present method - add config already configured """

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

        side_effect = MagicMock(side_effect=[config_data[0], config_data[1]])

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

                result = nxos_state.config_present(config_data)

                self.assertEqual(result["name"], config_data)
                self.assertTrue(result["result"])
                self.assertEqual(result["changes"], {})
                self.assertEqual(result["comment"], "Config is already set")
Exemple #7
0
def test_config_present_already_configured():
    """
    config_present method - add config already configured
    """

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

    side_effect = MagicMock(side_effect=[config_data[0], config_data[1]])

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

            result = nxos_state.config_present(config_data)

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