]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Generalize need_restart()
authorZack Cerza <zack@redhat.com>
Fri, 15 Jul 2016 16:03:21 +0000 (10:03 -0600)
committerZack Cerza <zack@redhat.com>
Fri, 15 Jul 2016 17:07:02 +0000 (11:07 -0600)
So that we can also use it to tell the workers to stop

Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/test/test_worker.py
teuthology/worker.py

index 3fcf1e57ccf318ec7b3e84dc8a64330604f7b173..575dfe316494e31de7528bd2ed26fea2a3387945 100644 (file)
@@ -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")
index 6a1e16fd5a1c4163d8aa0a883fb80928f598e6f0..e314e796896eae2cf7c178b69e012ffb16d070f8 100644 (file)
@@ -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)