Commit 47d1404d authored by Ville Hallivuori's avatar Ville Hallivuori
Browse files

Pull request #5: vhallivu/xr_pytest_with_http_mock

Merge in XRCA/teraflow from vhallivu/xr_pytest_with_http_mock to xr_development

Squashed commit of the following:

commit d0688826c369c9320027cc6b3eef34d82674f1ec
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Tue Aug 30 07:29:30 2022 +0300

    XR Teraflow driver logging cleanup

commit 89922d37c7709b4fe5acb3b122f5d6aea023c956
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Tue Aug 30 07:04:15 2022 +0300

    Improved HTTP request logging

commit c50420a5358686dbafa1cf61acf35ac753a2dc5f
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Mon Aug 29 14:33:28 2022 +0300

    POST refactoring

commit a133ed135816fd252bdc026e25598e8c2e65e8ec
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Mon Aug 29 13:24:15 2022 +0300

    More refactoring

commit 202c9827f7373dabc98ac2e72464fca104d6ba64
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Mon Aug 29 08:16:07 2022 +0300

    Start of HTTP refactoring

commit 8595e63c2cc6fef51476315134c12f6f4e700a46
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Wed Aug 24 08:06:58 2022 +0300

    Add missing mutexes to XrDriver

commit d250437104322de12232320aa55e371f9777875a
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Tue Aug 23 17:54:48 2022 +0300

    Connection update unit test

commit 5240a96941b43e2cc2488443bb927475fc96ac81
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Mon Aug 22 14:34:56 2022 +0300

    Improved HTTP get error handling

commit 10fa5132aa47db2a69345c5f69a60dd9e2c25c74
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Mon Aug 22 11:51:12 2022 +0300

    Higher level unit test for XR

commit 242f44363b8bdb63e02ec92c034aa3208abd7219
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Sat Aug 20 16:59:18 2022 +0300

    Improved test data for constellation pytests

commit 3f834ba6f7e9448cab77869789ed0ded6d838e70
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Sat Aug 20 16:32:48 2022 +0300

    Initial prototyping of mock based testing for xr
parent c2aeea99
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ python-json-logger==2.0.2
pytz==2021.3
redis==4.1.2
requests==2.27.1
requests-mock==1.9.3
xmltodict==0.12.0

# pip's dependency resolver does not take into account installed packages.
+70 −58
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ class XrDriver(_Driver):
        self.__started = threading.Event()
        self.__terminate = threading.Event()
        self.__timeout = int(settings.get('timeout', 120))
        self.__cm_address = address
        # Mandatory key, an exception will get thrown if missing
        self.__hub_module_name = settings["hub_module_name"]

@@ -47,7 +48,11 @@ class XrDriver(_Driver):

        LOGGER.info(f"XrDriver instantiated, cm {address}:{port}, {settings=}")

    def __str__(self):
        return f"{self.__hub_module_name}@{self.__cm_address}"

    def Connect(self) -> bool:
        LOGGER.info(f"Connect[{self}]")
        with self.__lock:
            if self.__started.is_set():
                return True
@@ -58,18 +63,25 @@ class XrDriver(_Driver):
                return True

    def Disconnect(self) -> bool:
        LOGGER.info(f"Disconnect[{self}]")
        with self.__lock:
            self.__terminate.set()
            return True

    def GetInitialConfig(self) -> List[Tuple[str, Any]]:
        LOGGER.info(f"GetInitialConfig[{self}]")
        with self.__lock:
            return []

    #pylint: disable=dangerous-default-value
    def GetConfig(self, resource_keys : List[str] = []) -> List[Tuple[str, Union[Any, None, Exception]]]:
        LOGGER.info(f"GetConfig[{self}]: {resource_keys=}")
        chk_type('resources', resource_keys, list)

        # Empty resource_keys means all resources. As we only have endpoints, we ignore parameter and always
        # return everything.

        with self.__lock:
            constellation = self.__cm_connection.get_constellation_by_hub_name(self.__hub_module_name)
            if constellation:
                self.__constellation = constellation
@@ -77,13 +89,12 @@ class XrDriver(_Driver):
            else:
                return []


    def SetConfig(self, resources: List[Tuple[str, Any]]) -> List[Union[bool, Exception]]:
        LOGGER.info(f"SetConfig {resources=}")

        LOGGER.info(f"SetConfig[{self}]: {resources=}")
        # Logged config seems like:
        #[('/service[52ff5f0f-fda4-40bd-a0b1-066f4ff04079:optical]', '{"capacity_unit": "GHz", "capacity_value": 1, "direction": "UNIDIRECTIONAL", "input_sip": "XR HUB 1|XR-T4", "layer_protocol_name": "PHOTONIC_MEDIA", "layer_protocol_qualifier": "tapi-photonic-media:PHOTONIC_LAYER_QUALIFIER_NMC", "output_sip": "XR LEAF 1|XR-T1", "uuid": "52ff5f0f-fda4-40bd-a0b1-066f4ff04079:optical"}')]

        with self.__lock:
            if self.__constellation is None:
                self.__constellation = self.__cm_connection.get_constellation_by_hub_name(self.__hub_module_name)

@@ -106,11 +117,12 @@ class XrDriver(_Driver):
            return results

    def DeleteConfig(self, resources: List[Tuple[str, Any]]) -> List[Union[bool, Exception]]:
        LOGGER.info(f"DeleteConfig {resources=}")
        LOGGER.info(f"DeleteConfig[{self}]: {resources=}")

        # Input looks like:
        #  resources=[('/service[c8a35e81-88d8-4468-9afc-a8abd92a64d0:optical]', '{"uuid": "c8a35e81-88d8-4468-9afc-a8abd92a64d0:optical"}')]

        with self.__lock:
            results = []
            if len(resources) == 0:
                return results
+149 −123

File changed.

Preview size limit exceeded, changes collapsed.

+388 −0

File added.

Preview size limit exceeded, changes collapsed.

+130 −1236

File changed.

Preview size limit exceeded, changes collapsed.

Loading