Skip to content

Commit eab981b

Browse files
committed
fix logic in compare to check if new site has additional data inserted. Skip those inserted items in compare.
1 parent df4ca35 commit eab981b

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/api.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import json
6+
import logging
67
import os
78
import re
89
import sys
@@ -353,7 +354,8 @@ def _get_by_path(self, root: dict | list = None, items: list = None, resp: list
353354
items.pop(0)
354355

355356
if isinstance(root, list) and item.isdigit():
356-
if int(item) <= len(root):
357+
#Skip inserted elements on new site
358+
if int(item) <= len(root)-1:
357359
self._get_by_path(root[int(item)], items, resp)
358360
#else:
359361
# self._get_by_path(root[len(root)-1], items, resp)
@@ -449,6 +451,9 @@ def _get_keys(self, parent_key: str = None, compared: dict = None, resp: list[st
449451
elif key.label == "replace":
450452
self.logger.debug(f"REPLACE: {parent_key} -- {key} -- {compared.get(key)}")
451453
resp.append(f"{parent_key}" if parent_key else f"{key}")
454+
#elif key.label == "insert":
455+
# self.logger.info(f"INSERT: {parent_key} -- {key} -- {compared.get(key)}")
456+
#resp.append(f"{parent_key}" if parent_key else f"{key}")
452457
else:
453458
self.logger.debug(f"UNKNOWN KEY: {key}")
454459
elif isinstance(compared.get(key), list):
@@ -492,7 +497,15 @@ def compare(self, old_site: str = None, old_file: str = None, new_site: str = No
492497
self.logger.debug(f"DATA_NEW: {data_new}")
493498

494499
if data_old and data_new:
495-
# Only support comparison if site type is of same kind or if source site is secure mesh v1 and destination site is seure mesh v2
500+
# Only support comparison if site type is of same kind or if source site is secure mesh v1 and destination site is secure mesh v2
501+
if not new_site in data_new['site']:
502+
self.logger.info(f"Comparing new site <{new_site}> not found in file {new_file}.")
503+
return None
504+
505+
if not old_site in data_old['site']:
506+
self.logger.info(f"Comparing new site <{old_site}> not found in file {old_file}.")
507+
return None
508+
496509
same = data_old['site'][old_site]['kind'] == data_new['site'][new_site]['kind']
497510
secure_mesh = data_old['site'][old_site]['kind'] == "securemesh_site" and data_new['site'][new_site]['kind'] == "securemesh_site_v2"
498511

lib/const.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@
5858
API_PROCESSORS = ["site", "vs", "lb", "proxy", "originpool", "bgp", "smg", "cloudconnect", "segment"]
5959
PROCESSOR_PACKAGE = "lib.processor"
6060
CSV_EXPORT_KEYS = ["spec", "efp", "fpp", "bgp", "smg", "spoke", "segments", "dc_cluster_group", "nodes", "namespaces"]
61-
EXCLUDE_COMPARE_ATTRIBUTES = ["serial", "asset_tag", "hw-serial-number", "spec/site_to_site_ipsec_connectivity"]
6261
COMPARE_REGEX_HW_INFO_CPU_FLAGS = "nodes/.*/hw_info/cpu/flags"
6362
COMPARE_REGEX_HW_INFO_USB = "nodes/.*/hw_info/usb"
63+
EXCLUDE_COMPARE_ATTRIBUTES = ["serial", "asset_tag", "hw-serial-number", "spec/site_to_site_ipsec_connectivity",
64+
COMPARE_REGEX_HW_INFO_USB]
6465
SITE_OBJECT_TYPE_SMS = "sms"
6566
SITE_OBJECT_TYPE_LEGACY = "legacy"
6667
SITE_OBJECT_PROCESSORS = ["site_details", "efp", "fpp", "dc_cluster_group", "cloudlink", "node_interfaces", "hw_info",

0 commit comments

Comments
 (0)