[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [OSSTEST PATCH 09/26] power: Provide `try_off' pdu method; deprecate ipmi_try



We are going to want to use this magically, in our new approach.  Make
a general version, and deprecate ipmi_try (which will be obsoleted by
the new approach and which has probably not been used very much).

Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 Osstest/PDU/ipmi_try.pm |  2 ++
 Osstest/PDU/try_off.pm  | 65 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)
 create mode 100644 Osstest/PDU/try_off.pm

diff --git a/Osstest/PDU/ipmi_try.pm b/Osstest/PDU/ipmi_try.pm
index cf851d21..17eb504e 100644
--- a/Osstest/PDU/ipmi_try.pm
+++ b/Osstest/PDU/ipmi_try.pm
@@ -14,6 +14,8 @@
 # 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/>.
 
+# NOTE: this method is deprecated.  Use try_off instead.
+
 package Osstest::PDU::ipmi_try;
 
 use strict;
diff --git a/Osstest/PDU/try_off.pm b/Osstest/PDU/try_off.pm
new file mode 100644
index 00000000..aa73c854
--- /dev/null
+++ b/Osstest/PDU/try_off.pm
@@ -0,0 +1,65 @@
+# 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::try_off;
+
+use strict;
+use warnings;
+
+use Osstest;
+use Osstest::TestSupport;
+use IO::File;
+
+use parent qw(Osstest::PDU::unsupported);
+
+our $default_attempts = 3;
+
+sub new {
+    my ($class, $ho, $methname, @opts) = @_;
+    my $attempts;
+    if ($opts[0] =~ m/^\d+$/) {
+       $attempts = shift @opts;
+    }
+    return bless { Attempts => $attempts,
+                  Then => get_host_method_object($ho, 'PDU', "@opts"),
+                }, $class;
+}
+
+sub new_from_mo {
+    my ($class, $mo, $attempts) = @_;
+    return bless { Attempts => $attempts,
+                  Then => $mo
+                }, $class;
+}
+
+sub pdu_power_state {
+    my ($mo, $on) = @_;
+
+    if ($on) {
+       $mo->{Then}->pdu_power_state($on);
+    } else {
+       my $attempts = ($mo->{Attempts} // $default_attempts);
+       foreach my $attempt (1..$attempts) {
+           eval {
+               $mo->{Then}->pdu_power_state($on);
+           };
+           last unless $@;
+           warn "(attempt $attempt/$attempts) $@";
+       }
+    }
+}
+
+1;
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.