summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Wong <stephen.kf.wong@gmail.com>2018-04-19 23:47:05 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-04-19 23:47:05 +0000
commitaf5f78f5221c5b55cff1c45fa4f5a879a772b796 (patch)
tree90e5725456b7a42db13b176fec5f72a548764273
parenteec41c3e79d3cfe8611d705e80af8c2b60641683 (diff)
parent2ecbe8435b9f158633243b39503a9a418bec8b96 (diff)
Merge "Cover validation of elasticsearch cluster"
-rw-r--r--.gitignore1
-rw-r--r--clover/logging/conftest.py15
-rw-r--r--clover/logging/es_test.py30
-rw-r--r--clover/logging/validate.py3
4 files changed, 49 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 988165b..e2075ec 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,3 +35,4 @@ cover/
.tox/
# work env
work/
+.pytest_cache
diff --git a/clover/logging/conftest.py b/clover/logging/conftest.py
new file mode 100644
index 0000000..d464fab
--- /dev/null
+++ b/clover/logging/conftest.py
@@ -0,0 +1,15 @@
+# Copyright (c) Authors of Clover
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+from elasticsearch import Elasticsearch
+import pytest
+
+ES_HOST="localhost:9200"
+
+@pytest.fixture
+def es():
+ return Elasticsearch([ES_HOST])
diff --git a/clover/logging/es_test.py b/clover/logging/es_test.py
new file mode 100644
index 0000000..bd0e359
--- /dev/null
+++ b/clover/logging/es_test.py
@@ -0,0 +1,30 @@
+# Copyright (c) Authors of Clover
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+INDEX_PATTERN='logstash-*'
+TAG='newlog.logentry.istio-system'
+
+def test_health(es):
+ assert es.cat.health(h='status') != 'red\n'
+
+def test_indices(es):
+ assert len(es.cat.indices(INDEX_PATTERN)) > 0
+
+def test_logentry(es):
+ assert es.count(
+ index=INDEX_PATTERN,
+ body={"query":{"match":{"tag":TAG}}})['count'] > 0
+
+def test_lb(es):
+ """requests in and out load balance should match"""
+ from_lb = es.count(
+ index=INDEX_PATTERN,
+ body={"query":{"match":{"source": "http-lb"}}})
+ to_lb = es.count(
+ index=INDEX_PATTERN,
+ body={"query":{"match":{"destination": "http-lb"}}})
+ assert from_lb['count'] == to_lb['count']
diff --git a/clover/logging/validate.py b/clover/logging/validate.py
index 821f912..aca0394 100644
--- a/clover/logging/validate.py
+++ b/clover/logging/validate.py
@@ -9,6 +9,8 @@ from kubernetes import client, config
from kubernetes.stream import stream
import sh
import re
+import os
+import pytest
FLUENTD_NAMESPACE = 'logging'
FLUENTD_PATTERN = 'fluentd-.*'
@@ -54,3 +56,4 @@ def main():
if __name__ == '__main__':
main()
+ pytest.main([os.path.dirname(os.path.realpath(__file__))])