5181445c3be062af338e82b09a27d2b8ec68ac3f
[it/dep.git] / smo-install / test / pythonsdk / src / orantests / smo / cl_usecase.py
1 #!/usr/bin/env python3
2 ###
3 # ============LICENSE_START=======================================================
4 # ORAN SMO PACKAGE - PYTHONSDK TESTS
5 # ================================================================================
6 # Copyright (C) 2021-2022 AT&T Intellectual Property. All rights
7 #                             reserved.
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
12 #
13 # http://www.apache.org/licenses/LICENSE-2.0
14 #
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 # ===================================================================
22 #
23 ###
24
25 """Cl usecase utils module."""
26
27 import logging.config
28 from waiting import wait
29 from onapsdk.configuration import settings
30 from oransdk.policy.clamp import ClampToscaTemplate
31
32 logging.config.dictConfig(settings.LOG_CONFIG)
33 logger = logging.getLogger("Cl usecae utils")
34 clamp = ClampToscaTemplate(settings.CLAMP_BASICAUTH)
35
36
37 class ClCommissioningUtils():
38     """Can be used to have cl usecase utils methods."""
39
40     @classmethod
41     def clean_instance(cls, usecase_name):
42         """Clean template instance."""
43         clamp.change_instance_status("UNINITIALISED", usecase_name, "1.2.3")
44         wait(lambda: clamp.verify_instance_status("UNINITIALISED"), sleep_seconds=5, timeout_seconds=60,
45              waiting_for="Clamp instance switches to UNINITIALISED")
46
47         logger.info("Delete Instance")
48         clamp.delete_template_instance(usecase_name, "1.2.3")
49         logger.info("Decommission tosca")
50         clamp.decommission_template("ToscaServiceTemplateSimple", "1.0.0")
51
52     @classmethod
53     def create_instance(cls, usecase_name, commissioning_payload, instance_payload) -> bool:
54         """Create template instance."""
55         response = clamp.upload_commission(commissioning_payload)
56         if response["errorDetails"] is not None:
57             return False
58
59         logger.info("Create Instance")
60         response = clamp.create_instance(instance_payload)
61         if response["errorDetails"] is not None:
62             return False
63
64         logger.info("Change Instance Status to PASSIVE")
65         clamp.change_instance_status("PASSIVE", usecase_name, "1.2.3")
66         wait(lambda: clamp.verify_instance_status("PASSIVE"), sleep_seconds=5, timeout_seconds=60,
67              waiting_for="Clamp instance switches to PASSIVE")
68
69         return True