blob: ae33e25b28ceaf283d01bbb8c82ae41d746dda00 [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
5import logging
Bartek Grzybowski92b3cd12019-10-07 14:25:30 +02006from subprocess import Popen,PIPE,STDOUT,check_output,CalledProcessError
Michal Ptacek995fd6e2019-08-20 11:37:43 +00007import sys
Brian Freeman81f6e9e2018-11-11 22:36:20 -05008
Michal Ptacek995fd6e2019-08-20 11:37:43 +00009def parse_args():
10 """
11 Parse command line arguments
12 :return: arguments
13 """
Bartek Grzybowski4baa51c2019-09-10 13:50:15 +020014 parser = argparse.ArgumentParser(description='Processing arguments for vCPE healthcheck',formatter_class=argparse.ArgumentDefaultsHelpFormatter)
Michal Ptacek995fd6e2019-08-20 11:37:43 +000015 parser.add_argument('--namespace', default="onap",
16 metavar=('<namespace_name>'),
17 help='Namespace name for existing ONAP deployment')
18 parser.add_argument('--environment', default="dev",
19 metavar=('<environment_name>'),
20 help='Environment name for existing ONAP deployment visible in <environment_name>-sdnc-sdnc-0 pod name')
21 args = parser.parse_args()
22 return args
Brian Freeman81f6e9e2018-11-11 22:36:20 -050023
Michal Ptacek995fd6e2019-08-20 11:37:43 +000024
25args = parse_args()
26
27namespace = args.namespace
28environment = args.environment
Brian Freeman81f6e9e2018-11-11 22:36:20 -050029
Bartek Grzybowski0ca3d402019-09-13 12:50:59 +020030# config section
Bartek Grzybowski92b3cd12019-10-07 14:25:30 +020031kube_cmd = 'kubectl -n {0} exec {1}-sdnc-sdnc-0 -c sdnc -- bash -c '.format(namespace, environment)
32curl_check_cmd = 'apk info -e curl'
33curl_install_cmd = 'sudo apk add curl'
Bartek Grzybowski0ca3d402019-09-13 12:50:59 +020034curl_cmd = 'curl -s -u admin:admin -X GET http://{0}:8183/restconf/config/ietf-interfaces:interfaces'
35endpoints = {
36 "vGMUX": '10.0.101.21',
37 "vBRG": '10.3.0.2'
38}
39# end of config section
Brian Freeman81f6e9e2018-11-11 22:36:20 -050040
Bartek Grzybowski92b3cd12019-10-07 14:25:30 +020041# Install curl command in SDNC container
42try:
43 check_output(kube_cmd.split() + [curl_check_cmd], stderr=STDOUT)
44except CalledProcessError:
45 try:
46 check_output(kube_cmd.split() + [curl_install_cmd], stderr=STDOUT)
47 except CalledProcessError:
48 print('Curl package installation failed, exiting.')
49 sys.exit(1)
50 else:
51 print("Curl package was installed in SDNC container")
52
Bartek Grzybowski0ca3d402019-09-13 12:50:59 +020053for ename,eip in endpoints.items():
54 print('Checking {0} REST API from SDNC'.format(ename))
55 p = Popen(kube_cmd.split() + [curl_cmd.format(eip)], stdout=PIPE, stderr=PIPE)
56 (output, error) = p.communicate()
57 if p.returncode:
58 print(error)
59 sys.exit(p.returncode)
60 else:
61 print(json.dumps(json.loads(output), indent=4))
62 print('\n')
Brian Freeman81f6e9e2018-11-11 22:36:20 -050063
64print('Checking SDNC DB for vBRG MAC address')
Bartek Grzybowski0ca3d402019-09-13 12:50:59 +020065kube_db_cmd = 'kubectl -n {0} exec {1}-mariadb-galera-mariadb-galera-0 -- bash -c'
66db_cmd = "mysql -uroot -psecretpassword sdnctl -e 'select * from DHCP_MAP'"
67p = Popen(kube_db_cmd.format(namespace, environment).split() + [db_cmd], stdout=PIPE)
Yang Xuaa8c5842019-01-02 12:05:40 -050068(output, error) = p.communicate()
69print(output)