3 # ============LICENSE_START=======================================================
4 # ORAN SMO PACKAGE - PYTHONSDK TESTS
5 # ================================================================================
6 # Copyright (C) 2021-2022 AT&T Intellectual Property. All rights
8 # ================================================================================
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 # ============LICENSE_END============================================
21 # ===================================================================
25 """Cl usecase utils module."""
28 from waiting import wait
29 from onapsdk.configuration import settings
30 from oransdk.policy.clamp import ClampToscaTemplate
32 logging.config.dictConfig(settings.LOG_CONFIG)
33 logger = logging.getLogger("Cl usecae utils")
34 clamp = ClampToscaTemplate(settings.CLAMP_BASICAUTH)
37 class ClCommissioningUtils():
38 """Can be used to have cl usecase utils methods."""
41 def clean_instance(cls):
42 """Clean template instance."""
43 clamp.change_instance_status("PASSIVE", "PMSH_Instance1", "1.2.3")
44 wait(lambda: clamp.verify_instance_status("PASSIVE"), sleep_seconds=5, timeout_seconds=60,
45 waiting_for="Clamp instance switches to PASSIVE")
46 clamp.change_instance_status("UNINITIALISED", "PMSH_Instance1", "1.2.3")
47 wait(lambda: clamp.verify_instance_status("UNINITIALISED"), sleep_seconds=5, timeout_seconds=60,
48 waiting_for="Clamp instance switches to UNINITIALISED")
50 logger.info("Delete Instance")
51 clamp.delete_template_instance("PMSH_Instance1", "1.2.3")
52 logger.info("Decommission tosca")
53 clamp.decommission_template("ToscaServiceTemplateSimple", "1.0.0")
56 def create_instance(cls, tosca_template) -> bool:
57 """Create template instance."""
58 response = clamp.upload_commission(tosca_template)
59 if response["errorDetails"] is not None:
62 logger.info("Create Instance")
63 response = clamp.create_instance(tosca_template)
64 if response["errorDetails"] is not None:
67 logger.info("Change Instance Status to PASSIVE")
68 clamp.change_instance_status("PASSIVE", "PMSH_Instance1", "1.2.3")
69 wait(lambda: clamp.verify_instance_status("PASSIVE"), sleep_seconds=5, timeout_seconds=60,
70 waiting_for="Clamp instance switches to PASSIVE")
72 logger.info("Change Instance Status to RUNNING")
73 clamp.change_instance_status("RUNNING", "PMSH_Instance1", "1.2.3")
74 wait(lambda: clamp.verify_instance_status("RUNNING"), sleep_seconds=5, timeout_seconds=60,
75 waiting_for="Clamp instance switches to RUNNING")