Python SDK 7.4.0 compatibility 82/117582/3
authorMichal Jagiello <michal.jagiello@t-mobile.pl>
Fri, 5 Feb 2021 20:37:02 +0000 (20:37 +0000)
committermorganrol <morgan.richomme@orange.com>
Mon, 8 Feb 2021 17:12:38 +0000 (18:12 +0100)
Use Python SDK exceptions.

Issue-ID: TEST-302
Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl>
Change-Id: I76996817c0d7b91c0214ad521c3768682ff07e83

12 files changed:
requirements.txt
src/onaptests/scenario/basic_network.py
src/onaptests/scenario/basic_vm.py
src/onaptests/steps/base.py
src/onaptests/steps/cloud/cloud_region_create.py
src/onaptests/steps/cloud/complex_create.py
src/onaptests/steps/cloud/customer_create.py
src/onaptests/steps/cloud/k8s_connectivity_info_create.py
src/onaptests/steps/cloud/register_cloud.py
src/onaptests/steps/instantiate/k8s_profile_create.py
src/onaptests/steps/instantiate/service_ala_carte.py
src/onaptests/steps/instantiate/service_macro.py

index ead56f4..fec6816 100644 (file)
@@ -1,6 +1,6 @@
 xtesting
 openstacksdk
-onapsdk>=7.1.0
+onapsdk==7.4.0
 jinja2
 kubernetes
 docker
\ No newline at end of file
index 8aafd32..7a0b9f7 100644 (file)
@@ -5,6 +5,7 @@ import time
 
 from xtesting.core import testcase
 from onapsdk.configuration import settings
+from onapsdk.exceptions import SDKException
 
 import onaptests.utils.exceptions as onap_test_exceptions
 from onaptests.steps.instantiate.vl_ala_carte import YamlTemplateVlAlaCarteInstantiateStep
@@ -40,8 +41,8 @@ class BasicNetwork(testcase.TestCase):
                 time.sleep(settings.CLEANUP_ACTIVITY_TIMER)
                 try:
                     self.test.cleanup()
-                except ValueError as error:
-                    self.__logger.info("service deleted as expected {0}".format(error))
+                except SDKException as error:
+                    self.__logger.info("service deletion error {0}".format(error))
                 self.result = 100
             else:
                 self.__logger.info("No cleanup requested. Test completed.")
index cbf9b7c..8972a8c 100644 (file)
@@ -5,6 +5,7 @@ import time
 
 from xtesting.core import testcase
 from onapsdk.configuration import settings
+from onapsdk.exceptions import SDKException
 
 import onaptests.utils.exceptions as onap_test_exceptions
 from onaptests.steps.instantiate.vf_module_ala_carte import YamlTemplateVfModuleAlaCarteInstantiateStep
@@ -46,6 +47,8 @@ class BasicVm(testcase.TestCase):
         except onap_test_exceptions.OnapTestException as exc:
             self.result = 0
             self.__logger.error(exc.error_message)
+        except SDKException as error:
+            self.__logger.info("service error {0}".format(error))
         finally:
             self.stop_time = time.time()
 
index aa2be6a..97924bd 100644 (file)
@@ -4,8 +4,9 @@ import time
 
 from abc import ABC, abstractmethod
 from typing import List
-from onapsdk.configuration import settings
 from onapsdk.aai.business import Customer
+from onapsdk.configuration import settings
+from onapsdk.exceptions import SettingsError
 
 from .reports_collection import Report, ReportsCollection, ReportStepStatus
 
@@ -26,7 +27,7 @@ class BaseStep(ABC):
         # Setup Proxy if SOCK_HTTP is defined in settings
         try:
             cls.set_proxy(settings.SOCK_HTTP)
-        except AttributeError:
+        except SettingsError:
             pass
 
     def __init__(self, cleanup: bool = False) -> None:
index ba46466..21c846f 100644 (file)
@@ -1,6 +1,7 @@
 """A&AI cloud region creation module."""
 from onapsdk.aai.cloud_infrastructure import CloudRegion
 from onapsdk.configuration import settings
+from onapsdk.exceptions import ResourceNotFound
 
 from ..base import BaseStep
 
@@ -38,7 +39,7 @@ class CloudRegionCreateStep(BaseStep):
                 cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER,
                 cloud_region_id=settings.CLOUD_REGION_ID,
             )
-        except ValueError:
+        except ResourceNotFound:
             CloudRegion.create(
                 cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER,
                 cloud_region_id=settings.CLOUD_REGION_ID,
index 1bb7e51..60565f4 100644 (file)
@@ -1,5 +1,6 @@
 from onapsdk.aai.cloud_infrastructure import Complex
 from onapsdk.configuration import settings
+from onapsdk.exceptions import APIError
 
 from ..base import BaseStep
 
@@ -27,8 +28,10 @@ class ComplexCreateStep(BaseStep):
 
         """
         super().execute()
-        Complex.create(
-            physical_location_id=settings.COMPLEX_PHYSICAL_LOCATION_ID,
-            data_center_code=settings.COMPLEX_DATA_CENTER_CODE,
-            name=settings.COMPLEX_PHYSICAL_LOCATION_ID
-        )
+        try:
+            Complex.create(
+                physical_location_id=settings.COMPLEX_PHYSICAL_LOCATION_ID,
+                data_center_code=settings.COMPLEX_DATA_CENTER_CODE,
+                name=settings.COMPLEX_PHYSICAL_LOCATION_ID)
+        except APIError:
+            self._logger.warn("Try to update the complex failed.")
index 6c78d55..1cc0879 100644 (file)
@@ -1,5 +1,6 @@
 from onapsdk.aai.business import Customer
 from onapsdk.configuration import settings
+from onapsdk.exceptions import APIError
 
 from ..base import BaseStep
 
@@ -25,4 +26,7 @@ class CustomerCreateStep(BaseStep):
          - GLOBAL_CUSTOMER_ID.
         """
         super().execute()
-        Customer.create(settings.GLOBAL_CUSTOMER_ID, settings.GLOBAL_CUSTOMER_ID, "INFRA")
+        try:
+            Customer.create(settings.GLOBAL_CUSTOMER_ID, settings.GLOBAL_CUSTOMER_ID, "INFRA")
+        except APIError:
+            self._logger.warn("Try to update the Customer failed.")
index de0e683..2855be7 100644 (file)
@@ -1,5 +1,6 @@
 """Connectivity info creation module."""
 from onapsdk.configuration import settings
+from onapsdk.exceptions import APIError
 from onapsdk.msb.k8s import ConnectivityInfo
 
 from ..base import BaseStep
@@ -31,7 +32,7 @@ class K8SConnectivityInfoStep(BaseStep):
         try:
             self._logger.info("Check if k8s connectivity information exists")
             ConnectivityInfo.get_connectivity_info_by_region_id(settings.CLOUD_REGION_ID)
-        except ValueError:
+        except APIError:
             self._logger.info("Create the k8s connectivity information")
             ConnectivityInfo.create(settings.CLOUD_REGION_ID,
                                     settings.CLOUD_REGION_CLOUD_OWNER,
index 72da4f7..58c3e35 100644 (file)
@@ -4,6 +4,7 @@ from uuid import uuid4
 
 from onapsdk.aai.cloud_infrastructure import CloudRegion
 from onapsdk.configuration import settings
+from onapsdk.exceptions import ResourceNotFound
 
 from ..base import BaseStep
 from onaptests.steps.cloud.cloud_region_create import CloudRegionCreateStep
@@ -45,11 +46,11 @@ class RegisterCloudRegionStep(BaseStep):
          - TENANT_NAME.
         """
         super().execute()
-        cloud_region: CloudRegion = CloudRegion.get_by_id(
-            cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER,
-            cloud_region_id=settings.CLOUD_REGION_ID,
-        )
-        if not list(cloud_region.esr_system_infos):
+        try:
+            cloud_region: CloudRegion = CloudRegion.get_by_id(
+                cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER,
+                cloud_region_id=settings.CLOUD_REGION_ID)
+        except ResourceNotFound:
             cloud_region.add_esr_system_info(
                 esr_system_info_id=str(uuid4()),
                 user_name=settings.VIM_USERNAME,
@@ -78,7 +79,7 @@ class RegisterCloudRegionStep(BaseStep):
         # if it does not exist, create it
         try:
             cloud_region.get_tenant(settings.TENANT_ID)
-        except ValueError:
+        except ResourceNotFound:
             self._logger.warning("Impossible to retrieve the Specificed Tenant")
             self._logger.debug("If no multicloud selected, add the tenant")
             cloud_region.add_tenant(
@@ -90,7 +91,7 @@ class RegisterCloudRegionStep(BaseStep):
         try:
             cloud_region.get_availability_zone_by_name(
                 settings.AVAILABILITY_ZONE_NAME)
-        except ValueError:
+        except ResourceNotFound:
             cloud_region.add_availability_zone(
                 settings.AVAILABILITY_ZONE_NAME,
                 settings.AVAILABILITY_ZONE_TYPE)
index a875f11..c2692c8 100644 (file)
@@ -4,6 +4,7 @@ from yaml import load
 
 from onapsdk.aai.business import Customer, ServiceInstance, ServiceSubscription
 from onapsdk.configuration import settings
+from onapsdk.exceptions import APIError, ResourceNotFound
 from onapsdk.msb.k8s import Definition
 from onapsdk.so.instantiation import VnfParameter
 
@@ -142,7 +143,7 @@ class K8SProfileStep(BaseStep):
                 ######## Check profile for Definition ###################################
                 try:
                     rbdef.get_profile_by_name(k8s_profile_name)
-                except ValueError:
+                except ResourceNotFound:
                     ######## Create profile for Definition ###################################
                     profile = rbdef.create_profile(k8s_profile_name,
                                                    k8s_profile_namespace,
@@ -174,7 +175,7 @@ class K8SProfileStep(BaseStep):
                 try:
                     profile = rbdef.get_profile_by_name(k8s_profile_name)
                     profile.delete()
-                except ValueError:
+                except APIError:
                     self._logger.error("K8s profile deletion %s failed", k8s_profile_name)
                     raise onap_test_exceptions.ProfileCleanupException
         super().cleanup()
index d5e5096..6000e73 100644 (file)
@@ -6,6 +6,7 @@ from onapsdk.aai.cloud_infrastructure import CloudRegion, Tenant
 from onapsdk.aai.business import Customer, ServiceInstance, ServiceSubscription
 from onapsdk.aai.business.owning_entity import OwningEntity as AaiOwningEntity
 from onapsdk.configuration import settings
+from onapsdk.exceptions import ResourceNotFound
 from onapsdk.sdc.service import Service
 from onapsdk.so.instantiation import ServiceInstantiation
 from onapsdk.vid import Project
@@ -66,7 +67,7 @@ class ServiceAlaCarteInstantiateStep(BaseStep):
         try:
             owning_entity = AaiOwningEntity.get_by_owning_entity_name(
                 settings.OWNING_ENTITY)
-        except ValueError:
+        except ResourceNotFound:
             self._logger.info("Owning entity not found, create it")
             owning_entity = AaiOwningEntity.create(settings.OWNING_ENTITY)
         vid_project = Project.create(settings.PROJECT)
@@ -187,7 +188,7 @@ class YamlTemplateServiceAlaCarteInstantiateStep(YamlTemplateBaseStep):
         try:
             owning_entity = AaiOwningEntity.get_by_owning_entity_name(
                 settings.OWNING_ENTITY)
-        except ValueError:
+        except ResourceNotFound:
             self._logger.info("Owning entity not found, create it")
             owning_entity = AaiOwningEntity.create(settings.OWNING_ENTITY)
         vid_project = Project.create(settings.PROJECT)
index 36f0130..04c3931 100644 (file)
@@ -9,6 +9,7 @@ from onapsdk.aai.business.owning_entity import OwningEntity
 from onapsdk.aai.cloud_infrastructure.cloud_region import CloudRegion
 from onapsdk.aai.cloud_infrastructure.tenant import Tenant
 from onapsdk.configuration import settings
+from onapsdk.exceptions import ResourceNotFound
 from onapsdk.sdc.service import Service
 from onapsdk.so.instantiation import ServiceInstantiation
 from onapsdk.vid import LineOfBusiness, Platform, Project
@@ -137,7 +138,7 @@ class YamlTemplateServiceMacroInstantiateStep(YamlTemplateBaseStep):
         try:
             owning_entity = OwningEntity.get_by_owning_entity_name(
                 settings.OWNING_ENTITY)
-        except ValueError:
+        except ResourceNotFound:
             self._logger.info("Owning entity not found, create it")
             owning_entity = OwningEntity.create(settings.OWNING_ENTITY)
         vid_project: Project = Project(settings.PROJECT)