Skip to content

Commit

Permalink
Merge pull request #60 from chadell/release-v1.2.0
Browse files Browse the repository at this point in the history
Release v1.2.0
  • Loading branch information
chadell authored Oct 5, 2022
2 parents da6a708 + d3c95ad commit cdb05c7
Show file tree
Hide file tree
Showing 17 changed files with 1,443 additions and 1,221 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9"]
nautobot-version: ["1.0.3", "1.1.4"]
python-version: ["3.7", "3.8", "3.9"]
nautobot-version: ["1.2.11", "stable"]
runs-on: "ubuntu-20.04"
env:
INVOKE_NAUTOBOT_SSOT_PYTHON_VER: "${{ matrix.python-version }}"
Expand Down
17 changes: 14 additions & 3 deletions development/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ ARG PYTHON_VER
ARG NAUTOBOT_VER
FROM ghcr.io/nautobot/nautobot-dev:${NAUTOBOT_VER}-py${PYTHON_VER}

ARG NAUTOBOT_VER

ENV prometheus_multiproc_dir=/prom_cache

ARG NAUTOBOT_ROOT=/opt/nautobot
Expand All @@ -19,17 +21,26 @@ RUN poetry config virtualenvs.create false \
# Install Nautobot Plugin
# -------------------------------------------------------------------------------------

WORKDIR /source
WORKDIR /tmp/install

# Copy in only pyproject.toml/poetry.lock to help with caching this layer if no updates to dependencies
COPY poetry.lock pyproject.toml /source/
COPY poetry.lock pyproject.toml /tmp/install/

# Add the version of Nautobot to the pyproject toml for testing
RUN if [ "$NAUTOBOT_VER" = "stable" ]; \
then poetry add nautobot@latest; \
else poetry add nautobot==$NAUTOBOT_VER; \
fi

# --no-root declares not to install the project package since we're wanting to take advantage of caching dependency installation
# and the project is copied in and installed after this step
RUN poetry install --no-interaction --no-ansi --no-root

# Copy in the rest of the source code and install local Nautobot plugin
WORKDIR /source
COPY . /source
RUN poetry install --no-interaction --no-ansi
# Copy updated Poetry files to override the Poetry files from the project.
# This will make sure that the correct Nautobot version is used.
RUN cp /tmp/install/* /source/ && poetry install --no-interaction --no-ansi

COPY development/nautobot_config.py /opt/nautobot/nautobot_config.py
10 changes: 10 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## v1.2.0 - 2022-09-30

### Fixed

- [#58](https://github.com/nautobot/nautobot-plugin-ssot/pull/58) - Change `message` and `object_repr` from 200 `CharField` field, to a `TextField`

### Changed

- [#56](https://github.com/nautobot/nautobot-plugin-ssot/pull/56) - Drop Python 3.6 support

## v1.1.2 - 2022-05-09

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion nautobot_ssot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Plugin declaration for nautobot_ssot."""

# flake8: noqa
try:
from importlib import metadata
except ImportError:
Expand Down
4 changes: 2 additions & 2 deletions nautobot_ssot/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .models import Sync, SyncLogEntry


class SyncFilter(BaseFilterSet):
class SyncFilterSet(BaseFilterSet):
"""Filter capabilities for SyncOverview instances."""

class Meta:
Expand All @@ -18,7 +18,7 @@ class Meta:
fields = ["dry_run", "job_result"]


class SyncLogEntryFilter(BaseFilterSet):
class SyncLogEntryFilterSet(BaseFilterSet):
"""Filter capabilities for SyncLogEntry instances."""

q = django_filters.CharFilter(method="search", label="Search")
Expand Down
9 changes: 7 additions & 2 deletions nautobot_ssot/jobs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import traceback
import tracemalloc
from typing import Iterable
from packaging.version import Version

from django.forms import HiddenInput
from django.templatetags.static import static
Expand All @@ -16,6 +17,7 @@
from diffsync.enum import DiffSyncFlags
import structlog

from nautobot import __version__ as nautobot_version
from nautobot.extras.jobs import BaseJob, BooleanVar

from nautobot_ssot.choices import SyncLogEntryActionChoices
Expand Down Expand Up @@ -268,9 +270,12 @@ def __init__(self):
# Default diffsync flags. You can overwrite them at any time.
self.diffsync_flags = DiffSyncFlags.CONTINUE_ON_FAILURE | DiffSyncFlags.LOG_UNCHANGED_RECORDS

def as_form(self, data=None, files=None, initial=None):
def as_form(self, data=None, files=None, initial=None, approval_view=False):
"""Render this instance as a Django form for user inputs, including a "Dry run" field."""
form = super().as_form(data=data, files=files, initial=initial)
if Version(nautobot_version) < Version("1.2"):
form = super().as_form(data=data, files=files, initial=initial)
else:
form = super().as_form(data=data, files=files, initial=initial, approval_view=approval_view)
# Set the "dry_run" widget's initial value based on our Meta attribute, if any
form.fields["dry_run"].initial = getattr(self.Meta, "dry_run_default", True)
# Hide the "commit" widget to reduce user confusion
Expand Down
3 changes: 3 additions & 0 deletions nautobot_ssot/jobs/examples.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""Sample data-source and data-target Jobs."""
# Skip colon check for multiple statements on one line.
# flake8: noqa: E701

from typing import Optional, Mapping
from uuid import UUID
from django.contrib.contenttypes.models import ContentType
Expand Down
23 changes: 23 additions & 0 deletions nautobot_ssot/migrations/0003_alter_synclogentry_textfields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.15 on 2022-09-27 13:52

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("nautobot_ssot", "0002_performance_metrics"),
]

operations = [
migrations.AlterField(
model_name="synclogentry",
name="message",
field=models.TextField(blank=True),
),
migrations.AlterField(
model_name="synclogentry",
name="object_repr",
field=models.TextField(blank=True, default="", editable=False),
),
]
4 changes: 2 additions & 2 deletions nautobot_ssot/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ class SyncLogEntry(BaseModel):
synced_object_id = models.UUIDField(blank=True, null=True)
synced_object = GenericForeignKey(ct_field="synced_object_type", fk_field="synced_object_id")

object_repr = models.CharField(max_length=200, blank=True, default="", editable=False)
object_repr = models.TextField(blank=True, default="", editable=False)

message = models.CharField(max_length=511, blank=True)
message = models.TextField(blank=True)

class Meta:
"""Metaclass attributes of SyncLogEntry."""
Expand Down
6 changes: 6 additions & 0 deletions nautobot_ssot/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
"""Unit tests for nautobot_ssot plugin."""

from django.conf import settings

if "job_logs" in settings.DATABASES:
settings.DATABASES["job_logs"] = settings.DATABASES["job_logs"].copy()
settings.DATABASES["job_logs"]["TEST"] = {"MIRROR": "default"}
16 changes: 16 additions & 0 deletions nautobot_ssot/tests/jobs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Override of classes."""
from nautobot.extras.jobs import Job
from nautobot_ssot.jobs import DataSource as _DataSource, DataTarget as _DataTarget
from nautobot_ssot.jobs.base import DataSyncBaseJob as _DataSyncBaseJob


class DataSyncBaseJob(_DataSyncBaseJob, Job): # pylint: disable=abstract-method
"""DataSyncBaseJob import of the sync base job and Nautobot Job."""


class DataSource(_DataSource, Job): # pylint: disable=abstract-method
"""DataSource import of the DataSource job and Nautobot Job."""


class DataTarget(_DataTarget, Job): # pylint: disable=abstract-method
"""DataSyncBaseJob import of the DataTarget job and Nautobot Job."""
18 changes: 14 additions & 4 deletions nautobot_ssot/tests/test_jobs.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
"""Test the Job classes in nautobot_ssot."""
import os.path
from unittest.mock import Mock
import uuid
from django.contrib.contenttypes.models import ContentType

from django.forms import HiddenInput
from django.test import TestCase
from django.test import override_settings

# from django.test import TestCase

from nautobot.extras.models import JobResult
from nautobot.utilities.testing import TransactionTestCase

from nautobot_ssot.choices import SyncLogEntryActionChoices, SyncLogEntryStatusChoices
from nautobot_ssot.jobs.base import DataSyncBaseJob
from nautobot_ssot.jobs import DataSource, DataTarget
from nautobot_ssot.tests.jobs import DataSyncBaseJob, DataSource, DataTarget
from nautobot_ssot.models import SyncLogEntry


class BaseJobTestCase(TestCase):
@override_settings(JOBS_ROOT=os.path.join(os.path.dirname(__file__), "jobs"))
class BaseJobTestCase(TransactionTestCase):
"""Test the DataSyncBaseJob class."""

job_class = DataSyncBaseJob
databases = (
"default",
"job_logs",
)

def setUp(self):
"""Per-test setup."""
Expand All @@ -29,6 +37,8 @@ def setUp(self):
job_id=uuid.uuid4(),
)

# name=self.job.class_path,

self.job.load_source_adapter = lambda *x, **y: None
self.job.load_target_adapter = lambda *x, **y: None

Expand Down
6 changes: 6 additions & 0 deletions nautobot_ssot/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def test_data_source_target_view_with_permission(self):
200,
)

def test_has_advanced_tab(self):
pass


class SyncLogEntryViewsTestCase(ViewTestCases.ListObjectsViewTestCase): # pylint: disable=too-many-ancestors
"""Test views related to the SyncLogEntry model."""
Expand Down Expand Up @@ -139,3 +142,6 @@ def setUpTestData(cls):
object_repr="Placeholder",
message="Log message",
)

def test_has_advanced_tab(self):
pass
8 changes: 4 additions & 4 deletions nautobot_ssot/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from nautobot.utilities.paginator import EnhancedPaginator
from nautobot.utilities.views import ContentTypePermissionRequiredMixin

from .filters import SyncFilter, SyncLogEntryFilter
from .filters import SyncFilterSet, SyncLogEntryFilterSet
from .forms import SyncFilterForm, SyncLogEntryFilterForm
from .jobs import get_data_jobs, DataSource, DataTarget
from .models import Sync, SyncLogEntry
Expand Down Expand Up @@ -97,7 +97,7 @@ class SyncListView(ObjectListView):
"""View for listing Sync records."""

queryset = Sync.annotated_queryset()
filterset = SyncFilter
filterset = SyncFilterSet
filterset_form = SyncFilterForm
table = SyncTable
action_buttons = []
Expand Down Expand Up @@ -155,7 +155,7 @@ class SyncLogEntriesView(ObjectListView):
"""View for SyncLogEntries associated with a given Sync."""

queryset = SyncLogEntry.objects.all()
filterset = SyncLogEntryFilter
filterset = SyncLogEntryFilterSet
filterset_form = SyncLogEntryFilterForm
table = SyncLogEntryTable
action_buttons = []
Expand All @@ -177,7 +177,7 @@ class SyncLogEntryListView(ObjectListView):
"""View for listing SyncLogEntry records."""

queryset = SyncLogEntry.objects.all()
filterset = SyncLogEntryFilter
filterset = SyncLogEntryFilterSet
filterset_form = SyncLogEntryFilterForm
table = SyncLogEntryTable
action_buttons = []
Expand Down
Loading

0 comments on commit cdb05c7

Please sign in to comment.