]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Setup LVM_SYSTEM_DIR earlier in LVM.__init()
authorFergal Mc Carthy <fergal.mccarthy@hpe.com>
Tue, 22 Sep 2015 20:39:48 +0000 (16:39 -0400)
committerFergal Mc Carthy <fergal.mccarthy@hpe.com>
Tue, 22 Sep 2015 20:39:48 +0000 (16:39 -0400)
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

index 67f8e19907f9376f5ca12245656a358a04ef897e..283f2cb92957609020565f49489fc27cb67125a1 100644 (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.