From 94896426bd314bcd6b7fd4863ebda7f5130837d0 Mon Sep 17 00:00:00 2001 From: Jan Snasel Date: Wed, 9 Aug 2023 08:00:27 +0000 Subject: [PATCH 1/5] fix: Use App without extras installed Currently, when installing without extras, ChatOps App fails to initialize. What's changed: - Moved Grafana VALID_MODELS to grafana models to avoid unnecessary import. - Encapsulate importing grafana urls to `try ... except` block --- .../integrations/grafana/helpers.py | 19 ----------------- .../integrations/grafana/models.py | 21 +++++++++++++++++-- .../integrations/grafana/worker.py | 3 +-- nautobot_chatops/urls.py | 10 ++++++++- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/nautobot_chatops/integrations/grafana/helpers.py b/nautobot_chatops/integrations/grafana/helpers.py index 8e0c616e..f0f50682 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,18 +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..678cbb28 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"), From e5f47a263061b5c2abd75af3daf786a4f467ba30 Mon Sep 17 00:00:00 2001 From: Jan Snasel Date: Wed, 9 Aug 2023 08:14:20 +0000 Subject: [PATCH 2/5] fix: Formatting --- nautobot_chatops/integrations/grafana/helpers.py | 1 + nautobot_chatops/urls.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/nautobot_chatops/integrations/grafana/helpers.py b/nautobot_chatops/integrations/grafana/helpers.py index f0f50682..67e3f551 100644 --- a/nautobot_chatops/integrations/grafana/helpers.py +++ b/nautobot_chatops/integrations/grafana/helpers.py @@ -16,6 +16,7 @@ ">": "greater-than", } + def format_command(command: str) -> str: """_format_command_name will format the panel titles into a valid slash command. diff --git a/nautobot_chatops/urls.py b/nautobot_chatops/urls.py index 678cbb28..b84f4774 100644 --- a/nautobot_chatops/urls.py +++ b/nautobot_chatops/urls.py @@ -25,7 +25,7 @@ grafana_urlpatterns = [] logger = logging.getLogger(__name__) logger.warning("Grafana ChatOps integration is not available.", exc_info=True) - + urlpatterns = [ path("", NautobotHomeView.as_view(), name="home"), From bc377273e563793c491151cbbe6d28af2ac29684 Mon Sep 17 00:00:00 2001 From: Jan Snasel Date: Wed, 9 Aug 2023 08:16:05 +0000 Subject: [PATCH 3/5] fix: Add change info --- changes/223.fixed | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/223.fixed 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. From 73a41166ff454d1384326cd3045c2a8109dc5cd8 Mon Sep 17 00:00:00 2001 From: Stephen Kiely Date: Wed, 9 Aug 2023 15:45:04 -0500 Subject: [PATCH 4/5] Prep for release v2.0.2 --- docs/admin/release_notes/version_2.0.md | 7 ++++++- pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/admin/release_notes/version_2.0.md b/docs/admin/release_notes/version_2.0.md index 28f8db3a..b48e76c5 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-09)](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/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" From 88c9f670339e323e14f5393b3cdce0f50608ae73 Mon Sep 17 00:00:00 2001 From: Stephen Kiely Date: Fri, 11 Aug 2023 08:06:11 -0500 Subject: [PATCH 5/5] Update date to match release date. --- docs/admin/release_notes/version_2.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/admin/release_notes/version_2.0.md b/docs/admin/release_notes/version_2.0.md index b48e76c5..377c9670 100644 --- a/docs/admin/release_notes/version_2.0.md +++ b/docs/admin/release_notes/version_2.0.md @@ -2,7 +2,7 @@ # v2.0 Release Notes -## [v2.0.2 (2023-08-09)](https://github.com/nautobot/nautobot-plugin-chatops/releases/tag/v2.0.2) +## [v2.0.2 (2023-08-11)](https://github.com/nautobot/nautobot-plugin-chatops/releases/tag/v2.0.2) ### Changed