nixosTests.mutable-users: Port tests to python

This commit is contained in:
Christian Kampka 2019-12-15 19:53:17 +01:00
parent 58cd46ba21
commit c811e76d82
No known key found for this signature in database
GPG key ID: B88E140DB4FE1AA5

View file

@ -1,6 +1,6 @@
# Mutable users tests.
import ./make-test.nix ({ pkgs, ...} : {
import ./make-test-python.nix ({ pkgs, ...} : {
name = "mutable-users";
meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ gleber ];
@ -19,21 +19,27 @@ import ./make-test.nix ({ pkgs, ...} : {
immutableSystem = nodes.machine.config.system.build.toplevel;
mutableSystem = nodes.mutable.config.system.build.toplevel;
in ''
$machine->start();
$machine->waitForUnit("default.target");
machine.start()
machine.wait_for_unit("default.target")
# Machine starts in immutable mode. Add a user and test if reactivating
# configuration removes the user.
$machine->fail("cat /etc/passwd | grep ^foobar:");
$machine->succeed("sudo useradd foobar");
$machine->succeed("cat /etc/passwd | grep ^foobar:");
$machine->succeed("${immutableSystem}/bin/switch-to-configuration test");
$machine->fail("cat /etc/passwd | grep ^foobar:");
with subtest("Machine in immutable mode"):
assert "foobar" not in machine.succeed("cat /etc/passwd")
machine.succeed("sudo useradd foobar")
assert "foobar" in machine.succeed("cat /etc/passwd")
machine.succeed(
"${immutableSystem}/bin/switch-to-configuration test"
)
assert "foobar" not in machine.succeed("cat /etc/passwd")
# In immutable mode passwd is not wrapped, while in mutable mode it is
# wrapped.
$machine->succeed('which passwd | grep /run/current-system/');
$machine->succeed("${mutableSystem}/bin/switch-to-configuration test");
$machine->succeed('which passwd | grep /run/wrappers/');
with subtest("Password is wrapped in mutable mode"):
assert "/run/current-system/" in machine.succeed("which passwd")
machine.succeed(
"${mutableSystem}/bin/switch-to-configuration test"
)
assert "/run/wrappers/" in machine.succeed("which passwd")
'';
})