From a849fe69911660b4035b06cd9beb9a5ebe62baf4 Mon Sep 17 00:00:00 2001 From: corubba Date: Sun, 8 Oct 2023 18:30:13 +0200 Subject: [PATCH] Update liblxc error message The error is not specific to python2, so remove the version. Also add a test for it. --- plugins/connection/lxc.py | 2 +- tests/unit/plugins/connection/test_lxc.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/connection/lxc.py b/plugins/connection/lxc.py index 7ad5807244..e24a71248c 100644 --- a/plugins/connection/lxc.py +++ b/plugins/connection/lxc.py @@ -68,7 +68,7 @@ class Connection(ConnectionBase): super(Connection, self)._connect() if not HAS_LIBLXC: - msg = "lxc bindings for python2 are not installed" + msg = "lxc python bindings are not installed" raise errors.AnsibleError(msg) if self.container: diff --git a/tests/unit/plugins/connection/test_lxc.py b/tests/unit/plugins/connection/test_lxc.py index e574d1d263..4d50df3a94 100644 --- a/tests/unit/plugins/connection/test_lxc.py +++ b/tests/unit/plugins/connection/test_lxc.py @@ -11,6 +11,7 @@ import sys from io import StringIO +from ansible.errors import AnsibleError from ansible.playbook.play_context import PlayContext from ansible.plugins.loader import connection_loader from ansible_collections.community.general.tests.unit.compat import mock @@ -60,3 +61,13 @@ class TestLXCConnectionClass(): conn = connection_loader.get('lxc', play_context, in_stream) assert conn assert isinstance(conn, lxc.Connection) + + @pytest.mark.parametrize('lxc', [False], indirect=True) + def test_lxc_connection_liblxc_error(self, lxc): + """Test that on connect an error is thrown if liblxc is not present.""" + play_context = PlayContext() + in_stream = StringIO() + conn = connection_loader.get('lxc', play_context, in_stream) + + with pytest.raises(AnsibleError, match='lxc python bindings are not installed'): + conn._connect()