nautobot-app-ssot icon indicating copy to clipboard operation
nautobot-app-ssot copied to clipboard

SNOW SSoT Caching

Open itdependsnetworks opened this issue 1 year ago • 2 comments

Environment

  • Python version: 3.12
  • Nautobot version: 2.3
  • nautobot-ssot version: 2.8.0

Expected Behavior

  • Not to cache cmdb_ci / sys_id between runs
  • Not to use old cmdb_ci / sys_id when creating interface records

Observed Behavior

  • In job one, ssot collects a sys_id
  • In between the device is deleted
  • in job two, the memory from job 1 is used, that has the cached sys_id for creating interfaces only (e.g. not to create the device, which is created properly created) points the FK relationship to the old sys_id, leaving it in no mans land

Steps to Reproduce

  1. Sync job
  2. Delete device in snow
  3. Run job in same worker with same memory foot print

Ways to work around

Set --max-tasks-per-child on celery worker.

itdependsnetworks avatar Aug 22 '24 14:08 itdependsnetworks

ServiceNowCRUDMixin._sys_id_cache and ServiceNowDiffSync.objects_to_delete should both become instance attributes and/or be explicitly emptied out at job start time.

glennmatthews avatar Aug 22 '24 14:08 glennmatthews

@glennmatthews Would something like this work?

class ServiceNowCRUDMixin:
    """Mixin class for all ServiceNow models, to support CRUD operations based on mappings.yaml."""

    _sys_id_cache = {}
    """Dict of table -> column_name -> value -> sys_id."""

    def model_rebuild(cls):
        super().model_rebuild()
        cls._sys_id_cache = {}

we are calling model_rebuild at the end of the file anyway.

itdependsnetworks avatar Aug 22 '24 21:08 itdependsnetworks