Loading src/context/service/database/Link.py +5 −2 Original line number Diff line number Diff line Loading @@ -102,14 +102,17 @@ def link_set(db_engine : Engine, messagebroker : MessageBroker, request : Link) total_capacity_gbps, used_capacity_gbps = None, None if request.HasField('attributes'): attributes = request.attributes # In proto3, HasField() does not work for scalar fields, using ListFields() instead. attribute_names = set([field.name for field,_ in attributes.ListFields()]) if 'total_capacity_gbps' in attribute_names: total_capacity_gbps = attributes.total_capacity_gbps if 'used_capacity_gbps' in attribute_names: used_capacity_gbps = attributes.used_capacity_gbps elif total_capacity_gbps is not None: used_capacity_gbps = total_capacity_gbps else: used_capacity_gbps = 0.0 link_data = [{ 'link_uuid' : link_uuid, Loading src/context/tests/test_link.py +7 −2 Original line number Diff line number Diff line Loading @@ -100,8 +100,13 @@ def test_link(context_client : ContextClient) -> None: attribute_names = set([field.name for field,_ in response.attributes.ListFields()]) assert 'total_capacity_gbps' in attribute_names assert abs(response.attributes.total_capacity_gbps - 100) < 1.e-12 assert 'used_capacity_gbps' in attribute_names assert abs(response.attributes.used_capacity_gbps - response.attributes.total_capacity_gbps) < 1.e-12 assert ( ('used_capacity_gbps' not in attribute_names) or ( ('used_capacity_gbps' in attribute_names) and ( abs(response.attributes.used_capacity_gbps - response.attributes.total_capacity_gbps) < 1.e-12 ) ) ) # ----- List when the object exists -------------------------------------------------------------------------------- response = context_client.ListLinkIds(Empty()) Loading Loading
src/context/service/database/Link.py +5 −2 Original line number Diff line number Diff line Loading @@ -102,14 +102,17 @@ def link_set(db_engine : Engine, messagebroker : MessageBroker, request : Link) total_capacity_gbps, used_capacity_gbps = None, None if request.HasField('attributes'): attributes = request.attributes # In proto3, HasField() does not work for scalar fields, using ListFields() instead. attribute_names = set([field.name for field,_ in attributes.ListFields()]) if 'total_capacity_gbps' in attribute_names: total_capacity_gbps = attributes.total_capacity_gbps if 'used_capacity_gbps' in attribute_names: used_capacity_gbps = attributes.used_capacity_gbps elif total_capacity_gbps is not None: used_capacity_gbps = total_capacity_gbps else: used_capacity_gbps = 0.0 link_data = [{ 'link_uuid' : link_uuid, Loading
src/context/tests/test_link.py +7 −2 Original line number Diff line number Diff line Loading @@ -100,8 +100,13 @@ def test_link(context_client : ContextClient) -> None: attribute_names = set([field.name for field,_ in response.attributes.ListFields()]) assert 'total_capacity_gbps' in attribute_names assert abs(response.attributes.total_capacity_gbps - 100) < 1.e-12 assert 'used_capacity_gbps' in attribute_names assert abs(response.attributes.used_capacity_gbps - response.attributes.total_capacity_gbps) < 1.e-12 assert ( ('used_capacity_gbps' not in attribute_names) or ( ('used_capacity_gbps' in attribute_names) and ( abs(response.attributes.used_capacity_gbps - response.attributes.total_capacity_gbps) < 1.e-12 ) ) ) # ----- List when the object exists -------------------------------------------------------------------------------- response = context_client.ListLinkIds(Empty()) Loading