Commit f19ad697 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Context component:

- Renamed Link attribute current_capacity_gbps to used_capacity_gbps
parent f14940f3
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -99,21 +99,21 @@ def link_set(db_engine : Engine, messagebroker : MessageBroker, request : Link)
            })
            topology_uuids.add(endpoint_topology_uuid)

    total_capacity_gbps, current_capacity_gbps = None, None
    total_capacity_gbps, used_capacity_gbps = None, None
    if request.HasField('attributes'):
        attributes = request.attributes
        if attributes.HasField('total_capacity_gbps'):
            total_capacity_gbps = attributes.total_capacity_gbps
        if attributes.HasField('current_capacity_gbps'):
            current_capacity_gbps = attributes.current_capacity_gbps
        if attributes.HasField('used_capacity_gbps'):
            used_capacity_gbps = attributes.used_capacity_gbps
        elif total_capacity_gbps is not None:
            current_capacity_gbps = total_capacity_gbps
            used_capacity_gbps = total_capacity_gbps

    link_data = [{
        'link_uuid'           : link_uuid,
        'link_name'           : link_name,
        'total_capacity_gbps' : total_capacity_gbps,
        'current_capacity_gbps': current_capacity_gbps,
        'used_capacity_gbps'  : used_capacity_gbps,
        'created_at'          : now,
        'updated_at'          : now,
    }]
@@ -125,7 +125,7 @@ def link_set(db_engine : Engine, messagebroker : MessageBroker, request : Link)
            set_=dict(
                link_name           = stmt.excluded.link_name,
                total_capacity_gbps = stmt.excluded.total_capacity_gbps,
                current_capacity_gbps = stmt.excluded.current_capacity_gbps,
                used_capacity_gbps  = stmt.excluded.used_capacity_gbps,
                updated_at          = stmt.excluded.updated_at,
            )
        )
+10 −10
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ class LinkModel(_Base):
    link_uuid           = Column(UUID(as_uuid=False), primary_key=True)
    link_name           = Column(String, nullable=False)
    total_capacity_gbps = Column(Float, nullable=True)
    current_capacity_gbps = Column(Float, nullable=True)
    used_capacity_gbps  = Column(Float, nullable=True)
    created_at          = Column(DateTime, nullable=False)
    updated_at          = Column(DateTime, nullable=False)

@@ -34,7 +34,7 @@ class LinkModel(_Base):

    __table_args__ = (
        CheckConstraint(total_capacity_gbps >= 0, name='check_value_total_capacity_gbps'),
        CheckConstraint(current_capacity_gbps >= 0, name='check_value_current_capacity_gbps'),
        CheckConstraint(used_capacity_gbps  >= 0, name='check_value_used_capacity_gbps' ),
    )

    def dump_id(self) -> Dict:
@@ -52,9 +52,9 @@ class LinkModel(_Base):
        if self.total_capacity_gbps is not None:
            attributes : Dict = result.setdefault('attributes', dict())
            attributes.setdefault('total_capacity_gbps', self.total_capacity_gbps)
        if self.current_capacity_gbps is not None:
        if self.used_capacity_gbps is not None:
            attributes : Dict = result.setdefault('attributes', dict())
            attributes.setdefault('current_capacity_gbps', self.current_capacity_gbps)
            attributes.setdefault('used_capacity_gbps', self.used_capacity_gbps)
        return result

class LinkEndPointModel(_Base):
+5 −6
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ DEVICE_R3_NAME, DEVICE_R3_ID, DEVICE_R3 = compose_device('R3', ['1.1', '1.2', '2
# ----- Link -----------------------------------------------------------------------------------------------------------
def compose_link(
    name : str, endpoint_ids : List[Tuple[str, str]],
    total_capacity_gbps : Optional[float] = None, current_capacity_gbps : Optional[float] = None
    total_capacity_gbps : Optional[float] = None, used_capacity_gbps : Optional[float] = None
) -> Tuple[str, Dict, Dict]:
    link_id = json_link_id(name)
    endpoint_ids = [
@@ -81,22 +81,21 @@ def compose_link(
        for device_id, endpoint_name in endpoint_ids
    ]
    link = json_link(
        name, endpoint_ids, total_capacity_gbps=total_capacity_gbps,
        current_capacity_gbps=current_capacity_gbps
        name, endpoint_ids, total_capacity_gbps=total_capacity_gbps, used_capacity_gbps=used_capacity_gbps
    )
    return name, link_id, link

LINK_R1_R2_NAME, LINK_R1_R2_ID, LINK_R1_R2 = compose_link(
    'R1==R2', [(DEVICE_R1_ID, '1.2'), (DEVICE_R2_ID, '1.1')],
    total_capacity_gbps=100, # current_capacity_gbps=None => current_capacity_gbps=total_capacity_gbps
    total_capacity_gbps=100, # used_capacity_gbps=None => used_capacity_gbps=total_capacity_gbps
)
LINK_R2_R3_NAME, LINK_R2_R3_ID, LINK_R2_R3 = compose_link(
    'R2==R3', [(DEVICE_R2_ID, '1.3'), (DEVICE_R3_ID, '1.2')],
    total_capacity_gbps=100, # current_capacity_gbps=None => current_capacity_gbps=total_capacity_gbps
    total_capacity_gbps=100, # used_capacity_gbps=None => used_capacity_gbps=total_capacity_gbps
)
LINK_R1_R3_NAME, LINK_R1_R3_ID, LINK_R1_R3 = compose_link(
    'R1==R3', [(DEVICE_R1_ID, '1.3'), (DEVICE_R3_ID, '1.1')],
    total_capacity_gbps=100, # current_capacity_gbps=None => current_capacity_gbps=total_capacity_gbps
    total_capacity_gbps=100, # used_capacity_gbps=None => used_capacity_gbps=total_capacity_gbps
)


+7 −7
Original line number Diff line number Diff line
@@ -98,8 +98,8 @@ def test_link(context_client : ContextClient) -> None:
    assert response.HasField('attributes')
    assert response.attributes.HasField('total_capacity_gbps')
    assert abs(response.attributes.total_capacity_gbps - 100) < 1.e-12
    assert response.attributes.HasField('current_capacity_gbps')
    assert abs(response.attributes.current_capacity_gbps - response.attributes.total_capacity_gbps) < 1.e-12
    assert response.attributes.HasField('used_capacity_gbps')
    assert abs(response.attributes.used_capacity_gbps - response.attributes.total_capacity_gbps) < 1.e-12

    # ----- List when the object exists --------------------------------------------------------------------------------
    response = context_client.ListLinkIds(Empty())
@@ -117,7 +117,7 @@ def test_link(context_client : ContextClient) -> None:
    LINK_UPDATED = copy.deepcopy(LINK_R1_R2)
    LINK_UPDATED['name'] = new_link_name
    LINK_UPDATED['attributes']['total_capacity_gbps'] = 200
    LINK_UPDATED['attributes']['current_capacity_gbps'] = 50
    LINK_UPDATED['attributes']['used_capacity_gbps'] = 50
    response = context_client.SetLink(Link(**LINK_UPDATED))
    assert response.link_uuid.uuid == link_uuid

@@ -135,8 +135,8 @@ def test_link(context_client : ContextClient) -> None:
    assert response.HasField('attributes')
    assert response.attributes.HasField('total_capacity_gbps')
    assert abs(response.attributes.total_capacity_gbps - 200) < 1.e-12
    assert response.attributes.HasField('current_capacity_gbps')
    assert abs(response.attributes.current_capacity_gbps - 50) < 1.e-12
    assert response.attributes.HasField('used_capacity_gbps')
    assert abs(response.attributes.used_capacity_gbps - 50) < 1.e-12

    # ----- List when the object is modified ---------------------------------------------------------------------------
    response = context_client.ListLinkIds(Empty())
@@ -152,8 +152,8 @@ def test_link(context_client : ContextClient) -> None:
    assert response.links[0].HasField('attributes')
    assert response.links[0].attributes.HasField('total_capacity_gbps')
    assert abs(response.links[0].attributes.total_capacity_gbps - 200) < 1.e-12
    assert response.links[0].attributes.HasField('current_capacity_gbps')
    assert abs(response.links[0].attributes.current_capacity_gbps - 50) < 1.e-12
    assert response.links[0].attributes.HasField('used_capacity_gbps')
    assert abs(response.links[0].attributes.used_capacity_gbps - 50) < 1.e-12

    # ----- Check relation was created ---------------------------------------------------------------------------------
    response = context_client.GetTopology(TopologyId(**TOPOLOGY_ID))