Use lvs instead of os.listdir in _cleanup_lvm
Compute user may not have permission to list /dev/<VolGroup> directory. This results in error during instance cleanup and not deleted lvm images, if libvirt driver use lvm images backend. To prevent this, _cleanup_lvm use lvs command instead of os.listdir. This fixes bug 1042710 Change-Id: I82ab4ca5ba3320f50c84e23839fcf6ed8f02be8c
This commit is contained in:
parent
06dec8ec1e
commit
08f172bb6c
@ -185,5 +185,8 @@ lvremove: CommandFilter, /sbin/lvremove, root
|
||||
# nova/virt/libvirt/utils.py:
|
||||
lvcreate: CommandFilter, /sbin/lvcreate, root
|
||||
|
||||
# nova/virt/libvirt/utils.py:
|
||||
lvs: CommandFilter, /sbin/lvs, root
|
||||
|
||||
# nova/virt/libvirt/utils.py:
|
||||
vgs: CommandFilter, /sbin/vgs, root
|
||||
|
@ -565,7 +565,9 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
def fullpath(name):
|
||||
return os.path.join(vg, name)
|
||||
|
||||
disk_names = filter(belongs_to_instance, os.listdir(vg))
|
||||
logical_volumes = libvirt_utils.list_logical_volumes(vg)
|
||||
|
||||
disk_names = filter(belongs_to_instance, logical_volumes)
|
||||
disks = map(fullpath, disk_names)
|
||||
return disks
|
||||
return []
|
||||
|
@ -138,6 +138,17 @@ def volume_group_free_space(vg):
|
||||
return int(out.strip())
|
||||
|
||||
|
||||
def list_logical_volumes(vg):
|
||||
"""List logical volumes paths for given volume group.
|
||||
|
||||
:param vg: volume group name
|
||||
"""
|
||||
out, err = execute('lvs', '--noheadings', '-o', 'lv_path', vg,
|
||||
run_as_root=True)
|
||||
|
||||
return [line.strip() for line in out.splitlines()]
|
||||
|
||||
|
||||
def remove_logical_volumes(*paths):
|
||||
"""Remove one or more logical volume."""
|
||||
if paths:
|
||||
|
Loading…
Reference in New Issue
Block a user