Merge "Fix rbd backend not working for none admin ceph user"
This commit is contained in:
commit
80efcae3a3
|
@ -53,3 +53,45 @@ blah BLAH: bb
|
|||
size = libvirt_utils.logical_volume_size('/dev/foo')
|
||||
self.assertEqual(expected_commands, executes)
|
||||
self.assertEqual(size, 123456789)
|
||||
|
||||
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()
|
||||
self.mox.StubOutWithMock(libvirt_utils.utils, 'execute')
|
||||
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()
|
||||
|
|
|
@ -508,8 +508,10 @@ class Rbd(Image):
|
|||
|
||||
def _ceph_args(self):
|
||||
args = []
|
||||
args.extend(['--id', self.rbd_user])
|
||||
args.extend(['--conf', self.ceph_conf])
|
||||
if self.rbd_user:
|
||||
args.extend(['--id', self.rbd_user])
|
||||
if self.ceph_conf:
|
||||
args.extend(['--conf', self.ceph_conf])
|
||||
return args
|
||||
|
||||
def _get_mon_addrs(self):
|
||||
|
|
|
@ -265,12 +265,27 @@ def import_rbd_image(*args):
|
|||
execute('rbd', 'import', *args)
|
||||
|
||||
|
||||
def _run_rbd(*args, **kwargs):
|
||||
total = list(args)
|
||||
|
||||
if CONF.libvirt.rbd_user:
|
||||
total.extend(['--id', str(CONF.libvirt.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()]
|
||||
|
||||
|
@ -278,9 +293,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})
|
||||
|
|
Loading…
Reference in New Issue