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
1=== modified file 'helpers/helpers.go'
2--- helpers/helpers.go 2015-06-04 15:00:44 +0000
3+++ helpers/helpers.go 2015-06-04 20:52:35 +0000
4@@ -471,3 +471,19 @@
5 "SNAPP_APP_USER_DATA_PATH={{.Home}}{{.AppPath}}",
6 })
7 }
8+
9+// CleanDir cleans all regular files in the given directory
10+func CleanDir(dir string) error {
11+ dents, err := ioutil.ReadDir(dir)
12+ if err != nil {
13+ return err
14+ }
15+ for _, dent := range dents {
16+ if dent.Mode().IsRegular() {
17+ if err := os.Remove(filepath.Join(dir, dent.Name())); err != nil {
18+ return err
19+ }
20+ }
21+ }
22+ return nil
23+}
24
25=== modified file 'helpers/helpers_test.go'
26--- helpers/helpers_test.go 2015-06-04 15:00:44 +0000
27+++ helpers/helpers_test.go 2015-06-04 20:52:35 +0000
28@@ -382,3 +382,14 @@
29 c.Check(err, NotNil)
30 c.Check(err, ErrorMatches, ".*permission denied.*")
31 }
32+
33+func (ts *HTestSuite) TestCleanDir(c *C) {
34+ d := c.MkDir()
35+ canary := filepath.Join(d, "foo")
36+ err := ioutil.WriteFile(canary, []byte(nil), 0644)
37+ c.Assert(err, IsNil)
38+
39+ err = CleanDir(d)
40+ c.Assert(err, IsNil)
41+ c.Assert(FileExists(canary), Equals, false)
42+}
43
44=== modified file 'snappy/dirs.go'
45--- snappy/dirs.go 2015-04-20 16:51:29 +0000
46+++ snappy/dirs.go 2015-06-04 20:52:35 +0000
47@@ -31,6 +31,8 @@
48 snapSeccompDir string
49 snapUdevRulesDir string
50
51+ systemApparmorProfileCacheDir string
52+
53 snapBinariesDir string
54 snapServicesDir string
55 snapBusPolicyDir string
56@@ -60,4 +62,6 @@
57 cloudMetaDataFile = filepath.Join(rootdir, "/var/lib/cloud/seed/nocloud-net/meta-data")
58
59 snapUdevRulesDir = filepath.Join(rootdir, "/etc/udev/rules.d")
60+
61+ systemApparmorProfileCacheDir = filepath.Join(rootdir, "/etc/apparmor.d/cache")
62 }
63
64=== modified file 'snappy/systemimage.go'
65--- snappy/systemimage.go 2015-05-29 11:52:39 +0000
66+++ snappy/systemimage.go 2015-06-04 20:52:35 +0000
67@@ -227,12 +227,25 @@
68 if pb != nil {
69 pb.Notify("Updating boot files")
70 }
71+
72+ // this needs to go once we have a clean fix for #1460152
73+ if err := s.postUpgradeHacks(); err != nil {
74+ return "", err
75+ }
76+
77 if err = s.partition.ToggleNextBoot(); err != nil {
78 return "", err
79 }
80 return systemImagePartName, nil
81 }
82
83+// this makes me cry
84+func (s *SystemImagePart) postUpgradeHacks() error {
85+ // Apply HACK to deal with bug #1460152 where the apparmor
86+ // cache is confused after the upgrade
87+ return helpers.CleanDir(systemApparmorProfileCacheDir)
88+}
89+
90 // Ensure the expected version update was applied to the expected partition.
91 func (s *SystemImagePart) verifyUpgradeWasApplied() error {
92 // The upgrade has now been applied, so check that the expected
93
94=== modified file 'snappy/systemimage_test.go'
95--- snappy/systemimage_test.go 2015-04-22 10:35:09 +0000
96+++ snappy/systemimage_test.go 2015-06-04 20:52:35 +0000
97@@ -56,6 +56,13 @@
98 // setup fake /other partition
99 makeFakeSystemImageChannelConfig(c, filepath.Join(tempdir, "other", systemImageChannelConfig), "2")
100
101+ // fake the apparmor.d/cache
102+ systemApparmorProfileCacheDir = filepath.Join(systemImageRoot, "etc", "apparmor.d", "cache")
103+ err := os.MkdirAll(systemApparmorProfileCacheDir, 0755)
104+ c.Assert(err, IsNil)
105+ err = ioutil.WriteFile(filepath.Join(systemApparmorProfileCacheDir, "some-cache"), []byte(nil), 0644)
106+ c.Assert(err, IsNil)
107+
108 // run test webserver instead of talking to the real one
109 //
110 // The mock webserver versions "1" and "2"
111@@ -189,6 +196,29 @@
112 c.Assert(pb.progress, DeepEquals, []float64{20.0, 40.0, 60.0, 80.0, 100.0})
113 }
114
115+func (s *SITestSuite) TestSystemImagePartInstalAppliesHackLp1460152(c *C) {
116+ // add a update
117+ mockSystemImageIndexJSON = fmt.Sprintf(mockSystemImageIndexJSONTemplate, "2")
118+ parts, err := s.systemImage.Updates()
119+
120+ sp := parts[0].(*SystemImagePart)
121+ mockPartition := MockPartition{}
122+ sp.partition = &mockPartition
123+
124+ dents, err := ioutil.ReadDir(systemApparmorProfileCacheDir)
125+ c.Assert(err, IsNil)
126+ c.Assert(dents, HasLen, 1)
127+
128+ pb := &MockProgressMeter{}
129+ // do the install
130+ _, err = sp.Install(pb, 0)
131+ c.Assert(err, IsNil)
132+
133+ dents, err = ioutil.ReadDir(systemApparmorProfileCacheDir)
134+ c.Assert(err, IsNil)
135+ c.Assert(dents, HasLen, 0)
136+}
137+
138 func (s *SITestSuite) TestSystemImagePartInstallUpdatesBroken(c *C) {
139 // fake a broken upgrade
140 scriptContent := `#!/bin/sh

Subscribers

People subscribed via source and target branches