diff --git a/src/tests/Fixtures.py b/src/tests/Fixtures.py new file mode 100644 index 0000000000000000000000000000000000000000..aeead8448651b386f4c69d12c139b6043fe5ef55 --- /dev/null +++ b/src/tests/Fixtures.py @@ -0,0 +1,38 @@ +# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) +# +# 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 pytest +from common.Settings import get_setting +from compute.tests.mock_osm.MockOSM import MockOSM +from context.client.ContextClient import ContextClient +from device.client.DeviceClient import DeviceClient +from monitoring.client.MonitoringClient import MonitoringClient + +@pytest.fixture(scope='session') +def context_client(): + _client = ContextClient() + yield _client + _client.close() + +@pytest.fixture(scope='session') +def device_client(): + _client = DeviceClient() + yield _client + _client.close() + +@pytest.fixture(scope='session') +def monitoring_client(): + _client = MonitoringClient() + yield _client + _client.close() diff --git a/src/tests/ecoc22/tests/Fixtures.py b/src/tests/ecoc22/tests/Fixtures.py index 70b41bdcb159552daa3dcf0c041a3713e2d1c821..0e5c7fbe3107ea55ba8243be18e9b100571d1c4b 100644 --- a/src/tests/ecoc22/tests/Fixtures.py +++ b/src/tests/ecoc22/tests/Fixtures.py @@ -1,24 +1,24 @@ +# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) +# +# 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 pytest from common.Settings import get_setting from compute.tests.mock_osm.MockOSM import MockOSM -from context.client.ContextClient import ContextClient -from device.client.DeviceClient import DeviceClient #from .Objects_BigNet import WIM_MAPPING, WIM_PASSWORD, WIM_USERNAME from .Objects_DC_CSGW_TN import WIM_MAPPING, WIM_PASSWORD, WIM_USERNAME #from .Objects_DC_CSGW_TN_OLS import WIM_MAPPING, WIM_PASSWORD, WIM_USERNAME -@pytest.fixture(scope='session') -def context_client(): - _client = ContextClient() - yield _client - _client.close() - -@pytest.fixture(scope='session') -def device_client(): - _client = DeviceClient() - yield _client - _client.close() - @pytest.fixture(scope='session') def osm_wim(): wim_url = 'http://{:s}:{:s}'.format( diff --git a/src/tests/ecoc22/tests/test_functional_bootstrap.py b/src/tests/ecoc22/tests/test_functional_bootstrap.py index 14ee21658838b21d989646134f263f7961fc6c11..75f2bddf2c3bb21084efb6be3f5957df122da429 100644 --- a/src/tests/ecoc22/tests/test_functional_bootstrap.py +++ b/src/tests/ecoc22/tests/test_functional_bootstrap.py @@ -16,7 +16,7 @@ import logging from common.proto.context_pb2 import Context, ContextId, Device, DeviceId, Empty, Link, LinkId, Topology, TopologyId from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient -from .Fixtures import context_client, device_client +from tests.Fixtures import context_client, device_client #from .Objects_BigNet import CONTEXT_ID, CONTEXTS, DEVICES, LINKS, TOPOLOGIES #from .Objects_DC_CSGW_TN import CONTEXT_ID, CONTEXTS, DEVICES, LINKS, TOPOLOGIES, OBJECTS_PER_TOPOLOGY #from .Objects_DC_CSGW_TN_OLS import CONTEXT_ID, CONTEXTS, DEVICES, LINKS, TOPOLOGIES, OBJECTS_PER_TOPOLOGY diff --git a/src/tests/ecoc22/tests/test_functional_cleanup.py b/src/tests/ecoc22/tests/test_functional_cleanup.py index 2fc61e818ac5371ea0730ce40db4f69e56324668..017cc991dd5bb49f6f02f178fc4354653b7bea43 100644 --- a/src/tests/ecoc22/tests/test_functional_cleanup.py +++ b/src/tests/ecoc22/tests/test_functional_cleanup.py @@ -17,7 +17,7 @@ from common.proto.context_pb2 import ContextId, DeviceId, Empty, LinkId, Topolog from common.tools.object_factory.Context import json_context_id from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient -from .Fixtures import context_client, device_client +from tests.Fixtures import context_client, device_client #from .Objects_BigNet import CONTEXT_ID, CONTEXTS, DEVICES, LINKS, TOPOLOGIES #from .Objects_DC_CSGW_TN import CONTEXT_ID, CONTEXTS, DEVICES, LINKS, TOPOLOGIES #from .Objects_DC_CSGW_TN_OLS import CONTEXT_ID, CONTEXTS, DEVICES, LINKS, TOPOLOGIES diff --git a/src/tests/ecoc22/tests/test_functional_create_service.py b/src/tests/ecoc22/tests/test_functional_create_service.py index 2f576db836b6868dbc8617c1e81686b4f6ee5093..8c9ca36a96d161f10ed69c1a86794abf78555571 100644 --- a/src/tests/ecoc22/tests/test_functional_create_service.py +++ b/src/tests/ecoc22/tests/test_functional_create_service.py @@ -17,7 +17,8 @@ from common.proto.context_pb2 import ContextId, Empty, ServiceTypeEnum from common.tools.grpc.Tools import grpc_message_to_json_string from compute.tests.mock_osm.MockOSM import MockOSM from context.client.ContextClient import ContextClient -from .Fixtures import context_client, osm_wim +from tests.Fixtures import context_client +from .Fixtures import osm_wim #from .Objects_BigNet import ( # CONTEXT_ID, CONTEXTS, DEVICES, LINKS, TOPOLOGIES, WIM_SERVICE_CONNECTION_POINTS, WIM_SERVICE_TYPE) #from .Objects_DC_CSGW_TN import ( diff --git a/src/tests/ecoc22/tests/test_functional_delete_service.py b/src/tests/ecoc22/tests/test_functional_delete_service.py index 89d7a621fb21a7c26da8bd64269ca1e02ececebb..de152ebb71111c9201dfde18262586b242b04083 100644 --- a/src/tests/ecoc22/tests/test_functional_delete_service.py +++ b/src/tests/ecoc22/tests/test_functional_delete_service.py @@ -23,7 +23,8 @@ from common.tools.object_factory.Service import json_service_id from common.tools.grpc.Tools import grpc_message_to_json_string from compute.tests.mock_osm.MockOSM import MockOSM from context.client.ContextClient import ContextClient -from .Fixtures import context_client, osm_wim +from tests.Fixtures import context_client +from .Fixtures import osm_wim #from .Objects_BigNet import ( # CONTEXT_ID, CONTEXTS, DEVICES, LINKS, TOPOLOGIES, WIM_SERVICE_CONNECTION_POINTS, WIM_SERVICE_TYPE) #from .Objects_DC_CSGW_TN import ( diff --git a/src/tests/ofc22/tests/Fixtures.py b/src/tests/ofc22/tests/Fixtures.py new file mode 100644 index 0000000000000000000000000000000000000000..370731e5de14b2c7c4acdcfa86eacfa66f2ffd4b --- /dev/null +++ b/src/tests/ofc22/tests/Fixtures.py @@ -0,0 +1,25 @@ +# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) +# +# 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 pytest +from common.Settings import get_setting +from compute.tests.mock_osm.MockOSM import MockOSM +from .Objects import WIM_MAPPING, WIM_PASSWORD, WIM_USERNAME + + +@pytest.fixture(scope='session') +def osm_wim(): + wim_url = 'http://{:s}:{:s}'.format( + get_setting('COMPUTESERVICE_SERVICE_HOST'), str(get_setting('COMPUTESERVICE_SERVICE_PORT_HTTP'))) + return MockOSM(wim_url, WIM_MAPPING, WIM_USERNAME, WIM_PASSWORD) diff --git a/src/tests/ofc22/tests/test_functional_bootstrap.py b/src/tests/ofc22/tests/test_functional_bootstrap.py index 3ea9393c5e7f575b24a7fd0ec2f5de929900d066..76c52810bb855a28f772dcc564e97e9f3ff1f92e 100644 --- a/src/tests/ofc22/tests/test_functional_bootstrap.py +++ b/src/tests/ofc22/tests/test_functional_bootstrap.py @@ -14,36 +14,24 @@ import copy, logging, pytest from common.Settings import get_setting +from common.proto.monitoring_pb2 import KpiDescriptorList from common.tests.EventTools import EVENT_CREATE, EVENT_UPDATE, check_events from common.tools.object_factory.Context import json_context_id from common.tools.object_factory.Device import json_device_id from common.tools.object_factory.Link import json_link_id from common.tools.object_factory.Topology import json_topology_id from context.client.ContextClient import ContextClient +from monitoring.client.MonitoringClient import MonitoringClient from context.client.EventsCollector import EventsCollector from common.proto.context_pb2 import Context, ContextId, Device, Empty, Link, Topology from device.client.DeviceClient import DeviceClient from .Objects import CONTEXT_ID, CONTEXTS, DEVICES, LINKS, TOPOLOGIES - +from tests.Fixtures import context_client, device_client, monitoring_client LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) -@pytest.fixture(scope='session') -def context_client(): - _client = ContextClient(get_setting('CONTEXTSERVICE_SERVICE_HOST'), get_setting('CONTEXTSERVICE_SERVICE_PORT_GRPC')) - yield _client - _client.close() - - -@pytest.fixture(scope='session') -def device_client(): - _client = DeviceClient(get_setting('DEVICESERVICE_SERVICE_HOST'), get_setting('DEVICESERVICE_SERVICE_PORT_GRPC')) - yield _client - _client.close() - - def test_scenario_empty(context_client : ContextClient): # pylint: disable=redefined-outer-name # ----- List entities - Ensure database is empty ------------------------------------------------------------------- response = context_client.ListContexts(Empty()) @@ -202,3 +190,15 @@ def test_links_created(context_client : ContextClient): # pylint: disable=redef response = context_client.ListServices(ContextId(**CONTEXT_ID)) assert len(response.services) == 0 + + +def test_scenario_kpis_created(monitoring_client: MonitoringClient): + """ + This test validates that KPIs related to the service/device/endpoint were created + during the service creation process. + """ + response: KpiDescriptorList = monitoring_client.GetKpiDescriptorList(Empty()) + LOGGER.info("Number of KPIs created: {}".format(len(response.kpi_descriptor_list))) + # TODO: replace the magic number `16` below for a formula that adapts to the number + # of links and devices + assert len(response.kpi_descriptor_list) == 16 diff --git a/src/tests/ofc22/tests/test_functional_cleanup.py b/src/tests/ofc22/tests/test_functional_cleanup.py index 60bb86b50853680e0699906dcb28ebd2e8777bb4..b0dfe54900f5a806607fcd669942e7fa592dcbaa 100644 --- a/src/tests/ofc22/tests/test_functional_cleanup.py +++ b/src/tests/ofc22/tests/test_functional_cleanup.py @@ -23,26 +23,13 @@ from context.client.ContextClient import ContextClient from context.client.EventsCollector import EventsCollector from common.proto.context_pb2 import ContextId, DeviceId, Empty, LinkId, TopologyId from device.client.DeviceClient import DeviceClient +from tests.Fixtures import context_client, device_client from .Objects import CONTEXT_ID, CONTEXTS, DEVICES, LINKS, TOPOLOGIES LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) -@pytest.fixture(scope='session') -def context_client(): - _client = ContextClient(get_setting('CONTEXTSERVICE_SERVICE_HOST'), get_setting('CONTEXTSERVICE_SERVICE_PORT_GRPC')) - yield _client - _client.close() - - -@pytest.fixture(scope='session') -def device_client(): - _client = DeviceClient(get_setting('DEVICESERVICE_SERVICE_HOST'), get_setting('DEVICESERVICE_SERVICE_PORT_GRPC')) - yield _client - _client.close() - - def test_services_removed(context_client : ContextClient): # pylint: disable=redefined-outer-name # ----- List entities - Ensure service is removed ------------------------------------------------------------------ response = context_client.ListContexts(Empty()) diff --git a/src/tests/ofc22/tests/test_functional_create_service.py b/src/tests/ofc22/tests/test_functional_create_service.py index 1f5b80cbf250a7b58321fcae693acf078b6b0a67..5615f119b91fba10dd767d7188b303f926750e06 100644 --- a/src/tests/ofc22/tests/test_functional_create_service.py +++ b/src/tests/ofc22/tests/test_functional_create_service.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging, pytest +import logging, pytest, random, time from common.DeviceTypes import DeviceTypeEnum from common.Settings import get_setting from common.tests.EventTools import EVENT_CREATE, EVENT_UPDATE, check_events @@ -22,11 +22,14 @@ from common.tools.object_factory.Service import json_service_id from common.tools.grpc.Tools import grpc_message_to_json_string from compute.tests.mock_osm.MockOSM import MockOSM from context.client.ContextClient import ContextClient +from monitoring.client.MonitoringClient import MonitoringClient from context.client.EventsCollector import EventsCollector from common.proto.context_pb2 import ContextId, Empty +from tests.Fixtures import context_client, monitoring_client +from .Fixtures import osm_wim from .Objects import ( CONTEXT_ID, CONTEXTS, DEVICE_O1_UUID, DEVICE_R1_UUID, DEVICE_R3_UUID, DEVICES, LINKS, TOPOLOGIES, - WIM_MAPPING, WIM_PASSWORD, WIM_SERVICE_CONNECTION_POINTS, WIM_SERVICE_TYPE, WIM_USERNAME) + WIM_SERVICE_CONNECTION_POINTS, WIM_SERVICE_TYPE) LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) @@ -35,20 +38,6 @@ DEVTYPE_EMU_PR = DeviceTypeEnum.EMULATED_PACKET_ROUTER.value DEVTYPE_EMU_OLS = DeviceTypeEnum.EMULATED_OPEN_LINE_SYSTEM.value -@pytest.fixture(scope='session') -def context_client(): - _client = ContextClient(get_setting('CONTEXTSERVICE_SERVICE_HOST'), get_setting('CONTEXTSERVICE_SERVICE_PORT_GRPC')) - yield _client - _client.close() - - -@pytest.fixture(scope='session') -def osm_wim(): - wim_url = 'http://{:s}:{:s}'.format( - get_setting('COMPUTESERVICE_SERVICE_HOST'), str(get_setting('COMPUTESERVICE_SERVICE_PORT_HTTP'))) - return MockOSM(wim_url, WIM_MAPPING, WIM_USERNAME, WIM_PASSWORD) - - def test_scenario_is_correct(context_client : ContextClient): # pylint: disable=redefined-outer-name # ----- List entities - Ensure links are created ------------------------------------------------------------------- response = context_client.ListContexts(Empty()) @@ -69,8 +58,9 @@ def test_scenario_is_correct(context_client : ContextClient): # pylint: disable def test_service_creation(context_client : ContextClient, osm_wim : MockOSM): # pylint: disable=redefined-outer-name # ----- Start the EventsCollector ---------------------------------------------------------------------------------- - #events_collector = EventsCollector(context_client, log_events_received=True) - #events_collector.start() + # TODO: restablish the tests of the events + # events_collector = EventsCollector(context_client, log_events_received=True) + # events_collector.start() # ----- Create Service --------------------------------------------------------------------------------------------- service_uuid = osm_wim.create_connectivity_service(WIM_SERVICE_TYPE, WIM_SERVICE_CONNECTION_POINTS) @@ -78,30 +68,30 @@ def test_service_creation(context_client : ContextClient, osm_wim : MockOSM): # # ----- Validate collected events ---------------------------------------------------------------------------------- - #packet_connection_uuid = '{:s}:{:s}'.format(service_uuid, DEVTYPE_EMU_PR) - #optical_connection_uuid = '{:s}:optical:{:s}'.format(service_uuid, DEVTYPE_EMU_OLS) - #optical_service_uuid = '{:s}:optical'.format(service_uuid) + # packet_connection_uuid = '{:s}:{:s}'.format(service_uuid, DEVTYPE_EMU_PR) + # optical_connection_uuid = '{:s}:optical:{:s}'.format(service_uuid, DEVTYPE_EMU_OLS) + # optical_service_uuid = '{:s}:optical'.format(service_uuid) - #expected_events = [ + # expected_events = [ # # Create packet service and add first endpoint # ('ServiceEvent', EVENT_CREATE, json_service_id(service_uuid, context_id=CONTEXT_ID)), # ('ServiceEvent', EVENT_UPDATE, json_service_id(service_uuid, context_id=CONTEXT_ID)), - # + # # Configure OLS controller, create optical service, create optical connection # ('DeviceEvent', EVENT_UPDATE, json_device_id(DEVICE_O1_UUID)), # ('ServiceEvent', EVENT_CREATE, json_service_id(optical_service_uuid, context_id=CONTEXT_ID)), # ('ConnectionEvent', EVENT_CREATE, json_connection_id(optical_connection_uuid)), - # + # # Configure endpoint packet devices, add second endpoint to service, create connection # ('DeviceEvent', EVENT_UPDATE, json_device_id(DEVICE_R1_UUID)), # ('DeviceEvent', EVENT_UPDATE, json_device_id(DEVICE_R3_UUID)), # ('ServiceEvent', EVENT_UPDATE, json_service_id(service_uuid, context_id=CONTEXT_ID)), # ('ConnectionEvent', EVENT_CREATE, json_connection_id(packet_connection_uuid)), - #] - #check_events(events_collector, expected_events) + # ] + # check_events(events_collector, expected_events) - # ----- Stop the EventsCollector ----------------------------------------------------------------------------------- - #events_collector.stop() + # # ----- Stop the EventsCollector ----------------------------------------------------------------------------------- + # events_collector.stop() def test_scenario_service_created(context_client : ContextClient): # pylint: disable=redefined-outer-name @@ -127,3 +117,17 @@ def test_scenario_service_created(context_client : ContextClient): # pylint: di LOGGER.info(' ServiceId[{:s}] => Connections[{:d}] = {:s}'.format( grpc_message_to_json_string(service_id), len(response.connections), grpc_message_to_json_string(response))) assert len(response.connections) == 1 # one connection per service + + +def test_scenario_kpi_values_created(monitoring_client: MonitoringClient): + """ + This test validates that KPI values have been inserted into the monitoring database. + We short k KPI descriptors to test. + """ + response = monitoring_client.GetKpiDescriptorList(Empty()) + kpi_descriptors = random.choices(response.kpi_descriptor_list, k=2) + + for kpi_descriptor in kpi_descriptors: + response = monitoring_client.GetInstantKpi(kpi_descriptor.kpi_id) + assert response.kpi_id.kpi_id.uuid == kpi_descriptor.kpi_id.kpi_id.uuid + assert response.timestamp.timestamp > 0 diff --git a/src/tests/ofc22/tests/test_functional_delete_service.py b/src/tests/ofc22/tests/test_functional_delete_service.py index f0cc916cf9da794ec32550a609e4f45962370cfc..5d9568cd81906ac76b600a2253a5e0bdf741bc01 100644 --- a/src/tests/ofc22/tests/test_functional_delete_service.py +++ b/src/tests/ofc22/tests/test_functional_delete_service.py @@ -24,6 +24,8 @@ from compute.tests.mock_osm.MockOSM import MockOSM from context.client.ContextClient import ContextClient from context.client.EventsCollector import EventsCollector from common.proto.context_pb2 import ContextId, Empty, ServiceTypeEnum +from tests.Fixtures import context_client +from .Fixtures import osm_wim from .Objects import ( CONTEXT_ID, CONTEXTS, DEVICE_O1_UUID, DEVICE_R1_UUID, DEVICE_R3_UUID, DEVICES, LINKS, TOPOLOGIES, WIM_MAPPING, WIM_PASSWORD, WIM_USERNAME) @@ -36,20 +38,6 @@ DEVTYPE_EMU_PR = DeviceTypeEnum.EMULATED_PACKET_ROUTER.value DEVTYPE_EMU_OLS = DeviceTypeEnum.EMULATED_OPEN_LINE_SYSTEM.value -@pytest.fixture(scope='session') -def context_client(): - _client = ContextClient(get_setting('CONTEXTSERVICE_SERVICE_HOST'), get_setting('CONTEXTSERVICE_SERVICE_PORT_GRPC')) - yield _client - _client.close() - - -@pytest.fixture(scope='session') -def osm_wim(): - wim_url = 'http://{:s}:{:s}'.format( - get_setting('COMPUTESERVICE_SERVICE_HOST'), str(get_setting('COMPUTESERVICE_SERVICE_PORT_HTTP'))) - return MockOSM(wim_url, WIM_MAPPING, WIM_USERNAME, WIM_PASSWORD) - - def test_scenario_is_correct(context_client : ContextClient): # pylint: disable=redefined-outer-name # ----- List entities - Ensure service is created ------------------------------------------------------------------ response = context_client.ListContexts(Empty())