Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle series selection supports charm default series #21

Merged
merged 4 commits into from
Apr 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions changes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package bundlechanges_test
import (
"encoding/json"
"fmt"
"io/ioutil"
"path/filepath"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -1395,20 +1397,13 @@ func (s *changesSuite) TestFromData(c *gc.C) {
}
}

func (s *changesSuite) TestLocalCharmWithSeries(c *gc.C) {
charmDir := c.MkDir()
content := fmt.Sprintf(`
services:
django:
charm: %s
series: xenial
`, charmDir)
func (s *changesSuite) assertLocalBundleChanges(c *gc.C, charmDir, bundleContent, series string) {
expected := []record{{
Id: "addCharm-0",
Method: "addCharm",
Params: bundlechanges.AddCharmParams{
Charm: charmDir,
Series: "xenial",
Series: series,
},
GUIArgs: []interface{}{charmDir},
}, {
Expand All @@ -1428,5 +1423,38 @@ func (s *changesSuite) TestLocalCharmWithSeries(c *gc.C) {
},
Requires: []string{"addCharm-0"},
}}
s.assertParseData(c, content, expected)
s.assertParseData(c, bundleContent, expected)
}

func (s *changesSuite) TestLocalCharmWithExplicitSeries(c *gc.C) {
charmDir := c.MkDir()
bundleContent := fmt.Sprintf(`
services:
django:
charm: %s
series: xenial
`, charmDir)
s.assertLocalBundleChanges(c, charmDir, bundleContent, "xenial")
}

func (s *changesSuite) TestLocalCharmWithSeriesFromCharm(c *gc.C) {
charmDir := c.MkDir()
bundleContent := fmt.Sprintf(`
services:
django:
charm: %s
`, charmDir)
charmMeta := `
name: multi-series
summary: "That's a dummy charm with multi-series."
description: |
This is a longer description which
potentially contains multiple lines.
series:
- precise
- trusty
`[1:]
err := ioutil.WriteFile(filepath.Join(charmDir, "metadata.yaml"), []byte(charmMeta), 0644)
c.Assert(err, jc.ErrorIsNil)
s.assertLocalBundleChanges(c, charmDir, bundleContent, "precise")
}
10 changes: 9 additions & 1 deletion dependencies.tsv
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
github.com/gabriel-samfira/sys git 9ddc60d56b511544223adecea68da1e4f2153beb 2015-06-08T13:21:19Z
github.com/juju/errors git 1b5e39b83d1835fa480e0c2ddefb040ee82d58b3 2015-09-16T12:56:42Z
github.com/juju/gojsonpointer git afe8b77aa08f272b49e01b82de78510c11f61500 2015-02-04T19:46:29Z
github.com/juju/gojsonreference git f0d24ac5ee330baa21721cdff56d45e4ee42628e 2015-02-04T19:46:33Z
github.com/juju/gojsonschema git e1ad140384f254c82f89450d9a7c8dd38a632838 2015-03-12T17:00:16Z
github.com/juju/httpprof git 14bf14c307672fd2456bdbf35d19cf0ccd3cf565 2014-12-17T16:00:36Z
github.com/juju/httprequest git 89d547093c45e293599088cc63e805c6f1205dc0 2016-03-02T10:09:58Z
github.com/juju/loggo git 8477fc936adf0e382d680310047ca27e128a309a 2015-05-27T03:58:39Z
github.com/juju/names git 0fa6e46604f432b3064b02b2160fc5e6056131b8 2016-01-22T05:59:08Z
github.com/juju/schema git 1e25943f8c6fd6815282d6f1ac87091d21e14e19 2016-03-01T11:16:46Z
github.com/juju/testing git 321edad6b2d1ccac4af9ee05c25b8ad734d40546 2016-02-03T23:31:10Z
github.com/juju/utils git 0cac78a34dd1c42d2f2dc718c345fd13e3a264fc 2016-01-29T15:50:19Z
github.com/juju/version git ef897ad7f130870348ce306f61332f5335355063 2015-11-27T20:34:00Z
github.com/juju/webbrowser git 54b8c57083b4afb7dc75da7f13e2967b2606a507 2016-03-09T14:36:29Z
github.com/julienschmidt/httprouter git 77a895ad01ebc98a4dc95d8355bc825ce80a56f6 2015-10-13T22:55:20Z
golang.org/x/crypto git aedad9a179ec1ea11b7064c57cbc6dc30d7724ec 2015-08-30T18:06:42Z
golang.org/x/net git ea47fc708ee3e20177f3ca3716217c4ab75942cb 2015-08-29T23:03:18Z
gopkg.in/check.v1 git 4f90aeace3a26ad7021961c297b22c42160c7b25 2016-01-05T16:49:36Z
gopkg.in/errgo.v1 git 66cb46252b94c1f3d65646f54ee8043ab38d766c 2015-10-07T15:31:57Z
gopkg.in/juju/charm.v6-unstable git bd14aa9815cd1988c93991f4ac390622562a520e 2016-03-16T18:40:18Z
gopkg.in/juju/charmrepo.v2-unstable git c457416da598dffa665fc75aeb5c7265ff1273c0 2016-04-13T10:03:17Z
gopkg.in/macaroon-bakery.v1 git fddb3dcd74806133259879d033fdfe92f9e67a8a 2016-04-01T12:14:21Z
gopkg.in/macaroon.v1 git ab3940c6c16510a850e1c2dd628b919f0f3f1464 2015-01-21T11:42:31Z
gopkg.in/mgo.v2 git 4d04138ffef2791c479c0c8bbffc30b34081b8d9 2015-10-26T16:34:53Z
gopkg.in/yaml.v1 git 9f9df34309c04878acc86042b16630b0f696e1de 2014-09-24T16:16:07Z
gopkg.in/yaml.v2 git 53feefa2559fb8dfa8d81baad31be332c97d6c77 2015-09-24T14:23:14Z
13 changes: 12 additions & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"gopkg.in/juju/charm.v6-unstable"
"gopkg.in/juju/charmrepo.v2-unstable"
)

// handleServices populates the change set with "addCharm"/"addService" records.
Expand Down Expand Up @@ -242,11 +243,21 @@ func addContainer(add func(Change), containerType, parentId string, series strin
}

// getSeries retrieves the series of a service from the ServiceSpec or from the
// charm URL if provided, otherwise falling back on a default series.
// charm path or URL if provided, otherwise falling back on a default series.
func getSeries(service *charm.ServiceSpec, defaultSeries string) string {
if service.Series != "" {
return service.Series
}
// We may have a local charm path.
_, curl, err := charmrepo.NewCharmAtPath(service.Charm, "")
if charm.IsMissingSeriesError(err) {
// local charm path is valid but the charm doesn't declare a default series.
return defaultSeries
}
if err == nil {
// Return the default series from the local charm.
return curl.Series
}
// The following is safe because the bundle data is assumed to be already
// verified, and therefore this must be a valid charm URL.
series := charm.MustParseURL(service.Charm).Series
Expand Down