diff mbox

[Xen-devel,OSSTEST,v2,11/20] Osstest/PDU: Add eth008.pm method to control the ARM rack PDU

Message ID 1414579302-6692-11-git-send-email-ian.campbell@citrix.com
State New
Headers show

Commit Message

Ian Campbell Oct. 29, 2014, 10:41 a.m. UTC
This controls the eth008 relay board: http://www.robot-electronics.co.uk/htm/eth008tech.htm

Due to the use of the CGI interface this requires firmware version 4+.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
v2: Pass username and password via a netrc file.
---
 Osstest/PDU/eth008.pm | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
 create mode 100644 Osstest/PDU/eth008.pm

Comments

Ian Jackson Oct. 29, 2014, 4:27 p.m. UTC | #1
Ian Campbell writes ("[PATCH OSSTEST v2 11/20] Osstest/PDU: Add eth008.pm method to control the ARM rack PDU"):
> This controls the eth008 relay board: http://www.robot-electronics.co.uk/htm/eth008tech.htm
> 
> Due to the use of the CGI interface this requires firmware version 4+.
...
> +    # Create a netrc file to avoid putting l/p on command line
> +    my ($passfh, $passfilename) = tempfile( UNLINK => 1 );
> +    print $passfh "machine $mo->{PDU} login $mo->{User} password $mo->{Pass}\n";

Where does tempfile(UNLINK=>1) create its files and what deletes it if
the script crashes ?  It might be better to use something in tmp/
(presumably with the host name in the filename).  See for example
ts-host-install which uses tmp/t.<host>.initrd.

Or of course you could use LWP::UserAgent.

Ian.
Ian Campbell Oct. 29, 2014, 4:39 p.m. UTC | #2
On Wed, 2014-10-29 at 16:27 +0000, Ian Jackson wrote:
> Ian Campbell writes ("[PATCH OSSTEST v2 11/20] Osstest/PDU: Add eth008.pm method to control the ARM rack PDU"):
> > This controls the eth008 relay board: http://www.robot-electronics.co.uk/htm/eth008tech.htm
> > 
> > Due to the use of the CGI interface this requires firmware version 4+.
> ...
> > +    # Create a netrc file to avoid putting l/p on command line
> > +    my ($passfh, $passfilename) = tempfile( UNLINK => 1 );
> > +    print $passfh "machine $mo->{PDU} login $mo->{User} password $mo->{Pass}\n";
> 
> Where does tempfile(UNLINK=>1) create its files

I had assumed it was in /tmp (perhaps with handling for $TMP and
synonyms). TFD doesn't really say anything about it though.

> and what deletes it if the script crashes ?

Nothing (it just does it when the thing goes out of scope).

>   It might be better to use something in tmp/
> (presumably with the host name in the filename).  See for example
> ts-host-install which uses tmp/t.<host>.initrd.

Good idea.

> Or of course you could use LWP::UserAgent.

I'll check that out.

Ian/
diff mbox

Patch

diff --git a/Osstest/PDU/eth008.pm b/Osstest/PDU/eth008.pm
new file mode 100644
index 0000000..f56cfa0
--- /dev/null
+++ b/Osstest/PDU/eth008.pm
@@ -0,0 +1,73 @@ 
+# This is part of "osstest", an automated testing framework for Xen.
+# Copyright (C) 2014 Citrix Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+package Osstest::PDU::eth008;
+
+use strict;
+use warnings;
+
+use Osstest;
+use Osstest::TestSupport;
+use IO::File;
+use File::Temp qw/ tempfile /;
+
+BEGIN {
+    use Exporter ();
+    our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
+    $VERSION     = 1.00;
+    @ISA         = qw(Exporter);
+    @EXPORT      = qw();
+    %EXPORT_TAGS = ( );
+
+    @EXPORT_OK   = qw();
+}
+
+sub new {
+    my ($class, $ho, $methname, $pdu, $user, $pass, $port, @opts) = @_;
+    return bless { Host => $ho,
+		   PDU => $pdu,
+		   User => $user,
+		   Pass => $pass,
+		   Port => $port,
+		   Opts => \@opts }, $class;
+}
+
+sub pdu_power_state {
+    my ($mo, $on) = @_;
+    my $op= $on ? "DOA" : "DOI"; # Digital Output (In)Active
+
+    # Use the CGI interface since it is less prone to being firewalled
+    # off, unlike the standard interface on port 17494. This is only
+    # available from firmware v4 onwards.
+
+    # Create a netrc file to avoid putting l/p on command line
+    my ($passfh, $passfilename) = tempfile( UNLINK => 1 );
+    print $passfh "machine $mo->{PDU} login $mo->{User} password $mo->{Pass}\n";
+
+    my $url = "http://$mo->{PDU}/io.cgi?$op$mo->{Port}=0";
+    my $cmd = "curl --silent --netrc --netrc-file $passfilename $url";
+
+    logm("$cmd");
+    open CURL, "$cmd |" or die "fork curl: $!";
+    
+    my $result = <CURL>;
+    close CURL or die "result curl: $!";
+
+    logm("$result");
+    die "curl failed" unless $result =~ /^Success! \d+/;
+}
+
+1;