|
3 | 3 | """ |
4 | 4 |
|
5 | 5 | import json |
| 6 | +import logging |
6 | 7 | import os |
7 | 8 | import re |
8 | 9 | import sys |
@@ -353,7 +354,8 @@ def _get_by_path(self, root: dict | list = None, items: list = None, resp: list |
353 | 354 | items.pop(0) |
354 | 355 |
|
355 | 356 | 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: |
357 | 359 | self._get_by_path(root[int(item)], items, resp) |
358 | 360 | #else: |
359 | 361 | # 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 |
449 | 451 | elif key.label == "replace": |
450 | 452 | self.logger.debug(f"REPLACE: {parent_key} -- {key} -- {compared.get(key)}") |
451 | 453 | 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}") |
452 | 457 | else: |
453 | 458 | self.logger.debug(f"UNKNOWN KEY: {key}") |
454 | 459 | 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 |
492 | 497 | self.logger.debug(f"DATA_NEW: {data_new}") |
493 | 498 |
|
494 | 499 | 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 | + |
496 | 509 | same = data_old['site'][old_site]['kind'] == data_new['site'][new_site]['kind'] |
497 | 510 | secure_mesh = data_old['site'][old_site]['kind'] == "securemesh_site" and data_new['site'][new_site]['kind'] == "securemesh_site_v2" |
498 | 511 |
|
|
0 commit comments