xenapi: ensure vcpu_weight configured correctly

Currently the vcpu_weight specified by the flavor is only set after
the VM has started, and is not set during migrate_finish.

This changes moves the setting of the vcpu_weight to the same place
that other vCPU options are set, such as the number of vCPUs, during
the initial creation of the VM record.

Fixes bug 1203714
Change-Id: I475a247f1ac3153798e9e58d64700f8124dd2a95
This commit is contained in:
John Garbutt 2013-07-22 13:08:36 +01:00
parent 19dc70f0c0
commit ff223d635c
4 changed files with 19 additions and 14 deletions

View File

@ -369,7 +369,7 @@ def stub_out_db_instance_api(stubs, injected=True):
name='m1.large',
memory_mb=8192,
vcpus=4,
vcpu_weight=None,
vcpu_weight=10,
root_gb=80,
ephemeral_gb=80,
flavorid=4,

View File

@ -584,12 +584,13 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
self.vm_info = vm_info
self.vm = vm
def check_vm_record(self, conn, check_injection=False):
# Check that m1.large above turned into the right thing.
instance_type = db.flavor_get_by_name(conn, 'm1.large')
def check_vm_record(self, conn, instance_type_id, check_injection):
instance_type = db.flavor_get(conn, instance_type_id)
mem_kib = long(instance_type['memory_mb']) << 10
mem_bytes = str(mem_kib << 10)
vcpus = instance_type['vcpus']
vcpu_weight = instance_type['vcpu_weight']
self.assertEquals(self.vm_info['max_mem'], mem_kib)
self.assertEquals(self.vm_info['mem'], mem_kib)
self.assertEquals(self.vm['memory_static_max'], mem_bytes)
@ -597,6 +598,11 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
self.assertEquals(self.vm['memory_dynamic_min'], mem_bytes)
self.assertEquals(self.vm['VCPUs_max'], str(vcpus))
self.assertEquals(self.vm['VCPUs_at_startup'], str(vcpus))
if vcpu_weight == None:
self.assertEquals(self.vm['VCPUs_params'], {})
else:
self.assertEquals(self.vm['VCPUs_params'],
{'weight': str(vcpu_weight)})
# Check that the VM is running according to Nova
self.assertEquals(self.vm_info['state'], power_state.RUNNING)
@ -736,7 +742,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
self.conn.spawn(self.context, instance, image_meta, injected_files,
'herp', network_info, block_device_info)
self.create_vm_record(self.conn, os_type, instance['name'])
self.check_vm_record(self.conn, check_injection)
self.check_vm_record(self.conn, instance_type_id, check_injection)
self.assertTrue(instance['os_type'])
self.assertTrue(instance['architecture'])
@ -815,7 +821,8 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
def test_spawn_vhd_glance_windows(self):
self._test_spawn(IMAGE_VHD, None, None,
os_type="windows", architecture="i386")
os_type="windows", architecture="i386",
instance_type_id=5)
self.check_vm_params_for_windows()
def test_spawn_iso_glance(self):

View File

@ -217,6 +217,11 @@ def create_vm(session, instance, name_label, kernel, ramdisk,
mem = str(long(instance_type['memory_mb']) * 1024 * 1024)
vcpus = str(instance_type['vcpus'])
vcpu_weight = instance_type['vcpu_weight']
vcpu_params = {}
if vcpu_weight is not None:
vcpu_params = {"weight": str(vcpu_weight)}
rec = {
'actions_after_crash': 'destroy',
'actions_after_reboot': 'restart',
@ -250,7 +255,7 @@ def create_vm(session, instance, name_label, kernel, ramdisk,
'user_version': '0',
'VCPUs_at_startup': vcpus,
'VCPUs_max': vcpus,
'VCPUs_params': {},
'VCPUs_params': vcpu_params,
'xenstore_data': {'allowvssprovider': 'false'}}
# Complete VM configuration record according to the image type

View File

@ -704,13 +704,6 @@ class VMOps(object):
agent.resetnetwork()
self.remove_hostname(instance, vm_ref)
# Set VCPU weight
instance_type = flavors.extract_flavor(instance)
vcpu_weight = instance_type['vcpu_weight']
if vcpu_weight is not None:
LOG.debug(_("Setting VCPU weight"), instance=instance)
self._session.call_xenapi('VM.add_to_VCPUs_params', vm_ref,
'weight', str(vcpu_weight))
def _get_vm_opaque_ref(self, instance, check_rescue=False):
"""Get xapi OpaqueRef from a db record.