~fgimenez/+junk/always-wait-for-boot-ok

« back to all changes in this revision

Viewing changes to _integration-tests/tests/failover_systemd_loop_test.go

  • Committer: Snappy Tarmac
  • Author(s): Federico Gimenez
  • Date: 2015-10-02 10:43:13 UTC
  • mfrom: (715.2.7 cli-pkg)
  • Revision ID: snappy_tarmac-20151002104313-q7tm0j97kx89ng01
cli package with ExecCommand functions by fgimenez approved by fgimenez

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import (
23
23
        "fmt"
24
24
 
25
 
        . "launchpad.net/snappy/_integration-tests/testutils/common"
 
25
        "launchpad.net/snappy/_integration-tests/testutils/cli"
 
26
        "launchpad.net/snappy/_integration-tests/testutils/common"
26
27
 
27
 
        check "gopkg.in/check.v1"
 
28
        "gopkg.in/check.v1"
28
29
)
29
30
 
30
31
const (
61
62
type systemdDependencyLoop struct{}
62
63
 
63
64
func (systemdDependencyLoop) set(c *check.C) {
64
 
        installService(c, "deadlock", deadlockService, BaseAltPartitionPath)
65
 
        installService(c, "emerg-reboot", rebootService, BaseAltPartitionPath)
 
65
        installService(c, "deadlock", deadlockService, common.BaseAltPartitionPath)
 
66
        installService(c, "emerg-reboot", rebootService, common.BaseAltPartitionPath)
66
67
}
67
68
 
68
69
func (systemdDependencyLoop) unset(c *check.C) {
69
 
        unInstallService(c, "deadlock", BaseAltPartitionPath)
70
 
        unInstallService(c, "emerg-reboot", BaseAltPartitionPath)
 
70
        unInstallService(c, "deadlock", common.BaseAltPartitionPath)
 
71
        unInstallService(c, "emerg-reboot", common.BaseAltPartitionPath)
71
72
}
72
73
 
73
74
func installService(c *check.C, serviceName, serviceCfg, basePath string) {
74
 
        MakeWritable(c, basePath)
75
 
        defer MakeReadonly(c, basePath)
 
75
        common.MakeWritable(c, basePath)
 
76
        defer common.MakeReadonly(c, basePath)
76
77
 
77
78
        // Create service file
78
79
        serviceFile := fmt.Sprintf("%s%s/%s.service", basePath, baseSystemdPath, serviceName)
79
 
        ExecCommand(c, "sudo", "chmod", "a+w", fmt.Sprintf("%s%s", basePath, baseSystemdPath))
80
 
        ExecCommandToFile(c, serviceFile, "sudo", "echo", serviceCfg)
 
80
        cli.ExecCommand(c, "sudo", "chmod", "a+w", fmt.Sprintf("%s%s", basePath, baseSystemdPath))
 
81
        cli.ExecCommandToFile(c, serviceFile, "sudo", "echo", serviceCfg)
81
82
 
82
83
        // Create requires directory
83
84
        requiresDirPart := fmt.Sprintf("%s/%s", baseSystemdPath, systemdTargetRequiresDir)
84
85
        requiresDir := fmt.Sprintf("%s%s", basePath, requiresDirPart)
85
 
        ExecCommand(c, "sudo", "mkdir", "-p", requiresDir)
 
86
        cli.ExecCommand(c, "sudo", "mkdir", "-p", requiresDir)
86
87
 
87
88
        // Symlink from the requires dir to the service file (with chroot for being
88
89
        // usable in the other partition)
89
 
        ExecCommand(c, "sudo", "chroot", basePath, "ln", "-s",
 
90
        cli.ExecCommand(c, "sudo", "chroot", basePath, "ln", "-s",
90
91
                fmt.Sprintf("%s/%s.service", baseSystemdPath, serviceName),
91
92
                fmt.Sprintf("%s/%s.service", requiresDirPart, serviceName),
92
93
        )
93
94
}
94
95
 
95
96
func unInstallService(c *check.C, serviceName, basePath string) {
96
 
        MakeWritable(c, basePath)
97
 
        defer MakeReadonly(c, basePath)
 
97
        common.MakeWritable(c, basePath)
 
98
        defer common.MakeReadonly(c, basePath)
98
99
 
99
100
        // Disable the service
100
 
        ExecCommand(c, "sudo", "chroot", basePath,
 
101
        cli.ExecCommand(c, "sudo", "chroot", basePath,
101
102
                "systemctl", "disable", fmt.Sprintf("%s.service", serviceName))
102
103
 
103
104
        // Remove the service file
104
 
        ExecCommand(c, "sudo", "rm",
 
105
        cli.ExecCommand(c, "sudo", "rm",
105
106
                fmt.Sprintf("%s%s/%s.service", basePath, baseSystemdPath, serviceName))
106
107
 
107
108
        // Remove the requires symlink
108
 
        ExecCommand(c, "sudo", "rm",
 
109
        cli.ExecCommand(c, "sudo", "rm",
109
110
                fmt.Sprintf("%s%s/%s/%s.service", basePath, baseSystemdPath, systemdTargetRequiresDir, serviceName))
110
111
}
111
112