Skip to content

Commit

Permalink
Merge pull request juju#17929 from hmlanigan/update-juju-client-backu…
Browse files Browse the repository at this point in the history
…p-download

juju#17929

Rather than a 404 message, print a nice error message if attempting to download a backup archive from a 4.0 controller, or any other which does not support the action.

## Checklist

- [ ] Code style: imports ordered, good names, simple structure, etc
- [ ] Comments saying why design decisions were made
- [ ] Go unit tests, with comments saying what you're testing
- [ ] [Integration tests](https://github.com/juju/juju/tree/main/tests), with comments saying what you're testing
- [ ] [doc.go](https://discourse.charmhub.io/t/readme-in-packages/451) added or updated in changed packages

## QA steps

If it hasn't been merged into main yet, use juju#17928 to bootstrap juju.

```
# Bootstrap juju from juju#17928 unless it's already merged. In that case use juju 4.0.
$ juju bootstrap lxd no-backup-download

# using the juju client built from this PR
$ juju download-backup -m controller /tmp/testme
Download of backup archive files is not supported by this controller.
```

## Links

**Jira card:** JUJU-6470
  • Loading branch information
jujubot authored Aug 14, 2024
2 parents e716fb0 + 5c20ac3 commit 6772899
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion api/client/backups/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/juju/errors"
"gopkg.in/httprequest.v1"

apiservererrors "github.com/juju/juju/apiserver/errors"
"github.com/juju/juju/rpc/params"
)

Expand All @@ -36,7 +37,7 @@ func (c *Client) Download(filename string) (io.ReadCloser, error) {
&resp,
)
if err != nil {
return nil, errors.Trace(err)
return nil, errors.Trace(apiservererrors.RestoreError(err))
}
return resp.Body, nil
}
8 changes: 6 additions & 2 deletions cmd/juju/backups/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,21 @@ func (c *downloadCommand) Run(ctx *cmd.Context) error {
// Download the archive.
resultArchive, err := client.Download(c.RemoteFilename)
if err != nil {
if errors.Is(err, errors.NotFound) {
ctx.Errorf("Download of backup archive files is not supported by this controller.")
return nil
}
return errors.Trace(err)
}
defer resultArchive.Close()
defer func() { _ = resultArchive.Close() }()

// Prepare the local archive.
filename := c.ResolveFilename()
archive, err := c.Filesystem().Create(filename)
if err != nil {
return errors.Annotate(err, "while creating local archive file")
}
defer archive.Close()
defer func() { _ = archive.Close() }()

// Write out the archive.
_, err = io.Copy(archive, resultArchive)
Expand Down

0 comments on commit 6772899

Please sign in to comment.