From c6d7b605e023c80a6156be92b6e1a986cedfb801 Mon Sep 17 00:00:00 2001 From: Jacob Salmela Date: Tue, 22 Aug 2023 09:23:42 -0500 Subject: [PATCH 1/2] update node by passing --uuid Signed-off-by: Jacob Salmela --- cmd/node/init.go | 3 +++ cmd/node/update_node.go | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/cmd/node/init.go b/cmd/node/init.go index 1f939436..74399a77 100644 --- a/cmd/node/init.go +++ b/cmd/node/init.go @@ -39,6 +39,7 @@ var ( subrole string nid int alias string + nodeUuid string format string sortBy string ) @@ -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") } diff --git a/cmd/node/update_node.go b/cmd/node/update_node.go index 490334d5..e515fa31 100644 --- a/cmd/node/update_node.go +++ b/cmd/node/update_node.go @@ -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" ) @@ -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? From 13f6f2897783b57dc3696cbfd2e8c41b7b55f9eb Mon Sep 17 00:00:00 2001 From: Jacob Salmela Date: Tue, 22 Aug 2023 13:25:45 -0500 Subject: [PATCH 2/2] add update node --uuid test Signed-off-by: Jacob Salmela --- spec/cani_update_node_spec.sh | 57 +++ spec/spec_helper.sh | 6 + .../canitestdb_valid_ex2000_one_blade.json | 436 ++++++++++++++++++ 3 files changed, 499 insertions(+) create mode 100644 spec/cani_update_node_spec.sh create mode 100644 testdata/fixtures/cani/configs/canitestdb_valid_ex2000_one_blade.json diff --git a/spec/cani_update_node_spec.sh b/spec/cani_update_node_spec.sh new file mode 100644 index 00000000..d0bdcf49 --- /dev/null +++ b/spec/cani_update_node_spec.sh @@ -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 diff --git a/spec/spec_helper.sh b/spec/spec_helper.sh index 36ab4197..338d4e3a 100644 --- a/spec/spec_helper.sh +++ b/spec/spec_helper.sh @@ -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 @@ -123,6 +128,7 @@ spec_helper_configure() { #shellcheck disable=SC2317 cp "$FIXTURES"/cani/configs/canitestdb_valid_ex4000_only.json canitestdb.json } + } diff --git a/testdata/fixtures/cani/configs/canitestdb_valid_ex2000_one_blade.json b/testdata/fixtures/cani/configs/canitestdb_valid_ex2000_one_blade.json new file mode 100644 index 00000000..7945b686 --- /dev/null +++ b/testdata/fixtures/cani/configs/canitestdb_valid_ex2000_one_blade.json @@ -0,0 +1,436 @@ +{ + "SchemaVersion": "v1alpha1", + "Provider": "csm", + "Hardware": { + "05b4d2c1-2a15-4527-9ff9-315b55fcaba4": { + "ID": "05b4d2c1-2a15-4527-9ff9-315b55fcaba4", + "Type": "Chassis", + "DeviceTypeSlug": "hpe-crayex-chassis", + "Vendor": "HPE", + "Model": "CrayEX liquid-cooled cabinet chassis", + "Status": "staged", + "Parent": "30f99fb5-fbff-49df-9e78-134ce7778478", + "Children": [ + "4cd4b532-b18f-4786-8286-c4343e921210" + ], + "LocationPath": [ + { + "HardwareType": "System", + "Ordinal": 0 + }, + { + "HardwareType": "Cabinet", + "Ordinal": 9000 + }, + { + "HardwareType": "Chassis", + "Ordinal": 3 + } + ], + "LocationOrdinal": 3 + }, + "07853d8f-0e6a-4926-9574-dd317ac8758e": { + "ID": "07853d8f-0e6a-4926-9574-dd317ac8758e", + "Type": "NodeCard", + "DeviceTypeSlug": "hpe-crayex-ex235a-compute-blade-bard-peak-node-card", + "Vendor": "HPE", + "Model": "EX235A AMD MI200 accelerator blade, Bard Peak Node Card (BPNC)", + "Status": "staged", + "Parent": "1d87f035-6c89-4670-a86d-61bb09f1928c", + "Children": [ + "77969c13-fd76-4eb2-bf87-f12ef813db3f", + "d28c3201-9dfa-4788-852f-86054cd99232" + ], + "LocationPath": [ + { + "HardwareType": "System", + "Ordinal": 0 + }, + { + "HardwareType": "Cabinet", + "Ordinal": 9000 + }, + { + "HardwareType": "Chassis", + "Ordinal": 1 + }, + { + "HardwareType": "NodeBlade", + "Ordinal": 0 + }, + { + "HardwareType": "NodeCard", + "Ordinal": 0 + } + ], + "LocationOrdinal": 0 + }, + "1d87f035-6c89-4670-a86d-61bb09f1928c": { + "ID": "1d87f035-6c89-4670-a86d-61bb09f1928c", + "Type": "NodeBlade", + "DeviceTypeSlug": "hpe-crayex-ex235a-compute-blade", + "Vendor": "HPE", + "Model": "EX235A AMD MI200 accelerator blade (Bard Peak)", + "Status": "staged", + "Parent": "edb7775e-46d3-4f0f-bbf0-d4b992438e57", + "Children": [ + "07853d8f-0e6a-4926-9574-dd317ac8758e", + "89c800f9-bb4b-4950-906d-c66a0476ef47" + ], + "LocationPath": [ + { + "HardwareType": "System", + "Ordinal": 0 + }, + { + "HardwareType": "Cabinet", + "Ordinal": 9000 + }, + { + "HardwareType": "Chassis", + "Ordinal": 1 + }, + { + "HardwareType": "NodeBlade", + "Ordinal": 0 + } + ], + "LocationOrdinal": 0 + }, + "30f99fb5-fbff-49df-9e78-134ce7778478": { + "ID": "30f99fb5-fbff-49df-9e78-134ce7778478", + "Type": "Cabinet", + "DeviceTypeSlug": "hpe-ex2000", + "Vendor": "HPE", + "Model": "EX2000", + "Status": "staged", + "ProviderMetadata": { + "csm": { + "Cabinet": { + "HMNVlan": 3000 + } + } + }, + "Parent": "abcdef12-3456-2789-abcd-ef1234567890", + "Children": [ + "05b4d2c1-2a15-4527-9ff9-315b55fcaba4", + "50aa9384-55e8-4913-96e9-b71e0d8ad74e", + "edb7775e-46d3-4f0f-bbf0-d4b992438e57" + ], + "LocationPath": [ + { + "HardwareType": "System", + "Ordinal": 0 + }, + { + "HardwareType": "Cabinet", + "Ordinal": 9000 + } + ], + "LocationOrdinal": 9000 + }, + "495d2130-2cbf-4dc6-95f6-e2bde6945d7e": { + "ID": "495d2130-2cbf-4dc6-95f6-e2bde6945d7e", + "Type": "ChassisManagementModule", + "DeviceTypeSlug": "hpe-crayex-chassis-management-module", + "Vendor": "HPE", + "Model": "CrayEX Chassis Management Module", + "Status": "staged", + "Parent": "edb7775e-46d3-4f0f-bbf0-d4b992438e57", + "LocationPath": [ + { + "HardwareType": "System", + "Ordinal": 0 + }, + { + "HardwareType": "Cabinet", + "Ordinal": 9000 + }, + { + "HardwareType": "Chassis", + "Ordinal": 1 + }, + { + "HardwareType": "ChassisManagementModule", + "Ordinal": 0 + } + ], + "LocationOrdinal": 0 + }, + "4c4f1867-a742-47fe-b8ed-539cd3ded8e7": { + "ID": "4c4f1867-a742-47fe-b8ed-539cd3ded8e7", + "Type": "NodeController", + "DeviceTypeSlug": "hpe-crayex-ex235a-compute-blade-bard-peak-node-bmc", + "Vendor": "HPE", + "Model": "EX235A AMD MI200 accelerator blade, Bard Peak Node BMC", + "Status": "staged", + "Parent": "89c800f9-bb4b-4950-906d-c66a0476ef47", + "LocationPath": [ + { + "HardwareType": "System", + "Ordinal": 0 + }, + { + "HardwareType": "Cabinet", + "Ordinal": 9000 + }, + { + "HardwareType": "Chassis", + "Ordinal": 1 + }, + { + "HardwareType": "NodeBlade", + "Ordinal": 0 + }, + { + "HardwareType": "NodeCard", + "Ordinal": 1 + }, + { + "HardwareType": "NodeController", + "Ordinal": 0 + } + ], + "LocationOrdinal": 0 + }, + "4cd4b532-b18f-4786-8286-c4343e921210": { + "ID": "4cd4b532-b18f-4786-8286-c4343e921210", + "Type": "ChassisManagementModule", + "DeviceTypeSlug": "hpe-crayex-chassis-management-module", + "Vendor": "HPE", + "Model": "CrayEX Chassis Management Module", + "Status": "staged", + "Parent": "05b4d2c1-2a15-4527-9ff9-315b55fcaba4", + "LocationPath": [ + { + "HardwareType": "System", + "Ordinal": 0 + }, + { + "HardwareType": "Cabinet", + "Ordinal": 9000 + }, + { + "HardwareType": "Chassis", + "Ordinal": 3 + }, + { + "HardwareType": "ChassisManagementModule", + "Ordinal": 0 + } + ], + "LocationOrdinal": 0 + }, + "50aa9384-55e8-4913-96e9-b71e0d8ad74e": { + "ID": "50aa9384-55e8-4913-96e9-b71e0d8ad74e", + "Type": "CabinetEnvironmentalController", + "DeviceTypeSlug": "hpe-crayex-cabinet-environmental-controller", + "Vendor": "HPE", + "Model": "CrayEX Cabinet Environmental Controller", + "Status": "staged", + "Parent": "30f99fb5-fbff-49df-9e78-134ce7778478", + "LocationPath": [ + { + "HardwareType": "System", + "Ordinal": 0 + }, + { + "HardwareType": "Cabinet", + "Ordinal": 9000 + }, + { + "HardwareType": "CabinetEnvironmentalController", + "Ordinal": 0 + } + ], + "LocationOrdinal": 0 + }, + "77969c13-fd76-4eb2-bf87-f12ef813db3f": { + "ID": "77969c13-fd76-4eb2-bf87-f12ef813db3f", + "Type": "NodeController", + "DeviceTypeSlug": "hpe-crayex-ex235a-compute-blade-bard-peak-node-bmc", + "Vendor": "HPE", + "Model": "EX235A AMD MI200 accelerator blade, Bard Peak Node BMC", + "Status": "staged", + "Parent": "07853d8f-0e6a-4926-9574-dd317ac8758e", + "LocationPath": [ + { + "HardwareType": "System", + "Ordinal": 0 + }, + { + "HardwareType": "Cabinet", + "Ordinal": 9000 + }, + { + "HardwareType": "Chassis", + "Ordinal": 1 + }, + { + "HardwareType": "NodeBlade", + "Ordinal": 0 + }, + { + "HardwareType": "NodeCard", + "Ordinal": 0 + }, + { + "HardwareType": "NodeController", + "Ordinal": 0 + } + ], + "LocationOrdinal": 0 + }, + "89c800f9-bb4b-4950-906d-c66a0476ef47": { + "ID": "89c800f9-bb4b-4950-906d-c66a0476ef47", + "Type": "NodeCard", + "DeviceTypeSlug": "hpe-crayex-ex235a-compute-blade-bard-peak-node-card", + "Vendor": "HPE", + "Model": "EX235A AMD MI200 accelerator blade, Bard Peak Node Card (BPNC)", + "Status": "staged", + "Parent": "1d87f035-6c89-4670-a86d-61bb09f1928c", + "Children": [ + "4c4f1867-a742-47fe-b8ed-539cd3ded8e7", + "8ab879e0-f269-4c88-aaf4-4a345985d41e" + ], + "LocationPath": [ + { + "HardwareType": "System", + "Ordinal": 0 + }, + { + "HardwareType": "Cabinet", + "Ordinal": 9000 + }, + { + "HardwareType": "Chassis", + "Ordinal": 1 + }, + { + "HardwareType": "NodeBlade", + "Ordinal": 0 + }, + { + "HardwareType": "NodeCard", + "Ordinal": 1 + } + ], + "LocationOrdinal": 1 + }, + "8ab879e0-f269-4c88-aaf4-4a345985d41e": { + "ID": "8ab879e0-f269-4c88-aaf4-4a345985d41e", + "Type": "Node", + "DeviceTypeSlug": "hpe-crayex-ex235a-compute-node", + "Vendor": "HPE", + "Model": "EX235A AMD MI200 accelerator compute node", + "Status": "staged", + "Parent": "89c800f9-bb4b-4950-906d-c66a0476ef47", + "LocationPath": [ + { + "HardwareType": "System", + "Ordinal": 0 + }, + { + "HardwareType": "Cabinet", + "Ordinal": 9000 + }, + { + "HardwareType": "Chassis", + "Ordinal": 1 + }, + { + "HardwareType": "NodeBlade", + "Ordinal": 0 + }, + { + "HardwareType": "NodeCard", + "Ordinal": 1 + }, + { + "HardwareType": "Node", + "Ordinal": 0 + } + ], + "LocationOrdinal": 0 + }, + "abcdef12-3456-2789-abcd-ef1234567890": { + "ID": "abcdef12-3456-2789-abcd-ef1234567890", + "Type": "System", + "Parent": "00000000-0000-0000-0000-000000000000", + "Children": [ + "30f99fb5-fbff-49df-9e78-134ce7778478" + ], + "LocationPath": [ + { + "HardwareType": "System", + "Ordinal": 0 + } + ], + "LocationOrdinal": 0 + }, + "d28c3201-9dfa-4788-852f-86054cd99232": { + "ID": "d28c3201-9dfa-4788-852f-86054cd99232", + "Type": "Node", + "DeviceTypeSlug": "hpe-crayex-ex235a-compute-node", + "Vendor": "HPE", + "Model": "EX235A AMD MI200 accelerator compute node", + "Status": "staged", + "Parent": "07853d8f-0e6a-4926-9574-dd317ac8758e", + "LocationPath": [ + { + "HardwareType": "System", + "Ordinal": 0 + }, + { + "HardwareType": "Cabinet", + "Ordinal": 9000 + }, + { + "HardwareType": "Chassis", + "Ordinal": 1 + }, + { + "HardwareType": "NodeBlade", + "Ordinal": 0 + }, + { + "HardwareType": "NodeCard", + "Ordinal": 0 + }, + { + "HardwareType": "Node", + "Ordinal": 0 + } + ], + "LocationOrdinal": 0 + }, + "edb7775e-46d3-4f0f-bbf0-d4b992438e57": { + "ID": "edb7775e-46d3-4f0f-bbf0-d4b992438e57", + "Type": "Chassis", + "DeviceTypeSlug": "hpe-crayex-chassis", + "Vendor": "HPE", + "Model": "CrayEX liquid-cooled cabinet chassis", + "Status": "staged", + "Parent": "30f99fb5-fbff-49df-9e78-134ce7778478", + "Children": [ + "1d87f035-6c89-4670-a86d-61bb09f1928c", + "495d2130-2cbf-4dc6-95f6-e2bde6945d7e" + ], + "LocationPath": [ + { + "HardwareType": "System", + "Ordinal": 0 + }, + { + "HardwareType": "Cabinet", + "Ordinal": 9000 + }, + { + "HardwareType": "Chassis", + "Ordinal": 1 + } + ], + "LocationOrdinal": 1 + } + } +} \ No newline at end of file