-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 lxc plugin options #7369
Fix lxc plugin options #7369
Conversation
Add a fixture to allow testing the lxc connection plugin both with and without liblxc being present. Also change the test from unittest to pytest.
The error is not specific to python2, so remove the version. Also add a test for it.
Because the lxc plugin was only using PlayContext properties, using host vars like `ansible_lxc_host` didn't work. This is fixed by instead using the `get_option` method inherited from `AnsiblePlugin`. The options are not yet available in the `__init__` function, so the determination of the container name is moved to the `_connect` method, which is the first time it is actually needed. The default for the `remote_addr` option is removed, because the string `inventory_hostname` is not very useful. At all. This seams to have been spread with copy&paste and a bit of cargo culting. The variable priority already takes care of setting the value.
`TypeError: super() takes at least 1 argument (0 given)`
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!
raise errors.AnsibleError(msg) | ||
|
||
if self.container: | ||
return | ||
|
||
self.container_name = self.get_option('remote_addr') |
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.
Since the container can change from task to task, the check if self.container
above should probably also check whether self.get_option('remote_addr')
didn't change. But that's something that shouldn't happen in this PR, since it changes the behavior of the plugin (which so far also ignored this).
This partially reverts commit 429d8c8.
Backport to stable-6: 💚 backport PR created✅ Backport PR branch: Backported as #7370 🤖 @patchback |
* Fixture for liblxc Add a fixture to allow testing the lxc connection plugin both with and without liblxc being present. Also change the test from unittest to pytest. * Update liblxc error message The error is not specific to python2, so remove the version. Also add a test for it. * Migrate to options Because the lxc plugin was only using PlayContext properties, using host vars like `ansible_lxc_host` didn't work. This is fixed by instead using the `get_option` method inherited from `AnsiblePlugin`. The options are not yet available in the `__init__` function, so the determination of the container name is moved to the `_connect` method, which is the first time it is actually needed. The default for the `remote_addr` option is removed, because the string `inventory_hostname` is not very useful. At all. This seams to have been spread with copy&paste and a bit of cargo culting. The variable priority already takes care of setting the value. * Add changelog fragment * Fix for Py2.7 `TypeError: super() takes at least 1 argument (0 given)` * Add plugin type to changelog fragment. * Restore untemplated default This partially reverts commit 429d8c8. --------- Co-authored-by: Felix Fontein <[email protected]> (cherry picked from commit 1bf5a44)
@corubba thanks for your contribution! |
Backport to stable-7: 💚 backport PR created✅ Backport PR branch: Backported as #7371 🤖 @patchback |
* Fixture for liblxc Add a fixture to allow testing the lxc connection plugin both with and without liblxc being present. Also change the test from unittest to pytest. * Update liblxc error message The error is not specific to python2, so remove the version. Also add a test for it. * Migrate to options Because the lxc plugin was only using PlayContext properties, using host vars like `ansible_lxc_host` didn't work. This is fixed by instead using the `get_option` method inherited from `AnsiblePlugin`. The options are not yet available in the `__init__` function, so the determination of the container name is moved to the `_connect` method, which is the first time it is actually needed. The default for the `remote_addr` option is removed, because the string `inventory_hostname` is not very useful. At all. This seams to have been spread with copy&paste and a bit of cargo culting. The variable priority already takes care of setting the value. * Add changelog fragment * Fix for Py2.7 `TypeError: super() takes at least 1 argument (0 given)` * Add plugin type to changelog fragment. * Restore untemplated default This partially reverts commit 429d8c8. --------- Co-authored-by: Felix Fontein <[email protected]> (cherry picked from commit 1bf5a44)
Fix lxc plugin options (#7369) * Fixture for liblxc Add a fixture to allow testing the lxc connection plugin both with and without liblxc being present. Also change the test from unittest to pytest. * Update liblxc error message The error is not specific to python2, so remove the version. Also add a test for it. * Migrate to options Because the lxc plugin was only using PlayContext properties, using host vars like `ansible_lxc_host` didn't work. This is fixed by instead using the `get_option` method inherited from `AnsiblePlugin`. The options are not yet available in the `__init__` function, so the determination of the container name is moved to the `_connect` method, which is the first time it is actually needed. The default for the `remote_addr` option is removed, because the string `inventory_hostname` is not very useful. At all. This seams to have been spread with copy&paste and a bit of cargo culting. The variable priority already takes care of setting the value. * Add changelog fragment * Fix for Py2.7 `TypeError: super() takes at least 1 argument (0 given)` * Add plugin type to changelog fragment. * Restore untemplated default This partially reverts commit 429d8c8. --------- Co-authored-by: Felix Fontein <[email protected]> (cherry picked from commit 1bf5a44) Co-authored-by: Corubba <[email protected]>
Fix lxc plugin options (#7369) * Fixture for liblxc Add a fixture to allow testing the lxc connection plugin both with and without liblxc being present. Also change the test from unittest to pytest. * Update liblxc error message The error is not specific to python2, so remove the version. Also add a test for it. * Migrate to options Because the lxc plugin was only using PlayContext properties, using host vars like `ansible_lxc_host` didn't work. This is fixed by instead using the `get_option` method inherited from `AnsiblePlugin`. The options are not yet available in the `__init__` function, so the determination of the container name is moved to the `_connect` method, which is the first time it is actually needed. The default for the `remote_addr` option is removed, because the string `inventory_hostname` is not very useful. At all. This seams to have been spread with copy&paste and a bit of cargo culting. The variable priority already takes care of setting the value. * Add changelog fragment * Fix for Py2.7 `TypeError: super() takes at least 1 argument (0 given)` * Add plugin type to changelog fragment. * Restore untemplated default This partially reverts commit 429d8c8. --------- Co-authored-by: Felix Fontein <[email protected]> (cherry picked from commit 1bf5a44) Co-authored-by: Corubba <[email protected]>
* Fixture for liblxc Add a fixture to allow testing the lxc connection plugin both with and without liblxc being present. Also change the test from unittest to pytest. * Update liblxc error message The error is not specific to python2, so remove the version. Also add a test for it. * Migrate to options Because the lxc plugin was only using PlayContext properties, using host vars like `ansible_lxc_host` didn't work. This is fixed by instead using the `get_option` method inherited from `AnsiblePlugin`. The options are not yet available in the `__init__` function, so the determination of the container name is moved to the `_connect` method, which is the first time it is actually needed. The default for the `remote_addr` option is removed, because the string `inventory_hostname` is not very useful. At all. This seams to have been spread with copy&paste and a bit of cargo culting. The variable priority already takes care of setting the value. * Add changelog fragment * Fix for Py2.7 `TypeError: super() takes at least 1 argument (0 given)` * Add plugin type to changelog fragment. * Restore untemplated default This partially reverts commit 429d8c8. --------- Co-authored-by: Felix Fontein <[email protected]>
SUMMARY
Because the lxc plugin was only using
PlayContext
properties, using host vars likeansible_lxc_host
didn't work. This is fixed by instead using theget_option
method inherited fromAnsiblePlugin
. The options are not yet available in the__init__
function, so the determination of the container name is moved to the_connect
method, which is the first time it is actually needed. The default for theremote_addr
option is removed, because the stringinventory_hostname
is not very useful. At all. This seams to have been spread with copy&paste and a bit of cargo culting. The variable priority already takes care of setting the value.Add a fixture to allow testing the lxc connection plugin both with and without liblxc being present. Also change the test from unittest to pytest, and add more tests.
ISSUE TYPE
COMPONENT NAME
lxc
ADDITIONAL INFORMATION