diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-07-25 17:49:54 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-07-25 17:49:54 +0000 |
| commit | 68135241484ede24c8838afc2cf3d076f5b9c19f (patch) | |
| tree | c280f84b6d285fd1ca8e021f41e87bd37cd4ebeb /nova | |
| parent | 474b41d07a5813c17dcb5ab77558e4bfb3153fe5 (diff) | |
| parent | 9a2cc2544a4e6609c409b06c8ff91d596fe43a8c (diff) | |
| download | nova-68135241484ede24c8838afc2cf3d076f5b9c19f.tar.gz nova-68135241484ede24c8838afc2cf3d076f5b9c19f.tar.xz nova-68135241484ede24c8838afc2cf3d076f5b9c19f.zip | |
Merge "Adds xcp disk resize support."
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/tests/test_xenapi.py | 28 | ||||
| -rw-r--r-- | nova/tests/xenapi/stubs.py | 7 | ||||
| -rw-r--r-- | nova/virt/xenapi/driver.py | 14 | ||||
| -rw-r--r-- | nova/virt/xenapi/vmops.py | 19 |
4 files changed, 55 insertions, 13 deletions
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 9486f4144..81c1ab909 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -952,7 +952,27 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase): self.stubs.Set(stubs.FakeSessionForVMTests, "VDI_resize", fake_vdi_resize) stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests, - product_version=(6, 0, 0)) + product_version=(6, 0, 0), + product_brand='XenServer') + conn = xenapi_conn.XenAPIDriver(False) + vdi_ref = xenapi_fake.create_vdi('hurr', 'fake') + vdi_uuid = xenapi_fake.get_record('VDI', vdi_ref)['uuid'] + conn._vmops._resize_instance(instance, + {'uuid': vdi_uuid, 'ref': vdi_ref}) + self.assertEqual(called['resize'], True) + + def test_resize_xcp(self): + instance = db.instance_create(self.context, self.instance_values) + called = {'resize': False} + + def fake_vdi_resize(*args, **kwargs): + called['resize'] = True + + self.stubs.Set(stubs.FakeSessionForVMTests, + "VDI_resize", fake_vdi_resize) + stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests, + product_version=(1, 4, 99), + product_brand='XCP') conn = xenapi_conn.XenAPIDriver(False) vdi_ref = xenapi_fake.create_vdi('hurr', 'fake') vdi_uuid = xenapi_fake.get_record('VDI', vdi_ref)['uuid'] @@ -1011,6 +1031,9 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase): self.stubs.Set(vmops.VMOps, '_start', fake_vm_start) self.stubs.Set(vmops.VMOps, 'finish_revert_migration', fake_finish_revert_migration) + stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests, + product_version=(4, 0, 0), + product_brand='XenServer') conn = xenapi_conn.XenAPIDriver(False) network_info = fake_network.fake_get_instance_nw_info(self.stubs, @@ -1043,6 +1066,9 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase): self.stubs.Set(vmops.VMOps, '_start', fake_vm_start) self.stubs.Set(stubs.FakeSessionForVMTests, "VDI_resize_online", fake_vdi_resize) + stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests, + product_version=(4, 0, 0), + product_brand='XenServer') conn = xenapi_conn.XenAPIDriver(False) network_info = fake_network.fake_get_instance_nw_info(self.stubs, diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index 483356424..b7de16e9c 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -53,12 +53,13 @@ def stubout_instance_snapshot(stubs): stubs.Set(vm_utils, '_wait_for_vhd_coalesce', fake_wait_for_vhd_coalesce) -def stubout_session(stubs, cls, product_version=(5, 6, 2), **opt_args): +def stubout_session(stubs, cls, product_version=(5, 6, 2), + product_brand='XenServer', **opt_args): """Stubs out methods from XenAPISession""" stubs.Set(xenapi_conn.XenAPISession, '_create_session', lambda s, url: cls(url, **opt_args)) - stubs.Set(xenapi_conn.XenAPISession, '_get_product_version', - lambda s: product_version) + stubs.Set(xenapi_conn.XenAPISession, '_get_product_version_and_brand', + lambda s: (product_version, product_brand)) def stubout_get_this_vm_uuid(stubs): diff --git a/nova/virt/xenapi/driver.py b/nova/virt/xenapi/driver.py index 07b775fd9..2a86277e5 100644 --- a/nova/virt/xenapi/driver.py +++ b/nova/virt/xenapi/driver.py @@ -590,7 +590,8 @@ class XenAPISession(object): url = self._create_first_session(url, user, pw, exception) self._populate_session_pool(url, user, pw, exception) self.host_uuid = self._get_host_uuid() - self.product_version = self._get_product_version() + self.product_version, self.product_brand = \ + self._get_product_version_and_brand() def _create_first_session(self, url, user, pw, exception): try: @@ -632,13 +633,16 @@ class XenAPISession(object): host_ref = session.xenapi.session.get_this_host(session.handle) return session.xenapi.host.get_uuid(host_ref) - def _get_product_version(self): - """Return a tuple of (major, minor, rev) for the host version""" + def _get_product_version_and_brand(self): + """Return a tuple of (major, minor, rev) for the host version and + a string of the product brand""" host = self.get_xenapi_host() software_version = self.call_xenapi('host.get_software_version', host) - product_version = software_version['product_version'] - return tuple(int(part) for part in product_version.split('.')) + product_version = tuple(int(part) for part in + software_version['product_version'].split('.')) + product_brand = software_version['product_brand'] + return product_version, product_brand def get_session_id(self): """Return a string session_id. Used for vnc consoles.""" diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 785cd614c..008dc15e9 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -790,14 +790,25 @@ class VMOps(object): vdi_uuid = root_vdi['uuid'] LOG.debug(_("Resizing up VDI %(vdi_uuid)s from %(old_gb)dGB to " "%(new_gb)dGB"), locals(), instance=instance) - if self._session.product_version[0] > 5: - resize_func_name = 'VDI.resize' - else: - resize_func_name = 'VDI.resize_online' + resize_func_name = self.check_resize_func_name() self._session.call_xenapi(resize_func_name, root_vdi['ref'], str(new_disk_size)) LOG.debug(_("Resize complete"), instance=instance) + def check_resize_func_name(self): + """Check the function name used to resize an instance based + on product_brand and product_version.""" + if ((self._session.product_brand == 'XCP' and + (self._session.product_version[0] == 1 and + self._session.product_version[1] > 1)) or + (self._session.product_brand == 'XCP' and + self._session.product_version[0] > 1) or + (self._session.product_brand is 'XenServer' and + self._session.product_version[0] > 5)): + return 'VDI.resize' + else: + return 'VDI.resize_online' + def reboot(self, instance, reboot_type): """Reboot VM instance.""" # Note (salvatore-orlando): security group rules are not re-enforced |
