def test_remove_disk(self): vsan.remove_capacity_from_diskgroup( self.mock_si, self.mock_host_ref, self.mock_diskgroup, [self.mock_cap_disk1, self.mock_cap_disk2]) self.mock_remove_disk.assert_called_once_with( disk=[self.mock_cap_disk1, self.mock_cap_disk2], maintenanceSpec=self.mock_spec)
def test_maintenance_mode_no_action(self): vsan.remove_capacity_from_diskgroup( self.mock_si, self.mock_host_ref, self.mock_diskgroup, [self.mock_cap_disk1, self.mock_cap_disk2], data_evacuation=False) self.assertEqual(self.mock_spec.vsanMode.objectAction, vim.VsanHostDecommissionModeObjectAction.noAction)
def test_maintenance_mode_evacuate_all_data(self): vsan.remove_capacity_from_diskgroup( self.mock_si, self.mock_host_ref, self.mock_diskgroup, [self.mock_cap_disk1, self.mock_cap_disk2]) self.assertEqual( self.mock_spec.vsanMode.objectAction, vim.VsanHostDecommissionModeObjectAction.evacuateAllData)
def test_wait_for_tasks(self): mock_wait_for_task = MagicMock() with patch('salt.utils.vmware.wait_for_task', mock_wait_for_task): vsan.remove_capacity_from_diskgroup( self.mock_si, self.mock_host_ref, self.mock_diskgroup, [self.mock_cap_disk1, self.mock_cap_disk2]) mock_wait_for_task.assert_called_once_with(self.mock_task, 'fake_hostname', 'remove_capacity')
def test_get_hostname(self): mock_get_managed_object_name = MagicMock(return_value='fake_hostname') with patch('salt.utils.vmware.get_managed_object_name', mock_get_managed_object_name): vsan.remove_capacity_from_diskgroup( self.mock_si, self.mock_host_ref, self.mock_diskgroup, [self.mock_cap_disk1, self.mock_cap_disk2]) mock_get_managed_object_name.assert_called_once_with( self.mock_host_ref)
def test_remove_disk_raise_runtime_fault(self): err = vmodl.RuntimeFault() err.msg = 'runtime_fault' self.mock_host_vsan_system.RemoveDisk_Task = \ MagicMock(side_effect=err) with self.assertRaises(VMwareRuntimeError) as excinfo: vsan.remove_capacity_from_diskgroup( self.mock_si, self.mock_host_ref, self.mock_diskgroup, [self.mock_cap_disk1, self.mock_cap_disk2]) self.assertEqual(excinfo.exception.strerror, 'runtime_fault')
def test_remove_disk_mapping(self): vsan.remove_diskgroup(self.mock_si, self.mock_host_ref, self.mock_diskgroup) vsan.remove_capacity_from_diskgroup( self.mock_si, self.mock_host_ref, self.mock_diskgroup, [self.mock_cap_disk1, self.mock_cap_disk2], ) self.mock_remove_disk_mapping.assert_called_once_with( mapping=[self.mock_diskgroup], maintenanceSpec=self.mock_spec)
def test_remove_disk_raise_no_permission(self): err = vim.fault.NoPermission() err.privilegeId = 'Fake privilege' self.mock_host_vsan_system.RemoveDisk_Task = \ MagicMock(side_effect=err) with self.assertRaises(VMwareApiError) as excinfo: vsan.remove_capacity_from_diskgroup( self.mock_si, self.mock_host_ref, self.mock_diskgroup, [self.mock_cap_disk1, self.mock_cap_disk2]) self.assertEqual(excinfo.exception.strerror, 'Not enough permissions. Required privilege: ' 'Fake privilege')
def test_remove_disk_raise_vim_fault(self): err = vim.fault.VimFault() err.msg = "vim_fault" self.mock_host_vsan_system.RemoveDisk_Task = MagicMock(side_effect=err) with self.assertRaises(VMwareApiError) as excinfo: vsan.remove_capacity_from_diskgroup( self.mock_si, self.mock_host_ref, self.mock_diskgroup, [self.mock_cap_disk1, self.mock_cap_disk2], ) self.assertEqual(excinfo.exception.strerror, "vim_fault")
def test_result(self): res = vsan.remove_capacity_from_diskgroup( self.mock_si, self.mock_host_ref, self.mock_diskgroup, [self.mock_cap_disk1, self.mock_cap_disk2], ) self.assertTrue(res)