Skip to content

Commit

Permalink
netbox 3.7 support
Browse files Browse the repository at this point in the history
  • Loading branch information
amyasnikov committed Jan 17, 2024
1 parent e9599f5 commit 9aa1fc1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
netbox_version: [v3.5.9, v3.6.5]
netbox_version: [v3.5.9, v3.6.9, v3.7.1]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ known_first_party = ["validity"]
[tool.flake8]
max-line-length = 120
exclude = ["migrations", "__pycache__"]
per-file-ignores = ["__init__.py:F401"]
per-file-ignores = ["__init__.py:F401", "validity/netbox_changes.py:F401"]
extend-ignore = "E203"


Expand Down
5 changes: 3 additions & 2 deletions validity/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
ExportTemplatesMixin,
NetBoxModel,
RestrictedQuerySet,
WebhooksMixin,
)

from validity.netbox_changes import EventRulesMixin


logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -81,7 +82,7 @@ class BaseReadOnlyModel(
CustomLinksMixin,
CustomValidationMixin,
ExportTemplatesMixin,
WebhooksMixin,
EventRulesMixin,
models.Model,
):
created = models.DateTimeField(auto_now_add=True, blank=True, null=True)
Expand Down
12 changes: 11 additions & 1 deletion validity/netbox_changes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
"""
This module is going to contain all duct tape stuff which is required to support
newer versions of NetBox
different versions of NetBox together
"""
from validity import config


DEVICE_ROLE_RELATION = "device_role" if config.netbox_version < "3.6.0" else "role"


if config.netbox_version < "3.7.0":
from extras.webhooks import enqueue_object
from netbox.context import webhooks_queue as events_queue
from netbox.models.features import WebhooksMixin as EventRulesMixin
else:
from extras.events import enqueue_object
from netbox.context import events_queue
from netbox.models.features import EventRulesMixin
5 changes: 2 additions & 3 deletions validity/scripts/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
from extras.choices import ObjectChangeActionChoices
from extras.models import Tag
from extras.scripts import BooleanVar, MultiObjectVar, ObjectVar
from extras.webhooks import enqueue_object
from netbox.context import webhooks_queue

import validity
from validity.choices import ExplanationVerbosityChoices
Expand All @@ -27,6 +25,7 @@
VDataSource,
VDevice,
)
from validity.netbox_changes import enqueue_object, events_queue
from validity.utils.misc import datasource_sync, null_request
from .script_data import RunTestsScriptData, ScriptDataMixin
from .variables import VerbosityVar
Expand Down Expand Up @@ -151,7 +150,7 @@ def run_tests_for_selector(

def fire_report_webhook(self, report_id: int) -> None:
report = ComplianceReport.objects.filter(pk=report_id).annotate_result_stats().count_devices_and_tests().first()
queue = webhooks_queue.get()
queue = events_queue.get()
enqueue_object(queue, report, self.request.user, self.request.id, ObjectChangeActionChoices.ACTION_CREATE)

def save_to_db(self, results: Iterable[ComplianceTestResult], report: ComplianceReport | None) -> None:
Expand Down

0 comments on commit 9aa1fc1

Please sign in to comment.