Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: multi-level snapshot comparison and config parser refactor #128

Merged
merged 16 commits into from
Aug 9, 2024

Conversation

alperenkose
Copy link
Collaborator

@alperenkose alperenkose commented Dec 5, 2023

Description

This PR enhances snapshot comparison by allowing properties to be filtered on different levels of the snapshots.
missing/added comparison fields are also filtered according to the properties set.
It includes refactoring of ConfigParser class providing usable static methods for SnapshotComparison.

Motivation and Context

It fixes the issue #108 and complements the draft #109 PR.

In addition to the mentioned issue, considering the below snapshots (snapshot-1 and snapshot-2), it makes it possible to compare/exclude fields on different levels. See all possible examples below:

        {"license": {
            "properties": ["PAN-DB URL Filtering"]  # comparison for parent level
        }},
        {"license": {
            "properties": ["!Logging Service"]  # also support if property exists in different levels in different dicts
        }},
        {"license": {
            "properties": ["issued", "PAN-DB URL Filtering"]  # multi-level "AND" operation (combination with parent) for properties is not supported on purpose - "PAN-DB URL Filtering" diff will be made for all its attributes since its the parent
        }},

        # 1st and 2nd level keys
        {"license": {
            "properties": ["!_Log_Storage_TB"]
        }},
        {"license": {
            "properties": ["_Log_Storage_TB"]
        }},
        {"license": {
            "properties": ["_Log_Storage_TB","issued"]
        }},
        {"license": {
            "properties": ["issued", "!logtype"]
        }},
        {"license": {
            "properties": ["serial", "!logtype"]
        }},
        {"license": {
            "properties": ["custom"]
        }},
        {"license": {
            "properties": ["!custom"]
        }},
        {"license": {
            "properties": ["alogging"]
        }},
        {"license": {
            "properties": ["blogging"]
        }},
        {"license": {
            "properties": ["something"]  # since no such key is there it passes - works
        }},
        {"license": {
            "properties": ["serial", "non-existing"] # compare only requested
        }},
        {"license": {
            "properties": ["all"]
        }},
        {"license": {
            "properties": ["!issued", "all"] # compare all except
        }},
        {"license": {
            "properties": ["!logtype"]
        }},
        {"license": {
            "properties": ["!Logging Service", "issued"]
        }},

snapshot-1

{
  "license": {
    "Logging Service": {
      "authcode": null,
      "custom": {
          "_Log_Storage_TB": "7",
          "logtype": "disk",
          "alogging": "enabled"
      },
      "description": "Device Logging Service",
      "expired": "no",
      "expires": "August 04, 2024",
      "feature": "Logging Service",
      "issued": "June 27, 2022",
      "serial": "013201027229"
    },
    "Y feature": {
      "authcode": null,
      "description": "Device Logging Service",
      "expired": "no",
      "expires": "August 04, 2024",
      "feature": "Logging Service",
      "issued": "June 29, 2022",
      "serial": "013201027248"
    },
    "PAN-DB URL Filtering": {
      "Logging Service": "somehting",
      "authcode": null,
      "description": "Palo Alto Networks URL Filtering License",
      "expired": "no",
      "expires": "June 30, 2028",
      "feature": "PAN-DB URL Filtering",
      "issued": "April 27, 2023",
      "serial": "013201027229"
    },
    "C feature": {
      "authcode": null,
      "description": "Palo Alto Networks URL Filtering License",
      "expired": "no",
      "expires": "June 30, 2028",
      "feature": "PAN-DB URL Filtering",
      "issued": "April 27, 2023",
      "serial": "013201027229"
    }
  }
}

snapshot-2

{
  "license": {
    "Logging Service": {
      "authcode": null,
      "custom": {
          "_Log_Storage_TB": "9",
          "logtype": "tape",
          "blogging": "enabled"
      },
      "description": "Device Logging Service",
      "expired": "no",
      "expires": "August 04, 2024",
      "feature": "Logging Service",
      "issued": "June 29, 2022",
      "serial": "013201027229"
    },
    "X feature": {
      "authcode": null,
      "description": "Device Logging Service",
      "expired": "no",
      "expires": "August 04, 2024",
      "feature": "Logging Service",
      "issued": "June 29, 2022",
      "serial": "013201027248"
    },
    "PAN-DB URL Filtering": {
      "authcode": null,
      "description": "Palo Alto Networks URL Filtering License",
      "expired": "no",
      "expires": "June 30, 2028",
      "feature": "PAN-DB URL Filtering",
      "issued": "April 29, 2023",
      "serial": "013201027248"
    },
    "C feature": {
      "authcode": null,
      "description": "Palo Alto Networks URL Filtering License",
      "expired": "no",
      "expires": "June 30, 2028",
      "feature": "PAN-DB URL Filtering",
      "issued": "April 27, 2023",
      "serial": "013201027229"
    }
  }
}

How Has This Been Tested?

Tested with example scripts.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes if appropriate.
  • All new and existing tests passed.

Copy link

github-actions bot commented Jul 31, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  panos_upgrade_assurance
  snapshot_compare.py
  utils.py 461
Project Total  

This report was generated by python-coverage-comment-action

Copy link

A Preview PR in PanDev repo has been created. You can view it here.

@alperenkose alperenkose marked this pull request as ready for review August 1, 2024 08:16
@alperenkose alperenkose changed the title refactor: multi-level snapshot comparison and config parser refactor refactor!: multi-level snapshot comparison and config parser refactor Aug 2, 2024
Copy link
Collaborator

@horiagunica horiagunica left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

Copy link
Collaborator

@adambaumeister adambaumeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@alperenkose alperenkose merged commit b19c79f into main Aug 9, 2024
15 checks passed
@alperenkose alperenkose deleted the 108-refactor-multi-level-snapshot-comparison branch August 9, 2024 08:43
github-actions bot pushed a commit that referenced this pull request Aug 9, 2024
## [1.0.0](v0.3.6...v1.0.0) (2024-08-09)

### ⚠ BREAKING CHANGES

* multi-level snapshot comparison and config parser refactor (#128)

### Code Refactoring

* multi-level snapshot comparison and config parser refactor ([#128](#128)) ([b19c79f](b19c79f))
@horiagunica
Copy link
Collaborator

🎉 This PR is included in version 1.0.0 🎉

The release is available on PyPI and GitHub release

Posted by semantic-release bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants