diff options
author | Jenkins <jenkins@review.openstack.org> | 2013-01-09 04:09:45 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2013-01-09 04:09:45 +0000 |
commit | b9959b180e8035a0654313be3d6cded2da1d4894 (patch) | |
tree | ba1ac3bb47d570ef4b631dc344e31ce5be1c5c81 | |
parent | ddb2400047d0afd8bc8e408ac3e9034b4c625952 (diff) | |
parent | e6cae13dd21f03948a28088d45be678f6a0e5c4e (diff) | |
download | nova-b9959b180e8035a0654313be3d6cded2da1d4894.tar.gz nova-b9959b180e8035a0654313be3d6cded2da1d4894.tar.xz nova-b9959b180e8035a0654313be3d6cded2da1d4894.zip |
Merge "attach/detach_volume() take instance as a parameter"
-rw-r--r-- | nova/compute/manager.py | 4 | ||||
-rw-r--r-- | nova/tests/test_hypervapi.py | 4 | ||||
-rw-r--r-- | nova/tests/test_libvirt.py | 4 | ||||
-rw-r--r-- | nova/tests/test_virt_drivers.py | 8 | ||||
-rw-r--r-- | nova/tests/test_xenapi.py | 4 | ||||
-rw-r--r-- | nova/virt/baremetal/driver.py | 8 | ||||
-rw-r--r-- | nova/virt/baremetal/volume_driver.py | 34 | ||||
-rw-r--r-- | nova/virt/driver.py | 4 | ||||
-rw-r--r-- | nova/virt/fake.py | 7 | ||||
-rw-r--r-- | nova/virt/hyperv/driver.py | 8 | ||||
-rw-r--r-- | nova/virt/libvirt/driver.py | 6 | ||||
-rw-r--r-- | nova/virt/vmwareapi/driver.py | 4 | ||||
-rw-r--r-- | nova/virt/xenapi/driver.py | 8 |
13 files changed, 46 insertions, 57 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index f542fedf2..b24b4317b 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -2455,7 +2455,7 @@ class ComputeManager(manager.SchedulerDependentManager): try: self.driver.attach_volume(connection_info, - instance['name'], + instance, mountpoint) except Exception: # pylint: disable=W0702 with excutils.save_and_reraise_exception(): @@ -2502,7 +2502,7 @@ class ComputeManager(manager.SchedulerDependentManager): connection_info['serial'] = volume_id try: self.driver.detach_volume(connection_info, - instance['name'], + instance, mp) except Exception: # pylint: disable=W0702 with excutils.save_and_reraise_exception(): diff --git a/nova/tests/test_hypervapi.py b/nova/tests/test_hypervapi.py index cab877da9..f5713c457 100644 --- a/nova/tests/test_hypervapi.py +++ b/nova/tests/test_hypervapi.py @@ -508,7 +508,7 @@ class HyperVAPITestCase(basetestcase.BaseTestCase): self._volume_target_portal, self._volume_id) self._conn.attach_volume(connection_info, - self._instance_data["name"], '/dev/sdc') + self._instance_data, '/dev/sdc') def test_attach_volume(self): self._attach_volume() @@ -527,7 +527,7 @@ class HyperVAPITestCase(basetestcase.BaseTestCase): self._volume_target_portal, self._volume_id) self._conn.detach_volume(connection_info, - self._instance_data["name"], '/dev/sdc') + self._instance_data, '/dev/sdc') (_, volumes_paths, _) = self._hypervutils.get_vm_disks( self._instance_data["name"]) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index f23f96c2d..bd6816d71 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -1706,8 +1706,8 @@ class LibvirtConnTestCase(test.TestCase): self.assertRaises(exception.VolumeDriverNotFound, conn.attach_volume, {"driver_volume_type": "badtype"}, - "fake", - "/dev/fake") + {"name": "fake-instance"}, + "/dev/fake") def test_multi_nic(self): instance_data = dict(self.test_instance) diff --git a/nova/tests/test_virt_drivers.py b/nova/tests/test_virt_drivers.py index 9d9ebcad9..9e9309dfe 100644 --- a/nova/tests/test_virt_drivers.py +++ b/nova/tests/test_virt_drivers.py @@ -379,10 +379,10 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase): def test_attach_detach_volume(self): instance_ref, network_info = self._get_running_instance() self.connection.attach_volume({'driver_volume_type': 'fake'}, - instance_ref['name'], + instance_ref, '/mnt/nova/something') self.connection.detach_volume({'driver_volume_type': 'fake'}, - instance_ref['name'], + instance_ref, '/mnt/nova/something') @catch_notimplementederror @@ -390,11 +390,11 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase): instance_ref, network_info = self._get_running_instance() self.connection.power_off(instance_ref) self.connection.attach_volume({'driver_volume_type': 'fake'}, - instance_ref['name'], + instance_ref, '/mnt/nova/something') self.connection.power_on(instance_ref) self.connection.detach_volume({'driver_volume_type': 'fake'}, - instance_ref['name'], + instance_ref, '/mnt/nova/something') @catch_notimplementederror diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 8ac3b640f..2e2011a74 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -271,7 +271,7 @@ class XenAPIVolumeTestCase(stubs.XenAPITestBase): instance = db.instance_create(self.context, self.instance_values) vm = xenapi_fake.create_vm(instance['name'], 'Running') result = conn.attach_volume(self._make_connection_info(), - instance['name'], '/dev/sdc') + instance, '/dev/sdc') # check that the VM has a VBD attached to it # Get XenAPI record for VBD @@ -290,7 +290,7 @@ class XenAPIVolumeTestCase(stubs.XenAPITestBase): self.assertRaises(exception.VolumeDriverNotFound, conn.attach_volume, {'driver_volume_type': 'nonexist'}, - instance['name'], + instance, '/dev/sdc') diff --git a/nova/virt/baremetal/driver.py b/nova/virt/baremetal/driver.py index e517b399d..1d46e85a3 100644 --- a/nova/virt/baremetal/driver.py +++ b/nova/virt/baremetal/driver.py @@ -308,14 +308,14 @@ class BareMetalDriver(driver.ComputeDriver): def get_volume_connector(self, instance): return self.volume_driver.get_volume_connector(instance) - def attach_volume(self, connection_info, instance_name, mountpoint): + def attach_volume(self, connection_info, instance, mountpoint): return self.volume_driver.attach_volume(connection_info, - instance_name, mountpoint) + instance, mountpoint) @exception.wrap_exception() - def detach_volume(self, connection_info, instance_name, mountpoint): + def detach_volume(self, connection_info, instance, mountpoint): return self.volume_driver.detach_volume(connection_info, - instance_name, mountpoint) + instance, mountpoint) def get_info(self, instance): # NOTE(deva): compute/manager.py expects to get NotFound exception diff --git a/nova/virt/baremetal/volume_driver.py b/nova/virt/baremetal/volume_driver.py index 7f59ec517..09088dd53 100644 --- a/nova/virt/baremetal/volume_driver.py +++ b/nova/virt/baremetal/volume_driver.py @@ -50,22 +50,9 @@ CONF.import_opt('libvirt_volume_drivers', 'nova.virt.libvirt.driver') LOG = logging.getLogger(__name__) -def _get_baremetal_node_by_instance_name(virtapi, instance_name): +def _get_baremetal_node_by_instance_uuid(instance_uuid): context = nova_context.get_admin_context() - # TODO(deva): optimize this DB query. - # I don't think it should be _get_all - for node in bmdb.bm_node_get_all(context, service_host=CONF.host): - if not node['instance_uuid']: - continue - try: - inst = virtapi.instance_get_by_uuid(context, node['instance_uuid']) - if inst['name'] == instance_name: - return node - except exception.InstanceNotFound: - continue - - # raise exception if we found no matching instance - raise exception.InstanceNotFound(instance_name) + return bmdb.bm_node_get_by_instance_uuid(context, instance_uuid) def _create_iscsi_export_tgtadm(path, tid, iqn): @@ -200,10 +187,10 @@ class VolumeDriver(object): 'host': CONF.host, } - def attach_volume(self, connection_info, instance_name, mountpoint): + def attach_volume(self, connection_info, instance, mountpoint): raise NotImplementedError() - def detach_volume(self, connection_info, instance_name, mountpoint): + def detach_volume(self, connection_info, instance, mountpoint): raise NotImplementedError() @@ -227,22 +214,21 @@ class LibvirtVolumeDriver(VolumeDriver): method = getattr(driver, method_name) return method(connection_info, *args, **kwargs) - def attach_volume(self, connection_info, instance_name, mountpoint): - node = _get_baremetal_node_by_instance_name(self.virtapi, - instance_name) + def attach_volume(self, connection_info, instance, mountpoint): + node = _get_baremetal_node_by_instance_uuid(instance['uuid']) ctx = nova_context.get_admin_context() pxe_ip = bmdb.bm_pxe_ip_get_by_bm_node_id(ctx, node['id']) if not pxe_ip: if not CONF.baremetal.use_unsafe_iscsi: raise exception.NovaException(_( - 'No fixed PXE IP is associated to %s') % instance_name) + 'No fixed PXE IP is associated to %s') % instance['uuid']) mount_device = mountpoint.rpartition("/")[2] self._volume_driver_method('connect_volume', connection_info, mount_device) device_path = connection_info['data']['device_path'] - iqn = _get_iqn(instance_name, mountpoint) + iqn = _get_iqn(instance['name'], mountpoint) tid = _get_next_tid() _create_iscsi_export_tgtadm(device_path, tid, iqn) @@ -259,10 +245,10 @@ class LibvirtVolumeDriver(VolumeDriver): _allow_iscsi_tgtadm(tid, 'ALL') @exception.wrap_exception() - def detach_volume(self, connection_info, instance_name, mountpoint): + def detach_volume(self, connection_info, instance, mountpoint): mount_device = mountpoint.rpartition("/")[2] try: - iqn = _get_iqn(instance_name, mountpoint) + iqn = _get_iqn(instance['name'], mountpoint) tid = _find_tid(iqn) if tid is not None: _delete_iscsi_export_tgtadm(tid) diff --git a/nova/virt/driver.py b/nova/virt/driver.py index da4a9475c..a3fe68586 100644 --- a/nova/virt/driver.py +++ b/nova/virt/driver.py @@ -272,11 +272,11 @@ class ComputeDriver(object): # TODO(Vek): Need to pass context in for access to auth_token raise NotImplementedError() - def attach_volume(self, connection_info, instance_name, mountpoint): + def attach_volume(self, connection_info, instance, mountpoint): """Attach the disk to the instance at mountpoint using info""" raise NotImplementedError() - def detach_volume(self, connection_info, instance_name, mountpoint): + def detach_volume(self, connection_info, instance, mountpoint): """Detach the disk attached to the instance""" raise NotImplementedError() diff --git a/nova/virt/fake.py b/nova/virt/fake.py index 348675fe2..f719b1a74 100644 --- a/nova/virt/fake.py +++ b/nova/virt/fake.py @@ -199,17 +199,18 @@ class FakeDriver(driver.ComputeDriver): {'key': key, 'inst': self.instances}, instance=instance) - def attach_volume(self, connection_info, instance_name, mountpoint): + def attach_volume(self, connection_info, instance, mountpoint): """Attach the disk to the instance at mountpoint using info""" + instance_name = instance['name'] if not instance_name in self._mounts: self._mounts[instance_name] = {} self._mounts[instance_name][mountpoint] = connection_info return True - def detach_volume(self, connection_info, instance_name, mountpoint): + def detach_volume(self, connection_info, instance, mountpoint): """Detach the disk attached to the instance""" try: - del self._mounts[instance_name][mountpoint] + del self._mounts[instance['name']][mountpoint] except KeyError: pass return True diff --git a/nova/virt/hyperv/driver.py b/nova/virt/hyperv/driver.py index 62cb46f2f..9599bca33 100644 --- a/nova/virt/hyperv/driver.py +++ b/nova/virt/hyperv/driver.py @@ -105,16 +105,16 @@ class HyperVDriver(driver.ComputeDriver): def get_info(self, instance): return self._vmops.get_info(instance) - def attach_volume(self, connection_info, instance_name, mountpoint): + def attach_volume(self, connection_info, instance, mountpoint): """Attach volume storage to VM instance""" return self._volumeops.attach_volume(connection_info, - instance_name, + instance['name'], mountpoint) - def detach_volume(self, connection_info, instance_name, mountpoint): + def detach_volume(self, connection_info, instance, mountpoint): """Detach volume storage to VM instance""" return self._volumeops.detach_volume(connection_info, - instance_name, + instance['name'], mountpoint) def get_volume_connector(self, instance): diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index d90a34123..4a642922a 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -658,7 +658,8 @@ class LibvirtDriver(driver.ComputeDriver): return method(connection_info, *args, **kwargs) @exception.wrap_exception() - def attach_volume(self, connection_info, instance_name, mountpoint): + def attach_volume(self, connection_info, instance, mountpoint): + instance_name = instance['name'] virt_dom = self._lookup_by_name(instance_name) mount_device = mountpoint.rpartition("/")[2] conf = self.volume_driver_method('connect_volume', @@ -712,7 +713,8 @@ class LibvirtDriver(driver.ComputeDriver): return xml @exception.wrap_exception() - def detach_volume(self, connection_info, instance_name, mountpoint): + def detach_volume(self, connection_info, instance, mountpoint): + instance_name = instance['name'] mount_device = mountpoint.rpartition("/")[2] try: virt_dom = self._lookup_by_name(instance_name) diff --git a/nova/virt/vmwareapi/driver.py b/nova/virt/vmwareapi/driver.py index ce8005861..ff6291fe5 100644 --- a/nova/virt/vmwareapi/driver.py +++ b/nova/virt/vmwareapi/driver.py @@ -179,11 +179,11 @@ class VMWareESXDriver(driver.ComputeDriver): 'host': None } - def attach_volume(self, connection_info, instance_name, mountpoint): + def attach_volume(self, connection_info, instance, mountpoint): """Attach volume storage to VM instance.""" pass - def detach_volume(self, connection_info, instance_name, mountpoint): + def detach_volume(self, connection_info, instance, mountpoint): """Detach volume storage to VM instance.""" pass diff --git a/nova/virt/xenapi/driver.py b/nova/virt/xenapi/driver.py index 1b60faa9f..21affe72c 100644 --- a/nova/virt/xenapi/driver.py +++ b/nova/virt/xenapi/driver.py @@ -357,16 +357,16 @@ class XenAPIDriver(driver.ComputeDriver): xs_url = urlparse.urlparse(CONF.xenapi_connection_url) return xs_url.netloc - def attach_volume(self, connection_info, instance_name, mountpoint): + def attach_volume(self, connection_info, instance, mountpoint): """Attach volume storage to VM instance""" return self._volumeops.attach_volume(connection_info, - instance_name, + instance['name'], mountpoint) - def detach_volume(self, connection_info, instance_name, mountpoint): + def detach_volume(self, connection_info, instance, mountpoint): """Detach volume storage to VM instance""" return self._volumeops.detach_volume(connection_info, - instance_name, + instance['name'], mountpoint) def get_console_pool_info(self, console_type): |