From 625b361cd8010e78e38eac1c9092495c161c21e8 Mon Sep 17 00:00:00 2001 From: Chris Gascoigne Date: Fri, 5 Apr 2024 11:53:54 +1100 Subject: [PATCH] add workaround for applying MOs without a Name attribute MOs without a Name attribute will always execute a POST rather than checking and updating --- cmd/apply.go | 3 ++- tests/apply.bats | 12 ++++++++++++ tests/data/test-appliance-device-claim.yaml | 5 +++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/data/test-appliance-device-claim.yaml diff --git a/cmd/apply.go b/cmd/apply.go index 179d281b..58f34d1d 100644 --- a/cmd/apply.go +++ b/cmd/apply.go @@ -131,7 +131,8 @@ func applyMOs(client *util.IsctlClient, rawMOs []rawMO) error { var op *gen.Operation getOperation := gen.GetGetOperationForClassID(classID) - if getOperation == nil { + _, moHasName := mo["Name"] + if getOperation == nil || !moHasName { op = gen.GetCreateOperationForClassID(classID) if op == nil { return fmt.Errorf("no create operation for ClassId %s", classID) diff --git a/tests/apply.bats b/tests/apply.bats index 611e5bab..e047fde9 100644 --- a/tests/apply.bats +++ b/tests/apply.bats @@ -68,6 +68,18 @@ TEST_SECTION="Apply" run ./build/isctl ${ISCTL_OPTIONS} delete server profiletemplate name "${TEST_NAME}" } +@test "${TEST_SECTION}: apply for MO with no Name attribute" { + run ./build/isctl ${ISCTL_OPTIONS} apply -f tests/data/test-appliance-device-claim.yaml + # this should fail because we're are testing against SaaS, not an appliance but as long as the error code matches we know the request was sent properly + assert_failure + assert_line --partial "Performing create operation on new MO (ClassId: appliance.DeviceClaim)" + assert_line --partial "Error while applying MOs: error executing operation: request failed: 403 Forbidden: Operation not supported." +} + +setup() { + load 'test_helper/bats-support/load' # this is required by bats-assert! + load 'test_helper/bats-assert/load' +} setup_file() { # delete the test objects if they already exist. Don't check the exit code. diff --git a/tests/data/test-appliance-device-claim.yaml b/tests/data/test-appliance-device-claim.yaml new file mode 100644 index 00000000..e48e28af --- /dev/null +++ b/tests/data/test-appliance-device-claim.yaml @@ -0,0 +1,5 @@ +ClassId: appliance.DeviceClaim +PlatformType: IMC +Hostname: 192.168.9.10 +Username: admin +Password: ""