From 25bfd5e306de7336b5dff32425da6b6958b99a47 Mon Sep 17 00:00:00 2001 From: "lukasz.rajewski@t-mobile.pl" Date: Mon, 25 Mar 2024 12:43:54 +0000 Subject: Fix SDC v2 distribution status Check in the status if DOWNLOAD_OK is present Issue-ID: TEST-404 Signed-off-by: Lukasz Rajewski Change-Id: I270cdc6abfbe658fcd1940f25fa440e11f52e778 --- src/onapsdk/sdc2/service.py | 21 ++++++++++++++++++--- src/onapsdk/version.py | 2 +- tests/test_sdc2_service.py | 13 ++++++++++++- tests/test_version.py | 2 +- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/onapsdk/sdc2/service.py b/src/onapsdk/sdc2/service.py index 1ec64b5..079fff5 100644 --- a/src/onapsdk/sdc2/service.py +++ b/src/onapsdk/sdc2/service.py @@ -57,6 +57,19 @@ class ServiceDistribution(SDC): status: str error_reason: str + @property + def distributed(self) -> bool: + """Flag to detrmine if status is distributed. + + If status is not DOWNLOAD_OK it means that component is not yet + distributed and we need to wait for status update. + + Returns: + bool: True if distribution of component was completed. + + """ + return self.status == "DOWNLOAD_OK" + @property def failed(self) -> bool: """Flag to determine if distribution status is failed or not. @@ -137,17 +150,19 @@ class ServiceDistribution(SDC): @property def _distribution_components_test(self) -> bool: - """Test to check if all required components were notified about distribution. + """Test to check if all required components were notified and downloaded artifacts. List of required components can be configured via SDC_SERVICE_DISTRIBUTION_COMPONENTS setting value. Returns: - bool: True if all required components were notified, False otherwise + bool: True if all required components were notified and artifacts were downloaded + False otherwise """ notified_components_set: Set[str] = { - distribution.component_id for distribution in self.distribution_status_list + distribution.component_id for distribution in filter( + lambda item: item.distributed, self.distribution_status_list) } return set(settings.SDC_SERVICE_DISTRIBUTION_COMPONENTS).issubset(notified_components_set) diff --git a/src/onapsdk/version.py b/src/onapsdk/version.py index d606f96..33acbae 100644 --- a/src/onapsdk/version.py +++ b/src/onapsdk/version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "13.0.5" +__version__ = "13.0.6" diff --git a/tests/test_sdc2_service.py b/tests/test_sdc2_service.py index 69b732b..23fab64 100644 --- a/tests/test_sdc2_service.py +++ b/tests/test_sdc2_service.py @@ -540,13 +540,24 @@ def test_service_distribution_distribution_components_test(mock_distribution_sta error_reason=str(uuid4()) ) for component_id in settings.SDC_SERVICE_DISTRIBUTION_COMPONENTS ] + assert sd._distribution_components_test is False + + mock_distribution_status_list.return_value = [ + ServiceDistribution.DistributionStatus( + component_id=component_id, + timestamp=str(randint(0, maxsize)), + status="DOWNLOAD_OK", + url=str(uuid4()), + error_reason=str(uuid4()) + ) for component_id in settings.SDC_SERVICE_DISTRIBUTION_COMPONENTS + ] assert sd._distribution_components_test is True mock_distribution_status_list.return_value = [ ServiceDistribution.DistributionStatus( component_id=component_id, timestamp=str(randint(0, maxsize)), - status=str(uuid4()), + status="DOWNLOAD_OK", url=str(uuid4()), error_reason=str(uuid4()) ) for component_id in settings.SDC_SERVICE_DISTRIBUTION_COMPONENTS + ["additional-test-component"] diff --git a/tests/test_version.py b/tests/test_version.py index 7633f9f..9afad27 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -17,4 +17,4 @@ import onapsdk.version as version def test_version(): """Check version is the right one.""" - assert version.__version__ == '13.0.5' + assert version.__version__ == '13.0.6' -- cgit 1.2.3-korg