aboutsummaryrefslogtreecommitdiffstats
path: root/test/vcpe
diff options
context:
space:
mode:
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>2019-09-13 12:50:59 +0200
committerDaniel Rose <dr695h@att.com>2019-09-13 14:00:13 +0000
commit0ca3d400f25810df7b1eb811dc529e0d1231a184 (patch)
tree0d66de7bd407ce7f3e4101ac8681b609ab6cac7b /test/vcpe
parentbfeeb24819035523222149d4fffdf9f7de363fc2 (diff)
Refactor healthcheck-k8s.py
Error reporting was improved by returning actual error message from subprocess call to 'kubectl' command. Code readability was improved by defining a dictionary of endpoint names to check and their IPs. Unsecure 'shell=True' property in Popen constructor for kubectl command in SDNC DB was removed and command string itself sanitized. Overall code readability was improved by reusing common commands in a loop. Change-Id: I19f8f71e27196bb55a9be3d58cd0885ceba3af0c Issue-ID: TEST-213 Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
Diffstat (limited to 'test/vcpe')
-rwxr-xr-xtest/vcpe/healthcheck-k8s.py40
1 files changed, 23 insertions, 17 deletions
diff --git a/test/vcpe/healthcheck-k8s.py b/test/vcpe/healthcheck-k8s.py
index 45832418b..67a1981d2 100755
--- a/test/vcpe/healthcheck-k8s.py
+++ b/test/vcpe/healthcheck-k8s.py
@@ -1,10 +1,9 @@
#! /usr/bin/python
import argparse
-import commands
import json
import logging
-import subprocess
+from subprocess import Popen,PIPE
import sys
def parse_args():
@@ -28,22 +27,29 @@ args = parse_args()
namespace = args.namespace
environment = args.environment
-print('Checking vGMUX REST API from SDNC')
-cmd = 'curl -s -u admin:admin -X GET http://10.0.101.21:8183/restconf/config/ietf-interfaces:interfaces'
-ret = commands.getstatusoutput("kubectl -n {0} exec {1}-sdnc-sdnc-0 -- bash -c '{2}'".format(namespace, environment, cmd))
-sz = ret[-1].split('\n')[-1]
-print(json.dumps(json.loads(sz), indent=4))
+# config section
+kube_cmd = 'kubectl -n {0} exec {1}-sdnc-sdnc-0 -- bash -c '.format(namespace, environment)
+curl_cmd = 'curl -s -u admin:admin -X GET http://{0}:8183/restconf/config/ietf-interfaces:interfaces'
+endpoints = {
+ "vGMUX": '10.0.101.21',
+ "vBRG": '10.3.0.2'
+}
+# end of config section
+
+for ename,eip in endpoints.items():
+ print('Checking {0} REST API from SDNC'.format(ename))
+ p = Popen(kube_cmd.split() + [curl_cmd.format(eip)], stdout=PIPE, stderr=PIPE)
+ (output, error) = p.communicate()
+ if p.returncode:
+ print(error)
+ sys.exit(p.returncode)
+ else:
+ print(json.dumps(json.loads(output), indent=4))
+ print('\n')
-print('\n')
-print('Checking vBRG REST API from SDNC')
-cmd = 'curl -s -u admin:admin -X GET http://10.3.0.2:8183/restconf/config/ietf-interfaces:interfaces'
-ret = commands.getstatusoutput("kubectl -n {0} exec {1}-sdnc-sdnc-0 -- bash -c '{2}'".format(namespace, environment, cmd))
-sz = ret[-1].split('\n')[-1]
-print(json.dumps(json.loads(sz), indent=4))
-
-print('\n')
print('Checking SDNC DB for vBRG MAC address')
-cmd = "kubectl -n {0} exec {1}-mariadb-galera-mariadb-galera-0 -- mysql -uroot -psecretpassword sdnctl -e 'select * from DHCP_MAP'".format(namespace, environment)
-p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
+kube_db_cmd = 'kubectl -n {0} exec {1}-mariadb-galera-mariadb-galera-0 -- bash -c'
+db_cmd = "mysql -uroot -psecretpassword sdnctl -e 'select * from DHCP_MAP'"
+p = Popen(kube_db_cmd.format(namespace, environment).split() + [db_cmd], stdout=PIPE)
(output, error) = p.communicate()
print(output)