From 3b5ec214c506a47cbd8abf7bd6557246980ddea5 Mon Sep 17 00:00:00 2001 From: Vu Tran Date: Tue, 18 Mar 2014 21:01:01 -0400 Subject: nova-compute: enable to use ceph Enable nova-compute to: * use cinder volume stored in a ceph pool as a block device * store glance image into a ceph pool. Also port 2 patches from https://github.com/openstack/nova branch master into Havana branch. Signed-off-by: Vu Tran --- ...kend-not-working-for-none-admin-ceph-user.patch | 130 +++++++++++++++++++++ ...-rbd.libvirt_info-parent-class-compatible.patch | 48 ++++++++ .../recipes-devtools/python/python-nova/nova.conf | 7 ++ 3 files changed, 185 insertions(+) create mode 100644 meta-openstack/recipes-devtools/python/python-nova/Fix-rbd-backend-not-working-for-none-admin-ceph-user.patch create mode 100644 meta-openstack/recipes-devtools/python/python-nova/Make-rbd.libvirt_info-parent-class-compatible.patch (limited to 'meta-openstack/recipes-devtools/python/python-nova') diff --git a/meta-openstack/recipes-devtools/python/python-nova/Fix-rbd-backend-not-working-for-none-admin-ceph-user.patch b/meta-openstack/recipes-devtools/python/python-nova/Fix-rbd-backend-not-working-for-none-admin-ceph-user.patch new file mode 100644 index 0000000..c5fbbbb --- /dev/null +++ b/meta-openstack/recipes-devtools/python/python-nova/Fix-rbd-backend-not-working-for-none-admin-ceph-user.patch @@ -0,0 +1,130 @@ +Fix rbd backend not working for none admin ceph user + +commit 7104a6d8b1885f04d3012d621ec14f4be5145994 from +https://github.com/openstack/nova + +The 'rbd_user' option allows nova administrators to override the default user +account used for RBD operations, with one that has potentially lower +privileges. Not all parts of the Nova code honoured the 'rbd_user' option, +which resulted in failures when attempting to use a lesser privileged user for +RBD. This fix ensures the '--id' and '--config' parameters are passed to the +RBD command line tools in all cases. + +Change-Id: Id99aa303791143360ad78074184583048e4878f0 +Close-bug: 1255536 + +Signed-off-by: Haomai Wang +[VT: Ported to Havana branch] +Signed-off-by: Vu Tran + +diff --git a/nova/tests/virt/libvirt/test_libvirt_utils.py b/nova/tests/virt/libvirt/test_libvirt_utils.py +index ea83d3a..74f4a9e 100644 +--- a/nova/tests/virt/libvirt/test_libvirt_utils.py ++++ b/nova/tests/virt/libvirt/test_libvirt_utils.py +@@ -40,3 +40,44 @@ blah BLAH: bb + self.mox.ReplayAll() + disk_type = libvirt_utils.get_disk_type(path) + self.assertEqual(disk_type, 'raw') ++ ++ def test_list_rbd_volumes(self): ++ conf = '/etc/ceph/fake_ceph.conf' ++ pool = 'fake_pool' ++ user = 'user' ++ self.flags(images_rbd_ceph_conf=conf, group='libvirt') ++ self.flags(rbd_user=user, group='libvirt') ++ fn = self.mox.CreateMockAnything() ++ self.mox.StubOutWithMock(libvirt_utils.utils, ++ 'execute') ++ libvirt_utils.utils.execute('rbd', '-p', pool, 'ls', '--id', ++ user, ++ '--conf', conf).AndReturn(("Out", "Error")) ++ self.mox.ReplayAll() ++ ++ libvirt_utils.list_rbd_volumes(pool) ++ ++ self.mox.VerifyAll() ++ ++ def test_remove_rbd_volumes(self): ++ conf = '/etc/ceph/fake_ceph.conf' ++ pool = 'fake_pool' ++ user = 'user' ++ names = ['volume1', 'volume2', 'volume3'] ++ self.flags(images_rbd_ceph_conf=conf, group='libvirt') ++ self.flags(rbd_user=user, group='libvirt') ++ fn = self.mox.CreateMockAnything() ++ libvirt_utils.utils.execute('rbd', '-p', pool, 'rm', 'volume1', ++ '--id', user, '--conf', conf, attempts=3, ++ run_as_root=True) ++ libvirt_utils.utils.execute('rbd', '-p', pool, 'rm', 'volume2', ++ '--id', user, '--conf', conf, attempts=3, ++ run_as_root=True) ++ libvirt_utils.utils.execute('rbd', '-p', pool, 'rm', 'volume3', ++ '--id', user, '--conf', conf, attempts=3, ++ run_as_root=True) ++ self.mox.ReplayAll() ++ ++ libvirt_utils.remove_rbd_volumes(pool, *names) ++ ++ self.mox.VerifyAll() +diff --git a/nova/virt/libvirt/imagebackend.py b/nova/virt/libvirt/imagebackend.py +index 51872cf..89fe494 100644 +--- a/nova/virt/libvirt/imagebackend.py ++++ b/nova/virt/libvirt/imagebackend.py +@@ -460,8 +460,10 @@ class Rbd(Image): + + def _ceph_args(self): + args = [] +- args.extend(['--id', CONF.rbd_user]) +- args.extend(['--conf', self.ceph_conf]) ++ if CONF.rbd_user: ++ args.extend(['--id', CONF.rbd_user]) ++ if self.ceph_conf: ++ args.extend(['--conf', self.ceph_conf]) + return args + + def _get_mon_addrs(self): +diff --git a/nova/virt/libvirt/utils.py b/nova/virt/libvirt/utils.py +index d7c92b7..db533e1 100644 +--- a/nova/virt/libvirt/utils.py ++++ b/nova/virt/libvirt/utils.py +@@ -262,12 +262,27 @@ def import_rbd_image(*args): + execute('rbd', 'import', *args) + + ++def _run_rbd(*args, **kwargs): ++ total = list(args) ++ ++ if CONF.rbd_user: ++ total.extend(['--id', str(CONF.rbd_user)]) ++ if CONF.libvirt_images_rbd_ceph_conf: ++ total.extend(['--conf', str(CONF.libvirt_images_rbd_ceph_conf)]) ++ ++ return utils.execute(*total, **kwargs) ++ ++ + def list_rbd_volumes(pool): + """List volumes names for given ceph pool. + + :param pool: ceph pool name + """ +- out, err = utils.execute('rbd', '-p', pool, 'ls') ++ try: ++ out, err = _run_rbd('rbd', '-p', pool, 'ls') ++ except processutils.ProcessExecutionError: ++ # No problem when no volume in rbd pool ++ return [] + + return [line.strip() for line in out.splitlines()] + +@@ -275,9 +290,9 @@ def list_rbd_volumes(pool): + def remove_rbd_volumes(pool, *names): + """Remove one or more rbd volume.""" + for name in names: +- rbd_remove = ('rbd', '-p', pool, 'rm', name) ++ rbd_remove = ['rbd', '-p', pool, 'rm', name] + try: +- execute(*rbd_remove, attempts=3, run_as_root=True) ++ _run_rbd(*rbd_remove, attempts=3, run_as_root=True) + except processutils.ProcessExecutionError: + LOG.warn(_("rbd remove %(name)s in pool %(pool)s failed"), + {'name': name, 'pool': pool}) diff --git a/meta-openstack/recipes-devtools/python/python-nova/Make-rbd.libvirt_info-parent-class-compatible.patch b/meta-openstack/recipes-devtools/python/python-nova/Make-rbd.libvirt_info-parent-class-compatible.patch new file mode 100644 index 0000000..542abf5 --- /dev/null +++ b/meta-openstack/recipes-devtools/python/python-nova/Make-rbd.libvirt_info-parent-class-compatible.patch @@ -0,0 +1,48 @@ +Make rbd.libvirt_info parent class compatible + +commit 7a34be0ec0cd0cb9555fe64ff6c486faae1ae91d from +https://github.com/openstack/nova + +Rbd.libvirt_info function definition misses hypervisor_version argument added in change: +https://review.openstack.org/32379 + +Closes-Bug: #1233188 +Change-Id: Ib68d743e783af0f6d82d2ba180869ee642e86050 + +diff --git a/nova/tests/virt/libvirt/test_imagebackend.py b/nova/tests/virt/libvirt/test_imagebackend.py +index 2455ec8..5bfa94d 100644 +--- a/nova/tests/virt/libvirt/test_imagebackend.py ++++ b/nova/tests/virt/libvirt/test_imagebackend.py +@@ -20,6 +20,8 @@ import os + import fixtures + from oslo.config import cfg + ++from inspect import getargspec ++ + from nova import exception + from nova.openstack.common import uuidutils + from nova import test +@@ -630,6 +632,10 @@ class RbdTestCase(_ImageTestCase, test.NoDBTestCase): + + self.assertEqual(fake_processutils.fake_execute_get_log(), []) + ++ def test_parent_compatible(self): ++ self.assertEqual(getargspec(imagebackend.Image.libvirt_info), ++ getargspec(self.image_class.libvirt_info)) ++ + + class BackendTestCase(test.NoDBTestCase): + INSTANCE = {'name': 'fake-instance', +diff --git a/nova/virt/libvirt/imagebackend.py b/nova/virt/libvirt/imagebackend.py +index e900789..51872cf 100644 +--- a/nova/virt/libvirt/imagebackend.py ++++ b/nova/virt/libvirt/imagebackend.py +@@ -482,7 +482,7 @@ class Rbd(Image): + return hosts, ports + + def libvirt_info(self, disk_bus, disk_dev, device_type, cache_mode, +- extra_specs): ++ extra_specs, hypervisor_version): + """Get `LibvirtConfigGuestDisk` filled for this image. + + :disk_dev: Disk bus device name diff --git a/meta-openstack/recipes-devtools/python/python-nova/nova.conf b/meta-openstack/recipes-devtools/python/python-nova/nova.conf index 84ef48b..8aaf41a 100644 --- a/meta-openstack/recipes-devtools/python/python-nova/nova.conf +++ b/meta-openstack/recipes-devtools/python/python-nova/nova.conf @@ -21,6 +21,7 @@ my_ip = %CONTROLLER_IP% glance_host = %CONTROLLER_IP% lock_path=/var/lock/nova/ state_path=/var/run/nova/ +libvirt_images_type = %LIBVIRT_IMAGES_TYPE% #VNC vnc_enabled = true @@ -61,3 +62,9 @@ instance_usage_audit_period=hour notify_on_state_change=vm_and_task_state notification_driver=nova.openstack.common.notifier.rpc_notifier notification_driver=ceilometer.compute.nova_notifier + +# nova-compute configuration for ceph +libvirt_images_rbd_pool=cinder-volumes +libvirt_images_rbd_ceph_conf=/etc/ceph/ceph.conf +rbd_user=cinder-volume +#rbd_secret_uuid= -- cgit v1.2.3-54-g00ecf