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.create_cluster(self.mock_dc, 'fake_cluster', self.mock_cluster_spec) mock_get_managed_object_name.assert_called_once_with(self.mock_dc)
def test_create_cluster_raise_runtime_fault(self): exc = vmodl.RuntimeFault() exc.msg = 'RuntimeFault msg' self.mock_dc.hostFolder.CreateClusterEx = MagicMock(side_effect=exc) with self.assertRaises(VMwareRuntimeError) as excinfo: vmware.create_cluster(self.mock_dc, 'fake_cluster', self.mock_cluster_spec) self.assertEqual(excinfo.exception.strerror, 'RuntimeFault msg')
def test_create_cluster_raise_runtime_fault(self): exc = vmodl.RuntimeFault() exc.msg = 'RuntimeFault msg' self.mock_dc.hostFolder.CreateClusterEx = MagicMock( side_effect=exc) with self.assertRaises(VMwareRuntimeError) as excinfo: vmware.create_cluster(self.mock_dc, 'fake_cluster', self.mock_cluster_spec) self.assertEqual(excinfo.exception.strerror, 'RuntimeFault msg')
def test_create_cluster_raise_no_permission(self): exc = vim.fault.NoPermission() exc.privilegeId = 'Fake privilege' self.mock_dc.hostFolder.CreateClusterEx = MagicMock(side_effect=exc) with self.assertRaises(VMwareApiError) as excinfo: vmware.create_cluster(self.mock_dc, 'fake_cluster', self.mock_cluster_spec) self.assertEqual( excinfo.exception.strerror, 'Not enough permissions. Required privilege: ' 'Fake privilege')
def test_create_cluster_call(self): vmware.create_cluster(self.mock_dc, 'fake_cluster', self.mock_cluster_spec) self.mock_create_cluster_ex.assert_called_once_with( 'fake_cluster', self.mock_cluster_spec)