diff options
| author | Salvatore Orlando <salvatore.orlando@eu.citrix.com> | 2011-01-11 01:50:14 +0000 |
|---|---|---|
| committer | Salvatore Orlando <salvatore.orlando@eu.citrix.com> | 2011-01-11 01:50:14 +0000 |
| commit | 6ba35582eec774253d725ab7a6959fdc12cea215 (patch) | |
| tree | 0a37f27dc9b3654c0d274d359cbe205922ea3b21 | |
| parent | 97ff39bd1d83f3cfa412f291087e025a91d147cd (diff) | |
Now removing kernel/ramdisk VDI after copy
Code tested with PV and HVM guests
Fixed pep8 errors
Could not run tests - test environment broken on dev machine
| -rw-r--r-- | nova/tests/test_xenapi.py | 81 | ||||
| -rw-r--r-- | nova/virt/hyperv.py | 2 | ||||
| -rw-r--r-- | nova/virt/xenapi/vm_utils.py | 20 | ||||
| -rw-r--r-- | plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 3 |
4 files changed, 65 insertions, 41 deletions
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index ec9462ada..7c256968f 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -206,40 +206,57 @@ class XenAPIVMTestCase(test.TestCase): check() - def test_spawn(self): - instance = self._create_instance() - - def check(): - instances = self.conn.list_instances() - self.assertEquals(instances, [1]) - - # Get Nova record for VM - vm_info = self.conn.get_info(1) + def check_vm_record(self, conn): + instances = conn.list_instances() + self.assertEquals(instances, [1]) + + # Get Nova record for VM + vm_info = conn.get_info(1) + + # Get XenAPI record for VM + vms = fake.get_all('VM') + vm = fake.get_record('VM', vms[0]) + + # Check that m1.large above turned into the right thing. + instance_type = instance_types.INSTANCE_TYPES['m1.large'] + mem_kib = long(instance_type['memory_mb']) << 10 + mem_bytes = str(mem_kib << 10) + vcpus = instance_type['vcpus'] + self.assertEquals(vm_info['max_mem'], mem_kib) + self.assertEquals(vm_info['mem'], mem_kib) + self.assertEquals(vm['memory_static_max'], mem_bytes) + self.assertEquals(vm['memory_dynamic_max'], mem_bytes) + self.assertEquals(vm['memory_dynamic_min'], mem_bytes) + self.assertEquals(vm['VCPUs_max'], str(vcpus)) + self.assertEquals(vm['VCPUs_at_startup'], str(vcpus)) + + # Check that the VM is running according to Nova + self.assertEquals(vm_info['state'], power_state.RUNNING) + + # Check that the VM is running according to XenAPI. + self.assertEquals(vm['power_state'], 'Running') + + def _test_spawn(self, image_id, kernel_id, ramdisk_id): + stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests) + values = {'name': 1, + 'project_id': self.project.id, + 'user_id': self.user.id, + 'image_id': image_id, + 'kernel_id': kernel_id, + 'ramdisk_id': ramdisk_id, + 'instance_type': 'm1.large', + 'mac_address': 'aa:bb:cc:dd:ee:ff', + } + conn = xenapi_conn.get_connection(False) + instance = db.instance_create(values) + conn.spawn(instance) + self.check_vm_record(conn) - # Get XenAPI record for VM - vms = xenapi_fake.get_all('VM') - vm = xenapi_fake.get_record('VM', vms[0]) - - # Check that m1.large above turned into the right thing. - instance_type = instance_types.INSTANCE_TYPES['m1.large'] - mem_kib = long(instance_type['memory_mb']) << 10 - mem_bytes = str(mem_kib << 10) - vcpus = instance_type['vcpus'] - self.assertEquals(vm_info['max_mem'], mem_kib) - self.assertEquals(vm_info['mem'], mem_kib) - self.assertEquals(vm['memory_static_max'], mem_bytes) - self.assertEquals(vm['memory_dynamic_max'], mem_bytes) - self.assertEquals(vm['memory_dynamic_min'], mem_bytes) - self.assertEquals(vm['VCPUs_max'], str(vcpus)) - self.assertEquals(vm['VCPUs_at_startup'], str(vcpus)) - - # Check that the VM is running according to Nova - self.assertEquals(vm_info['state'], power_state.RUNNING) - - # Check that the VM is running according to XenAPI. - self.assertEquals(vm['power_state'], 'Running') + def test_spawn_raw(self): + self._test_spawn(1, None, None) - check() + def test_spawn(self): + self._test_spawn(1, 2, 3) def tearDown(self): super(XenAPIVMTestCase, self).tearDown() diff --git a/nova/virt/hyperv.py b/nova/virt/hyperv.py index 4b9f6f946..4f0f6f9c7 100644 --- a/nova/virt/hyperv.py +++ b/nova/virt/hyperv.py @@ -89,7 +89,7 @@ REQ_POWER_STATE = { 'Reboot': 10, 'Reset': 11, 'Paused': 32768, - 'Suspended': 32769 + 'Suspended': 32769, } diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 674459841..4f2c754fa 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -54,6 +54,7 @@ MBR_SIZE_SECTORS = 63 MBR_SIZE_BYTES = MBR_SIZE_SECTORS * SECTOR_SIZE KERNEL_DIR = '/boot/guest' + class ImageType: """ Enumeration class for distinguishing different image types @@ -310,7 +311,7 @@ class VMHelper(HelperBase): virtual_size = int(meta['size']) vdi_size = virtual_size - logging.debug("Size for image %s:%d",image,virtual_size) + logging.debug("Size for image %s:%d", image, virtual_size) if type == ImageType.DISK: # Make room for MBR. vdi_size += MBR_SIZE_BYTES @@ -330,15 +331,20 @@ class VMHelper(HelperBase): f.write(chunk) with_vdi_attached_here(session, vdi, False, stream) - if (type==ImageType.KERNEL_RAMDISK): - #we need to invoke a plugin for copying VDI's content into proper path + if (type == ImageType.KERNEL_RAMDISK): + #we need to invoke a plugin for copying VDI's + #content into proper path + logging.debug("Copying VDI %s to /boot/guest on dom0", vdi) fn = "copy_kernel_vdi" args = {} args['vdi-ref'] = vdi - args['image-size']=str(vdi_size) + #let the plugin copy the correct number of bytes + args['image-size'] = str(vdi_size) task = session.async_call_plugin('glance', fn, args) - filename=session.wait_for_task(instance_id,task) - #TODO(salvatore-orlando): remove the VDI as it is not needed anymore + filename = session.wait_for_task(instance_id, task) + #remove the VDI as it is not needed anymore + session.get_xenapi().VDI.destroy(vdi) + logging.debug("Kernel/Ramdisk VDI %s destroyed", vdi) return filename else: return session.get_xenapi().VDI.get_uuid(vdi) @@ -596,7 +602,7 @@ def with_vdi_attached_here(session, vdi, read_only, f): vbd_rec['userdevice'] = 'autodetect' vbd_rec['bootable'] = False vbd_rec['mode'] = read_only and 'RO' or 'RW' - logging.debug("read_only: %s",str(read_only)) + logging.debug("read_only: %s", str(read_only)) vbd_rec['type'] = 'disk' vbd_rec['unpluggable'] = True vbd_rec['empty'] = False diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index 7f0b375e1..97cf32dcf 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -18,7 +18,7 @@ # under the License. # -# XenAPI plugin for putting images into glance +# XenAPI plugin for managing glance images # import base64 @@ -62,6 +62,7 @@ def _copy_kernel_vdi(dest,copy_args): #read data from /dev/ and write into a file on /boot/guest of=open(filename,'wb') f=open(dest,'rb') + #copy only vdi_size bytes data=f.read(vdi_size) of.write(data) f.close() |
