Skip to content

Commit

Permalink
Merge pull request #127 from Cray-HPE/proper-vision
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsalmela committed Aug 23, 2023
2 parents 4d83d45 + 13f6f28 commit 01755eb
Show file tree
Hide file tree
Showing 5 changed files with 524 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/node/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
subrole string
nid int
alias string
nodeUuid string
format string
sortBy string
)
Expand Down Expand Up @@ -71,8 +72,10 @@ func init() {
UpdateNodeCmd.Flags().StringVar(&subrole, "subrole", "", "Subrole of the node")
UpdateNodeCmd.Flags().IntVar(&nid, "nid", 0, "NID of the node")
UpdateNodeCmd.Flags().StringVar(&alias, "alias", "", "Alias of the node")
UpdateNodeCmd.Flags().StringVar(&nodeUuid, "uuid", "", "UUID of the node to update")

UpdateNodeCmd.MarkFlagsRequiredTogether("cabinet", "chassis", "blade", "nodecard", "node")
UpdateNodeCmd.MarkFlagsMutuallyExclusive("uuid")
ListNodeCmd.Flags().StringVarP(&format, "format", "f", "pretty", "Format output")
ListNodeCmd.Flags().StringVarP(&sortBy, "sort", "s", "location", "Sort by a specific key")
}
22 changes: 22 additions & 0 deletions cmd/node/update_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/Cray-HPE/cani/internal/domain"
"github.com/Cray-HPE/cani/internal/provider"
"github.com/Cray-HPE/cani/internal/provider/csm"
"github.com/google/uuid"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -74,6 +75,27 @@ func updateNode(cmd *cobra.Command, args []string) error {
}

// Remove the node from the inventory using domain methods
if cmd.Flags().Changed("uuid") {
// parse the passed in uuid
u, err := uuid.Parse(nodeUuid)
if err != nil {
return err
}
// get the inventory
inv, err := d.List()
if err != nil {
return err
}
// if the hardware exists, extract the location ordinals for the user
if n, ok := inv.Hardware[u]; ok {
cabinet = n.LocationPath.GetOrdinalPath()[1]
chassis = n.LocationPath.GetOrdinalPath()[2]
blade = n.LocationPath.GetOrdinalPath()[3]
nodecard = n.LocationPath.GetOrdinalPath()[4]
node = n.LocationPath.GetOrdinalPath()[5]
}
}

result, err := d.UpdateNode(cmd.Context(), cabinet, chassis, blade, nodecard, node, nodeMeta)
if errors.Is(err, provider.ErrDataValidationFailure) {
// TODO the following should probably suggest commands to fix the issue?
Expand Down
57 changes: 57 additions & 0 deletions spec/cani_update_node_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env sh
# MIT License
#
# (C) Copyright 2023 Hewlett Packard Enterprise Development LP
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation 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 permission 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 ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

#TODO: parameterize
Describe 'cani update node'

# check auto adding each blade type to each cabinet type using the dynamic matrix above
It "validate blade exists"
BeforeCall use_active_session # session is active
BeforeCall use_valid_datastore_one_ex2000_one_blade # deploy a valid datastore with one cabinet
When call bin/cani alpha list blade --config canitest.yml
The status should equal 0
The line 2 of stdout should include '1d87f035-6c89-4670-a86d-61bb09f1928c'
End

It "validate nodes exist"
When call bin/cani alpha list node --config canitest.yml
The status should equal 0
The line 2 of stdout should include 'd28c3201-9dfa-4788-852f-86054cd99232'
The line 3 of stdout should include '8ab879e0-f269-4c88-aaf4-4a345985d41e'
End

It "update node --config canitest.yml --uuid 8ab879e0-f269-4c88-aaf4-4a345985d41e --role Application --subrole Worker"
When call bin/cani alpha update node --config canitest.yml --uuid 8ab879e0-f269-4c88-aaf4-4a345985d41e --role Application --subrole Worker
The status should equal 0
The line 1 of stderr should include 'Updated node'
End

It "validate node is updated"
When call bin/cani alpha list node --config canitest.yml
The status should equal 0
The line 3 of stdout should include '8ab879e0-f269-4c88-aaf4-4a345985d41e'
The line 3 of stdout should include 'Application'
The line 3 of stdout should include 'Worker'
End

End
6 changes: 6 additions & 0 deletions spec/spec_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ spec_helper_configure() {
cp "$FIXTURES"/cani/configs/canitestdb_valid_ex2000_only.json canitestdb.json
}

# deploys a datastore with one ex2000 cabinet (and one blade)
use_valid_datastore_one_ex2000_one_blade(){
#shellcheck disable=SC2317
cp "$FIXTURES"/cani/configs/canitestdb_valid_ex2000_one_blade.json canitestdb.json
}
# deploys a datastore with one ex2500_1 cabinet (and child hardware)
use_valid_datastore_one_ex2500_1_cabinet(){
#shellcheck disable=SC2317
Expand Down Expand Up @@ -123,6 +128,7 @@ spec_helper_configure() {
#shellcheck disable=SC2317
cp "$FIXTURES"/cani/configs/canitestdb_valid_ex4000_only.json canitestdb.json
}


}

Expand Down
Loading

0 comments on commit 01755eb

Please sign in to comment.