Bartek Grzybowski | fbbdbec | 2019-09-25 16:37:05 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 2 | |
Michal Ptacek | 995fd6e | 2019-08-20 11:37:43 +0000 | [diff] [blame] | 3 | import argparse |
Michal Ptacek | 995fd6e | 2019-08-20 11:37:43 +0000 | [diff] [blame] | 4 | import json |
Bartek Grzybowski | 92b3cd1 | 2019-10-07 14:25:30 +0200 | [diff] [blame] | 5 | from subprocess import Popen,PIPE,STDOUT,check_output,CalledProcessError |
Michal Ptacek | 995fd6e | 2019-08-20 11:37:43 +0000 | [diff] [blame] | 6 | import sys |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 7 | |
Michal Ptacek | 995fd6e | 2019-08-20 11:37:43 +0000 | [diff] [blame] | 8 | def parse_args(): |
| 9 | """ |
| 10 | Parse command line arguments |
| 11 | :return: arguments |
| 12 | """ |
Bartek Grzybowski | 4baa51c | 2019-09-10 13:50:15 +0200 | [diff] [blame] | 13 | parser = argparse.ArgumentParser(description='Processing arguments for vCPE healthcheck',formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
Michal Ptacek | 995fd6e | 2019-08-20 11:37:43 +0000 | [diff] [blame] | 14 | 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 Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 22 | |
Michal Ptacek | 995fd6e | 2019-08-20 11:37:43 +0000 | [diff] [blame] | 23 | |
| 24 | args = parse_args() |
| 25 | |
| 26 | namespace = args.namespace |
| 27 | environment = args.environment |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 28 | |
Bartek Grzybowski | 0ca3d40 | 2019-09-13 12:50:59 +0200 | [diff] [blame] | 29 | # config section |
Bartek Grzybowski | 92b3cd1 | 2019-10-07 14:25:30 +0200 | [diff] [blame] | 30 | kube_cmd = 'kubectl -n {0} exec {1}-sdnc-sdnc-0 -c sdnc -- bash -c '.format(namespace, environment) |
| 31 | curl_check_cmd = 'apk info -e curl' |
| 32 | curl_install_cmd = 'sudo apk add curl' |
Bartek Grzybowski | 0ca3d40 | 2019-09-13 12:50:59 +0200 | [diff] [blame] | 33 | curl_cmd = 'curl -s -u admin:admin -X GET http://{0}:8183/restconf/config/ietf-interfaces:interfaces' |
| 34 | endpoints = { |
| 35 | "vGMUX": '10.0.101.21', |
| 36 | "vBRG": '10.3.0.2' |
| 37 | } |
| 38 | # end of config section |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 39 | |
Bartek Grzybowski | 92b3cd1 | 2019-10-07 14:25:30 +0200 | [diff] [blame] | 40 | # Install curl command in SDNC container |
| 41 | try: |
| 42 | check_output(kube_cmd.split() + [curl_check_cmd], stderr=STDOUT) |
| 43 | except 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 Grzybowski | 0ca3d40 | 2019-09-13 12:50:59 +0200 | [diff] [blame] | 52 | for 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 Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 62 | |
| 63 | print('Checking SDNC DB for vBRG MAC address') |
Bartek Grzybowski | 0ca3d40 | 2019-09-13 12:50:59 +0200 | [diff] [blame] | 64 | kube_db_cmd = 'kubectl -n {0} exec {1}-mariadb-galera-mariadb-galera-0 -- bash -c' |
| 65 | db_cmd = "mysql -uroot -psecretpassword sdnctl -e 'select * from DHCP_MAP'" |
| 66 | p = Popen(kube_db_cmd.format(namespace, environment).split() + [db_cmd], stdout=PIPE) |
Yang Xu | aa8c584 | 2019-01-02 12:05:40 -0500 | [diff] [blame] | 67 | (output, error) = p.communicate() |
| 68 | print(output) |