OLD | NEW |
1 package uniter_test | 1 package uniter_test |
2 | 2 |
3 import ( | 3 import ( |
4 "bytes" | 4 "bytes" |
5 "crypto/sha256" | 5 "crypto/sha256" |
6 "encoding/hex" | 6 "encoding/hex" |
7 "fmt" | 7 "fmt" |
8 "io" | 8 "io" |
9 "io/ioutil" | 9 "io/ioutil" |
10 . "launchpad.net/gocheck" | 10 . "launchpad.net/gocheck" |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 } | 249 } |
250 | 250 |
251 var installHookTests = []uniterTest{ | 251 var installHookTests = []uniterTest{ |
252 ut( | 252 ut( |
253 "install hook fail and resolve", | 253 "install hook fail and resolve", |
254 startupError{"install"}, | 254 startupError{"install"}, |
255 verifyWaiting{}, | 255 verifyWaiting{}, |
256 | 256 |
257 resolveError{state.ResolvedNoHooks}, | 257 resolveError{state.ResolvedNoHooks}, |
258 waitUnit{ | 258 waitUnit{ |
259 » » » status: params.UnitStarted, | 259 » » » status: params.StatusStarted, |
260 }, | 260 }, |
261 waitHooks{"config-changed", "start"}, | 261 waitHooks{"config-changed", "start"}, |
262 ), ut( | 262 ), ut( |
263 "install hook fail and retry", | 263 "install hook fail and retry", |
264 startupError{"install"}, | 264 startupError{"install"}, |
265 verifyWaiting{}, | 265 verifyWaiting{}, |
266 | 266 |
267 resolveError{state.ResolvedRetryHooks}, | 267 resolveError{state.ResolvedRetryHooks}, |
268 waitUnit{ | 268 waitUnit{ |
269 » » » status: params.UnitError, | 269 » » » status: params.StatusError, |
270 info: `hook failed: "install"`, | 270 info: `hook failed: "install"`, |
271 }, | 271 }, |
272 waitHooks{"fail-install"}, | 272 waitHooks{"fail-install"}, |
273 fixHook{"install"}, | 273 fixHook{"install"}, |
274 verifyWaiting{}, | 274 verifyWaiting{}, |
275 | 275 |
276 resolveError{state.ResolvedRetryHooks}, | 276 resolveError{state.ResolvedRetryHooks}, |
277 waitUnit{ | 277 waitUnit{ |
278 » » » status: params.UnitStarted, | 278 » » » status: params.StatusStarted, |
279 }, | 279 }, |
280 waitHooks{"install", "config-changed", "start"}, | 280 waitHooks{"install", "config-changed", "start"}, |
281 ), | 281 ), |
282 } | 282 } |
283 | 283 |
284 func (s *UniterSuite) TestUniterInstallHook(c *C) { | 284 func (s *UniterSuite) TestUniterInstallHook(c *C) { |
285 s.runUniterTests(c, installHookTests) | 285 s.runUniterTests(c, installHookTests) |
286 } | 286 } |
287 | 287 |
288 var startHookTests = []uniterTest{ | 288 var startHookTests = []uniterTest{ |
289 ut( | 289 ut( |
290 "start hook fail and resolve", | 290 "start hook fail and resolve", |
291 startupError{"start"}, | 291 startupError{"start"}, |
292 verifyWaiting{}, | 292 verifyWaiting{}, |
293 | 293 |
294 resolveError{state.ResolvedNoHooks}, | 294 resolveError{state.ResolvedNoHooks}, |
295 waitUnit{ | 295 waitUnit{ |
296 » » » status: params.UnitStarted, | 296 » » » status: params.StatusStarted, |
297 }, | 297 }, |
298 waitHooks{"config-changed"}, | 298 waitHooks{"config-changed"}, |
299 verifyRunning{}, | 299 verifyRunning{}, |
300 ), ut( | 300 ), ut( |
301 "start hook fail and retry", | 301 "start hook fail and retry", |
302 startupError{"start"}, | 302 startupError{"start"}, |
303 verifyWaiting{}, | 303 verifyWaiting{}, |
304 | 304 |
305 resolveError{state.ResolvedRetryHooks}, | 305 resolveError{state.ResolvedRetryHooks}, |
306 waitUnit{ | 306 waitUnit{ |
307 » » » status: params.UnitError, | 307 » » » status: params.StatusError, |
308 info: `hook failed: "start"`, | 308 info: `hook failed: "start"`, |
309 }, | 309 }, |
310 waitHooks{"fail-start"}, | 310 waitHooks{"fail-start"}, |
311 verifyWaiting{}, | 311 verifyWaiting{}, |
312 | 312 |
313 fixHook{"start"}, | 313 fixHook{"start"}, |
314 resolveError{state.ResolvedRetryHooks}, | 314 resolveError{state.ResolvedRetryHooks}, |
315 waitUnit{ | 315 waitUnit{ |
316 » » » status: params.UnitStarted, | 316 » » » status: params.StatusStarted, |
317 }, | 317 }, |
318 waitHooks{"start", "config-changed"}, | 318 waitHooks{"start", "config-changed"}, |
319 verifyRunning{}, | 319 verifyRunning{}, |
320 ), | 320 ), |
321 } | 321 } |
322 | 322 |
323 func (s *UniterSuite) TestUniterStartHook(c *C) { | 323 func (s *UniterSuite) TestUniterStartHook(c *C) { |
324 s.runUniterTests(c, startHookTests) | 324 s.runUniterTests(c, startHookTests) |
325 } | 325 } |
326 | 326 |
327 var configChangedHookTests = []uniterTest{ | 327 var configChangedHookTests = []uniterTest{ |
328 ut( | 328 ut( |
329 "config-changed hook fail and resolve", | 329 "config-changed hook fail and resolve", |
330 startupError{"config-changed"}, | 330 startupError{"config-changed"}, |
331 verifyWaiting{}, | 331 verifyWaiting{}, |
332 | 332 |
333 // Note: we'll run another config-changed as soon as we hit the | 333 // Note: we'll run another config-changed as soon as we hit the |
334 // started state, so the broken hook would actually prevent us | 334 // started state, so the broken hook would actually prevent us |
335 // from advancing at all if we didn't fix it. | 335 // from advancing at all if we didn't fix it. |
336 fixHook{"config-changed"}, | 336 fixHook{"config-changed"}, |
337 resolveError{state.ResolvedNoHooks}, | 337 resolveError{state.ResolvedNoHooks}, |
338 waitUnit{ | 338 waitUnit{ |
339 » » » status: params.UnitStarted, | 339 » » » status: params.StatusStarted, |
340 }, | 340 }, |
341 waitHooks{"start", "config-changed"}, | 341 waitHooks{"start", "config-changed"}, |
342 // If we'd accidentally retried that hook, somehow, we would get | 342 // If we'd accidentally retried that hook, somehow, we would get |
343 // an extra config-changed as we entered started; see that we do
n't. | 343 // an extra config-changed as we entered started; see that we do
n't. |
344 waitHooks{}, | 344 waitHooks{}, |
345 verifyRunning{}, | 345 verifyRunning{}, |
346 ), ut( | 346 ), ut( |
347 "config-changed hook fail and retry", | 347 "config-changed hook fail and retry", |
348 startupError{"config-changed"}, | 348 startupError{"config-changed"}, |
349 verifyWaiting{}, | 349 verifyWaiting{}, |
350 | 350 |
351 resolveError{state.ResolvedRetryHooks}, | 351 resolveError{state.ResolvedRetryHooks}, |
352 waitUnit{ | 352 waitUnit{ |
353 » » » status: params.UnitError, | 353 » » » status: params.StatusError, |
354 info: `hook failed: "config-changed"`, | 354 info: `hook failed: "config-changed"`, |
355 }, | 355 }, |
356 waitHooks{"fail-config-changed"}, | 356 waitHooks{"fail-config-changed"}, |
357 verifyWaiting{}, | 357 verifyWaiting{}, |
358 | 358 |
359 fixHook{"config-changed"}, | 359 fixHook{"config-changed"}, |
360 resolveError{state.ResolvedRetryHooks}, | 360 resolveError{state.ResolvedRetryHooks}, |
361 waitUnit{ | 361 waitUnit{ |
362 » » » status: params.UnitStarted, | 362 » » » status: params.StatusStarted, |
363 }, | 363 }, |
364 waitHooks{"config-changed", "start"}, | 364 waitHooks{"config-changed", "start"}, |
365 verifyRunning{}, | 365 verifyRunning{}, |
366 ), | 366 ), |
367 ut( | 367 ut( |
368 "steady state config change with config-get verification", | 368 "steady state config change with config-get verification", |
369 createCharm{ | 369 createCharm{ |
370 customize: func(c *C, ctx *context, path string) { | 370 customize: func(c *C, ctx *context, path string) { |
371 appendHook(c, path, "config-changed", "config-ge
t --format yaml --output config.out") | 371 appendHook(c, path, "config-changed", "config-ge
t --format yaml --output config.out") |
372 }, | 372 }, |
373 }, | 373 }, |
374 serveCharm{}, | 374 serveCharm{}, |
375 createUniter{}, | 375 createUniter{}, |
376 waitUnit{ | 376 waitUnit{ |
377 » » » status: params.UnitStarted, | 377 » » » status: params.StatusStarted, |
378 }, | 378 }, |
379 waitHooks{"install", "config-changed", "start"}, | 379 waitHooks{"install", "config-changed", "start"}, |
380 assertYaml{"charm/config.out", map[string]interface{}{ | 380 assertYaml{"charm/config.out", map[string]interface{}{ |
381 "blog-title": "My Title", | 381 "blog-title": "My Title", |
382 }}, | 382 }}, |
383 changeConfig{"blog-title": "Goodness Gracious Me"}, | 383 changeConfig{"blog-title": "Goodness Gracious Me"}, |
384 waitHooks{"config-changed"}, | 384 waitHooks{"config-changed"}, |
385 verifyRunning{}, | 385 verifyRunning{}, |
386 assertYaml{"charm/config.out", map[string]interface{}{ | 386 assertYaml{"charm/config.out", map[string]interface{}{ |
387 "blog-title": "Goodness Gracious Me", | 387 "blog-title": "Goodness Gracious Me", |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 } | 444 } |
445 | 445 |
446 var steadyUpgradeTests = []uniterTest{ | 446 var steadyUpgradeTests = []uniterTest{ |
447 // Upgrade scenarios from steady state. | 447 // Upgrade scenarios from steady state. |
448 ut( | 448 ut( |
449 "steady state upgrade", | 449 "steady state upgrade", |
450 quickStart{}, | 450 quickStart{}, |
451 createCharm{revision: 1}, | 451 createCharm{revision: 1}, |
452 upgradeCharm{revision: 1}, | 452 upgradeCharm{revision: 1}, |
453 waitUnit{ | 453 waitUnit{ |
454 » » » status: params.UnitStarted, | 454 » » » status: params.StatusStarted, |
455 charm: 1, | 455 charm: 1, |
456 }, | 456 }, |
457 waitHooks{"upgrade-charm", "config-changed"}, | 457 waitHooks{"upgrade-charm", "config-changed"}, |
458 verifyCharm{revision: 1}, | 458 verifyCharm{revision: 1}, |
459 verifyRunning{}, | 459 verifyRunning{}, |
460 ), ut( | 460 ), ut( |
461 "steady state forced upgrade (identical behaviour)", | 461 "steady state forced upgrade (identical behaviour)", |
462 quickStart{}, | 462 quickStart{}, |
463 createCharm{revision: 1}, | 463 createCharm{revision: 1}, |
464 upgradeCharm{revision: 1, forced: true}, | 464 upgradeCharm{revision: 1, forced: true}, |
465 waitUnit{ | 465 waitUnit{ |
466 » » » status: params.UnitStarted, | 466 » » » status: params.StatusStarted, |
467 charm: 1, | 467 charm: 1, |
468 }, | 468 }, |
469 waitHooks{"upgrade-charm", "config-changed"}, | 469 waitHooks{"upgrade-charm", "config-changed"}, |
470 verifyCharm{revision: 1}, | 470 verifyCharm{revision: 1}, |
471 verifyRunning{}, | 471 verifyRunning{}, |
472 ), ut( | 472 ), ut( |
473 "steady state upgrade hook fail and resolve", | 473 "steady state upgrade hook fail and resolve", |
474 quickStart{}, | 474 quickStart{}, |
475 createCharm{revision: 1, badHooks: []string{"upgrade-charm"}}, | 475 createCharm{revision: 1, badHooks: []string{"upgrade-charm"}}, |
476 upgradeCharm{revision: 1}, | 476 upgradeCharm{revision: 1}, |
477 waitUnit{ | 477 waitUnit{ |
478 » » » status: params.UnitError, | 478 » » » status: params.StatusError, |
479 info: `hook failed: "upgrade-charm"`, | 479 info: `hook failed: "upgrade-charm"`, |
480 charm: 1, | 480 charm: 1, |
481 }, | 481 }, |
482 waitHooks{"fail-upgrade-charm"}, | 482 waitHooks{"fail-upgrade-charm"}, |
483 verifyCharm{revision: 1}, | 483 verifyCharm{revision: 1}, |
484 verifyWaiting{}, | 484 verifyWaiting{}, |
485 | 485 |
486 resolveError{state.ResolvedNoHooks}, | 486 resolveError{state.ResolvedNoHooks}, |
487 waitUnit{ | 487 waitUnit{ |
488 » » » status: params.UnitStarted, | 488 » » » status: params.StatusStarted, |
489 charm: 1, | 489 charm: 1, |
490 }, | 490 }, |
491 waitHooks{"config-changed"}, | 491 waitHooks{"config-changed"}, |
492 verifyRunning{}, | 492 verifyRunning{}, |
493 ), ut( | 493 ), ut( |
494 "steady state upgrade hook fail and retry", | 494 "steady state upgrade hook fail and retry", |
495 quickStart{}, | 495 quickStart{}, |
496 createCharm{revision: 1, badHooks: []string{"upgrade-charm"}}, | 496 createCharm{revision: 1, badHooks: []string{"upgrade-charm"}}, |
497 upgradeCharm{revision: 1}, | 497 upgradeCharm{revision: 1}, |
498 waitUnit{ | 498 waitUnit{ |
499 » » » status: params.UnitError, | 499 » » » status: params.StatusError, |
500 info: `hook failed: "upgrade-charm"`, | 500 info: `hook failed: "upgrade-charm"`, |
501 charm: 1, | 501 charm: 1, |
502 }, | 502 }, |
503 waitHooks{"fail-upgrade-charm"}, | 503 waitHooks{"fail-upgrade-charm"}, |
504 verifyCharm{revision: 1}, | 504 verifyCharm{revision: 1}, |
505 verifyWaiting{}, | 505 verifyWaiting{}, |
506 | 506 |
507 resolveError{state.ResolvedRetryHooks}, | 507 resolveError{state.ResolvedRetryHooks}, |
508 waitUnit{ | 508 waitUnit{ |
509 » » » status: params.UnitError, | 509 » » » status: params.StatusError, |
510 info: `hook failed: "upgrade-charm"`, | 510 info: `hook failed: "upgrade-charm"`, |
511 charm: 1, | 511 charm: 1, |
512 }, | 512 }, |
513 waitHooks{"fail-upgrade-charm"}, | 513 waitHooks{"fail-upgrade-charm"}, |
514 verifyWaiting{}, | 514 verifyWaiting{}, |
515 | 515 |
516 fixHook{"upgrade-charm"}, | 516 fixHook{"upgrade-charm"}, |
517 resolveError{state.ResolvedRetryHooks}, | 517 resolveError{state.ResolvedRetryHooks}, |
518 waitUnit{ | 518 waitUnit{ |
519 » » » status: params.UnitStarted, | 519 » » » status: params.StatusStarted, |
520 charm: 1, | 520 charm: 1, |
521 }, | 521 }, |
522 waitHooks{"upgrade-charm", "config-changed"}, | 522 waitHooks{"upgrade-charm", "config-changed"}, |
523 verifyRunning{}, | 523 verifyRunning{}, |
524 ), | 524 ), |
525 ut( | 525 ut( |
526 // This test does an add-relation as quickly as possible | 526 // This test does an add-relation as quickly as possible |
527 // after an upgrade-charm, in the hope that the scheduler will | 527 // after an upgrade-charm, in the hope that the scheduler will |
528 // deliver the events in the wrong order. The observed | 528 // deliver the events in the wrong order. The observed |
529 // behaviour should be the same in either case. | 529 // behaviour should be the same in either case. |
(...skipping 21 matching lines...) Expand all Loading... |
551 } | 551 } |
552 | 552 |
553 var errorUpgradeTests = []uniterTest{ | 553 var errorUpgradeTests = []uniterTest{ |
554 // Upgrade scenarios from error state. | 554 // Upgrade scenarios from error state. |
555 ut( | 555 ut( |
556 "error state unforced upgrade (ignored until started state)", | 556 "error state unforced upgrade (ignored until started state)", |
557 startupError{"start"}, | 557 startupError{"start"}, |
558 createCharm{revision: 1}, | 558 createCharm{revision: 1}, |
559 upgradeCharm{revision: 1}, | 559 upgradeCharm{revision: 1}, |
560 waitUnit{ | 560 waitUnit{ |
561 » » » status: params.UnitError, | 561 » » » status: params.StatusError, |
562 info: `hook failed: "start"`, | 562 info: `hook failed: "start"`, |
563 }, | 563 }, |
564 waitHooks{}, | 564 waitHooks{}, |
565 verifyCharm{}, | 565 verifyCharm{}, |
566 verifyWaiting{}, | 566 verifyWaiting{}, |
567 | 567 |
568 resolveError{state.ResolvedNoHooks}, | 568 resolveError{state.ResolvedNoHooks}, |
569 waitUnit{ | 569 waitUnit{ |
570 » » » status: params.UnitStarted, | 570 » » » status: params.StatusStarted, |
571 charm: 1, | 571 charm: 1, |
572 }, | 572 }, |
573 waitHooks{"config-changed", "upgrade-charm", "config-changed"}, | 573 waitHooks{"config-changed", "upgrade-charm", "config-changed"}, |
574 verifyCharm{revision: 1}, | 574 verifyCharm{revision: 1}, |
575 verifyRunning{}, | 575 verifyRunning{}, |
576 ), ut( | 576 ), ut( |
577 "error state forced upgrade", | 577 "error state forced upgrade", |
578 startupError{"start"}, | 578 startupError{"start"}, |
579 createCharm{revision: 1}, | 579 createCharm{revision: 1}, |
580 upgradeCharm{revision: 1, forced: true}, | 580 upgradeCharm{revision: 1, forced: true}, |
581 // It's not possible to tell directly from state when the upgrad
e is | 581 // It's not possible to tell directly from state when the upgrad
e is |
582 // complete, because the new unit charm URL is set at the upgrad
e | 582 // complete, because the new unit charm URL is set at the upgrad
e |
583 // process's point of no return (before actually deploying, but
after | 583 // process's point of no return (before actually deploying, but
after |
584 // the charm has been downloaded and verified). However, it's st
ill | 584 // the charm has been downloaded and verified). However, it's st
ill |
585 // useful to wait until that point... | 585 // useful to wait until that point... |
586 waitUnit{ | 586 waitUnit{ |
587 » » » status: params.UnitError, | 587 » » » status: params.StatusError, |
588 info: `hook failed: "start"`, | 588 info: `hook failed: "start"`, |
589 charm: 1, | 589 charm: 1, |
590 }, | 590 }, |
591 // ...because the uniter *will* complete a started deployment ev
en if | 591 // ...because the uniter *will* complete a started deployment ev
en if |
592 // we stop it from outside. So, by stopping and starting, we can
be | 592 // we stop it from outside. So, by stopping and starting, we can
be |
593 // sure that the operation has completed and can safely verify t
hat | 593 // sure that the operation has completed and can safely verify t
hat |
594 // the charm state on disk is as we expect. | 594 // the charm state on disk is as we expect. |
595 verifyWaiting{}, | 595 verifyWaiting{}, |
596 verifyCharm{revision: 1}, | 596 verifyCharm{revision: 1}, |
597 | 597 |
598 resolveError{state.ResolvedNoHooks}, | 598 resolveError{state.ResolvedNoHooks}, |
599 waitUnit{ | 599 waitUnit{ |
600 » » » status: params.UnitStarted, | 600 » » » status: params.StatusStarted, |
601 charm: 1, | 601 charm: 1, |
602 }, | 602 }, |
603 waitHooks{"config-changed"}, | 603 waitHooks{"config-changed"}, |
604 verifyRunning{}, | 604 verifyRunning{}, |
605 ), | 605 ), |
606 } | 606 } |
607 | 607 |
608 func (s *UniterSuite) TestUniterErrorStateUpgrade(c *C) { | 608 func (s *UniterSuite) TestUniterErrorStateUpgrade(c *C) { |
609 s.runUniterTests(c, errorUpgradeTests) | 609 s.runUniterTests(c, errorUpgradeTests) |
610 } | 610 } |
611 | 611 |
612 var upgradeConflictsTests = []uniterTest{ | 612 var upgradeConflictsTests = []uniterTest{ |
613 // Upgrade scenarios - handling conflicts. | 613 // Upgrade scenarios - handling conflicts. |
614 ut( | 614 ut( |
615 "upgrade: conflicting files", | 615 "upgrade: conflicting files", |
616 startUpgradeError{}, | 616 startUpgradeError{}, |
617 | 617 |
618 // NOTE: this is just dumbly committing the conflicts, but AFAIC
T this | 618 // NOTE: this is just dumbly committing the conflicts, but AFAIC
T this |
619 // is the only reasonable solution; if the user tells us it's re
solved | 619 // is the only reasonable solution; if the user tells us it's re
solved |
620 // we have to take their word for it. | 620 // we have to take their word for it. |
621 resolveError{state.ResolvedNoHooks}, | 621 resolveError{state.ResolvedNoHooks}, |
622 waitHooks{"upgrade-charm", "config-changed"}, | 622 waitHooks{"upgrade-charm", "config-changed"}, |
623 waitUnit{ | 623 waitUnit{ |
624 » » » status: params.UnitStarted, | 624 » » » status: params.StatusStarted, |
625 charm: 1, | 625 charm: 1, |
626 }, | 626 }, |
627 verifyCharm{revision: 1}, | 627 verifyCharm{revision: 1}, |
628 ), ut( | 628 ), ut( |
629 `upgrade: conflicting directories`, | 629 `upgrade: conflicting directories`, |
630 createCharm{ | 630 createCharm{ |
631 customize: func(c *C, ctx *context, path string) { | 631 customize: func(c *C, ctx *context, path string) { |
632 err := os.Mkdir(filepath.Join(path, "data"), 075
5) | 632 err := os.Mkdir(filepath.Join(path, "data"), 075
5) |
633 c.Assert(err, IsNil) | 633 c.Assert(err, IsNil) |
634 appendHook(c, path, "start", "echo DATA > data/n
ewfile") | 634 appendHook(c, path, "start", "echo DATA > data/n
ewfile") |
635 }, | 635 }, |
636 }, | 636 }, |
637 serveCharm{}, | 637 serveCharm{}, |
638 createUniter{}, | 638 createUniter{}, |
639 waitUnit{ | 639 waitUnit{ |
640 » » » status: params.UnitStarted, | 640 » » » status: params.StatusStarted, |
641 }, | 641 }, |
642 waitHooks{"install", "config-changed", "start"}, | 642 waitHooks{"install", "config-changed", "start"}, |
643 verifyCharm{}, | 643 verifyCharm{}, |
644 | 644 |
645 createCharm{ | 645 createCharm{ |
646 revision: 1, | 646 revision: 1, |
647 customize: func(c *C, ctx *context, path string) { | 647 customize: func(c *C, ctx *context, path string) { |
648 data := filepath.Join(path, "data") | 648 data := filepath.Join(path, "data") |
649 err := ioutil.WriteFile(data, []byte("<nelson>ha
ha</nelson>"), 0644) | 649 err := ioutil.WriteFile(data, []byte("<nelson>ha
ha</nelson>"), 0644) |
650 c.Assert(err, IsNil) | 650 c.Assert(err, IsNil) |
651 }, | 651 }, |
652 }, | 652 }, |
653 serveCharm{}, | 653 serveCharm{}, |
654 upgradeCharm{revision: 1}, | 654 upgradeCharm{revision: 1}, |
655 waitUnit{ | 655 waitUnit{ |
656 » » » status: params.UnitError, | 656 » » » status: params.StatusError, |
657 info: "upgrade failed", | 657 info: "upgrade failed", |
658 charm: 1, | 658 charm: 1, |
659 }, | 659 }, |
660 verifyWaiting{}, | 660 verifyWaiting{}, |
661 verifyCharm{dirty: true}, | 661 verifyCharm{dirty: true}, |
662 | 662 |
663 resolveError{state.ResolvedNoHooks}, | 663 resolveError{state.ResolvedNoHooks}, |
664 waitHooks{"upgrade-charm", "config-changed"}, | 664 waitHooks{"upgrade-charm", "config-changed"}, |
665 waitUnit{ | 665 waitUnit{ |
666 » » » status: params.UnitStarted, | 666 » » » status: params.StatusStarted, |
667 charm: 1, | 667 charm: 1, |
668 }, | 668 }, |
669 verifyCharm{revision: 1}, | 669 verifyCharm{revision: 1}, |
670 ), ut( | 670 ), ut( |
671 "upgrade conflict resolved with forced upgrade", | 671 "upgrade conflict resolved with forced upgrade", |
672 startUpgradeError{}, | 672 startUpgradeError{}, |
673 createCharm{ | 673 createCharm{ |
674 revision: 2, | 674 revision: 2, |
675 customize: func(c *C, ctx *context, path string) { | 675 customize: func(c *C, ctx *context, path string) { |
676 otherdata := filepath.Join(path, "otherdata") | 676 otherdata := filepath.Join(path, "otherdata") |
677 err := ioutil.WriteFile(otherdata, []byte("blah"
), 0644) | 677 err := ioutil.WriteFile(otherdata, []byte("blah"
), 0644) |
678 c.Assert(err, IsNil) | 678 c.Assert(err, IsNil) |
679 }, | 679 }, |
680 }, | 680 }, |
681 serveCharm{}, | 681 serveCharm{}, |
682 upgradeCharm{revision: 2, forced: true}, | 682 upgradeCharm{revision: 2, forced: true}, |
683 waitUnit{ | 683 waitUnit{ |
684 » » » status: params.UnitStarted, | 684 » » » status: params.StatusStarted, |
685 charm: 2, | 685 charm: 2, |
686 }, | 686 }, |
687 waitHooks{"upgrade-charm", "config-changed"}, | 687 waitHooks{"upgrade-charm", "config-changed"}, |
688 verifyCharm{revision: 2}, | 688 verifyCharm{revision: 2}, |
689 custom{func(c *C, ctx *context) { | 689 custom{func(c *C, ctx *context) { |
690 // otherdata should exist (in v2) | 690 // otherdata should exist (in v2) |
691 otherdata, err := ioutil.ReadFile(filepath.Join(ctx.path
, "charm", "otherdata")) | 691 otherdata, err := ioutil.ReadFile(filepath.Join(ctx.path
, "charm", "otherdata")) |
692 c.Assert(err, IsNil) | 692 c.Assert(err, IsNil) |
693 c.Assert(string(otherdata), Equals, "blah") | 693 c.Assert(string(otherdata), Equals, "blah") |
694 | 694 |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 | 1133 |
1134 type startupError struct { | 1134 type startupError struct { |
1135 badHook string | 1135 badHook string |
1136 } | 1136 } |
1137 | 1137 |
1138 func (s startupError) step(c *C, ctx *context) { | 1138 func (s startupError) step(c *C, ctx *context) { |
1139 step(c, ctx, createCharm{badHooks: []string{s.badHook}}) | 1139 step(c, ctx, createCharm{badHooks: []string{s.badHook}}) |
1140 step(c, ctx, serveCharm{}) | 1140 step(c, ctx, serveCharm{}) |
1141 step(c, ctx, createUniter{}) | 1141 step(c, ctx, createUniter{}) |
1142 step(c, ctx, waitUnit{ | 1142 step(c, ctx, waitUnit{ |
1143 » » status: params.UnitError, | 1143 » » status: params.StatusError, |
1144 info: fmt.Sprintf(`hook failed: %q`, s.badHook), | 1144 info: fmt.Sprintf(`hook failed: %q`, s.badHook), |
1145 }) | 1145 }) |
1146 for _, hook := range []string{"install", "config-changed", "start"} { | 1146 for _, hook := range []string{"install", "config-changed", "start"} { |
1147 if hook == s.badHook { | 1147 if hook == s.badHook { |
1148 step(c, ctx, waitHooks{"fail-" + hook}) | 1148 step(c, ctx, waitHooks{"fail-" + hook}) |
1149 break | 1149 break |
1150 } | 1150 } |
1151 step(c, ctx, waitHooks{hook}) | 1151 step(c, ctx, waitHooks{hook}) |
1152 } | 1152 } |
1153 step(c, ctx, verifyCharm{}) | 1153 step(c, ctx, verifyCharm{}) |
1154 } | 1154 } |
1155 | 1155 |
1156 type quickStart struct{} | 1156 type quickStart struct{} |
1157 | 1157 |
1158 func (s quickStart) step(c *C, ctx *context) { | 1158 func (s quickStart) step(c *C, ctx *context) { |
1159 step(c, ctx, createCharm{}) | 1159 step(c, ctx, createCharm{}) |
1160 step(c, ctx, serveCharm{}) | 1160 step(c, ctx, serveCharm{}) |
1161 step(c, ctx, createUniter{}) | 1161 step(c, ctx, createUniter{}) |
1162 » step(c, ctx, waitUnit{status: params.UnitStarted}) | 1162 » step(c, ctx, waitUnit{status: params.StatusStarted}) |
1163 step(c, ctx, waitHooks{"install", "config-changed", "start"}) | 1163 step(c, ctx, waitHooks{"install", "config-changed", "start"}) |
1164 step(c, ctx, verifyCharm{}) | 1164 step(c, ctx, verifyCharm{}) |
1165 } | 1165 } |
1166 | 1166 |
1167 type quickStartRelation struct{} | 1167 type quickStartRelation struct{} |
1168 | 1168 |
1169 func (s quickStartRelation) step(c *C, ctx *context) { | 1169 func (s quickStartRelation) step(c *C, ctx *context) { |
1170 step(c, ctx, quickStart{}) | 1170 step(c, ctx, quickStart{}) |
1171 step(c, ctx, addRelation{}) | 1171 step(c, ctx, addRelation{}) |
1172 step(c, ctx, addRelationUnit{}) | 1172 step(c, ctx, addRelationUnit{}) |
1173 step(c, ctx, waitHooks{"db-relation-joined mysql/0 db:0", "db-relation-c
hanged mysql/0 db:0"}) | 1173 step(c, ctx, waitHooks{"db-relation-joined mysql/0 db:0", "db-relation-c
hanged mysql/0 db:0"}) |
1174 step(c, ctx, verifyRunning{}) | 1174 step(c, ctx, verifyRunning{}) |
1175 } | 1175 } |
1176 | 1176 |
1177 type resolveError struct { | 1177 type resolveError struct { |
1178 resolved state.ResolvedMode | 1178 resolved state.ResolvedMode |
1179 } | 1179 } |
1180 | 1180 |
1181 func (s resolveError) step(c *C, ctx *context) { | 1181 func (s resolveError) step(c *C, ctx *context) { |
1182 err := ctx.unit.SetResolved(s.resolved) | 1182 err := ctx.unit.SetResolved(s.resolved) |
1183 c.Assert(err, IsNil) | 1183 c.Assert(err, IsNil) |
1184 } | 1184 } |
1185 | 1185 |
1186 type waitUnit struct { | 1186 type waitUnit struct { |
1187 » status params.UnitStatus | 1187 » status params.Status |
1188 info string | 1188 info string |
1189 charm int | 1189 charm int |
1190 resolved state.ResolvedMode | 1190 resolved state.ResolvedMode |
1191 } | 1191 } |
1192 | 1192 |
1193 func (s waitUnit) step(c *C, ctx *context) { | 1193 func (s waitUnit) step(c *C, ctx *context) { |
1194 timeout := time.After(worstCase) | 1194 timeout := time.After(worstCase) |
1195 for { | 1195 for { |
1196 ctx.st.StartSync() | 1196 ctx.st.StartSync() |
1197 select { | 1197 select { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 func (s startUpgradeError) step(c *C, ctx *context) { | 1331 func (s startUpgradeError) step(c *C, ctx *context) { |
1332 steps := []stepper{ | 1332 steps := []stepper{ |
1333 createCharm{ | 1333 createCharm{ |
1334 customize: func(c *C, ctx *context, path string) { | 1334 customize: func(c *C, ctx *context, path string) { |
1335 appendHook(c, path, "start", "echo STARTDATA > d
ata") | 1335 appendHook(c, path, "start", "echo STARTDATA > d
ata") |
1336 }, | 1336 }, |
1337 }, | 1337 }, |
1338 serveCharm{}, | 1338 serveCharm{}, |
1339 createUniter{}, | 1339 createUniter{}, |
1340 waitUnit{ | 1340 waitUnit{ |
1341 » » » status: params.UnitStarted, | 1341 » » » status: params.StatusStarted, |
1342 }, | 1342 }, |
1343 waitHooks{"install", "config-changed", "start"}, | 1343 waitHooks{"install", "config-changed", "start"}, |
1344 verifyCharm{}, | 1344 verifyCharm{}, |
1345 | 1345 |
1346 createCharm{ | 1346 createCharm{ |
1347 revision: 1, | 1347 revision: 1, |
1348 customize: func(c *C, ctx *context, path string) { | 1348 customize: func(c *C, ctx *context, path string) { |
1349 data := filepath.Join(path, "data") | 1349 data := filepath.Join(path, "data") |
1350 err := ioutil.WriteFile(data, []byte("<nelson>ha
ha</nelson>"), 0644) | 1350 err := ioutil.WriteFile(data, []byte("<nelson>ha
ha</nelson>"), 0644) |
1351 c.Assert(err, IsNil) | 1351 c.Assert(err, IsNil) |
1352 ignore := filepath.Join(path, "ignore") | 1352 ignore := filepath.Join(path, "ignore") |
1353 err = ioutil.WriteFile(ignore, []byte("anything"
), 0644) | 1353 err = ioutil.WriteFile(ignore, []byte("anything"
), 0644) |
1354 c.Assert(err, IsNil) | 1354 c.Assert(err, IsNil) |
1355 }, | 1355 }, |
1356 }, | 1356 }, |
1357 serveCharm{}, | 1357 serveCharm{}, |
1358 upgradeCharm{revision: 1}, | 1358 upgradeCharm{revision: 1}, |
1359 waitUnit{ | 1359 waitUnit{ |
1360 » » » status: params.UnitError, | 1360 » » » status: params.StatusError, |
1361 info: "upgrade failed", | 1361 info: "upgrade failed", |
1362 charm: 1, | 1362 charm: 1, |
1363 }, | 1363 }, |
1364 verifyWaiting{}, | 1364 verifyWaiting{}, |
1365 verifyCharm{dirty: true}, | 1365 verifyCharm{dirty: true}, |
1366 } | 1366 } |
1367 for _, s_ := range steps { | 1367 for _, s_ := range steps { |
1368 step(c, ctx, s_) | 1368 step(c, ctx, s_) |
1369 } | 1369 } |
1370 } | 1370 } |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1630 newmeta, err := goyaml.Marshal(meta) | 1630 newmeta, err := goyaml.Marshal(meta) |
1631 c.Assert(err, IsNil) | 1631 c.Assert(err, IsNil) |
1632 ioutil.WriteFile(path, newmeta, 0644) | 1632 ioutil.WriteFile(path, newmeta, 0644) |
1633 | 1633 |
1634 f, err = os.Open(path) | 1634 f, err = os.Open(path) |
1635 c.Assert(err, IsNil) | 1635 c.Assert(err, IsNil) |
1636 defer f.Close() | 1636 defer f.Close() |
1637 meta, err = charm.ReadMeta(f) | 1637 meta, err = charm.ReadMeta(f) |
1638 c.Assert(err, IsNil) | 1638 c.Assert(err, IsNil) |
1639 } | 1639 } |
OLD | NEW |