diff mbox series

[OSSTEST,09/16] PDU/MSU: Retransmit on/off until PDU has changed

Message ID 20201022164506.1552-10-iwj@xenproject.org (mailing list archive)
State New, archived
Headers show
Series Bugfixes | expand

Commit Message

Ian Jackson Oct. 22, 2020, 4:44 p.m. UTC
The main effect of this is that the transcript will actually show the
new PDU state.  Previously we would call show(), but APC PDUs would
normally not change immediately, so the transcript would show the old
state.

This also guards against an unresponsive PDU or a packet getting lost.
I don't think we have ever seen that.

Signed-off-by: Ian Jackson <iwj@xenproject.org>
---
 pdu-msw | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/pdu-msw b/pdu-msw
index 2d4ec967..c57f9f7c 100755
--- a/pdu-msw
+++ b/pdu-msw
@@ -41,6 +41,7 @@  while (@ARGV && $ARGV[0] =~ m/^-/) {
 
 if (@ARGV<2 || @ARGV>3 || $ARGV[0] =~ m/^-/) { die "bad usage\n$usagemsg"; }
 
+our ($max_retries) = 16; # timeout = 0.05 * max_retries^2
 our ($dnsname,$outlet,$action) = @ARGV;
 
 my ($session,$error) = Net::SNMP->session(
@@ -142,7 +143,21 @@  if (!defined $action) {
 } else {
     my $valset = action_value();
     print "was: "; show();
-    set($valset);
-    print "now: "; show();
-    print "^ note, PDUs often do not update returned info immediately\n";
+
+    my $retries = 0;
+    for (;;) {
+	set($valset);
+	sleep $retries * 0.1;
+	print "now: "; my $got = show();
+	if ($got eq $map[$valset]) { last; }
+	if ($map[$valset] !~ m{^(?:off|on)$}) {
+	    print
+ "^ note, PDUs often do not update returned info immediately\n";
+	    last;
+	}
+	if ($retries >= $max_retries) {
+	    die "PDU does not seem to be changing state!\n";
+	}
+	$retries++;
+    }
 }