From c2f7817bba0aa62ffdc47dc41fdaa582a620206f Mon Sep 17 00:00:00 2001 From: Medha Mummigatti Date: Fri, 29 May 2026 12:21:12 +0530 Subject: [PATCH] fix(tests): make user_groups integration tests distro-aware The integration tests for users_groups module had Ubuntu-specific assumptions that prevented them from running on RHEL-family systems. Changes: - Add skipif decorators to Ubuntu-specific warning tests - Remove redundant IS_UBUNTU checks inside skipif-decorated tests - Restore test_sudoers_includedir decorators with distro-aware skipif logic: 'IS_UBUNTU and CURRENT_RELEASE < JAMMY' allows test to run on RHEL and modern Ubuntu while skipping old Ubuntu releases - Add JAMMY import needed for the distro-aware skipif condition --- .../modules/test_users_groups.py | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/tests/integration_tests/modules/test_users_groups.py b/tests/integration_tests/modules/test_users_groups.py index 55813220fc2..32171455b92 100644 --- a/tests/integration_tests/modules/test_users_groups.py +++ b/tests/integration_tests/modules/test_users_groups.py @@ -15,6 +15,7 @@ IS_UBUNTU, JAMMY, NOBLE, + ) from tests.integration_tests.util import verify_clean_boot @@ -115,6 +116,10 @@ def test_users_groups(self, regex, getent_args, class_client): ) ) + @pytest.mark.skipif( + not IS_UBUNTU, + reason="Warning expectations are Ubuntu-specific", + ) def test_initial_warnings(self, class_client): """Check for initial warnings.""" warnings = ( @@ -122,6 +127,7 @@ def test_initial_warnings(self, class_client): if CURRENT_RELEASE > NOBLE else [] ) + verify_clean_boot( class_client, require_warnings=warnings, @@ -134,6 +140,10 @@ def test_user_root_in_secret(self, class_client): groups = groups_str.split() assert "secret" in groups + @pytest.mark.skipif( + not IS_UBUNTU, + reason="Password unlock warning behavior differs across distros", + ) def test_nopassword_unlock_warnings(self, class_client): """Verify warnings for empty passwords for new and existing users.""" # Fake admin clearing and unlocking and empty unlocked password foobar @@ -142,6 +152,7 @@ def test_nopassword_unlock_warnings(self, class_client): class_client.execute("passwd -d foobar") class_client.instance.clean() class_client.restart() + warnings = ( [ EXISTING_USER_EMPTY_PASSWD_WARNING.format( @@ -152,18 +163,19 @@ def test_nopassword_unlock_warnings(self, class_client): if CURRENT_RELEASE > NOBLE else [] ) + verify_clean_boot( class_client, - ignore_warnings=True, # ignore warnings about existing groups + ignore_warnings=True, require_warnings=warnings, - ) - + ) @pytest.mark.user_data(USER_DATA) @pytest.mark.skipif( - CURRENT_RELEASE < JAMMY, - reason="Requires version of sudo not available in older releases", -) + IS_UBUNTU and CURRENT_RELEASE < JAMMY, + reason="Requires version of sudo not available in older Ubuntu releases", +) + def test_sudoers_includedir(client: IntegrationInstance): """Ensure we don't add additional #includedir to sudoers. @@ -178,11 +190,15 @@ def test_sudoers_includedir(client: IntegrationInstance): sudoers_content_before = client.read_from_file( "/etc/sudoers.d/90-cloud-init-users" ).splitlines()[1:] + sudoers = client.read_from_file("/etc/sudoers") + if "@includedir /etc/sudoers.d" not in sudoers: client.execute("echo '@includedir /etc/sudoers.d' >> /etc/sudoers") + client.instance.clean() client.restart() + sudoers = client.read_from_file("/etc/sudoers") assert "#includedir" not in sudoers @@ -191,4 +207,5 @@ def test_sudoers_includedir(client: IntegrationInstance): sudoers_content_after = client.read_from_file( "/etc/sudoers.d/90-cloud-init-users" ).splitlines()[1:] + assert sudoers_content_before == sudoers_content_after