mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-26 04:43:09 +03:00
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 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");
|
||||
}
|
||||
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
};
|
||||
'';
|
||||
|
@ -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");
|
||||
'';
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ in
|
||||
services.httpd.enable = true;
|
||||
services.httpd.adminAddr = "e.dolstra@tudelft.nl";
|
||||
services.httpd.extraSubservices =
|
||||
[ { serviceType = "subversion";
|
||||
[ { function = import <services/subversion>;
|
||||
urlPrefix = "";
|
||||
dataDir = "/data/subversion";
|
||||
userCreationDomain = "192.168.0.0/16";
|
||||
|
Loading…
Reference in New Issue
Block a user