Skip to content

fix(ontap): handle missing SnapMirror policy field#44

Open
navyaa14 wants to merge 3 commits into
NetApp:mainfrom
navyaa14:fix/issue-33-snapmirror-policy
Open

fix(ontap): handle missing SnapMirror policy field#44
navyaa14 wants to merge 3 commits into
NetApp:mainfrom
navyaa14:fix/issue-33-snapmirror-policy

Conversation

@navyaa14

Copy link
Copy Markdown

Summary

Fixes #33.

list_snap_mirror_relationships() accessed relationship.policy.type unconditionally. When a SnapmirrorRelationship SDK object does not expose the optional policy field, the SDK raises an AttributeError, preventing the available relationship data from being returned.

Fix

Safely return None for Type when policy.type is unavailable, while preserving the existing value when the field is present.

try:
    policy_type = relationship.policy.type
except AttributeError:
    policy_type = None

I intentionally left get_collection() unchanged because the function already calls relationship.get() for each relationship before reading its fields. This PR focuses narrowly on preventing the listing operation from failing when the optional field is still unavailable.

Tests

Added unit tests covering:

  • a relationship without policy, which should return "Type": None
  • a relationship with policy.type == "async", which should preserve "Type": "async"

The tests use SnapmirrorRelationship.from_dict() objects and mock network-dependent operations only.

tests/ontap/test_snapmirror_issue33.py::test_missing_policy_returns_none PASSED
tests/ontap/test_snapmirror_issue33.py::test_present_policy_returns_type PASSED

2 passed

Limitations

This change has been validated with mock-based unit tests. It has not been integration-tested against a live ONTAP cluster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

List SnapMirror Relationships tool fails with "policy field has not been set" error

1 participant