aboutsummaryrefslogtreecommitdiffstats
path: root/calipso
diff options
context:
space:
mode:
authoryayogev <yaronyogev@gmail.com>2017-08-23 19:04:23 +0300
committeryayogev <yaronyogev@gmail.com>2017-08-23 19:04:23 +0300
commit15d1868e9f8fea37a3b023c9f0504ac3dce4292e (patch)
treef348a76f8663790c5ae39c42e45a6e3f2896e4d4 /calipso
parentec6fe945f521d2b1fc8e9a54cb889978239ccbb8 (diff)
move smoke_test.py to calipso/tests/functest/
Change-Id: I60a901035514ba5f40beed64c8a6b83c21fbe6d1 Signed-off-by: yayogev <yaronyogev@gmail.com>
Diffstat (limited to 'calipso')
-rw-r--r--calipso/tests/functest/smoke_test.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/calipso/tests/functest/smoke_test.py b/calipso/tests/functest/smoke_test.py
new file mode 100644
index 0000000..373a7c3
--- /dev/null
+++ b/calipso/tests/functest/smoke_test.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python3
+###############################################################################
+# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
+# and others #
+# #
+# 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 #
+###############################################################################
+
+# Check that Docker images are up and running
+
+import argparse
+from subprocess import check_output
+import sys
+
+from utils.binary_converter import BinaryConverter
+
+IMAGES_TO_SEARCH = ["ui", "sensu", "scan", "api", "ldap", "listen", "mongo"]
+
+
+class DockerImageCheck:
+ STATUS_HEADER = "STATUS"
+ PORTS_HEADER = "PORTS"
+ HEADERS = [
+ "CONTAINER ID",
+ "IMAGE",
+ "COMMAND",
+ "CREATED",
+ "STATUS",
+ "PORTS",
+ "NAMES"
+ ]
+
+ def __init__(self):
+ args = self.get_args()
+ self.docker_ps = ""
+ if args.inputfile:
+ try:
+ with open(args.inputfile, 'r') as input_file:
+ dummy_input = input_file.read()
+ self.docker_ps = dummy_input.splitlines()
+ except FileNotFoundError:
+ raise FileNotFoundError("failed to open input file: {}"
+ .format(args.inputfile))
+ exit(1)
+ else:
+ cmd = "sudo docker ps"
+ output = check_output(cmd, shell=True)
+ converter = BinaryConverter()
+ output = converter.binary2str(output)
+ self.docker_ps = output.splitlines()
+ headers_line = self.docker_ps[0]
+ self.header_location = {}
+ for h in self.HEADERS:
+ self.header_location[h] = headers_line.index(h)
+
+ @staticmethod
+ def get_args():
+ # try to read scan plan from command line parameters
+ parser = argparse.ArgumentParser()
+ parser.add_argument('-i', '--inputfile', nargs='?', type=str,
+ default='',
+ help="read input from the specifed file \n" +
+ "(default: from stdin)")
+ return parser.parse_args()
+
+ def verify_image_is_up(self, image_name) -> bool:
+ matches = [line for line in self.docker_ps if line.endswith(image_name)]
+ if not matches:
+ print("missing docker image: {}".format(image_name))
+ return False
+ line = matches[0]
+ status = line[self.header_location[self.STATUS_HEADER]-1:]
+ status = status.split()[0] if ' ' in status else status
+ status = status.lower()
+ if status == "up":
+ return True
+ print("image {} is not up".format(image_name))
+ return False
+
+if __name__ == '__main__':
+ image_checker = DockerImageCheck()
+ ret = True
+ for image in ["calipso-{}".format(i) for i in IMAGES_TO_SEARCH]:
+ if not image_checker.verify_image_is_up(image):
+ ret = False
+ sys.exit(0 if ret else 1)