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

Handle RpcError in CVP #580

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/467.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix get_tags_by_type() to handle possible RpcError Exception being thrown.
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def load_ip_addresses(self, dev: device):
def load_device_tags(self, device):
"""Load device tags from CloudVision."""
system_tags = cloudvision.get_tags_by_type(
client=self.conn.comm_channel, creator_type=TAG.models.CREATOR_TYPE_SYSTEM
client=self.conn.comm_channel, logger=self.job.logger, creator_type=TAG.models.CREATOR_TYPE_SYSTEM
)
dev_tags = [
tag
Expand Down
23 changes: 13 additions & 10 deletions nautobot_ssot/integrations/aristacv/utils/cloudvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,21 @@ def get_devices(client, import_active: bool):
return devices


def get_tags_by_type(client, creator_type: int = tag_models.CREATOR_TYPE_USER):
def get_tags_by_type(client, logger, creator_type: int = tag_models.CREATOR_TYPE_USER):
"""Get tags by creator type from CloudVision."""
tag_stub = tag_services.TagServiceStub(client)
req = tag_services.TagStreamRequest(partial_eq_filter=[tag_models.Tag(creator_type=creator_type)])
responses = tag_stub.GetAll(req)
tags = []
for resp in responses:
dev_tag = {
"label": resp.value.key.label.value,
"value": resp.value.key.value.value,
}
tags.append(dev_tag)
try:
tag_stub = tag_services.TagServiceStub(client)
req = tag_services.TagStreamRequest(partial_eq_filter=[tag_models.Tag(creator_type=creator_type)])
responses = tag_stub.GetAll(req)
for resp in responses:
dev_tag = {
"label": resp.value.key.label.value,
"value": resp.value.key.value.value,
}
tags.append(dev_tag)
except grpc.RpcError as err:
logger.error(f"Error when pulling Tags: {err}")
return tags


Expand Down
2 changes: 1 addition & 1 deletion nautobot_ssot/tests/aristacv/test_utils_cloudvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_get_tags_by_type(self):
device_tag_stub.TagServiceStub.return_value.GetAll.return_value = [mock_tag]

with patch("nautobot_ssot.integrations.aristacv.utils.cloudvision.tag_services", device_tag_stub):
results = cloudvision.get_tags_by_type(client=self.client)
results = cloudvision.get_tags_by_type(client=self.client, logger=MagicMock())
expected = [{"label": "test", "value": "test"}]
self.assertEqual(results, expected)

Expand Down