Skip to content

Commit

Permalink
add workaround for applying MOs without a Name attribute
Browse files Browse the repository at this point in the history
MOs without a Name attribute will always execute a POST rather than checking and updating
  • Loading branch information
cgascoig committed Apr 5, 2024
1 parent 3a27ea1 commit 625b361
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions tests/apply.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions tests/data/test-appliance-device-claim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ClassId: appliance.DeviceClaim
PlatformType: IMC
Hostname: 192.168.9.10
Username: admin
Password: "<redacted>"

0 comments on commit 625b361

Please sign in to comment.