Skip to content

Commit

Permalink
fix: 404 on backupunit wait (#487)
Browse files Browse the repository at this point in the history
* fix: mark wait as hidden, make flag not do anything

* test: re-add wait to test

* test: update tests

* doc: fix docs

* doc: changelog

* test: expect no error
  • Loading branch information
avirtopeanu-ionos authored Feb 3, 2025
1 parent 74d723e commit ca6c200
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed

- Fixed not being able to use snapshot IDs for --image-id
- Fixed 404 when waiting for backupunits to be ready

## [v6.8.0] (January 2025)

Expand Down
48 changes: 30 additions & 18 deletions commands/cloudapi-v6/backupunit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import (

"github.com/ionos-cloud/ionosctl/v6/commands/cloudapi-v6/completer"
"github.com/ionos-cloud/ionosctl/v6/commands/cloudapi-v6/query"
"github.com/ionos-cloud/ionosctl/v6/commands/cloudapi-v6/waiter"
"github.com/ionos-cloud/ionosctl/v6/internal/constants"
"github.com/ionos-cloud/ionosctl/v6/internal/core"
"github.com/ionos-cloud/ionosctl/v6/internal/printer/json2table/jsonpaths"
"github.com/ionos-cloud/ionosctl/v6/internal/printer/jsontabwriter"
"github.com/ionos-cloud/ionosctl/v6/internal/printer/tabheaders"
"github.com/ionos-cloud/ionosctl/v6/internal/request"
"github.com/ionos-cloud/ionosctl/v6/internal/waitfor"
"github.com/ionos-cloud/ionosctl/v6/pkg/confirm"
cloudapiv6 "github.com/ionos-cloud/ionosctl/v6/services/cloudapi-v6"
"github.com/ionos-cloud/ionosctl/v6/services/cloudapi-v6/resources"
Expand Down Expand Up @@ -145,7 +143,9 @@ Required values to run a command:
create.AddStringFlag(cloudapiv6.ArgName, cloudapiv6.ArgNameShort, "", "Alphanumeric name you want to assign to the BackupUnit", core.RequiredFlagOption())
create.AddStringFlag(cloudapiv6.ArgEmail, cloudapiv6.ArgEmailShort, "", "The e-mail address you want to assign to the BackupUnit", core.RequiredFlagOption())
create.AddStringFlag(cloudapiv6.ArgPassword, cloudapiv6.ArgPasswordShort, "", "Alphanumeric password you want to assign to the BackupUnit", core.RequiredFlagOption())
create.AddBoolFlag(constants.ArgWaitForRequest, constants.ArgWaitForRequestShort, constants.DefaultWait, "Wait for the Request for BackupUnit creation to be executed")
create.AddBoolFlag(constants.ArgWaitForRequest, constants.ArgWaitForRequestShort, constants.DefaultWait,
"Wait for the Request for BackupUnit creation to be executed")
create.Command.Flags().MarkHidden(constants.ArgWaitForRequest) // Backupunit resources are not tracked by /requests endpoint yet - but keep the flag for backward compatibility
create.AddIntFlag(constants.ArgTimeout, constants.ArgTimeoutShort, constants.DefaultTimeoutSeconds, "Timeout option for Request for BackupUnit creation [seconds]")
create.AddInt32Flag(cloudapiv6.ArgDepth, cloudapiv6.ArgDepthShort, cloudapiv6.DefaultCreateDepth, cloudapiv6.ArgDepthDescription)

Expand Down Expand Up @@ -174,7 +174,9 @@ Required values to run command:
_ = update.Command.RegisterFlagCompletionFunc(cloudapiv6.ArgBackupUnitId, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completer.BackupUnitsIds(), cobra.ShellCompDirectiveNoFileComp
})
update.AddBoolFlag(constants.ArgWaitForRequest, constants.ArgWaitForRequestShort, constants.DefaultWait, "Wait for the Request for BackupUnit update to be executed")
update.AddBoolFlag(constants.ArgWaitForRequest, constants.ArgWaitForRequestShort, constants.DefaultWait,
"Wait for the Request for BackupUnit update to be executed")
update.Command.Flags().MarkHidden(constants.ArgWaitForRequest) // Backupunit resources are not tracked by /requests endpoint yet - but keep the flag for backward compatibility
update.AddIntFlag(constants.ArgTimeout, constants.ArgTimeoutShort, constants.DefaultTimeoutSeconds, "Timeout option for Request for BackupUnit update [seconds]")
update.AddInt32Flag(cloudapiv6.ArgDepth, cloudapiv6.ArgDepthShort, cloudapiv6.DefaultUpdateDepth, cloudapiv6.ArgDepthDescription)

Expand All @@ -201,7 +203,9 @@ Required values to run command:
_ = deleteCmd.Command.RegisterFlagCompletionFunc(cloudapiv6.ArgBackupUnitId, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completer.BackupUnitsIds(), cobra.ShellCompDirectiveNoFileComp
})
deleteCmd.AddBoolFlag(constants.ArgWaitForRequest, constants.ArgWaitForRequestShort, constants.DefaultWait, "Wait for the Request for BackupUnit deletion to be executed")
deleteCmd.AddBoolFlag(constants.ArgWaitForRequest, constants.ArgWaitForRequestShort, constants.DefaultWait,
"Wait for the Request for BackupUnit deletion to be executed")
deleteCmd.Command.Flags().MarkHidden(constants.ArgWaitForRequest) // Backupunit resources are not tracked by /requests endpoint yet - but keep the flag for backward compatibility
deleteCmd.AddBoolFlag(cloudapiv6.ArgAll, cloudapiv6.ArgAllShort, false, "Delete all BackupUnits.")
deleteCmd.AddIntFlag(constants.ArgTimeout, constants.ArgTimeoutShort, constants.DefaultTimeoutSeconds, "Timeout option for Request for BackupUnit deletion [seconds]")
deleteCmd.AddInt32Flag(cloudapiv6.ArgDepth, cloudapiv6.ArgDepthShort, cloudapiv6.DefaultDeleteDepth, cloudapiv6.ArgDepthDescription)
Expand Down Expand Up @@ -355,9 +359,11 @@ func RunBackupUnitCreate(c *core.CommandConfig) error {
return err
}

if err = waitfor.WaitForRequest(c, waiter.RequestInterrogator, request.GetId(resp)); err != nil {
return err
}
// Backupunit resources are not tracked by /requests endpoint.
// They are always returned in AVAILABLE state. But we keep the flag for backward-compatibility.
// if err = waitfor.WaitForRequest(c, waiter.RequestInterrogator, request.GetId(resp)); err != nil {
// return err
// }

fmt.Fprintf(c.Command.Command.OutOrStdout(), jsontabwriter.GenerateLogOutput(backupUnitNote))

Expand Down Expand Up @@ -388,9 +394,11 @@ func RunBackupUnitUpdate(c *core.CommandConfig) error {
return err
}

if err = waitfor.WaitForRequest(c, waiter.RequestInterrogator, request.GetId(resp)); err != nil {
return err
}
// Backupunit resources are not tracked by /requests endpoint.
// They are always returned in AVAILABLE state. But we keep the flag for backward-compatibility.
// if err = waitfor.WaitForRequest(c, waiter.RequestInterrogator, request.GetId(resp)); err != nil {
// return err
// }

cols := viper.GetStringSlice(core.GetFlagName(c.Resource, constants.ArgCols))

Expand Down Expand Up @@ -434,9 +442,11 @@ func RunBackupUnitDelete(c *core.CommandConfig) error {
return err
}

if err = waitfor.WaitForRequest(c, waiter.RequestInterrogator, request.GetId(resp)); err != nil {
return err
}
// Backupunit resources are not tracked by /requests endpoint.
// They are always returned in AVAILABLE state. But we keep the flag for backward-compatibility.
// if err = waitfor.WaitForRequest(c, waiter.RequestInterrogator, request.GetId(resp)); err != nil {
// return err
// }

fmt.Fprintf(c.Command.Command.OutOrStdout(), jsontabwriter.GenerateLogOutput("Backup Unit successfully deleted"))

Expand Down Expand Up @@ -530,10 +540,12 @@ func DeleteAllBackupUnits(c *core.CommandConfig) error {

fmt.Fprintf(c.Command.Command.ErrOrStderr(), jsontabwriter.GenerateLogOutput(constants.MessageDeletingAll, c.Resource, *id))

if err = waitfor.WaitForRequest(c, waiter.RequestInterrogator, request.GetId(resp)); err != nil {
multiErr = errors.Join(multiErr, fmt.Errorf(constants.ErrWaitDeleteAll, c.Resource, *id, err))
continue
}
// Backupunit resources are not tracked by /requests endpoint.
// They are always returned in AVAILABLE state. But we keep the flag for backward-compatibility.
// if err = waitfor.WaitForRequest(c, waiter.RequestInterrogator, request.GetId(resp)); err != nil {
// multiErr = errors.Join(multiErr, fmt.Errorf(constants.ErrWaitDeleteAll, c.Resource, *id, err))
// continue
// }
}

if multiErr != nil {
Expand Down
8 changes: 4 additions & 4 deletions commands/cloudapi-v6/backupunit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func TestRunBackupUnitCreateWaitErr(t *testing.T) {
viper.Set(core.GetFlagName(cfg.NS, cloudapiv6.ArgEmail), testBackupUnitVar)
viper.Set(core.GetFlagName(cfg.NS, cloudapiv6.ArgPassword), testBackupUnitVar)
rm.CloudApiV6Mocks.BackupUnit.EXPECT().Create(backupUnitTest, gomock.AssignableToTypeOf(testQueryParamOther)).Return(&backupUnitTest, &testResponse, nil)
rm.CloudApiV6Mocks.Request.EXPECT().GetStatus(testRequestIdVar).Return(&testRequestStatus, nil, nil)
// Note: in #487 we no longer expect a status check when using -w , as backupunits are not registered on /requests
err := RunBackupUnitCreate(cfg)
assert.NoError(t, err)
})
Expand Down Expand Up @@ -421,9 +421,9 @@ func TestRunBackupUnitUpdateWaitErr(t *testing.T) {
viper.Set(core.GetFlagName(cfg.NS, cloudapiv6.ArgPassword), testBackupUnitNewVar)
viper.Set(core.GetFlagName(cfg.NS, cloudapiv6.ArgEmail), testBackupUnitNewVar)
rm.CloudApiV6Mocks.BackupUnit.EXPECT().Update(testBackupUnitVar, backupUnitProperties, gomock.AssignableToTypeOf(testQueryParamOther)).Return(&backupUnitNew, &testResponse, nil)
rm.CloudApiV6Mocks.Request.EXPECT().GetStatus(testRequestIdVar).Return(&testRequestStatus, nil, testRequestErr)
// Note: in #487 we no longer expect a status check when using -w , as backupunits are not registered on /requests
err := RunBackupUnitUpdate(cfg)
assert.Error(t, err)
assert.NoError(t, err)
})
}

Expand Down Expand Up @@ -564,7 +564,7 @@ func TestRunBackupUnitDeleteWaitErr(t *testing.T) {
viper.Set(core.GetFlagName(cfg.NS, cloudapiv6.ArgBackupUnitId), testBackupUnitVar)
viper.Set(core.GetFlagName(cfg.NS, constants.ArgWaitForRequest), true)
rm.CloudApiV6Mocks.BackupUnit.EXPECT().Delete(testBackupUnitVar, gomock.AssignableToTypeOf(testQueryParamOther)).Return(&testResponse, nil)
rm.CloudApiV6Mocks.Request.EXPECT().GetStatus(testRequestIdVar).Return(&testRequestStatus, nil, nil)
// Note: in #487 we no longer expect a status check when using -w , as backupunits are not registered on /requests
err := RunBackupUnitDelete(cfg)
assert.NoError(t, err)
})
Expand Down
31 changes: 15 additions & 16 deletions docs/subcommands/Managed-Backup/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,21 @@ Required values to run a command:
## Options

```text
-u, --api-url string Override default host url (default "https://api.ionos.com")
--cols strings Set of columns to be printed on output
Available columns: [BackupUnitId Name Email State] (default [BackupUnitId,Name,Email,State])
-c, --config string Configuration file used for authentication (default "$XDG_CONFIG_HOME/ionosctl/config.json")
-D, --depth int32 Controls the detail depth of the response objects. Max depth is 10.
-e, --email string The e-mail address you want to assign to the BackupUnit (required)
-f, --force Force command to execute without user input
-h, --help Print usage
-n, --name string Alphanumeric name you want to assign to the BackupUnit (required)
--no-headers Don't print table headers when table output is used
-o, --output string Desired output format [text|json|api-json] (default "text")
-p, --password string Alphanumeric password you want to assign to the BackupUnit (required)
-q, --quiet Quiet output
-t, --timeout int Timeout option for Request for BackupUnit creation [seconds] (default 60)
-v, --verbose Print step-by-step process when running command
-w, --wait-for-request Wait for the Request for BackupUnit creation to be executed
-u, --api-url string Override default host url (default "https://api.ionos.com")
--cols strings Set of columns to be printed on output
Available columns: [BackupUnitId Name Email State] (default [BackupUnitId,Name,Email,State])
-c, --config string Configuration file used for authentication (default "$XDG_CONFIG_HOME/ionosctl/config.json")
-D, --depth int32 Controls the detail depth of the response objects. Max depth is 10.
-e, --email string The e-mail address you want to assign to the BackupUnit (required)
-f, --force Force command to execute without user input
-h, --help Print usage
-n, --name string Alphanumeric name you want to assign to the BackupUnit (required)
--no-headers Don't print table headers when table output is used
-o, --output string Desired output format [text|json|api-json] (default "text")
-p, --password string Alphanumeric password you want to assign to the BackupUnit (required)
-q, --quiet Quiet output
-t, --timeout int Timeout option for Request for BackupUnit creation [seconds] (default 60)
-v, --verbose Print step-by-step process when running command
```

## Examples
Expand Down
1 change: 0 additions & 1 deletion docs/subcommands/Managed-Backup/delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ Required values to run command:
-q, --quiet Quiet output
-t, --timeout int Timeout option for Request for BackupUnit deletion [seconds] (default 60)
-v, --verbose Print step-by-step process when running command
-w, --wait-for-request Wait for the Request for BackupUnit deletion to be executed
```

## Examples
Expand Down
1 change: 0 additions & 1 deletion docs/subcommands/Managed-Backup/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ Required values to run command:
-q, --quiet Quiet output
-t, --timeout int Timeout option for Request for BackupUnit update [seconds] (default 60)
-v, --verbose Print step-by-step process when running command
-w, --wait-for-request Wait for the Request for BackupUnit update to be executed
```

## Examples
Expand Down
2 changes: 1 addition & 1 deletion test/bats/cloudapi/volume.bats
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ setup_file() {
export IONOS_PASSWORD="$(cat /tmp/bats_test/password)"

run ionosctl backupunit create --name "bats$(randStr 6)" --email "$(cat /tmp/bats_test/email)" \
--password "$(cat /tmp/bats_test/password)" -o json 2> /dev/null
--password "$(cat /tmp/bats_test/password)" -w -t 300 -o json 2> /dev/null
assert_success
assert_regex "$output" "$uuid_v4_regex"
echo "$output" | jq -r '.id' > /tmp/bats_test/backupunit_id
Expand Down

0 comments on commit ca6c200

Please sign in to comment.