Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tomsajan
Copy link

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
Copy link
Author

tomsajan commented May 28, 2020

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

@CLAassistant
Copy link

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.

@findmyname666
Copy link

Any update here ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants