From 13a5ebad32b269e11feb2e039fad26f63b2d2679 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 4 Oct 2012 12:34:44 -0400 Subject: [PATCH] Update some tests for systemd --- lib/test-driver/Machine.pm | 42 +++++++++++++++++++++++++++----------- tests/login.nix | 32 ++++++++++++++--------------- tests/misc.nix | 2 +- tests/openssh.nix | 2 +- tests/subversion.nix | 2 +- 5 files changed, 49 insertions(+), 31 deletions(-) diff --git a/lib/test-driver/Machine.pm b/lib/test-driver/Machine.pm index 76c736b609d..c7e0bc102f1 100644 --- a/lib/test-driver/Machine.pm +++ b/lib/test-driver/Machine.pm @@ -352,18 +352,39 @@ sub mustFail { } -# Wait for an Upstart job to reach the "running" state. -sub waitForJob { - my ($self, $jobName) = @_; - $self->nest("waiting for job ‘$jobName’", sub { +sub getUnitInfo { + my ($self, $unit) = @_; + my ($status, $lines) = $self->execute("systemctl --no-pager show '$unit'"); + return undef if $status != 0; + my $info = {}; + foreach my $line (split '\n', $lines) { + $line =~ /^([^=]+)=(.*)$/ or next; + $info->{$1} = $2; + } + return $info; +} + + +# Wait for a systemd unit to reach the "active" state. +sub waitForUnit { + my ($self, $unit) = @_; + $self->nest("waiting for unit ‘$unit’", sub { retry sub { - my ($status, $out) = $self->execute("initctl status $jobName"); - return 1 if $out =~ /start\/running/; + my $info = $self->getUnitInfo($unit); + my $state = $info->{ActiveState}; + die "unit ‘$unit’ reached state ‘$state’\n" if $state eq "failed"; + return 1 if $state eq "active"; }; }); } +sub waitForJob { + my ($self, $jobName) = @_; + return $self->waitForUnit($jobName . ".service"); +} + + # Wait until the specified file exists. sub waitForFile { my ($self, $fileName) = @_; @@ -377,16 +398,13 @@ sub waitForFile { sub startJob { my ($self, $jobName) = @_; - $self->execute("initctl start $jobName"); - my ($status, $out) = $self->execute("initctl status $jobName"); - die "failed to start $jobName" unless $out =~ /start\/running/; + $self->execute("systemctl stop $jobName.service"); + # FIXME: check result } sub stopJob { my ($self, $jobName) = @_; - $self->execute("initctl stop $jobName"); - my ($status, $out) = $self->execute("initctl status $jobName"); - die "failed to stop $jobName" unless $out =~ /stop\/waiting/; + $self->execute("systemctl stop $jobName.service"); } diff --git a/tests/login.nix b/tests/login.nix index 90987782f8c..cdd6414744a 100644 --- a/tests/login.nix +++ b/tests/login.nix @@ -6,14 +6,23 @@ testScript = '' + $machine->waitForUnit("default.target"); + $machine->screenshot("postboot"); + subtest "create user", sub { $machine->succeed("useradd -m alice"); $machine->succeed("(echo foobar; echo foobar) | passwd alice"); }; + # Check whether switching VTs works. + subtest "virtual console switching", sub { + $machine->sendKeys("alt-f2"); + $machine->waitUntilSucceeds("[ \$(fgconsole) = 2 ]"); + $machine->waitForUnit('getty@tty2.service'); + }; + # Log in as alice on a virtual console. subtest "virtual console login", sub { - $machine->waitForJob("tty1"); $machine->sleep(2); # urgh: wait for username prompt $machine->sendChars("alice\n"); $machine->waitUntilSucceeds("pgrep login"); @@ -24,28 +33,19 @@ $machine->waitForFile("/home/alice/done"); }; - # Check whether switching VTs works. - subtest "virtual console switching", sub { - $machine->sendKeys("alt-f10"); - $machine->waitUntilSucceeds("[ \$(fgconsole) = 10 ]"); - $machine->sleep(2); # allow fbcondecor to catch up (not important) - $machine->screenshot("syslog"); - }; - - # Check whether ConsoleKit/udev gives and removes device - # ownership as needed. + # Check whether systemd gives and removes device ownership as + # needed. subtest "device permissions", sub { + $machine->succeed("getfacl /dev/snd/timer | grep -q alice"); + $machine->sendKeys("alt-f1"); + $machine->waitUntilSucceeds("[ \$(fgconsole) = 1 ]"); $machine->fail("getfacl /dev/snd/timer | grep -q alice"); - $machine->succeed("chvt 1"); - $machine->waitUntilSucceeds("getfacl /dev/snd/timer | grep -q alice"); $machine->succeed("chvt 2"); - $machine->sleep(2); # urgh - $machine->fail("getfacl /dev/snd/timer | grep -q alice"); + $machine->waitUntilSucceeds("getfacl /dev/snd/timer | grep -q alice"); }; # Log out. subtest "virtual console logout", sub { - $machine->succeed("chvt 1"); $machine->sendChars("exit\n"); $machine->waitUntilFails("pgrep -u alice bash"); $machine->screenshot("mingetty"); diff --git a/tests/misc.nix b/tests/misc.nix index 8501d6a0979..9f85877e8bb 100644 --- a/tests/misc.nix +++ b/tests/misc.nix @@ -30,7 +30,7 @@ # Test that the swap file got created. subtest "swapfile", sub { - $machine->waitUntilSucceeds("cat /proc/swaps | grep /root/swapfile"); + $machine->waitForUnit("root-swapfile.swap"); $machine->succeed("ls -l /root/swapfile | grep 134217728"); }; ''; diff --git a/tests/openssh.nix b/tests/openssh.nix index 5818c9d6ceb..7a3d789327a 100644 --- a/tests/openssh.nix +++ b/tests/openssh.nix @@ -30,6 +30,6 @@ $client->mustSucceed("chmod 600 /root/.ssh/id_dsa"); $client->waitForJob("network-interfaces"); - $client->mustSucceed("ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no server 'echo hello world'"); + $client->mustSucceed("ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no server 'echo hello world' >&2"); ''; } diff --git a/tests/subversion.nix b/tests/subversion.nix index fb8bba93806..dc4fe9da470 100644 --- a/tests/subversion.nix +++ b/tests/subversion.nix @@ -41,7 +41,7 @@ in services.httpd.enable = true; services.httpd.adminAddr = "e.dolstra@tudelft.nl"; services.httpd.extraSubservices = - [ { serviceType = "subversion"; + [ { function = import ; urlPrefix = ""; dataDir = "/data/subversion"; userCreationDomain = "192.168.0.0/16";