From c72eaa32fc05932457409a80045f766bb4f4b5ba Mon Sep 17 00:00:00 2001 From: Przemek Rogala Date: Wed, 2 Oct 2024 17:12:14 +0100 Subject: [PATCH 1/6] Fix infite loop when resolving location parents. --- .../integrations/servicenow/diffsync/adapter_nautobot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nautobot_ssot/integrations/servicenow/diffsync/adapter_nautobot.py b/nautobot_ssot/integrations/servicenow/diffsync/adapter_nautobot.py index a31469f4..c2bc4680 100644 --- a/nautobot_ssot/integrations/servicenow/diffsync/adapter_nautobot.py +++ b/nautobot_ssot/integrations/servicenow/diffsync/adapter_nautobot.py @@ -63,6 +63,7 @@ def load_locations(self): ancestor = self.site_filter.parent while ancestor is not None: locations.insert(0, ancestor) + ancestor = ancestor.parent else: locations = Location.objects.all() From d05f1d6c92560dc77d4a92cb7d06a0f4c2d567d2 Mon Sep 17 00:00:00 2001 From: Przemek Rogala Date: Wed, 2 Oct 2024 17:13:10 +0100 Subject: [PATCH 2/6] Replace region reference with parent. --- .../integrations/servicenow/diffsync/adapter_servicenow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nautobot_ssot/integrations/servicenow/diffsync/adapter_servicenow.py b/nautobot_ssot/integrations/servicenow/diffsync/adapter_servicenow.py index 3ba5f94c..591864e3 100644 --- a/nautobot_ssot/integrations/servicenow/diffsync/adapter_servicenow.py +++ b/nautobot_ssot/integrations/servicenow/diffsync/adapter_servicenow.py @@ -81,7 +81,7 @@ def load(self): # Load all Nautobot ancestor records as well # This is so in case the Nautobot ancestors exist in ServiceNow but aren't linked to the record, # we link them together instead of creating new, redundant ancestor records in ServiceNow. - ancestor = self.site_filter.region + ancestor = self.site_filter.parent while ancestor is not None: try: self.get(self.location, ancestor.name) From 56a6321263846f363472a414ab2ccead5301b925 Mon Sep 17 00:00:00 2001 From: Przemek Rogala Date: Wed, 2 Oct 2024 17:13:32 +0100 Subject: [PATCH 3/6] Disable unused job flag. --- nautobot_ssot/integrations/servicenow/jobs.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nautobot_ssot/integrations/servicenow/jobs.py b/nautobot_ssot/integrations/servicenow/jobs.py index f8bcdbf5..5017d4f9 100644 --- a/nautobot_ssot/integrations/servicenow/jobs.py +++ b/nautobot_ssot/integrations/servicenow/jobs.py @@ -21,7 +21,8 @@ class ServiceNowDataTarget(DataTarget, Job): # pylint: disable=abstract-method debug = BooleanVar(description="Enable for more verbose logging.") - delete_records = BooleanVar(description="Delete synced records from ServiceNow if not present in Nautobot") + # TODO: Implement or remove + # delete_records = BooleanVar(description="Delete synced records from ServiceNow if not present in Nautobot") site_filter = ObjectVar( description="Only sync records belonging to a single Site.", From 6366c9c23014b9835bd36a2fe7f80e7bcbfc0dd9 Mon Sep 17 00:00:00 2001 From: Przemek Rogala Date: Thu, 3 Oct 2024 18:07:10 +0100 Subject: [PATCH 4/6] Implement SNOW SSOT 'delete_records' flag. --- nautobot_ssot/integrations/servicenow/jobs.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nautobot_ssot/integrations/servicenow/jobs.py b/nautobot_ssot/integrations/servicenow/jobs.py index 5017d4f9..c3e5a175 100644 --- a/nautobot_ssot/integrations/servicenow/jobs.py +++ b/nautobot_ssot/integrations/servicenow/jobs.py @@ -1,5 +1,6 @@ """ServiceNow Data Target Job.""" +from diffsync.enum import DiffSyncFlags from django.core.exceptions import ObjectDoesNotExist from django.templatetags.static import static from django.urls import reverse @@ -21,8 +22,7 @@ class ServiceNowDataTarget(DataTarget, Job): # pylint: disable=abstract-method debug = BooleanVar(description="Enable for more verbose logging.") - # TODO: Implement or remove - # delete_records = BooleanVar(description="Delete synced records from ServiceNow if not present in Nautobot") + delete_records = BooleanVar(description="Delete synced records from ServiceNow if not present in Nautobot") site_filter = ObjectVar( description="Only sync records belonging to a single Site.", @@ -80,11 +80,14 @@ def load_target_adapter(self): self.target_adapter = ServiceNowDiffSync(client=snc, job=self, sync=self.sync, site_filter=self.site_filter) self.target_adapter.load() - def run(self, dryrun, memory_profiling, site_filter, *args, **kwargs): # pylint:disable=arguments-differ + def run(self, dryrun, memory_profiling, delete_records, site_filter, *args, **kwargs): # pylint:disable=arguments-differ """Run sync.""" self.dryrun = dryrun self.memory_profiling = memory_profiling self.site_filter = site_filter + self.delete_records = delete_records + if not self.delete_records: + self.diffsync_flags |= DiffSyncFlags.SKIP_UNMATCHED_DST super().run(dryrun, memory_profiling, *args, **kwargs) def lookup_object(self, model_name, unique_id): From 427384700d0b79f406f01bba6847bc2ae7203347 Mon Sep 17 00:00:00 2001 From: Przemek Rogala Date: Thu, 14 Nov 2024 16:39:32 +0000 Subject: [PATCH 5/6] Add change fragments. --- changes/449.added | 1 + changes/449.fixed | 1 + 2 files changed, 2 insertions(+) create mode 100644 changes/449.added create mode 100644 changes/449.fixed diff --git a/changes/449.added b/changes/449.added new file mode 100644 index 00000000..fa41a93b --- /dev/null +++ b/changes/449.added @@ -0,0 +1 @@ +Add `delete_records` flag to the ServiceNow DataTarget job \ No newline at end of file diff --git a/changes/449.fixed b/changes/449.fixed new file mode 100644 index 00000000..b4be9627 --- /dev/null +++ b/changes/449.fixed @@ -0,0 +1 @@ +Fix logic used for loading location records to make ServiceNow SSoT Nautobot 2.x compatible \ No newline at end of file From e039a96f6014453cd21a6ed1182fa205700a67b5 Mon Sep 17 00:00:00 2001 From: Przemek Rogala Date: Wed, 20 Nov 2024 15:11:37 +0000 Subject: [PATCH 6/6] Fix linting error. --- nautobot_ssot/integrations/servicenow/jobs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nautobot_ssot/integrations/servicenow/jobs.py b/nautobot_ssot/integrations/servicenow/jobs.py index c3e5a175..edad6637 100644 --- a/nautobot_ssot/integrations/servicenow/jobs.py +++ b/nautobot_ssot/integrations/servicenow/jobs.py @@ -17,7 +17,7 @@ name = "SSoT - ServiceNow" # pylint: disable=invalid-name -class ServiceNowDataTarget(DataTarget, Job): # pylint: disable=abstract-method +class ServiceNowDataTarget(DataTarget, Job): # pylint: disable=abstract-method, too-many-instance-attributes """Job syncing data from Nautobot to ServiceNow.""" debug = BooleanVar(description="Enable for more verbose logging.")