-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent_test.go
130 lines (114 loc) · 3.22 KB
/
agent_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2015 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package service_test
import (
"path"
"path/filepath"
"runtime"
"strings"
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/juju/juju/osenv"
"github.com/juju/juju/service"
"github.com/juju/juju/service/common"
)
func init() {
quote = "'"
if runtime.GOOS == "windows" {
cmdSuffix = ".exe"
quote = `"`
}
}
var quote, cmdSuffix string
type agentSuite struct {
testing.IsolationSuite
}
var _ = gc.Suite(&agentSuite{})
func (*agentSuite) TestMachineAgentConfLocal(c *gc.C) {
dataDir := c.MkDir()
logDir := c.MkDir()
conf, toolsDir := service.MachineAgentConf("0", dataDir, logDir, "")
c.Check(toolsDir, gc.Equals, filepath.Join(dataDir, "tools", "machine-0"))
cmd := strings.Join([]string{
quote + filepath.Join(toolsDir, "jujud"+cmdSuffix) + quote,
"machine",
"--data-dir", quote + dataDir + quote,
"--machine-id", "0",
"--debug",
}, " ")
c.Check(conf, jc.DeepEquals, common.Conf{
Desc: "juju agent for machine-0",
ExecStart: cmd,
Output: filepath.Join(logDir, "machine-0.log"),
Env: osenv.FeatureFlags(),
Limit: map[string]string{
"nofile": "20000 20000",
},
})
}
func (*agentSuite) TestMachineAgentConfUbuntu(c *gc.C) {
dataDir := "/var/lib/juju"
logDir := "/var/log/juju"
conf, toolsDir := service.MachineAgentConf("0", dataDir, logDir, "ubuntu")
c.Check(toolsDir, gc.Equals, dataDir+"/tools/machine-0")
cmd := strings.Join([]string{
"'" + toolsDir + "/jujud'",
"machine",
"--data-dir", "'" + dataDir + "'",
"--machine-id", "0",
"--debug",
}, " ")
c.Check(conf, jc.DeepEquals, common.Conf{
Desc: "juju agent for machine-0",
ExecStart: cmd,
Output: logDir + "/machine-0.log",
Env: osenv.FeatureFlags(),
Limit: map[string]string{
"nofile": "20000 20000",
},
})
}
func (*agentSuite) TestMachineAgentConfWindows(c *gc.C) {
dataDir := `c:\Juju\lib\juju`
logDir := `c:\Juju\logs\juju`
conf, toolsDir := service.MachineAgentConf("0", dataDir, logDir, "windows")
c.Check(toolsDir, gc.Equals, dataDir+`\tools\machine-0`)
cmd := strings.Join([]string{
`"` + toolsDir + `\jujud.exe"`,
"machine",
"--data-dir", `"` + dataDir + `"`,
"--machine-id", "0",
"--debug",
}, " ")
c.Check(conf, jc.DeepEquals, common.Conf{
Desc: "juju agent for machine-0",
ExecStart: cmd,
Output: logDir + `\machine-0.log`,
Env: osenv.FeatureFlags(),
Limit: map[string]string{
"nofile": "20000 20000",
},
})
}
func (*agentSuite) TestUnitAgentConf(c *gc.C) {
dataDir := c.MkDir()
logDir := c.MkDir()
conf, toolsDir := service.UnitAgentConf("wordpress/0", dataDir, logDir, "", "cont")
c.Check(toolsDir, gc.Equals, path.Join(dataDir, "tools", "unit-wordpress-0"))
cmd := strings.Join([]string{
filepath.Join(toolsDir, "jujud"+cmdSuffix),
"unit",
"--data-dir", "'" + dataDir + "'",
"--unit-name", "wordpress/0",
"--debug",
}, " ")
env := osenv.FeatureFlags()
env[osenv.JujuContainerTypeEnvKey] = "cont"
c.Check(conf, jc.DeepEquals, common.Conf{
Desc: "juju unit agent for wordpress/0",
ExecStart: cmd,
Output: filepath.Join(logDir, "unit-wordpress-0.log"),
Env: env,
})
}