-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(charm): drop dangerous ReadCharm and ReadBundle
These generic functions look at a path, determin if the resource is an archive or dir, and then run the associated parser. However, ever since we dropped support for deploying charms from directories, we have always known ahead of time the format of what we are about to read. In fact, we never need to parse a full charm as a directory. At most, we need to read one particular charm file. The only exception are in tests. So move ReadCharmDir into a testing package. The rest of the PR is made up of refactors/simplifications which were made possible by this change.
- Loading branch information
1 parent
bba5ec3
commit ed0ff3e
Showing
62 changed files
with
1,016 additions
and
899 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ import ( | |
corecharm "github.com/juju/juju/core/charm" | ||
"github.com/juju/juju/core/crossmodel" | ||
"github.com/juju/juju/internal/charm" | ||
charmtesting "github.com/juju/juju/internal/charm/testing" | ||
"github.com/juju/juju/internal/cmd/cmdtesting" | ||
coretesting "github.com/juju/juju/internal/testing" | ||
jujutesting "github.com/juju/juju/juju/testing" | ||
|
@@ -129,7 +130,7 @@ func (s *BundleDeploySuite) setupCharmMaybeForce(c *gc.C, url, name string, abas | |
} | ||
|
||
var chDir charm.Charm | ||
chDir, err := charm.ReadCharmDir(testcharms.RepoWithSeries("bionic").CharmDirPath(name)) | ||
chDir, err := charmtesting.ReadCharmDir(testcharms.RepoWithSeries("bionic").CharmDirPath(name)) | ||
if err != nil { | ||
if !os.IsNotExist(errors.Cause(err)) { | ||
c.Fatal(err) | ||
|
@@ -140,12 +141,11 @@ func (s *BundleDeploySuite) setupCharmMaybeForce(c *gc.C, url, name string, abas | |
return chDir | ||
} | ||
|
||
func (s *BundleDeploySuite) setupBundle(c *gc.C, url, name string, allBase ...base.Base) { | ||
func (s *BundleDeploySuite) setupFakeBundle(c *gc.C, url string, allBase ...base.Base) { | ||
bundleResolveURL := charm.MustParseURL(url) | ||
baseURL := *bundleResolveURL | ||
baseURL.Revision = -1 | ||
withCharmRepoResolvable(s.fakeAPI, &baseURL, base.Base{}) | ||
bundleDir := testcharms.RepoWithSeries("bionic").BundleArchive(c.MkDir(), name) | ||
|
||
// Resolve a bundle with no revision and return a url with a version. Ensure | ||
// GetBundle expects the url with revision. | ||
|
@@ -159,7 +159,7 @@ func (s *BundleDeploySuite) setupBundle(c *gc.C, url, name string, allBase ...ba | |
origin, | ||
error(nil), | ||
) | ||
s.fakeAPI.Call("GetBundle", bundleResolveURL).Returns(bundleDir, error(nil)) | ||
s.fakeAPI.Call("GetBundle", bundleResolveURL).Returns(nil, error(nil)) | ||
} | ||
} | ||
|
||
|
@@ -172,7 +172,7 @@ func (s *BundleDeploySuite) runDeploy(c *gc.C, args ...string) error { | |
func (s *BundleDeploySuite) TestDeployBundleInvalidFlags(c *gc.C) { | ||
s.setupCharm(c, "ch:mysql-42", "mysql", base.MustParseBaseFromString("[email protected]")) | ||
s.setupCharm(c, "ch:wordpress-47", "wordpress", base.MustParseBaseFromString("[email protected]")) | ||
s.setupBundle(c, "ch:wordpress-simple-1", "wordpress-simple", base.Base{}, base.MustParseBaseFromString("[email protected]"), base.MustParseBaseFromString("[email protected]")) | ||
s.setupFakeBundle(c, "ch:wordpress-simple-1", base.Base{}, base.MustParseBaseFromString("[email protected]"), base.MustParseBaseFromString("[email protected]")) | ||
|
||
err := s.runDeploy(c, "ch:wordpress-simple", "--config", "config.yaml") | ||
c.Assert(err, gc.ErrorMatches, "options provided but not supported when deploying a bundle: --config") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.