xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [OSSTEST PATCH 0/7] Prepare for ServerTech PDUs
@ 2020-10-27 13:43 Ian Jackson
  2020-10-27 13:43 ` [OSSTEST PATCH 1/7] README: Fix a typo Ian Jackson
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Ian Jackson @ 2020-10-27 13:43 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson

We have taken delivery of two Servertech PDUs which do
(near-)zero-crossing switching.  We hope these will not suffer from
the relays welding shut like our APC PDUs do.

We will control these PDUs via SNMP, as we do for the APC PDUs, but
each PDU manufacturer uses their own SNMP range, so adjustments to the
code and configuration are needed.

These new arrangements have been tested successfully in a mockup
environment.

Ian Jackson (7):
  README: Fix a typo
  pdu-snmp: Rename from pdu-msw
  pdu-snmp: Centralise base OIDs
  pdu-snmp: Refactor model handling
  pdu-snmp: Support ServerTech PDUs "Pro 1/2" aka "Sentry4"
  PDU::snmp, PDU::msw: Rename from msw to snmp
  pdu-snmp: Fix sleeping

 Osstest/PDU/msw.pm  | 14 +-------------
 Osstest/PDU/snmp.pm | 39 +++++++++++++++++++++++++++++++++++++++
 README              |  9 ++++++---
 pdu-msw => pdu-snmp | 45 +++++++++++++++++++++++++++++++++++----------
 4 files changed, 81 insertions(+), 26 deletions(-)
 create mode 100644 Osstest/PDU/snmp.pm
 rename pdu-msw => pdu-snmp (78%)

-- 
2.20.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [OSSTEST PATCH 1/7] README: Fix a typo
  2020-10-27 13:43 [OSSTEST PATCH 0/7] Prepare for ServerTech PDUs Ian Jackson
@ 2020-10-27 13:43 ` Ian Jackson
  2020-10-27 13:43 ` [OSSTEST PATCH 2/7] pdu-snmp: Rename from pdu-msw Ian Jackson
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Ian Jackson @ 2020-10-27 13:43 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson

Signed-off-by: Ian Jackson <iwj@xenproject.org>
---
 README | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README b/README
index 1703e076..ef6c4e60 100644
--- a/README
+++ b/README
@@ -655,7 +655,7 @@ HostProp_<host>_PowerILOM
         unsupported     Fails whenever a power operation is needed
 
         msw [--apc6] <pdu> <port-name-regexp|port-num>
-             Control and APC masterswitch via SNMP.  The SNMP
+             Control an APC masterswitch via SNMP.  The SNMP
              community is `private'.  See the `pdu-msw' script.
 
         ipmi <mgmt> [<user> [<pass> [<ipmitool options...>]]]
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [OSSTEST PATCH 2/7] pdu-snmp: Rename from pdu-msw
  2020-10-27 13:43 [OSSTEST PATCH 0/7] Prepare for ServerTech PDUs Ian Jackson
  2020-10-27 13:43 ` [OSSTEST PATCH 1/7] README: Fix a typo Ian Jackson
@ 2020-10-27 13:43 ` Ian Jackson
  2020-10-27 13:43 ` [OSSTEST PATCH 3/7] pdu-snmp: Centralise base OIDs Ian Jackson
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Ian Jackson @ 2020-10-27 13:43 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson

We are going to make this script control PDUs other than APC ones.

No overall functional change for internal callers.  Anyone out-of-tree
using this script will need to change the name of the program they run.

Signed-off-by: Ian Jackson <iwj@xenproject.org>
---
 Osstest/PDU/msw.pm  | 2 +-
 README              | 2 +-
 pdu-msw => pdu-snmp | 6 +++---
 3 files changed, 5 insertions(+), 5 deletions(-)
 rename pdu-msw => pdu-snmp (95%)

diff --git a/Osstest/PDU/msw.pm b/Osstest/PDU/msw.pm
index 19d9f56b..614216d4 100644
--- a/Osstest/PDU/msw.pm
+++ b/Osstest/PDU/msw.pm
@@ -33,7 +33,7 @@ sub new {
 sub pdu_power_state {
     my ($mo, $on) = @_;
     my $onoff= $on ? "on" : "off";
-    system_checked("./pdu-msw @{ $mo->{Args} } $onoff");
+    system_checked("./pdu-snmp @{ $mo->{Args} } $onoff");
 }
 
 1;
diff --git a/README b/README
index ef6c4e60..70f8ae73 100644
--- a/README
+++ b/README
@@ -656,7 +656,7 @@ HostProp_<host>_PowerILOM
 
         msw [--apc6] <pdu> <port-name-regexp|port-num>
              Control an APC masterswitch via SNMP.  The SNMP
-             community is `private'.  See the `pdu-msw' script.
+             community is `private'.  See the `pdu-snmp' script.
 
         ipmi <mgmt> [<user> [<pass> [<ipmitool options...>]]]
              Use IPMI by (by running ipmitool).  <mgmt> is the name or
diff --git a/pdu-msw b/pdu-snmp
similarity index 95%
rename from pdu-msw
rename to pdu-snmp
index c57f9f7c..581a60b0 100755
--- a/pdu-msw
+++ b/pdu-snmp
@@ -19,7 +19,7 @@
 
 my $usagemsg= <<END;
 usage:
-  pdu-msw SWITCH-DNS-NAME PORT-NAME-REGEXP|PORT [[delayed-]on|off|0|1|reboot]
+  pdu-snmp SWITCH-DNS-NAME PORT-NAME-REGEXP|PORT [[delayed-]on|off|0|1|reboot]
 END
 
 use strict qw(refs vars);
@@ -89,7 +89,7 @@ if ($outlet =~ m/^\d+$/) {
                    ($t->[2] ? '*' : ''),
                    $t->[0], $t->[1]);
         }
-        die "pdu-msw $dnsname: ".
+        die "pdu-snmp $dnsname: ".
             (@found ? "multiple ports match" : "no ports match").
             "\n";
     }
@@ -119,7 +119,7 @@ sub get () {
 
 sub show () {
     my $mean = get();
-    printf "pdu-msw $dnsname: #%s \"%s\" = %s\n", $useport, $usename, $mean;
+    printf "pdu-snmp $dnsname: #%s \"%s\" = %s\n", $useport, $usename, $mean;
     return $mean;
 }
 
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [OSSTEST PATCH 3/7] pdu-snmp: Centralise base OIDs
  2020-10-27 13:43 [OSSTEST PATCH 0/7] Prepare for ServerTech PDUs Ian Jackson
  2020-10-27 13:43 ` [OSSTEST PATCH 1/7] README: Fix a typo Ian Jackson
  2020-10-27 13:43 ` [OSSTEST PATCH 2/7] pdu-snmp: Rename from pdu-msw Ian Jackson
@ 2020-10-27 13:43 ` Ian Jackson
  2020-10-27 13:43 ` [OSSTEST PATCH 4/7] pdu-snmp: Refactor model handling Ian Jackson
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Ian Jackson @ 2020-10-27 13:43 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson

Do not hardcoode .3 and .4 in the main logic.

No functional change.

Signed-off-by: Ian Jackson <iwj@xenproject.org>
---
 pdu-snmp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/pdu-snmp b/pdu-snmp
index 581a60b0..a4918f53 100755
--- a/pdu-snmp
+++ b/pdu-snmp
@@ -27,8 +27,11 @@ use Net::SNMP;
 use Data::Dumper;
 
 my $community= 'private';
+
 my $baseoid= '.1.3.6.1.4.1.318.1.1.4.4.2.1';
 my $baseoid_write= "$baseoid.3";
+my $baseoid_name= "$baseoid.4";
+my $baseoid_read= "$baseoid.3";
 
 while (@ARGV && $ARGV[0] =~ m/^-/) {
     $_ = shift @ARGV;
@@ -52,7 +55,7 @@ die "SNMP error $error " unless defined $session;
 
 sub getname ($) {
     my ($port) = @_;
-    my $oid= "$baseoid.4.$port";
+    my $oid= "$baseoid_name.$port";
     my $res= $session->get_request($oid);
     if ($res) {
         my $name= $res->{$oid};
@@ -96,7 +99,7 @@ if ($outlet =~ m/^\d+$/) {
     ($useport,$usename)= @{ $found[0] };
 }
 
-my $read_oid= "$baseoid.3.$useport";
+my $read_oid= "$baseoid_read.$useport";
 my $write_oid= "$baseoid_write.$useport";
 
 my @map= (undef, qw(
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [OSSTEST PATCH 4/7] pdu-snmp: Refactor model handling
  2020-10-27 13:43 [OSSTEST PATCH 0/7] Prepare for ServerTech PDUs Ian Jackson
                   ` (2 preceding siblings ...)
  2020-10-27 13:43 ` [OSSTEST PATCH 3/7] pdu-snmp: Centralise base OIDs Ian Jackson
@ 2020-10-27 13:43 ` Ian Jackson
  2020-10-27 13:43 ` [OSSTEST PATCH 5/7] pdu-snmp: Support ServerTech PDUs "Pro 1/2" aka "Sentry4" Ian Jackson
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Ian Jackson @ 2020-10-27 13:43 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson

This makes it easier to see waht is going on and to add new model(s).

No functional change.

Signed-off-by: Ian Jackson <iwj@xenproject.org>
---
 pdu-snmp | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/pdu-snmp b/pdu-snmp
index a4918f53..74244145 100755
--- a/pdu-snmp
+++ b/pdu-snmp
@@ -28,15 +28,28 @@ use Data::Dumper;
 
 my $community= 'private';
 
-my $baseoid= '.1.3.6.1.4.1.318.1.1.4.4.2.1';
-my $baseoid_write= "$baseoid.3";
-my $baseoid_name= "$baseoid.4";
-my $baseoid_read= "$baseoid.3";
+our ($baseoid, $baseoid_write, $baseoid_name, $baseoid_read);
+
+sub model_msw () {
+    # APC MasterSwitch
+    $baseoid= '.1.3.6.1.4.1.318.1.1.4.4.2.1';
+    $baseoid_name= "$baseoid.4";
+    $baseoid_read= "$baseoid.3";
+    $baseoid_write= "$baseoid.3";
+}
+
+sub model_apc6 () {
+    # APC MasterSwitch protocol version 6 (?)
+    model_msw();
+    $baseoid_write= '.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4';
+}
+
+my $model_name = 'msw';
 
 while (@ARGV && $ARGV[0] =~ m/^-/) {
     $_ = shift @ARGV;
-    if (m/^--apc6$/) {
-	$baseoid_write= '.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4';
+    if (m/^--(\w+)$/ && ${*::}{"model_$1"}) {
+	$model_name= $1;
     } else {
 	die "$_ ?";
     }
@@ -44,6 +57,8 @@ while (@ARGV && $ARGV[0] =~ m/^-/) {
 
 if (@ARGV<2 || @ARGV>3 || $ARGV[0] =~ m/^-/) { die "bad usage\n$usagemsg"; }
 
+${*::}{"model_$model_name"}->();
+
 our ($max_retries) = 16; # timeout = 0.05 * max_retries^2
 our ($dnsname,$outlet,$action) = @ARGV;
 
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [OSSTEST PATCH 5/7] pdu-snmp: Support ServerTech PDUs "Pro 1/2" aka "Sentry4"
  2020-10-27 13:43 [OSSTEST PATCH 0/7] Prepare for ServerTech PDUs Ian Jackson
                   ` (3 preceding siblings ...)
  2020-10-27 13:43 ` [OSSTEST PATCH 4/7] pdu-snmp: Refactor model handling Ian Jackson
@ 2020-10-27 13:43 ` Ian Jackson
  2020-10-27 13:43 ` [OSSTEST PATCH 6/7] PDU::snmp, PDU::msw: Rename from msw to snmp Ian Jackson
  2020-10-27 13:43 ` [OSSTEST PATCH 7/7] pdu-snmp: Fix sleeping Ian Jackson
  6 siblings, 0 replies; 8+ messages in thread
From: Ian Jackson @ 2020-10-27 13:43 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson

Values from Sentry4.mib, from
  https://www.servertech.com/support/sentry-mib-oid-tree-downloads

Useful runes used when developing and testing, with "Sentry.mib" from
the Servertech zipfile renamed to "mibs/Sentry4-MIB":
  snmpwalk -On -m Sentry4-MIB -M +:mibs/ -Ci -v 2c -c private pdu1 iso.3.6.1.4.1.1718.4
  snmpwalk -m Sentry4-MIB -M +:mibs/ -Ci -v 2c -c private pdu1 iso.3.6.1.4.1.1718.4
  snmptranslate -Td -m Sentry4-MIB -M +:mibs/ Sentry4-MIB::st4OutletControlAction.1.1.2

Signed-off-by: Ian Jackson <iwj@xenproject.org>
---
 pdu-snmp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/pdu-snmp b/pdu-snmp
index 74244145..61380766 100755
--- a/pdu-snmp
+++ b/pdu-snmp
@@ -44,6 +44,13 @@ sub model_apc6 () {
     $baseoid_write= '.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4';
 }
 
+sub model_sentry4 () {
+    $baseoid = ".1.3.6.1.4.1.1718.4.1.8";
+    $baseoid_name = "$baseoid.2.1.3.1.1"; # st4OutletName.1.1
+    $baseoid_read = "$baseoid.3.1.1.1.1"; # st4OutletState.1.1
+    $baseoid_write= "$baseoid.5.1.2.1.1"; # st4OutletControlAction.1.1
+}
+
 my $model_name = 'msw';
 
 while (@ARGV && $ARGV[0] =~ m/^-/) {
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [OSSTEST PATCH 6/7] PDU::snmp, PDU::msw: Rename from msw to snmp
  2020-10-27 13:43 [OSSTEST PATCH 0/7] Prepare for ServerTech PDUs Ian Jackson
                   ` (4 preceding siblings ...)
  2020-10-27 13:43 ` [OSSTEST PATCH 5/7] pdu-snmp: Support ServerTech PDUs "Pro 1/2" aka "Sentry4" Ian Jackson
@ 2020-10-27 13:43 ` Ian Jackson
  2020-10-27 13:43 ` [OSSTEST PATCH 7/7] pdu-snmp: Fix sleeping Ian Jackson
  6 siblings, 0 replies; 8+ messages in thread
From: Ian Jackson @ 2020-10-27 13:43 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson

Retain the old name for compatibility with existing configuration.

No change other than to messages.

Signed-off-by: Ian Jackson <iwj@xenproject.org>
---
 Osstest/PDU/msw.pm  | 14 +-------------
 Osstest/PDU/snmp.pm | 39 +++++++++++++++++++++++++++++++++++++++
 README              |  9 ++++++---
 3 files changed, 46 insertions(+), 16 deletions(-)
 create mode 100644 Osstest/PDU/snmp.pm

diff --git a/Osstest/PDU/msw.pm b/Osstest/PDU/msw.pm
index 614216d4..099ef778 100644
--- a/Osstest/PDU/msw.pm
+++ b/Osstest/PDU/msw.pm
@@ -22,18 +22,6 @@ use warnings;
 
 use Osstest;
 
-use parent qw(Osstest::PDU::unsupported);
-
-sub new {
-    my ($class, $ho, $methname, @args) = @_;
-
-    return bless { Args => \@args }, $class;
-}
-
-sub pdu_power_state {
-    my ($mo, $on) = @_;
-    my $onoff= $on ? "on" : "off";
-    system_checked("./pdu-snmp @{ $mo->{Args} } $onoff");
-}
+use parent qw(Osstest::PDU::snmp);
 
 1;
diff --git a/Osstest/PDU/snmp.pm b/Osstest/PDU/snmp.pm
new file mode 100644
index 00000000..dca60df7
--- /dev/null
+++ b/Osstest/PDU/snmp.pm
@@ -0,0 +1,39 @@
+# This is part of "osstest", an automated testing framework for Xen.
+# Copyright (C) 2009-2013 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::snmp;
+
+use strict;
+use warnings;
+
+use Osstest;
+
+use parent qw(Osstest::PDU::unsupported);
+
+sub new {
+    my ($class, $ho, $methname, @args) = @_;
+
+    return bless { Args => \@args }, $class;
+}
+
+sub pdu_power_state {
+    my ($mo, $on) = @_;
+    my $onoff= $on ? "on" : "off";
+    system_checked("./pdu-snmp @{ $mo->{Args} } $onoff");
+}
+
+1;
diff --git a/README b/README
index 70f8ae73..33c4d2cc 100644
--- a/README
+++ b/README
@@ -654,9 +654,9 @@ HostProp_<host>_PowerILOM
         manual          Asks the user on the controlling terminal
         unsupported     Fails whenever a power operation is needed
 
-        msw [--apc6] <pdu> <port-name-regexp|port-num>
-             Control an APC masterswitch via SNMP.  The SNMP
-             community is `private'.  See the `pdu-snmp' script.
+        snmp --<model> <pdu> <port-name-regexp|port-num>
+             Control a PDU via SNMP.  The SNMP community is `private'.
+             See the `pdu-snmp' script for supported model names.
 
         ipmi <mgmt> [<user> [<pass> [<ipmitool options...>]]]
              Use IPMI by (by running ipmitool).  <mgmt> is the name or
@@ -667,6 +667,9 @@ HostProp_<host>_PowerILOM
              Does nothing if `on|off|both' is inapplicable, and has
              less error checking and less defaulting than ipmi.
 
+        msw ....
+             Deprecated alias for snmp.
+
         Supported specially are:
 
         <delay>
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [OSSTEST PATCH 7/7] pdu-snmp: Fix sleeping
  2020-10-27 13:43 [OSSTEST PATCH 0/7] Prepare for ServerTech PDUs Ian Jackson
                   ` (5 preceding siblings ...)
  2020-10-27 13:43 ` [OSSTEST PATCH 6/7] PDU::snmp, PDU::msw: Rename from msw to snmp Ian Jackson
@ 2020-10-27 13:43 ` Ian Jackson
  6 siblings, 0 replies; 8+ messages in thread
From: Ian Jackson @ 2020-10-27 13:43 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson

sleep takes only an integer.  We have to use select to sleep for
fractions of a second.

Signed-off-by: Ian Jackson <iwj@xenproject.org>
---
 pdu-snmp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pdu-snmp b/pdu-snmp
index 61380766..79d22e1f 100755
--- a/pdu-snmp
+++ b/pdu-snmp
@@ -172,7 +172,7 @@ if (!defined $action) {
     my $retries = 0;
     for (;;) {
 	set($valset);
-	sleep $retries * 0.1;
+	select undef,undef,undef, $retries * 0.1;
 	print "now: "; my $got = show();
 	if ($got eq $map[$valset]) { last; }
 	if ($map[$valset] !~ m{^(?:off|on)$}) {
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-10-27 13:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-27 13:43 [OSSTEST PATCH 0/7] Prepare for ServerTech PDUs Ian Jackson
2020-10-27 13:43 ` [OSSTEST PATCH 1/7] README: Fix a typo Ian Jackson
2020-10-27 13:43 ` [OSSTEST PATCH 2/7] pdu-snmp: Rename from pdu-msw Ian Jackson
2020-10-27 13:43 ` [OSSTEST PATCH 3/7] pdu-snmp: Centralise base OIDs Ian Jackson
2020-10-27 13:43 ` [OSSTEST PATCH 4/7] pdu-snmp: Refactor model handling Ian Jackson
2020-10-27 13:43 ` [OSSTEST PATCH 5/7] pdu-snmp: Support ServerTech PDUs "Pro 1/2" aka "Sentry4" Ian Jackson
2020-10-27 13:43 ` [OSSTEST PATCH 6/7] PDU::snmp, PDU::msw: Rename from msw to snmp Ian Jackson
2020-10-27 13:43 ` [OSSTEST PATCH 7/7] pdu-snmp: Fix sleeping Ian Jackson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).