Skip to content

Commit

Permalink
Checks for not found error before returning from LXD image acquisition.
Browse files Browse the repository at this point in the history
  • Loading branch information
manadart committed Aug 20, 2019
1 parent 6d5e31a commit b73a3ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions container/lxd/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@ func (s *Server) FindImage(
callback environs.StatusCallbackFunc,
) (SourcedImage, error) {
if callback != nil {
callback(status.Provisioning, "acquiring LXD image", nil)
_ = callback(status.Provisioning, "acquiring LXD image", nil)
}

// First we check if we have the image locally.
localAlias := seriesLocalAlias(series, arch)
var target string
entry, _, err := s.GetImageAlias(localAlias)
if err != nil {
if err != nil && !IsLXDNotFound(err) {
return SourcedImage{}, errors.Trace(err)
}

if entry != nil {
// We already have an image with the given alias, so just use that.
target = entry.Target
Expand Down Expand Up @@ -144,7 +145,7 @@ func (s *Server) CopyRemoteImage(
}
for _, key := range []string{"fs_progress", "download_progress"} {
if value, ok := op.Metadata[key]; ok {
callback(status.Provisioning, fmt.Sprintf("Retrieving image: %s", value.(string)), nil)
_ = callback(status.Provisioning, fmt.Sprintf("Retrieving image: %s", value.(string)), nil)
return
}
}
Expand Down
8 changes: 4 additions & 4 deletions container/lxd/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (s *imageSuite) TestFindImageLocalServerUnknownSeries(c *gc.C) {
ctrl := gomock.NewController(c)
defer ctrl.Finish()
iSvr := s.NewMockServer(ctrl)
iSvr.EXPECT().GetImageAlias("juju/pldlinux/"+s.Arch()).Return(nil, lxdtesting.ETag, nil)
iSvr.EXPECT().GetImageAlias("juju/pldlinux/"+s.Arch()).Return(nil, lxdtesting.ETag, errors.New("not found"))

jujuSvr, err := lxd.NewServer(iSvr)
c.Assert(err, jc.ErrorIsNil)
Expand All @@ -101,8 +101,8 @@ func (s *imageSuite) TestFindImageRemoteServers(c *gc.C) {
image := lxdapi.Image{Filename: "this-is-our-image"}
alias := lxdapi.ImageAliasesEntry{ImageAliasesEntryPut: lxdapi.ImageAliasesEntryPut{Target: "foo-remote-target"}}
gomock.InOrder(
iSvr.EXPECT().GetImageAlias("juju/xenial/"+s.Arch()).Return(nil, lxdtesting.ETag, nil),
rSvr1.EXPECT().GetImageAlias("xenial/"+s.Arch()).Return(nil, lxdtesting.ETag, nil),
iSvr.EXPECT().GetImageAlias("juju/xenial/"+s.Arch()).Return(nil, lxdtesting.ETag, errors.New("not found")),
rSvr1.EXPECT().GetImageAlias("xenial/"+s.Arch()).Return(nil, lxdtesting.ETag, errors.New("not found")),
rSvr2.EXPECT().GetImageAlias("xenial/"+s.Arch()).Return(&alias, lxdtesting.ETag, nil),
rSvr2.EXPECT().GetImage("foo-remote-target").Return(&image, lxdtesting.ETag, nil),
)
Expand Down Expand Up @@ -170,7 +170,7 @@ func (s *imageSuite) TestFindImageRemoteServersNotFound(c *gc.C) {

alias := lxdapi.ImageAliasesEntry{ImageAliasesEntryPut: lxdapi.ImageAliasesEntryPut{Target: "foo-remote-target"}}
gomock.InOrder(
iSvr.EXPECT().GetImageAlias("juju/bionic/"+s.Arch()).Return(nil, lxdtesting.ETag, nil),
iSvr.EXPECT().GetImageAlias("juju/bionic/"+s.Arch()).Return(nil, lxdtesting.ETag, errors.New("not found")),
rSvr.EXPECT().GetImageAlias("bionic/"+s.Arch()).Return(&alias, lxdtesting.ETag, nil),
rSvr.EXPECT().GetImage("foo-remote-target").Return(
nil, lxdtesting.ETag, errors.New("failed to retrieve image")),
Expand Down

0 comments on commit b73a3ca

Please sign in to comment.