Пример #1
0
    def test_ensure_device_role_assigned(self):
        """Verify ensure_device_role function when DeviceRole exist and is already assigned."""
        device_role = DeviceRole.objects.create(name="Firewall",
                                                slug="firewall")

        onboarding_kwargs = {
            "netdev_hostname": "device1",
            "netdev_nb_role_slug": device_role.slug,
            "netdev_nb_role_color":
            PLUGIN_SETTINGS["default_device_role_color"],
            "netdev_vendor": "Cisco",
            "netdev_nb_site_slug": self.site1.slug,
        }

        nbk = NautobotKeeper(**onboarding_kwargs)
        nbk.ensure_device_role(create_device_role=True)

        self.assertEqual(nbk.nb_device_role, device_role)
Пример #2
0
    def test_ensure_device_role_not_exist(self):
        """Verify ensure_device_role function when DeviceRole does not already exist."""
        test_role_name = "mytestrole"

        onboarding_kwargs = {
            "netdev_hostname": "device1",
            "netdev_nb_role_slug": test_role_name,
            "netdev_nb_role_color":
            PLUGIN_SETTINGS["default_device_role_color"],
            "netdev_vendor": "Cisco",
            "netdev_nb_site_slug": self.site1.slug,
        }

        nbk = NautobotKeeper(**onboarding_kwargs)

        with self.assertRaises(OnboardException) as exc_info:
            nbk.ensure_device_role(create_device_role=False)
            self.assertEqual(exc_info.exception.message,
                             f"ERROR device role not found: {test_role_name}")
            self.assertEqual(exc_info.exception.reason, "fail-config")

        nbk.ensure_device_role(create_device_role=True)
        self.assertIsInstance(nbk.nb_device_role, DeviceRole)
        self.assertEqual(nbk.nb_device_role.slug, slugify(test_role_name))