Commit 5e702454 authored by Waleed Akbar's avatar Waleed Akbar
Browse files

cleaning to resolve pipelines error #26381

parent de8b6a59
Loading
Loading
Loading
Loading
+161 −161
Changes for src/device/service/drivers/__init__.py: 161 added lines, 161 removed lines.
Original line number Diff line number Diff line
@@ -20,69 +20,69 @@ from ..driver_api.FilterFields import FilterFieldEnum

DRIVERS = []

# from .emulated.EmulatedDriver import EmulatedDriver # pylint: disable=wrong-import-position
# DRIVERS.append(
#     (EmulatedDriver, [
#         {
#             FilterFieldEnum.DEVICE_TYPE: [], # any device type
#             FilterFieldEnum.DRIVER: [
#                 DeviceDriverEnum.DEVICEDRIVER_UNDEFINED,
#             ],
#         }
#     ]))
from .emulated.EmulatedDriver import EmulatedDriver # pylint: disable=wrong-import-position
DRIVERS.append(
    (EmulatedDriver, [
        {
            FilterFieldEnum.DEVICE_TYPE: [], # any device type
            FilterFieldEnum.DRIVER: [
                DeviceDriverEnum.DEVICEDRIVER_UNDEFINED,
            ],
        }
    ]))

# if LOAD_ALL_DEVICE_DRIVERS:
#     from .ietf_l2vpn.IetfL2VpnDriver import IetfL2VpnDriver # pylint: disable=wrong-import-position
#     DRIVERS.append(
#         (IetfL2VpnDriver, [
#             {
#                 FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.TERAFLOWSDN_CONTROLLER,
#                 FilterFieldEnum.DRIVER: DeviceDriverEnum.DEVICEDRIVER_IETF_L2VPN,
#             }
#         ]))
if LOAD_ALL_DEVICE_DRIVERS:
    from .ietf_l2vpn.IetfL2VpnDriver import IetfL2VpnDriver # pylint: disable=wrong-import-position
    DRIVERS.append(
        (IetfL2VpnDriver, [
            {
                FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.TERAFLOWSDN_CONTROLLER,
                FilterFieldEnum.DRIVER: DeviceDriverEnum.DEVICEDRIVER_IETF_L2VPN,
            }
        ]))

# if LOAD_ALL_DEVICE_DRIVERS:
#     from .ietf_l3vpn.IetfL3VpnDriver import IetfL3VpnDriver # pylint: disable=wrong-import-position
#     DRIVERS.append(
#         (IetfL3VpnDriver, [
#             {
#                 FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.TERAFLOWSDN_CONTROLLER,
#                 FilterFieldEnum.DRIVER: DeviceDriverEnum.DEVICEDRIVER_IETF_L3VPN,
#             }
#         ]))
if LOAD_ALL_DEVICE_DRIVERS:
    from .ietf_l3vpn.IetfL3VpnDriver import IetfL3VpnDriver # pylint: disable=wrong-import-position
    DRIVERS.append(
        (IetfL3VpnDriver, [
            {
                FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.TERAFLOWSDN_CONTROLLER,
                FilterFieldEnum.DRIVER: DeviceDriverEnum.DEVICEDRIVER_IETF_L3VPN,
            }
        ]))

# if LOAD_ALL_DEVICE_DRIVERS:
#     from .ietf_actn.IetfActnDriver import IetfActnDriver # pylint: disable=wrong-import-position
#     DRIVERS.append(
#         (IetfActnDriver, [
#             {
#                 FilterFieldEnum.DEVICE_TYPE: [
#                     DeviceTypeEnum.OPEN_LINE_SYSTEM,
#                     DeviceTypeEnum.NCE,
#                 ],
#                 FilterFieldEnum.DRIVER: DeviceDriverEnum.DEVICEDRIVER_IETF_ACTN,
#             }
#         ]))
if LOAD_ALL_DEVICE_DRIVERS:
    from .ietf_actn.IetfActnDriver import IetfActnDriver # pylint: disable=wrong-import-position
    DRIVERS.append(
        (IetfActnDriver, [
            {
                FilterFieldEnum.DEVICE_TYPE: [
                    DeviceTypeEnum.OPEN_LINE_SYSTEM,
                    DeviceTypeEnum.NCE,
                ],
                FilterFieldEnum.DRIVER: DeviceDriverEnum.DEVICEDRIVER_IETF_ACTN,
            }
        ]))

# if LOAD_ALL_DEVICE_DRIVERS:
#     from .ietf_slice.IetfSliceDriver import IetfSliceDriver # pylint: disable=wrong-import-position
#     DRIVERS.append(
#         (IetfSliceDriver, [
#             {
#                 FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.TERAFLOWSDN_CONTROLLER,
#                 FilterFieldEnum.DRIVER: DeviceDriverEnum.DEVICEDRIVER_IETF_SLICE,
#             }
#         ]))
if LOAD_ALL_DEVICE_DRIVERS:
    from .ietf_slice.IetfSliceDriver import IetfSliceDriver # pylint: disable=wrong-import-position
    DRIVERS.append(
        (IetfSliceDriver, [
            {
                FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.TERAFLOWSDN_CONTROLLER,
                FilterFieldEnum.DRIVER: DeviceDriverEnum.DEVICEDRIVER_IETF_SLICE,
            }
        ]))

# if LOAD_ALL_DEVICE_DRIVERS:
#     from .nce.NCEDriver import NCEDriver # pylint: disable=wrong-import-position
#     DRIVERS.append(
#         (NCEDriver, [
#             {
#                 FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.NCE,
#                 FilterFieldEnum.DRIVER: DeviceDriverEnum.DEVICEDRIVER_NCE,
#             }
#         ]))
if LOAD_ALL_DEVICE_DRIVERS:
    from .nce.NCEDriver import NCEDriver # pylint: disable=wrong-import-position
    DRIVERS.append(
        (NCEDriver, [
            {
                FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.NCE,
                FilterFieldEnum.DRIVER: DeviceDriverEnum.DEVICEDRIVER_NCE,
            }
        ]))

if LOAD_ALL_DEVICE_DRIVERS:
    from .openconfig.OpenConfigDriver import OpenConfigDriver # pylint: disable=wrong-import-position
@@ -112,105 +112,105 @@ if LOAD_ALL_DEVICE_DRIVERS:
            }
        ]))

# if LOAD_ALL_DEVICE_DRIVERS:
#     from .gnmi_nokia_srlinux.GnmiNokiaSrLinuxDriver import GnmiNokiaSrLinuxDriver # pylint: disable=wrong-import-position
#     DRIVERS.append(
#         (GnmiNokiaSrLinuxDriver, [
#             {
#                 # Real Packet Router, specifying gNMI Nokia SR Linux Driver => use GnmiNokiaSrLinuxDriver
#                 FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.PACKET_ROUTER,
#                 FilterFieldEnum.DRIVER     : DeviceDriverEnum.DEVICEDRIVER_GNMI_NOKIA_SRLINUX,
#             }
#         ]))
if LOAD_ALL_DEVICE_DRIVERS:
    from .gnmi_nokia_srlinux.GnmiNokiaSrLinuxDriver import GnmiNokiaSrLinuxDriver # pylint: disable=wrong-import-position
    DRIVERS.append(
        (GnmiNokiaSrLinuxDriver, [
            {
                # Real Packet Router, specifying gNMI Nokia SR Linux Driver => use GnmiNokiaSrLinuxDriver
                FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.PACKET_ROUTER,
                FilterFieldEnum.DRIVER     : DeviceDriverEnum.DEVICEDRIVER_GNMI_NOKIA_SRLINUX,
            }
        ]))

# if LOAD_ALL_DEVICE_DRIVERS:
#     from .transport_api.TransportApiDriver import TransportApiDriver # pylint: disable=wrong-import-position
#     DRIVERS.append(
#         (TransportApiDriver, [
#             {
#                 # Real OLS, specifying TAPI Driver => use TransportApiDriver
#                 FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.OPEN_LINE_SYSTEM,
#                 FilterFieldEnum.DRIVER     : DeviceDriverEnum.DEVICEDRIVER_TRANSPORT_API,
#             }
#         ]))
if LOAD_ALL_DEVICE_DRIVERS:
    from .transport_api.TransportApiDriver import TransportApiDriver # pylint: disable=wrong-import-position
    DRIVERS.append(
        (TransportApiDriver, [
            {
                # Real OLS, specifying TAPI Driver => use TransportApiDriver
                FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.OPEN_LINE_SYSTEM,
                FilterFieldEnum.DRIVER     : DeviceDriverEnum.DEVICEDRIVER_TRANSPORT_API,
            }
        ]))

# if LOAD_ALL_DEVICE_DRIVERS:
#     from .p4.p4_driver import P4Driver # pylint: disable=wrong-import-position
#     DRIVERS.append(
#         (P4Driver, [
#             {
#                 # Real P4 Switch, specifying P4 Driver => use P4Driver
#                 FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.P4_SWITCH,
#                 FilterFieldEnum.DRIVER     : DeviceDriverEnum.DEVICEDRIVER_P4,
#             }
#         ]))
if LOAD_ALL_DEVICE_DRIVERS:
    from .p4.p4_driver import P4Driver # pylint: disable=wrong-import-position
    DRIVERS.append(
        (P4Driver, [
            {
                # Real P4 Switch, specifying P4 Driver => use P4Driver
                FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.P4_SWITCH,
                FilterFieldEnum.DRIVER     : DeviceDriverEnum.DEVICEDRIVER_P4,
            }
        ]))
    
# if LOAD_ALL_DEVICE_DRIVERS:
#     from .smartnic.SmartnicDriver import SmartnicDriver # pylint: disable=wrong-import-position
#     DRIVERS.append(
#         (SmartnicDriver, [
#             {
#                 # Real SmartNics device => use SmartNicsDriver
#                 FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.SMARTNIC,
#                 FilterFieldEnum.DRIVER     : DeviceDriverEnum.DEVICEDRIVER_SMARTNIC,
#             }
#         ]))
if LOAD_ALL_DEVICE_DRIVERS:
    from .smartnic.SmartnicDriver import SmartnicDriver # pylint: disable=wrong-import-position
    DRIVERS.append(
        (SmartnicDriver, [
            {
                # Real SmartNics device => use SmartNicsDriver
                FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.SMARTNIC,
                FilterFieldEnum.DRIVER     : DeviceDriverEnum.DEVICEDRIVER_SMARTNIC,
            }
        ]))

# if LOAD_ALL_DEVICE_DRIVERS:
#     from .morpheus.MorpheusApiDriver import MorpheusApiDriver
#     DRIVERS.append(
#         (MorpheusApiDriver, [
#             {
#                 # Close enough, it does optical switching
#                 FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.MORPHEUS,
#                 FilterFieldEnum.DRIVER     : DeviceDriverEnum.DEVICEDRIVER_MORPHEUS,
#             }
#         ]))
if LOAD_ALL_DEVICE_DRIVERS:
    from .morpheus.MorpheusApiDriver import MorpheusApiDriver
    DRIVERS.append(
        (MorpheusApiDriver, [
            {
                # Close enough, it does optical switching
                FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.MORPHEUS,
                FilterFieldEnum.DRIVER     : DeviceDriverEnum.DEVICEDRIVER_MORPHEUS,
            }
        ]))

# if LOAD_ALL_DEVICE_DRIVERS:
#     from .microwave.IETFApiDriver import IETFApiDriver # pylint: disable=wrong-import-position
#     DRIVERS.append(
#         (IETFApiDriver, [
#             {
#                 FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.MICROWAVE_RADIO_SYSTEM,
#                 FilterFieldEnum.DRIVER     : DeviceDriverEnum.DEVICEDRIVER_IETF_NETWORK_TOPOLOGY,
#             }
#         ]))
if LOAD_ALL_DEVICE_DRIVERS:
    from .microwave.IETFApiDriver import IETFApiDriver # pylint: disable=wrong-import-position
    DRIVERS.append(
        (IETFApiDriver, [
            {
                FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.MICROWAVE_RADIO_SYSTEM,
                FilterFieldEnum.DRIVER     : DeviceDriverEnum.DEVICEDRIVER_IETF_NETWORK_TOPOLOGY,
            }
        ]))

# if LOAD_ALL_DEVICE_DRIVERS:
#     from .ryu.RyuDriver import RyuDriver
#     DRIVERS.append(
#         (RyuDriver, [
#             {
#                 FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.OPENFLOW_RYU_CONTROLLER,
#                 FilterFieldEnum.DRIVER     : DeviceDriverEnum.DEVICEDRIVER_RYU,
#             }
#         ])
#     )
if LOAD_ALL_DEVICE_DRIVERS:
    from .ryu.RyuDriver import RyuDriver
    DRIVERS.append(
        (RyuDriver, [
            {
                FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.OPENFLOW_RYU_CONTROLLER,
                FilterFieldEnum.DRIVER     : DeviceDriverEnum.DEVICEDRIVER_RYU,
            }
        ])
    )

# if LOAD_ALL_DEVICE_DRIVERS:
#     from .xr.XrDriver import XrDriver # pylint: disable=wrong-import-position
#     DRIVERS.append(
#         (XrDriver, [
#             {
#                 # Close enough, it does optical switching
#                 FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.XR_CONSTELLATION,
#                 FilterFieldEnum.DRIVER     : DeviceDriverEnum.DEVICEDRIVER_XR,
#             }
#         ]))
if LOAD_ALL_DEVICE_DRIVERS:
    from .xr.XrDriver import XrDriver # pylint: disable=wrong-import-position
    DRIVERS.append(
        (XrDriver, [
            {
                # Close enough, it does optical switching
                FilterFieldEnum.DEVICE_TYPE: DeviceTypeEnum.XR_CONSTELLATION,
                FilterFieldEnum.DRIVER     : DeviceDriverEnum.DEVICEDRIVER_XR,
            }
        ]))

# if LOAD_ALL_DEVICE_DRIVERS:
#     from .optical_tfs.OpticalTfsDriver import OpticalTfsDriver # pylint: disable=wrong-import-position
#     DRIVERS.append(
#         (OpticalTfsDriver, [
#             {
#                 FilterFieldEnum.DEVICE_TYPE: [
#                     DeviceTypeEnum.OPEN_LINE_SYSTEM,
#                     DeviceTypeEnum.TERAFLOWSDN_CONTROLLER,
#                 ],
#                 FilterFieldEnum.DRIVER: DeviceDriverEnum.DEVICEDRIVER_OPTICAL_TFS,
#             }
#         ]))
if LOAD_ALL_DEVICE_DRIVERS:
    from .optical_tfs.OpticalTfsDriver import OpticalTfsDriver # pylint: disable=wrong-import-position
    DRIVERS.append(
        (OpticalTfsDriver, [
            {
                FilterFieldEnum.DEVICE_TYPE: [
                    DeviceTypeEnum.OPEN_LINE_SYSTEM,
                    DeviceTypeEnum.TERAFLOWSDN_CONTROLLER,
                ],
                FilterFieldEnum.DRIVER: DeviceDriverEnum.DEVICEDRIVER_OPTICAL_TFS,
            }
        ]))

if LOAD_ALL_DEVICE_DRIVERS:
    from .oc_driver.OCDriver import OCDriver # pylint: disable=wrong-import-position
@@ -226,18 +226,18 @@ if LOAD_ALL_DEVICE_DRIVERS:
            }
        ]))
    
# if LOAD_ALL_DEVICE_DRIVERS:
#     from .openroadm.OpenROADMDriver import OpenROADMDriver # pylint: disable=wrong-import-position
#     DRIVERS.append(
#         (OpenROADMDriver, [
#             {
#                 # Real Packet Router, specifying OpenConfig Driver => use OpenConfigDriver
#                 FilterFieldEnum.DEVICE_TYPE: [
#                     DeviceTypeEnum.OPEN_ROADM,
#                 ],
#                 FilterFieldEnum.DRIVER     : DeviceDriverEnum.DEVICEDRIVER_OPENROADM,
#             }
#         ]))    
if LOAD_ALL_DEVICE_DRIVERS:
    from .openroadm.OpenROADMDriver import OpenROADMDriver # pylint: disable=wrong-import-position
    DRIVERS.append(
        (OpenROADMDriver, [
            {
                # Real Packet Router, specifying OpenConfig Driver => use OpenConfigDriver
                FilterFieldEnum.DEVICE_TYPE: [
                    DeviceTypeEnum.OPEN_ROADM,
                ],
                FilterFieldEnum.DRIVER     : DeviceDriverEnum.DEVICEDRIVER_OPENROADM,
            }
        ]))

if LOAD_ALL_DEVICE_DRIVERS:
    from .qkd.QKDDriver2 import QKDDriver # pylint: disable=wrong-import-position
+69 −108
Changes for src/nbi/tests/test_dscm_restconf.py: 69 added lines, 108 removed lines.
Original line number Diff line number Diff line
@@ -12,129 +12,90 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Union
import logging
import os, pytest, time
import requests
from .DSCM_MockWebServer           import MockWebServer
from .messages.dscm_messages       import get_hub_payload, get_leaf_payload
from common.Constants              import ServiceNameEnum
from nbi.service.NbiApplication    import NbiApplication
from common.proto.context_pb2_grpc import add_ContextServiceServicer_to_server
from common.Settings import (
        ENVVAR_SUFIX_SERVICE_HOST, ENVVAR_SUFIX_SERVICE_PORT_GRPC, 
    get_env_var_name, get_service_port_grpc)
from common.tests.MockServicerImpl_Context   import MockServicerImpl_Context
from common.tools.service.GenericGrpcService import GenericGrpcService
from unittest.mock import Mock
import pytest
from flask import Flask
from common.method_wrappers.ServiceExceptions import NotFoundException
from common.proto.context_pb2 import Empty
from common.proto.pluggables_pb2 import Pluggable
from nbi.service.dscm_oc import routes
from pluggables.client.PluggablesClient import PluggablesClient
from pluggables.service.PluggablesService    import PluggablesService

from .messages.dscm_messages import get_hub_payload, get_leaf_payload

LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)

BASE_URL = "http://127.0.0.1:18080/restconf/data/"
BASE_URL = "/restconf/data/"
HEADERS = {"Accept": "application/yang-data+json",
           "Content-Type": "application/yang-data+json"}

###########################
# Tests Setup
###########################

LOCAL_HOST = '127.0.0.1'

DSCMPLUGGABLE_SERVICE_PORT = get_service_port_grpc(ServiceNameEnum.PLUGGABLES)  
os.environ[get_env_var_name(ServiceNameEnum.PLUGGABLES, ENVVAR_SUFIX_SERVICE_HOST     )] = str(LOCAL_HOST)
os.environ[get_env_var_name(ServiceNameEnum.PLUGGABLES, ENVVAR_SUFIX_SERVICE_PORT_GRPC)] = str(DSCMPLUGGABLE_SERVICE_PORT)

# class MockContextService(GenericGrpcService):
#     def __init__(self, bind_port: Union[str, int]) -> None:
#         super().__init__(bind_port, LOCAL_HOST, enable_health_servicer=False, cls_name='MockService')

#     def install_servicers(self):
#         self.context_servicer = MockServicerImpl_Context()
#         add_ContextServiceServicer_to_server(self.context_servicer, self.server)


@pytest.fixture(scope='session')
def nbi_service_rest() -> NbiApplication:
    """Fixture to start the NBI REST service with DSCM plugin."""
    mock_web_server = MockWebServer()
    mock_web_server.start()
    time.sleep(1)   # give time for the server to start

    nbi_app = mock_web_server.nbi_app
    yield nbi_app

    # Cleanup: web server runs as daemon thread, so will terminate with main process
@pytest.fixture
def dscm_pluggable_client(monkeypatch):
    # Patch where routes instantiate the client; no gRPC server or device needed.
    client = Mock(spec=PluggablesClient)
    monkeypatch.setattr(routes, 'PluggablesClient', lambda: client)
    return client

@pytest.fixture(scope='session')
def pluggables_service():
    LOGGER.info('Initializing DscmPluggableService...')
    _service = PluggablesService()
    _service.start()

    LOGGER.info('Yielding DscmPluggableService...')
    yield _service
@pytest.fixture
def nbi_service_rest(dscm_pluggable_client):
    app = Flask(__name__)
    app.config['TESTING'] = True
    app.register_blueprint(routes.blueprint, url_prefix='/restconf/data')
    with app.test_client() as client:
        yield client

    LOGGER.info('Terminating DscmPluggableService...')
    _service.stop()
    LOGGER.info('Terminated DscmPluggableService...')

@pytest.fixture(scope='function')
def dscm_pluggable_client(pluggables_service : PluggablesService):
    LOGGER.info('Creating PluggablesClient...')
    _client = PluggablesClient()
def test_post_hub_optical_channel_frequency(nbi_service_rest, dscm_pluggable_client):
    response_message = Pluggable()
    response_message.id.device.device_uuid.uuid = 'T1.1'
    response_message.id.pluggable_index = 1
    dscm_pluggable_client.CreatePluggable.return_value = response_message

    LOGGER.info('Yielding PluggablesClient...')
    yield _client

    LOGGER.info('Closing PluggablesClient...')
    _client.close()
    LOGGER.info('Closed PluggablesClient...')

@pytest.fixture(autouse=True)
def log_each(request):
    LOGGER.info(f">>>>>> START {request.node.name} >>>>>>")
    yield
    LOGGER.info(f"<<<<<< END   {request.node.name} <<<<<<")


# Actual test cases

def test_post_hub_optical_channel_frequency(nbi_service_rest, dscm_pluggable_client: PluggablesClient):
    """Test PATCH to update optical channel frequency."""
    device = "device=T1.1/"
    encoded_path = f"{device}openconfig-platform:components/component=1/optical-channel/config"
    
    post_data = get_hub_payload()
    response = requests.post(f"{BASE_URL}{encoded_path}", 
                            json=post_data, 
                            headers=HEADERS)
    path = BASE_URL + 'device=T1.1/openconfig-platform:components/component=1/optical-channel/config'
    response = nbi_service_rest.post(path, json=get_hub_payload(), headers=HEADERS)
    assert response.status_code == 201

def test_post_get_delete_leaf_optical_channel_frequency(nbi_service_rest, dscm_pluggable_client: PluggablesClient):
    """Test POST, GET, DELETE to manage optical channel frequency for leaf device."""
    device = "device=T1.2/"
    encoded_path = f"{device}openconfig-platform:components/component=1/optical-channel/config"
    
    # Step 1: POST to create a new device configuration
    post_data = get_leaf_payload()
    response = requests.post(f"{BASE_URL}{encoded_path}", 
                            json=post_data, 
                            headers=HEADERS)
    dscm_pluggable_client.CreatePluggable.assert_called_once()
    request = dscm_pluggable_client.CreatePluggable.call_args[0][0]
    assert request.device.device_uuid.uuid == 'T1.1'
    assert request.preferred_pluggable_index == 1
    assert len(request.initial_config.dsc_groups) == 4
    dscm_pluggable_client.close.assert_called_once()


def test_post_get_delete_leaf_optical_channel_frequency(nbi_service_rest, dscm_pluggable_client):
    response_message = Pluggable()
    response_message.id.device.device_uuid.uuid = 'T1.2'
    response_message.id.pluggable_index = 1
    dscm_pluggable_client.CreatePluggable.return_value = response_message
    dscm_pluggable_client.GetPluggable.side_effect = [
        response_message, NotFoundException('Pluggable', 'T1.2:1')]
    dscm_pluggable_client.DeletePluggable.side_effect = [
        Empty(), NotFoundException('Pluggable', 'T1.2:1')]

    path = BASE_URL + 'device=T1.2/openconfig-platform:components/component=1/optical-channel/config'
    response = nbi_service_rest.post(path, json=get_leaf_payload(), headers=HEADERS)
    assert response.status_code == 201
    request = dscm_pluggable_client.CreatePluggable.call_args[0][0]
    assert request.device.device_uuid.uuid == 'T1.2'
    assert request.preferred_pluggable_index == 1
    assert len(request.initial_config.channel_configs) == 3

    # Step 2: GET to retrieve the created device configuration
    response = requests.get(f"{BASE_URL}{encoded_path}", headers={"Accept": "application/yang-data+json"})
    response = nbi_service_rest.get(path, headers=HEADERS)
    assert response.status_code == 200
    get_data = response.json()
    assert get_data is not None
    assert response.get_json()['id']['device']['device_uuid']['uuid'] == 'T1.2'
    request = dscm_pluggable_client.GetPluggable.call_args[0][0]
    assert request.id.device.device_uuid.uuid == 'T1.2'
    assert request.id.pluggable_index == 1

    # Step 3: DELETE to remove the created device configuration
    response = requests.delete(f"{BASE_URL}{encoded_path}", headers={"Accept": "application/yang-data+json"})
    response = nbi_service_rest.delete(path, headers=HEADERS)
    assert response.status_code == 204

    # Step 4: GET again to verify the device configuration has been deleted
    response = requests.get(f"{BASE_URL}{encoded_path}", headers={"Accept": "application/yang-data+json"})
    assert response.status_code == 400  # Assuming 400 is returned for non-existing resource
    request = dscm_pluggable_client.DeletePluggable.call_args[0][0]
    assert request.id.device.device_uuid.uuid == 'T1.2'
    assert request.id.pluggable_index == 1

    # The route returns 404 for GET on a missing resource; DELETE is idempotent.
    response = nbi_service_rest.get(path, headers=HEADERS)
    assert response.status_code == 404
    response = nbi_service_rest.delete(path, headers=HEADERS)
    assert response.status_code == 204
    assert dscm_pluggable_client.close.call_count == 5
+9 −45

File changed.

Preview size limit exceeded, changes collapsed.

+1 −0
Changes for src/pluggables/Dockerfile: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ COPY src/device/service/. device/service/
COPY src/monitoring/__init__.py monitoring/__init__.py
COPY src/monitoring/client/. monitoring/client/
COPY src/pluggables/. pluggables/
COPY pytest.ini pytest.ini

# Start the service
ENTRYPOINT ["python", "-m", "pluggables.service"]
+59 −127

File changed.

Preview size limit exceeded, changes collapsed.

Loading