blob: 67a1981d260f3ed79e470779ec42946017303449 [file] [log] [blame]
Brian Freeman81f6e9e2018-11-11 22:36:20 -05001#! /usr/bin/python
2
Michal Ptacek995fd6e2019-08-20 11:37:43 +00003import argparse
Michal Ptacek995fd6e2019-08-20 11:37:43 +00004import json
5import logging
Bartek Grzybowski0ca3d402019-09-13 12:50:59 +02006from subprocess import Popen,PIPE
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
31kube_cmd = 'kubectl -n {0} exec {1}-sdnc-sdnc-0 -- bash -c '.format(namespace, environment)
32curl_cmd = 'curl -s -u admin:admin -X GET http://{0}:8183/restconf/config/ietf-interfaces:interfaces'
33endpoints = {
34 "vGMUX": '10.0.101.21',
35 "vBRG": '10.3.0.2'
36}
37# end of config section
Brian Freeman81f6e9e2018-11-11 22:36:20 -050038
Bartek Grzybowski0ca3d402019-09-13 12:50:59 +020039for ename,eip in endpoints.items():
40 print('Checking {0} REST API from SDNC'.format(ename))
41 p = Popen(kube_cmd.split() + [curl_cmd.format(eip)], stdout=PIPE, stderr=PIPE)
42 (output, error) = p.communicate()
43 if p.returncode:
44 print(error)
45 sys.exit(p.returncode)
46 else:
47 print(json.dumps(json.loads(output), indent=4))
48 print('\n')
Brian Freeman81f6e9e2018-11-11 22:36:20 -050049
50print('Checking SDNC DB for vBRG MAC address')
Bartek Grzybowski0ca3d402019-09-13 12:50:59 +020051kube_db_cmd = 'kubectl -n {0} exec {1}-mariadb-galera-mariadb-galera-0 -- bash -c'
52db_cmd = "mysql -uroot -psecretpassword sdnctl -e 'select * from DHCP_MAP'"
53p = Popen(kube_db_cmd.format(namespace, environment).split() + [db_cmd], stdout=PIPE)
Yang Xuaa8c5842019-01-02 12:05:40 -050054(output, error) = p.communicate()
55print(output)