Skip to content

Commit

Permalink
Merge pull request juju#16269 from hmlanigan/merge-into-3-3
Browse files Browse the repository at this point in the history
juju#16269

- juju#16267 from hmlanigan/merge-into-3-1
- juju#16254 from hmlanigan/no-deployed-base-refresh
- juju#16260 from nvinuesa/merge-2.9-3.1-20230914

Conflicts in 
 cmd/juju/application/refresher/refresher.go
 cmd/juju/application/refresher/refresher_test.go
  • Loading branch information
jujubot authored Sep 15, 2023
2 parents 9863a69 + 9b1b34f commit 7a9b76f
Show file tree
Hide file tree
Showing 9 changed files with 341 additions and 266 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@ go-install: $(INSTALL_TARGETS)
.PHONY: clean
clean:
## clean: Clean the cache and test caches
go clean -n -r --cache --testcache $(PROJECT)/...
go clean -x --cache --testcache
go clean -x -r $(PROJECT)/...

.PHONY: vendor-dependencies
vendor-dependencies:
Expand Down
11 changes: 4 additions & 7 deletions cmd/juju/application/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,21 +408,18 @@ func (c *refreshCommand) Run(ctx *cmd.Context) error {
}
}

chBase, err := corebase.ParseBase(applicationInfo.Base.Name, applicationInfo.Base.Channel)
if err != nil {
return errors.Trace(err)
}
cfg := refresher.RefresherConfig{
ApplicationName: c.ApplicationName,
CharmURL: oldURL,
CharmOrigin: oldOrigin.CoreCharmOrigin(),
CharmRef: newRef,
Channel: c.Channel,
DeployedBase: chBase,
Force: c.Force,
ForceBase: c.ForceBase,
Switch: c.SwitchURL != "",
Logger: ctx,
// If revision is supplied by the user, treat it as a switch operation,
// the revision has already been added to the "newRef" above.
Switch: c.SwitchURL != "" || c.Revision != -1,
Logger: ctx,
}
factory, err := c.getRefresherFactory(apiRoot)
if err != nil {
Expand Down
119 changes: 76 additions & 43 deletions cmd/juju/application/refresh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ type BaseRefreshSuite struct {
resourceLister mockResourceLister
spacesClient mockSpacesClient
downloadBundleClient mockDownloadBundleClient

testPlatform corecharm.Platform
testBase corebase.Base
}

func (s *BaseRefreshSuite) runRefresh(c *gc.C, args ...string) (*cmd.Context, error) {
Expand Down Expand Up @@ -98,6 +101,9 @@ func (s *BaseRefreshSuite) setup(c *gc.C, currentCharmURL, latestCharmURL *charm
cookieFile := filepath.Join(c.MkDir(), "cookies")
s.PatchEnvironment("JUJU_COOKIEFILE", cookieFile)

s.testPlatform = corecharm.MustParsePlatform("amd64/ubuntu/22.04")
s.testBase = corebase.MakeDefaultBase("ubuntu", "22.04")

s.deployResources = func(
applicationID string,
chID resources.CharmID,
Expand Down Expand Up @@ -150,9 +156,11 @@ func (s *BaseRefreshSuite) setup(c *gc.C, currentCharmURL, latestCharmURL *charm
"": network.AlphaSpaceName,
},
charmOrigin: commoncharm.Origin{
ID: "testing",
Source: schemaToOriginScource(currentCharmURL.Schema),
Risk: "stable",
ID: "testing",
Source: schemaToOriginScource(currentCharmURL.Schema),
Risk: "stable",
Architecture: arch.DefaultArchitecture,
Base: s.testBase,
},
}
s.modelConfigGetter = newMockModelConfigGetter()
Expand Down Expand Up @@ -249,9 +257,11 @@ func (s *RefreshSuite) TestStorageConstraints(c *gc.C) {
CharmID: application.CharmID{
URL: s.resolvedCharmURL,
Origin: commoncharm.Origin{
ID: "testing",
Source: "charm-hub",
Risk: "stable",
ID: "testing",
Source: "charm-hub",
Risk: "stable",
Architecture: arch.DefaultArchitecture,
Base: s.testBase,
},
},
StorageConstraints: map[string]storage.Constraints{
Expand All @@ -277,9 +287,11 @@ func (s *RefreshSuite) TestConfigSettings(c *gc.C) {
CharmID: application.CharmID{
URL: s.resolvedCharmURL,
Origin: commoncharm.Origin{
ID: "testing",
Source: "charm-hub",
Risk: "stable",
ID: "testing",
Source: "charm-hub",
Risk: "stable",
Architecture: arch.DefaultArchitecture,
Base: s.testBase,
},
},
ConfigSettingsYAML: "foo:{}",
Expand All @@ -298,9 +310,11 @@ func (s *RefreshSuite) TestConfigSettingsWithTrust(c *gc.C) {
CharmID: application.CharmID{
URL: s.resolvedCharmURL,
Origin: commoncharm.Origin{
ID: "testing",
Source: "charm-hub",
Risk: "stable",
ID: "testing",
Source: "charm-hub",
Risk: "stable",
Architecture: arch.DefaultArchitecture,
Base: s.testBase,
},
},
ConfigSettings: map[string]string{"trust": "true", "foo": "bar"},
Expand All @@ -318,9 +332,11 @@ func (s *RefreshSuite) TestConfigSettingsWithTrustFalse(c *gc.C) {
CharmID: application.CharmID{
URL: s.resolvedCharmURL,
Origin: commoncharm.Origin{
ID: "testing",
Source: "charm-hub",
Risk: "stable",
ID: "testing",
Source: "charm-hub",
Risk: "stable",
Architecture: arch.DefaultArchitecture,
Base: s.testBase,
},
},
ConfigSettings: map[string]string{"trust": "false", "foo": "bar"},
Expand All @@ -343,9 +359,11 @@ func (s *RefreshSuite) TestConfigSettingsWithKeyValuesAndFile(c *gc.C) {
CharmID: application.CharmID{
URL: s.resolvedCharmURL,
Origin: commoncharm.Origin{
ID: "testing",
Source: "charm-hub",
Risk: "stable",
ID: "testing",
Source: "charm-hub",
Risk: "stable",
Architecture: arch.DefaultArchitecture,
Base: s.testBase,
},
},
ConfigSettingsYAML: "foo:{}",
Expand Down Expand Up @@ -389,9 +407,11 @@ func (s *RefreshSuite) testUpgradeWithBind(c *gc.C, expectedBindings map[string]
CharmID: application.CharmID{
URL: s.resolvedCharmURL,
Origin: commoncharm.Origin{
ID: "testing",
Source: "charm-hub",
Risk: "stable",
ID: "testing",
Source: "charm-hub",
Risk: "stable",
Architecture: arch.DefaultArchitecture,
Base: s.testBase,
},
},
ConfigSettings: map[string]string{},
Expand Down Expand Up @@ -616,17 +636,20 @@ func (s *RefreshSuite) TestUpgradeWithChannel(c *gc.C) {
})
origin.ID = "testing"
origin.Revision = (*int)(nil)
origin.Architecture = ""
origin.Architecture = arch.DefaultArchitecture
origin.Base = s.testBase
s.charmAdder.CheckCall(c, 0, "AddCharm", s.resolvedCharmURL, origin, false)
s.charmAPIClient.CheckCallNames(c, "GetCharmURLOrigin", "Get", "SetCharm")
s.charmAPIClient.CheckCall(c, 2, "SetCharm", model.GenerationMaster, application.SetCharmConfig{
ApplicationName: "foo",
CharmID: application.CharmID{
URL: s.resolvedCharmURL,
Origin: commoncharm.Origin{
ID: "testing",
Source: "charm-hub",
Risk: "beta",
ID: "testing",
Source: "charm-hub",
Risk: "beta",
Architecture: arch.DefaultArchitecture,
Base: s.testBase,
},
},
ConfigSettings: map[string]string{},
Expand All @@ -649,9 +672,11 @@ func (s *RefreshSuite) TestUpgradeWithChannelNoNewCharmURL(c *gc.C) {
CharmID: application.CharmID{
URL: s.resolvedCharmURL,
Origin: commoncharm.Origin{
ID: "testing",
Source: "charm-hub",
Risk: "beta",
ID: "testing",
Source: "charm-hub",
Risk: "beta",
Architecture: arch.DefaultArchitecture,
Base: s.testBase,
},
},
ConfigSettings: map[string]string{},
Expand All @@ -665,20 +690,21 @@ func (s *RefreshSuite) TestRefreshShouldRespectDeployedChannelByDefault(c *gc.C)
c.Assert(err, jc.ErrorIsNil)

s.charmAdder.CheckCallNames(c, "AddCharm")
origin, _ := utils.DeduceOrigin(s.resolvedCharmURL, charm.Channel{Risk: charm.Beta}, corecharm.Platform{})
origin, _ := utils.DeduceOrigin(s.resolvedCharmURL, charm.Channel{Risk: charm.Beta}, s.testPlatform)
origin.ID = "testing"
origin.Revision = (*int)(nil)
origin.Architecture = ""
s.charmAdder.CheckCall(c, 0, "AddCharm", s.resolvedCharmURL, origin, false)
s.charmAPIClient.CheckCallNames(c, "GetCharmURLOrigin", "Get", "SetCharm")
s.charmAPIClient.CheckCall(c, 2, "SetCharm", model.GenerationMaster, application.SetCharmConfig{
ApplicationName: "foo",
CharmID: application.CharmID{
URL: s.resolvedCharmURL,
Origin: commoncharm.Origin{
ID: "testing",
Source: "charm-hub",
Risk: "beta",
ID: "testing",
Source: "charm-hub",
Risk: "beta",
Architecture: arch.DefaultArchitecture,
Base: s.testBase,
},
},
ConfigSettings: map[string]string{},
Expand All @@ -702,7 +728,7 @@ func (s *RefreshSuite) TestSwitch(c *gc.C) {
s.charmClient.CheckCallNames(c, "CharmInfo", "CharmInfo")
s.charmClient.CheckCall(c, 0, "CharmInfo", s.resolvedCharmURL.String())
s.charmAdder.CheckCallNames(c, "CheckCharmPlacement", "AddCharm")
origin, _ := utils.DeduceOrigin(s.resolvedCharmURL, charm.Channel{Risk: charm.Stable}, corecharm.Platform{})
origin, _ := utils.DeduceOrigin(s.resolvedCharmURL, charm.Channel{Risk: charm.Stable}, s.testPlatform)

parsedSwitchUrl, err := charm.ParseURL("ch:trusty/anotherriak")
c.Assert(err, jc.ErrorIsNil)
Expand All @@ -718,6 +744,7 @@ func (s *RefreshSuite) TestSwitch(c *gc.C) {
Source: "charm-hub",
Architecture: arch.DefaultArchitecture,
Risk: "stable",
Base: s.testBase,
},
},
ConfigSettings: map[string]string{},
Expand Down Expand Up @@ -956,9 +983,11 @@ func (s *RefreshSuite) TestUpgradeSameVersionWithResourceUpload(c *gc.C) {
CharmID: application.CharmID{
URL: s.resolvedCharmURL,
Origin: commoncharm.Origin{
ID: "testing",
Source: "charm-hub",
Risk: "stable",
ID: "testing",
Source: "charm-hub",
Risk: "stable",
Architecture: arch.DefaultArchitecture,
Base: s.testBase,
},
},
ConfigSettings: map[string]string{},
Expand Down Expand Up @@ -1016,9 +1045,11 @@ func (s *RefreshCharmHubSuite) TestUpgradeResourceRevision(c *gc.C) {
s.CheckCall(c, 9, "DeployResources", "foo", resources.CharmID{
URL: s.resolvedCharmURL,
Origin: commoncharm.Origin{
ID: "testing",
Source: "charm-hub",
Risk: "stable"}},
ID: "testing",
Source: "charm-hub",
Risk: "stable",
Architecture: arch.DefaultArchitecture,
Base: s.testBase}},
map[string]string(nil),
map[string]charmresource.Meta{"bar": {Name: "bar", Type: charmresource.TypeFile}},
)
Expand Down Expand Up @@ -1057,9 +1088,11 @@ func (s *RefreshCharmHubSuite) TestUpgradeResourceRevisionSupplied(c *gc.C) {
s.CheckCall(c, 9, "DeployResources", "foo", resources.CharmID{
URL: s.resolvedCharmURL,
Origin: commoncharm.Origin{
ID: "testing",
Source: "charm-hub",
Risk: "stable"}},
ID: "testing",
Source: "charm-hub",
Risk: "stable",
Architecture: arch.DefaultArchitecture,
Base: s.testBase}},
map[string]string{"bar": "3"},
map[string]charmresource.Meta{"bar": {Name: "bar", Type: charmresource.TypeFile}},
)
Expand Down
Loading

0 comments on commit 7a9b76f

Please sign in to comment.