def test_choose_from_multiple_cdroms(self, proxy_getter, mount_mock, unmount_mock, valid_mock, kernel_arguments_mock): """Test CD-ROM Source setup installation source task run - choice from multiple CD-ROMs. Fake four CD-ROM devices: First fails to mount, second has nothing useful, third has what we want so is left mounted, fourth is entirely skipped. The other two tests below are needed only to test the exit when nothing is found. """ kernel_arguments_mock.get.return_value = None device_tree = self.set_up_device_tree(4) proxy_getter.return_value = device_tree mount_mock.side_effect = \ [PayloadSetupError("Mocked failure"), DEFAULT, DEFAULT, DEFAULT] # only for devices 2-4; the expected first call is prevented by the exception from mount valid_mock.side_effect = [False, True, False] task = SetUpCdromSourceTask(self.mount_location) result = task.run() # 3/4 devices tried, 1/4 untried self.assert_resolve_and_mount_calls(device_tree, mount_mock, 3, 1) # Only 2 & 3 were mounted assert valid_mock.call_count == 2 # It makes no sense to check how validation was called because all mounting is to the same # path. # #1 died earlier, #2 was unmounted, #3 was left mounted, #4 never got mounted unmount_mock.assert_called_once_with(self.mount_location) # Test device name returned assert result == "test2"
def failure_to_mount_test(self, proxy_getter, mount_mock, unmount_mock, valid_mock): """Test CD-ROM Source setup installation source task run - mount failure. Mocks one disk which fails to mount, expect exception. """ device_tree = self.set_up_device_tree(1) proxy_getter.return_value = device_tree mount_mock.side_effect = PayloadSetupError("Mocked failure") valid_mock.return_value = True with self.assertRaises(SourceSetupError) as cm: task = SetUpCdromSourceTask(self.mount_location) task.run() # 1/1 devices tried, 0 untried self.assert_resolve_and_mount_calls(device_tree, mount_mock, 1, 0) # neither validation nor unmounting could not have been reached valid_mock.assert_not_called() unmount_mock.assert_not_called() # no device was selected self.assertFalse(task._device_name) # exception happened due to no disk self.assertEqual(str(cm.exception), "Found no CD-ROM")
class NFSSourceSetupTaskTestCase(unittest.TestCase): def setup_install_source_task_name_test(self): """Test NFS Source setup installation source task name.""" task = SetUpNFSSourceTask(mount_location, nfs_url) self.assertEqual(task.name, "Set up NFS installation source") @patch("pyanaconda.modules.payloads.source.nfs.initialization.mount") def setup_install_source_task_success_test(self, mount_mock): """Test NFS source setup success""" SetUpNFSSourceTask(mount_location, nfs_url).run() mount_mock.assert_called_once_with(nfs_address, mount_location, fstype="nfs", options="nolock") @patch("pyanaconda.modules.payloads.source.nfs.initialization.mount") def setup_install_source_task_options_nolock_test(self, mount_mock): """Test NFS source setup adding nolock to options """ SetUpNFSSourceTask(mount_location, "nfs:some-option:" + nfs_address).run() mount_mock.assert_called_with(nfs_address, mount_location, fstype="nfs", options="some-option,nolock") @patch("pyanaconda.modules.payloads.source.nfs.initialization.mount") def setup_install_source_task_success_options_test(self, mount_mock): """Test NFS source setup handling nolock in options""" SetUpNFSSourceTask(mount_location, "nfs:some-option,nolock:" + nfs_address).run() mount_mock.assert_called_with(nfs_address, mount_location, fstype="nfs", options="some-option,nolock") @patch("pyanaconda.modules.payloads.source.nfs.initialization.mount", side_effect=PayloadSetupError("Testing...")) def setup_install_source_task_failure_test(self, mount_mock): """Test NFS source setup failure""" task = SetUpNFSSourceTask(mount_location, nfs_url) with self.assertRaises(PayloadSetupError): task.run() mount_mock.assert_called_once_with(nfs_address, mount_location, fstype="nfs", options="nolock")
class NFSSourceSetupTaskTestCase(unittest.TestCase): def test_setup_install_source_task_name(self): """Test NFS Source setup installation source task name.""" task = SetUpNFSSourceTask(DEVICE_MOUNT_LOCATION, ISO_MOUNT_LOCATION, NFS_URL) assert task.name == "Set up NFS installation source" @patch( "pyanaconda.modules.payloads.source.nfs.initialization.find_and_mount_iso_image", return_value="trojan.iso") @patch("pyanaconda.modules.payloads.source.nfs.initialization.mount") def test_success_find_iso(self, mount_mock, find_and_mount_iso_image_mock): """Test NFS source setup find ISO success""" task = _create_setup_task() result = task.run() mount_mock.assert_called_once_with(NFS_ADDRESS, DEVICE_MOUNT_LOCATION, fstype="nfs", options="nolock") find_and_mount_iso_image_mock.assert_called_once_with( DEVICE_MOUNT_LOCATION, ISO_MOUNT_LOCATION) assert result == ISO_MOUNT_LOCATION @patch( "pyanaconda.modules.payloads.source.nfs.initialization.find_and_mount_iso_image", return_value="trojan.iso") @patch("pyanaconda.modules.payloads.source.nfs.initialization.mount") def test_success_find_path_with_iso(self, mount_mock, find_and_mount_iso_image_mock): """Test NFS source setup when url has ISO in a path success""" task = _create_setup_task("nfs:secret.com:/path/to/super.iso") result = task.run() mount_mock.assert_called_once_with("secret.com:/path/to", DEVICE_MOUNT_LOCATION, fstype="nfs", options="nolock") find_and_mount_iso_image_mock.assert_called_once_with( DEVICE_MOUNT_LOCATION + "/super.iso", ISO_MOUNT_LOCATION) assert result == ISO_MOUNT_LOCATION @patch( "pyanaconda.modules.payloads.source.nfs.initialization.verify_valid_repository", return_value=True) @patch( "pyanaconda.modules.payloads.source.nfs.initialization.find_and_mount_iso_image", return_value="") @patch("pyanaconda.modules.payloads.source.nfs.initialization.mount") def test_success_find_dir(self, mount_mock, find_and_mount_iso_image_mock, verify_valid_repository_mock): """Test NFS source setup find installation tree success""" task = _create_setup_task() result = task.run() mount_mock.assert_called_once_with(NFS_ADDRESS, DEVICE_MOUNT_LOCATION, fstype="nfs", options="nolock") find_and_mount_iso_image_mock.assert_called_once_with( DEVICE_MOUNT_LOCATION, ISO_MOUNT_LOCATION) verify_valid_repository_mock.assert_called_once_with( DEVICE_MOUNT_LOCATION) assert result == DEVICE_MOUNT_LOCATION @patch( "pyanaconda.modules.payloads.source.nfs.initialization.find_and_mount_iso_image", return_value="trojan.iso") @patch("pyanaconda.modules.payloads.source.nfs.initialization.mount") def test_setup_install_source_task_options_nolock( self, mount_mock, find_and_mount_iso_image_mock): """Test NFS source setup adding nolock to options""" task = SetUpNFSSourceTask(DEVICE_MOUNT_LOCATION, ISO_MOUNT_LOCATION, "nfs:some-option:" + NFS_ADDRESS) task.run() mount_mock.assert_called_with(NFS_ADDRESS, DEVICE_MOUNT_LOCATION, fstype="nfs", options="some-option,nolock") find_and_mount_iso_image_mock.assert_called_once_with( DEVICE_MOUNT_LOCATION, ISO_MOUNT_LOCATION) @patch( "pyanaconda.modules.payloads.source.nfs.initialization.find_and_mount_iso_image", return_value="trojan.iso") @patch("pyanaconda.modules.payloads.source.nfs.initialization.mount") def test_setup_install_source_task_success_options( self, mount_mock, find_and_mount_iso_image_mock): """Test NFS source setup handling nolock in options""" task = SetUpNFSSourceTask(DEVICE_MOUNT_LOCATION, ISO_MOUNT_LOCATION, "nfs:some-option,nolock:" + NFS_ADDRESS) task.run() mount_mock.assert_called_with(NFS_ADDRESS, DEVICE_MOUNT_LOCATION, fstype="nfs", options="some-option,nolock") find_and_mount_iso_image_mock.assert_called_once_with( DEVICE_MOUNT_LOCATION, ISO_MOUNT_LOCATION) @patch("pyanaconda.modules.payloads.source.nfs.initialization.mount", side_effect=PayloadSetupError("Testing...")) def test_setup_install_source_task_mount_failure(self, mount_mock): """Test NFS source setup failure""" task = SetUpNFSSourceTask(DEVICE_MOUNT_LOCATION, ISO_MOUNT_LOCATION, NFS_URL) with pytest.raises(SourceSetupError): task.run() mount_mock.assert_called_once_with(NFS_ADDRESS, DEVICE_MOUNT_LOCATION, fstype="nfs", options="nolock") @patch("pyanaconda.modules.payloads.source.nfs.initialization.unmount") @patch( "pyanaconda.modules.payloads.source.nfs.initialization.verify_valid_repository", return_value=False) @patch( "pyanaconda.modules.payloads.source.nfs.initialization.find_and_mount_iso_image", return_value="") @patch("pyanaconda.modules.payloads.source.nfs.initialization.mount") def test_setup_install_source_task_find_anything_failure( self, mount_mock, find_and_mount_iso_image_mock, verify_valid_repository_mock, unmount_mock): """Test NFS can't find anything to install from""" task = SetUpNFSSourceTask(DEVICE_MOUNT_LOCATION, ISO_MOUNT_LOCATION, NFS_URL) with pytest.raises(SourceSetupError): task.run() mount_mock.assert_called_once_with(NFS_ADDRESS, DEVICE_MOUNT_LOCATION, fstype="nfs", options="nolock") find_and_mount_iso_image_mock.assert_called_once_with( DEVICE_MOUNT_LOCATION, ISO_MOUNT_LOCATION) verify_valid_repository_mock.assert_called_once_with( DEVICE_MOUNT_LOCATION) unmount_mock.assert_called_once_with(DEVICE_MOUNT_LOCATION) @patch( "pyanaconda.modules.payloads.source.nfs.initialization.os.path.ismount", return_value=True) def test_failure_mount_already_used(self, ismount_mock): """NFS source setup failure to mount partition device.""" task = _create_setup_task() with pytest.raises(SourceSetupError) as cm: task.run() ismount_mock.assert_called_once() # must die on first check assert str(cm.value).startswith("The mount point")
class NFSSourceSetupTaskTestCase(unittest.TestCase): def setup_install_source_task_name_test(self): """Test NFS Source setup installation source task name.""" task = SetUpNFSSourceTask(device_mount_location, iso_mount_location, nfs_url) self.assertEqual(task.name, "Set up NFS installation source") @patch( "pyanaconda.modules.payloads.source.nfs.initialization.find_and_mount_iso_image", return_value="trojan.iso") @patch("pyanaconda.modules.payloads.source.nfs.initialization.mount") def success_find_iso_test(self, mount_mock, find_and_mount_iso_image_mock): """Test NFS source setup find ISO success""" task = _create_setup_task() result = task.run() mount_mock.assert_called_once_with(nfs_address, device_mount_location, fstype="nfs", options="nolock") find_and_mount_iso_image_mock.assert_called_once_with( device_mount_location, iso_mount_location) self.assertEqual(result, iso_mount_location) @patch( "pyanaconda.modules.payloads.source.nfs.initialization.verify_valid_installtree", return_value=True) @patch( "pyanaconda.modules.payloads.source.nfs.initialization.find_and_mount_iso_image", return_value="") @patch("pyanaconda.modules.payloads.source.nfs.initialization.mount") def success_find_dir_test(self, mount_mock, find_and_mount_iso_image_mock, verify_valid_installtree_mock): """Test NFS source setup find installation tree success""" task = _create_setup_task() result = task.run() mount_mock.assert_called_once_with(nfs_address, device_mount_location, fstype="nfs", options="nolock") find_and_mount_iso_image_mock.assert_called_once_with( device_mount_location, iso_mount_location) verify_valid_installtree_mock.assert_called_once_with( device_mount_location) self.assertEqual(result, device_mount_location) @patch( "pyanaconda.modules.payloads.source.nfs.initialization.find_and_mount_iso_image", return_value="trojan.iso") @patch("pyanaconda.modules.payloads.source.nfs.initialization.mount") def setup_install_source_task_options_nolock_test( self, mount_mock, find_and_mount_iso_image_mock): """Test NFS source setup adding nolock to options""" task = SetUpNFSSourceTask(device_mount_location, iso_mount_location, "nfs:some-option:" + nfs_address) task.run() mount_mock.assert_called_with(nfs_address, device_mount_location, fstype="nfs", options="some-option,nolock") find_and_mount_iso_image_mock.assert_called_once_with( device_mount_location, iso_mount_location) @patch( "pyanaconda.modules.payloads.source.nfs.initialization.find_and_mount_iso_image", return_value="trojan.iso") @patch("pyanaconda.modules.payloads.source.nfs.initialization.mount") def setup_install_source_task_success_options_test( self, mount_mock, find_and_mount_iso_image_mock): """Test NFS source setup handling nolock in options""" task = SetUpNFSSourceTask(device_mount_location, iso_mount_location, "nfs:some-option,nolock:" + nfs_address) task.run() mount_mock.assert_called_with(nfs_address, device_mount_location, fstype="nfs", options="some-option,nolock") find_and_mount_iso_image_mock.assert_called_once_with( device_mount_location, iso_mount_location) @patch("pyanaconda.modules.payloads.source.nfs.initialization.mount", side_effect=PayloadSetupError("Testing...")) def setup_install_source_task_mount_failure_test(self, mount_mock): """Test NFS source setup failure""" task = SetUpNFSSourceTask(device_mount_location, iso_mount_location, nfs_url) with self.assertRaises(SourceSetupError): task.run() mount_mock.assert_called_once_with(nfs_address, device_mount_location, fstype="nfs", options="nolock") @patch("pyanaconda.modules.payloads.source.nfs.initialization.unmount") @patch( "pyanaconda.modules.payloads.source.nfs.initialization.verify_valid_installtree", return_value=False) @patch( "pyanaconda.modules.payloads.source.nfs.initialization.find_and_mount_iso_image", return_value="") @patch("pyanaconda.modules.payloads.source.nfs.initialization.mount") def setup_install_source_task_find_anything_failure_test( self, mount_mock, find_and_mount_iso_image_mock, verify_valid_installtree_mock, unmount_mock): """Test NFS can't find anything to install from""" task = SetUpNFSSourceTask(device_mount_location, iso_mount_location, nfs_url) with self.assertRaises(SourceSetupError): task.run() mount_mock.assert_called_once_with(nfs_address, device_mount_location, fstype="nfs", options="nolock") find_and_mount_iso_image_mock.assert_called_once_with( device_mount_location, iso_mount_location) verify_valid_installtree_mock.assert_called_once_with( device_mount_location) unmount_mock.assert_called_once_with(device_mount_location) @patch( "pyanaconda.modules.payloads.source.nfs.initialization.os.path.ismount", return_value=True) def failure_mount_already_used_test(self, ismount_mock): """NFS source setup failure to mount partition device.""" task = _create_setup_task() with self.assertRaises(SourceSetupError) as cm: task.run() ismount_mock.assert_called_once() # must die on first check self.assertTrue(str(cm.exception).startswith("The mount point"))