From b8bc3da644e4d3f26354edef800459140d37ea64 Mon Sep 17 00:00:00 2001 From: Russell Bunch Date: Fri, 14 Jun 2024 15:25:38 -0500 Subject: [PATCH] Fixes 60 - `off` and `cycle` (#61) * Fixes 60 - `off` and `cycle` `power off` and `power cycle` had `Args: cobra.MinimumNArgs(1)` set. This was previously removed for several other commands because it broke piping. When piping occurs, at least with how `gru` accepts piped arguments, the `args[]` slice is empty. In order for piping to work, we can not set a minimum number of arguments. There may be another way to handle piping, assuming there's a way to get in front of Cobra. * add power cycle tests and update power off to use STDIN (#66) * add power cycle tests and update power off to use STDIN Signed-off-by: Jacob Salmela * Update spec/functional/chassis_power_cycle_spec.sh --------- Signed-off-by: Jacob Salmela Co-authored-by: Russell Bunch --------- Signed-off-by: Jacob Salmela Co-authored-by: Jacob Salmela --- pkg/cmd/cli/chassis/power/cycle.go | 1 - pkg/cmd/cli/chassis/power/off.go | 1 - spec/functional/chassis_power_cycle_spec.sh | 56 +++++++++++++++++++++ spec/functional/chassis_power_off_spec.sh | 15 ++++++ 4 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 spec/functional/chassis_power_cycle_spec.sh diff --git a/pkg/cmd/cli/chassis/power/cycle.go b/pkg/cmd/cli/chassis/power/cycle.go index 2882093..43b1162 100644 --- a/pkg/cmd/cli/chassis/power/cycle.go +++ b/pkg/cmd/cli/chassis/power/cycle.go @@ -43,7 +43,6 @@ func NewPowerCycleCommand() *cobra.Command { Short: "Power cycle the target machine(s)", Long: `Performs an ACPI shutdown and startup to power cycle the target machine(s). Also allows bypassing the OS shutdown, forcing a warm boot.`, - Args: cobra.MinimumNArgs(1), Run: func(c *cobra.Command, args []string) { var resetType redfish.ResetType diff --git a/pkg/cmd/cli/chassis/power/off.go b/pkg/cmd/cli/chassis/power/off.go index b07c739..fa6161f 100644 --- a/pkg/cmd/cli/chassis/power/off.go +++ b/pkg/cmd/cli/chassis/power/off.go @@ -44,7 +44,6 @@ func NewPowerOffCommand() *cobra.Command { Long: `Powers off the target machine(s) with an ACPI shutdown. Permits forcing a shutdown (without waiting for the OS), as well as a power-button emulated shutdown.`, - Args: cobra.MinimumNArgs(1), Run: func(c *cobra.Command, args []string) { var resetType redfish.ResetType diff --git a/spec/functional/chassis_power_cycle_spec.sh b/spec/functional/chassis_power_cycle_spec.sh new file mode 100644 index 0000000..bfa1228 --- /dev/null +++ b/spec/functional/chassis_power_cycle_spec.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env sh +# MIT License +# +# (C) Copyright 2024 Hewlett Packard Enterprise Development LP +# +# Permissioff is hereby granted, free of charge, to any persoff obtaining a +# copy of this software and associated documentatioff files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permissioff notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTIoff OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTIoff WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. + + +Describe 'gru chassis power cycle' + +# Running against an active host with good credentials should succeed and show output +It "--config ${GRU_CONF} 127.0.0.1:5000" + BeforeCall use_valid_config + When call ./gru chassis power cycle --config "${GRU_CONF}" 127.0.0.1:5000 + The status should equal 0 + The line 1 of stderr should include 'Asynchronously updating' + The line 1 of stdout should equal '127.0.0.1:5000:' + The line 2 of stdout should include 'PreviousPowerState' + The line 3 of stdout should include 'RequestedPowerState' + The line 3 of stdout should include 'GracefulRestart' + The lines of stderr should equal 1 +End + +# validate piping to STDIN works +It "--config ${GRU_CONF} (via STDIN)" + BeforeCall use_valid_config + + Data "127.0.0.1:5000" # STDIN + + When call ./gru chassis power cycle --config "${GRU_CONF}" + The status should equal 0 + The line 1 of stderr should include 'Asynchronously updating' + The line 1 of stdout should equal '127.0.0.1:5000:' + The line 2 of stdout should include 'PowerState' + The line 3 of stdout should include 'GracefulRestart' + The line 4 of stdout should include "reset type 'GracefulRestart' is not supported by this service" + The lines of stderr should equal 1 +End + +End diff --git a/spec/functional/chassis_power_off_spec.sh b/spec/functional/chassis_power_off_spec.sh index e731f73..817d1ad 100644 --- a/spec/functional/chassis_power_off_spec.sh +++ b/spec/functional/chassis_power_off_spec.sh @@ -58,5 +58,20 @@ It "--config ${GRU_CONF} 127.0.0.1:5000" The line 2 of stdout should include 'Off' The lines of stderr should equal 1 End + +# validate piping to STDIN works +It "--config ${GRU_CONF}" + BeforeCall use_valid_config + + Data "127.0.0.1:5000" # STDIN + + When call ./gru chassis power off --config "${GRU_CONF}" + The status should equal 0 + The line 1 of stderr should include 'Asynchronously updating' + The line 1 of stdout should equal '127.0.0.1:5000:' + The line 2 of stdout should include 'PowerState' + The line 2 of stdout should include 'Off' + The lines of stdout should equal 3 +End End