Skip to contentSkip to conversation

PDU/xenuse: Support xenuse on machine not locked by current user

PATCH Superseded Ian Campbell 2 participants 4 messages Oct 21, 2013

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 PDU/xenuse: Support xenuse on machine not locked by current user

xenuse checks that whoever is trying to reboot a machine "owns" that machine via a locking mechanism. This is usually fine doesn't work well when one wants to book a machine out of the osstest pool for adhoc testing. In this case machine ownership is maintained by osstest ahd the machine remains locked to osstest as far as xenuse is concerned.

Therefore add a global configuration option and perhost override to override $USER (which xenuse obeys) to osstest.
---
v2: Use "local $ENV{USER}" which contrary to my previous experiments does actually work.

---
 Osstest/PDU/xenuse.pm |    8 ++++++++
 production-config     |    1 +
 2 files changed, 9 insertions(+)
Osstest/PDU/xenuse.pm +8 -0
index 73a542d..fd3a148 100644
@@ -44,7 +44,15 @@ sub pdu_power_state {
     my ($mo, $on) = @_;
     my $onoff= $on ? "on" : "off";
     my $xenuse= $c{XenUsePath} || "xenuse";
+    my $user= $c{XenUseUser} || undef;
+    $user= get_host_property($mo->{Host}, "XenUseUser", $user);
 
+    local $ENV{USER} = $ENV{USER};
+
+    if ($user) {
+	logm("XenUse overriding \$USER to $user");
+	$ENV{USER} = $user;
+    }
     system_checked($xenuse, "--$onoff", "$mo->{Host}{Name}");
 }
 
production-config +1 -0
index de9e55c..fb9d750 100644
@@ -75,6 +75,7 @@ TftpPxeGroup osstest
 TftpDiVersion 2013-09-23
 
 XenUsePath /usr/groups/xencore/systems/bin/xenuse
+XenUseUser osstest
 
 # We use the IP address because Citrix can't manage reliable nameservice
 #DebianMirrorHost debian.uk.xensource.com
Signature · 1 line
1.7.10.4
#1 lore raw

Ian Campbell writes ("[PATCH OSSTEST v2] PDU/xenuse: Support xenuse on machine not locked by current user"):

Quoted 5 lines

xenuse checks that whoever is trying to reboot a machine "owns" that machine via a locking mechanism. This is usually fine doesn't work well when one wants to book a machine out of the osstest pool for adhoc testing. In this case machine ownership is maintained by osstest ahd the machine remains locked to osstest as far as xenuse is concerned.

...

Osstest/PDU/xenuse.pm sub pdu_power_state { · line 48

Quoted 2 lines
Osstest/PDU/xenuse.pm +2 -0
+    my $user= $c{XenUseUser} || undef;
+    $user= get_host_property($mo->{Host}, "XenUseUser", $user);

I'm not sure what's wrong with:

    my $user= get_host_property($mo->{Host}, "XenUseUser",
                                $c{XenUseUser} || undef $user);

?

Quoted 1 line

+ local $ENV{USER} = $ENV{USER};

If USER isn't in the environment, this will set it to an empty value. If you use the suffix if, you don't get a { } which limits the scope of local:

( logm("XenUse overriding \$USER to $user"),
local $ENV{USER} = $user )
if $user;

perhaps.

Ian.

#2 lore raw

Ian Jackson writes ("Re: [PATCH OSSTEST v2] PDU/xenuse: Support xenuse on machine not locked by current user"):

Quoted 4 lines

I'm not sure what's wrong with:

    my $user= get_host_property($mo->{Host}, "XenUseUser",
                                $c{XenUseUser} || undef $user);
                                                ^^^^^^^^^^^^^^^
Quoted 2 lines

?

Well, apart from that spurious c&p error...

Ian.

#3 lore raw
In reply to Ian Jackson
Quoted 10 lines · Ian Jackson

Ian Campbell writes ("[PATCH OSSTEST v2] PDU/xenuse: Support xenuse on machine not locked by current user"):

Quoted 5 lines

xenuse checks that whoever is trying to reboot a machine "owns" that machine via a locking mechanism. This is usually fine doesn't work well when one wants to book a machine out of the osstest pool for adhoc testing. In this case machine ownership is maintained by osstest ahd the machine remains locked to osstest as far as xenuse is concerned.

...

Osstest/PDU/xenuse.pm sub pdu_power_state { · line 48

Quoted 2 lines
Osstest/PDU/xenuse.pm +2 -0
+    my $user= $c{XenUseUser} || undef;
+    $user= get_host_property($mo->{Host}, "XenUseUser", $user);
Quoted 6 lines

I'm not sure what's wrong with:

    my $user= get_host_property($mo->{Host}, "XenUseUser",
                                $c{XenUseUser} || undef $user);

?

I just don't think like a Perl programmer ;-)

Quoted 3 lines
Quoted 1 line

+ local $ENV{USER} = $ENV{USER};

If USER isn't in the environment, this will set it to an empty value.

Ah yes. I was trying to work around the fact that "local $ENV{USER}" by itself would clear any existing $USER but didn't think this through.

Quoted 8 lines

If you use the suffix if, you don't get a { } which limits the scope of local:

( logm("XenUse overriding \$USER to $user"),
local $ENV{USER} = $user )
if $user;

perhaps.

I was trying to avoid the double "if $user", this looks like it might work. I'll try it.

Ian.