]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
test_nuke: add unit tests for internal nuke options 1614/head
authorJosh Durgin <jdurgin@redhat.com>
Fri, 12 Feb 2021 22:54:17 +0000 (22:54 +0000)
committerJosh Durgin <jdurgin@redhat.com>
Fri, 12 Feb 2021 22:54:45 +0000 (22:54 +0000)
Signed-off-by: Josh Durgin <jdurgin@redhat.com>
teuthology/test/test_nuke.py

index c660e7ee19f4da56b76ecc08f63544f9ba93d10c..726dccd41ce314b316f81e6d5c4ef5ef7ae0ef7d 100644 (file)
@@ -4,12 +4,12 @@ import os
 import pytest
 import subprocess
 
-from unittest.mock import patch, Mock, DEFAULT
+from unittest.mock import patch, Mock, DEFAULT, ANY
 
 from teuthology import nuke
 from teuthology import misc
 from teuthology.config import config
-
+from teuthology.dispatcher.supervisor import create_fake_context
 
 class TestNuke(object):
 
@@ -230,3 +230,61 @@ class TestNuke(object):
                 misc.canonicalize_hostname(name, user=None): {},
             })
             m['destroy'].assert_not_called()
+
+def test_nuke_internal():
+    job_config = dict(
+        owner='test_owner',
+        targets={'user@host1': 'key1', 'user@host2': 'key2'},
+        archive_path='/path/to/test_run',
+        machine_type='test_machine',
+        os_type='centos',
+        os_version='8.3',
+        name='test_name',
+    )
+    locks = [{'name': target, 'description': job_config['name']} for target
+             in job_config['targets'].keys()]
+    ctx = create_fake_context(job_config)
+
+    # minimal call using defaults
+    with patch.multiple(
+            nuke,
+            nuke_helper=DEFAULT,
+            list_locks=lambda: locks,
+            unlock_one=DEFAULT,
+            ) as m:
+        nuke.nuke(ctx, True)
+        m['nuke_helper'].assert_called_with(ANY, True, False, True)
+        m['unlock_one'].assert_called()
+
+    # don't unlock
+    with patch.multiple(
+            nuke,
+            nuke_helper=DEFAULT,
+            list_locks=lambda: locks,
+            unlock_one=DEFAULT,
+            ) as m:
+        nuke.nuke(ctx, False)
+        m['nuke_helper'].assert_called_with(ANY, False, False, True)
+        m['unlock_one'].assert_not_called()
+
+    # mimicing what teuthology-dispatcher --supervisor does
+    with patch.multiple(
+            nuke,
+            nuke_helper=DEFAULT,
+            list_locks=lambda: locks,
+            unlock_one=DEFAULT,
+            ) as m:
+        nuke.nuke(ctx, False, True, False, True, False)
+        m['nuke_helper'].assert_called_with(ANY, False, True, False)
+        m['unlock_one'].assert_not_called()
+
+    # no targets
+    del ctx.config['targets']
+    with patch.multiple(
+            nuke,
+            nuke_helper=DEFAULT,
+            unlock_one=DEFAULT,
+            ) as m:
+        nuke.nuke(ctx, True)
+        m['nuke_helper'].assert_not_called()
+        m['unlock_one'].assert_not_called()