Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 1 | #! /usr/bin/python |
| 2 | |
Michal Ptacek | 995fd6e | 2019-08-20 11:37:43 +0000 | [diff] [blame^] | 3 | import argparse |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 4 | import commands |
Michal Ptacek | 995fd6e | 2019-08-20 11:37:43 +0000 | [diff] [blame^] | 5 | import json |
| 6 | import logging |
Yang Xu | aa8c584 | 2019-01-02 12:05:40 -0500 | [diff] [blame] | 7 | import subprocess |
Michal Ptacek | 995fd6e | 2019-08-20 11:37:43 +0000 | [diff] [blame^] | 8 | import sys |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 9 | |
Michal Ptacek | 995fd6e | 2019-08-20 11:37:43 +0000 | [diff] [blame^] | 10 | def parse_args(): |
| 11 | """ |
| 12 | Parse command line arguments |
| 13 | :return: arguments |
| 14 | """ |
| 15 | parser = argparse.ArgumentParser(description='Processing arguments for vCPE healthcheck') |
| 16 | parser.add_argument('--namespace', default="onap", |
| 17 | metavar=('<namespace_name>'), |
| 18 | help='Namespace name for existing ONAP deployment') |
| 19 | parser.add_argument('--environment', default="dev", |
| 20 | metavar=('<environment_name>'), |
| 21 | help='Environment name for existing ONAP deployment visible in <environment_name>-sdnc-sdnc-0 pod name') |
| 22 | args = parser.parse_args() |
| 23 | return args |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 24 | |
Michal Ptacek | 995fd6e | 2019-08-20 11:37:43 +0000 | [diff] [blame^] | 25 | |
| 26 | args = parse_args() |
| 27 | |
| 28 | namespace = args.namespace |
| 29 | environment = args.environment |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 30 | |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 31 | print('Checking vGMUX REST API from SDNC') |
Yang Xu | aa8c584 | 2019-01-02 12:05:40 -0500 | [diff] [blame] | 32 | cmd = 'curl -s -u admin:admin -X GET http://10.0.101.21:8183/restconf/config/ietf-interfaces:interfaces' |
Michal Ptacek | 995fd6e | 2019-08-20 11:37:43 +0000 | [diff] [blame^] | 33 | ret = commands.getstatusoutput("kubectl -n {0} exec {1}-sdnc-sdnc-0 -- bash -c '{2}'".format(args.namespace, args.environment, cmd)) |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 34 | sz = ret[-1].split('\n')[-1] |
Yang Xu | aa8c584 | 2019-01-02 12:05:40 -0500 | [diff] [blame] | 35 | print(json.dumps(json.loads(sz), indent=4)) |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 36 | |
Yang Xu | aa8c584 | 2019-01-02 12:05:40 -0500 | [diff] [blame] | 37 | print('\n') |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 38 | print('Checking vBRG REST API from SDNC') |
Yang Xu | aa8c584 | 2019-01-02 12:05:40 -0500 | [diff] [blame] | 39 | cmd = 'curl -s -u admin:admin -X GET http://10.3.0.2:8183/restconf/config/ietf-interfaces:interfaces' |
Michal Ptacek | 995fd6e | 2019-08-20 11:37:43 +0000 | [diff] [blame^] | 40 | ret = commands.getstatusoutput("kubectl -n {0} exec {1}-sdnc-sdnc-0 -- bash -c '{2}'".format(args.namespace, args.environment, cmd)) |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 41 | sz = ret[-1].split('\n')[-1] |
Yang Xu | aa8c584 | 2019-01-02 12:05:40 -0500 | [diff] [blame] | 42 | print(json.dumps(json.loads(sz), indent=4)) |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 43 | |
Yang Xu | aa8c584 | 2019-01-02 12:05:40 -0500 | [diff] [blame] | 44 | print('\n') |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 45 | print('Checking SDNC DB for vBRG MAC address') |
Michal Ptacek | 995fd6e | 2019-08-20 11:37:43 +0000 | [diff] [blame^] | 46 | cmd = "kubectl -n {0} exec {1}-mariadb-galera-mariadb-galera-0 -- mysql -uroot -psecretpassword sdnctl -e 'select * from DHCP_MAP'".format(args.namespace, args.environment) |
Yang Xu | aa8c584 | 2019-01-02 12:05:40 -0500 | [diff] [blame] | 47 | p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) |
| 48 | (output, error) = p.communicate() |
| 49 | print(output) |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 50 | |