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"
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
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, "")
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
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
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()
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()
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"]
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()
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()
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()
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
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()
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"]
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()
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
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}
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()
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()
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
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}
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
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()
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}
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}
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}
def mock_get_device(opts, *args, **kwargs): assert opts == TEST_OPTS return {'DRIVER': napalm_test_support.MockNapalmDevice(), 'UP': True}
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__": {
def mock_get_device(opts, *args, **kwargs): assert opts == self.test_opts return {"DRIVER": napalm_test_support.MockNapalmDevice(), "UP": True}