Bug 1211376

Summary: Fetching host power state using "power_action": "status" fails for VMs
Product: Red Hat Satellite Reporter: Jan Krocil <jkrocil>
Component: ProvisioningAssignee: Shlomi Zadok <szadok>
Status: CLOSED ERRATA QA Contact: Roman Plevka <rplevka>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.0.8CC: bkearney, cwelton, ehelms, kbidarka, lzap, ohadlevy, rplevka, szadok
Target Milestone: UnspecifiedKeywords: Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
URL: http://projects.theforeman.org/issues/13430
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-07-27 11:22:19 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1341149    
Bug Blocks:    

Description Jan Krocil 2015-04-13 19:32:38 UTC
Description of problem:
User is unable to fetch a power state of a VM using REST API `"power_action": "status"` ; PUT /api/hosts/:id/power.

Version-Release number of selected component (if applicable):
Upstream foreman 1.7.4-1
Downstream Sat 6.0.8

How reproducible:
-

Steps to Reproduce:
1. Setup a compute resource
2. Create a host on that compute resource
3. Run power state check using the rest api against the virtualized host:
[jkrocil@lysandros ~]$ curl --insecure -X PUT -d '{"power_action": "status"}' -u admin -H "Content-Type:application/json" -H "Accept:application/json"  https://my-foreman.domain.com/api/v2/hosts/my-vm.nested.lan/power

Actual results:
{
  "error": {"message":"undefined method `status' for #<PowerManager::Virt:0x007f8e196e0268>"}
}

Expected results:
Valid response with power state info.

Additional info:
Running `"power_action": "state"` instead of "status" works.

The issue is here:
https://github.com/theforeman/foreman/blob/develop/app/services/power_manager/virt.rb#L24

"state" and "status" is being removed from the SUPPORTED_ACTIONS.
There are methods being created dynamically for each power state except the 2.
For "state" though, there is a method defined at L18.
For "status", there is nothing.

Thanks to stbenjam for help.

Comment 1 RHEL Program Management 2015-04-13 19:33:05 UTC
Since this issue was entered in Red Hat Bugzilla, the release flag has been
set to ? to ensure that it is properly evaluated for this release.

Comment 3 Lukas Zapletal 2015-04-14 11:04:38 UTC
Valid bug, we should return same flags for both bare metal and hypervisors.

Comment 4 Bryan Kearney 2015-09-01 17:10:40 UTC
Created redmine issue http://projects.theforeman.org/issues/11642 from this bug

Comment 5 Bryan Kearney 2015-09-02 10:03:34 UTC
Upstream bug component is Power & BMC

Comment 6 Bryan Kearney 2016-03-17 12:44:44 UTC
Connecting redmine issue http://projects.theforeman.org/issues/13430 from this bug

Comment 7 Bryan Kearney 2016-03-17 14:11:24 UTC
Upstream bug component is Provisioning

Comment 8 Bryan Kearney 2016-03-17 14:11:27 UTC
Moving to POST since upstream bug http://projects.theforeman.org/issues/13430 has been closed
-------------
Anonymous
Applied in changeset commit:1bf5ff536572e0209095532d7f5c7dd986d2aa19.

Comment 15 Roman Plevka 2016-07-01 09:20:53 UTC
VERIFIED
on sat6.2.0 snap18.1

<pre>
# curl -ku admin:changeme -X PUT -H 'Content-Type:application/json' -d '{"power_action": "off"}' https://$(hostname)/api/v2/hosts/3/power/
{"power":true}
[root ~]# curl -ku admin:changeme -X PUT -H 'Content-Type:application/json' -d '{"power_action": "state"}' https://$(hostname)/api/v2/hosts/3/power/
{"power":"off"}
[root ~]# curl -ku admin:changeme -X PUT -H 'Content-Type:application/json' -d '{"power_action": "on"}' https://$(hostname)/api/v2/hosts/3/power/
{"power":true}
[root ~]# curl -ku admin:changeme -X PUT -H 'Content-Type:application/json' -d '{"power_action": "state"}' https://$(hostname)/api/v2/hosts/3/power/
{"power":"running"}
</pre>

Comment 16 Bryan Kearney 2016-07-27 11:22:19 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2016:1501