From adf2d4306a6886268ffb1a6e4c8fe7ef2fe683e3 Mon Sep 17 00:00:00 2001 From: Fergal Mc Carthy Date: Tue, 22 Sep 2015 16:39:48 -0400 Subject: [PATCH] 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 --- cinder/brick/local_dev/lvm.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cinder/brick/local_dev/lvm.py b/cinder/brick/local_dev/lvm.py index 67f8e1990..283f2cb92 100644 --- a/cinder/brick/local_dev/lvm.py +++ b/cinder/brick/local_dev/lvm.py @@ -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. -- 2.45.2