forked from mirrors/nixpkgs
Update some tests for systemd
This commit is contained in:
parent
02624758b1
commit
13a5ebad32
|
@ -352,18 +352,39 @@ sub mustFail {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Wait for an Upstart job to reach the "running" state.
|
sub getUnitInfo {
|
||||||
sub waitForJob {
|
my ($self, $unit) = @_;
|
||||||
my ($self, $jobName) = @_;
|
my ($status, $lines) = $self->execute("systemctl --no-pager show '$unit'");
|
||||||
$self->nest("waiting for job ‘$jobName’", sub {
|
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 {
|
retry sub {
|
||||||
my ($status, $out) = $self->execute("initctl status $jobName");
|
my $info = $self->getUnitInfo($unit);
|
||||||
return 1 if $out =~ /start\/running/;
|
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.
|
# Wait until the specified file exists.
|
||||||
sub waitForFile {
|
sub waitForFile {
|
||||||
my ($self, $fileName) = @_;
|
my ($self, $fileName) = @_;
|
||||||
|
@ -377,16 +398,13 @@ sub waitForFile {
|
||||||
|
|
||||||
sub startJob {
|
sub startJob {
|
||||||
my ($self, $jobName) = @_;
|
my ($self, $jobName) = @_;
|
||||||
$self->execute("initctl start $jobName");
|
$self->execute("systemctl stop $jobName.service");
|
||||||
my ($status, $out) = $self->execute("initctl status $jobName");
|
# FIXME: check result
|
||||||
die "failed to start $jobName" unless $out =~ /start\/running/;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub stopJob {
|
sub stopJob {
|
||||||
my ($self, $jobName) = @_;
|
my ($self, $jobName) = @_;
|
||||||
$self->execute("initctl stop $jobName");
|
$self->execute("systemctl stop $jobName.service");
|
||||||
my ($status, $out) = $self->execute("initctl status $jobName");
|
|
||||||
die "failed to stop $jobName" unless $out =~ /stop\/waiting/;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,23 @@
|
||||||
|
|
||||||
testScript =
|
testScript =
|
||||||
''
|
''
|
||||||
|
$machine->waitForUnit("default.target");
|
||||||
|
$machine->screenshot("postboot");
|
||||||
|
|
||||||
subtest "create user", sub {
|
subtest "create user", sub {
|
||||||
$machine->succeed("useradd -m alice");
|
$machine->succeed("useradd -m alice");
|
||||||
$machine->succeed("(echo foobar; echo foobar) | passwd 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.
|
# Log in as alice on a virtual console.
|
||||||
subtest "virtual console login", sub {
|
subtest "virtual console login", sub {
|
||||||
$machine->waitForJob("tty1");
|
|
||||||
$machine->sleep(2); # urgh: wait for username prompt
|
$machine->sleep(2); # urgh: wait for username prompt
|
||||||
$machine->sendChars("alice\n");
|
$machine->sendChars("alice\n");
|
||||||
$machine->waitUntilSucceeds("pgrep login");
|
$machine->waitUntilSucceeds("pgrep login");
|
||||||
|
@ -24,28 +33,19 @@
|
||||||
$machine->waitForFile("/home/alice/done");
|
$machine->waitForFile("/home/alice/done");
|
||||||
};
|
};
|
||||||
|
|
||||||
# Check whether switching VTs works.
|
# Check whether systemd gives and removes device ownership as
|
||||||
subtest "virtual console switching", sub {
|
# needed.
|
||||||
$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.
|
|
||||||
subtest "device permissions", sub {
|
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->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->succeed("chvt 2");
|
||||||
$machine->sleep(2); # urgh
|
$machine->waitUntilSucceeds("getfacl /dev/snd/timer | grep -q alice");
|
||||||
$machine->fail("getfacl /dev/snd/timer | grep -q alice");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
# Log out.
|
# Log out.
|
||||||
subtest "virtual console logout", sub {
|
subtest "virtual console logout", sub {
|
||||||
$machine->succeed("chvt 1");
|
|
||||||
$machine->sendChars("exit\n");
|
$machine->sendChars("exit\n");
|
||||||
$machine->waitUntilFails("pgrep -u alice bash");
|
$machine->waitUntilFails("pgrep -u alice bash");
|
||||||
$machine->screenshot("mingetty");
|
$machine->screenshot("mingetty");
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
# Test that the swap file got created.
|
# Test that the swap file got created.
|
||||||
subtest "swapfile", sub {
|
subtest "swapfile", sub {
|
||||||
$machine->waitUntilSucceeds("cat /proc/swaps | grep /root/swapfile");
|
$machine->waitForUnit("root-swapfile.swap");
|
||||||
$machine->succeed("ls -l /root/swapfile | grep 134217728");
|
$machine->succeed("ls -l /root/swapfile | grep 134217728");
|
||||||
};
|
};
|
||||||
'';
|
'';
|
||||||
|
|
|
@ -30,6 +30,6 @@
|
||||||
$client->mustSucceed("chmod 600 /root/.ssh/id_dsa");
|
$client->mustSucceed("chmod 600 /root/.ssh/id_dsa");
|
||||||
|
|
||||||
$client->waitForJob("network-interfaces");
|
$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");
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ in
|
||||||
services.httpd.enable = true;
|
services.httpd.enable = true;
|
||||||
services.httpd.adminAddr = "e.dolstra@tudelft.nl";
|
services.httpd.adminAddr = "e.dolstra@tudelft.nl";
|
||||||
services.httpd.extraSubservices =
|
services.httpd.extraSubservices =
|
||||||
[ { serviceType = "subversion";
|
[ { function = import <services/subversion>;
|
||||||
urlPrefix = "";
|
urlPrefix = "";
|
||||||
dataDir = "/data/subversion";
|
dataDir = "/data/subversion";
|
||||||
userCreationDomain = "192.168.0.0/16";
|
userCreationDomain = "192.168.0.0/16";
|
||||||
|
|
Loading…
Reference in a new issue