def test_create_cluster_raise_vim_fault(self): exc = vim.fault.VimFault() exc.msg = 'VimFault msg' self.mock_cluster.ReconfigureComputeResource_Task = \ MagicMock(side_effect=exc) with self.assertRaises(VMwareApiError) as excinfo: vmware.update_cluster(self.mock_cluster, self.mock_cluster_spec) self.assertEqual(excinfo.exception.strerror, 'VimFault msg')
def test_reconfigure_compute_resource_raise_runtime_fault(self): exc = vmodl.RuntimeFault() exc.msg = 'RuntimeFault msg' self.mock_cluster.ReconfigureComputeResource_Task = \ MagicMock(side_effect=exc) with self.assertRaises(VMwareRuntimeError) as excinfo: vmware.update_cluster(self.mock_cluster, self.mock_cluster_spec) self.assertEqual(excinfo.exception.strerror, 'RuntimeFault msg')
def test_wait_for_task_call(self): mock_wait_for_task = MagicMock() with patch('salt.utils.vmware.get_managed_object_name', MagicMock(return_value='fake_cluster')): with patch('salt.utils.vmware.wait_for_task', mock_wait_for_task): vmware.update_cluster(self.mock_cluster, self.mock_cluster_spec) mock_wait_for_task.assert_called_once_with( self.mock_task, 'fake_cluster', 'ClusterUpdateTask')
def test_wait_for_task_call(self): mock_wait_for_task = MagicMock() with patch('salt.utils.vmware.get_managed_object_name', MagicMock(return_value='fake_cluster')): with patch('salt.utils.vmware.wait_for_task', mock_wait_for_task): vmware.update_cluster(self.mock_cluster, self.mock_cluster_spec) mock_wait_for_task.assert_called_once_with(self.mock_task, 'fake_cluster', 'ClusterUpdateTask')
def test_reconfigure_compute_resource_raise_no_permission(self): exc = vim.fault.NoPermission() exc.privilegeId = 'Fake privilege' self.mock_cluster.ReconfigureComputeResource_Task = \ MagicMock(side_effect=exc) with self.assertRaises(VMwareApiError) as excinfo: vmware.update_cluster(self.mock_cluster, self.mock_cluster_spec) self.assertEqual( excinfo.exception.strerror, 'Not enough permissions. Required privilege: ' 'Fake privilege')
def test_reconfigure_compute_resource_task_call(self): vmware.update_cluster(self.mock_cluster, self.mock_cluster_spec) self.mock_reconfigure_compute_resource_task.assert_called_once_with( self.mock_cluster_spec, modify=True)
def test_get_managed_object_name(self): mock_get_managed_object_name = MagicMock() with patch('salt.utils.vmware.get_managed_object_name', mock_get_managed_object_name): vmware.update_cluster(self.mock_cluster, self.mock_cluster_spec) mock_get_managed_object_name.assert_called_once_with(self.mock_cluster)