Add ability to publish to channels #72

Merged
merged 3 commits into from Mar 16, 2016

Conversation

Projects
None yet
4 participants
Contributor

natefinch commented Mar 15, 2016

No description provided.

Member

jujugui commented Mar 15, 2016

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
http://ci.jujugui.org:8080//job/charmrepo/201/
Test PASSed.

Contributor

ericsnowcurrently commented Mar 15, 2016

LGTM

charmstore.go
+// Publish tells the charmstore to mark the given charm as published with the
+// given resource revisions to the given channels. If no channels are specified,
+// the stable channel will be assumed.
+func (s *CharmStore) Publish(id *charm.URL, channels []string, resources map[string]int) (*charm.URL, error) {
@rogpeppe

rogpeppe Mar 16, 2016

Owner

Why not just make this take a []params.Channel as an argument?
Then there's no need to copy the slice.

@natefinch

natefinch Mar 16, 2016

Contributor

The point of the wrapper is to hide the ugly details of the HTTP API. The params package should be an implementation detail, IMO... that way you're not letting the API details leak outside the wrapper. Given that you're generally going to be using this from a CLI where we have to translate between a plain string and the API type anyway... seems like we might as well hide it away as far as possible.

charmstore.go
-// Publish tells the charmstore to mark the given charm as published with the given resource revisions.
-func (s *CharmStore) Publish(id *charm.URL, resources map[string]int) (*charm.URL, error) {
+// Publish tells the charmstore to mark the given charm as published with the
+// given resource revisions to the given channels. If no channels are specified,
@rogpeppe

rogpeppe Mar 16, 2016

Owner

I'm not entirely sure if we should do the "no channels==stable" thing at this level. It seems to me like that's more a policy decision for the outer level to take. This method could work OK as a very thin layer over the actual API endpoint, with no logic to speak of.

@natefinch

natefinch Mar 16, 2016

Contributor

agreed

charmstore_internal_test.go
@@ -177,12 +177,13 @@ func (ResourceSuite) TestPublish(c *gc.C) {
"data": 1,
"lib": 2,
}
- result, err := s.Publish(id, resources)
+ result, err := s.Publish(id, []string{"development"}, resources)
@rogpeppe

rogpeppe Mar 16, 2016

Owner

You should probably test the "no channels == stable" thing. Or just delete that logic, which I think I prefer.

@natefinch

natefinch Mar 16, 2016

Contributor

I agree with dropping the default to stable in this layer, will do.

charmstore.go
+ }
+ for i, ch := range channels {
+ chans[i] = params.Channel(ch)
+ }
val := &params.PublishRequest{
Published: true,
@rogpeppe

rogpeppe Mar 16, 2016

Owner

Delete this - it's ignored by the current API (and note TODO comment on the field in Publish).
You'll need to update the dependencies to use the latest charmstore version (which you should
do anyway so you're testing against a version that actually implements the functionality
we're trying to test).

@natefinch

natefinch Mar 16, 2016

Contributor

I noticed last night that it wasn't being used elsewhere... I'll remove it.

charmstore_internal_test.go
@@ -177,12 +177,13 @@ func (ResourceSuite) TestPublish(c *gc.C) {
"data": 1,
"lib": 2,
}
- result, err := s.Publish(id, resources)
+ result, err := s.Publish(id, []string{"development"}, resources)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, gc.DeepEquals, idrev)
f.CheckCall(c, 0, "PutWithResponse", "/"+id.Path()+"/publish", &params.PublishRequest{
@rogpeppe

rogpeppe Mar 16, 2016

Owner

Unfortunately this isn't actually checking what you think it's checking.
It's running the Publish call against the old (pre-new-channels-model)
charmstore, and it's "working" because the Publish field in the request
is set, which causes the previously uploaded charm id to be made available
in its non-development form. Well, you're not even checking whether the
charm has actually been published, but if you did, it would seem to work,
but if you tried retrieving the charm with the stable channel, it would
work even though the charm has only been published to development.

Let's make this test actually test whether the charm has been published
appropriately please, and that it has not been published to stable.

Again, you'll need to update the charmstore dep and fix the resulting
test failures.

@natefinch

natefinch Mar 16, 2016

Contributor

Added a full stack test that publishes to development then tries to get from dev and stable (obv checking that it fails when retrieving from stable).

Owner

rogpeppe commented Mar 16, 2016

LGTM with a bunch of suggestions. You're in luck - I updated charmrepo to fix that charmstore dependency (PR #73) so if you rebase on that, you should be OK to have some working tests.

Member

jujugui commented Mar 16, 2016

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
http://ci.jujugui.org:8080//job/charmrepo/206/
Test PASSed.

Member

jujugui commented Mar 16, 2016

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
http://ci.jujugui.org:8080//job/charmrepo/208/
Test PASSed.

Contributor

natefinch commented Mar 16, 2016

:shipit:

Member

jujugui commented Mar 16, 2016

Status: merge request accepted. Url: http://ci.jujugui.org:8080/job/charmrepo-merge

jujugui added a commit that referenced this pull request Mar 16, 2016

Merge pull request #72 from natefinch/publish-channels
Add ability to publish to channels

@jujugui jujugui merged commit 0e86a44 into juju:v2-unstable Mar 16, 2016

1 check passed

default Merged build finished.
Details

@natefinch natefinch deleted the natefinch:publish-channels branch Mar 16, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment