Merge lp:~mvo/snappy/snappy-improve-developer-mode-detection into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Michael Vogt on 2015-06-10
Status: Merged
Approved by: Michael Vogt on 2015-06-22
Approved revision: 507
Merged at revision: 515
Proposed branch: lp:~mvo/snappy/snappy-improve-developer-mode-detection
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 301 lines (+94/-85)
4 files modified
provisioning/provisioning.go (+29/-5)
provisioning/provisioning_test.go (+58/-40)
snappy/install.go (+7/-25)
snappy/install_test.go (+0/-15)
To merge this branch: bzr merge lp:~mvo/snappy/snappy-improve-developer-mode-detection
Reviewer Review Type Date Requested Status
Michael Vogt Approve on 2015-06-22
Sergio Schvezov 2015-06-10 Approve on 2015-06-19
Review via email: mp+261646@code.launchpad.net

Commit Message

Use install.yaml to detect if in developer mode.

Description of the Change

This branch improves the developer mode detection by using the new
ubuntu-device-flash mechanism. It does not care about backward
compatibility currently. If thats a issue I can add the old code
back but given that it was not really reliable this seems like the
better approach.

It also does a bit of cleanup in the tests.

To post a comment you must log in.
Sergio Schvezov (sergiusens) wrote :

hey, looks good, just some comments and maybe merge trunk.

we also maybe should define those // no idea

Michael Vogt (mvo) :
Michael Vogt (mvo) wrote :

Thanks, addressed (most) points and replied inline in the previous comment.

Michael Vogt (mvo) wrote :

Is there anything else missing in this branch? It has some dependencies that are stalled right now :)

Sergio Schvezov (sergiusens) wrote :

> Is there anything else missing in this branch? It has some dependencies that
> are stalled right now :)

It is related to the conversation from yesterday about u-d-f only being in tools-proposed; I guess its fine in any case as this is rolling...

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

The attempt to merge lp:~mvo/snappy/snappy-improve-developer-mode-detection 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.BeKP6ui6Ol/src/launchpad.net/snappy
=== RUN Test
OK: 16 passed
--- PASS: Test (0.32 seconds)
PASS
coverage: 74.3% of statements
ok launchpad.net/snappy/clickdeb 0.327s coverage: 74.3% of statements
=== RUN Test
OK: 6 passed
--- PASS: Test (0.07 seconds)
PASS
coverage: 12.9% of statements
ok launchpad.net/snappy/cmd/snappy 0.083s coverage: 12.9% of statements
=== RUN Test
OK: 24 passed
--- PASS: Test (0.08 seconds)
PASS
coverage: 100.0% of statements
ok launchpad.net/snappy/coreconfig 0.088s coverage: 100.0% of statements
=== RUN Test
OK: 50 passed
--- PASS: Test (0.34 seconds)
PASS
coverage: 80.9% of statements
ok launchpad.net/snappy/helpers 0.347s 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.005s coverage: 100.0% of statements
=== RUN Test
OK: 38 passed
--- PASS: Test (0.19 seconds)
PASS
coverage: 81.1% of statements
ok launchpad.net/snappy/partition 0.191s 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.004s coverage: 100.0% of statements
=== RUN Test
OK: 12 passed
--- PASS: Test (0.07 seconds)
PASS
coverage: 94.3% of statements
ok launchpad.net/snappy/policy 0.072s coverage: 94.3% of statements
=== RUN Test
OK: 5 passed
--- PASS: Test (0.20 seconds)
PASS
coverage: 91.1% of statements
ok launchpad.net/snappy/priv 0.210s coverage: 91.1% of statements
=== RUN Test
OK: 4 passed
--- PASS: Test (0.02 seconds)
PASS
coverage: 50.0% of statements
ok launchpad.net/snappy/progress 0.020s coverage: 50.0% of statements
=== RUN Test

----------------------------------------------------------------------
FAIL: provis...

Read more...

506. By Michael Vogt on 2015-06-22

merged lp:snappy

507. By Michael Vogt on 2015-06-22

fix test in tarmac

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 'provisioning/provisioning.go'
2--- provisioning/provisioning.go 2015-06-09 18:07:51 +0000
3+++ provisioning/provisioning.go 2015-06-22 13:55:37 +0000
4@@ -29,18 +29,24 @@
5 "gopkg.in/yaml.v2"
6 )
7
8-var (
9+const (
10 // InstallYamlFile is the name of the file created by
11 // ubuntu-device-flash(1), created at system installation time,
12 // that contains metadata on the installation.
13 //
14 // XXX: Public for ubuntu-device-flash(1)
15 InstallYamlFile = "install.yaml"
16-
17- // ErrNoInstallYaml is emitted when InstallYamlFile does not exist.
18- ErrNoInstallYaml = fmt.Errorf("no %s", InstallYamlFile)
19 )
20
21+// ErrNoInstallYaml is emitted when InstallYamlFile does not exist.
22+type ErrNoInstallYaml struct {
23+ origErr error
24+}
25+
26+func (e *ErrNoInstallYaml) Error() string {
27+ return fmt.Sprintf("failed to read provisioning data: %s", e.origErr)
28+}
29+
30 // InstallMeta encapsulates the metadata for a system install.
31 type InstallMeta struct {
32 Timestamp time.Time
33@@ -79,7 +85,7 @@
34 func parseInstallYaml(path string) (*InstallYaml, error) {
35 data, err := ioutil.ReadFile(path)
36 if err != nil {
37- return nil, ErrNoInstallYaml
38+ return nil, &ErrNoInstallYaml{origErr: err}
39 }
40
41 return parseInstallYamlData(data)
42@@ -124,3 +130,21 @@
43
44 return false
45 }
46+
47+// InDeveloperMode returns true if the image was build with --developer-mode
48+func InDeveloperMode(bootloaderDir string) bool {
49+ file := filepath.Join(bootloaderDir, InstallYamlFile)
50+
51+ if !helpers.FileExists(file) {
52+ // no idea
53+ return false
54+ }
55+
56+ InstallYaml, err := parseInstallYaml(file)
57+ if err != nil {
58+ // no idea
59+ return false
60+ }
61+
62+ return InstallYaml.InstallOptions.DeveloperMode
63+}
64
65=== modified file 'provisioning/provisioning_test.go'
66--- provisioning/provisioning_test.go 2015-06-10 12:52:22 +0000
67+++ provisioning/provisioning_test.go 2015-06-22 13:55:37 +0000
68@@ -30,8 +30,8 @@
69 func Test(t *testing.T) { TestingT(t) }
70
71 type ProvisioningTestSuite struct {
72- tempdir string
73- installYamlFile string
74+ mockBootDir string
75+ mockYamlFile string
76 }
77
78 var _ = Suite(&ProvisioningTestSuite{})
79@@ -78,74 +78,70 @@
80 var garbageData = `Fooled you!?`
81
82 func (ts *ProvisioningTestSuite) SetUpTest(c *C) {
83- ts.tempdir = c.MkDir()
84-
85- ts.installYamlFile = filepath.Join(ts.tempdir, "install.yaml")
86-
87- InstallYamlFile = ts.installYamlFile
88- os.Remove(InstallYamlFile)
89+ ts.mockBootDir = c.MkDir()
90+ ts.mockYamlFile = filepath.Join(ts.mockBootDir, "install.yaml")
91 }
92
93 func (ts *ProvisioningTestSuite) TestSideLoadedSystemNoInstallYaml(c *C) {
94- c.Assert(IsSideLoaded(""), Equals, false)
95+ c.Assert(IsSideLoaded(ts.mockBootDir), Equals, false)
96 }
97
98 func (ts *ProvisioningTestSuite) TestSideLoadedSystem(c *C) {
99- c.Assert(IsSideLoaded(""), Equals, false)
100+ c.Assert(IsSideLoaded(ts.mockBootDir), Equals, false)
101
102- err := ioutil.WriteFile(InstallYamlFile, []byte(yamlData), 0750)
103+ err := ioutil.WriteFile(ts.mockYamlFile, []byte(yamlData), 0750)
104 c.Assert(err, IsNil)
105
106- c.Assert(IsSideLoaded(""), Equals, true)
107+ c.Assert(IsSideLoaded(ts.mockBootDir), Equals, true)
108
109- os.Remove(InstallYamlFile)
110- c.Assert(IsSideLoaded(""), Equals, false)
111+ os.Remove(ts.mockYamlFile)
112+ c.Assert(IsSideLoaded(ts.mockBootDir), Equals, false)
113 }
114
115 func (ts *ProvisioningTestSuite) TestSideLoadedSystemNoDevicePart(c *C) {
116
117- c.Assert(IsSideLoaded(""), Equals, false)
118+ c.Assert(IsSideLoaded(ts.mockBootDir), Equals, false)
119
120- err := ioutil.WriteFile(InstallYamlFile, []byte(yamlDataNoDevicePart), 0750)
121+ err := ioutil.WriteFile(ts.mockYamlFile, []byte(yamlDataNoDevicePart), 0750)
122 c.Assert(err, IsNil)
123
124- c.Assert(IsSideLoaded(""), Equals, false)
125+ c.Assert(IsSideLoaded(ts.mockBootDir), Equals, false)
126
127- os.Remove(InstallYamlFile)
128- c.Assert(IsSideLoaded(""), Equals, false)
129+ os.Remove(ts.mockYamlFile)
130+ c.Assert(IsSideLoaded(ts.mockBootDir), Equals, false)
131 }
132
133 func (ts *ProvisioningTestSuite) TestSideLoadedSystemGarbageInstallYaml(c *C) {
134- c.Assert(IsSideLoaded(""), Equals, false)
135+ c.Assert(IsSideLoaded(ts.mockBootDir), Equals, false)
136
137- err := ioutil.WriteFile(InstallYamlFile, []byte(garbageData), 0750)
138+ err := ioutil.WriteFile(ts.mockYamlFile, []byte(garbageData), 0750)
139 c.Assert(err, IsNil)
140
141 // we assume sideloaded if the file isn't parseable
142- c.Assert(IsSideLoaded(""), Equals, true)
143+ c.Assert(IsSideLoaded(ts.mockBootDir), Equals, true)
144
145- os.Remove(InstallYamlFile)
146- c.Assert(IsSideLoaded(""), Equals, false)
147+ os.Remove(ts.mockYamlFile)
148+ c.Assert(IsSideLoaded(ts.mockBootDir), Equals, false)
149 }
150
151 func (ts *ProvisioningTestSuite) TestParseInstallYaml(c *C) {
152
153- _, err := parseInstallYaml(InstallYamlFile)
154- c.Check(err, Equals, ErrNoInstallYaml)
155-
156- err = ioutil.WriteFile(InstallYamlFile, []byte(yamlData), 0750)
157- c.Check(err, IsNil)
158- _, err = parseInstallYaml(InstallYamlFile)
159- c.Check(err, IsNil)
160-
161- err = ioutil.WriteFile(InstallYamlFile, []byte(yamlDataNoDevicePart), 0750)
162- c.Check(err, IsNil)
163- _, err = parseInstallYaml(InstallYamlFile)
164- c.Check(err, IsNil)
165-
166- err = ioutil.WriteFile(InstallYamlFile, []byte(garbageData), 0750)
167- c.Check(err, IsNil)
168- _, err = parseInstallYaml(InstallYamlFile)
169+ _, err := parseInstallYaml(ts.mockYamlFile)
170+ c.Check(err, ErrorMatches, `failed to read provisioning data: open .*/install.yaml: no such file or directory`)
171+
172+ err = ioutil.WriteFile(ts.mockYamlFile, []byte(yamlData), 0750)
173+ c.Check(err, IsNil)
174+ _, err = parseInstallYaml(ts.mockYamlFile)
175+ c.Check(err, IsNil)
176+
177+ err = ioutil.WriteFile(ts.mockYamlFile, []byte(yamlDataNoDevicePart), 0750)
178+ c.Check(err, IsNil)
179+ _, err = parseInstallYaml(ts.mockYamlFile)
180+ c.Check(err, IsNil)
181+
182+ err = ioutil.WriteFile(ts.mockYamlFile, []byte(garbageData), 0750)
183+ c.Check(err, IsNil)
184+ _, err = parseInstallYaml(ts.mockYamlFile)
185 c.Check(err, Not(Equals), nil)
186 }
187
188@@ -163,3 +159,25 @@
189 _, err = parseInstallYamlData([]byte(garbageData))
190 c.Check(err, Not(Equals), nil)
191 }
192+
193+func (ts *ProvisioningTestSuite) TestInDeveloperModeEmpty(c *C) {
194+ c.Assert(InDeveloperMode(""), Equals, false)
195+}
196+
197+func (ts *ProvisioningTestSuite) TestInDeveloperModeWithDevModeOn(c *C) {
198+ err := ioutil.WriteFile(ts.mockYamlFile, []byte(`
199+options:
200+ developer-mode: true
201+`), 0644)
202+ c.Assert(err, IsNil)
203+ c.Assert(InDeveloperMode(ts.mockBootDir), Equals, true)
204+}
205+
206+func (ts *ProvisioningTestSuite) TestInDeveloperModeWithDevModeOff(c *C) {
207+ err := ioutil.WriteFile(ts.mockYamlFile, []byte(`
208+options:
209+ developer-mode: false
210+`), 0644)
211+ c.Assert(err, IsNil)
212+ c.Assert(InDeveloperMode(ts.mockBootDir), Equals, false)
213+}
214
215=== modified file 'snappy/install.go'
216--- snappy/install.go 2015-06-10 13:38:10 +0000
217+++ snappy/install.go 2015-06-22 13:55:37 +0000
218@@ -21,13 +21,12 @@
219
220 import (
221 "fmt"
222- "io/ioutil"
223 "os"
224 "sort"
225- "strings"
226
227 "launchpad.net/snappy/logger"
228 "launchpad.net/snappy/progress"
229+ "launchpad.net/snappy/provisioning"
230 )
231
232 // InstallFlags can be used to pass additional flags to the install of a
233@@ -45,28 +44,6 @@
234 AllowOEM
235 )
236
237-// check if the image is in developer mode
238-// FIXME: this is a bit crude right now, but it seems like there is not more
239-// meta-data to check right now
240-// TODO: add feature to ubuntu-device-flash to write better info file when
241-// the image is in developer mode
242-func inDeveloperMode() bool {
243- f, err := os.Open(cloudMetaDataFile)
244- if err != nil {
245- return false
246- }
247- defer f.Close()
248- data, err := ioutil.ReadAll(f)
249- if err != nil {
250- return false
251- }
252- needle := "public-keys:\n"
253- if strings.Contains(string(data), needle) {
254- return true
255- }
256- return false
257-}
258-
259 // Update the installed snappy packages, it returns the updated Parts
260 // if updates where available and an error and nil if any of the updates
261 // fail to apply.
262@@ -115,7 +92,12 @@
263 if fi, err := os.Stat(name); err == nil && fi.Mode().IsRegular() {
264 // we allow unauthenticated package when in developer
265 // mode
266- if inDeveloperMode() {
267+ //
268+ // FIXME: this is terrible, we really need a single
269+ // bootloader dir like /boot or /boot/loader
270+ // instead of having to query the partition code
271+ p := newPartition()
272+ if provisioning.InDeveloperMode(p.BootloaderDir()) {
273 flags |= AllowUnauthenticated
274 }
275
276
277=== modified file 'snappy/install_test.go'
278--- snappy/install_test.go 2015-06-10 15:13:07 +0000
279+++ snappy/install_test.go 2015-06-22 13:55:37 +0000
280@@ -42,21 +42,6 @@
281 return w.Name()
282 }
283
284-func (s *SnapTestSuite) TestNotInDeveloperMode(c *C) {
285- cloudMetaDataFile = makeCloudInitMetaData(c, `instance-id: nocloud-static`)
286- defer os.Remove(cloudMetaDataFile)
287- c.Assert(inDeveloperMode(), Equals, false)
288-}
289-
290-func (s *SnapTestSuite) TestInDeveloperMode(c *C) {
291- cloudMetaDataFile = makeCloudInitMetaData(c, `instance-id: nocloud-static
292-public-keys:
293- - ssh-rsa AAAAB3NzAndSoOn
294-`)
295- defer os.Remove(cloudMetaDataFile)
296- c.Assert(inDeveloperMode(), Equals, true)
297-}
298-
299 func (s *SnapTestSuite) TestInstallInstall(c *C) {
300 snapFile := makeTestSnapPackage(c, "")
301 name, err := Install(snapFile, AllowUnauthenticated|DoInstallGC, &progress.NullProgress{})

Subscribers

People subscribed via source and target branches