From patchwork Tue Jul 9 07:38:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyler Baker X-Patchwork-Id: 18284 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f69.google.com (mail-ee0-f69.google.com [74.125.83.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0BBBB25E04 for ; Tue, 9 Jul 2013 07:38:18 +0000 (UTC) Received: by mail-ee0-f69.google.com with SMTP id c50sf5259503eek.8 for ; Tue, 09 Jul 2013 00:38:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-beenthere:x-forwarded-to:x-forwarded-for:delivered-to :mime-version:x-launchpad-project:x-launchpad-branch :x-launchpad-message-rationale:x-launchpad-branch-revision-number :x-launchpad-notification-type:to:from:subject:message-id:date :reply-to:sender:errors-to:precedence:x-generated-by :x-launchpad-hash:x-gm-message-state:x-original-sender :x-original-authentication-results:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe :content-type; bh=+TWo6Nw9MVgYkwUnuLK+mO+pUxPz5wz+a5zKxtsGx4U=; b=J5sk3W+uRvY4hKyKQwj9u196iedOqnWMSGpK8aoCPEK0xHoHNKgq1JPTYrIGqkgjaf TUMe8bSlnN7uZGAQIJdt+uykRebExQ9AT8cPcVarkrJu+sAgZHmXrAbcE1//jw62WcnD tSfA8h3jiVUN62MGqfxZF0/unjannKg9deZY1/33cKOLBP4A/kiKDuwnHU0N5MFYxcSD NqPJZpN0hRBEPaGlK8j8rqyyuO4vS9W51tWvtipuLo8e+LLlVSP/iRKD2nse1Fw1Aef0 ozaRaOgC5VpM31ubyuHmVf88EY+60nfYK2GVqbb3mnScONWeNryMDFzh6fvBbhvVbzz0 ZsWg== X-Received: by 10.180.207.44 with SMTP id lt12mr6860936wic.5.1373355497612; Tue, 09 Jul 2013 00:38:17 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.180.104.169 with SMTP id gf9ls2341887wib.35.canary; Tue, 09 Jul 2013 00:38:17 -0700 (PDT) X-Received: by 10.180.85.6 with SMTP id d6mr30946074wiz.47.1373355496990; Tue, 09 Jul 2013 00:38:16 -0700 (PDT) Received: from mail-ve0-f176.google.com (mail-ve0-f176.google.com [209.85.128.176]) by mx.google.com with ESMTPS id pn9si8185900wjc.42.2013.07.09.00.38.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Jul 2013 00:38:16 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.176; Received: by mail-ve0-f176.google.com with SMTP id c13so4267900vea.21 for ; Tue, 09 Jul 2013 00:38:15 -0700 (PDT) X-Received: by 10.220.164.138 with SMTP id e10mr15678431vcy.27.1373355495804; Tue, 09 Jul 2013 00:38:15 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.149.77 with SMTP id s13csp13590vcv; Tue, 9 Jul 2013 00:38:15 -0700 (PDT) X-Received: by 10.14.218.8 with SMTP id j8mr28933155eep.129.1373355494704; Tue, 09 Jul 2013 00:38:14 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id n3si19313766eef.24.2013.07.09.00.38.13 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 09 Jul 2013 00:38:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1UwSV3-0004El-On for ; Tue, 09 Jul 2013 07:38:13 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id AC4A3E012D for ; Tue, 9 Jul 2013 07:38:13 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: lava-dispatcher X-Launchpad-Branch: ~linaro-validation/lava-dispatcher/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 634 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-validation/lava-dispatcher/trunk] Rev 634: Add get_power_status function to ipmi api. Message-Id: <20130709073813.2358.53362.launchpad@ackee.canonical.com> Date: Tue, 09 Jul 2013 07:38:13 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: list X-Generated-By: Launchpad (canonical.com); Revision="16696"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: fa8bfde9f401dbd3409b9ccd54e127b204221173 X-Gm-Message-State: ALoCoQnyvGm5cqAdbTasuxgpFhgsj230cFXjh5ejeSsc7WCq0S3fmgCNLFBsevKBNkeTHINddULo X-Original-Sender: noreply@launchpad.net X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Merge authors: Arthur She (arthur-she) Related merge proposals: https://code.launchpad.net/~arthur-she/lava-dispatcher/add-get_power_status-to-ipmi/+merge/172075 proposed by: Arthur She (arthur-she) review: Approve - Tyler Baker (tyler-baker) ------------------------------------------------------------ revno: 634 [merge] committer: Tyler Baker branch nick: lava-dispatcher timestamp: Tue 2013-07-09 00:37:43 -0700 message: Add get_power_status function to ipmi api. modified: lava_dispatcher/context.py lava_dispatcher/ipmi.py --- lp:lava-dispatcher https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk You are subscribed to branch lp:lava-dispatcher. To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk/+edit-subscription === modified file 'lava_dispatcher/context.py' --- lava_dispatcher/context.py 2013-06-11 20:27:05 +0000 +++ lava_dispatcher/context.py 2013-06-28 12:34:59 +0000 @@ -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' --- lava_dispatcher/ipmi.py 2013-05-29 22:07:56 +0000 +++ lava_dispatcher/ipmi.py 2013-07-09 05:54:26 +0000 @@ -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()