Adjust function to report correctly free space for multipath disks

The command host-disk-list was reporting free space wrongly for
multipath disks that have partitions added to nova-local
logical volume.

This happens when the device node path has a dash in it like in
'/dev/mapper/mpathc-part1'. A 'grep -w' command was used to verify
if the device node is a physical volume. The command 'grep -w'
searchs for whole word, but the dash is considered a word separator,
causing the device node '/dev/mapper/mpathc' to be matched with
'/dev/mapper/mpathc-part1', once 'grep -w' detects the word
'/dev/mapper/mpathc'.

To fix this, the command is changed to detect the device node as
a string with an extra space at the end, for instance,
'/dev/mapper/mpathc '.

As an example consider device_node='/dev/mapper/mpathc' and
the output of 'pvs' command below:
  PV                       VG      Fmt  Attr PSize    PFree
  /dev/mapper/mpatha-part5 cgts-vg lvm2 a--  <488.41g 251.59g
  /dev/mapper/mpathb       cgts-vg lvm2 a--   <20.00g <20.00g
  /dev/mapper/mpathc-part1 cgts-vg lvm2 a--   <15.00g <15.00g

The 'pvs | grep -w /dev/mapper/mpathc' will match the string
'/dev/mapper/mpathc-part1', but it should not.

The 'pvs | grep "/dev/mapper/mpathc "' will not match any
string in that output.

Test Plan:
    PASS: Install AIO-SX with multipath disks, add a new partition
          to a spare multipath disk using half of its capacity.
          Add this partition to nova-local logical volume group and
          run 'system host-disk-list controller-0'. The available_gib
          column should report the expected free space correctly.
    PASS: Install AIO-SX without multipath disks, add a new partition
          to a spare disk using half of its capacity.
          Add this partition to nova-local logical volume group and
          run 'system host-disk-list controller-0'. The available_gib
          column should report the expected free space correctly.

Closes-bug: 2007309
Signed-off-by: Felipe Sanches Zanoni <Felipe.SanchesZanoni@windriver.com>
Change-Id: If7636f39c0ff3d0858623d7ada8a391fd783ca32
This commit is contained in:
Felipe Sanches Zanoni 2023-02-14 11:39:14 -05:00
parent 6faf275d9e
commit b0eb83f6ac
1 changed files with 1 additions and 1 deletions

View File

@ -107,7 +107,7 @@ class DiskOperator(object):
LOG.debug("Format of disk node %s is not GPT." % device_node)
return 0
pvs_command = '{} {}'.format('pvs | grep -w ', device_node)
pvs_command = '{} "{} "'.format('pvs | grep', device_node)
pvs_process = subprocess.Popen(pvs_command, stdout=subprocess.PIPE,
shell=True, universal_newlines=True)
pvs_output = pvs_process.stdout.read()