Skip to content
Snippets Groups Projects
Commit 4153e3ca authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Context component:

- Fixed inspection of Link attribute presence
parent be91069e
No related branches found
No related tags found
2 merge requests!235Release TeraFlowSDN 3.0,!160Resolve "(CTTC) Forecaster component"
......@@ -102,7 +102,8 @@ 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
attribute_names = set([field.name for field in attributes._fields])
# 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:
......
......@@ -96,7 +96,8 @@ def test_link(context_client : ContextClient) -> None:
assert response.name == LINK_R1_R2_NAME
assert len(response.link_endpoint_ids) == 2
assert response.HasField('attributes')
attribute_names = set([field.name for field in response.attributes._fields])
# In proto3, HasField() does not work for scalar fields, using ListFields() instead.
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
......@@ -134,7 +135,8 @@ def test_link(context_client : ContextClient) -> None:
assert response.name == new_link_name
assert len(response.link_endpoint_ids) == 2
assert response.HasField('attributes')
attribute_names = set([field.name for field in response.attributes._fields])
# In proto3, HasField() does not work for scalar fields, using ListFields() instead.
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 - 200) < 1.e-12
assert 'used_capacity_gbps' in attribute_names
......@@ -152,9 +154,11 @@ def test_link(context_client : ContextClient) -> None:
assert len(response.links[0].link_endpoint_ids) == 2
assert len(response.links[0].link_endpoint_ids) == 2
assert response.links[0].HasField('attributes')
assert response.links[0].attributes.HasField('total_capacity_gbps')
# In proto3, HasField() does not work for scalar fields, using ListFields() instead.
attribute_names = set([field.name for field,_ in response.links[0].attributes.ListFields()])
assert 'total_capacity_gbps' in attribute_names
assert abs(response.links[0].attributes.total_capacity_gbps - 200) < 1.e-12
assert response.links[0].attributes.HasField('used_capacity_gbps')
assert 'used_capacity_gbps' in attribute_names
assert abs(response.links[0].attributes.used_capacity_gbps - 50) < 1.e-12
# ----- Check relation was created ---------------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment