def test_ensure_primary_ip_not_exist(self): """Verify ensure_primary_ip function when the IP address do not already exist.""" onboarding_kwargs = { "netdev_hostname": "device1", "netdev_nb_role_slug": PLUGIN_SETTINGS["default_device_role"], "netdev_nb_role_color": PLUGIN_SETTINGS["default_device_role_color"], "netdev_vendor": "Cisco", "netdev_model": "CSR1000v", "netdev_nb_site_slug": self.site1.slug, "netdev_netmiko_device_type": "cisco_ios", "netdev_serial_number": "123456", "netdev_mgmt_ip_address": "192.0.2.10", "netdev_mgmt_ifname": "ge-0/0/0", "netdev_mgmt_pflen": 24, } nbk = NautobotKeeper(**onboarding_kwargs) nbk.ensure_device() self.assertIsInstance(nbk.nb_primary_ip, IPAddress) self.assertIn( nbk.nb_primary_ip, Interface.objects.get(device=nbk.device, name="ge-0/0/0").ip_addresses.all()) self.assertEqual(nbk.device.primary_ip, nbk.nb_primary_ip)
def test_ensure_device_instance_not_exist(self): """Verify ensure_device_instance function.""" serial_number = "123456" platform_slug = "cisco_ios" hostname = "device1" onboarding_kwargs = { "netdev_hostname": hostname, "netdev_nb_role_slug": PLUGIN_SETTINGS["default_device_role"], "netdev_nb_role_color": PLUGIN_SETTINGS["default_device_role_color"], "netdev_vendor": "Cisco", "netdev_model": "CSR1000v", "netdev_nb_site_slug": self.site1.slug, "netdev_netmiko_device_type": platform_slug, "netdev_serial_number": serial_number, "netdev_mgmt_ip_address": "192.0.2.10", "netdev_mgmt_ifname": "GigaEthernet0", "netdev_mgmt_pflen": 24, } nbk = NautobotKeeper(**onboarding_kwargs) nbk.ensure_device() self.assertIsInstance(nbk.device, Device) self.assertEqual(nbk.device.name, hostname) device_status = Status.objects.get( content_types__in=[ContentType.objects.get_for_model(Device)], name=PLUGIN_SETTINGS["default_device_status"]) self.assertEqual(nbk.device.status, device_status) self.assertEqual(nbk.device.platform.slug, platform_slug) self.assertEqual(nbk.device.serial, serial_number)
def run(self, onboarding_kwargs): """Ensures network device.""" # Access hostname from onboarding_kwargs and get device role automatically device_new_role = self.get_device_role( hostname=onboarding_kwargs["netdev_hostname"]) # Update the device role in onboarding kwargs dictionary onboarding_kwargs["netdev_nb_role_slug"] = device_new_role nb_k = NautobotKeeper(**onboarding_kwargs) nb_k.ensure_device() self.created_device = nb_k.device
def test_ensure_device_instance_exist(self): """Verify ensure_device_instance function.""" manufacturer = Manufacturer.objects.create(name="Cisco", slug="cisco") device_role = DeviceRole.objects.create(name="Switch", slug="switch") device_type = DeviceType.objects.create(slug="c2960", model="c2960", manufacturer=manufacturer) device_name = "test_name" planned_status = Status.objects.get( content_types__in=[ContentType.objects.get_for_model(Device)], name="Planned") device = Device.objects.create( name=device_name, site=self.site1, device_type=device_type, device_role=device_role, status=planned_status, serial="987654", ) onboarding_kwargs = { "netdev_hostname": device_name, "netdev_nb_role_slug": "switch", "netdev_vendor": "Cisco", "netdev_model": "c2960", "netdev_nb_site_slug": self.site1.slug, "netdev_netmiko_device_type": "cisco_ios", "netdev_serial_number": "123456", "netdev_mgmt_ip_address": "192.0.2.10", "netdev_mgmt_ifname": "GigaEthernet0", "netdev_mgmt_pflen": 24, } nbk = NautobotKeeper(**onboarding_kwargs) nbk.ensure_device() self.assertIsInstance(nbk.device, Device) self.assertEqual(nbk.device.pk, device.pk) self.assertEqual(nbk.device.name, device_name) self.assertEqual(nbk.device.platform.slug, "cisco_ios") self.assertEqual(nbk.device.serial, "123456")
def test_ensure_interface_not_exist(self): """Verify ensure_interface function when the interface do not exist.""" onboarding_kwargs = { "netdev_hostname": "device1", "netdev_nb_role_slug": PLUGIN_SETTINGS["default_device_role"], "netdev_nb_role_color": PLUGIN_SETTINGS["default_device_role_color"], "netdev_vendor": "Cisco", "netdev_model": "CSR1000v", "netdev_nb_site_slug": self.site1.slug, "netdev_netmiko_device_type": "cisco_ios", "netdev_serial_number": "123456", "netdev_mgmt_ip_address": "192.0.2.10", "netdev_mgmt_ifname": "ge-0/0/0", "netdev_mgmt_pflen": 24, } nbk = NautobotKeeper(**onboarding_kwargs) nbk.ensure_device() self.assertIsInstance(nbk.nb_mgmt_ifname, Interface) self.assertEqual(nbk.nb_mgmt_ifname.name, "ge-0/0/0")
def run(self, onboarding_kwargs): """Ensure device is created with Nautobot Keeper.""" nb_k = NautobotKeeper(**onboarding_kwargs) nb_k.ensure_device() self.created_device = nb_k.device