Browse Source

Merge pull request #1357 from marko-asplund/feature/issue-1103

Toolset: Verify database connectivity before running tests
Hamilton Turner 10 years ago
parent
commit
7d429bf86c
2 changed files with 41 additions and 0 deletions
  1. 10 0
      toolset/benchmark/benchmarker.py
  2. 31 0
      toolset/benchmark/utils.py

+ 10 - 0
toolset/benchmark/benchmarker.py

@@ -6,6 +6,7 @@ from benchmark.test_types import *
 from utils import header
 from utils import gather_tests
 from utils import gather_frameworks
+from utils import verify_database_connections
 
 import os
 import json
@@ -539,6 +540,15 @@ class Benchmarker:
           """)
           time.sleep(10)
 
+          st = verify_database_connections([
+            ("mysql", self.database_host, 3306),
+            ("mongodb", self.database_host, 27017),
+            ("redis", self.database_host, 6379),
+            ("postgresql", self.database_host, 5432),
+            ("cassandra", self.database_host, 9160)
+          ])
+          print "database connection test results:\n" + "\n".join(st[1])
+
         if self.__is_port_bound(test.port):
           # This can happen sometimes - let's try again
           self.__stop_test(out, err)

+ 31 - 0
toolset/benchmark/utils.py

@@ -2,6 +2,7 @@ import ConfigParser
 import os
 import glob
 import json
+import socket
 
 from ast import literal_eval
 
@@ -138,3 +139,33 @@ def header(message, top='-', bottom='-'):
       else:
         result += "\n%s" % bottomheader
     return result + '\n'
+
+def check_services(services):
+
+  def check_service(address, port):
+    try:
+      s = socket.socket()
+      s.settimeout(20)
+      s.connect((address, port))
+      return (True, "")
+    except Exception as ex:
+      return (False, ex)
+    finally:
+      s.close
+
+  res = []
+  for s in services:
+    r = check_service(s[1], s[2])
+    res.append((s[0], r[0], str(r[1])))
+  return res
+
+def verify_database_connections(services):
+  allGo = True
+  messages = []
+  for r in check_services(services):
+    if r[1]:
+      messages.append(r[0] + ": is GO!")
+    else:
+      messages.append(r[0] + ": is _NO_ GO!: ERROR: " + r[2])
+      allGo = False
+  return (allGo, messages)