Merge lp:~fgimenez/snappy/extract-mount-functions into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Federico Gimenez
Status: Merged
Approved by: Federico Gimenez
Approved revision: 723
Merged at revision: 734
Proposed branch: lp:~fgimenez/snappy/extract-mount-functions
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Prerequisite: lp:~fgimenez/snappy/cli-pkg
Diff against target: 261 lines (+126/-26)
6 files modified
_integration-tests/tests/failover_rclocal_crash_test.go (+5/-4)
_integration-tests/tests/failover_systemd_loop_test.go (+5/-4)
_integration-tests/tests/failover_zero_size_file_test.go (+2/-2)
_integration-tests/testutils/common/common.go (+7/-16)
_integration-tests/testutils/partition/partition.go (+38/-0)
_integration-tests/testutils/partition/partition_test.go (+69/-0)
To merge this branch: bzr merge lp:~fgimenez/snappy/extract-mount-functions
Reviewer Review Type Date Requested Status
Leo Arias (community) Approve
Review via email: mp+273035@code.launchpad.net

Commit message

MakeWritable and MakeReadonly moved from common to partition

Description of the change

MakeWritable and MakeReadonly moved from common to partition

To post a comment you must log in.
722. By Federico Gimenez

cmd without join

Revision history for this message
Leo Arias (elopio) wrote :

nice

review: Approve
723. By Federico Gimenez

merged prerequisite

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '_integration-tests/tests/failover_rclocal_crash_test.go'
2--- _integration-tests/tests/failover_rclocal_crash_test.go 2015-10-02 10:28:33 +0000
3+++ _integration-tests/tests/failover_rclocal_crash_test.go 2015-10-02 10:28:33 +0000
4@@ -24,6 +24,7 @@
5
6 "launchpad.net/snappy/_integration-tests/testutils/cli"
7 "launchpad.net/snappy/_integration-tests/testutils/common"
8+ "launchpad.net/snappy/_integration-tests/testutils/partition"
9
10 "gopkg.in/check.v1"
11 )
12@@ -31,8 +32,8 @@
13 type rcLocalCrash struct{}
14
15 func (rcLocalCrash) set(c *check.C) {
16- common.MakeWritable(c, common.BaseAltPartitionPath)
17- defer common.MakeReadonly(c, common.BaseAltPartitionPath)
18+ partition.MakeWritable(c, common.BaseAltPartitionPath)
19+ defer partition.MakeReadonly(c, common.BaseAltPartitionPath)
20 targetFile := fmt.Sprintf("%s/etc/rc.local", common.BaseAltPartitionPath)
21 cli.ExecCommand(c, "sudo", "chmod", "a+xw", targetFile)
22
23@@ -41,8 +42,8 @@
24 }
25
26 func (rcLocalCrash) unset(c *check.C) {
27- common.MakeWritable(c, common.BaseAltPartitionPath)
28- defer common.MakeReadonly(c, common.BaseAltPartitionPath)
29+ partition.MakeWritable(c, common.BaseAltPartitionPath)
30+ defer partition.MakeReadonly(c, common.BaseAltPartitionPath)
31 cli.ExecCommand(c, "sudo", "rm", fmt.Sprintf("%s/etc/rc.local", common.BaseAltPartitionPath))
32 }
33
34
35=== modified file '_integration-tests/tests/failover_systemd_loop_test.go'
36--- _integration-tests/tests/failover_systemd_loop_test.go 2015-10-02 10:28:33 +0000
37+++ _integration-tests/tests/failover_systemd_loop_test.go 2015-10-02 10:28:33 +0000
38@@ -24,6 +24,7 @@
39
40 "launchpad.net/snappy/_integration-tests/testutils/cli"
41 "launchpad.net/snappy/_integration-tests/testutils/common"
42+ "launchpad.net/snappy/_integration-tests/testutils/partition"
43
44 "gopkg.in/check.v1"
45 )
46@@ -72,8 +73,8 @@
47 }
48
49 func installService(c *check.C, serviceName, serviceCfg, basePath string) {
50- common.MakeWritable(c, basePath)
51- defer common.MakeReadonly(c, basePath)
52+ partition.MakeWritable(c, basePath)
53+ defer partition.MakeReadonly(c, basePath)
54
55 // Create service file
56 serviceFile := fmt.Sprintf("%s%s/%s.service", basePath, baseSystemdPath, serviceName)
57@@ -94,8 +95,8 @@
58 }
59
60 func unInstallService(c *check.C, serviceName, basePath string) {
61- common.MakeWritable(c, basePath)
62- defer common.MakeReadonly(c, basePath)
63+ partition.MakeWritable(c, basePath)
64+ defer partition.MakeReadonly(c, basePath)
65
66 // Disable the service
67 cli.ExecCommand(c, "sudo", "chroot", basePath,
68
69=== modified file '_integration-tests/tests/failover_zero_size_file_test.go'
70--- _integration-tests/tests/failover_zero_size_file_test.go 2015-10-02 10:28:33 +0000
71+++ _integration-tests/tests/failover_zero_size_file_test.go 2015-10-02 10:28:33 +0000
72@@ -107,8 +107,8 @@
73 // Only need to make writable and revert for BaseAltPartitionPath,
74 // kernel files' boot directory is writable
75 if basePath == common.BaseAltPartitionPath {
76- common.MakeWritable(c, basePath)
77- defer common.MakeReadonly(c, basePath)
78+ partition.MakeWritable(c, basePath)
79+ defer partition.MakeReadonly(c, basePath)
80 }
81
82 cli.ExecCommand(c, "sudo", "mv", oldFilename, newFilename)
83
84=== modified file '_integration-tests/testutils/common/common.go'
85--- _integration-tests/testutils/common/common.go 2015-10-02 10:28:33 +0000
86+++ _integration-tests/testutils/common/common.go 2015-10-02 10:28:33 +0000
87@@ -32,6 +32,7 @@
88
89 "launchpad.net/snappy/_integration-tests/testutils/cli"
90 "launchpad.net/snappy/_integration-tests/testutils/config"
91+ "launchpad.net/snappy/_integration-tests/testutils/partition"
92 )
93
94 const (
95@@ -127,8 +128,8 @@
96 m[channelCfgOtherBackupFile()] = BaseAltPartitionPath
97 for backup, target := range m {
98 if _, err := os.Stat(backup); err == nil {
99- MakeWritable(c, target)
100- defer MakeReadonly(c, target)
101+ partition.MakeWritable(c, target)
102+ defer partition.MakeReadonly(c, target)
103 original := filepath.Join(target, channelCfgFile)
104 c.Logf("Restoring %s...", original)
105 cli.ExecCommand(c, "sudo", "mv", backup, original)
106@@ -153,8 +154,8 @@
107 for _, target := range targets {
108 file := filepath.Join(target, channelCfgFile)
109 if _, err := os.Stat(file); err == nil {
110- MakeWritable(c, target)
111- defer MakeReadonly(c, target)
112+ partition.MakeWritable(c, target)
113+ defer partition.MakeReadonly(c, target)
114 replaceSystemImageValues(c, file, release, channel, version)
115 }
116 }
117@@ -228,8 +229,8 @@
118 for target, backup := range m {
119 file := filepath.Join(target, channelCfgFile)
120 if _, err := os.Stat(file); err == nil {
121- MakeWritable(c, target)
122- defer MakeReadonly(c, target)
123+ partition.MakeWritable(c, target)
124+ defer partition.MakeReadonly(c, target)
125 // Back up the file. It will be restored during the test tear down.
126 cli.ExecCommand(c, "cp", file, backup)
127 replaceSystemImageValues(c, file, "", "", strconv.Itoa(newVersion))
128@@ -237,16 +238,6 @@
129 }
130 }
131
132-// MakeWritable remounts a path with read and write permissions.
133-func MakeWritable(c *check.C, path string) {
134- cli.ExecCommand(c, "sudo", "mount", "-o", "remount,rw", path)
135-}
136-
137-// MakeReadonly remounts a path with only read permissions.
138-func MakeReadonly(c *check.C, path string) {
139- cli.ExecCommand(c, "sudo", "mount", "-o", "remount,ro", path)
140-}
141-
142 // Reboot requests a reboot using the test name as the mark.
143 func Reboot(c *check.C) {
144 RebootWithMark(c, c.TestName())
145
146=== added file '_integration-tests/testutils/partition/partition.go'
147--- _integration-tests/testutils/partition/partition.go 1970-01-01 00:00:00 +0000
148+++ _integration-tests/testutils/partition/partition.go 2015-10-02 10:28:33 +0000
149@@ -0,0 +1,38 @@
150+// -*- Mode: Go; indent-tabs-mode: t -*-
151+
152+/*
153+ * Copyright (C) 2015 Canonical Ltd
154+ *
155+ * This program is free software: you can redistribute it and/or modify
156+ * it under the terms of the GNU General Public License version 3 as
157+ * published by the Free Software Foundation.
158+ *
159+ * This program is distributed in the hope that it will be useful,
160+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
161+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
162+ * GNU General Public License for more details.
163+ *
164+ * You should have received a copy of the GNU General Public License
165+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
166+ *
167+ */
168+
169+package partition
170+
171+import (
172+ "gopkg.in/check.v1"
173+
174+ "launchpad.net/snappy/_integration-tests/testutils/cli"
175+)
176+
177+var execCommand = cli.ExecCommand
178+
179+// MakeWritable remounts a path with read and write permissions.
180+func MakeWritable(c *check.C, path string) {
181+ execCommand(c, "sudo", "mount", "-o", "remount,rw", path)
182+}
183+
184+// MakeReadonly remounts a path with only read permissions.
185+func MakeReadonly(c *check.C, path string) {
186+ execCommand(c, "sudo", "mount", "-o", "remount,ro", path)
187+}
188
189=== added file '_integration-tests/testutils/partition/partition_test.go'
190--- _integration-tests/testutils/partition/partition_test.go 1970-01-01 00:00:00 +0000
191+++ _integration-tests/testutils/partition/partition_test.go 2015-10-02 10:28:33 +0000
192@@ -0,0 +1,69 @@
193+// -*- Mode: Go; indent-tabs-mode: t -*-
194+
195+/*
196+ * Copyright (C) 2014-2015 Canonical Ltd
197+ *
198+ * This program is free software: you can redistribute it and/or modify
199+ * it under the terms of the GNU General Public License version 3 as
200+ * published by the Free Software Foundation.
201+ *
202+ * This program is distributed in the hope that it will be useful,
203+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
204+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
205+ * GNU General Public License for more details.
206+ *
207+ * You should have received a copy of the GNU General Public License
208+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
209+ *
210+ */
211+
212+package partition
213+
214+import (
215+ "strings"
216+
217+ "gopkg.in/check.v1"
218+)
219+
220+const path = "mypath"
221+
222+type partitionTestSuite struct {
223+ execCalls map[string]int
224+ backExecCommand func(*check.C, ...string) string
225+}
226+
227+var _ = check.Suite(&partitionTestSuite{})
228+
229+func (s *partitionTestSuite) SetUpSuite(c *check.C) {
230+ s.backExecCommand = execCommand
231+ execCommand = s.fakeExecCommand
232+}
233+
234+func (s *partitionTestSuite) TearDownSuite(c *check.C) {
235+ execCommand = s.backExecCommand
236+}
237+
238+func (s *partitionTestSuite) SetUpTest(c *check.C) {
239+ s.execCalls = make(map[string]int)
240+}
241+
242+func (s *partitionTestSuite) fakeExecCommand(c *check.C, args ...string) (output string) {
243+ s.execCalls[strings.Join(args, " ")]++
244+ return
245+}
246+
247+func (s *partitionTestSuite) TestMakeWritable(c *check.C) {
248+ cmd := "sudo mount -o remount,rw " + path
249+
250+ MakeWritable(c, path)
251+
252+ c.Assert(s.execCalls[cmd], check.Equals, 1)
253+}
254+
255+func (s *partitionTestSuite) TestMakeReadOnly(c *check.C) {
256+ cmd := "sudo mount -o remount,ro " + path
257+
258+ MakeReadonly(c, path)
259+
260+ c.Assert(s.execCalls[cmd], check.Equals, 1)
261+}

Subscribers

People subscribed via source and target branches