diff options
author | James Falcon <james.falcon@canonical.com> | 2021-10-29 15:39:29 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-29 15:39:29 -0500 |
commit | a90d8338f07b30a46887f7c133baade63129a53a (patch) | |
tree | f432b1911b81b3f83ae56175b83d3df61a5779cd /tests/unittests | |
parent | 0f8428f6227106c28615384d49a3e55e5c14dc17 (diff) | |
download | vyos-cloud-init-a90d8338f07b30a46887f7c133baade63129a53a.tar.gz vyos-cloud-init-a90d8338f07b30a46887f7c133baade63129a53a.zip |
Allow libexec for hotplug (#1088)
When we added the install hotplug module, we forgot to update the
redhet/cloud-init.spec.in file and allow for execution on /usr/libexec.
This PR adds that functionality.
Diffstat (limited to 'tests/unittests')
-rw-r--r-- | tests/unittests/test_handler/test_handler_install_hotplug.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/tests/unittests/test_handler/test_handler_install_hotplug.py b/tests/unittests/test_handler/test_handler_install_hotplug.py index 19b0cc41..5d6b1e77 100644 --- a/tests/unittests/test_handler/test_handler_install_hotplug.py +++ b/tests/unittests/test_handler/test_handler_install_hotplug.py @@ -7,7 +7,7 @@ import pytest from cloudinit.config.cc_install_hotplug import ( handle, HOTPLUG_UDEV_PATH, - HOTPLUG_UDEV_RULES, + HOTPLUG_UDEV_RULES_TEMPLATE, ) from cloudinit.event import EventScope, EventType @@ -38,7 +38,10 @@ def mocks(): class TestInstallHotplug: - def test_rules_installed_when_supported_and_enabled(self, mocks): + @pytest.mark.parametrize('libexec_exists', [True, False]) + def test_rules_installed_when_supported_and_enabled( + self, mocks, libexec_exists + ): mocks.m_which.return_value = 'udevadm' mocks.m_update_enabled.return_value = True m_cloud = mock.MagicMock() @@ -46,11 +49,17 @@ class TestInstallHotplug: EventScope.NETWORK: {EventType.HOTPLUG} } - handle(None, {}, m_cloud, mock.Mock(), None) - mocks.m_write.assert_called_once_with( - filename=HOTPLUG_UDEV_PATH, - content=HOTPLUG_UDEV_RULES, - ) + if libexec_exists: + libexecdir = "/usr/libexec/cloud-init" + else: + libexecdir = "/usr/lib/cloud-init" + with mock.patch('os.path.exists', return_value=libexec_exists): + handle(None, {}, m_cloud, mock.Mock(), None) + mocks.m_write.assert_called_once_with( + filename=HOTPLUG_UDEV_PATH, + content=HOTPLUG_UDEV_RULES_TEMPLATE.format( + libexecdir=libexecdir), + ) assert mocks.m_subp.call_args_list == [mock.call([ 'udevadm', 'control', '--reload-rules', ])] |