Bug 1264519

Summary: restraint-rhts is missing rhts-power
Product: [Retired] Restraint Reporter: Jeff Bastian <jbastian>
Component: generalAssignee: beaker-dev-list
Status: CLOSED WONTFIX QA Contact: tools-bugs <tools-bugs>
Severity: medium Docs Contact:
Priority: low    
Version: 0.1.21CC: asavkov, bpeck, cbouchar, egasiorowski, mjia, pbunyan, pkremens
Target Milestone: ---Keywords: FutureFeature
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-11-19 21:01:10 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:

Description Jeff Bastian 2015-09-18 16:30:52 UTC
Description of problem:
restraint-rhts is missing the /usr/bin/rhts-power utility to power-cycle a system, and rhts-test-env (which provides rhts-power for beah) requires rhts-python which has a conflict with restraint-rhts.


Version-Release number of selected component (if applicable):
restraint-rhts-0.1.21-3.el7.x86_64.rpm

How reproducible:
always

Steps to Reproduce:
1. run a task which calls rhts-power under the restraint harness, e.g.
   /distribution/utils/power-cycle

Actual results:
task fails because rhts-power command is missing

Expected results:
beaker power-cycles the system

Additional info:

Comment 1 Ed Gasiorowski 2017-10-23 17:26:02 UTC
Dan, 
Agree with Jeff, this would be very useful for power cycle testing.. a key requirement in our QA cycle.

Comment 2 Jeff Bastian 2020-03-31 21:36:00 UTC
Any updates for this bug?  The /distribution/utils/power-cycle task still fails.

I refreshed my memory and took a look at the old rhts-power command and found it's a simple Python script (see below) that calls the systems.power() XML-RPC function.  I can try and create a rstrnt-power equivalent for the same XML-RPC call.



~]# cat /usr/bin/rhts-power 
#!/bin/sh
#
# Copyright (c) 2012 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.


# Check the correct Python executable to run this file.
# Python3 will be preferred.
""":"

cmd=$(python-check.sh)

exec -- $cmd $0 "$@";

":"""
from __future__ import print_function

import sys
import os
import rhts.timeout_xmlrpclib

server = rhts.timeout_xmlrpclib.Server('http://%s:8000/RPC2' % os.environ['LAB_CONTROLLER'])
print(server.power(sys.argv[1], sys.argv[2]))

Comment 3 Jeff Bastian 2020-04-01 19:25:35 UTC
I tried a simple curl replacement, but I'm obviously doing something wrong since I get a "method not supported" error for the systems.power call.

~]# cat bkr-power-cycle.sh
#!/bin/bash

cat >bkr-power-cycle.xml <<EOF
<?xml version="1.0"?>
<methodCall>
  <methodName>systems.power</methodName>
  <params>
    <param>
      <value><string>reboot</string></value>
    </param>
    <param>
      <value><string>$(hostname)</string></value>
    </param>
  </params>
</methodCall>
EOF
curl --insecure --verbose --header "Content-Type: text/xml" \
    --data "@bkr-power-cycle.xml" \
    http://${LAB_CONTROLLER}:8000/RPC2 | xmllint --format -


~]# ./bkr-power-cycle.sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 192.168.0.1...
* TCP_NODELAY set
* Connected to lab-controller.example.com (192.168.0.1) port 8000 (#0)
> POST /RPC2 HTTP/1.1
> Host: lab-controller.example.com:8000
> User-Agent: curl/7.61.1
> Accept: */*
> Content-Type: text/xml
> Content-Length: 289
> 
} [289 bytes data]
* upload completely sent off: 289 out of 289 bytes
< HTTP/1.1 200 OK
< Content-Type: text/xml
< Content-Length: 330
< Date: Wed, 01 Apr 2020 19:17:30 GMT
< 
{ [330 bytes data]
100   619  100   330  100   289  66000  57800 --:--:-- --:--:-- --:--:--  120k
* Connection #0 to host lab-controller.example.com left intact
<?xml version="1.0"?>
<methodResponse>
  <fault>
    <value>
      <struct>
        <member>
          <name>faultCode</name>
          <value>
            <int>1</int>
          </value>
        </member>
        <member>
          <name>faultString</name>
          <value>
            <string>&lt;type 'exceptions.Exception'&gt;:method "systems.power" is not supported</string>
          </value>
        </member>
      </struct>
    </value>
  </fault>
</methodResponse>

Comment 4 Jeff Bastian 2020-04-01 20:00:14 UTC
Ok, with a little help from Wireshark while running the old rhts-power command, I figured out what was wrong in my XML: the command is just "power", not systems.power.

Also, the order of the arguments is backwards from how it's described in the documentation: the hostname comes first, then the action.

Does the documentation need an update?
  https://beaker-project.org/docs/server-api/xmlrpc.html#systems


This works:

~]# cat ./bkr-power-cycle.sh
#!/bin/bash

cat >bkr-power-cycle.xml <<EOF
<?xml version="1.0"?>
<methodCall>
  <methodName>power</methodName>
  <params>
    <param>
      <value><string>$(hostname)</string></value>
    </param>
    <param>
      <value><string>reboot</string></value>
    </param>
  </params>
</methodCall>
EOF
curl --insecure --verbose --header "Content-Type: text/xml" \
    --data "@bkr-power-cycle.xml" \
    http://${LAB_CONTROLLER}:8000/RPC2 | xmllint --format -

~]# ./bkr-power-cycle.sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 192.168.0.1...
* TCP_NODELAY set
* Connected to lab-controller.example.com (192.168.0.1) port 8000 (#0)
> POST /RPC2 HTTP/1.1
> Host: lab-controller.example.com:8000
> User-Agent: curl/7.61.1
> Accept: */*
> Content-Type: text/xml
> Content-Length: 281
> 
} [281 bytes data]
* upload completely sent off: 281 out of 281 bytes
< HTTP/1.1 200 OK
< Content-Type: text/xml
< Content-Length: 180
< Date: Wed, 01 Apr 2020 19:54:23 GMT
< 
{ [180 bytes data]
100   461  100   180  100   281   1111   1734 --:--:-- --:--:-- --:--:--  2845
* Connection #0 to host lab-controller.example.com left intact
<?xml version="1.0"?>
<methodResponse>
  <params>
    <param>
      <value>
        <string>system-under-test.example.com</string>
      </value>
    </param>
  </params>
</methodResponse>

Comment 5 Jeff Bastian 2020-04-01 21:12:08 UTC
Request for comment:
https://gerrit.beaker-project.org/#/c/restraint/+/6819