Commit a671c94e authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

scalability: wait for site-availability before getting metrics.

parent 83f1427c
......@@ -29,6 +29,11 @@ import threading
import time
import requests
# max time to wait for site availability before getting metrics
CHECK_SITE_AVAILABILITY_TIMEOUT = 60 * 30
# interval to check site availability
CHECK_SITE_AVAILABILITY_INTERVAL = 60
class TestThread(threading.Thread):
def __init__(self, process_manager, command, log, env={}):
......@@ -43,9 +48,10 @@ class TestThread(threading.Thread):
class TestMetricThread(threading.Thread):
def __init__(self, metric_url, log, stop_event, interval=60):
def __init__(self, metric_url, site_availability_url, log, stop_event, interval=60):
threading.Thread.__init__(self)
self.metric_url = metric_url
self.site_availability_url = site_availability_url
self.log = log
self.interval = interval
self.stop_event = stop_event
......@@ -55,6 +61,15 @@ class TestMetricThread(threading.Thread):
def run(self):
while(not self.stop_event.is_set()):
self.stop_event.wait(-time.time() % self.interval)
start_time = time.time()
while CHECK_SITE_AVAILABILITY_TIMEOUT > time.time() - start_time:
try:
response = requests.get(self.site_availability_url, timeout=60)
if response.status_code == 200 and response.content.strip() == '0':
break
except Exception as e:
self.log('Error checking site availability: %s' % e)
time.sleep(CHECK_SITE_AVAILABILITY_INTERVAL)
try:
response = requests.get(self.metric_url, timeout=60)
if response.status_code == 200:
......
......@@ -139,6 +139,10 @@ class ScalabilityLauncher(object):
metavar='METRIC_URL',
help='Url to connect to instance metric generator')
parser.add_argument('--site-availability-url',
metavar='SITE_AVAILABILITY_URL',
help='Url to check instance availability')
@staticmethod
def _checkParsedArguments(namespace):
return namespace
......@@ -230,10 +234,11 @@ class ScalabilityLauncher(object):
tester_path = self.__argumentNamespace.runner_path
instance_url = self.__argumentNamespace.instance_url
metric_url = self.__argumentNamespace.metric_url
site_availability_url = self.__argumentNamespace.site_availability_url
# To take metrics
metric_thread_stop_event = threading.Event()
metric_thread = TestMetricThread(metric_url, self.log, metric_thread_stop_event, interval=TEST_METRIC_TIME_INTERVAL)
metric_thread = TestMetricThread(metric_url, site_availability_url, self.log, metric_thread_stop_event, interval=TEST_METRIC_TIME_INTERVAL)
metric_thread.start()
bootstrap_password = self.__argumentNamespace.bootstrap_password
......
......@@ -650,7 +650,8 @@ Require valid-user
"--runner-path", runner,
"--repo-location", repo_location,
"--log-path", log_path,
"--metric-url", metric_url
"--metric-url", metric_url,
"--site-availability-url", site_availability_url,
]
logger.info("Running test case...")
test_thread = TestThread(self.testnode.process_manager, command, logger.info, env=self.exec_env)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment