-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New module zpool #10146
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
New module zpool #10146
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
felixfontein
left a comment
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.
Thanks for your contribution! I've added some first comments below. Please note that you also need to add tests.
russoz
left a comment
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.
hi @tomhesse, thanks for your contribution.
There are some adjustments needed, but the general structure seems good.
You might want to consider using CmdRunner to run the commands. See https://docs.ansible.com/ansible/latest/collections/community/general/docsite/guide_cmdrunner.html for more details.
And if you use VarDict (see https://docs.ansible.com/ansible/latest/collections/community/general/docsite/guide_vardict.html for that one), the management of diff output is super straightforward.
Finally, please bear in mind that new modules are required to come with tests (either unit tests or integration tests - the latter is preferred, but the former is accepted).
This comment was marked as outdated.
This comment was marked as outdated.
| --- | ||
| zpool_single_disk_config: | ||
| - file: /tmp/disk0.img | ||
| loop: /dev/loop89 |
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.
FYI, on Alpine you can only use /dev/loop0 up to /dev/loop7. Anything else does not work. Might be best to skip Alpine for now as well...
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.
(You can run mknod -m660 /dev/loopX b 7 X to create /dev/loopX; if you do that in a loop for all devices not there yet, then it should work fine I guess...)
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.
I updated the module to allow usage of files I realized this is probably better that setting up loop devices. This is probably the more convenient way.
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.
hi @tomhesse, thanks for the updates so far, it is looking good.
I got a couple of few other comments here, but other than that is is looking good indeed. Cheers
plugins/modules/zpool.py
Outdated
| role=dict( | ||
| type='str', | ||
| choices=['log', 'cache', 'spare', 'dedup', 'special'], | ||
| required=False, |
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.
required=False is redundant in the arg_spec, please remove it here and in the other options as well
plugins/modules/zpool.py
Outdated
| - List of device paths to include in this vdev. | ||
| required: true | ||
| type: list | ||
| elements: str |
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.
These are paths, right? If they are always paths, then use:
| elements: str | |
| elements: path |
(and adjust accordingly in the arg spec down below)
plugins/modules/zpool.py
Outdated
| rc, stdout, stderr = ctx.run( | ||
| subcommand='create', | ||
| disable_new_features=self.disable_new_features, | ||
| force=self.force, | ||
| dry_run=self.module.check_mode, | ||
| pool_properties=self.pool_properties, | ||
| filesystem_properties=self.filesystem_properties, | ||
| mountpoint=self.mountpoint, | ||
| altroot=self.altroot, | ||
| temp_name=self.temp_name, | ||
| name=self.name, | ||
| vdevs=self.vdevs, | ||
| ) |
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.
CmdRunner receives the reference to the module => the arguments that are named and mapped straight into module parameters do not need to be passed in the run() call. I haven't verified thoroughly, but I think you could make this:
| rc, stdout, stderr = ctx.run( | |
| subcommand='create', | |
| disable_new_features=self.disable_new_features, | |
| force=self.force, | |
| dry_run=self.module.check_mode, | |
| pool_properties=self.pool_properties, | |
| filesystem_properties=self.filesystem_properties, | |
| mountpoint=self.mountpoint, | |
| altroot=self.altroot, | |
| temp_name=self.temp_name, | |
| name=self.name, | |
| vdevs=self.vdevs, | |
| ) | |
| rc, stdout, stderr = ctx.run(subcommand='create') |
Maybe some other additional parameters here needs declaring, but the majority there can be skipped. ;-)
| zpool_single_disk_config: | ||
| - /tmp/disk0.img | ||
|
|
||
| zpool_mirror_disk_config: | ||
| - /tmp/disk1.img | ||
| - /tmp/disk2.img | ||
|
|
||
| zpool_raidz_disk_config: | ||
| - /tmp/disk3.img | ||
| - /tmp/disk4.img | ||
|
|
||
| zpool_vdevs_disk_config: | ||
| vdev1: | ||
| - /tmp/disk5.img | ||
| vdev2: | ||
| - /tmp/disk6.img | ||
| vdev3: | ||
| - /tmp/disk7.img | ||
| - /tmp/disk8.img | ||
| vdev4: | ||
| - /tmp/disk9.img | ||
| - /tmp/disk10.img |
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.
As a good practice I would recommend you use remote_tmp_dir (see other integration tests, for example run git grep remote_tmp_dir tests/integration/targets/snap/) instead of /tmp.
|
This PR fixes #10123 |
russoz
left a comment
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.
LGTM! Thank you!
|
@tomhesse You have my sword, my friend. Thanks! |
* Add zpool module * Add botmeta * Use str.format instead of f-strings * Remove nonlocal usage * Add check to only pass ashift to zpool add * Extend ansible_spec and remove unnecessary validation * Apply suggestions and fix style * Fix indentation of yaml lists * Add method to normalize vdevs Fix role: none in vdevs * Use CmdRunner instead of run_command * Fix styling and documentation * Use str.format instead of f-strings * Make sure vdevs are only required when state is present * Add support for loop devices and normalize vdev type * Add integration tests * Add missing test dependencies for alpine and redhat * Skip integration tests on rhel10 until there there packages available * Use package module for better auto detection of package manager on rhel * Add copyright header * Skip tests on rhel and remove redhat install requirements * Ensure loop devices under /dev exist * Enable usage of files as pool devices * Remove disk setup * Use files as disks * Apply suggestions * Fix argument_spec
* Add zpool module * Add botmeta * Use str.format instead of f-strings * Remove nonlocal usage * Add check to only pass ashift to zpool add * Extend ansible_spec and remove unnecessary validation * Apply suggestions and fix style * Fix indentation of yaml lists * Add method to normalize vdevs Fix role: none in vdevs * Use CmdRunner instead of run_command * Fix styling and documentation * Use str.format instead of f-strings * Make sure vdevs are only required when state is present * Add support for loop devices and normalize vdev type * Add integration tests * Add missing test dependencies for alpine and redhat * Skip integration tests on rhel10 until there there packages available * Use package module for better auto detection of package manager on rhel * Add copyright header * Skip tests on rhel and remove redhat install requirements * Ensure loop devices under /dev exist * Enable usage of files as pool devices * Remove disk setup * Use files as disks * Apply suggestions * Fix argument_spec
|
Adding some feedback from #10771 and #10744, as Some users uses |
|
@SandiyosDev please check out #11020. |
SUMMARY
Create, destroy, and modify ZFS zpools and their vdev layouts, pool properties, and filesystem properties.
Closes #10123.
ISSUE TYPE
COMPONENT NAME
zpool
ADDITIONAL INFORMATION
If any changes are necessary, please let me know.