Ejemplo n.º 1
0
def test_ping():
    with patch(
        "salt.utils.napalm.get_device",
        MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_network.ping("destination.com")
        assert list(ret["out"].keys())[0] == "success"
Ejemplo n.º 2
0
def test_load_filter_config():
    with patch(
            "salt.utils.napalm.get_device",
            MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_acl.load_filter_config("test_filter", "test_term")
        assert ret["already_configured"] is False
Ejemplo n.º 3
0
def test_config_control():
    with patch(
        "salt.utils.napalm.get_device",
        MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_network.config_control()
        assert ret == (True, "")
Ejemplo n.º 4
0
def test_connected_pass():
    with patch(
        "salt.utils.napalm.get_device",
        MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_network.connected()
        assert ret["out"] is True
Ejemplo n.º 5
0
def test_load_template():
    with patch(
        "salt.utils.napalm.get_device",
        MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_network.load_template("set_ntp_peers", peers=["192.168.0.1"])
        assert ret["out"] is None
Ejemplo n.º 6
0
def test_rollback():
    with patch(
        "salt.utils.napalm.get_device",
        MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_network.rollback()
        assert ret["out"] == napalm_test_support.TEST_RUNNING_CONFIG.copy()
Ejemplo n.º 7
0
def test_optics():
    with patch(
        "salt.utils.napalm.get_device",
        MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_network.optics()
        assert ret["out"] == napalm_test_support.TEST_OPTICS.copy()
Ejemplo n.º 8
0
def test_load_config_replace():
    with patch(
        "salt.utils.napalm.get_device",
        MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_network.load_config(text="new config", replace=True)
        assert ret["result"]
Ejemplo n.º 9
0
def test_lldp():
    with patch(
        "salt.utils.napalm.get_device",
        MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_network.lldp()
        assert ret["out"] == napalm_test_support.TEST_LLDP_NEIGHBORS.copy()
Ejemplo n.º 10
0
def test_interfaces():
    with patch(
        "salt.utils.napalm.get_device",
        MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_network.interfaces()
        assert ret["out"] == napalm_test_support.TEST_INTERFACES.copy()
Ejemplo n.º 11
0
def test_show():
    with patch(
        "salt.utils.napalm.get_device",
        MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_route.show("1.2.3.4")
        assert ret["out"] == napalm_test_support.TEST_ROUTE.copy()
Ejemplo n.º 12
0
def test_stats():
    with patch(
            "salt.utils.napalm.get_device",
            MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_ntp.stats()
        assert ret["out"][0]["reachability"] == 377
Ejemplo n.º 13
0
def test_environment():
    with patch(
        "salt.utils.napalm.get_device",
        MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_network.environment()
        assert ret["out"] == napalm_test_support.TEST_ENVIRONMENT.copy()
Ejemplo n.º 14
0
def test_servers():
    with patch(
            "salt.utils.napalm.get_device",
            MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_ntp.servers()
        assert "172.17.17.1" in ret["out"]
Ejemplo n.º 15
0
def test_arp():
    with patch(
        "salt.utils.napalm.get_device",
        MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_network.arp()
        assert ret["out"] == napalm_test_support.TEST_ARP_TABLE.copy()
Ejemplo n.º 16
0
def test_delete_peers():
    with patch(
            "salt.utils.napalm.get_device",
            MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_ntp.delete_peers("1.2.3.4", "5.6.7.8")
        assert ret is None
Ejemplo n.º 17
0
    def setup_loader_modules(self):
        patcher = patch(
            "salt.utils.napalm.get_device",
            MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
        )
        patcher.start()
        self.addCleanup(patcher.stop)
        module_globals = {
            "__salt__": {
                "config.get":
                MagicMock(return_value={
                    "test": {
                        "driver": "test",
                        "key": "2orgk34kgk34g"
                    }
                }),
                "file.file_exists":
                napalm_test_support.true,
                "file.join":
                napalm_test_support.join,
                "file.get_managed":
                napalm_test_support.get_managed_file,
                "random.hash":
                napalm_test_support.random_hash,
            }
        }

        return {napalm_network: module_globals}
Ejemplo n.º 18
0
def test_neighbors():
    with patch(
            "salt.utils.napalm.get_device",
            MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_bgp.neighbors("test_address")
        assert ret["out"] == napalm_test_support.TEST_BGP_NEIGHBORS.copy()
Ejemplo n.º 19
0
def test_config():
    with patch(
            "salt.utils.napalm.get_device",
            MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_bgp.config("test_group")
        assert ret["out"] == napalm_test_support.TEST_BGP_CONFIG.copy()
Ejemplo n.º 20
0
def test_update_config():
    with patch(
            "salt.utils.napalm.get_device",
            MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_snmp.update_config("1.2.3.4")
        assert ret["result"] is False
Ejemplo n.º 21
0
def test_config():
    with patch(
            "salt.utils.napalm.get_device",
            MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_snmp.config()
        assert ret["out"] == napalm_test_support.TEST_SNMP_INFO.copy()
    def setup_loader_modules(self):
        patcher = patch(
            "salt.utils.napalm.get_device",
            MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
        )
        patcher.start()
        self.addCleanup(patcher.stop)

        def mock_net_load_config(**kwargs):
            return self._test_config.copy()

        module_globals = {
            "__salt__": {
                "config.get": MagicMock(
                    return_value={"test": {"driver": "test", "key": "2orgk34kgk34g"}}
                ),
                "file.file_exists": napalm_test_support.true,
                "file.join": napalm_test_support.join,
                "file.get_managed": napalm_test_support.get_managed_file,
                "random.hash": napalm_test_support.random_hash,
                "net.load_template": napalm_network.load_template,
                "net.load_config": mock_net_load_config,
            },
            "napalm_yang": MockNapalmYangModule(self._test_diff.copy()),
        }

        return {napalm_yang_mod: module_globals, napalm_network: module_globals}
Ejemplo n.º 23
0
def test_delete_users():
    with patch(
            "salt.utils.napalm.get_device",
            MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_users.delete_users({"mircea": {}})
        assert ret["result"] is False
Ejemplo n.º 24
0
def test_cli_multi_command():
    """
    Test that CLI works with 2 arg
    """
    with patch(
        "salt.utils.napalm.get_device",
        MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
    ):
        ret = napalm_network.cli("show run", "show run")
        assert ret["out"] == napalm_test_support.TEST_COMMAND_RESPONSE.copy()
Ejemplo n.º 25
0
    def setup_loader_modules(self):
        patcher = patch(
            "salt.utils.napalm.get_device",
            MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
        )
        patcher.start()
        self.addCleanup(patcher.stop)
        module_globals = {
            "__salt__": {
                "config.get":
                MagicMock(return_value={
                    "test": {
                        "driver": "test",
                        "key": "2orgk34kgk34g"
                    }
                }),
                "file.file_exists":
                napalm_test_support.true,
                "file.join":
                napalm_test_support.join,
                "file.get_managed":
                napalm_test_support.get_managed_file,
                "random.hash":
                napalm_test_support.random_hash,
                "capirca.get_term_config":
                mock_capirca_term_config,
                "capirca.get_policy_config":
                mock_capirca_policy_config,
                "capirca.get_filter_config":
                mock_capirca_filter_config,
                "capirca.get_filter_pillar":
                mock_capirca_get_filter_pillar,
                "capirca.get_term_pillar":
                mock_capirca_get_term_pillar,
                "net.load_config":
                mock_net_load_config,
            },
            "__grains__": {
                "os": "ios",
                "vendor": "cisco",
                "model": "3750X"
            },
        }

        return {napalm_acl: module_globals}
Ejemplo n.º 26
0
    def setup_loader_modules(self):
        patcher = patch(
            "salt.utils.napalm.get_device",
            MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
        )
        patcher.start()
        self.addCleanup(patcher.stop)

        def mock_net_load(template, *args, **kwargs):
            if template == "set_probes":
                assert kwargs["probes"] == self._test_probes.copy()
                return napalm_test_support.TEST_TERM_CONFIG.copy()
            if template == "delete_probes":
                assert kwargs["probes"] == self._test_delete_probes.copy()
                return napalm_test_support.TEST_TERM_CONFIG.copy()
            if template == "schedule_probes":
                assert kwargs["probes"] == self._test_schedule_probes.copy()
                return napalm_test_support.TEST_TERM_CONFIG.copy()
            raise ValueError("incorrect template {}".format(template))

        module_globals = {
            "__salt__": {
                "config.get":
                MagicMock(return_value={
                    "test": {
                        "driver": "test",
                        "key": "2orgk34kgk34g"
                    }
                }),
                "file.file_exists":
                napalm_test_support.true,
                "file.join":
                napalm_test_support.join,
                "file.get_managed":
                napalm_test_support.get_managed_file,
                "random.hash":
                napalm_test_support.random_hash,
                "net.load_template":
                mock_net_load,
            }
        }

        return {napalm_probes: module_globals}
Ejemplo n.º 27
0
    def setup_loader_modules(self):
        patcher = patch.object(napalm_grains.salt.utils.napalm, "is_proxy",
                               MagicMock(return_value=True))
        patcher.start()
        test_device_cache = {
            "DRIVER": napalm_test_support.MockNapalmDevice(),
            "DRIVER_NAME": "cisco",
            "OS_VERSION": "1.2.3",
            "HOSTNAME": "test-device.com",
            "USERNAME": "******",
        }

        test_cache = {"result": True, "out": napalm_test_support.TEST_FACTS}
        patcher = patch("salt.grains.napalm.DEVICE_CACHE", test_device_cache)
        patcher.start()
        patcher = patch("salt.grains.napalm.GRAINS_CACHE", test_cache)
        patcher.start()
        self.addCleanup(patch.stopall)
        module_globals = {
            "__salt__": {
                "config.option":
                MagicMock(return_value={
                    "test": {
                        "driver": "test",
                        "key": "2orgk34kgk34g"
                    }
                }),
                "file.file_exists":
                napalm_test_support.true,
                "file.join":
                napalm_test_support.join,
                "file.get_managed":
                napalm_test_support.get_managed_file,
                "random.hash":
                napalm_test_support.random_hash,
            }
        }

        return {napalm_grains: module_globals}
Ejemplo n.º 28
0
def mock_get_device(opts, *args, **kwargs):
    assert opts == TEST_OPTS
    return {'DRIVER': napalm_test_support.MockNapalmDevice(), 'UP': True}
Ejemplo n.º 29
0
from __future__ import absolute_import, print_function, unicode_literals

import tests.support.napalm as napalm_test_support

# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.mock import MagicMock, patch
from tests.support.unit import TestCase

import salt.grains.napalm as napalm_grains  # NOQA
import salt.proxy.napalm as napalm_proxy  # NOQA

napalm_grains.salt.utils.napalm.is_proxy = MagicMock(return_value=True)

TEST_DEVICE_CACHE = {
    "DRIVER": napalm_test_support.MockNapalmDevice(),
    "DRIVER_NAME": "cisco",
    "OS_VERSION": "1.2.3",
    "HOSTNAME": "test-device.com",
    "USERNAME": "******",
}

TEST_CACHE = {"result": True, "out": napalm_test_support.TEST_FACTS}


@patch("salt.grains.napalm.DEVICE_CACHE", TEST_DEVICE_CACHE)
@patch("salt.grains.napalm.GRAINS_CACHE", TEST_CACHE)
class NapalmGrainsTestCase(TestCase, LoaderModuleMockMixin):
    def setup_loader_modules(self):
        module_globals = {
            "__salt__": {
Ejemplo n.º 30
0
 def mock_get_device(opts, *args, **kwargs):
     assert opts == self.test_opts
     return {"DRIVER": napalm_test_support.MockNapalmDevice(), "UP": True}