From c449f00d947ce173c69d0fe9cc6872e74c00a3e5 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Fri, 15 Jul 2016 10:03:21 -0600 Subject: [PATCH] Generalize need_restart() So that we can also use it to tell the workers to stop Signed-off-by: Zack Cerza --- teuthology/test/test_worker.py | 6 +++--- teuthology/worker.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/teuthology/test/test_worker.py b/teuthology/test/test_worker.py index 3fcf1e57cc..575dfe3164 100644 --- a/teuthology/test/test_worker.py +++ b/teuthology/test/test_worker.py @@ -21,7 +21,7 @@ class TestWorker(object): @patch("os.path.exists") def test_restart_file_path_doesnt_exist(self, m_exists): m_exists.return_value = False - result = worker.need_restart() + result = worker.sentinel(worker.restart_file_path) assert not result @patch("os.path.getmtime") @@ -30,7 +30,7 @@ class TestWorker(object): def test_needs_restart(self, m_datetime, m_exists, m_getmtime): m_exists.return_value = True m_datetime.utcfromtimestamp.return_value = datetime.utcnow() + timedelta(days=1) - result = worker.need_restart() + result = worker.sentinel(worker.restart_file_path) assert result @patch("os.path.getmtime") @@ -39,7 +39,7 @@ class TestWorker(object): def test_does_not_need_restart(self, m_datetime, m_exists, getmtime): m_exists.return_value = True m_datetime.utcfromtimestamp.return_value = datetime.utcnow() - timedelta(days=1) - result = worker.need_restart() + result = worker.sentinel(worker.restart_file_path) assert not result @patch("os.symlink") diff --git a/teuthology/worker.py b/teuthology/worker.py index 6a1e16fd5a..e314e79689 100644 --- a/teuthology/worker.py +++ b/teuthology/worker.py @@ -23,10 +23,10 @@ start_time = datetime.utcnow() restart_file_path = '/tmp/teuthology-restart-workers' -def need_restart(): +def sentinel(path): if not os.path.exists(restart_file_path): return False - file_mtime = datetime.utcfromtimestamp(os.path.getmtime(restart_file_path)) + file_mtime = datetime.utcfromtimestamp(os.path.getmtime(path)) if file_mtime > start_time: return True else: @@ -92,7 +92,7 @@ def main(ctx): result_proc.returncode) result_proc = None - if need_restart(): + if sentinel(restart_file_path): restart() job = connection.reserve(timeout=60) -- 2.39.5