diff options
author | Jörg Thalheim <Mic92@users.noreply.github.com> | 2018-01-04 09:40:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-04 09:40:41 +0100 |
commit | 814b38541f666febaa5d344eeb512f6ef8b68803 (patch) | |
tree | 4727505d96207140136072b53fd27dbebbb1455c /nixos | |
parent | 426c513c14c10feac6a6afb1a810f74d8a16ed6e (diff) | |
parent | e538e00404a7a79bde1465924a3f60f05648794e (diff) | |
download | nixlib-814b38541f666febaa5d344eeb512f6ef8b68803.tar nixlib-814b38541f666febaa5d344eeb512f6ef8b68803.tar.gz nixlib-814b38541f666febaa5d344eeb512f6ef8b68803.tar.bz2 nixlib-814b38541f666febaa5d344eeb512f6ef8b68803.tar.lz nixlib-814b38541f666febaa5d344eeb512f6ef8b68803.tar.xz nixlib-814b38541f666febaa5d344eeb512f6ef8b68803.tar.zst nixlib-814b38541f666febaa5d344eeb512f6ef8b68803.zip |
Merge pull request #32845 from Ma27/test-driver/allow-user-units
test-driver: support testing user units
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/lib/test-driver/Machine.pm | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/nixos/lib/test-driver/Machine.pm b/nixos/lib/test-driver/Machine.pm index a01c3c336a1b..78598b3efb4b 100644 --- a/nixos/lib/test-driver/Machine.pm +++ b/nixos/lib/test-driver/Machine.pm @@ -362,8 +362,8 @@ sub mustFail { sub getUnitInfo { - my ($self, $unit) = @_; - my ($status, $lines) = $self->execute("systemctl --no-pager show '$unit'"); + my ($self, $unit, $user) = @_; + my ($status, $lines) = $self->systemctl("--no-pager show \"$unit\"", $user); return undef if $status != 0; my $info = {}; foreach my $line (split '\n', $lines) { @@ -373,6 +373,16 @@ sub getUnitInfo { return $info; } +sub systemctl { + my ($self, $q, $user) = @_; + if ($user) { + $q =~ s/'/\\'/g; + return $self->execute("su -l $user -c \$'XDG_RUNTIME_DIR=/run/user/`id -u` systemctl --user $q'"); + } + + return $self->execute("systemctl $q"); +} + # Fail if the given systemd unit is not in the "active" state. sub requireActiveUnit { my ($self, $unit) = @_; @@ -387,16 +397,16 @@ sub requireActiveUnit { # Wait for a systemd unit to reach the "active" state. sub waitForUnit { - my ($self, $unit) = @_; + my ($self, $unit, $user) = @_; $self->nest("waiting for unit ‘$unit’", sub { retry sub { - my $info = $self->getUnitInfo($unit); + my $info = $self->getUnitInfo($unit, $user); my $state = $info->{ActiveState}; die "unit ‘$unit’ reached state ‘$state’\n" if $state eq "failed"; if ($state eq "inactive") { # If there are no pending jobs, then assume this unit # will never reach active state. - my ($status, $jobs) = $self->execute("systemctl list-jobs --full 2>&1"); + my ($status, $jobs) = $self->systemctl("list-jobs --full 2>&1", $user); if ($jobs =~ /No jobs/) { # FIXME: fragile # Handle the case where the unit may have started # between the previous getUnitInfo() and @@ -430,14 +440,14 @@ sub waitForFile { } sub startJob { - my ($self, $jobName) = @_; - $self->execute("systemctl start $jobName"); + my ($self, $jobName, $user) = @_; + $self->systemctl("start $jobName", $user); # FIXME: check result } sub stopJob { - my ($self, $jobName) = @_; - $self->execute("systemctl stop $jobName"); + my ($self, $jobName, $user) = @_; + $self->systemctl("stop $jobName", $user); } |