summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-10-22 01:24:32 +0000
committerGerrit Code Review <review@openstack.org>2012-10-22 01:24:32 +0000
commit8cb329b2a03f1d04f13c38244477e53ca4a321f0 (patch)
treebed6dbeb3d7a36f4b5562fe1442789174be21712 /nova
parentf1155fc9491070b58ac2908f82a324388ed3c27e (diff)
parentaf51b46b1e08b26c07bd32019e54b9c521cb7813 (diff)
Merge "Allow local rbd user and secret_uuid configuration"
Diffstat (limited to 'nova')
-rw-r--r--nova/tests/test_libvirt.py66
-rw-r--r--nova/virt/libvirt/volume.py15
2 files changed, 78 insertions, 3 deletions
diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py
index 7de72266b..43b4d4813 100644
--- a/nova/tests/test_libvirt.py
+++ b/nova/tests/test_libvirt.py
@@ -299,6 +299,38 @@ class LibvirtVolumeTestCase(test.TestCase):
libvirt_driver.disconnect_volume(connection_info, mount_device)
connection_info = vol_driver.terminate_connection(vol, self.connr)
+ def test_libvirt_rbd_driver_auth_enabled_flags_override(self):
+ vol_driver = volume_driver.RBDDriver()
+ libvirt_driver = volume.LibvirtNetVolumeDriver(self.fake_conn)
+ name = 'volume-00000001'
+ vol = {'id': 1, 'name': name}
+ connection_info = vol_driver.initialize_connection(vol, self.connr)
+ uuid = '875a8070-d0b9-4949-8b31-104d125c9a64'
+ user = 'foo'
+ secret_type = 'ceph'
+ connection_info['data']['auth_enabled'] = True
+ connection_info['data']['auth_username'] = user
+ connection_info['data']['secret_type'] = secret_type
+ connection_info['data']['secret_uuid'] = uuid
+
+ flags_uuid = '37152720-1785-11e2-a740-af0c1d8b8e4b'
+ flags_user = 'bar'
+ self.flags(rbd_user=flags_user,
+ rbd_secret_uuid=flags_uuid)
+
+ mount_device = "vde"
+ conf = libvirt_driver.connect_volume(connection_info, mount_device)
+ tree = conf.format_dom()
+ self.assertEqual(tree.get('type'), 'network')
+ self.assertEqual(tree.find('./source').get('protocol'), 'rbd')
+ rbd_name = '%s/%s' % (FLAGS.rbd_pool, name)
+ self.assertEqual(tree.find('./source').get('name'), rbd_name)
+ self.assertEqual(tree.find('./auth').get('username'), flags_user)
+ self.assertEqual(tree.find('./auth/secret').get('type'), secret_type)
+ self.assertEqual(tree.find('./auth/secret').get('uuid'), flags_uuid)
+ libvirt_driver.disconnect_volume(connection_info, mount_device)
+ connection_info = vol_driver.terminate_connection(vol, self.connr)
+
def test_libvirt_rbd_driver_auth_disabled(self):
vol_driver = volume_driver.RBDDriver()
libvirt_driver = volume.LibvirtNetVolumeDriver(self.fake_conn)
@@ -324,6 +356,40 @@ class LibvirtVolumeTestCase(test.TestCase):
libvirt_driver.disconnect_volume(connection_info, mount_device)
connection_info = vol_driver.terminate_connection(vol, self.connr)
+ def test_libvirt_rbd_driver_auth_disabled_flags_override(self):
+ vol_driver = volume_driver.RBDDriver()
+ libvirt_driver = volume.LibvirtNetVolumeDriver(self.fake_conn)
+ name = 'volume-00000001'
+ vol = {'id': 1, 'name': name}
+ connection_info = vol_driver.initialize_connection(vol, self.connr)
+ uuid = '875a8070-d0b9-4949-8b31-104d125c9a64'
+ user = 'foo'
+ secret_type = 'ceph'
+ connection_info['data']['auth_enabled'] = False
+ connection_info['data']['auth_username'] = user
+ connection_info['data']['secret_type'] = secret_type
+ connection_info['data']['secret_uuid'] = uuid
+
+ # NOTE: Supplying the rbd_secret_uuid will enable authentication
+ # locally in nova-compute even if not enabled in nova-volume/cinder
+ flags_uuid = '37152720-1785-11e2-a740-af0c1d8b8e4b'
+ flags_user = 'bar'
+ self.flags(rbd_user=flags_user,
+ rbd_secret_uuid=flags_uuid)
+
+ mount_device = "vde"
+ conf = libvirt_driver.connect_volume(connection_info, mount_device)
+ tree = conf.format_dom()
+ self.assertEqual(tree.get('type'), 'network')
+ self.assertEqual(tree.find('./source').get('protocol'), 'rbd')
+ rbd_name = '%s/%s' % (FLAGS.rbd_pool, name)
+ self.assertEqual(tree.find('./source').get('name'), rbd_name)
+ self.assertEqual(tree.find('./auth').get('username'), flags_user)
+ self.assertEqual(tree.find('./auth/secret').get('type'), secret_type)
+ self.assertEqual(tree.find('./auth/secret').get('uuid'), flags_uuid)
+ libvirt_driver.disconnect_volume(connection_info, mount_device)
+ connection_info = vol_driver.terminate_connection(vol, self.connr)
+
def test_libvirt_lxc_volume(self):
self.stubs.Set(os.path, 'exists', lambda x: True)
vol_driver = volume_driver.ISCSIDriver()
diff --git a/nova/virt/libvirt/volume.py b/nova/virt/libvirt/volume.py
index cf08ea85e..2a018c724 100644
--- a/nova/virt/libvirt/volume.py
+++ b/nova/virt/libvirt/volume.py
@@ -87,10 +87,19 @@ class LibvirtNetVolumeDriver(LibvirtVolumeDriver):
conf.target_bus = "virtio"
conf.serial = connection_info.get('serial')
netdisk_properties = connection_info['data']
- if netdisk_properties.get('auth_enabled'):
- conf.auth_username = netdisk_properties['auth_username']
+ auth_enabled = netdisk_properties.get('auth_enabled')
+ if (conf.source_protocol == 'rbd' and
+ FLAGS.rbd_secret_uuid):
+ conf.auth_secret_uuid = FLAGS.rbd_secret_uuid
+ auth_enabled = True # Force authentication locally
+ if FLAGS.rbd_user:
+ conf.auth_username = FLAGS.rbd_user
+ if auth_enabled:
+ conf.auth_username = (conf.auth_username or
+ netdisk_properties['auth_username'])
conf.auth_secret_type = netdisk_properties['secret_type']
- conf.auth_secret_uuid = netdisk_properties['secret_uuid']
+ conf.auth_secret_uuid = (conf.auth_secret_uuid or
+ netdisk_properties['secret_uuid'])
return conf