Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(151)

Side by Side Diff: worker/deployer/simple_test.go

Issue 66540044: Added LogDir to agent conf, upgrade steps (Closed)
Patch Set: Added LogDir to agent conf, upgrade steps Created 11 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« upgrades/rsyslogconf.go ('K') | « worker/deployer/simple.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012, 2013 Canonical Ltd. 1 // Copyright 2012, 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package deployer_test 4 package deployer_test
5 5
6 import ( 6 import (
7 "encoding/json" 7 "encoding/json"
8 "fmt" 8 "fmt"
9 "io/ioutil" 9 "io/ioutil"
10 "os" 10 "os"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 // Verify they're no longer discoverable. 128 // Verify they're no longer discoverable.
129 units, err = manager.DeployedUnits() 129 units, err = manager.DeployedUnits()
130 c.Assert(err, gc.IsNil) 130 c.Assert(err, gc.IsNil)
131 c.Assert(units, gc.HasLen, 0) 131 c.Assert(units, gc.HasLen, 0)
132 } 132 }
133 133
134 type SimpleToolsFixture struct { 134 type SimpleToolsFixture struct {
135 testbase.LoggingSuite 135 testbase.LoggingSuite
136 dataDir string 136 dataDir string
137 initDir string 137 initDir string
138 logDir string
139 origPath string 138 origPath string
140 binDir string 139 binDir string
141 syslogConfigDir string 140 syslogConfigDir string
142 } 141 }
143 142
144 var fakeJujud = "#!/bin/bash --norc\n# fake-jujud\nexit 0\n" 143 var fakeJujud = "#!/bin/bash --norc\n# fake-jujud\nexit 0\n"
145 144
146 func (fix *SimpleToolsFixture) SetUp(c *gc.C, dataDir string) { 145 func (fix *SimpleToolsFixture) SetUp(c *gc.C, dataDir string) {
147 fix.LoggingSuite.SetUpTest(c) 146 fix.LoggingSuite.SetUpTest(c)
148 fix.dataDir = dataDir 147 fix.dataDir = dataDir
149 fix.initDir = c.MkDir() 148 fix.initDir = c.MkDir()
150 fix.logDir = c.MkDir()
151 fix.syslogConfigDir = c.MkDir() 149 fix.syslogConfigDir = c.MkDir()
152 toolsDir := tools.SharedToolsDir(fix.dataDir, version.Current) 150 toolsDir := tools.SharedToolsDir(fix.dataDir, version.Current)
153 err := os.MkdirAll(toolsDir, 0755) 151 err := os.MkdirAll(toolsDir, 0755)
154 c.Assert(err, gc.IsNil) 152 c.Assert(err, gc.IsNil)
155 jujudPath := filepath.Join(toolsDir, "jujud") 153 jujudPath := filepath.Join(toolsDir, "jujud")
156 err = ioutil.WriteFile(jujudPath, []byte(fakeJujud), 0755) 154 err = ioutil.WriteFile(jujudPath, []byte(fakeJujud), 0755)
157 c.Assert(err, gc.IsNil) 155 c.Assert(err, gc.IsNil)
158 toolsPath := filepath.Join(toolsDir, "downloaded-tools.txt") 156 toolsPath := filepath.Join(toolsDir, "downloaded-tools.txt")
159 testTools := coretools.Tools{Version: version.Current, URL: "http://test ing.invalid/tools"} 157 testTools := coretools.Tools{Version: version.Current, URL: "http://test ing.invalid/tools"}
160 data, err := json.Marshal(testTools) 158 data, err := json.Marshal(testTools)
(...skipping 21 matching lines...) Expand all
182 c.Assert(err, gc.IsNil) 180 c.Assert(err, gc.IsNil)
183 } 181 }
184 182
185 func (fix *SimpleToolsFixture) assertUpstartCount(c *gc.C, count int) { 183 func (fix *SimpleToolsFixture) assertUpstartCount(c *gc.C, count int) {
186 fis, err := ioutil.ReadDir(fix.initDir) 184 fis, err := ioutil.ReadDir(fix.initDir)
187 c.Assert(err, gc.IsNil) 185 c.Assert(err, gc.IsNil)
188 c.Assert(fis, gc.HasLen, count) 186 c.Assert(fis, gc.HasLen, count)
189 } 187 }
190 188
191 func (fix *SimpleToolsFixture) getContext(c *gc.C) *deployer.SimpleContext { 189 func (fix *SimpleToolsFixture) getContext(c *gc.C) *deployer.SimpleContext {
192 » config := agentConfig("machine-tag", fix.dataDir) 190 » config := agentConfig("machine-tag", fix.dataDir, agent.DefaultLogDir)
193 » return deployer.NewTestSimpleContext(config, fix.initDir, fix.logDir, fi x.syslogConfigDir) 191 » return deployer.NewTestSimpleContext(config, fix.initDir, fix.syslogConf igDir)
194 } 192 }
195 193
196 func (fix *SimpleToolsFixture) getContextForMachine(c *gc.C, machineTag string) *deployer.SimpleContext { 194 func (fix *SimpleToolsFixture) getContextForMachine(c *gc.C, machineTag string) *deployer.SimpleContext {
197 » config := agentConfig(machineTag, fix.dataDir) 195 » config := agentConfig(machineTag, fix.dataDir, agent.DefaultLogDir)
198 » return deployer.NewTestSimpleContext(config, fix.initDir, fix.logDir, fi x.syslogConfigDir) 196 » return deployer.NewTestSimpleContext(config, fix.initDir, fix.syslogConf igDir)
199 } 197 }
200 198
201 func (fix *SimpleToolsFixture) paths(tag string) (confPath, agentDir, toolsDir, syslogConfPath string) { 199 func (fix *SimpleToolsFixture) paths(tag string) (confPath, agentDir, toolsDir, syslogConfPath string) {
202 confName := fmt.Sprintf("jujud-%s.conf", tag) 200 confName := fmt.Sprintf("jujud-%s.conf", tag)
203 confPath = filepath.Join(fix.initDir, confName) 201 confPath = filepath.Join(fix.initDir, confName)
204 agentDir = agent.Dir(fix.dataDir, tag) 202 agentDir = agent.Dir(fix.dataDir, tag)
205 toolsDir = tools.ToolsDir(fix.dataDir, tag) 203 toolsDir = tools.ToolsDir(fix.dataDir, tag)
206 syslogConfPath = filepath.Join(fix.syslogConfigDir, fmt.Sprintf("26-juju -%s.conf", tag)) 204 syslogConfPath = filepath.Join(fix.syslogConfigDir, fmt.Sprintf("26-juju -%s.conf", tag))
207 return 205 return
208 } 206 }
209 207
210 var expectedSyslogConf = ` 208 var expectedSyslogConf = `
211 $ModLoad imfile 209 $ModLoad imfile
212 210
213 $InputFilePersistStateInterval 50 211 $InputFilePersistStateInterval 50
214 $InputFilePollInterval 5 212 $InputFilePollInterval 5
215 $InputFileName /var/log/juju/%s.log 213 $InputFileName %s/%s.log
216 $InputFileTag juju-%s: 214 $InputFileTag juju-%s:
217 $InputFileStateFile %s 215 $InputFileStateFile %s
218 $InputRunFileMonitor 216 $InputRunFileMonitor
219 217
220 $template LongTagForwardFormat,"<%%PRI%%>%%TIMESTAMP:::date-rfc3339%% %%HOSTNAME %% %%syslogtag%%%%msg:::sp-if-no-1st-sp%%%%msg%%" 218 $template LongTagForwardFormat,"<%%PRI%%>%%TIMESTAMP:::date-rfc3339%% %%HOSTNAME %% %%syslogtag%%%%msg:::sp-if-no-1st-sp%%%%msg%%"
221 219
222 :syslogtag, startswith, "juju-" @s1:2345;LongTagForwardFormat 220 :syslogtag, startswith, "juju-" @s1:2345;LongTagForwardFormat
223 & ~ 221 & ~
224 ` 222 `
225 223
226 func (fix *SimpleToolsFixture) checkUnitInstalled(c *gc.C, name, password string ) { 224 func (fix *SimpleToolsFixture) checkUnitInstalled(c *gc.C, name, password string ) {
227 tag := names.UnitTag(name) 225 tag := names.UnitTag(name)
228 uconfPath, _, toolsDir, syslogConfPath := fix.paths(tag) 226 uconfPath, _, toolsDir, syslogConfPath := fix.paths(tag)
229 uconfData, err := ioutil.ReadFile(uconfPath) 227 uconfData, err := ioutil.ReadFile(uconfPath)
230 c.Assert(err, gc.IsNil) 228 c.Assert(err, gc.IsNil)
231 uconf := string(uconfData) 229 uconf := string(uconfData)
232 var execLine string 230 var execLine string
233 for _, line := range strings.Split(uconf, "\n") { 231 for _, line := range strings.Split(uconf, "\n") {
234 if strings.HasPrefix(line, "exec ") { 232 if strings.HasPrefix(line, "exec ") {
235 execLine = line 233 execLine = line
236 break 234 break
237 } 235 }
238 } 236 }
239 if execLine == "" { 237 if execLine == "" {
240 c.Fatalf("no command found in %s:\n%s", uconfPath, uconf) 238 c.Fatalf("no command found in %s:\n%s", uconfPath, uconf)
241 } 239 }
242 » logPath := filepath.Join(fix.logDir, tag+".log") 240 » logPath := filepath.Join(agent.DefaultLogDir, tag+".log")
243 jujudPath := filepath.Join(toolsDir, "jujud") 241 jujudPath := filepath.Join(toolsDir, "jujud")
244 for _, pat := range []string{ 242 for _, pat := range []string{
245 "^exec " + jujudPath + " unit ", 243 "^exec " + jujudPath + " unit ",
246 " --unit-name " + name + " ", 244 " --unit-name " + name + " ",
247 " >> " + logPath + " 2>&1$", 245 " >> " + logPath + " 2>&1$",
248 } { 246 } {
249 match, err := regexp.MatchString(pat, execLine) 247 match, err := regexp.MatchString(pat, execLine)
250 c.Assert(err, gc.IsNil) 248 c.Assert(err, gc.IsNil)
251 if !match { 249 if !match {
252 c.Fatalf("failed to match:\n%s\nin:\n%s", pat, execLine) 250 c.Fatalf("failed to match:\n%s\nin:\n%s", pat, execLine)
253 } 251 }
254 } 252 }
255 253
256 conf, err := agent.ReadConf(fix.dataDir, tag) 254 conf, err := agent.ReadConf(fix.dataDir, tag)
257 c.Assert(err, gc.IsNil) 255 c.Assert(err, gc.IsNil)
258 c.Assert(conf.Tag(), gc.Equals, tag) 256 c.Assert(conf.Tag(), gc.Equals, tag)
259 c.Assert(conf.DataDir(), gc.Equals, fix.dataDir) 257 c.Assert(conf.DataDir(), gc.Equals, fix.dataDir)
260 258
261 jujudData, err := ioutil.ReadFile(jujudPath) 259 jujudData, err := ioutil.ReadFile(jujudPath)
262 c.Assert(err, gc.IsNil) 260 c.Assert(err, gc.IsNil)
263 c.Assert(string(jujudData), gc.Equals, fakeJujud) 261 c.Assert(string(jujudData), gc.Equals, fakeJujud)
264 262
265 syslogConfData, err := ioutil.ReadFile(syslogConfPath) 263 syslogConfData, err := ioutil.ReadFile(syslogConfPath)
266 c.Assert(err, gc.IsNil) 264 c.Assert(err, gc.IsNil)
267 parts := strings.SplitN(name, "/", 2) 265 parts := strings.SplitN(name, "/", 2)
268 unitTag := fmt.Sprintf("unit-%s-%s", parts[0], parts[1]) 266 unitTag := fmt.Sprintf("unit-%s-%s", parts[0], parts[1])
269 » expectedSyslogConfReplaced := fmt.Sprintf(expectedSyslogConf, unitTag, u nitTag, unitTag) 267 » expectedSyslogConfReplaced := fmt.Sprintf(expectedSyslogConf, agent.Defa ultLogDir, unitTag, unitTag, unitTag)
270 c.Assert(string(syslogConfData), gc.Equals, expectedSyslogConfReplaced) 268 c.Assert(string(syslogConfData), gc.Equals, expectedSyslogConfReplaced)
271 269
272 } 270 }
273 271
274 func (fix *SimpleToolsFixture) checkUnitRemoved(c *gc.C, name string) { 272 func (fix *SimpleToolsFixture) checkUnitRemoved(c *gc.C, name string) {
275 tag := names.UnitTag(name) 273 tag := names.UnitTag(name)
276 confPath, agentDir, toolsDir, syslogConfPath := fix.paths(tag) 274 confPath, agentDir, toolsDir, syslogConfPath := fix.paths(tag)
277 for _, path := range []string{confPath, agentDir, toolsDir, syslogConfPa th} { 275 for _, path := range []string{confPath, agentDir, toolsDir, syslogConfPa th} {
278 _, err := ioutil.ReadFile(path) 276 _, err := ioutil.ReadFile(path)
279 if err == nil { 277 if err == nil {
(...skipping 10 matching lines...) Expand all
290 c.Assert(err, gc.IsNil) 288 c.Assert(err, gc.IsNil)
291 toolsDir := filepath.Join(fix.dataDir, "tools", unitTag) 289 toolsDir := filepath.Join(fix.dataDir, "tools", unitTag)
292 err = os.MkdirAll(toolsDir, 0755) 290 err = os.MkdirAll(toolsDir, 0755)
293 c.Assert(err, gc.IsNil) 291 c.Assert(err, gc.IsNil)
294 } 292 }
295 293
296 type mockConfig struct { 294 type mockConfig struct {
297 agent.Config 295 agent.Config
298 tag string 296 tag string
299 datadir string 297 datadir string
298 logDir string
300 } 299 }
301 300
302 func (mock *mockConfig) Tag() string { 301 func (mock *mockConfig) Tag() string {
303 return mock.tag 302 return mock.tag
304 } 303 }
305 304
306 func (mock *mockConfig) DataDir() string { 305 func (mock *mockConfig) DataDir() string {
307 return mock.datadir 306 return mock.datadir
308 } 307 }
309 308
309 func (mock *mockConfig) LogDir() string {
310 return mock.logDir
311 }
312
310 func (mock *mockConfig) CACert() []byte { 313 func (mock *mockConfig) CACert() []byte {
311 return []byte(testing.CACert) 314 return []byte(testing.CACert)
312 } 315 }
313 316
314 func (mock *mockConfig) Value(_ string) string { 317 func (mock *mockConfig) Value(_ string) string {
315 return "" 318 return ""
316 } 319 }
317 320
318 func agentConfig(tag, datadir string) agent.Config { 321 func agentConfig(tag, datadir, logDir string) agent.Config {
319 » return &mockConfig{tag: tag, datadir: datadir} 322 » return &mockConfig{tag: tag, datadir: datadir, logDir: logDir}
320 } 323 }
OLDNEW
« upgrades/rsyslogconf.go ('K') | « worker/deployer/simple.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b