Merge lp:~mvo/snappy/snappy-lp1460152-workaround-15.04 into lp:~snappy-dev/snappy/15.04-deprecated

Proposed by Michael Vogt
Status: Work in progress
Proposed branch: lp:~mvo/snappy/snappy-lp1460152-workaround-15.04
Merge into: lp:~snappy-dev/snappy/15.04-deprecated
Diff against target: 140 lines (+74/-0)
5 files modified
helpers/helpers.go (+16/-0)
helpers/helpers_test.go (+11/-0)
snappy/dirs.go (+4/-0)
snappy/systemimage.go (+13/-0)
snappy/systemimage_test.go (+30/-0)
To merge this branch: bzr merge lp:~mvo/snappy/snappy-lp1460152-workaround-15.04
Reviewer Review Type Date Requested Status
Snappy Developers Pending
Review via email: mp+261148@code.launchpad.net

Commit message

This is a cherry pick of the workaround for LP: #1460152 for the 15.04
branch.

Description of the change

This is a cherry pick of the workaround for LP: #1460152 for the 15.04
branch.

To post a comment you must log in.

Unmerged revisions

451. By Michael Vogt

cherry pick r486 from lp:~mvo/snappy/snappy-lp1460152-workaround

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'helpers/helpers.go'
--- helpers/helpers.go 2015-06-04 15:00:44 +0000
+++ helpers/helpers.go 2015-06-04 20:52:35 +0000
@@ -471,3 +471,19 @@
471 "SNAPP_APP_USER_DATA_PATH={{.Home}}{{.AppPath}}",471 "SNAPP_APP_USER_DATA_PATH={{.Home}}{{.AppPath}}",
472 })472 })
473}473}
474
475// CleanDir cleans all regular files in the given directory
476func CleanDir(dir string) error {
477 dents, err := ioutil.ReadDir(dir)
478 if err != nil {
479 return err
480 }
481 for _, dent := range dents {
482 if dent.Mode().IsRegular() {
483 if err := os.Remove(filepath.Join(dir, dent.Name())); err != nil {
484 return err
485 }
486 }
487 }
488 return nil
489}
474490
=== modified file 'helpers/helpers_test.go'
--- helpers/helpers_test.go 2015-06-04 15:00:44 +0000
+++ helpers/helpers_test.go 2015-06-04 20:52:35 +0000
@@ -382,3 +382,14 @@
382 c.Check(err, NotNil)382 c.Check(err, NotNil)
383 c.Check(err, ErrorMatches, ".*permission denied.*")383 c.Check(err, ErrorMatches, ".*permission denied.*")
384}384}
385
386func (ts *HTestSuite) TestCleanDir(c *C) {
387 d := c.MkDir()
388 canary := filepath.Join(d, "foo")
389 err := ioutil.WriteFile(canary, []byte(nil), 0644)
390 c.Assert(err, IsNil)
391
392 err = CleanDir(d)
393 c.Assert(err, IsNil)
394 c.Assert(FileExists(canary), Equals, false)
395}
385396
=== modified file 'snappy/dirs.go'
--- snappy/dirs.go 2015-04-20 16:51:29 +0000
+++ snappy/dirs.go 2015-06-04 20:52:35 +0000
@@ -31,6 +31,8 @@
31 snapSeccompDir string31 snapSeccompDir string
32 snapUdevRulesDir string32 snapUdevRulesDir string
3333
34 systemApparmorProfileCacheDir string
35
34 snapBinariesDir string36 snapBinariesDir string
35 snapServicesDir string37 snapServicesDir string
36 snapBusPolicyDir string38 snapBusPolicyDir string
@@ -60,4 +62,6 @@
60 cloudMetaDataFile = filepath.Join(rootdir, "/var/lib/cloud/seed/nocloud-net/meta-data")62 cloudMetaDataFile = filepath.Join(rootdir, "/var/lib/cloud/seed/nocloud-net/meta-data")
6163
62 snapUdevRulesDir = filepath.Join(rootdir, "/etc/udev/rules.d")64 snapUdevRulesDir = filepath.Join(rootdir, "/etc/udev/rules.d")
65
66 systemApparmorProfileCacheDir = filepath.Join(rootdir, "/etc/apparmor.d/cache")
63}67}
6468
=== modified file 'snappy/systemimage.go'
--- snappy/systemimage.go 2015-05-29 11:52:39 +0000
+++ snappy/systemimage.go 2015-06-04 20:52:35 +0000
@@ -227,12 +227,25 @@
227 if pb != nil {227 if pb != nil {
228 pb.Notify("Updating boot files")228 pb.Notify("Updating boot files")
229 }229 }
230
231 // this needs to go once we have a clean fix for #1460152
232 if err := s.postUpgradeHacks(); err != nil {
233 return "", err
234 }
235
230 if err = s.partition.ToggleNextBoot(); err != nil {236 if err = s.partition.ToggleNextBoot(); err != nil {
231 return "", err237 return "", err
232 }238 }
233 return systemImagePartName, nil239 return systemImagePartName, nil
234}240}
235241
242// this makes me cry
243func (s *SystemImagePart) postUpgradeHacks() error {
244 // Apply HACK to deal with bug #1460152 where the apparmor
245 // cache is confused after the upgrade
246 return helpers.CleanDir(systemApparmorProfileCacheDir)
247}
248
236// Ensure the expected version update was applied to the expected partition.249// Ensure the expected version update was applied to the expected partition.
237func (s *SystemImagePart) verifyUpgradeWasApplied() error {250func (s *SystemImagePart) verifyUpgradeWasApplied() error {
238 // The upgrade has now been applied, so check that the expected251 // The upgrade has now been applied, so check that the expected
239252
=== modified file 'snappy/systemimage_test.go'
--- snappy/systemimage_test.go 2015-04-22 10:35:09 +0000
+++ snappy/systemimage_test.go 2015-06-04 20:52:35 +0000
@@ -56,6 +56,13 @@
56 // setup fake /other partition56 // setup fake /other partition
57 makeFakeSystemImageChannelConfig(c, filepath.Join(tempdir, "other", systemImageChannelConfig), "2")57 makeFakeSystemImageChannelConfig(c, filepath.Join(tempdir, "other", systemImageChannelConfig), "2")
5858
59 // fake the apparmor.d/cache
60 systemApparmorProfileCacheDir = filepath.Join(systemImageRoot, "etc", "apparmor.d", "cache")
61 err := os.MkdirAll(systemApparmorProfileCacheDir, 0755)
62 c.Assert(err, IsNil)
63 err = ioutil.WriteFile(filepath.Join(systemApparmorProfileCacheDir, "some-cache"), []byte(nil), 0644)
64 c.Assert(err, IsNil)
65
59 // run test webserver instead of talking to the real one66 // run test webserver instead of talking to the real one
60 //67 //
61 // The mock webserver versions "1" and "2"68 // The mock webserver versions "1" and "2"
@@ -189,6 +196,29 @@
189 c.Assert(pb.progress, DeepEquals, []float64{20.0, 40.0, 60.0, 80.0, 100.0})196 c.Assert(pb.progress, DeepEquals, []float64{20.0, 40.0, 60.0, 80.0, 100.0})
190}197}
191198
199func (s *SITestSuite) TestSystemImagePartInstalAppliesHackLp1460152(c *C) {
200 // add a update
201 mockSystemImageIndexJSON = fmt.Sprintf(mockSystemImageIndexJSONTemplate, "2")
202 parts, err := s.systemImage.Updates()
203
204 sp := parts[0].(*SystemImagePart)
205 mockPartition := MockPartition{}
206 sp.partition = &mockPartition
207
208 dents, err := ioutil.ReadDir(systemApparmorProfileCacheDir)
209 c.Assert(err, IsNil)
210 c.Assert(dents, HasLen, 1)
211
212 pb := &MockProgressMeter{}
213 // do the install
214 _, err = sp.Install(pb, 0)
215 c.Assert(err, IsNil)
216
217 dents, err = ioutil.ReadDir(systemApparmorProfileCacheDir)
218 c.Assert(err, IsNil)
219 c.Assert(dents, HasLen, 0)
220}
221
192func (s *SITestSuite) TestSystemImagePartInstallUpdatesBroken(c *C) {222func (s *SITestSuite) TestSystemImagePartInstallUpdatesBroken(c *C) {
193 // fake a broken upgrade223 // fake a broken upgrade
194 scriptContent := `#!/bin/sh224 scriptContent := `#!/bin/sh

Subscribers

People subscribed via source and target branches