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
=== modified file '_integration-tests/tests/failover_rclocal_crash_test.go'
--- _integration-tests/tests/failover_rclocal_crash_test.go 2015-10-02 10:28:33 +0000
+++ _integration-tests/tests/failover_rclocal_crash_test.go 2015-10-02 10:28:33 +0000
@@ -24,6 +24,7 @@
2424
25 "launchpad.net/snappy/_integration-tests/testutils/cli"25 "launchpad.net/snappy/_integration-tests/testutils/cli"
26 "launchpad.net/snappy/_integration-tests/testutils/common"26 "launchpad.net/snappy/_integration-tests/testutils/common"
27 "launchpad.net/snappy/_integration-tests/testutils/partition"
2728
28 "gopkg.in/check.v1"29 "gopkg.in/check.v1"
29)30)
@@ -31,8 +32,8 @@
31type rcLocalCrash struct{}32type rcLocalCrash struct{}
3233
33func (rcLocalCrash) set(c *check.C) {34func (rcLocalCrash) set(c *check.C) {
34 common.MakeWritable(c, common.BaseAltPartitionPath)35 partition.MakeWritable(c, common.BaseAltPartitionPath)
35 defer common.MakeReadonly(c, common.BaseAltPartitionPath)36 defer partition.MakeReadonly(c, common.BaseAltPartitionPath)
36 targetFile := fmt.Sprintf("%s/etc/rc.local", common.BaseAltPartitionPath)37 targetFile := fmt.Sprintf("%s/etc/rc.local", common.BaseAltPartitionPath)
37 cli.ExecCommand(c, "sudo", "chmod", "a+xw", targetFile)38 cli.ExecCommand(c, "sudo", "chmod", "a+xw", targetFile)
3839
@@ -41,8 +42,8 @@
41}42}
4243
43func (rcLocalCrash) unset(c *check.C) {44func (rcLocalCrash) unset(c *check.C) {
44 common.MakeWritable(c, common.BaseAltPartitionPath)45 partition.MakeWritable(c, common.BaseAltPartitionPath)
45 defer common.MakeReadonly(c, common.BaseAltPartitionPath)46 defer partition.MakeReadonly(c, common.BaseAltPartitionPath)
46 cli.ExecCommand(c, "sudo", "rm", fmt.Sprintf("%s/etc/rc.local", common.BaseAltPartitionPath))47 cli.ExecCommand(c, "sudo", "rm", fmt.Sprintf("%s/etc/rc.local", common.BaseAltPartitionPath))
47}48}
4849
4950
=== modified file '_integration-tests/tests/failover_systemd_loop_test.go'
--- _integration-tests/tests/failover_systemd_loop_test.go 2015-10-02 10:28:33 +0000
+++ _integration-tests/tests/failover_systemd_loop_test.go 2015-10-02 10:28:33 +0000
@@ -24,6 +24,7 @@
2424
25 "launchpad.net/snappy/_integration-tests/testutils/cli"25 "launchpad.net/snappy/_integration-tests/testutils/cli"
26 "launchpad.net/snappy/_integration-tests/testutils/common"26 "launchpad.net/snappy/_integration-tests/testutils/common"
27 "launchpad.net/snappy/_integration-tests/testutils/partition"
2728
28 "gopkg.in/check.v1"29 "gopkg.in/check.v1"
29)30)
@@ -72,8 +73,8 @@
72}73}
7374
74func installService(c *check.C, serviceName, serviceCfg, basePath string) {75func installService(c *check.C, serviceName, serviceCfg, basePath string) {
75 common.MakeWritable(c, basePath)76 partition.MakeWritable(c, basePath)
76 defer common.MakeReadonly(c, basePath)77 defer partition.MakeReadonly(c, basePath)
7778
78 // Create service file79 // Create service file
79 serviceFile := fmt.Sprintf("%s%s/%s.service", basePath, baseSystemdPath, serviceName)80 serviceFile := fmt.Sprintf("%s%s/%s.service", basePath, baseSystemdPath, serviceName)
@@ -94,8 +95,8 @@
94}95}
9596
96func unInstallService(c *check.C, serviceName, basePath string) {97func unInstallService(c *check.C, serviceName, basePath string) {
97 common.MakeWritable(c, basePath)98 partition.MakeWritable(c, basePath)
98 defer common.MakeReadonly(c, basePath)99 defer partition.MakeReadonly(c, basePath)
99100
100 // Disable the service101 // Disable the service
101 cli.ExecCommand(c, "sudo", "chroot", basePath,102 cli.ExecCommand(c, "sudo", "chroot", basePath,
102103
=== modified file '_integration-tests/tests/failover_zero_size_file_test.go'
--- _integration-tests/tests/failover_zero_size_file_test.go 2015-10-02 10:28:33 +0000
+++ _integration-tests/tests/failover_zero_size_file_test.go 2015-10-02 10:28:33 +0000
@@ -107,8 +107,8 @@
107 // Only need to make writable and revert for BaseAltPartitionPath,107 // Only need to make writable and revert for BaseAltPartitionPath,
108 // kernel files' boot directory is writable108 // kernel files' boot directory is writable
109 if basePath == common.BaseAltPartitionPath {109 if basePath == common.BaseAltPartitionPath {
110 common.MakeWritable(c, basePath)110 partition.MakeWritable(c, basePath)
111 defer common.MakeReadonly(c, basePath)111 defer partition.MakeReadonly(c, basePath)
112 }112 }
113113
114 cli.ExecCommand(c, "sudo", "mv", oldFilename, newFilename)114 cli.ExecCommand(c, "sudo", "mv", oldFilename, newFilename)
115115
=== modified file '_integration-tests/testutils/common/common.go'
--- _integration-tests/testutils/common/common.go 2015-10-02 10:28:33 +0000
+++ _integration-tests/testutils/common/common.go 2015-10-02 10:28:33 +0000
@@ -32,6 +32,7 @@
3232
33 "launchpad.net/snappy/_integration-tests/testutils/cli"33 "launchpad.net/snappy/_integration-tests/testutils/cli"
34 "launchpad.net/snappy/_integration-tests/testutils/config"34 "launchpad.net/snappy/_integration-tests/testutils/config"
35 "launchpad.net/snappy/_integration-tests/testutils/partition"
35)36)
3637
37const (38const (
@@ -127,8 +128,8 @@
127 m[channelCfgOtherBackupFile()] = BaseAltPartitionPath128 m[channelCfgOtherBackupFile()] = BaseAltPartitionPath
128 for backup, target := range m {129 for backup, target := range m {
129 if _, err := os.Stat(backup); err == nil {130 if _, err := os.Stat(backup); err == nil {
130 MakeWritable(c, target)131 partition.MakeWritable(c, target)
131 defer MakeReadonly(c, target)132 defer partition.MakeReadonly(c, target)
132 original := filepath.Join(target, channelCfgFile)133 original := filepath.Join(target, channelCfgFile)
133 c.Logf("Restoring %s...", original)134 c.Logf("Restoring %s...", original)
134 cli.ExecCommand(c, "sudo", "mv", backup, original)135 cli.ExecCommand(c, "sudo", "mv", backup, original)
@@ -153,8 +154,8 @@
153 for _, target := range targets {154 for _, target := range targets {
154 file := filepath.Join(target, channelCfgFile)155 file := filepath.Join(target, channelCfgFile)
155 if _, err := os.Stat(file); err == nil {156 if _, err := os.Stat(file); err == nil {
156 MakeWritable(c, target)157 partition.MakeWritable(c, target)
157 defer MakeReadonly(c, target)158 defer partition.MakeReadonly(c, target)
158 replaceSystemImageValues(c, file, release, channel, version)159 replaceSystemImageValues(c, file, release, channel, version)
159 }160 }
160 }161 }
@@ -228,8 +229,8 @@
228 for target, backup := range m {229 for target, backup := range m {
229 file := filepath.Join(target, channelCfgFile)230 file := filepath.Join(target, channelCfgFile)
230 if _, err := os.Stat(file); err == nil {231 if _, err := os.Stat(file); err == nil {
231 MakeWritable(c, target)232 partition.MakeWritable(c, target)
232 defer MakeReadonly(c, target)233 defer partition.MakeReadonly(c, target)
233 // Back up the file. It will be restored during the test tear down.234 // Back up the file. It will be restored during the test tear down.
234 cli.ExecCommand(c, "cp", file, backup)235 cli.ExecCommand(c, "cp", file, backup)
235 replaceSystemImageValues(c, file, "", "", strconv.Itoa(newVersion))236 replaceSystemImageValues(c, file, "", "", strconv.Itoa(newVersion))
@@ -237,16 +238,6 @@
237 }238 }
238}239}
239240
240// MakeWritable remounts a path with read and write permissions.
241func MakeWritable(c *check.C, path string) {
242 cli.ExecCommand(c, "sudo", "mount", "-o", "remount,rw", path)
243}
244
245// MakeReadonly remounts a path with only read permissions.
246func MakeReadonly(c *check.C, path string) {
247 cli.ExecCommand(c, "sudo", "mount", "-o", "remount,ro", path)
248}
249
250// Reboot requests a reboot using the test name as the mark.241// Reboot requests a reboot using the test name as the mark.
251func Reboot(c *check.C) {242func Reboot(c *check.C) {
252 RebootWithMark(c, c.TestName())243 RebootWithMark(c, c.TestName())
253244
=== added file '_integration-tests/testutils/partition/partition.go'
--- _integration-tests/testutils/partition/partition.go 1970-01-01 00:00:00 +0000
+++ _integration-tests/testutils/partition/partition.go 2015-10-02 10:28:33 +0000
@@ -0,0 +1,38 @@
1// -*- Mode: Go; indent-tabs-mode: t -*-
2
3/*
4 * Copyright (C) 2015 Canonical Ltd
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20package partition
21
22import (
23 "gopkg.in/check.v1"
24
25 "launchpad.net/snappy/_integration-tests/testutils/cli"
26)
27
28var execCommand = cli.ExecCommand
29
30// MakeWritable remounts a path with read and write permissions.
31func MakeWritable(c *check.C, path string) {
32 execCommand(c, "sudo", "mount", "-o", "remount,rw", path)
33}
34
35// MakeReadonly remounts a path with only read permissions.
36func MakeReadonly(c *check.C, path string) {
37 execCommand(c, "sudo", "mount", "-o", "remount,ro", path)
38}
039
=== added file '_integration-tests/testutils/partition/partition_test.go'
--- _integration-tests/testutils/partition/partition_test.go 1970-01-01 00:00:00 +0000
+++ _integration-tests/testutils/partition/partition_test.go 2015-10-02 10:28:33 +0000
@@ -0,0 +1,69 @@
1// -*- Mode: Go; indent-tabs-mode: t -*-
2
3/*
4 * Copyright (C) 2014-2015 Canonical Ltd
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20package partition
21
22import (
23 "strings"
24
25 "gopkg.in/check.v1"
26)
27
28const path = "mypath"
29
30type partitionTestSuite struct {
31 execCalls map[string]int
32 backExecCommand func(*check.C, ...string) string
33}
34
35var _ = check.Suite(&partitionTestSuite{})
36
37func (s *partitionTestSuite) SetUpSuite(c *check.C) {
38 s.backExecCommand = execCommand
39 execCommand = s.fakeExecCommand
40}
41
42func (s *partitionTestSuite) TearDownSuite(c *check.C) {
43 execCommand = s.backExecCommand
44}
45
46func (s *partitionTestSuite) SetUpTest(c *check.C) {
47 s.execCalls = make(map[string]int)
48}
49
50func (s *partitionTestSuite) fakeExecCommand(c *check.C, args ...string) (output string) {
51 s.execCalls[strings.Join(args, " ")]++
52 return
53}
54
55func (s *partitionTestSuite) TestMakeWritable(c *check.C) {
56 cmd := "sudo mount -o remount,rw " + path
57
58 MakeWritable(c, path)
59
60 c.Assert(s.execCalls[cmd], check.Equals, 1)
61}
62
63func (s *partitionTestSuite) TestMakeReadOnly(c *check.C) {
64 cmd := "sudo mount -o remount,ro " + path
65
66 MakeReadonly(c, path)
67
68 c.Assert(s.execCalls[cmd], check.Equals, 1)
69}

Subscribers

People subscribed via source and target branches