Add odu tests and enable k8s oru test
[it/dep.git] / smo-install / test / pythonsdk / src / orantests / oran_tests / smo / onap.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 """Onap k8s module."""
26 import logging
27
28 import logging.config
29
30 from subprocess import check_output, run
31 from onapsdk.configuration import settings
32
33 logging.config.dictConfig(settings.LOG_CONFIG)
34 logger = logging.getLogger("Onap k8s")
35
36 class Onap():
37     """Can be used to check onap platform in K8S."""
38
39     @classmethod
40     def is_onap_up(cls) -> bool:
41         """Verify if ONAP platform is up or not."""
42         cmd = "kubectl get pods --field-selector 'status.phase=Failed' -n onap -o name | xargs kubectl delete -n onap"
43         run(cmd, shell=True, check=False)
44         cmd = "kubectl get pods --field-selector status.phase!=Running -n onap | wc -l"
45         result = check_output(cmd, shell=True).decode('utf-8')
46         logger.info("Number of Onap pods not in Running state (expected <= %s): %s", settings.ONAP_PODS_WHEN_READY, result)
47         if int(result) <= settings.ONAP_PODS_WHEN_READY:
48             logger.info("ONAP is Up")
49             return True
50         logger.info("ONAP is Down")
51         return False