Refactor LVM LV name generation and extract unique name generator into helper (COMPOSER-2355) #1003
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is part of #926 which I'm slowly splitting into smaller, bite-sized PRs.
disk: refactor LVM Logical Volume name generation
The VolumeGroup.CreateLogicalVolume() function assumed that the given
name was a mountpoint and would automatically escape it, append 'lv',
and append numbers in case of collisions. This made it impossible to
use the helper function for LV creation with desired names.
Refactor the function and modify all the calls so that now it uses the
provided name without validating, escaping, or checking for collisions,
and generates a name from the payload's mountpoint when one is not
provided.
The CreateMountpoint() function's functionality is not affected.
disk: helper function for generating unique names
The new genUniqueString() function follows the logic used when
generating logical volume names, which was based on the same
functionality in blivet.
It will be used to generate unique logical volume names, labels, and
btrfs volume names.
disk: replace the lvm name generation with genUniqueString()
Replace the heart of the lvm name generator with the new function.
Update the vg.CreateMountpoint() test, because the old implementation
was off by one and would fail when '99' was available.