Skip to content

Commit f6a418b

Browse files
committed
Merge 2.5 into develop
Lots of pieces were out of date, should be better now.
2 parents 2362c11 + a592900 commit f6a418b

61 files changed

Lines changed: 1389 additions & 359 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Gopkg.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147

148148
[[constraint]]
149149
name = "gopkg.in/juju/charm.v6"
150-
revision = "3469d139dfb3c189a92bebb42f7075fac4bba707"
150+
revision = "dd3e82d4f34c956e7c3b20a82e96dc533cc96fb7"
151151

152152
[[constraint]]
153153
revision = "7778a447283bd71109671c20818544514e16e9d9"
@@ -283,7 +283,7 @@
283283

284284
[[constraint]]
285285
name = "github.com/juju/clock"
286-
revision = "bab88fc672997ef02d03f85310182d97a93dee21"
286+
revision = "9c5c9712527c7986f012361e7d13756b4d99543d"
287287

288288
[[constraint]]
289289
name = "github.com/juju/cmd"

api/storage/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,18 @@ func (c *Client) CreatePool(pname, provider string, attrs map[string]interface{}
107107
return results.OneError()
108108
}
109109

110-
// DeletePool deletes the named pool
111-
func (c *Client) DeletePool(pname string) error {
110+
// RemovePool removes the named pool
111+
func (c *Client) RemovePool(pname string) error {
112112
if c.BestAPIVersion() < 5 {
113-
return errors.New("deleting storage pools is not supported by this version of Juju")
113+
return errors.New("removing storage pools is not supported by this version of Juju")
114114
}
115115
var results params.ErrorResults
116116
args := params.StoragePoolDeleteArgs{
117117
Pools: []params.StoragePoolDeleteArg{{
118118
Name: pname,
119119
}},
120120
}
121-
if err := c.facade.FacadeCall("DeletePool", args, &results); err != nil {
121+
if err := c.facade.FacadeCall("RemovePool", args, &results); err != nil {
122122
return errors.Trace(err)
123123
}
124124
return results.OneError()

api/storage/client_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ func (s *storageMockSuite) TestImportArityMismatch(c *gc.C) {
908908
c.Check(err, gc.ErrorMatches, `expected 1 result, got 2`)
909909
}
910910

911-
func (s *storageMockSuite) TestDeletePool(c *gc.C) {
911+
func (s *storageMockSuite) TestRemovePool(c *gc.C) {
912912
var called bool
913913
poolName := "poolName"
914914

@@ -921,7 +921,7 @@ func (s *storageMockSuite) TestDeletePool(c *gc.C) {
921921
called = true
922922
c.Check(objType, gc.Equals, "Storage")
923923
c.Check(id, gc.Equals, "")
924-
c.Check(request, gc.Equals, "DeletePool")
924+
c.Check(request, gc.Equals, "RemovePool")
925925

926926
args, ok := a.(params.StoragePoolDeleteArgs)
927927
c.Assert(ok, jc.IsTrue)
@@ -934,12 +934,12 @@ func (s *storageMockSuite) TestDeletePool(c *gc.C) {
934934
return nil
935935
})
936936
storageClient := storage.NewClient(basetesting.BestVersionCaller{BestVersion: 5, APICallerFunc: apiCaller})
937-
err := storageClient.DeletePool(poolName)
937+
err := storageClient.RemovePool(poolName)
938938
c.Assert(err, jc.ErrorIsNil)
939939
c.Assert(called, jc.IsTrue)
940940
}
941941

942-
func (s *storageMockSuite) TestDeletePoolFacadeCallError(c *gc.C) {
942+
func (s *storageMockSuite) TestRemovePoolFacadeCallError(c *gc.C) {
943943
msg := "facade failure"
944944
apiCaller := basetesting.APICallerFunc(
945945
func(objType string,
@@ -949,7 +949,7 @@ func (s *storageMockSuite) TestDeletePoolFacadeCallError(c *gc.C) {
949949
) error {
950950
c.Check(objType, gc.Equals, "Storage")
951951
c.Check(id, gc.Equals, "")
952-
c.Check(request, gc.Equals, "DeletePool")
952+
c.Check(request, gc.Equals, "RemovePool")
953953

954954
args, ok := a.(params.StoragePoolDeleteArgs)
955955
c.Assert(ok, jc.IsTrue)
@@ -961,7 +961,7 @@ func (s *storageMockSuite) TestDeletePoolFacadeCallError(c *gc.C) {
961961
return errors.New(msg)
962962
})
963963
storageClient := storage.NewClient(basetesting.BestVersionCaller{BestVersion: 5, APICallerFunc: apiCaller})
964-
err := storageClient.DeletePool("")
964+
err := storageClient.RemovePool("")
965965
c.Assert(errors.Cause(err), gc.ErrorMatches, msg)
966966
}
967967

apiserver/common/crossmodel/crossmodel.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func PublishRelationChange(backend Backend, relationTag names.Tag, change params
7171
if err != nil {
7272
return errors.Trace(err)
7373
}
74-
logger.Debugf("application tag for token %+v is %v", change.ApplicationToken, applicationTag)
74+
logger.Debugf("application tag for token %+v is %v in model %v", change.ApplicationToken, applicationTag, backend.ModelUUID())
7575

7676
// If the remote model has destroyed the relation, do it here also.
7777
forceCleanUp := change.ForceCleanup != nil && *change.ForceCleanup
@@ -118,7 +118,7 @@ func PublishRelationChange(backend Backend, relationTag names.Tag, change params
118118
logger.Infof("no remote application found for %v", relationTag.Id())
119119
return nil
120120
}
121-
logger.Debugf("remote application for changed relation %v is %v", relationTag.Id(), applicationTag.Id())
121+
logger.Debugf("remote application for changed relation %v is %v in model %v", relationTag.Id(), applicationTag.Id(), backend.ModelUUID())
122122

123123
for _, id := range change.DepartedUnits {
124124
unitTag := names.NewUnitTag(fmt.Sprintf("%s/%v", applicationTag.Id(), id))

apiserver/common/crossmodel/interface.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ type Backend interface {
5757
// GetRemoteEntity returns the tag of the entity associated with the given token.
5858
GetRemoteEntity(string) (names.Tag, error)
5959

60+
// GetToken returns the token associated with the entity with the given tag.
61+
GetToken(entity names.Tag) (string, error)
62+
6063
// ExportLocalEntity adds an entity to the remote entities collection,
6164
// returning an opaque token that uniquely identifies the entity within
6265
// the model.

apiserver/common/crossmodel/state.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ func (st stateShim) GetRemoteEntity(token string) (names.Tag, error) {
136136
return r.GetRemoteEntity(token)
137137
}
138138

139+
func (st stateShim) GetToken(entity names.Tag) (string, error) {
140+
r := st.State.RemoteEntities()
141+
return r.GetToken(entity)
142+
}
143+
139144
func (st stateShim) ExportLocalEntity(entity names.Tag) (string, error) {
140145
r := st.State.RemoteEntities()
141146
return r.ExportLocalEntity(entity)

apiserver/facades/client/application/charmstore.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,12 @@ func AddCharmWithAuthorizationAndRepo(st State, args params.AddCharmWithAuthoriz
163163
}
164164

165165
ca := CharmArchive{
166-
ID: charmURL,
167-
Charm: downloadedCharm,
168-
Data: archive,
169-
Size: size,
170-
SHA256: bundleSHA256,
166+
ID: charmURL,
167+
Charm: downloadedCharm,
168+
Data: archive,
169+
Size: size,
170+
SHA256: bundleSHA256,
171+
CharmVersion: downloadedBundle.Version(),
171172
}
172173
if args.CharmStoreMacaroon != nil {
173174
ca.Macaroon = macaroon.Slice{args.CharmStoreMacaroon}

apiserver/facades/client/application/charmstore_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package application_test
55

66
import (
7+
"fmt"
8+
79
"github.com/golang/mock/gomock"
810
gc "gopkg.in/check.v1"
911
charm "gopkg.in/juju/charm.v6"
@@ -15,6 +17,7 @@ import (
1517
"github.com/juju/juju/apiserver/facades/client/application"
1618
"github.com/juju/juju/apiserver/facades/client/application/mocks"
1719
"github.com/juju/juju/apiserver/params"
20+
"github.com/juju/juju/state"
1821
"github.com/juju/juju/state/storage"
1922
"github.com/juju/juju/testcharms"
2023
)
@@ -204,3 +207,66 @@ func (s *CharmStoreSuite) TestAddCharmWithAuthorizationWithInvalidLXDProfileAndF
204207
})
205208
c.Assert(err, gc.IsNil)
206209
}
210+
211+
func (s *CharmStoreSuite) TestAddVersionedCharmWithAuthorization(c *gc.C) {
212+
ctrl := gomock.NewController(c)
213+
defer ctrl.Finish()
214+
215+
cacheDir := c.MkDir()
216+
s.PatchValue(&charmrepo.CacheDir, cacheDir)
217+
218+
url := "cs:~juju-qa/bionic/versioned-0"
219+
charmURL, err := charm.ParseURL(url)
220+
c.Assert(err, gc.IsNil)
221+
222+
mockState := mocks.NewMockState(ctrl)
223+
mockStateCharm := mocks.NewMockStateCharm(ctrl)
224+
mockStorage := mocks.NewMockStorage(ctrl)
225+
mockInterface := mocks.NewMockInterface(ctrl)
226+
227+
charm := testcharms.Repo.CharmArchive(cacheDir, "versioned")
228+
229+
// inject the mock as a back handed dependency
230+
s.PatchValue(application.NewStateStorage, func(uuid string, session *mgo.Session) storage.Storage {
231+
return mockStorage
232+
})
233+
234+
sExp := mockState.EXPECT()
235+
sExp.PrepareStoreCharmUpload(charmURL).Return(mockStateCharm, nil)
236+
sExp.ModelUUID().Return("model-id")
237+
sExp.MongoSession().Return(&mgo.Session{})
238+
sExp.UpdateUploadedCharm(charmVersionMatcher{"929903d"}).Return(nil, nil)
239+
240+
cExp := mockStateCharm.EXPECT()
241+
cExp.IsUploaded().Return(false)
242+
243+
stExp := mockStorage.EXPECT()
244+
stExp.Put(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
245+
246+
iExp := mockInterface.EXPECT()
247+
iExp.Get(charmURL).Return(charm, nil)
248+
249+
err = application.AddCharmWithAuthorizationAndRepo(mockState, params.AddCharmWithAuthorization{
250+
URL: url,
251+
}, func() (charmrepo.Interface, error) {
252+
return mockInterface, nil
253+
})
254+
c.Assert(err, gc.IsNil)
255+
}
256+
257+
type charmVersionMatcher struct {
258+
expVersion string
259+
}
260+
261+
func (m charmVersionMatcher) Matches(x interface{}) bool {
262+
info, ok := x.(state.CharmInfo)
263+
if !ok {
264+
return false
265+
}
266+
267+
return info.Version == m.expVersion
268+
}
269+
270+
func (m charmVersionMatcher) String() string {
271+
return fmt.Sprintf("state.CharmInfo.Version == %q", m.expVersion)
272+
}

apiserver/facades/client/storage/base_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func (s *baseStorageSuite) constructPoolManager() *mockPoolManager {
346346
s.pools[name] = pool
347347
return pool, err
348348
},
349-
deletePool: func(name string) error {
349+
removePool: func(name string) error {
350350
delete(s.pools, name)
351351
return nil
352352
},

0 commit comments

Comments
 (0)