Skip to content

Commit

Permalink
Merge pull request #14452 from barrettj12/2.9-dev
Browse files Browse the repository at this point in the history
#14452

Pull requests:
- #14424 
- #14428 
- #14430 
- #14431 
- #14433 
- #14434 
- #14437 
- #14439 
- #14440 
- #14442 
- #14444
- #14445 
- #14446 
- #14448
- #14453 
- Updated `github.com/juju/charm/v9` to v9.0.4.

Conflicts:
- apiserver/common/tools_test.go
- cmd/juju/commands/upgradecontroller_test.go
- cmd/juju/commands/upgrademodel_test.go
- go.mod
- go.sum
- scripts/win-installer/setup.iss
- snap/snapcraft.yaml
- version/version.go

Note: ignoring #14427 since this is due to be reverted (see #14449).
  • Loading branch information
jujubot committed Aug 12, 2022
2 parents 7f3226a + 26a57a7 commit 61b014b
Show file tree
Hide file tree
Showing 42 changed files with 204 additions and 160 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
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
29 changes: 29 additions & 0 deletions cmd/juju/application/refresh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,35 @@ func (s *RefreshSuccessStateSuite) TestCharmPath(c *gc.C) {
s.assertLocalRevision(c, 42, myriakPath)
}

func (s *RefreshSuccessStateSuite) TestCharmPathNotFound(c *gc.C) {
myriakPath := filepath.Join(c.MkDir(), "riak")
_, err := os.Stat(myriakPath)
c.Assert(err, gc.ErrorMatches, ".*no such file or directory")
_, err = s.runRefresh(c, s.cmd, "riak", "--path", myriakPath)
c.Assert(err, gc.ErrorMatches, ".*file does not exist")
}

func (s *RefreshSuccessStateSuite) TestSwitchToLocal(c *gc.C) {
myriakPath := testcharms.RepoWithSeries("bionic").ClonedDirPath(c.MkDir(), "riak")

// Change the revision to 42 and upgrade to it with explicit revision.
err := ioutil.WriteFile(path.Join(myriakPath, "revision"), []byte("42"), 0644)
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)
c.Assert(curl.String(), gc.Equals, "local:bionic/riak-42")
s.assertLocalRevision(c, 42, myriakPath)
}

func (s *RefreshSuccessStateSuite) TestSwitchToLocalNotFound(c *gc.C) {
myriakPath := filepath.Join(c.MkDir(), "riak")
_, err := os.Stat(myriakPath)
c.Assert(err, gc.ErrorMatches, ".*no such file or directory")
_, err = s.runRefresh(c, s.cmd, "riak", "--switch", myriakPath)
c.Assert(err, gc.ErrorMatches, ".*file does not exist")
}

func (s *RefreshSuccessStateSuite) TestCharmPathNoRevUpgrade(c *gc.C) {
// Revision 7 is running to start with.
myriakPath := testcharms.RepoWithSeries("bionic").ClonedDirPath(c.MkDir(), "riak")
Expand Down
13 changes: 13 additions & 0 deletions cmd/juju/application/refresher/refresher.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,24 @@ func (d *localCharmRefresher) Refresh() (*CharmID, error) {
return nil, errors.Trace(err)
}

if IsLocalURL(d.charmRef) {
// This was clearly meant to refer to a local charm, which we've not
// been able to find, so return the error
return nil, errors.Annotatef(err, "%q", d.charmRef)
}

// Not a valid local charm, in this case, we should move onto the next
// refresher.
return nil, ErrExhausted
}

// IsLocalURL checks if the provided URL refers to a local charm (i.e. it
// begins with one of `/` `./` `../` ).
func IsLocalURL(url string) bool {
return strings.HasPrefix(url, "/") || strings.HasPrefix(url, "./") ||
strings.HasPrefix(url, "../")
}

func (d *localCharmRefresher) String() string {
return fmt.Sprintf("attempting to refresh local charm %q", d.charmRef)
}
Expand Down
13 changes: 10 additions & 3 deletions cmd/juju/cloud/addcredential.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Providing the ` + "`-f <credentials.yaml>` " + `option switches to the
non-interactive mode. <credentials.yaml> must be a path to a correctly
formatted YAML-formatted file.
Sample yaml file shows four credentials being stored against three clouds:
Sample yaml file shows five credentials being stored against four clouds:
credentials:
aws:
Expand All @@ -54,12 +54,19 @@ Sample yaml file shows four credentials being stored against three clouds:
application-password: <password>
subscription-id: <uuid>
lxd:
<credential-name>:
<credential-a>:
auth-type: interactive
trust-password: <password>
<credential-name>:
<credential-b>:
auth-type: interactive
trust-password: <password>
google:
<credential-name>:
auth-type: oauth2
project-id: <project-id>
private-key: <private-key>
client-email: <email>
client-id: <client-id>
The <credential-name> parameter of each credential is arbitrary, but must
be unique within each <cloud-name>. This allows allow each cloud to store
Expand Down
Loading

0 comments on commit 61b014b

Please sign in to comment.