=== modified file 'lava_dispatcher/context.py'
@@ -140,3 +140,10 @@
rc = subprocess.check_call(command, **output_args)
return rc
+ def run_command_get_output(self, command):
+ """run command 'command' then return the command output"""
+ if isinstance(command, (str, unicode)):
+ command = ['sh', '-c', command]
+ logging.debug("Executing on host : '%r'" % command)
+ return subprocess.check_output(command)
+
=== modified file 'lava_dispatcher/ipmi.py'
@@ -41,6 +41,12 @@
failok=False
)
+ def __ipmi_cmd_output(self, command):
+ return self.context.run_command_get_output(
+ "%s -H %s -U admin -P admin %s" % (
+ self.ipmitool, self.host, command)
+ )
+
def set_to_boot_from_disk(self):
self.__ipmi("chassis bootdev disk")
@@ -56,6 +62,11 @@
def reset(self):
self.__ipmi("chassis power reset")
+ def get_power_status(self):
+ """ Command 'ipmitool power status' will output 'Chassis Power is on'
+ or 'Chassis Power is off' """
+ return self.__ipmi_cmd_output("power status").split(' ')[-1]
+
class IpmiPxeBoot(object):
"""
This class provides a convenient object-oriented API that can be
@@ -68,14 +79,17 @@
def power_on_boot_master(self):
self.ipmitool.set_to_boot_from_pxe()
- self.ipmitool.power_off()
+ if self.ipmitool.get_power_status() == 'on':
+ self.ipmitool.power_off()
self.ipmitool.power_on()
def power_on_boot_image(self):
self.ipmitool.set_to_boot_from_disk()
- self.ipmitool.power_off()
+ if self.ipmitool.get_power_status() == 'on':
+ self.ipmitool.power_off()
self.ipmitool.power_on()
def power_off(self):
- self.ipmitool.power_off()
+ if self.ipmitool.get_power_status() == 'on':
+ self.ipmitool.power_off()