diff --git a/changes/223.fixed b/changes/223.fixed new file mode 100644 index 00000000..69579552 --- /dev/null +++ b/changes/223.fixed @@ -0,0 +1 @@ +Fixed App initialization when `[grafana]` extra is not installed. diff --git a/docs/admin/release_notes/version_2.0.md b/docs/admin/release_notes/version_2.0.md index 28f8db3a..377c9670 100644 --- a/docs/admin/release_notes/version_2.0.md +++ b/docs/admin/release_notes/version_2.0.md @@ -2,13 +2,18 @@ # v2.0 Release Notes +## [v2.0.2 (2023-08-11)](https://github.com/nautobot/nautobot-plugin-chatops/releases/tag/v2.0.2) + +### Changed + +- [#233](https://github.com/nautobot/nautobot-plugin-chatops/pull/233) - Fixed App initialization when `[grafana]` extra is not installed. + ## [v2.0.1 (2023-08-08)](https://github.com/nautobot/nautobot-plugin-chatops/releases/tag/v2.0.1) ### Changed - [#228](https://github.com/nautobot/nautobot-plugin-chatops/issues/228) - Move Contributing Changelog Fragments higher in documentation - ## [v2.0.0 (2023-08-02)](https://github.com/nautobot/nautobot-plugin-chatops/releases/tag/v2.0.0) ### Added diff --git a/nautobot_chatops/integrations/grafana/helpers.py b/nautobot_chatops/integrations/grafana/helpers.py index 8e0c616e..67e3f551 100644 --- a/nautobot_chatops/integrations/grafana/helpers.py +++ b/nautobot_chatops/integrations/grafana/helpers.py @@ -2,13 +2,6 @@ from typing import List from termcolor import colored -from nautobot.dcim import models as dcim_models -from nautobot.ipam import models as ipam_models -from nautobot.extras import models as extra_models -from nautobot.tenancy import models as tenancy_models -from nautobot.virtualization import models as virtualization_models -from nautobot.circuits import models as circuit_models - from schema_enforcer import config from schema_enforcer.schemas.manager import SchemaManager from schema_enforcer.instances.file import InstanceFileManager @@ -23,17 +16,6 @@ ">": "greater-than", } -# Valid models to be used in Panel Variables as query options. If a model doesn't exist in -# this list, you cannot set or use the `query` field in a panel variable. -VALID_MODELS = ( - dcim_models, - ipam_models, - extra_models, - tenancy_models, - virtualization_models, - circuit_models, -) - def format_command(command: str) -> str: """_format_command_name will format the panel titles into a valid slash command. diff --git a/nautobot_chatops/integrations/grafana/models.py b/nautobot_chatops/integrations/grafana/models.py index 7143d7b1..9087eac8 100644 --- a/nautobot_chatops/integrations/grafana/models.py +++ b/nautobot_chatops/integrations/grafana/models.py @@ -3,9 +3,26 @@ from django.core.exceptions import ValidationError from django.core.serializers.json import DjangoJSONEncoder from django.utils.translation import gettext_lazy as _ -from nautobot.extras.utils import extras_features +from nautobot.circuits import models as circuit_models from nautobot.core.models.generics import PrimaryModel, OrganizationalModel -from nautobot_chatops.integrations.grafana.helpers import VALID_MODELS +from nautobot.dcim import models as dcim_models +from nautobot.extras import models as extra_models +from nautobot.extras.utils import extras_features +from nautobot.ipam import models as ipam_models +from nautobot.tenancy import models as tenancy_models +from nautobot.virtualization import models as virtualization_models + + +# Valid models to be used in Panel Variables as query options. If a model doesn't exist in +# this list, you cannot set or use the `query` field in a panel variable. +VALID_MODELS = ( + dcim_models, + ipam_models, + extra_models, + tenancy_models, + virtualization_models, + circuit_models, +) @extras_features( diff --git a/nautobot_chatops/integrations/grafana/worker.py b/nautobot_chatops/integrations/grafana/worker.py index 5ddbc850..88226377 100644 --- a/nautobot_chatops/integrations/grafana/worker.py +++ b/nautobot_chatops/integrations/grafana/worker.py @@ -12,8 +12,7 @@ from nautobot.utilities.querysets import RestrictedQuerySet from nautobot_chatops.dispatchers import Dispatcher from nautobot_chatops.workers import handle_subcommands, add_subcommand -from nautobot_chatops.integrations.grafana.models import Panel, PanelVariable -from nautobot_chatops.integrations.grafana.helpers import VALID_MODELS +from nautobot_chatops.integrations.grafana.models import Panel, PanelVariable, VALID_MODELS from nautobot_chatops.integrations.grafana.grafana import ( SLASH_COMMAND, LOGGER, diff --git a/nautobot_chatops/urls.py b/nautobot_chatops/urls.py index 63c88033..b84f4774 100644 --- a/nautobot_chatops/urls.py +++ b/nautobot_chatops/urls.py @@ -1,4 +1,5 @@ """Django urlpatterns declaration for nautobot_chatops plugin.""" +import logging from django.urls import path @@ -17,7 +18,14 @@ AccessGrantBulkDeleteView, ) -from nautobot_chatops.integrations.grafana.urls import urlpatterns as grafana_urlpatterns +try: + from nautobot_chatops.integrations.grafana.urls import urlpatterns as grafana_urlpatterns +# pylint: disable-next=broad-except +except Exception: + grafana_urlpatterns = [] + logger = logging.getLogger(__name__) + logger.warning("Grafana ChatOps integration is not available.", exc_info=True) + urlpatterns = [ path("", NautobotHomeView.as_view(), name="home"), diff --git a/pyproject.toml b/pyproject.toml index b1fbb00f..0cd34045 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nautobot-chatops" -version = "2.0.1" +version = "2.0.2" description = "A plugin providing chatbot capabilities for Nautobot" authors = ["Network to Code, LLC "] readme = "README.md"