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 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() 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) diff --git a/nautobot_ssot/integrations/servicenow/jobs.py b/nautobot_ssot/integrations/servicenow/jobs.py index f8bcdbf5..edad6637 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 @@ -16,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.") @@ -79,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):