-
Notifications
You must be signed in to change notification settings - Fork 59
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
Add flag to prevent implicit removal of existing device/fs. #43
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ab7389d
Add flag to prevent implicit removal of existing device/fs.
dwlehman 4abed48
Don't crash when a pool contains no volumes.
dwlehman b3ee952
Fix key for partition pool class lookup.
dwlehman b47401d
Various test fixes
pcahyna 7682373
Don't unmount anything if only getting package list.
dwlehman 63ff3ba
More test fixes
pcahyna f9ce0dd
Don't raise safe_mode failures when packages_only is True.
dwlehman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,10 @@ | |
disklabel_type: | ||
description: | ||
- disklabel type string (eg: 'gpt') to use, overriding the built-in logic in blivet | ||
safe_mode: | ||
description: | ||
- boolean indicating that we should fail rather than implicitly/automatically | ||
removing devices or formatting | ||
|
||
author: | ||
- David Lehman ([email protected]) | ||
|
@@ -116,6 +120,8 @@ | |
|
||
use_partitions = None # create partitions on pool backing device disks? | ||
disklabel_type = None # user-specified disklabel type | ||
safe_mode = None # do not remove any existing devices or formatting | ||
packages_only = None # only set things up enough to get a list of required packages | ||
|
||
|
||
class BlivetAnsibleError(Exception): | ||
|
@@ -163,7 +169,6 @@ def _get_format(self): | |
label=self._volume['fs_label'], | ||
options=self._volume['fs_create_options']) | ||
if not fmt.supported or not fmt.formattable: | ||
# FAIL: fs type tools are not available | ||
raise BlivetAnsibleError("required tools for file system '%s' are missing" % self._volume['fs_type']) | ||
|
||
return fmt | ||
|
@@ -189,32 +194,35 @@ def _resize(self): | |
try: | ||
size = Size(self._volume['size']) | ||
except Exception: | ||
# FAIL: invalid size specification | ||
raise BlivetAnsibleError("invalid size specification for volume '%s': '%s'" % (self._volume['name'], self._volume['size'])) | ||
|
||
if size and self._device.resizable and self._device.size != size: | ||
if self._device.format.resizable: | ||
self._device.format.update_size_info() | ||
|
||
if not self._device.min_size <= size <= self._device.max_size: | ||
# FAIL: resize to specified size not possible | ||
raise BlivetAnsibleError("volume '%s' cannot be resized to '%s'" % (self._volume['name'], size)) | ||
|
||
try: | ||
self._blivet.resize_device(self._device, size) | ||
except ValueError as e: | ||
# FAIL: resize not possible | ||
raise BlivetAnsibleError("volume '%s' cannot be resized from %s to %s: %s" % (self._device.name, | ||
self._device.size, | ||
size, str(e))) | ||
|
||
def _reformat(self): | ||
""" Schedule actions as needed to ensure the volume is formatted as specified. """ | ||
global packages_only | ||
|
||
fmt = self._get_format() | ||
if self._device.format.type == fmt.type: | ||
return | ||
|
||
if self._device.format.status: | ||
if safe_mode and (self._device.format.type is not None or self._device.format.name != get_format(None).name) and \ | ||
not packages_only: | ||
raise BlivetAnsibleError("cannot remove existing formatting on volume '%s' in safe mode" % self._volume['name']) | ||
|
||
if self._device.format.status and not packages_only: | ||
self._device.format.teardown() | ||
self._blivet.format_device(self._device, fmt) | ||
|
||
|
@@ -255,6 +263,17 @@ def _get_device_id(self): | |
def _type_check(self): | ||
return self._device.is_disk | ||
|
||
def _look_up_device(self): | ||
super(BlivetDiskVolume, self)._look_up_device() | ||
if not self._get_device_id(): | ||
raise BlivetAnsibleError("no disks specified for volume '%s'" % self._volume['name']) | ||
elif not isinstance(self._volume['disks'], list): | ||
raise BlivetAnsibleError("volume disks must be specified as a list") | ||
|
||
if self._device is None: | ||
raise BlivetAnsibleError("unable to resolve disk specified for volume '%s' (%s)" % (self._volume['name'], self._volume['disks'])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this error meant that no disks from |
||
|
||
|
||
|
||
class BlivetPartitionVolume(BlivetVolume): | ||
def _type_check(self): | ||
|
@@ -273,21 +292,18 @@ def _create(self): | |
parent = self._blivet.devicetree.resolve_device(self._volume['pool']) | ||
|
||
if parent is None: | ||
# FAIL: failed to find pool | ||
raise BlivetAnsibleError("failed to find pool '%s' for volume '%s'" % (self._blivet_pool['name'], self._volume['name'])) | ||
|
||
size = Size("256 MiB") | ||
try: | ||
device = self._blivet.new_partition(parents=[parent], size=size, grow=True, fmt=self._get_format()) | ||
except Exception: | ||
# FAIL: failed to instantiate volume device | ||
raise BlivetAnsibleError("failed set up volume '%s'" % self._volume['name']) | ||
|
||
self._blivet.create_device(device) | ||
try: | ||
do_partitioning(self._blivet) | ||
except Exception: | ||
# FAIL: partition allocation failed: not enough space? | ||
raise BlivetAnsibleError("partition allocation failed for volume '%s'" % self._volume['name']) | ||
|
||
self._device = device | ||
|
@@ -303,18 +319,15 @@ def _create(self): | |
|
||
parent = self._blivet_pool._device | ||
if parent is None: | ||
# FAIL: failed to find pool | ||
raise BlivetAnsibleError("failed to find pool '%s' for volume '%s'" % (self._blivet_pool['name'], self._volume['name'])) | ||
|
||
try: | ||
size = Size(self._volume['size']) | ||
except Exception: | ||
# FAIL: invalid size specification | ||
raise BlivetAnsibleError("invalid size '%s' specified for volume '%s'" % (self._volume['size'], self._volume['name'])) | ||
|
||
fmt = self._get_format() | ||
if size > parent.free_space: | ||
# FAIL: volume size greater than pool free space | ||
raise BlivetAnsibleError("specified size for volume '%s' exceeds available space in pool '%s' (%s)" % (size, | ||
parent.name, | ||
parent.free_space)) | ||
|
@@ -323,7 +336,6 @@ def _create(self): | |
device = self._blivet.new_lv(name=self._volume['name'], | ||
parents=[parent], size=size, fmt=fmt) | ||
except Exception: | ||
# FAIL: failed to create volume | ||
raise BlivetAnsibleError("failed to set up volume '%s'" % self._volume['name']) | ||
|
||
self._blivet.create_device(device) | ||
|
@@ -391,8 +403,7 @@ def _type_check(self): # pylint: disable=no-self-use | |
def _look_up_disks(self): | ||
""" Look up the pool's disks in blivet's device tree. """ | ||
if not self._pool['disks']: | ||
# FAIL: no disks specified for pool | ||
raise BlivetAnsibleError("no disks specified for pool '%s'" % self._pool['name']) # sure about this one? | ||
raise BlivetAnsibleError("no disks specified for pool '%s'" % self._pool['name']) | ||
elif not isinstance(self._pool['disks'], list): | ||
raise BlivetAnsibleError("pool disks must be specified as a list") | ||
|
||
|
@@ -403,7 +414,6 @@ def _look_up_disks(self): | |
disks.append(device) | ||
|
||
if self._pool['disks'] and not disks: | ||
# FAIL: failed to find any disks | ||
raise BlivetAnsibleError("unable to resolve any disks specified for pool '%s' (%s)" % (self._pool['name'], self._pool['disks'])) | ||
|
||
self._disks = disks | ||
|
@@ -428,8 +438,11 @@ def _create_members(self): | |
""" Schedule actions as needed to ensure pool member devices exist. """ | ||
members = list() | ||
for disk in self._disks: | ||
if not disk.isleaf: | ||
self._blivet.devicetree.recursive_remove(disk) | ||
if not disk.isleaf or disk.format.type is not None: | ||
if safe_mode and not packages_only: | ||
raise BlivetAnsibleError("cannot remove existing formatting and/or devices on disk '%s' (pool '%s') in safe mode" % (disk.name, self._pool['name'])) | ||
else: | ||
self._blivet.devicetree.recursive_remove(disk) | ||
|
||
if use_partitions: | ||
label = get_format("disklabel", device=disk.path) | ||
|
@@ -446,7 +459,6 @@ def _create_members(self): | |
try: | ||
do_partitioning(self._blivet) | ||
except Exception: | ||
# FAIL: problem allocating partitions for pool backing devices | ||
raise BlivetAnsibleError("failed to allocation partitions for pool '%s'" % self._pool['name']) | ||
|
||
return members | ||
|
@@ -490,7 +502,11 @@ def _look_up_device(self): | |
def _create(self): | ||
if self._device.format.type != "disklabel" or \ | ||
self._device.format.label_type != disklabel_type: | ||
self._blivet.devicetree.recursive_remove(self._device, remove_device=False) | ||
if safe_mode and not packages_only: | ||
raise BlivetAnsibleError("cannot remove existing formatting and/or devices on disk '%s' " | ||
"(pool '%s') in safe mode" % (self._device.name, self._pool['name'])) | ||
else: | ||
self._blivet.devicetree.recursive_remove(self._device, remove_device=False) | ||
|
||
label = get_format("disklabel", device=self._device.path, label_type=disklabel_type) | ||
self._blivet.format_device(self._device, label) | ||
|
@@ -503,7 +519,6 @@ def _type_check(self): | |
def _get_format(self): | ||
fmt = get_format("lvmpv") | ||
if not fmt.supported or not fmt.formattable: | ||
# FAIL: lvm tools are not available | ||
raise BlivetAnsibleError("required tools for managing LVM are missing") | ||
|
||
return fmt | ||
|
@@ -516,15 +531,14 @@ def _create(self): | |
try: | ||
pool_device = self._blivet.new_vg(name=self._pool['name'], parents=members) | ||
except Exception: | ||
# FAIL: failed to instantiate pool device | ||
raise BlivetAnsibleError("failed to set up pool '%s'" % self._pool['name']) | ||
|
||
self._blivet.create_device(pool_device) | ||
self._device = pool_device | ||
|
||
|
||
_BLIVET_POOL_TYPES = { | ||
"disk": BlivetPartitionPool, | ||
"partition": BlivetPartitionPool, | ||
"lvm": BlivetLVMPool | ||
} | ||
|
||
|
@@ -660,6 +674,7 @@ def run_module(): | |
volumes=dict(type='list'), | ||
packages_only=dict(type='bool', required=False, default=False), | ||
disklabel_type=dict(type='str', required=False, default=None), | ||
safe_mode=dict(type='bool', required=False, default=True), | ||
use_partitions=dict(type='bool', required=False, default=True)) | ||
|
||
# seed the result dict in the object | ||
|
@@ -692,6 +707,12 @@ def run_module(): | |
global use_partitions | ||
use_partitions = module.params['use_partitions'] | ||
|
||
global safe_mode | ||
safe_mode = module.params['safe_mode'] | ||
|
||
global packages_only | ||
packages_only = module.params['packages_only'] | ||
|
||
b = Blivet() | ||
b.reset() | ||
fstab = FSTab(b) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
- hosts: all | ||
become: true | ||
vars: | ||
storage_safe_mode: false | ||
mount_location: '/opt/test1' | ||
|
||
tasks: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit does not seem to fit in this PR and it seems that the added functionality is not used or tested. Not sure what it is doing here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I can move this out.