summaryrefslogtreecommitdiffstats
path: root/meta-openstack/recipes-devtools/python/python-nova/Fix-rbd-backend-not-working-for-none-admin-ceph-user.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta-openstack/recipes-devtools/python/python-nova/Fix-rbd-backend-not-working-for-none-admin-ceph-user.patch')
-rw-r--r--meta-openstack/recipes-devtools/python/python-nova/Fix-rbd-backend-not-working-for-none-admin-ceph-user.patch130
1 files changed, 0 insertions, 130 deletions
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
deleted file mode 100644
index c5fbbbb..0000000
--- a/meta-openstack/recipes-devtools/python/python-nova/Fix-rbd-backend-not-working-for-none-admin-ceph-user.patch
+++ /dev/null
@@ -1,130 +0,0 @@
1Fix rbd backend not working for none admin ceph user
2
3commit 7104a6d8b1885f04d3012d621ec14f4be5145994 from
4https://github.com/openstack/nova
5
6The 'rbd_user' option allows nova administrators to override the default user
7account used for RBD operations, with one that has potentially lower
8privileges. Not all parts of the Nova code honoured the 'rbd_user' option,
9which resulted in failures when attempting to use a lesser privileged user for
10RBD. This fix ensures the '--id' and '--config' parameters are passed to the
11RBD command line tools in all cases.
12
13Change-Id: Id99aa303791143360ad78074184583048e4878f0
14Close-bug: 1255536
15
16Signed-off-by: Haomai Wang <haomai@unitedstack.com>
17[VT: Ported to Havana branch]
18Signed-off-by: Vu Tran <vu.tran@windriver.com>
19
20diff --git a/nova/tests/virt/libvirt/test_libvirt_utils.py b/nova/tests/virt/libvirt/test_libvirt_utils.py
21index ea83d3a..74f4a9e 100644
22--- a/nova/tests/virt/libvirt/test_libvirt_utils.py
23+++ b/nova/tests/virt/libvirt/test_libvirt_utils.py
24@@ -40,3 +40,44 @@ blah BLAH: bb
25 self.mox.ReplayAll()
26 disk_type = libvirt_utils.get_disk_type(path)
27 self.assertEqual(disk_type, 'raw')
28+
29+ def test_list_rbd_volumes(self):
30+ conf = '/etc/ceph/fake_ceph.conf'
31+ pool = 'fake_pool'
32+ user = 'user'
33+ self.flags(images_rbd_ceph_conf=conf, group='libvirt')
34+ self.flags(rbd_user=user, group='libvirt')
35+ fn = self.mox.CreateMockAnything()
36+ self.mox.StubOutWithMock(libvirt_utils.utils,
37+ 'execute')
38+ libvirt_utils.utils.execute('rbd', '-p', pool, 'ls', '--id',
39+ user,
40+ '--conf', conf).AndReturn(("Out", "Error"))
41+ self.mox.ReplayAll()
42+
43+ libvirt_utils.list_rbd_volumes(pool)
44+
45+ self.mox.VerifyAll()
46+
47+ def test_remove_rbd_volumes(self):
48+ conf = '/etc/ceph/fake_ceph.conf'
49+ pool = 'fake_pool'
50+ user = 'user'
51+ names = ['volume1', 'volume2', 'volume3']
52+ self.flags(images_rbd_ceph_conf=conf, group='libvirt')
53+ self.flags(rbd_user=user, group='libvirt')
54+ fn = self.mox.CreateMockAnything()
55+ libvirt_utils.utils.execute('rbd', '-p', pool, 'rm', 'volume1',
56+ '--id', user, '--conf', conf, attempts=3,
57+ run_as_root=True)
58+ libvirt_utils.utils.execute('rbd', '-p', pool, 'rm', 'volume2',
59+ '--id', user, '--conf', conf, attempts=3,
60+ run_as_root=True)
61+ libvirt_utils.utils.execute('rbd', '-p', pool, 'rm', 'volume3',
62+ '--id', user, '--conf', conf, attempts=3,
63+ run_as_root=True)
64+ self.mox.ReplayAll()
65+
66+ libvirt_utils.remove_rbd_volumes(pool, *names)
67+
68+ self.mox.VerifyAll()
69diff --git a/nova/virt/libvirt/imagebackend.py b/nova/virt/libvirt/imagebackend.py
70index 51872cf..89fe494 100644
71--- a/nova/virt/libvirt/imagebackend.py
72+++ b/nova/virt/libvirt/imagebackend.py
73@@ -460,8 +460,10 @@ class Rbd(Image):
74
75 def _ceph_args(self):
76 args = []
77- args.extend(['--id', CONF.rbd_user])
78- args.extend(['--conf', self.ceph_conf])
79+ if CONF.rbd_user:
80+ args.extend(['--id', CONF.rbd_user])
81+ if self.ceph_conf:
82+ args.extend(['--conf', self.ceph_conf])
83 return args
84
85 def _get_mon_addrs(self):
86diff --git a/nova/virt/libvirt/utils.py b/nova/virt/libvirt/utils.py
87index d7c92b7..db533e1 100644
88--- a/nova/virt/libvirt/utils.py
89+++ b/nova/virt/libvirt/utils.py
90@@ -262,12 +262,27 @@ def import_rbd_image(*args):
91 execute('rbd', 'import', *args)
92
93
94+def _run_rbd(*args, **kwargs):
95+ total = list(args)
96+
97+ if CONF.rbd_user:
98+ total.extend(['--id', str(CONF.rbd_user)])
99+ if CONF.libvirt_images_rbd_ceph_conf:
100+ total.extend(['--conf', str(CONF.libvirt_images_rbd_ceph_conf)])
101+
102+ return utils.execute(*total, **kwargs)
103+
104+
105 def list_rbd_volumes(pool):
106 """List volumes names for given ceph pool.
107
108 :param pool: ceph pool name
109 """
110- out, err = utils.execute('rbd', '-p', pool, 'ls')
111+ try:
112+ out, err = _run_rbd('rbd', '-p', pool, 'ls')
113+ except processutils.ProcessExecutionError:
114+ # No problem when no volume in rbd pool
115+ return []
116
117 return [line.strip() for line in out.splitlines()]
118
119@@ -275,9 +290,9 @@ def list_rbd_volumes(pool):
120 def remove_rbd_volumes(pool, *names):
121 """Remove one or more rbd volume."""
122 for name in names:
123- rbd_remove = ('rbd', '-p', pool, 'rm', name)
124+ rbd_remove = ['rbd', '-p', pool, 'rm', name]
125 try:
126- execute(*rbd_remove, attempts=3, run_as_root=True)
127+ _run_rbd(*rbd_remove, attempts=3, run_as_root=True)
128 except processutils.ProcessExecutionError:
129 LOG.warn(_("rbd remove %(name)s in pool %(pool)s failed"),
130 {'name': name, 'pool': pool})