Commit 367ff643 authored by Mohamad Rahhal's avatar Mohamad Rahhal
Browse files

Merge branch 'feat/143-cttc-logical-resources-component' of...

Merge branch 'feat/143-cttc-logical-resources-component' of https://labs.etsi.org/rep/tfs/controller into feat/390-cttc-integration-of-spine-leaf-fabric-management
parents 7b915080 859cf5a3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ service LogicalResources {
    rpc GetAvailableResources (Empty) returns (ResourceList) {}
    rpc ReserveResource (ResourceReservation) returns (Success) {}
    rpc ReleaseResource (ResourceReservation) returns (Success) {}
    rpc DeleteResource (ResourceReservation) returns (Success) {}
    rpc GetReservedResources (Empty) returns (ResourceList) {}
    rpc GetResourceOwner (Value) returns (FabricId) {}
    rpc GetResourcesByType (ResourceTypeQuery) returns (TypedResourceList) {}
+7 −0
Original line number Diff line number Diff line
@@ -77,6 +77,13 @@ class LogicalResourceClient:
        LOGGER.debug('ReleaseResource result: {:s}'.format(grpc_message_to_json_string(response)))
        return response

    @RETRY_DECORATOR
    def DeleteResource(self, request):
        LOGGER.debug('DeleteResource request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.DeleteResource(request)
        LOGGER.debug('DeleteResource result: {:s}'.format(grpc_message_to_json_string(response)))
        return response

    @RETRY_DECORATOR
    def GetReservedResources(self, request=None):
        if request is None:
+7 −0
Original line number Diff line number Diff line
@@ -73,6 +73,13 @@ class Database:
        self.resources[key] = ''
        return True, 'Resource released'

    def delete_resource(self, resource_type, resource_value):
        key = (resource_type, resource_value)
        if key not in self.resources:
            return False, 'Resource not found'
        del self.resources[key]
        return True, 'Resource deleted'

    def get_reserved_resources(self):
        return [
            (resource_type, resource_value, fabric_id)
+20 −1
Original line number Diff line number Diff line
# Copyright 2022-2025 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method
from common.proto.logical_resources_pb2 import (
@@ -73,6 +87,11 @@ class LogicalResourceServicerImpl(LogicalResourcesServicer):
        success, message = self.db.release_resource(request.tuple.type, request.tuple.value)
        return Success(success=success, message=message)

    @safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
    def DeleteResource(self, request, context: grpc.ServicerContext) -> Success:
        success, message = self.db.delete_resource(request.tuple.type, request.tuple.value)
        return Success(success=success, message=message)

    @safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
    def GetReservedResources(self, request, context: grpc.ServicerContext) -> ResourceList:
        reply = ResourceList()
+28 −16
Original line number Diff line number Diff line
@@ -259,24 +259,36 @@ def test_spine_leaf_realistic_example(logical_resource_client : LogicalResourceC
    assert ('loopback', '10.255.0.11', 'spine-fabric') in reserved_pairs
    assert ('vlan', '100', 'leaf-fabric') in reserved_pairs

    spine_owner = logical_resource_client.GetResourceOwner(Value(value='10.255.0.11'))
    assert spine_owner.fabric_id == 'spine-fabric'

    ip_resources = logical_resource_client.GetResourcesByType(ResourceTypeQuery(resource_type='ip'))
    assert any(r.value == '10.0.0.1' for r in ip_resources.resources)
    assert any(r.value == '10.0.0.2' for r in ip_resources.resources)
def test_delete_resource(logical_resource_client: LogicalResourceClient, logical_resource_service):
    add_request = ConfigParameters()
    add_request.device_uuid = "leaf-delete"
    add_request.endpoint_uuid = "sfp-delete"
    add_request.ip_address = "10.10.0.10"
    add_request.vlan_tag = 110
    add_request.asn = 65110
    add_request.router_id = "10.255.10.10"
    add_request.vni = 1110

    release_spine = logical_resource_client.ReleaseResource(ResourceReservation(
        tuple=Tuple(type='loopback', value='10.255.0.11'),
        fabric_id=FabricId(fabric_id='spine-fabric'),
    add_reply = logical_resource_client.AddResources(add_request)
    assert add_reply.success is True

    present_before = logical_resource_client.GetResourcesByType(ResourceTypeQuery(resource_type='ip'))
    assert any(r.value == '10.10.0.10' for r in present_before.resources)

    delete_reply = logical_resource_client.DeleteResource(ResourceReservation(
        tuple=Tuple(type='ip', value='10.10.0.10'),
        fabric_id=FabricId(fabric_id=''),
    ))
    assert release_spine.success is True
    assert delete_reply.success is True
    assert delete_reply.message == 'Resource deleted'

    available_after_release = logical_resource_client.GetAvailableResources(Empty())
    assert any(r.type == 'loopback' and r.value == '10.255.0.11' for r in available_after_release.resources)
    present_after = logical_resource_client.GetResourcesByType(ResourceTypeQuery(resource_type='ip'))
    assert not any(r.value == '10.10.0.10' for r in present_after.resources)

    print("spine add success:", True)
    print("leaf add success:", True)
    print("reserved count:", len(reserved.resources))
    print("available count after release:", len(available_after_release.resources))
    print("======================================\n")
    delete_missing = logical_resource_client.DeleteResource(ResourceReservation(
        tuple=Tuple(type='ip', value='10.10.0.10'),
        fabric_id=FabricId(fabric_id=''),
    ))
    assert delete_missing.success is False
    assert delete_missing.message == 'Resource not found'