Skip to content

Commit

Permalink
Merge 2.9 into develop + upgrade juju/charm to v9.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
barrettj12 committed Aug 12, 2022
2 parents 314022d + 0b5aa0e commit 1de1bbd
Show file tree
Hide file tree
Showing 46 changed files with 275 additions and 163 deletions.
2 changes: 1 addition & 1 deletion agent/tools/symlinks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var _ = gc.Suite(&SymlinksSuite{})

func (s *SymlinksSuite) SetUpTest(c *gc.C) {
s.dataDir = c.MkDir()
s.toolsDir = tools.SharedToolsDir(s.dataDir, testing.CurrentVersion(c))
s.toolsDir = tools.SharedToolsDir(s.dataDir, testing.CurrentVersion())
err := os.MkdirAll(s.toolsDir, 0755)
c.Assert(err, jc.ErrorIsNil)
c.Logf("created %s", s.toolsDir)
Expand Down
2 changes: 1 addition & 1 deletion api/agent/provisioner/provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ func (s *provisionerSuite) TestFindToolsLogicError(c *gc.C) {
}

func (s *provisionerSuite) testFindTools(c *gc.C, matchArch bool, apiError, logicError error) {
current := coretesting.CurrentVersion(c)
current := coretesting.CurrentVersion()
var toolsList = coretools.List{&coretools.Tools{Version: current}}
var called bool
var a string
Expand Down
10 changes: 5 additions & 5 deletions api/agent/upgrader/unitupgrader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ func (s *unitUpgraderSuite) addMachineApplicationCharmAndUnit(c *gc.C, appName s
}

func (s *unitUpgraderSuite) TestSetVersionWrongUnit(c *gc.C) {
err := s.st.SetVersion("unit-wordpress-42", testing.CurrentVersion(c))
err := s.st.SetVersion("unit-wordpress-42", testing.CurrentVersion())
c.Assert(err, gc.ErrorMatches, "permission denied")
c.Assert(err, jc.Satisfies, params.IsCodeUnauthorized)
}

func (s *unitUpgraderSuite) TestSetVersionNotUnit(c *gc.C) {
err := s.st.SetVersion("foo-42", testing.CurrentVersion(c))
err := s.st.SetVersion("foo-42", testing.CurrentVersion())
c.Assert(err, gc.ErrorMatches, "permission denied")
c.Assert(err, jc.Satisfies, params.IsCodeUnauthorized)
}

func (s *unitUpgraderSuite) TestSetVersion(c *gc.C) {
current := testing.CurrentVersion(c)
current := testing.CurrentVersion()
agentTools, err := s.rawUnit.AgentTools()
c.Assert(err, jc.Satisfies, errors.IsNotFound)
c.Assert(agentTools, gc.IsNil)
Expand All @@ -115,7 +115,7 @@ func (s *unitUpgraderSuite) TestToolsNotUnit(c *gc.C) {
}

func (s *unitUpgraderSuite) TestTools(c *gc.C) {
current := testing.CurrentVersion(c)
current := testing.CurrentVersion()
curTools := &tools.Tools{Version: current, URL: ""}
curTools.Version.Minor++
s.rawMachine.SetAgentVersion(current)
Expand Down Expand Up @@ -162,7 +162,7 @@ func (s *unitUpgraderSuite) TestWatchAPIVersionNotUnit(c *gc.C) {
}

func (s *unitUpgraderSuite) TestDesiredVersion(c *gc.C) {
current := testing.CurrentVersion(c)
current := testing.CurrentVersion()
curTools := &tools.Tools{Version: current, URL: ""}
curTools.Version.Minor++
s.rawMachine.SetAgentVersion(current)
Expand Down
10 changes: 5 additions & 5 deletions api/agent/upgrader/upgrader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ func (s *machineUpgraderSuite) TestNew(c *gc.C) {
}

func (s *machineUpgraderSuite) TestSetVersionWrongMachine(c *gc.C) {
err := s.st.SetVersion("machine-42", coretesting.CurrentVersion(c))
err := s.st.SetVersion("machine-42", coretesting.CurrentVersion())
c.Assert(err, gc.ErrorMatches, "permission denied")
c.Assert(err, jc.Satisfies, params.IsCodeUnauthorized)
}

func (s *machineUpgraderSuite) TestSetVersionNotMachine(c *gc.C) {
err := s.st.SetVersion("foo-42", coretesting.CurrentVersion(c))
err := s.st.SetVersion("foo-42", coretesting.CurrentVersion())
c.Assert(err, gc.ErrorMatches, "permission denied")
c.Assert(err, jc.Satisfies, params.IsCodeUnauthorized)
}

func (s *machineUpgraderSuite) TestSetVersion(c *gc.C) {
current := coretesting.CurrentVersion(c)
current := coretesting.CurrentVersion()
agentTools, err := s.rawMachine.AgentTools()
c.Assert(err, jc.Satisfies, errors.IsNotFound)
c.Assert(agentTools, gc.IsNil)
Expand All @@ -90,7 +90,7 @@ func (s *machineUpgraderSuite) TestToolsNotMachine(c *gc.C) {
}

func (s *machineUpgraderSuite) TestTools(c *gc.C) {
current := coretesting.CurrentVersion(c)
current := coretesting.CurrentVersion()
err := s.rawMachine.SetAgentVersion(current)
c.Assert(err, jc.ErrorIsNil)

Expand Down Expand Up @@ -132,7 +132,7 @@ func (s *machineUpgraderSuite) TestWatchAPIVersion(c *gc.C) {
}

func (s *machineUpgraderSuite) TestDesiredVersion(c *gc.C) {
current := coretesting.CurrentVersion(c)
current := coretesting.CurrentVersion()
err := s.rawMachine.SetAgentVersion(current)
c.Assert(err, jc.ErrorIsNil)

Expand Down
16 changes: 8 additions & 8 deletions apiserver/common/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (s *getToolsSuite) TestTools(c *gc.C) {
},
}

current := coretesting.CurrentVersion(c)
current := coretesting.CurrentVersion()
configAttrs := map[string]interface{}{
"name": "some-name",
"type": "some-type",
Expand Down Expand Up @@ -162,7 +162,7 @@ func (s *setToolsSuite) TestSetTools(c *gc.C) {
ts := common.NewToolsSetter(s.entityFinder, getCanWrite)
c.Assert(ts, gc.NotNil)

current := coretesting.CurrentVersion(c)
current := coretesting.CurrentVersion()
args := params.EntitiesVersion{
AgentTools: []params.EntityVersion{{
Tag: "machine-0",
Expand Down Expand Up @@ -206,7 +206,7 @@ func (s *setToolsSuite) TestToolsSetError(c *gc.C) {
AgentTools: []params.EntityVersion{{
Tag: "machine-42",
Tools: &params.Version{
Version: coretesting.CurrentVersion(c),
Version: coretesting.CurrentVersion(),
},
}},
}
Expand Down Expand Up @@ -256,7 +256,7 @@ func (s *findToolsSuite) expectMatchingStorageTools(c *gc.C, storageMetadata []b
}

func (s *findToolsSuite) expectBootstrapEnvironConfig(c *gc.C) {
current := coretesting.CurrentVersion(c)
current := coretesting.CurrentVersion()
configAttrs := map[string]interface{}{
"name": "some-name",
"type": "some-type",
Expand Down Expand Up @@ -434,7 +434,7 @@ func (s *findToolsSuite) TestFindToolsExactNotInStorage(c *gc.C) {

func (s *findToolsSuite) testFindToolsExact(c *gc.C, inStorage bool, develVersion bool) {
var called bool
current := coretesting.CurrentVersion(c)
current := coretesting.CurrentVersion()
s.PatchValue(common.EnvtoolsFindTools, func(_ envtools.SimplestreamsFetcher, e environs.BootstrapEnviron, major, minor int, stream []string, filter coretools.Filter) (list coretools.List, err error) {
called = true
c.Assert(filter.Number, gc.Equals, jujuversion.Current)
Expand Down Expand Up @@ -506,7 +506,7 @@ func (s *getUrlSuite) TestToolsURLGetterNoAPIHostPorts(c *gc.C) {
s.apiHostPortsGetter.EXPECT().APIHostPortsForAgents().Return(nil, nil)

g := common.NewToolsURLGetter("my-uuid", s.apiHostPortsGetter)
_, err := g.ToolsURLs(coretesting.CurrentVersion(c))
_, err := g.ToolsURLs(coretesting.CurrentVersion())
c.Assert(err, gc.ErrorMatches, "no suitable API server address to pick from")
}

Expand All @@ -516,7 +516,7 @@ func (s *getUrlSuite) TestToolsURLGetterAPIHostPortsError(c *gc.C) {
s.apiHostPortsGetter.EXPECT().APIHostPortsForAgents().Return(nil, errors.New("oh noes"))

g := common.NewToolsURLGetter("my-uuid", s.apiHostPortsGetter)
_, err := g.ToolsURLs(coretesting.CurrentVersion(c))
_, err := g.ToolsURLs(coretesting.CurrentVersion())
c.Assert(err, gc.ErrorMatches, "oh noes")
}

Expand All @@ -528,7 +528,7 @@ func (s *getUrlSuite) TestToolsURLGetter(c *gc.C) {
}, nil)

g := common.NewToolsURLGetter("my-uuid", s.apiHostPortsGetter)
current := coretesting.CurrentVersion(c)
current := coretesting.CurrentVersion()
urls, err := g.ToolsURLs(current)
c.Assert(err, jc.ErrorIsNil)
c.Assert(urls, jc.DeepEquals, []string{
Expand Down
10 changes: 5 additions & 5 deletions apiserver/facades/agent/upgrader/unitupgrader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (s *unitUpgraderSuite) TestToolsForAgent(c *gc.C) {
// The machine must have its existing tools set before we query for the
// next tools. This is so that we can grab Arch and OSType without
// having to pass it in again
current := testing.CurrentVersion(c)
current := testing.CurrentVersion()
err := s.rawMachine.SetAgentVersion(current)
c.Assert(err, jc.ErrorIsNil)

Expand Down Expand Up @@ -220,7 +220,7 @@ func (s *unitUpgraderSuite) TestSetToolsRefusesWrongAgent(c *gc.C) {
AgentTools: []params.EntityVersion{{
Tag: s.rawUnit.Tag().String(),
Tools: &params.Version{
Version: testing.CurrentVersion(c),
Version: testing.CurrentVersion(),
},
}},
}
Expand All @@ -232,7 +232,7 @@ func (s *unitUpgraderSuite) TestSetToolsRefusesWrongAgent(c *gc.C) {
}

func (s *unitUpgraderSuite) TestSetTools(c *gc.C) {
cur := testing.CurrentVersion(c)
cur := testing.CurrentVersion()
_, err := s.rawUnit.AgentTools()
c.Assert(err, jc.Satisfies, errors.IsNotFound)
args := params.EntitiesVersion{
Expand Down Expand Up @@ -290,7 +290,7 @@ func (s *unitUpgraderSuite) TestDesiredVersionRefusesWrongAgent(c *gc.C) {
}

func (s *unitUpgraderSuite) TestDesiredVersionNoticesMixedAgents(c *gc.C) {
current := testing.CurrentVersion(c)
current := testing.CurrentVersion()
err := s.rawMachine.SetAgentVersion(current)
c.Assert(err, jc.ErrorIsNil)
args := params.Entities{Entities: []params.Entity{
Expand All @@ -311,7 +311,7 @@ func (s *unitUpgraderSuite) TestDesiredVersionNoticesMixedAgents(c *gc.C) {
}

func (s *unitUpgraderSuite) TestDesiredVersionForAgent(c *gc.C) {
current := testing.CurrentVersion(c)
current := testing.CurrentVersion()
err := s.rawMachine.SetAgentVersion(current)
c.Assert(err, jc.ErrorIsNil)
args := params.Entities{Entities: []params.Entity{{Tag: s.rawUnit.Tag().String()}}}
Expand Down
8 changes: 4 additions & 4 deletions apiserver/facades/agent/upgrader/upgrader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (s *upgraderSuite) TestToolsRefusesWrongAgent(c *gc.C) {
}

func (s *upgraderSuite) TestToolsForAgent(c *gc.C) {
current := coretesting.CurrentVersion(c)
current := coretesting.CurrentVersion()
agent := params.Entity{Tag: s.rawMachine.Tag().String()}

// The machine must have its existing tools set before we query for the
Expand Down Expand Up @@ -284,7 +284,7 @@ func (s *upgraderSuite) TestSetToolsRefusesWrongAgent(c *gc.C) {
AgentTools: []params.EntityVersion{{
Tag: s.rawMachine.Tag().String(),
Tools: &params.Version{
Version: coretesting.CurrentVersion(c),
Version: coretesting.CurrentVersion(),
},
}},
}
Expand All @@ -296,7 +296,7 @@ func (s *upgraderSuite) TestSetToolsRefusesWrongAgent(c *gc.C) {
}

func (s *upgraderSuite) TestSetTools(c *gc.C) {
current := coretesting.CurrentVersion(c)
current := coretesting.CurrentVersion()
_, err := s.rawMachine.AgentTools()
c.Assert(err, jc.Satisfies, errors.IsNotFound)
args := params.EntitiesVersion{
Expand Down Expand Up @@ -378,7 +378,7 @@ func (s *upgraderSuite) TestDesiredVersionForAgent(c *gc.C) {
func (s *upgraderSuite) bumpDesiredAgentVersion(c *gc.C) version.Number {
// In order to call SetModelAgentVersion we have to first SetTools on
// all the existing machines
current := coretesting.CurrentVersion(c)
current := coretesting.CurrentVersion()
err := s.apiMachine.SetAgentVersion(current)
c.Assert(err, jc.ErrorIsNil)
err = s.rawMachine.SetAgentVersion(current)
Expand Down
6 changes: 3 additions & 3 deletions apiserver/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func (s *toolsSuite) TestUploadConvertsSeries(c *gc.C) {

func (s *toolsSuite) TestDownloadModelUUIDPath(c *gc.C) {
tools := s.storeFakeTools(c, s.State, "abc", binarystorage.Metadata{
Version: testing.CurrentVersion(c).String(),
Version: testing.CurrentVersion().String(),
Size: 3,
SHA256: "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
})
Expand All @@ -447,7 +447,7 @@ func (s *toolsSuite) TestDownloadOtherModelUUIDPath(c *gc.C) {
defer newSt.Close()

tools := s.storeFakeTools(c, newSt, "abc", binarystorage.Metadata{
Version: testing.CurrentVersion(c).String(),
Version: testing.CurrentVersion().String(),
Size: 3,
SHA256: "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
})
Expand All @@ -456,7 +456,7 @@ func (s *toolsSuite) TestDownloadOtherModelUUIDPath(c *gc.C) {

func (s *toolsSuite) TestDownloadTopLevelPath(c *gc.C) {
tools := s.storeFakeTools(c, s.State, "abc", binarystorage.Metadata{
Version: testing.CurrentVersion(c).String(),
Version: testing.CurrentVersion().String(),
Size: 3,
SHA256: "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
})
Expand Down
20 changes: 20 additions & 0 deletions cmd/juju/application/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ func (d *factory) maybeReadLocalBundle() (Deployer, error) {
if err != nil {
return nil, errors.Annotate(err, "cannot deploy bundle")
}
if err = handleUnmarshallError(ds.Parts()); err != nil && !d.force {
return nil, errors.Annotate(err, "cannot deploy bundle, invalid fields")
}

if err := d.validateBundleFlags(); err != nil {
return nil, errors.Trace(err)
}
Expand All @@ -284,6 +288,22 @@ func (d *factory) maybeReadLocalBundle() (Deployer, error) {
return &localBundle{deployBundle: db}, nil
}

func handleUnmarshallError(parts []*charm.BundleDataPart) error {
messages := set.NewStrings()
for _, part := range parts {
if part == nil {
continue
}
if part.UnmarshallError != nil {
messages.Add(part.UnmarshallError.Error())
}
}
if messages.IsEmpty() {
return nil
}
return errors.New(strings.Join(messages.Values(), "\n"))
}

// newDeployBundle returns the config needed to eventually call
// deployBundle.deploy. This is used by all types of bundles to
// be deployed
Expand Down
48 changes: 48 additions & 0 deletions cmd/juju/application/deployer/deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,54 @@ func (s *deployerSuite) TestGetDeployerLocalBundle(c *gc.C) {
c.Assert(deployer.String(), gc.Equals, fmt.Sprintf("deploy local bundle from: %s", bundlePath))
}

func (s *deployerSuite) TestGetDeployerLocalBundleStrict(c *gc.C) {
defer s.setupMocks(c).Finish()

_, err := s.testGetDeployerLocalBundleStrict(c, false)
c.Assert(err.Error(), gc.Equals, ("cannot deploy bundle, invalid fields: unmarshal document 0: yaml: unmarshal errors:\n line 3: field descriptn not found in bundle\n line 8: field contstraints not found in applications"))
}

func (s *deployerSuite) TestGetDeployerLocalBundleStrictUseForce(c *gc.C) {
defer s.setupMocks(c).Finish()

deployer, err := s.testGetDeployerLocalBundleStrict(c, true)
c.Assert(err, jc.ErrorIsNil)
c.Assert(deployer.String(), gc.Matches, "deploy local bundle from: .*")

}

func (s *deployerSuite) testGetDeployerLocalBundleStrict(c *gc.C, force bool) (Deployer, error) {
s.expectFilesystem()

cfg := s.basicDeployerConfig()
cfg.Series = "bionic"
cfg.FlagSet = &gnuflag.FlagSet{}
cfg.Force = force
s.expectModelType()

content := `
series: xenial
descriptn: bundle to fail strict parsing
applications:
wordpress:
charm: wordpress
num_units: 1
contstraints: "mem=8G"
mysql:
charm: mysql
num_units: 2
relations:
- ["wordpress:db", "mysql:server"]
`

bundlePath := s.makeBundleDir(c, content)
s.expectStat(bundlePath, nil)
cfg.CharmOrBundle = bundlePath

factory := s.newDeployerFactory()
return factory.GetDeployer(cfg, s.modelConfigGetter, s.resolver)
}

func (s *deployerSuite) TestGetDeployerCharmStoreBundle(c *gc.C) {
bundle := charm.MustParseURL("cs:test-bundle")
cfg := s.basicDeployerConfig()
Expand Down
7 changes: 5 additions & 2 deletions cmd/juju/application/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,11 @@ func (c *refreshCommand) Run(ctx *cmd.Context) error {
// Ensure that the switchURL (if provided) always contains a schema. If
// one is missing inject the default value we selected above.
if c.SwitchURL != "" {
if c.SwitchURL, err = charm.EnsureSchema(c.SwitchURL, defaultCharmSchema); err != nil {
return errors.Trace(err)
// Don't prepend `ch:` when referring to a local charm
if !refresher.IsLocalURL(c.SwitchURL) {
if c.SwitchURL, err = charm.EnsureSchema(c.SwitchURL, defaultCharmSchema); err != nil {
return errors.Trace(err)
}
}
}

Expand Down

0 comments on commit 1de1bbd

Please sign in to comment.