Skip to content

Commit

Permalink
Fixes 60 - off and cycle (#61)
Browse files Browse the repository at this point in the history
* 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 <jacob.salmela@hpe.com>

* Update spec/functional/chassis_power_cycle_spec.sh

---------

Signed-off-by: Jacob Salmela <jacob.salmela@hpe.com>
Co-authored-by: Russell Bunch <doomslayer@hpe.com>

---------

Signed-off-by: Jacob Salmela <jacob.salmela@hpe.com>
Co-authored-by: Jacob Salmela <me@jacobsalmela.com>
  • Loading branch information
rustydb and jacobsalmela authored Jun 14, 2024
1 parent 44d4b5d commit b8bc3da
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
1 change: 0 additions & 1 deletion pkg/cmd/cli/chassis/power/cycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion pkg/cmd/cli/chassis/power/off.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
56 changes: 56 additions & 0 deletions spec/functional/chassis_power_cycle_spec.sh
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions spec/functional/chassis_power_off_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b8bc3da

Please sign in to comment.