mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
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.
This commit is contained in:
@@ -71,3 +71,16 @@ class TestLXCConnectionClass():
|
||||
|
||||
with pytest.raises(AnsibleError, match='lxc python bindings are not installed'):
|
||||
conn._connect()
|
||||
|
||||
def test_remote_addr_option(self):
|
||||
"""Test that the remote_addr option is used"""
|
||||
play_context = PlayContext()
|
||||
in_stream = StringIO()
|
||||
conn = connection_loader.get('lxc', play_context, in_stream)
|
||||
|
||||
container_name = 'my-container'
|
||||
conn.set_option('remote_addr', container_name)
|
||||
assert conn.get_option('remote_addr') == container_name
|
||||
|
||||
conn._connect()
|
||||
assert conn.container_name == container_name
|
||||
|
||||
Reference in New Issue
Block a user