Add checks for netchecker metrics
Change-Id: Icc3ab64624168d4b39b18f06cda18e8b890eb4ee
Reviewed-on: https://review.gerrithub.io/368050
Reviewed-by: Tatyanka Leontovich <tleontovich@mirantis.com>
Tested-by: Tatyanka Leontovich <tleontovich@mirantis.com>
diff --git a/tcp_tests/helpers/netchecker.py b/tcp_tests/helpers/netchecker.py
index f23a5c8..9c920ec 100644
--- a/tcp_tests/helpers/netchecker.py
+++ b/tcp_tests/helpers/netchecker.py
@@ -331,7 +331,7 @@
@utils.retry(3, requests.exceptions.RequestException)
-def get_status(k8sclient, netchecker_pod_port=NETCHECKER_NODE_PORT,
+def get_connectivity_status(k8sclient, netchecker_pod_port=NETCHECKER_NODE_PORT,
pod_name='netchecker-server', namespace='default'):
netchecker_srv_pod_names = [pod.name for pod in
@@ -352,17 +352,33 @@
return response
-def check_network(k8sclient, namespace='default', works=True):
+@utils.retry(3, requests.exceptions.RequestException)
+def get_netchecker_pod_status(k8s,
+ pod_name='netchecker-server',
+ namespace='default'):
+
+ k8s.wait_pods_phase(
+ pods=[pod for pod in k8s.api.pods.list(namespace=namespace)
+ if pod_name in pod.name], phase='Running', timeout=600)
+
+
+def check_network(k8sclient, netchecker_pod_port,
+ namespace='default', works=True):
if works:
- assert get_status(k8sclient,
- namespace=namespace).status_code in (200, 204)
+ assert get_connectivity_status(
+ k8sclient, namespace=namespace,
+ netchecker_pod_port=netchecker_pod_port).status_code in (200, 204)
else:
- assert get_status(k8sclient, namespace=namespace).status_code == 400
+ assert get_connectivity_status(
+ k8sclient, namespace=namespace,
+ netchecker_pod_port=netchecker_pod_port).status_code == 400
def wait_check_network(k8sclient, namespace='default', works=True, timeout=120,
- interval=5):
- helpers.wait_pass(lambda: check_network(k8sclient, namespace=namespace,
+ interval=5, netchecker_pod_port=NETCHECKER_NODE_PORT):
+ helpers.wait_pass(lambda: check_network(k8sclient,
+ netchecker_pod_port=netchecker_pod_port,
+ namespace=namespace,
works=works),
timeout=timeout, interval=interval)
@@ -518,3 +534,25 @@
cmd_add_policy_hostnet = "echo '{0}' | kubectl create -f -".format(
json.dumps(kubernetes_policy_hostnet))
underlay.sudo_check_call(cmd=cmd_add_policy_hostnet, host=kube_host_ip)
+
+
+@utils.retry(3, requests.exceptions.RequestException)
+def get_metric(k8sclient, netchecker_pod_port,
+ pod_name='netchecker-server', namespace='default'):
+
+ netchecker_srv_pod_names = [pod.name for pod in
+ k8sclient.pods.list(namespace=namespace)
+ if pod_name in pod.name]
+
+ assert len(netchecker_srv_pod_names) > 0, \
+ "No netchecker-server pods found!"
+ netchecker_srv_pod = k8sclient.pods.get(name=netchecker_srv_pod_names[0],
+ namespace=namespace)
+
+ kube_host_ip = netchecker_srv_pod.status.host_ip
+ metrics_url = 'http://{0}:{1}/metrics'.format(
+ kube_host_ip, netchecker_pod_port)
+ response = requests.get(metrics_url, timeout=30)
+ LOG.debug('Metrics: [{0}] {1}'.format(
+ response.status_code, response.text.strip()))
+ return response