From d3a529f0765b4fd672d3e9ec0a56246bd0e065cd Mon Sep 17 00:00:00 2001
From: gifrerenom <lluis.gifre@cttc.es>
Date: Fri, 14 Mar 2025 20:29:07 +0000
Subject: [PATCH] OFC25 tests:

- Updated topology descriptor files
- Updated test scripts
- Moved old files to separate folder
---
 src/tests/ofc25/{ => _old}/deploy_e2e.sh      |  0
 src/tests/ofc25/{ => _old}/deploy_ip.sh       |  0
 src/tests/ofc25/{ => _old}/deploy_opt.sh      |  0
 .../ofc25/{ => _old}/subscription_ws_e2e.sh   |  0
 .../ofc25/{ => _old}/subscription_ws_ip.sh    |  0
 ...{descriptor_e2e.json => topology_e2e.json} |  0
 .../{descriptor_ip.json => topology_ip.json}  |  0
 ...{descriptor_opt.json => topology_opt.json} |  0
 .../tests/test_functional_bootstrap_e2e.py    | 19 +++++---
 .../tests/test_functional_bootstrap_ip.py     | 10 ++---
 .../tests/test_functional_bootstrap_opt.py    |  2 +-
 .../tests/test_functional_cleanup_e2e.py      | 44 +++++++++++++++++++
 ...eanup.py => test_functional_cleanup_ip.py} |  2 +-
 .../tests/test_functional_cleanup_opt.py      | 44 +++++++++++++++++++
 14 files changed, 106 insertions(+), 15 deletions(-)
 rename src/tests/ofc25/{ => _old}/deploy_e2e.sh (100%)
 rename src/tests/ofc25/{ => _old}/deploy_ip.sh (100%)
 rename src/tests/ofc25/{ => _old}/deploy_opt.sh (100%)
 rename src/tests/ofc25/{ => _old}/subscription_ws_e2e.sh (100%)
 rename src/tests/ofc25/{ => _old}/subscription_ws_ip.sh (100%)
 rename src/tests/ofc25/descriptors/{descriptor_e2e.json => topology_e2e.json} (100%)
 rename src/tests/ofc25/descriptors/{descriptor_ip.json => topology_ip.json} (100%)
 rename src/tests/ofc25/descriptors/{descriptor_opt.json => topology_opt.json} (100%)
 create mode 100644 src/tests/ofc25/tests/test_functional_cleanup_e2e.py
 rename src/tests/ofc25/tests/{test_functional_cleanup.py => test_functional_cleanup_ip.py} (97%)
 create mode 100644 src/tests/ofc25/tests/test_functional_cleanup_opt.py

diff --git a/src/tests/ofc25/deploy_e2e.sh b/src/tests/ofc25/_old/deploy_e2e.sh
similarity index 100%
rename from src/tests/ofc25/deploy_e2e.sh
rename to src/tests/ofc25/_old/deploy_e2e.sh
diff --git a/src/tests/ofc25/deploy_ip.sh b/src/tests/ofc25/_old/deploy_ip.sh
similarity index 100%
rename from src/tests/ofc25/deploy_ip.sh
rename to src/tests/ofc25/_old/deploy_ip.sh
diff --git a/src/tests/ofc25/deploy_opt.sh b/src/tests/ofc25/_old/deploy_opt.sh
similarity index 100%
rename from src/tests/ofc25/deploy_opt.sh
rename to src/tests/ofc25/_old/deploy_opt.sh
diff --git a/src/tests/ofc25/subscription_ws_e2e.sh b/src/tests/ofc25/_old/subscription_ws_e2e.sh
similarity index 100%
rename from src/tests/ofc25/subscription_ws_e2e.sh
rename to src/tests/ofc25/_old/subscription_ws_e2e.sh
diff --git a/src/tests/ofc25/subscription_ws_ip.sh b/src/tests/ofc25/_old/subscription_ws_ip.sh
similarity index 100%
rename from src/tests/ofc25/subscription_ws_ip.sh
rename to src/tests/ofc25/_old/subscription_ws_ip.sh
diff --git a/src/tests/ofc25/descriptors/descriptor_e2e.json b/src/tests/ofc25/descriptors/topology_e2e.json
similarity index 100%
rename from src/tests/ofc25/descriptors/descriptor_e2e.json
rename to src/tests/ofc25/descriptors/topology_e2e.json
diff --git a/src/tests/ofc25/descriptors/descriptor_ip.json b/src/tests/ofc25/descriptors/topology_ip.json
similarity index 100%
rename from src/tests/ofc25/descriptors/descriptor_ip.json
rename to src/tests/ofc25/descriptors/topology_ip.json
diff --git a/src/tests/ofc25/descriptors/descriptor_opt.json b/src/tests/ofc25/descriptors/topology_opt.json
similarity index 100%
rename from src/tests/ofc25/descriptors/descriptor_opt.json
rename to src/tests/ofc25/descriptors/topology_opt.json
diff --git a/src/tests/ofc25/tests/test_functional_bootstrap_e2e.py b/src/tests/ofc25/tests/test_functional_bootstrap_e2e.py
index 27648969b..54225ea3f 100644
--- a/src/tests/ofc25/tests/test_functional_bootstrap_e2e.py
+++ b/src/tests/ofc25/tests/test_functional_bootstrap_e2e.py
@@ -16,6 +16,7 @@ import logging, os, time
 from common.Constants import DEFAULT_CONTEXT_NAME
 from common.proto.context_pb2 import ContextId, DeviceOperationalStatusEnum, Empty
 from common.tools.descriptor.Loader import DescriptorLoader, check_descriptor_load_results, validate_empty_scenario
+from common.tools.grpc.Tools import grpc_message_to_json, grpc_message_to_json_string
 from common.tools.object_factory.Context import json_context_id
 from context.client.ContextClient import ContextClient
 from device.client.DeviceClient import DeviceClient
@@ -24,7 +25,7 @@ from tests.Fixtures import context_client, device_client # pylint: disable=unuse
 LOGGER = logging.getLogger(__name__)
 LOGGER.setLevel(logging.DEBUG)
 
-DESCRIPTOR_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'descriptors', 'descriptor_e2e.json')
+DESCRIPTOR_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'descriptors', 'topology_e2e.json')
 ADMIN_CONTEXT_ID = ContextId(**json_context_id(DEFAULT_CONTEXT_NAME))
 
 def test_scenario_bootstrap(
@@ -50,7 +51,7 @@ def test_scenario_devices_enabled(
     """
     This test validates that the devices are enabled.
     """
-    """     DEVICE_OP_STATUS_ENABLED = DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED
+    DEVICE_OP_STATUS_ENABLED = DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED
 
     num_devices = -1
     num_devices_enabled, num_retry = 0, 0
@@ -59,9 +60,15 @@ def test_scenario_devices_enabled(
         response = context_client.ListDevices(Empty())
         num_devices = len(response.devices)
         num_devices_enabled = 0
+        disabled_devices = list()
         for device in response.devices:
-            if device.device_operational_status != DEVICE_OP_STATUS_ENABLED: continue
-            num_devices_enabled += 1
+            if device.device_operational_status == DEVICE_OP_STATUS_ENABLED:
+                num_devices_enabled += 1
+            else:
+                disabled_devices.append(grpc_message_to_json(device))
         LOGGER.info('Num Devices enabled: {:d}/{:d}'.format(num_devices_enabled, num_devices))
-        num_retry += 1 """
-    assert 1 == 1
+        num_retry += 1
+    if num_devices_enabled != num_devices:
+        LOGGER.info('Disabled Devices: {:s}'.format(str(disabled_devices)))
+    LOGGER.info('Devices: {:s}'.format(grpc_message_to_json_string(response)))
+    assert num_devices_enabled == num_devices
diff --git a/src/tests/ofc25/tests/test_functional_bootstrap_ip.py b/src/tests/ofc25/tests/test_functional_bootstrap_ip.py
index 668213a56..e4ace756f 100644
--- a/src/tests/ofc25/tests/test_functional_bootstrap_ip.py
+++ b/src/tests/ofc25/tests/test_functional_bootstrap_ip.py
@@ -24,7 +24,7 @@ from tests.Fixtures import context_client, device_client # pylint: disable=unuse
 LOGGER = logging.getLogger(__name__)
 LOGGER.setLevel(logging.DEBUG)
 
-DESCRIPTOR_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'descriptors', 'descriptor_ip.json')
+DESCRIPTOR_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'descriptors', 'topology_ip.json')
 ADMIN_CONTEXT_ID = ContextId(**json_context_id(DEFAULT_CONTEXT_NAME))
 
 def test_scenario_bootstrap(
@@ -47,10 +47,7 @@ def test_scenario_bootstrap(
 def test_scenario_devices_enabled(
     context_client : ContextClient,         # pylint: disable=redefined-outer-name
 ) -> None:
-    """
-    This test validates that the devices are enabled.
-    """
-    """     DEVICE_OP_STATUS_ENABLED = DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED
+    DEVICE_OP_STATUS_ENABLED = DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED
 
     num_devices = -1
     num_devices_enabled, num_retry = 0, 0
@@ -63,5 +60,4 @@ def test_scenario_devices_enabled(
             if device.device_operational_status != DEVICE_OP_STATUS_ENABLED: continue
             num_devices_enabled += 1
         LOGGER.info('Num Devices enabled: {:d}/{:d}'.format(num_devices_enabled, num_devices))
-        num_retry += 1 """
-    assert 1 == 1
+        num_retry += 1
diff --git a/src/tests/ofc25/tests/test_functional_bootstrap_opt.py b/src/tests/ofc25/tests/test_functional_bootstrap_opt.py
index f3097519a..32893e5dd 100644
--- a/src/tests/ofc25/tests/test_functional_bootstrap_opt.py
+++ b/src/tests/ofc25/tests/test_functional_bootstrap_opt.py
@@ -24,7 +24,7 @@ from tests.Fixtures import context_client, device_client # pylint: disable=unuse
 LOGGER = logging.getLogger(__name__)
 LOGGER.setLevel(logging.DEBUG)
 
-DESCRIPTOR_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'descriptors', 'descriptor_opt.json')
+DESCRIPTOR_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'descriptors', 'topology_opt.json')
 ADMIN_CONTEXT_ID = ContextId(**json_context_id(DEFAULT_CONTEXT_NAME))
 
 def test_scenario_bootstrap(
diff --git a/src/tests/ofc25/tests/test_functional_cleanup_e2e.py b/src/tests/ofc25/tests/test_functional_cleanup_e2e.py
new file mode 100644
index 000000000..cd294ae90
--- /dev/null
+++ b/src/tests/ofc25/tests/test_functional_cleanup_e2e.py
@@ -0,0 +1,44 @@
+# Copyright 2022-2024 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, os
+from common.Constants import DEFAULT_CONTEXT_NAME
+from common.proto.context_pb2 import ContextId
+from common.tools.descriptor.Loader import DescriptorLoader, validate_empty_scenario
+from common.tools.object_factory.Context import json_context_id
+from context.client.ContextClient import ContextClient
+from device.client.DeviceClient import DeviceClient
+from tests.Fixtures import context_client, device_client    # pylint: disable=unused-import
+
+LOGGER = logging.getLogger(__name__)
+LOGGER.setLevel(logging.DEBUG)
+
+DESCRIPTOR_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'descriptors', 'topology_e2e.json')
+ADMIN_CONTEXT_ID = ContextId(**json_context_id(DEFAULT_CONTEXT_NAME))
+
+def test_scenario_cleanup(
+    context_client : ContextClient, # pylint: disable=redefined-outer-name
+    device_client : DeviceClient,   # pylint: disable=redefined-outer-name
+) -> None:
+    # Verify the scenario has no services/slices
+    response = context_client.GetContext(ADMIN_CONTEXT_ID)
+    assert len(response.service_ids) == 0
+    assert len(response.slice_ids) == 0
+
+    # Load descriptors and validate the base scenario
+    descriptor_loader = DescriptorLoader(
+        descriptors_file=DESCRIPTOR_FILE, context_client=context_client, device_client=device_client)
+    descriptor_loader.validate()
+    descriptor_loader.unload()
+    validate_empty_scenario(context_client)
diff --git a/src/tests/ofc25/tests/test_functional_cleanup.py b/src/tests/ofc25/tests/test_functional_cleanup_ip.py
similarity index 97%
rename from src/tests/ofc25/tests/test_functional_cleanup.py
rename to src/tests/ofc25/tests/test_functional_cleanup_ip.py
index a482c6e46..87c5e2e38 100644
--- a/src/tests/ofc25/tests/test_functional_cleanup.py
+++ b/src/tests/ofc25/tests/test_functional_cleanup_ip.py
@@ -24,7 +24,7 @@ from tests.Fixtures import context_client, device_client    # pylint: disable=un
 LOGGER = logging.getLogger(__name__)
 LOGGER.setLevel(logging.DEBUG)
 
-DESCRIPTOR_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'descriptors', 'topology.json')
+DESCRIPTOR_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'descriptors', 'topology_ip.json')
 ADMIN_CONTEXT_ID = ContextId(**json_context_id(DEFAULT_CONTEXT_NAME))
 
 def test_scenario_cleanup(
diff --git a/src/tests/ofc25/tests/test_functional_cleanup_opt.py b/src/tests/ofc25/tests/test_functional_cleanup_opt.py
new file mode 100644
index 000000000..03fa50fff
--- /dev/null
+++ b/src/tests/ofc25/tests/test_functional_cleanup_opt.py
@@ -0,0 +1,44 @@
+# Copyright 2022-2024 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, os
+from common.Constants import DEFAULT_CONTEXT_NAME
+from common.proto.context_pb2 import ContextId
+from common.tools.descriptor.Loader import DescriptorLoader, validate_empty_scenario
+from common.tools.object_factory.Context import json_context_id
+from context.client.ContextClient import ContextClient
+from device.client.DeviceClient import DeviceClient
+from tests.Fixtures import context_client, device_client    # pylint: disable=unused-import
+
+LOGGER = logging.getLogger(__name__)
+LOGGER.setLevel(logging.DEBUG)
+
+DESCRIPTOR_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'descriptors', 'topology_opt.json')
+ADMIN_CONTEXT_ID = ContextId(**json_context_id(DEFAULT_CONTEXT_NAME))
+
+def test_scenario_cleanup(
+    context_client : ContextClient, # pylint: disable=redefined-outer-name
+    device_client : DeviceClient,   # pylint: disable=redefined-outer-name
+) -> None:
+    # Verify the scenario has no services/slices
+    response = context_client.GetContext(ADMIN_CONTEXT_ID)
+    assert len(response.service_ids) == 0
+    assert len(response.slice_ids) == 0
+
+    # Load descriptors and validate the base scenario
+    descriptor_loader = DescriptorLoader(
+        descriptors_file=DESCRIPTOR_FILE, context_client=context_client, device_client=device_client)
+    descriptor_loader.validate()
+    descriptor_loader.unload()
+    validate_empty_scenario(context_client)
-- 
GitLab