2e78b5ba488e8d6fe459f05e9f1f7d02bb7257d2
[it/dep.git] / smo-install / test / pythonsdk / src / orantests / conftest.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 """Module called by pytest."""
25 import logging
26 import logging.config
27 import os
28 from oransdk.dmaap.dmaap import OranDmaap
29 from oransdk.sdnc.sdnc import OranSdnc
30 from onapsdk.configuration import settings
31 from waiting import wait
32 from smo.smo import Smo
33 from smo.network_simulators import NetworkSimulators
34
35 # Set working dir as python script location
36 abspath = os.path.abspath(__file__)
37 dname = os.path.dirname(abspath)
38 os.chdir(dname)
39
40 logging.config.dictConfig(settings.LOG_CONFIG)
41 logger = logging.getLogger("Test Session setup")
42
43 network_sims = NetworkSimulators("./resources")
44 smo = Smo()
45 dmaap = OranDmaap()
46 sdnc = OranSdnc()
47
48 TOPIC_PNFREG = '{"topicName": "unauthenticated.VES_PNFREG_OUTPUT"}'
49
50 TOPIC_FAULT = '{"topicName": "unauthenticated.SEC_FAULT_OUTPUT"}'
51
52 #TOPIC_PNFREG = {
53 #    "owner": "",
54 #    "readerAcl": {
55 #        "enabled": "true",
56 #        "users": []
57 #    },
58 #    "name": "unauthenticated.VES_PNFREG_OUTPUT",
59 #    "description": "",
60 #    "writerAcl": {
61 #        "enabled": "true",
62 #        "users": []
63 #    }
64 #}
65
66 #TOPIC_FAULT = {
67 #    "owner": "",
68 #    "readerAcl": {
69 #        "enabled": "true",
70 #        "users": []
71 #    },
72 #    "name": "unauthenticated.SEC_FAULT_OUTPUT",
73 #    "description": "",
74 #    "writerAcl": {
75 #        "enabled": "true",
76 #        "users": []
77 #    }
78 #}
79
80 ###### Entry points of PYTEST Session
81 def pytest_sessionstart():
82     """Pytest calls it when starting a test session."""
83     logger.info("Check and wait for SMO to be running")
84     smo.wait_for_smo_to_be_running()
85     logger.info("Check and for for SDNC to be running")
86     wait(lambda: OranSdnc.get_events(settings.SDNC_BASICAUTH, "test").status_code == 200, sleep_seconds=10, timeout_seconds=300, waiting_for="SDNC to be ready")
87
88     dmaap.create_topic(TOPIC_PNFREG)
89     dmaap.create_topic(TOPIC_FAULT)
90     ### Due to an Onap Ves/dmaap behavior !!! DU sims must send messages
91     ### twice so we need to create/delete the sims
92 #    network_sims.start_network_simulators()
93 #    network_sims.wait_for_network_simulators_to_be_running()
94 #    time.sleep(20)
95     ## Now kill the simulators and restart them for the test session
96     network_sims.stop_network_simulators()
97     ###### END of FIRST start, now we can start the sims for the real tests.