def test_clone_vm_resource_pool_is_not_empty(self): """ Checks clone_vm """ '#arrange' si = Mock(spec=vim.ServiceInstance) vim_mock = Mock() vim_mock.vm = Mock() vim_mock.vm.RelocateSpec = Mock() vim_mock.vm.CloneSpec = Mock() vim_mock.Datacenter = vim.Datacenter vim_mock.Datastore = vim.Datastore vim_mock.ServiceInstance = vim.ServiceInstance datacenter = Mock(spec=vim.Datacenter) template = Mock(spec=vim.VirtualMachine) template.datastore = [Mock()] pv_service = pyVmomiService(None, None, Mock(), vim_mock) pv_service.find_vm_by_name = Mock(return_value=template) pv_service.get_obj = Mock() pv_service.get_folder = Mock(return_value=datacenter) pv_service._get_datastore = Mock(return_value=Mock(spec=vim.Datastore)) pv_service._get_resource_pool = Mock(return_value=(Mock( spec=vim.ResourcePool), None)) params = pv_service.CloneVmParameters(si=si, template_name='my_temp', vm_name='my_name', vm_folder='my_folder', resource_pool='my_resource_pool') '#act' res = pv_service.clone_vm(clone_params=params, logger=Mock(), cancellation_context=Mock()) '#assert' self.assertIsNone(res.error) self.assertTrue(vim_mock.vm.RelocateSpec.called) self.assertTrue(vim_mock.vm.CloneSpec.called) self.assertTrue(pv_service.get_folder.called) self.assertTrue(pv_service.find_vm_by_name.called) self.assertTrue(pv_service.task_waiter.wait_for_task.called)
def test_clone_vm_resource_pool_is_not_empty(self): """ Checks clone_vm """ '#arrange' si = Mock(spec=vim.ServiceInstance) vim_mock = Mock() vim_mock.vm = Mock() vim_mock.vm.RelocateSpec = Mock() vim_mock.vm.CloneSpec = Mock() vim_mock.Datacenter = vim.Datacenter vim_mock.Datastore = vim.Datastore vim_mock.ServiceInstance = vim.ServiceInstance datacenter = Mock(spec=vim.Datacenter) template = Mock(spec=vim.VirtualMachine) template.datastore = [Mock()] pv_service = pyVmomiService(None, None, vim_mock) pv_service.find_vm_by_name = Mock(return_value=template) pv_service.get_obj = Mock() pv_service.get_folder = Mock(return_value=datacenter) pv_service.wait_for_task = Mock() pv_service._get_datastore = Mock(return_value=Mock(spec=vim.Datastore)) pv_service._get_resource_pool = Mock(return_value=(Mock(spec=vim.ResourcePool), None)) params = pv_service.CloneVmParameters(si=si, template_name='my_temp', vm_name='my_name', vm_folder='my_folder', resource_pool='my_resource_pool') '#act' res = pv_service.clone_vm(clone_params=params, logger=Mock()) '#assert' self.assertIsNone(res.error) self.assertTrue(vim_mock.vm.RelocateSpec.called) self.assertTrue(vim_mock.vm.CloneSpec.called) self.assertTrue(pv_service.get_folder.called) self.assertTrue(pv_service.find_vm_by_name.called) self.assertTrue(pv_service.wait_for_task.called)
def test_clone_vm_power_on_false(self): """ Checks clone_vm """ '#arrange' si = Mock(spec=vim.ServiceInstance) vim_mock = Mock() vim_mock.vm = Mock() vim_mock.vm.RelocateSpec = Mock() vim_mock.vm.CloneSpec = Mock() vim_mock.Datacenter = vim.Datacenter vim_mock.Datastore = vim.Datastore vim_mock.ServiceInstance = vim.ServiceInstance datacenter = Mock(spec=vim.Datacenter) template = Mock(spec=vim.VirtualMachine) template.datastore = [Mock()] pv_service = pyVmomiService(None, None, vim_mock) pv_service.find_vm_by_name = Mock(return_value=template) pv_service.get_obj = Mock() pv_service.get_folder = Mock(return_value=datacenter) pv_service.wait_for_task = Mock() params = pv_service.CloneVmParameters(si=si, template_name='my_temp', vm_name='my_name', vm_folder='my_folder', power_on=False) '#act' res = pv_service.clone_vm(params) '#assert' self.assertIsNone(res.error) self.assertTrue(vim_mock.vm.RelocateSpec.called) self.assertTrue(vim_mock.vm.CloneSpec.called) self.assertTrue(pv_service.get_folder.called) self.assertTrue(pv_service.find_vm_by_name.called) self.assertTrue(pv_service.get_obj.called) self.assertTrue(pv_service.wait_for_task.called)
def test_clone_vm_resource_pool_is_not_empty(self): """ Checks clone_vm """ "#arrange" si = Mock(spec=vim.ServiceInstance) vim_mock = Mock() vim_mock.vm = Mock() vim_mock.vm.RelocateSpec = Mock() vim_mock.vm.CloneSpec = Mock() vim_mock.Datacenter = vim.Datacenter vim_mock.Datastore = vim.Datastore vim_mock.ServiceInstance = vim.ServiceInstance datacenter = Mock(spec=vim.Datacenter) template = Mock(spec=vim.VirtualMachine) template.datastore = [Mock()] pv_service = pyVmomiService(None, None, vim_mock) pv_service.find_vm_by_name = Mock(return_value=template) pv_service.get_obj = Mock() pv_service.get_folder = Mock(return_value=datacenter) pv_service.wait_for_task = Mock() params = pv_service.CloneVmParameters( si=si, template_name="my_temp", vm_name="my_name", vm_folder="my_folder", resource_pool="my_resource_pool" ) "#act" res = pv_service.clone_vm(params) "#assert" self.assertIsNone(res.error) self.assertTrue(vim_mock.vm.RelocateSpec.called) self.assertTrue(vim_mock.vm.CloneSpec.called) self.assertTrue(pv_service.get_folder.called) self.assertTrue(pv_service.find_vm_by_name.called) self.assertTrue(pv_service.get_obj.called) self.assertTrue(pv_service.wait_for_task.called)
def test_clone_vm_destenation_folder_is_unsupported(self): """ Checks clone_vm """ '#arrange' si = Mock(spec=vim.ServiceInstance) vim_mock = Mock() vim_mock.vm = Mock() vim_mock.vm.RelocateSpec = Mock() vim_mock.vm.CloneSpec = Mock() vim_mock.Folder = vim.Folder vim_mock.Datacenter = vim.Datacenter vim_mock.ServiceInstance = vim.ServiceInstance folder = Mock(spec=vim.VirtualMachine) template = Mock(spec=vim.VirtualMachine) template.datastore = [Mock()] pv_service = pyVmomiService(None, None, Mock(), vim_mock) pv_service.find_vm_by_name = Mock(return_value=template) pv_service.get_obj = Mock() pv_service.get_folder = Mock(return_value=folder) pv_service._get_datastore = Mock(return_value=Mock(spec=vim.Datastore)) pv_service._get_resource_pool = Mock(return_value=Mock( spec=vim.ResourcePool)) params = pv_service.CloneVmParameters(si=si, template_name='my_temp', vm_name='my_name', vm_folder='my_folder') '#assert' self.assertRaises(ValueError, pv_service.clone_vm, params, Mock(), Mock()) self.assertTrue(pv_service.get_folder.called) self.assertFalse(vim_mock.vm.RelocateSpec.called) self.assertFalse(vim_mock.vm.CloneSpec.called) self.assertFalse(pv_service.find_vm_by_name.called) self.assertFalse(pv_service.task_waiter.wait_for_task.called)
def test_clone_vm_destenation_folder_is_unsupported(self): """ Checks clone_vm """ '#arrange' si = Mock(spec=vim.ServiceInstance) vim_mock = Mock() vim_mock.vm = Mock() vim_mock.vm.RelocateSpec = Mock() vim_mock.vm.CloneSpec = Mock() vim_mock.Folder = vim.Folder vim_mock.Datacenter = vim.Datacenter vim_mock.ServiceInstance = vim.ServiceInstance folder = Mock(spec=vim.VirtualMachine) template = Mock(spec=vim.VirtualMachine) template.datastore = [Mock()] pv_service = pyVmomiService(None, None, vim_mock) pv_service.find_vm_by_name = Mock(return_value=template) pv_service.get_obj = Mock() pv_service.get_folder = Mock(return_value=folder) pv_service.wait_for_task = Mock() pv_service._get_datastore = Mock(return_value=Mock(spec=vim.Datastore)) pv_service._get_resource_pool = Mock(return_value=Mock(spec=vim.ResourcePool)) params = pv_service.CloneVmParameters(si=si, template_name='my_temp', vm_name='my_name', vm_folder='my_folder') '#assert' self.assertRaises(ValueError, pv_service.clone_vm, params, Mock()) self.assertTrue(pv_service.get_folder.called) self.assertFalse(vim_mock.vm.RelocateSpec.called) self.assertFalse(vim_mock.vm.CloneSpec.called) self.assertFalse(pv_service.find_vm_by_name.called) self.assertFalse(pv_service.wait_for_task.called)