Merge lp:~sergiusens/snappy/upload into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Sergio Schvezov on 2015-06-09
Status: Merged
Approved by: Sergio Schvezov on 2015-06-10
Approved revision: 410
Merged at revision: 501
Proposed branch: lp:~sergiusens/snappy/upload
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Prerequisite: lp:~sergiusens/snappy/installYamlAndSideloading
Diff against target: 192 lines (+116/-12)
4 files modified
cmd/snappy/cmd_update.go (+1/-11)
snappy/install.go (+24/-0)
snappy/install_test.go (+88/-0)
snappy/systemimage.go (+3/-1)
To merge this branch: bzr merge lp:~sergiusens/snappy/upload
Reviewer Review Type Date Requested Status
Sergio Schvezov Approve on 2015-06-10
Michael Vogt 2015-06-09 Approve on 2015-06-10
Review via email: mp+261563@code.launchpad.net

Commit Message

Factor out update from cmd

To post a comment you must log in.
Michael Vogt (mvo) wrote :

Yay! I like that a lot! Some nit-picking inline, but really good stuff.

Sergio Schvezov (sergiusens) wrote :

I did it

Michael Vogt (mvo) wrote :

Very impressive, thanks a bunch. We need the opposite of FIXME now so that we can re-use the fully mocked store to re-use it in other tests :-D

review: Approve
Snappy Tarmac (snappydevtarmac) wrote :
Download full text (5.7 KiB)

The attempt to merge lp:~sergiusens/snappy/upload into lp:snappy failed. Below is the output from the failed tests.

Checking docs
Checking formatting
Installing godeps
Install golint
Obtaining dependencies
update code.google.com/p/go.crypto failed; trying to fetch newer version
update github.com/blakesmith/ar failed; trying to fetch newer version
code.google.com/p/go.crypto now at 69e2a90ed92d03812364aeb947b7068dc42e561e
update github.com/cheggaaa/pb failed; trying to fetch newer version
github.com/blakesmith/ar now at c9a977dd0cc1392b023382c7bfa5a22af8d3b730
update github.com/jessevdk/go-flags failed; trying to fetch newer version
github.com/cheggaaa/pb now at e8c7cc515bfde3e267957a3b110080ceed51354e
update github.com/mvo5/goconfigparser failed; trying to fetch newer version
github.com/jessevdk/go-flags now at 15347ef417a300349807983f15af9e65cd2e1b3a
update gopkg.in/check.v1 failed; trying to fetch newer version
github.com/mvo5/goconfigparser now at 26426272dda20cc76aa1fa44286dc743d2972fe8
update gopkg.in/yaml.v2 failed; trying to fetch newer version
gopkg.in/check.v1 now at 64131543e7896d5bcc6bd5a76287eb75ea96c673
gopkg.in/yaml.v2 now at 49c95bdc21843256fb6c4e0d370a05f24a0bf213
Building
Running tests from /home/tarmac/tmp/tmp.5ftTLX4xMx/src/launchpad.net/snappy
=== RUN Test
OK: 16 passed
--- PASS: Test (0.32 seconds)
PASS
coverage: 74.8% of statements
ok launchpad.net/snappy/clickdeb 0.323s coverage: 74.8% of statements
=== RUN Test
OK: 6 passed
--- PASS: Test (0.01 seconds)
PASS
coverage: 12.2% of statements
ok launchpad.net/snappy/cmd/snappy 0.021s coverage: 12.2% of statements
=== RUN Test
OK: 24 passed
--- PASS: Test (0.10 seconds)
PASS
coverage: 100.0% of statements
ok launchpad.net/snappy/coreconfig 0.101s coverage: 100.0% of statements
=== RUN Test
OK: 50 passed
--- PASS: Test (0.32 seconds)
PASS
coverage: 80.9% of statements
ok launchpad.net/snappy/helpers 0.323s coverage: 80.9% of statements
=== RUN Test
OK: 6 passed
--- PASS: Test (0.00 seconds)
PASS
coverage: 93.5% of statements
ok launchpad.net/snappy/logger 0.005s coverage: 93.5% of statements
=== RUN Test
OK: 4 passed
--- PASS: Test (0.00 seconds)
PASS
coverage: 100.0% of statements
ok launchpad.net/snappy/oauth 0.006s coverage: 100.0% of statements
=== RUN Test
OK: 38 passed
--- PASS: Test (0.16 seconds)
PASS
coverage: 81.1% of statements
ok launchpad.net/snappy/partition 0.165s coverage: 81.1% of statements
=== RUN Test
OK: 3 passed
--- PASS: Test (0.00 seconds)
PASS
coverage: 100.0% of statements
ok launchpad.net/snappy/pkg 0.003s coverage: 100.0% of statements
=== RUN Test
OK: 12 passed
--- PASS: Test (0.10 seconds)
PASS
coverage: 94.3% of statements
ok launchpad.net/snappy/policy 0.110s coverage: 94.3% of statements
=== RUN Test
OK: 3 passed
--- PASS: Test (0.00 seconds)
PASS
coverage: 84.8% of statements
ok launchpad.net/snappy/priv 0.005s coverage: 84.8% of statements
=== RUN Test
OK: 4 passed
--- PASS: Test (0.00 seconds)
PASS
coverage: 50.0% of statements
ok launchpad.net/snappy/progress 0.008s coverage: 50.0% of statements
=== RUN Test
OK: 6 passed
--- PASS: Test (0.01 seconds)
PASS
coverage: 100.0% of statements
ok launchpad.net/snappy/provi...

Read more...

review: Approve
Snappy Tarmac (snappydevtarmac) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmd/snappy/cmd_update.go'
2--- cmd/snappy/cmd_update.go 2015-05-19 14:09:19 +0000
3+++ cmd/snappy/cmd_update.go 2015-06-10 15:13:33 +0000
4@@ -66,21 +66,11 @@
5 flags = 0
6 }
7
8- updates, err := snappy.ListUpdates()
9+ updates, err := snappy.Update(flags, progress.MakeProgressBar())
10 if err != nil {
11 return err
12 }
13
14- for _, part := range updates {
15- fmt.Printf("Installing %s (%s)\n", part.Name(), part.Version())
16- if _, err := part.Install(progress.MakeProgressBar(), flags); err != nil {
17- return err
18- }
19- if err := snappy.GarbageCollect(part.Name(), flags, progress.MakeProgressBar()); err != nil {
20- return err
21- }
22- }
23-
24 if len(updates) > 0 {
25 showVerboseList(updates, os.Stdout)
26 }
27
28=== modified file 'snappy/install.go'
29--- snappy/install.go 2015-05-20 17:24:29 +0000
30+++ snappy/install.go 2015-06-10 15:13:33 +0000
31@@ -20,6 +20,7 @@
32 package snappy
33
34 import (
35+ "fmt"
36 "io/ioutil"
37 "os"
38 "sort"
39@@ -65,6 +66,29 @@
40 return false
41 }
42
43+// Update the installed snappy packages, it returns the updated Parts
44+// if updates where available and an error and nil if any of the updates
45+// fail to apply.
46+func Update(flags InstallFlags, meter progress.Meter) ([]Part, error) {
47+ updates, err := ListUpdates()
48+ if err != nil {
49+ return nil, err
50+ }
51+
52+ for _, part := range updates {
53+ meter.Notify(fmt.Sprintf("Updating %s (%s)", part.Name(), part.Version()))
54+
55+ if _, err := part.Install(meter, flags); err != nil {
56+ return nil, err
57+ }
58+ if err := GarbageCollect(part.Name(), flags, meter); err != nil {
59+ return nil, err
60+ }
61+ }
62+
63+ return updates, nil
64+}
65+
66 // Install the givens snap names provided via args. This can be local
67 // files or snaps that are queried from the store
68 func Install(name string, flags InstallFlags, meter progress.Meter) (string, error) {
69
70=== modified file 'snappy/install_test.go'
71--- snappy/install_test.go 2015-06-09 19:11:54 +0000
72+++ snappy/install_test.go 2015-06-10 15:13:33 +0000
73@@ -20,6 +20,7 @@
74 package snappy
75
76 import (
77+ "fmt"
78 "io"
79 "io/ioutil"
80 "net/http"
81@@ -29,6 +30,7 @@
82 "path/filepath"
83
84 . "gopkg.in/check.v1"
85+ "launchpad.net/snappy/partition"
86 "launchpad.net/snappy/progress"
87 )
88
89@@ -182,3 +184,89 @@
90 _, err = Install("hello-app.potato", 0, ag)
91 c.Assert(err, ErrorMatches, ".*"+ErrPackageNameAlreadyInstalled.Error())
92 }
93+
94+func (s *SnapTestSuite) TestUpdate(c *C) {
95+ snapPackagev1 := makeTestSnapPackage(c, "name: foo\nversion: 1\nvendor: foo")
96+ name, err := Install(snapPackagev1, AllowUnauthenticated|DoInstallGC, &progress.NullProgress{})
97+ c.Assert(err, IsNil)
98+ c.Assert(name, Equals, "foo")
99+
100+ snapPackagev2 := makeTestSnapPackage(c, "name: foo\nversion: 2\nvendor: foo")
101+
102+ snapR, err := os.Open(snapPackagev2)
103+ c.Assert(err, IsNil)
104+ defer snapR.Close()
105+
106+ // details
107+ var dlURL string
108+ mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
109+ switch r.URL.Path {
110+ case "/details/foo":
111+ io.WriteString(w, `{
112+"package_name": "foo",
113+"version": "2",
114+"origin": "sideload",
115+"anon_download_url": "`+dlURL+`"
116+}`)
117+ case "/dl":
118+ snapR.Seek(0, 0)
119+ io.Copy(w, snapR)
120+ default:
121+ panic("unexpected url path: " + r.URL.Path)
122+ }
123+ }))
124+ dlURL = mockServer.URL + "/dl"
125+
126+ storeDetailsURI, err = url.Parse(mockServer.URL + "/details/")
127+ c.Assert(err, IsNil)
128+
129+ c.Assert(mockServer, NotNil)
130+ defer mockServer.Close()
131+
132+ // bulk
133+ mockServer = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
134+ io.WriteString(w, `[{
135+ "package_name": "foo",
136+ "version": "2",
137+ "origin": "sideload",
138+ "anon_download_url": "`+dlURL+`"
139+}]`)
140+ }))
141+
142+ storeBulkURI, err = url.Parse(mockServer.URL)
143+ c.Assert(err, IsNil)
144+
145+ c.Assert(mockServer, NotNil)
146+ defer mockServer.Close()
147+
148+ // system image
149+ newPartition = func() (p partition.Interface) {
150+ return new(MockPartition)
151+ }
152+ defer func() { newPartition = newPartitionImpl }()
153+
154+ tempdir := c.MkDir()
155+ systemImageRoot = tempdir
156+
157+ makeFakeSystemImageChannelConfig(c, filepath.Join(tempdir, systemImageChannelConfig), "1")
158+ // setup fake /other partition
159+ makeFakeSystemImageChannelConfig(c, filepath.Join(tempdir, "other", systemImageChannelConfig), "2")
160+
161+ siServer := runMockSystemImageWebServer()
162+ defer siServer.Close()
163+
164+ mockServer = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
165+ io.WriteString(w, fmt.Sprintf(mockSystemImageIndexJSONTemplate, "1"))
166+ }))
167+ c.Assert(mockServer, NotNil)
168+ defer mockServer.Close()
169+
170+ systemImageServer = mockServer.URL
171+
172+ // the test
173+ updates, err := Update(0, &progress.NullProgress{})
174+ c.Assert(err, IsNil)
175+ c.Assert(updates, HasLen, 1)
176+ c.Check(updates[0].Name(), Equals, "foo")
177+ c.Check(updates[0].Version(), Equals, "2")
178+}
179
180=== modified file 'snappy/systemimage.go'
181--- snappy/systemimage.go 2015-06-09 20:36:07 +0000
182+++ snappy/systemimage.go 2015-06-10 15:13:33 +0000
183@@ -68,7 +68,9 @@
184 var systemImageRoot = "/"
185
186 // will replace newPartition() to return a mockPartition
187-var newPartition = func() (p partition.Interface) {
188+var newPartition = newPartitionImpl
189+
190+func newPartitionImpl() (p partition.Interface) {
191 return partition.New()
192 }
193

Subscribers

People subscribed via source and target branches