From 445a88ee72cb01d4fd6cba4a0bbc651c75429654 Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Thu, 12 Oct 2017 09:22:54 +0800 Subject: Mock sleep() to accelerate the unit test Change-Id: I664ba714ab4094754fa3d71587da8536555a02ce Signed-off-by: Alex Yang --- tests/unit/test_daisy_server.py | 2 ++ tests/unit/test_environment.py | 6 ++++++ 2 files changed, 8 insertions(+) (limited to 'tests/unit') diff --git a/tests/unit/test_daisy_server.py b/tests/unit/test_daisy_server.py index 97e0a1e2..65282e82 100644 --- a/tests/unit/test_daisy_server.py +++ b/tests/unit/test_daisy_server.py @@ -394,6 +394,7 @@ bin_file_path2 = os.path.join(WORKSPACE, bin_file_name) @pytest.mark.parametrize('bin_file', [ (bin_file_path1), (bin_file_path2)]) +@mock.patch('deploy.daisy_server.time.sleep') @mock.patch.object(daisy_server.DaisyServer, 'delete_dir') @mock.patch.object(daisy_server.DaisyServer, 'scp_put') @mock.patch.object(daisy_server.DaisyServer, 'create_dir') @@ -402,6 +403,7 @@ def test_prepare_files_DaisyServer(mock_update_config, mock_create_dir, mock_scp_put, mock_delete_dir, + mock_sleep, bin_file, tmpdir): DaisyServerInst = DaisyServer(daisy_server_info['name'], diff --git a/tests/unit/test_environment.py b/tests/unit/test_environment.py index dcd8b046..aed2c73c 100644 --- a/tests/unit/test_environment.py +++ b/tests/unit/test_environment.py @@ -244,6 +244,7 @@ def test_create_daisy_server_BareMetalEnvironment(mock_create_daisy_server_vm, m tmpdir.remove() +@mock.patch('deploy.environment.time.sleep') @mock.patch.object(daisy_server.DaisyServer, 'prepare_cluster') @mock.patch.object(environment.BareMetalEnvironment, 'reboot_nodes') @mock.patch.object(daisy_server.DaisyServer, 'prepare_host_and_pxe') @@ -253,6 +254,7 @@ def test_create_daisy_server_BareMetalEnvironment(mock_create_daisy_server_vm, m def test_deploy_BareMetalEnvironment(mock_post_deploy, mock_check_openstack_installation, mock_check_os_installation, mock_prepare_host_and_pxe, mock_reboot_nodes, mock_prepare_cluster, + mock_sleep, tmpdir): work_dir = os.path.join(tmpdir.dirname, tmpdir.basename, work_dir_name) storage_dir = os.path.join(tmpdir.dirname, tmpdir.basename, storage_dir_name) @@ -439,12 +441,14 @@ def test_create_virtual_node_VirtualEnvironment(mock_create_virtual_disk, mock_c tmpdir.remove() +@mock.patch('deploy.environment.time.sleep') @mock.patch('deploy.environment.create_virtual_network') @mock.patch('deploy.environment.get_vm_mac_addresses') @mock.patch.object(environment.VirtualEnvironment, 'create_virtual_node') def test_create_nodes_VirtualEnvironment(mock_create_virtual_node, mock_get_vm_mac_addresses, mock_create_virtual_network, + mock_sleep, tmpdir): keepalived_net_name = 'daisy3' work_dir = os.path.join(tmpdir.dirname, tmpdir.basename, work_dir_name) @@ -538,6 +542,7 @@ def test_delete_old_environment_VirtualEnvironment(mock_delete_daisy_server, tmpdir.remove() +@mock.patch('deploy.environment.time.sleep') @mock.patch.object(environment.DaisyServer, 'post_deploy') @mock.patch.object(environment.DaisyServer, 'check_openstack_installation') @mock.patch.object(environment.DaisyServer, 'check_os_installation') @@ -553,6 +558,7 @@ def test_deploy_VirtualEnvironment(mock_create_nodes, mock_reboot_nodes, mock_copy_new_deploy_config, mock_prepare_host_and_pxe, mock_install_virtual_nodes, mock_check_os_installation, mock_check_openstack_installation, mock_post_deploy, + mock_sleep, tmpdir): work_dir = os.path.join(tmpdir.dirname, tmpdir.basename, work_dir_name) storage_dir = os.path.join(tmpdir.dirname, tmpdir.basename, storage_dir_name) -- cgit 1.2.3-korg