Setup LVM_SYSTEM_DIR earlier in LVM.__init()

When using a Cinder specific lvm.conf file, we need to setup the
LVM_SYSTEM_DIR setting in the LVM.LVM_CMD_PREFIX before issuing
any LVM commands to ensure that the correct lvm.conf is used.

The issue was uncovered when testing on a Cinder Volume host setup
as follows:
  * Cinder is configured to use an LVM backend, backed by the
    cinder-volumes VG, which already exists.
  * /etc/lvm/lvm.conf rejects all devices other than those on which
    the operating system is installed.
  * /etc/cinder/lvm.conf accepts only the devices backing the
    cinder-volumes LVM VG

The cinder-volume service would fail to initialise the specified LVM
backend because the cinder.brick.local_dev.lvm.LVM.__init__() call
checks for the existence of the specified VG before
    LVM_SYSTEM_DIR=/etc/cinder
has been added to the LVM.LVM_CMD_PREFIX, and thus fails to find the
VG, and raises an exception.

By moving the setup of the LVM_SYSTEM_DIR environment variable in
LVM.LVM_CMD_PREFIX to happen before any LVM commands are issued we
ensure that all subsequent LVM commands are run against the correct
lvm.conf file.

Change-Id: I6551b045ab48ee60c3ee4cd15c13058635c144c2
Closes-Bug: #1498480
This commit is contained in:
Fergal Mc Carthy 2015-09-22 16:39:48 -04:00
parent a882b6d2f3
commit adf2d4306a
1 changed files with 7 additions and 4 deletions

View File

@ -71,6 +71,13 @@ class LVM(executor.Executor):
self._supports_lvchange_ignoreskipactivation = None
self.vg_provisioned_capacity = 0.0
# Ensure LVM_SYSTEM_DIR has been added to LVM.LVM_CMD_PREFIX
# before the first LVM command is executed.
if lvm_conf and os.path.isfile(lvm_conf):
LVM.LVM_CMD_PREFIX = ['env',
'LC_ALL=C',
'LVM_SYSTEM_DIR=/etc/cinder']
if create_vg and physical_volumes is not None:
self.pv_list = physical_volumes
@ -104,10 +111,6 @@ class LVM(executor.Executor):
self.vg_thin_pool = pool_name
self.activate_lv(self.vg_thin_pool)
self.pv_list = self.get_all_physical_volumes(root_helper, vg_name)
if lvm_conf and os.path.isfile(lvm_conf):
LVM.LVM_CMD_PREFIX = ['env',
'LC_ALL=C',
'LVM_SYSTEM_DIR=/etc/cinder']
def _vg_exists(self):
"""Simple check to see if VG exists.