[Fuego] [PATCH] ftc: add a new command to interact with pdudaemon
Tim.Bird at sony.com
Tim.Bird at sony.com
Wed Mar 13 19:55:10 UTC 2019
Here are some overall comments:
Rather than add a new command to ftc for managing pdudaemon operations,
I was expecting to install support for pdudaemon at Fuego's board management (/board_control)
layer. That is, I was expecting to see something like this:
diff --git a/overlays/base/base-board.fuegoclass b/overlays/base/base-board.fuegoclass
index ae35464..8f34922 100644
--- a/overlays/base/base-board.fuegoclass
+++ b/overlays/base/base-board.fuegoclass
@@ -299,6 +299,9 @@ function ov_board_control_reboot() {
"ttc")
$TTC $TTC_TARGET reboot
;;
+ "pdudaemon"):
+ curl "http://$PDUDAEMON_HOST:$PDUDAEMON_PORT/power/control/reboot?hostname=$PDU_HOSTNAME&port=$PDU_PORT"
+ ;;
*)
abort_job "Error reason: unsupported BOARD_CONTROL ${BOARD_CONTROL}"
;;
----
Note that I don't know if pdudaemon supports the 'reboot' control option, or if I would have
to synthesize something by sending 'on' and 'off'. But you get the idea, I think.
I'm not sure if the hostname in the URL is supposed to be the board name or the pdu name,
but presumably PDUDAEMON_HOST and PDUDAEMON_PORT would come from
fuego.conf, and PDU_HOSTNAME and PDU_PORT would come from the board file?
If more fine-grained control is desired, than just the 'reboot' operation,
we could add more ov_board_control() functions if needed, and have Fuego use those.
e.g. ov_board_control_on() and ov_board_control_off().
Once we've plugged pdudaemon into the board layer, I'd prefer to have a generic
set of operations that someone can use from ftc, like:
ftc reboot-board -b <board>
ftc power-on-board -b <board>
ftc power-off-board -b <board>
and maybe even
ftc show-status-of-board <board>
In some labs, there may be a layer between pdudaemon and Fuego (for example libvirt,
or labgrid or even LAVA).
I think I'd rather have an abstraction layer between Fuego and pdudaemon, rather than
integrating it directly into our user interface.
Thoughts?
-- tim
> -----Original Message-----
> From: Daniel Sangorrin
>
> This patch adds the "pdu" command to send requests for pdudaemon
> to power-on/off or reboot a board.
>
> Signed-off-by: Daniel Sangorrin <daniel.sangorrin at toshiba.co.jp>
> ---
> scripts/ftc | 80
> +++++++++++++++++++++++++++++++++++++++++++++++
> scripts/ftc_completion.sh | 5 +++
> 2 files changed, 85 insertions(+)
>
> diff --git a/scripts/ftc b/scripts/ftc
> index 7153c01..30ea470 100755
> --- a/scripts/ftc
> +++ b/scripts/ftc
> @@ -426,6 +426,29 @@ A message and the exit code indicate if the resource
> was released.
>
> ex: ftc release-resource -b beaglebone"""),
>
> +"pdu": ("Send a request to pdudaemon.",
> + """Usage: ftc pdu -b <board> --command on|off|reboot [--
> pdudaemon_hostname localhost --pdudaemon_port 16421]
> +
> +This command is used to send a request for pdudaemon to power-on,
> power-off or reboot a board.
> +
> +The command accepts these arguments:
> + - board file: bbb, raspberrypi3, etc (see ftc list-boards)
> + - command: on|off|reboot
> + - pdudaemon_hostname: hostname or IP address where pdudaemon is
> running (default: localhost)
> + - pdudaemon_port: port where pdudaemon is listening (default: 16421)
> + [Note] make sure that pdudaemon is configured to accept http requests
> +
> +Additionally, you need to define two variables in your board file:
> + - PDU_HOSTNAME: the PDU hostname or IP address used in the
> pdudaemon configuration file
> + - PDU_PORT: the PDU port number (a plug port, not a tcp port)
> +
> +You need to install pdudaemon by yourself
> + $ git clone https://github.com/pdudaemon/pdudaemon
> + $ cd pdudaemon
> + $ less README.md
> +
> +Example: ftc pdu -b raspberrypi3 --command on"""),
> +
> "package-test": ("Package a test.",
> """Usage: ftc package-test <test_name> [options]
>
> @@ -4783,6 +4806,59 @@ def do_release_resource(conf, options):
>
> return 0
>
> +def do_pdu(bvars, conf, options):
> + # pdudaemon hostname
> + pdudaemon_hostname = 'localhost'
> + if '--pdudaemon_hostname' in options:
> + try:
> + pdudaemon_hostname = options[options.index('--
> pdudaemon_hostname')+1]
> + except IndexError:
> + error_out('Value not provided after --pdudaemon_hostname')
> + options.remove(pdudaemon_hostname)
> + options.remove('--pdudaemon_hostname')
> +
> + # pdudaemon port
> + pdudaemon_port = '16421'
> + if '--pdudaemon_port' in options:
> + try:
> + pdudaemon_port = options[options.index('--pdudaemon_port')+1]
> + except IndexError:
> + error_out('Value not provided after --pdudaemon_port')
> + options.remove(pdudaemon_port)
> + options.remove('--pdudaemon_port')
> +
> + # pdu hostname
> + if 'PDU_HOSTNAME' in bvars:
> + pdu_hostname = bvars['PDU_HOSTNAME']
> + else:
> + error_out('PDU_HOSTNAME not specified in board file')
> +
> + # pdu port
> + if 'PDU_PORT' in bvars:
> + pdu_port = bvars['PDU_PORT']
> + else:
> + error_out('PDU_PORT not specified in board file')
> +
> + # command (on|off|reboot)
> + if '--command' in options:
> + try:
> + command = options[options.index('--command')+1]
> + except IndexError:
> + error_out('Value not provided after --command')
> + options.remove(command)
> + options.remove('--command')
> + if command not in ['on', 'off', 'reboot']:
> + error_out('Unrecognized PDU command %s' % command)
> + else:
> + error_out('Command not supplied')
> +
> + query='&'.join(['hostname='+pdu_hostname, 'port='+pdu_port])
> + url = 'http://%s:%s/power/control/%s?%s' % (pdudaemon_hostname,
> pdudaemon_port, command, query)
> + resp = requests.get(url)
> + if resp.status_code != 200:
> + error_out("pdudaemon did not accept the request")
> + return 0
> +
> def main():
> # use global module names
> global re, time, copy2, subprocess, signal, fcntl, requests, json
> @@ -5094,6 +5170,10 @@ def main():
> do_delete_var(bvars, options)
> sys.exit(0)
>
> + if command == "pdu":
> + rcode = do_pdu(bvars, conf, options)
> + sys.exit(rcode)
> +
> error_out("Unknown command %s" % command)
>
>
> diff --git a/scripts/ftc_completion.sh b/scripts/ftc_completion.sh
> index 984e003..2cfb77a 100755
> --- a/scripts/ftc_completion.sh
> +++ b/scripts/ftc_completion.sh
> @@ -55,6 +55,7 @@ _ftc()
> ["list-tests"]="-q"
> ["package-run"]="-o -f"
> ["package-test"]="-o -f"
> + ["pdu"]="-b --command --pdudaemon_hostname --pdudaemon_port"
> ["put-request"]="-R -s"
> ["put-run"]=""
> ["put-test"]=""
> @@ -123,6 +124,10 @@ _ftc()
> COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
> return 0
> ;;
> + '--command')
> + COMPREPLY=( $( compgen -W "on off reboot" -- "$cur" ) )
> + return 0
> + ;;
> 'put-run')
> COMPREPLY=( $( compgen -W "$(ftc list-runs -q)" -- "$cur" ) )
> return 0
> --
> 2.7.4
>
> _______________________________________________
> Fuego mailing list
> Fuego at lists.linuxfoundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/fuego
More information about the Fuego
mailing list