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