Skip to content

Commit

Permalink
Clear hash, id and channel when switching to local charms
Browse files Browse the repository at this point in the history
Local charm origins can not include hashes, ids or channels. However,
when switching from a charmhub charm to a local one these attributes
were accidentally copies over

Ensure these attributes are droped when constructing the new charm
origin

Similarly with the revision, a new revision would not be set, meaning
the revision of the original charm would be kept. Make sure the revision
is updated as well

There is a slight nuance here, simply deploying a local charm does not
fill in a revision, but switching to a local charm will fill in a
revision. This is not a problem, as ideally we would have a revision for
local charms. This is something added in a later version
  • Loading branch information
jack-w-shaw committed Oct 13, 2023
1 parent ab7984d commit 214a1b2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
30 changes: 20 additions & 10 deletions cmd/juju/application/refresh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,14 @@ func (s *RefreshSuccessStateSuite) SetUpSuite(c *gc.C) {
s.RepoSuite.SetUpSuite(c)
}

func (s *RefreshSuccessStateSuite) assertUpgraded(c *gc.C, riak *state.Application, revision int, forced bool) *charm.URL {
func (s *RefreshSuccessStateSuite) assertUpgraded(c *gc.C, riak *state.Application, revision int, forced bool) (*charm.URL, *state.CharmOrigin) {
err := riak.Refresh()
c.Assert(err, jc.ErrorIsNil)
ch, force, err := riak.Charm()
c.Assert(err, jc.ErrorIsNil)
c.Assert(ch.Revision(), gc.Equals, revision)
c.Assert(force, gc.Equals, forced)
return ch.URL()
return ch.URL(), riak.CharmOrigin()
}

func (s *RefreshSuccessStateSuite) runRefresh(c *gc.C, cmd cmd.Command, args ...string) (*cmd.Context, error) {
Expand Down Expand Up @@ -614,7 +614,7 @@ func (s *RefreshSuccessStateSuite) assertLocalRevision(c *gc.C, revision int, pa
func (s *RefreshSuccessStateSuite) TestLocalRevisionUnchanged(c *gc.C) {
_, err := s.runRefresh(c, s.cmd, "riak", "--path", s.path)
c.Assert(err, jc.ErrorIsNil)
curl := s.assertUpgraded(c, s.riak, 8, false)
curl, _ := s.assertUpgraded(c, s.riak, 8, false)
s.AssertCharmUploaded(c, curl)
// Even though the remote revision is bumped, the local one should
// be unchanged.
Expand Down Expand Up @@ -767,7 +767,7 @@ func (s *RefreshSuccessStateSuite) TestRespectsLocalRevisionWhenPossible(c *gc.C
}
_, err = s.runRefresh(c, s.cmd, "riak", "--path", s.path)
c.Assert(err, jc.ErrorIsNil)
curl := s.assertUpgraded(c, s.riak, 42, false)
curl, _ := s.assertUpgraded(c, s.riak, 42, false)
s.AssertCharmUploaded(c, curl)
s.assertLocalRevision(c, 42, s.path)
}
Expand Down Expand Up @@ -1089,7 +1089,7 @@ func (s *RefreshCharmHubSuite) TestUpgradeResourceNoChange(c *gc.C) {
func (s *RefreshSuccessStateSuite) TestForcedUnitsUpgrade(c *gc.C) {
_, err := s.runRefresh(c, s.cmd, "riak", "--force-units", "--path", s.path)
c.Assert(err, jc.ErrorIsNil)
curl := s.assertUpgraded(c, s.riak, 8, true)
curl, _ := s.assertUpgraded(c, s.riak, 8, true)
s.AssertCharmUploaded(c, curl)
// Local revision is not changed.
s.assertLocalRevision(c, 7, s.path)
Expand All @@ -1100,7 +1100,7 @@ func (s *RefreshSuccessStateSuite) TestBlockForcedUnitsUpgrade(c *gc.C) {
s.BlockAllChanges(c, "TestBlockForcedUpgrade")
_, err := s.runRefresh(c, s.cmd, "riak", "--force-units", "--path", s.path)
c.Assert(err, jc.ErrorIsNil)
curl := s.assertUpgraded(c, s.riak, 8, true)
curl, _ := s.assertUpgraded(c, s.riak, 8, true)
s.AssertCharmUploaded(c, curl)
// Local revision is not changed.
s.assertLocalRevision(c, 7, s.path)
Expand All @@ -1114,7 +1114,7 @@ func (s *RefreshSuccessStateSuite) TestCharmPath(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)
_, err = s.runRefresh(c, s.cmd, "riak", "--path", myriakPath)
c.Assert(err, jc.ErrorIsNil)
curl := s.assertUpgraded(c, s.riak, 42, false)
curl, _ := s.assertUpgraded(c, s.riak, 42, false)
c.Assert(curl.String(), gc.Equals, "local:bionic/riak-42")
s.assertLocalRevision(c, 42, myriakPath)
}
Expand All @@ -1135,9 +1135,19 @@ func (s *RefreshSuccessStateSuite) TestSwitchToLocal(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)
_, err = s.runRefresh(c, s.cmd, "riak", "--switch", myriakPath)
c.Assert(err, jc.ErrorIsNil)
curl := s.assertUpgraded(c, s.riak, 42, false)
rev := 42
curl, origin := s.assertUpgraded(c, s.riak, rev, false)
c.Assert(curl.String(), gc.Equals, "local:bionic/riak-42")
s.assertLocalRevision(c, 42, myriakPath)
c.Assert(origin, gc.DeepEquals, &state.CharmOrigin{
Source: "local",
Revision: &rev,
Platform: &state.Platform{
Architecture: "amd64",
OS: "ubuntu",
Series: "bionic",
},
})
s.assertLocalRevision(c, rev, myriakPath)
}

func (s *RefreshSuccessStateSuite) TestSwitchToLocalNotFound(c *gc.C) {
Expand All @@ -1154,7 +1164,7 @@ func (s *RefreshSuccessStateSuite) TestCharmPathNoRevUpgrade(c *gc.C) {
s.assertLocalRevision(c, 7, myriakPath)
_, err := s.runRefresh(c, s.cmd, "riak", "--path", myriakPath)
c.Assert(err, jc.ErrorIsNil)
curl := s.assertUpgraded(c, s.riak, 8, false)
curl, _ := s.assertUpgraded(c, s.riak, 8, false)
c.Assert(curl.String(), gc.Equals, "local:bionic/riak-8")
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/juju/application/refresher/refresher.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ func (d *localCharmRefresher) Refresh() (*CharmID, error) {

newOrigin := d.charmOrigin
newOrigin.Source = corecharm.Local
newOrigin.Channel = nil
newOrigin.Hash = ""
newOrigin.ID = ""
newOrigin.Revision = &addedURL.Revision
return &CharmID{
URL: addedURL,
Origin: newOrigin,
Expand Down

0 comments on commit 214a1b2

Please sign in to comment.