コード例 #1
0
 def _get_vm(self, conn_v2, vm_name):
     vms = conn_v2.Msvm_ComputerSystem(ElementName=vm_name)
     n = len(vms)
     if not n:
         raise exceptions.HyperVVMNotFoundException(vm_name=vm_name)
     elif n > 1:
         raise exceptions.HyperVException(
             _('Duplicate VM name found: %s') % vm_name)
     return vms[0]
コード例 #2
0
 def _lookup_vm_check(self,
                      vm_name,
                      as_vssd=True,
                      for_update=False,
                      virtual_system_type=_VIRTUAL_SYSTEM_TYPE_REALIZED):
     vm = self._lookup_vm(vm_name, as_vssd, for_update, virtual_system_type)
     if not vm:
         raise exceptions.HyperVVMNotFoundException(vm_name=vm_name)
     return vm
コード例 #3
0
    def test_get_instance_dir(self,
                              mock_get_vmutils,
                              mock_exists,
                              mock_check_dir,
                              mock_get_remote_unc_path,
                              mock_get_instances_sub_dir,
                              configured_dir_exists=False,
                              remote_server=None,
                              vm_exists=False):
        mock_get_instances_sub_dir.return_value = mock.sentinel.configured_dir
        mock_exists.return_value = configured_dir_exists

        expected_vmutils = (self._pathutils._vmutils if not remote_server else
                            mock_get_vmutils.return_value)
        mock_get_root_dir = expected_vmutils.get_vm_config_root_dir
        mock_get_root_dir.side_effect = (
            (mock.sentinel.config_root_dir, )
            if vm_exists else os_win_exc.HyperVVMNotFoundException(
                vm_name=mock.sentinel.instance_name))

        mock_get_remote_unc_path.return_value = mock.sentinel.remote_root_dir

        instance_dir = self._pathutils.get_instance_dir(
            mock.sentinel.instance_name,
            remote_server=remote_server,
            create_dir=mock.sentinel.create_dir,
            remove_dir=mock.sentinel.remove_dir)

        if configured_dir_exists or not vm_exists:
            expected_instance_dir = mock.sentinel.configured_dir
        else:
            # In this case, we expect the instance location to be
            # retrieved from the vm itself.
            mock_get_root_dir.assert_called_once_with(
                mock.sentinel.instance_name)

            if remote_server:
                expected_instance_dir = mock.sentinel.remote_root_dir
                mock_get_remote_unc_path.assert_called_once_with(
                    mock.sentinel.remote_server, mock.sentinel.config_root_dir)
            else:
                expected_instance_dir = mock.sentinel.config_root_dir

        self.assertEqual(expected_instance_dir, instance_dir)

        mock_get_instances_sub_dir.assert_called_once_with(
            mock.sentinel.instance_name,
            remote_server,
            create_dir=False,
            remove_dir=False)
        mock_check_dir.assert_called_once_with(
            expected_instance_dir,
            create_dir=mock.sentinel.create_dir,
            remove_dir=mock.sentinel.remove_dir)
コード例 #4
0
    def test_converted_exception(self):
        self.driver._vmops.get_info.side_effect = (os_win_exc.OSWinException)
        self.assertRaises(exception.NovaException, self.driver.get_info,
                          mock.sentinel.instance)

        self.driver._vmops.get_info.side_effect = os_win_exc.HyperVException
        self.assertRaises(exception.NovaException, self.driver.get_info,
                          mock.sentinel.instance)

        self.driver._vmops.get_info.side_effect = (
            os_win_exc.HyperVVMNotFoundException(vm_name='foofoo'))
        self.assertRaises(exception.InstanceNotFound, self.driver.get_info,
                          mock.sentinel.instance)
コード例 #5
0
    def test_get_instance_by_name_not_update_map(self, mock_get_by_uuid):
        mock_instance = fake_instance.fake_instance_obj(self.context)
        self.clusterops._vmutils.get_instance_uuid.side_effect = (
            os_win_exc.HyperVVMNotFoundException(vm_name=mock_instance.name))
        self.clusterops._update_instance_map = mock.MagicMock()
        self.clusterops._instance_map = mock.MagicMock()
        self.clusterops._instance_map.get.side_effect = [None,
                                                          mock_instance.uuid]
        mock_get_by_uuid.return_value = mock_instance

        ret = self.clusterops._get_instance_by_name(mock_instance.name)
        self.assertEqual(ret, mock_instance)
        self.clusterops._update_instance_map.assert_called_with()
コード例 #6
0
ファイル: test_snapshotops.py プロジェクト: youbun/nova
    def test_snapshot_instance_not_found(self, mock_snapshot):
        mock_instance = fake_instance.fake_instance_obj(self.context)
        mock_snapshot.side_effect = os_win_exc.HyperVVMNotFoundException(
            vm_name=mock_instance.name)

        self.assertRaises(exception.InstanceNotFound,
                          self._snapshotops.snapshot, self.context,
                          mock_instance, mock.sentinel.image_id,
                          mock.sentinel.update_task_state)

        mock_snapshot.assert_called_once_with(self.context, mock_instance,
                                              mock.sentinel.image_id,
                                              mock.sentinel.update_task_state)
コード例 #7
0
ファイル: test_eventhandler.py プロジェクト: mnaser/nova-1
    def _test_get_instance_uuid(self, instance_found=True, missing_uuid=False):
        if instance_found:
            side_effect = (mock.sentinel.instance_uuid
                           if not missing_uuid else None, )
        else:
            side_effect = os_win_exc.HyperVVMNotFoundException(
                vm_name=mock.sentinel.instance_name)
        mock_get_uuid = self._event_handler._vmutils.get_instance_uuid
        mock_get_uuid.side_effect = side_effect

        instance_uuid = self._event_handler._get_instance_uuid(
            mock.sentinel.instance_name)

        expected_uuid = (mock.sentinel.instance_uuid
                         if instance_found and not missing_uuid else None)
        self.assertEqual(expected_uuid, instance_uuid)
コード例 #8
0
    def test_live_migration_in_cluster_exception(self):
        mock_instance = fake_instance.fake_instance_obj(self._fake_context)
        self.livemigrops._clustutils.vm_exists.return_value = True
        recover_method = mock.MagicMock()
        dest = 'fake_dest'
        node_names = [dest, 'fake_node2']
        get_nodes = self.livemigrops._clustutils.get_cluster_node_names
        get_nodes.return_value = node_names
        clustutils = self.livemigrops._clustutils
        clustutils.live_migrate_vm.side_effect = [
            os_win_exc.HyperVVMNotFoundException(mock_instance.name)]

        self.assertRaises(
            os_win_exc.HyperVVMNotFoundException,
            self.livemigrops.live_migration,
            self._fake_context, mock_instance, dest, mock.sentinel.post_method,
            recover_method, block_migration=False, migrate_data=None)

        recover_method.assert_called_once_with(
            self._fake_context, mock_instance, dest, False)
コード例 #9
0
 def bar(self):
     foo = "foofoo"
     raise os_win_exc.HyperVVMNotFoundException(vm_name=foo)
コード例 #10
0
 def _lookup_vm_check(self, vm_name):
     vm = self._lookup_vm(vm_name)
     if not vm:
         raise exceptions.HyperVVMNotFoundException(vm_name=vm_name)
     return vm
コード例 #11
0
 def _lookup_vm_check(self, vm_name, as_vssd=True, for_update=False):
     vm = self._lookup_vm(vm_name, as_vssd, for_update)
     if not vm:
         raise exceptions.HyperVVMNotFoundException(vm_name=vm_name)
     return vm