puppetlabs-lvm icon indicating copy to clipboard operation
puppetlabs-lvm copied to clipboard

Fix `undefined method '[]' for nil:NilClass` when creating filesystem…

Open tomsajan opened this issue 4 years ago • 3 comments

The filesystem resource of this module is useful for creating filesystems even outside of the LVM. When we want to create a filesystem on a partition not created by LVM, the filesystem resource fails with the following error:

Filesystem[/dev/sdb2]: Could not evaluate: undefined method `[]' for nil:NilClass

The current code only catches non zero return codes from blkid when checking on logical volumes. On LVM volumes with no filesystem, the blkid fails with return code 2 and that is catched and the function fstype returns nil

# blkid /dev/vg-nvme/test
# echo $?
2

But when we want to apply it to a partition that was not created by LVM that does not have filesystem yet, the blkid run succeeds, but the output is not as expected by this module. It misses the TYPE=" " part. Example: partition without FS

# blkid /dev/sdb3
/dev/sdb3: PARTUUID="1b29bbd9-03"

partition with fs

# blkid /dev/sdb2
/dev/sdb2: UUID="5d7aa665-26d6-455f-89b7-084628b88791" TYPE="ext4" PARTUUID="1b29bbd9-02"

When it happens, the pattern matching does not find the TYPE and the result is nil. Therefore it fails with the above mentioned error.

This PR introduces a fix that checks the value before trying to use the [1] indexing. If TYPE was not found, it returns nil, as before.

Thanks for the good work on the LVM module :)

tomsajan avatar May 28 '20 09:05 tomsajan

Those failed build doesn't seem to be related to the change I introduced....

tomsajan avatar May 28 '20 12:05 tomsajan

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Feb 24 '21 17:02 CLAassistant

Any update here ?

findmyname666 avatar Aug 11 '22 10:08 findmyname666