Merge lp:~sergiusens/snappy/qualifiedUpdate into lp:~snappy-dev/snappy/15.04-deprecated

Proposed by Sergio Schvezov
Status: Merged
Approved by: Michael Vogt
Approved revision: 460
Merged at revision: 459
Proposed branch: lp:~sergiusens/snappy/qualifiedUpdate
Merge into: lp:~snappy-dev/snappy/15.04-deprecated
Diff against target: 210 lines (+115/-22)
3 files modified
snappy/parts.go (+6/-2)
snappy/snapp.go (+29/-3)
snappy/snapp_test.go (+80/-17)
To merge this branch: bzr merge lp:~sergiusens/snappy/qualifiedUpdate
Reviewer Review Type Date Requested Status
Michael Vogt (community) Approve
Review via email: mp+263987@code.launchpad.net

Commit message

Update using full qualifiers

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

Nice, this looks good. Just one (silly?) inline question.

Revision history for this message
Michael Vogt (mvo) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'snappy/parts.go'
2--- snappy/parts.go 2015-07-06 19:40:55 +0000
3+++ snappy/parts.go 2015-07-07 02:36:11 +0000
4@@ -248,7 +248,9 @@
5 }
6
7 // ActiveSnapsByType returns all installed snaps with the given type
8-func ActiveSnapsByType(snapTs ...SnapType) (res []Part, err error) {
9+var ActiveSnapsByType = activeSnapsByTypeImpl
10+
11+func activeSnapsByTypeImpl(snapTs ...SnapType) (res []Part, err error) {
12 m := NewMetaRepository()
13 installed, err := m.Installed()
14 if err != nil {
15@@ -282,7 +284,9 @@
16 }
17
18 // ActiveSnapByName returns all active snaps with the given name
19-func ActiveSnapByName(needle string) Part {
20+var ActiveSnapByName = activeSnapByNameImpl
21+
22+func activeSnapByNameImpl(needle string) Part {
23 m := NewMetaRepository()
24 installed, err := m.Installed()
25 if err != nil {
26
27=== modified file 'snappy/snapp.go'
28--- snappy/snapp.go 2015-07-06 19:52:32 +0000
29+++ snappy/snapp.go 2015-07-07 02:36:11 +0000
30@@ -225,6 +225,15 @@
31 Version string `json:"version"`
32 }
33
34+func (s remoteSnap) qualifiedName() string {
35+ switch s.Type {
36+ case SnapTypeApp:
37+ return fmt.Sprintf("%s.%s", s.Name, s.Namespace)
38+ default:
39+ return s.Name
40+ }
41+}
42+
43 type searchResults struct {
44 Payload struct {
45 Packages []remoteSnap `json:"clickindex:package"`
46@@ -1253,11 +1262,22 @@
47 func (s *SnapUbuntuStoreRepository) Updates() (parts []Part, err error) {
48 // the store only supports apps, oem and frameworks currently, so no
49 // sense in sending it our ubuntu-core snap
50- installed, err := ActiveSnapNamesByType(SnapTypeApp, SnapTypeFramework, SnapTypeOem)
51+ installed, err := ActiveSnapsByType(SnapTypeApp, SnapTypeFramework, SnapTypeOem)
52 if err != nil || len(installed) == 0 {
53 return nil, err
54 }
55- jsonData, err := json.Marshal(map[string][]string{"name": installed})
56+
57+ snapNames := make([]string, 0, len(installed))
58+ for _, snap := range installed {
59+ // this can be dropped once package origins are correctly recorded for everything
60+ if snap.Namespace() != "" {
61+ snapNames = append(snapNames, fmt.Sprintf("%s.%s", snap.Name(), snap.Namespace()))
62+ } else {
63+ snapNames = append(snapNames, snap.Name())
64+ }
65+ }
66+
67+ jsonData, err := json.Marshal(map[string][]string{"name": snapNames})
68 if err != nil {
69 return nil, err
70 }
71@@ -1286,7 +1306,13 @@
72 }
73
74 for _, pkg := range updateData {
75- current := ActiveSnapByName(pkg.Name)
76+ current := ActiveSnapByName(pkg.qualifiedName())
77+
78+ // this check is for non apps
79+ if current != nil && current.Namespace() != "" && current.Namespace() != pkg.Namespace {
80+ continue
81+ }
82+
83 if current == nil || current.Version() != pkg.Version {
84 snap := NewRemoteSnapPart(pkg)
85 parts = append(parts, snap)
86
87=== modified file 'snappy/snapp_test.go'
88--- snappy/snapp_test.go 2015-07-06 19:08:24 +0000
89+++ snappy/snapp_test.go 2015-07-07 02:36:11 +0000
90@@ -105,6 +105,8 @@
91 policy.SecBase = s.secbase
92 regenerateAppArmorRules = regenerateAppArmorRulesImpl
93 ActiveSnapNamesByType = activeSnapNamesByTypeImpl
94+ ActiveSnapsByType = activeSnapsByTypeImpl
95+ ActiveSnapByName = activeSnapByNameImpl
96 duCmd = "du"
97 stripGlobalRootDir = stripGlobalRootDirImpl
98 runScFilterGen = runScFilterGenImpl
99@@ -511,33 +513,94 @@
100 }
101 }
102
103+func mockActiveSnapsByType(mockParts []Part) {
104+ ActiveSnapsByType = func(snapTs ...SnapType) (res []Part, err error) {
105+ return mockParts, nil
106+ }
107+}
108+
109+func mockActiveSnapByName(mockPart Part) {
110+ ActiveSnapByName = func(string) Part {
111+ return mockPart
112+ }
113+}
114+
115 func (s *SnapTestSuite) TestUbuntuStoreRepositoryUpdates(c *C) {
116 mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
117 jsonReq, err := ioutil.ReadAll(r.Body)
118 c.Assert(err, IsNil)
119- c.Assert(string(jsonReq), Equals, `{"name":["`+funkyAppName+`"]}`)
120- io.WriteString(w, MockUpdatesJSON)
121- }))
122-
123- c.Assert(mockServer, NotNil)
124- defer mockServer.Close()
125-
126- var err error
127- storeBulkURI, err = url.Parse(mockServer.URL + "/updates/")
128- c.Assert(err, IsNil)
129- snap := NewUbuntuStoreSnapRepository()
130- c.Assert(snap, NotNil)
131+ c.Assert(string(jsonReq), Equals, `{"name":["`+funkyAppName+`.`+funkyAppOrigin+`"]}`)
132+ io.WriteString(w, MockUpdatesJSON)
133+ }))
134+
135+ c.Assert(mockServer, NotNil)
136+ defer mockServer.Close()
137+
138+ var err error
139+ storeBulkURI, err = url.Parse(mockServer.URL + "/updates/")
140+ c.Assert(err, IsNil)
141+ snap := NewUbuntuStoreSnapRepository()
142+ c.Assert(snap, NotNil)
143+
144+ part := SnapPart{
145+ m: &packageYaml{
146+ Name: funkyAppName,
147+ Type: SnapTypeApp,
148+ Version: "41",
149+ },
150+ namespace: funkyAppOrigin,
151+ }
152+
153+ // override the real ActiveSnapsByType to return our
154+ // mock data
155+ mockActiveSnapsByType([]Part{&part})
156+
157+ // the actual test
158+ results, err := snap.Updates()
159+ c.Assert(err, IsNil)
160+ c.Assert(results, HasLen, 1)
161+ c.Check(results[0].Name(), Equals, funkyAppName)
162+ c.Check(results[0].Version(), Equals, "42")
163+}
164+
165+func (s *SnapTestSuite) TestUbuntuStoreRepositoryUpdatesDifferentNamespace(c *C) {
166+ mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
167+ jsonReq, err := ioutil.ReadAll(r.Body)
168+ c.Assert(err, IsNil)
169+ c.Assert(string(jsonReq), Equals, `{"name":["`+funkyAppName+`.yadayada"]}`)
170+ io.WriteString(w, MockUpdatesJSON)
171+ }))
172+
173+ c.Assert(mockServer, NotNil)
174+ defer mockServer.Close()
175+
176+ var err error
177+ storeBulkURI, err = url.Parse(mockServer.URL + "/updates/")
178+ c.Assert(err, IsNil)
179+ snap := NewUbuntuStoreSnapRepository()
180+ c.Assert(snap, NotNil)
181+
182+ part := SnapPart{
183+ m: &packageYaml{
184+ Name: funkyAppName,
185+ Type: SnapTypeApp,
186+ Version: "41",
187+ },
188+ namespace: "yadayada",
189+ }
190+
191+ // override the real ActiveSnapsByType to return our
192+ // mock data
193+ mockActiveSnapsByType([]Part{&part})
194
195 // override the real ActiveSnapNamesByType to return our
196 // mock data
197- mockActiveSnapNamesByType([]string{funkyAppName})
198+ mockActiveSnapByName(&part)
199
200 // the actual test
201 results, err := snap.Updates()
202- c.Assert(err, IsNil)
203- c.Assert(results, HasLen, 1)
204- c.Assert(results[0].Name(), Equals, funkyAppName)
205- c.Assert(results[0].Version(), Equals, "42")
206+ c.Check(err, IsNil)
207+ c.Check(results, HasLen, 0)
208 }
209
210 func (s *SnapTestSuite) TestUbuntuStoreRepositoryUpdatesNoSnaps(c *C) {

Subscribers

People subscribed via source and target branches