blob: 2d58cc9d3b1d9fa0c19bf6d0940437f36314fac1 [file] [log] [blame]
Bartek Grzybowskifbbdbec2019-09-25 16:37:05 +02001#!/usr/bin/env python
Brian Freeman81f6e9e2018-11-11 22:36:20 -05002
Michal Ptacek995fd6e2019-08-20 11:37:43 +00003import argparse
Michal Ptacek995fd6e2019-08-20 11:37:43 +00004import json
Bartek Grzybowski92b3cd12019-10-07 14:25:30 +02005from subprocess import Popen,PIPE,STDOUT,check_output,CalledProcessError
Michal Ptacek995fd6e2019-08-20 11:37:43 +00006import sys
Brian Freeman81f6e9e2018-11-11 22:36:20 -05007
Michal Ptacek995fd6e2019-08-20 11:37:43 +00008def parse_args():
9 """
10 Parse command line arguments
11 :return: arguments
12 """
Bartek Grzybowski4baa51c2019-09-10 13:50:15 +020013 parser = argparse.ArgumentParser(description='Processing arguments for vCPE healthcheck',formatter_class=argparse.ArgumentDefaultsHelpFormatter)
Michal Ptacek995fd6e2019-08-20 11:37:43 +000014 parser.add_argument('--namespace', default="onap",
15 metavar=('<namespace_name>'),
16 help='Namespace name for existing ONAP deployment')
17 parser.add_argument('--environment', default="dev",
18 metavar=('<environment_name>'),
19 help='Environment name for existing ONAP deployment visible in <environment_name>-sdnc-sdnc-0 pod name')
20 args = parser.parse_args()
21 return args
Brian Freeman81f6e9e2018-11-11 22:36:20 -050022
Michal Ptacek995fd6e2019-08-20 11:37:43 +000023
24args = parse_args()
25
26namespace = args.namespace
27environment = args.environment
Brian Freeman81f6e9e2018-11-11 22:36:20 -050028
Bartek Grzybowski0ca3d402019-09-13 12:50:59 +020029# config section
Bartek Grzybowski92b3cd12019-10-07 14:25:30 +020030kube_cmd = 'kubectl -n {0} exec {1}-sdnc-sdnc-0 -c sdnc -- bash -c '.format(namespace, environment)
31curl_check_cmd = 'apk info -e curl'
32curl_install_cmd = 'sudo apk add curl'
Bartek Grzybowski0ca3d402019-09-13 12:50:59 +020033curl_cmd = 'curl -s -u admin:admin -X GET http://{0}:8183/restconf/config/ietf-interfaces:interfaces'
34endpoints = {
35 "vGMUX": '10.0.101.21',
36 "vBRG": '10.3.0.2'
37}
38# end of config section
Brian Freeman81f6e9e2018-11-11 22:36:20 -050039
Bartek Grzybowski92b3cd12019-10-07 14:25:30 +020040# Install curl command in SDNC container
41try:
42 check_output(kube_cmd.split() + [curl_check_cmd], stderr=STDOUT)
43except CalledProcessError:
44 try:
45 check_output(kube_cmd.split() + [curl_install_cmd], stderr=STDOUT)
46 except CalledProcessError:
47 print('Curl package installation failed, exiting.')
48 sys.exit(1)
49 else:
50 print("Curl package was installed in SDNC container")
51
Bartek Grzybowski0ca3d402019-09-13 12:50:59 +020052for ename,eip in endpoints.items():
53 print('Checking {0} REST API from SDNC'.format(ename))
54 p = Popen(kube_cmd.split() + [curl_cmd.format(eip)], stdout=PIPE, stderr=PIPE)
55 (output, error) = p.communicate()
56 if p.returncode:
57 print(error)
58 sys.exit(p.returncode)
59 else:
60 print(json.dumps(json.loads(output), indent=4))
61 print('\n')
Brian Freeman81f6e9e2018-11-11 22:36:20 -050062
63print('Checking SDNC DB for vBRG MAC address')
Bartek Grzybowski0ca3d402019-09-13 12:50:59 +020064kube_db_cmd = 'kubectl -n {0} exec {1}-mariadb-galera-mariadb-galera-0 -- bash -c'
65db_cmd = "mysql -uroot -psecretpassword sdnctl -e 'select * from DHCP_MAP'"
66p = Popen(kube_db_cmd.format(namespace, environment).split() + [db_cmd], stdout=PIPE)
Yang Xuaa8c5842019-01-02 12:05:40 -050067(output, error) = p.communicate()
68print(output)