Add strong typing for baremetal power statuses
Baremetal host power statuses are handled as strings in airshipctl. Invoking remotedirect on a host that is powered off will result in a remotedirect failure; therefore, the power status of a host needs to be verified before remotedirect can begin. This change adds strict typing to baremetal power statuses so airshipctl can verify the status of a remote host before performing remotedirect regardless of the client type (e.g. redfish, other). Change-Id: I22f1784006add018ee1d67c18f94499aa9544752 Signed-off-by: Drew Walters <andrew.walters@att.com>changes/59/724759/8
parent
54d7b5f229
commit
69e8c886fe
@ -0,0 +1,45 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package power safely translates power information between different management clients.
|
||||
package power
|
||||
|
||||
const (
|
||||
// StatusUnknown indicates that a baremetal host is in an unknown power state.
|
||||
StatusUnknown Status = iota
|
||||
// StatusOn indicates that a baremetal host is powered on.
|
||||
StatusOn
|
||||
// StatusOff indicates that a baremetal host is not powered on.
|
||||
StatusOff
|
||||
// StatusPoweringOn indicates that a baremetal host is powering on.
|
||||
StatusPoweringOn
|
||||
// StatusPoweringOff indicates that a baremetal host is powering off.
|
||||
StatusPoweringOff
|
||||
)
|
||||
|
||||
// Status indicates the power status of a baremetal host e.g. on, off, unknown.
|
||||
type Status int
|
||||
|
||||
var statusMap = [5]string{
|
||||
"UNKNOWN",
|
||||
"ON",
|
||||
"OFF",
|
||||
"POWERING ON",
|
||||
"POWERING OFF",
|
||||
}
|
||||
|
||||
// String provides a human-readable string value for a power status.
|
||||
func (s Status) String() string {
|
||||
return statusMap[s]
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package power
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStatus(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
status Status
|
||||
}{
|
||||
{
|
||||
name: "StatusUnknown",
|
||||
status: StatusUnknown,
|
||||
},
|
||||
{
|
||||
name: "StatusOn",
|
||||
status: StatusOn,
|
||||
},
|
||||
{
|
||||
name: "StatusOff",
|
||||
status: StatusOff,
|
||||
},
|
||||
{
|
||||
name: "StatusPoweringOn",
|
||||
status: StatusPoweringOn,
|
||||
},
|
||||
{
|
||||
name: "StatusPoweringOff",
|
||||
status: StatusPoweringOff,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
test := test
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
assert.Equal(t, statusMap[test.status], test.status.String())
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue