summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDorin Paslaru <dpaslaru@cloudbasesolutions.com>2015-03-10 18:55:27 +0545
committerDorin Paslaru <dpaslaru@cloudbasesolutions.com>2015-03-26 09:55:14 +0200
commit3e42c7ae3f7a9353834c8c9c4dc79ee39dd0783b (patch)
tree271f08aa7ac6059dbcac66350dc65e4fb0b4a3be
parent1fb09cc821589cde69da293c7d74f8e10b08d128 (diff)
downloadnova-3e42c7ae3f7a9353834c8c9c4dc79ee39dd0783b.tar.gz
Hyper-V: Sets *DataRoot paths for instances
Sets the path for the instance's ConfigurationDataRoot, LogDataRoot, SnapshotDataRoot, SuspendDataRoot and SwapFileDataRoot for vmutilsv2 instances and ExternalDataRoot and SnapshotDataRoot for vmutils to the instance's location. Closes-Bug: #1430239 Change-Id: I3c9e2dece00df06cafdcd164ece6269337feda71
-rw-r--r--nova/tests/unit/virt/hyperv/test_hypervapi.py1
-rw-r--r--nova/tests/unit/virt/hyperv/test_vmops.py4
-rw-r--r--nova/tests/unit/virt/hyperv/test_vmutils.py17
-rw-r--r--nova/tests/unit/virt/hyperv/test_vmutilsv2.py17
-rw-r--r--nova/virt/hyperv/vmops.py2
-rw-r--r--nova/virt/hyperv/vmutils.py8
-rw-r--r--nova/virt/hyperv/vmutilsv2.py10
7 files changed, 45 insertions, 14 deletions
diff --git a/nova/tests/unit/virt/hyperv/test_hypervapi.py b/nova/tests/unit/virt/hyperv/test_hypervapi.py
index 3f4583a239..a8460e4aeb 100644
--- a/nova/tests/unit/virt/hyperv/test_hypervapi.py
+++ b/nova/tests/unit/virt/hyperv/test_hypervapi.py
@@ -370,6 +370,7 @@ class HyperVAPITestCase(HyperVAPIBaseTestCase):
mox.IsA(int), mox.IsA(bool),
CONF.hyperv.dynamic_memory_ratio,
mox.IsA(int),
+ mox.IsA(str),
mox.IsA(list))
if not boot_from_volume:
diff --git a/nova/tests/unit/virt/hyperv/test_vmops.py b/nova/tests/unit/virt/hyperv/test_vmops.py
index f6babfa5d4..2578f0a56e 100644
--- a/nova/tests/unit/virt/hyperv/test_vmops.py
+++ b/nova/tests/unit/virt/hyperv/test_vmops.py
@@ -372,6 +372,8 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
fake_network_info = {'id': mock.sentinel.ID,
'address': mock.sentinel.ADDRESS}
mock_instance = fake_instance.fake_instance_obj(self.context)
+ instance_path = os.path.join(CONF.instances_path, mock_instance.name)
+
self._vmops.create_instance(instance=mock_instance,
network_info=[fake_network_info],
block_device_info=mock.sentinel.DEV_INFO,
@@ -381,7 +383,7 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
self._vmops._vmutils.create_vm.assert_called_once_with(
mock_instance.name, mock_instance.memory_mb,
mock_instance.vcpus, CONF.hyperv.limit_cpu_features,
- CONF.hyperv.dynamic_memory_ratio, vm_gen,
+ CONF.hyperv.dynamic_memory_ratio, vm_gen, instance_path,
[mock_instance.uuid])
expected = []
ctrl_type = vmops.VM_GENERATIONS_CONTROLLER_TYPES[vm_gen]
diff --git a/nova/tests/unit/virt/hyperv/test_vmutils.py b/nova/tests/unit/virt/hyperv/test_vmutils.py
index 1f8f0cafcb..b4ea793d95 100644
--- a/nova/tests/unit/virt/hyperv/test_vmutils.py
+++ b/nova/tests/unit/virt/hyperv/test_vmutils.py
@@ -237,7 +237,8 @@ class VMUtilsTestCase(test.NoDBTestCase):
self._vmutils.create_vm(self._FAKE_VM_NAME, self._FAKE_MEMORY_MB,
self._FAKE_VCPUS_NUM, False,
self._FAKE_DYNAMIC_MEMORY_RATIO,
- self._VM_GEN)
+ self._VM_GEN,
+ mock.sentinel.instance_path)
self.assertTrue(getattr(mock_svc, self._DEFINE_SYSTEM).called)
mock_set_mem.assert_called_with(mock_vm, mock_s, self._FAKE_MEMORY_MB,
@@ -691,17 +692,21 @@ class VMUtilsTestCase(test.NoDBTestCase):
fake_job_path,
fake_ret_val)
- response = self._vmutils._create_vm_obj(vs_man_svc=mock_vs_man_svc,
- vm_name='fake vm',
- vm_gen='fake vm gen',
- notes='fake notes',
- dynamic_memory_ratio=1.0)
+ response = self._vmutils._create_vm_obj(
+ vs_man_svc=mock_vs_man_svc,
+ vm_name='fake vm', vm_gen='fake vm gen',
+ notes='fake notes', dynamic_memory_ratio=1.0,
+ instance_path=mock.sentinel.instance_path)
_conn.new.assert_called_once_with()
self.assertEqual(mock_vs_gs_data.ElementName, 'fake vm')
mock_vs_man_svc.DefineVirtualSystem.assert_called_once_with(
[], None, mock_vs_gs_data.GetText_(1))
mock_check_ret_val.assert_called_once_with(fake_ret_val, fake_job_path)
+ self.assertEqual(mock.sentinel.instance_path,
+ mock_vs_gs_data.ExternalDataRoot)
+ self.assertEqual(mock.sentinel.instance_path,
+ mock_vs_gs_data.SnapshotDataRoot)
mock_get_wmi_obj.assert_called_with(fake_vm_path)
mock_get_vm_setting_data.assert_called_once_with(mock_get_wmi_obj())
diff --git a/nova/tests/unit/virt/hyperv/test_vmutilsv2.py b/nova/tests/unit/virt/hyperv/test_vmutilsv2.py
index 68fb7a42ae..cc189ee77b 100644
--- a/nova/tests/unit/virt/hyperv/test_vmutilsv2.py
+++ b/nova/tests/unit/virt/hyperv/test_vmutilsv2.py
@@ -157,6 +157,7 @@ class VMUtilsV2TestCase(test_vmutils.VMUtilsTestCase):
mock_job = mock.MagicMock()
fake_job_path = 'fake job path'
fake_ret_val = 'fake return value'
+ fake_vm_name = 'fake_vm_name'
_conn = self._vmutils._conn.Msvm_VirtualSystemSettingData
mock_check_ret_val.return_value = mock_job
@@ -168,17 +169,18 @@ class VMUtilsV2TestCase(test_vmutils.VMUtilsTestCase):
response = self._vmutils._create_vm_obj(
vs_man_svc=mock_vs_man_svc,
- vm_name='fake vm',
+ vm_name=fake_vm_name,
vm_gen='fake vm gen',
notes='fake notes',
- dynamic_memory_ratio=dynamic_memory_ratio)
+ dynamic_memory_ratio=dynamic_memory_ratio,
+ instance_path=mock.sentinel.instance_path)
if not vm_path:
mock_job.associators.assert_called_once_with(
self._vmutils._AFFECTED_JOB_ELEMENT_CLASS)
_conn.new.assert_called_once_with()
- self.assertEqual(mock_vs_data.ElementName, 'fake vm')
+ self.assertEqual(mock_vs_data.ElementName, fake_vm_name)
mock_vs_man_svc.DefineSystem.assert_called_once_with(
ResourceSettings=[], ReferenceConfiguration=None,
SystemSettings=mock_vs_data.GetText_(1))
@@ -190,6 +192,15 @@ class VMUtilsV2TestCase(test_vmutils.VMUtilsTestCase):
mock_get_wmi_obj.assert_called_with('fake vm path')
self.assertEqual(mock_vs_data.Notes, 'fake notes')
+ self.assertEqual(mock.sentinel.instance_path,
+ mock_vs_data.ConfigurationDataRoot)
+ self.assertEqual(mock.sentinel.instance_path, mock_vs_data.LogDataRoot)
+ self.assertEqual(mock.sentinel.instance_path,
+ mock_vs_data.SnapshotDataRoot)
+ self.assertEqual(mock.sentinel.instance_path,
+ mock_vs_data.SuspendDataRoot)
+ self.assertEqual(mock.sentinel.instance_path,
+ mock_vs_data.SwapFileDataRoot)
self.assertEqual(response, mock_get_wmi_obj())
def test_create_vm_obj(self):
diff --git a/nova/virt/hyperv/vmops.py b/nova/virt/hyperv/vmops.py
index 3ee63e6cc8..8d126842a7 100644
--- a/nova/virt/hyperv/vmops.py
+++ b/nova/virt/hyperv/vmops.py
@@ -294,6 +294,7 @@ class VMOps(object):
def create_instance(self, instance, network_info, block_device_info,
root_vhd_path, eph_vhd_path, vm_gen):
instance_name = instance.name
+ instance_path = os.path.join(CONF.instances_path, instance_name)
self._vmutils.create_vm(instance_name,
instance.memory_mb,
@@ -301,6 +302,7 @@ class VMOps(object):
CONF.hyperv.limit_cpu_features,
CONF.hyperv.dynamic_memory_ratio,
vm_gen,
+ instance_path,
[instance.uuid])
self._vmutils.create_scsi_controller(instance_name)
diff --git a/nova/virt/hyperv/vmutils.py b/nova/virt/hyperv/vmutils.py
index 586e19663e..686c288183 100644
--- a/nova/virt/hyperv/vmutils.py
+++ b/nova/virt/hyperv/vmutils.py
@@ -248,13 +248,13 @@ class VMUtils(object):
raise HyperVAuthorizationException(msg)
def create_vm(self, vm_name, memory_mb, vcpus_num, limit_cpu_features,
- dynamic_memory_ratio, vm_gen, notes=None):
+ dynamic_memory_ratio, vm_gen, instance_path, notes=None):
"""Creates a VM."""
vs_man_svc = self._conn.Msvm_VirtualSystemManagementService()[0]
LOG.debug('Creating VM %s', vm_name)
vm = self._create_vm_obj(vs_man_svc, vm_name, vm_gen, notes,
- dynamic_memory_ratio)
+ dynamic_memory_ratio, instance_path)
vmsetting = self._get_vm_setting_data(vm)
@@ -265,11 +265,13 @@ class VMUtils(object):
self._set_vm_vcpus(vm, vmsetting, vcpus_num, limit_cpu_features)
def _create_vm_obj(self, vs_man_svc, vm_name, vm_gen, notes,
- dynamic_memory_ratio):
+ dynamic_memory_ratio, instance_path):
vs_gs_data = self._conn.Msvm_VirtualSystemGlobalSettingData.new()
vs_gs_data.ElementName = vm_name
# Don't start automatically on host boot
vs_gs_data.AutomaticStartupAction = self._AUTOMATIC_STARTUP_ACTION_NONE
+ vs_gs_data.ExternalDataRoot = instance_path
+ vs_gs_data.SnapshotDataRoot = instance_path
(vm_path,
job_path,
diff --git a/nova/virt/hyperv/vmutilsv2.py b/nova/virt/hyperv/vmutilsv2.py
index 4834e61a03..3324e9848c 100644
--- a/nova/virt/hyperv/vmutilsv2.py
+++ b/nova/virt/hyperv/vmutilsv2.py
@@ -92,7 +92,7 @@ class VMUtilsV2(vmutils.VMUtils):
VirtualSystemType=self._VIRTUAL_SYSTEM_TYPE_REALIZED)]
def _create_vm_obj(self, vs_man_svc, vm_name, vm_gen, notes,
- dynamic_memory_ratio):
+ dynamic_memory_ratio, instance_path):
vs_data = self._conn.Msvm_VirtualSystemSettingData.new()
vs_data.ElementName = vm_name
vs_data.Notes = notes
@@ -107,6 +107,14 @@ class VMUtilsV2(vmutils.VMUtils):
vs_data.VirtualSystemSubType = self._VIRTUAL_SYSTEM_SUBTYPE_GEN2
vs_data.SecureBootEnabled = False
+ # Created VMs must have their *DataRoot paths in the same location as
+ # the instances' path.
+ vs_data.ConfigurationDataRoot = instance_path
+ vs_data.LogDataRoot = instance_path
+ vs_data.SnapshotDataRoot = instance_path
+ vs_data.SuspendDataRoot = instance_path
+ vs_data.SwapFileDataRoot = instance_path
+
(job_path,
vm_path,
ret_val) = vs_man_svc.DefineSystem(ResourceSettings=[],