Skip to content

Commit

Permalink
Merge pull request #580 from nautobot/patch-fix_467
Browse files Browse the repository at this point in the history
Handle RpcError in CVP
  • Loading branch information
jdrew82 authored Oct 23, 2024
2 parents 73c0048 + c2b042f commit 649fcc7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
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

0 comments on commit 649fcc7

Please sign in to comment.