Skip to content

Commit 6bab2b1

Browse files
authored
Fix functional.states.test_user for SLES 16 and Micro systems
1 parent 4cdce68 commit 6bab2b1

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

tests/pytests/functional/states/test_user.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ def test_user_present_nondefault(grains, modules, states, username, user_home):
138138
if not salt.utils.platform.is_darwin() and not salt.utils.platform.is_windows():
139139
assert user_home.is_dir()
140140

141-
if grains["os_family"] in ("Suse",) and not grains.get("transactional", False):
141+
if grains["os_family"] == "Suse" and not (
142+
grains.get("transactional", False) or grains.get("osmajorrelease", 0) >= 16
143+
):
142144
expected_group_name = "users"
143145
elif grains["os_family"] == "MacOS":
144146
expected_group_name = "staff"
@@ -381,11 +383,15 @@ def test_user_present_existing(states, username):
381383

382384

383385
@pytest.mark.skip_unless_on_linux(reason="underlying functionality only runs on Linux")
384-
@pytest.mark.skipif(
385-
bool(salt.utils.path.which("transactional-update")),
386-
reason="Skipping on transactional systems",
387-
)
388-
def test_user_present_change_groups(modules, states, username, group_1, group_2):
386+
def test_user_present_change_groups(
387+
grains, modules, states, username, group_1, group_2
388+
):
389+
expected_groups = [group_2.name, group_1.name]
390+
if grains["os_family"] == "Suse" and (
391+
grains.get("transactional", False) or grains.get("osmajorrelease", 0) >= 16
392+
):
393+
expected_groups.append(username)
394+
389395
ret = states.user.present(
390396
name=username,
391397
groups=[group_1.name, group_2.name],
@@ -394,7 +400,9 @@ def test_user_present_change_groups(modules, states, username, group_1, group_2)
394400

395401
user_info = modules.user.info(username)
396402
assert user_info
397-
assert user_info["groups"] == [group_2.name, group_1.name]
403+
assert sorted(user_info["groups"]) == sorted(expected_groups)
404+
405+
expected_groups.remove(group_2.name)
398406

399407
# run again and remove group_2
400408
ret = states.user.present(
@@ -405,17 +413,19 @@ def test_user_present_change_groups(modules, states, username, group_1, group_2)
405413

406414
user_info = modules.user.info(username)
407415
assert user_info
408-
assert user_info["groups"] == [group_1.name]
416+
assert sorted(user_info["groups"]) == sorted(expected_groups)
409417

410418

411419
@pytest.mark.skip_unless_on_linux(reason="underlying functionality only runs on Linux")
412-
@pytest.mark.skipif(
413-
bool(salt.utils.path.which("transactional-update")),
414-
reason="Skipping on transactional systems",
415-
)
416420
def test_user_present_change_optional_groups(
417-
modules, states, username, group_1, group_2
421+
grains, modules, states, username, group_1, group_2
418422
):
423+
expected_groups = [group_2.name, group_1.name]
424+
if grains["os_family"] == "Suse" and (
425+
grains.get("transactional", False) or grains.get("osmajorrelease", 0) >= 16
426+
):
427+
expected_groups.append(username)
428+
419429
ret = states.user.present(
420430
name=username,
421431
optional_groups=[group_1.name, group_2.name],
@@ -424,7 +434,9 @@ def test_user_present_change_optional_groups(
424434

425435
user_info = modules.user.info(username)
426436
assert user_info
427-
assert user_info["groups"] == [group_2.name, group_1.name]
437+
assert sorted(user_info["groups"]) == sorted(expected_groups)
438+
439+
expected_groups.remove(group_2.name)
428440

429441
# run again and remove group_2
430442
ret = states.user.present(
@@ -435,7 +447,7 @@ def test_user_present_change_optional_groups(
435447

436448
user_info = modules.user.info(username)
437449
assert user_info
438-
assert user_info["groups"] == [group_1.name]
450+
assert sorted(user_info["groups"]) == sorted(expected_groups)
439451

440452

441453
@pytest.mark.skip_unless_on_linux(reason="underlying functionality only runs on Linux")

0 commit comments

Comments
 (0)