github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/worker/uniter/operation/deploy_test.go (about) 1 // Copyright 2014-2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package operation_test 5 6 import ( 7 "github.com/juju/errors" 8 "github.com/juju/testing" 9 jc "github.com/juju/testing/checkers" 10 gc "gopkg.in/check.v1" 11 corecharm "gopkg.in/juju/charm.v4" 12 "gopkg.in/juju/charm.v4/hooks" 13 14 "github.com/juju/juju/worker/uniter/hook" 15 "github.com/juju/juju/worker/uniter/operation" 16 ) 17 18 type DeploySuite struct { 19 testing.IsolationSuite 20 } 21 22 var _ = gc.Suite(&DeploySuite{}) 23 24 type newDeploy func(operation.Factory, *corecharm.URL) (operation.Operation, error) 25 26 func (s *DeploySuite) testPrepareAlreadyDone( 27 c *gc.C, newDeploy newDeploy, kind operation.Kind, expectClearResolvedFlag bool, 28 ) { 29 callbacks := &DeployCallbacks{ 30 MockClearResolvedFlag: &MockNoArgs{}, 31 } 32 factory := operation.NewFactory(nil, nil, callbacks, nil) 33 op, err := newDeploy(factory, curl("cs:quantal/hive-23")) 34 c.Assert(err, jc.ErrorIsNil) 35 newState, err := op.Prepare(operation.State{ 36 Kind: kind, 37 Step: operation.Done, 38 CharmURL: curl("cs:quantal/hive-23"), 39 }) 40 c.Check(newState, gc.IsNil) 41 c.Check(errors.Cause(err), gc.Equals, operation.ErrSkipExecute) 42 c.Check(callbacks.MockClearResolvedFlag.called, gc.Equals, expectClearResolvedFlag) 43 } 44 45 func (s *DeploySuite) TestPrepareAlreadyDone_Install(c *gc.C) { 46 s.testPrepareAlreadyDone(c, 47 (operation.Factory).NewInstall, 48 operation.Install, 49 false, 50 ) 51 } 52 53 func (s *DeploySuite) TestPrepareAlreadyDone_Upgrade(c *gc.C) { 54 s.testPrepareAlreadyDone(c, 55 (operation.Factory).NewUpgrade, 56 operation.Upgrade, 57 false, 58 ) 59 } 60 61 func (s *DeploySuite) TestPrepareAlreadyDone_RevertUpgrade(c *gc.C) { 62 s.testPrepareAlreadyDone(c, 63 (operation.Factory).NewRevertUpgrade, 64 operation.Upgrade, 65 true, 66 ) 67 } 68 69 func (s *DeploySuite) TestPrepareAlreadyDone_ResolvedUpgrade(c *gc.C) { 70 s.testPrepareAlreadyDone(c, 71 (operation.Factory).NewResolvedUpgrade, 72 operation.Upgrade, 73 true, 74 ) 75 } 76 77 func (s *DeploySuite) testClearResolvedFlagError(c *gc.C, newDeploy newDeploy) { 78 callbacks := &DeployCallbacks{ 79 MockClearResolvedFlag: &MockNoArgs{err: errors.New("blort")}, 80 } 81 factory := operation.NewFactory(nil, nil, callbacks, nil) 82 op, err := newDeploy(factory, curl("cs:quantal/hive-23")) 83 c.Assert(err, jc.ErrorIsNil) 84 newState, err := op.Prepare(operation.State{}) 85 c.Check(newState, gc.IsNil) 86 c.Check(err, gc.ErrorMatches, "blort") 87 c.Check(callbacks.MockClearResolvedFlag.called, jc.IsTrue) 88 } 89 90 func (s *DeploySuite) TestClearResolvedFlagError_RevertUpgrade(c *gc.C) { 91 s.testClearResolvedFlagError(c, (operation.Factory).NewRevertUpgrade) 92 } 93 94 func (s *DeploySuite) TestClearResolvedFlagError_ResolvedUpgrade(c *gc.C) { 95 s.testClearResolvedFlagError(c, (operation.Factory).NewResolvedUpgrade) 96 } 97 98 func (s *DeploySuite) testNotifyDeployerError( 99 c *gc.C, newDeploy newDeploy, expectNotifyRevert bool, 100 ) { 101 callbacks := &DeployCallbacks{ 102 MockClearResolvedFlag: &MockNoArgs{}, 103 } 104 deployer := &MockDeployer{} 105 expectCall := &MockNoArgs{err: errors.New("snh")} 106 if expectNotifyRevert { 107 deployer.MockNotifyRevert = expectCall 108 } else { 109 deployer.MockNotifyResolved = expectCall 110 } 111 factory := operation.NewFactory(deployer, nil, callbacks, nil) 112 op, err := newDeploy(factory, curl("cs:quantal/hive-23")) 113 c.Assert(err, jc.ErrorIsNil) 114 115 newState, err := op.Prepare(operation.State{}) 116 c.Check(newState, gc.IsNil) 117 c.Check(err, gc.ErrorMatches, "snh") 118 c.Check(expectCall.called, jc.IsTrue) 119 } 120 121 func (s *DeploySuite) TestNotifyDeployerError_RevertUpgrade(c *gc.C) { 122 s.testNotifyDeployerError(c, (operation.Factory).NewRevertUpgrade, true) 123 } 124 125 func (s *DeploySuite) TestNotifyDeployerError_ResolvedUpgrade(c *gc.C) { 126 s.testNotifyDeployerError(c, (operation.Factory).NewResolvedUpgrade, false) 127 } 128 129 func (s *DeploySuite) testPrepareArchiveInfoError(c *gc.C, newDeploy newDeploy) { 130 callbacks := &DeployCallbacks{ 131 MockClearResolvedFlag: &MockNoArgs{}, 132 MockGetArchiveInfo: &MockGetArchiveInfo{err: errors.New("pew")}, 133 } 134 deployer := &MockDeployer{ 135 MockNotifyRevert: &MockNoArgs{}, 136 MockNotifyResolved: &MockNoArgs{}, 137 } 138 factory := operation.NewFactory(deployer, nil, callbacks, nil) 139 op, err := newDeploy(factory, curl("cs:quantal/hive-23")) 140 c.Assert(err, jc.ErrorIsNil) 141 142 newState, err := op.Prepare(operation.State{}) 143 c.Check(newState, gc.IsNil) 144 c.Check(err, gc.ErrorMatches, "pew") 145 c.Check(callbacks.MockGetArchiveInfo.gotCharmURL, gc.DeepEquals, curl("cs:quantal/hive-23")) 146 } 147 148 func (s *DeploySuite) TestPrepareArchiveInfoError_Install(c *gc.C) { 149 s.testPrepareArchiveInfoError(c, (operation.Factory).NewInstall) 150 } 151 152 func (s *DeploySuite) TestPrepareArchiveInfoError_Upgrade(c *gc.C) { 153 s.testPrepareArchiveInfoError(c, (operation.Factory).NewUpgrade) 154 } 155 156 func (s *DeploySuite) TestPrepareArchiveInfoError_RevertUpgrade(c *gc.C) { 157 s.testPrepareArchiveInfoError(c, (operation.Factory).NewRevertUpgrade) 158 } 159 160 func (s *DeploySuite) TestPrepareArchiveInfoError_ResolvedUpgrade(c *gc.C) { 161 s.testPrepareArchiveInfoError(c, (operation.Factory).NewResolvedUpgrade) 162 } 163 164 func (s *DeploySuite) testPrepareStageError(c *gc.C, newDeploy newDeploy) { 165 callbacks := &DeployCallbacks{ 166 MockClearResolvedFlag: &MockNoArgs{}, 167 MockGetArchiveInfo: &MockGetArchiveInfo{info: &MockBundleInfo{}}, 168 } 169 deployer := &MockDeployer{ 170 MockNotifyRevert: &MockNoArgs{}, 171 MockNotifyResolved: &MockNoArgs{}, 172 MockStage: &MockStage{err: errors.New("squish")}, 173 } 174 var abort <-chan struct{} = make(chan struct{}) 175 factory := operation.NewFactory(deployer, nil, callbacks, abort) 176 op, err := newDeploy(factory, curl("cs:quantal/hive-23")) 177 c.Assert(err, jc.ErrorIsNil) 178 179 newState, err := op.Prepare(operation.State{}) 180 c.Check(newState, gc.IsNil) 181 c.Check(err, gc.ErrorMatches, "squish") 182 c.Check(*deployer.MockStage.gotInfo, gc.Equals, callbacks.MockGetArchiveInfo.info) 183 c.Check(*deployer.MockStage.gotAbort, gc.Equals, abort) 184 } 185 186 func (s *DeploySuite) TestPrepareStageError_Install(c *gc.C) { 187 s.testPrepareStageError(c, (operation.Factory).NewInstall) 188 } 189 190 func (s *DeploySuite) TestPrepareStageError_Upgrade(c *gc.C) { 191 s.testPrepareStageError(c, (operation.Factory).NewUpgrade) 192 } 193 194 func (s *DeploySuite) TestPrepareStageError_RevertUpgrade(c *gc.C) { 195 s.testPrepareStageError(c, (operation.Factory).NewRevertUpgrade) 196 } 197 198 func (s *DeploySuite) TestPrepareStageError_ResolvedUpgrade(c *gc.C) { 199 s.testPrepareStageError(c, (operation.Factory).NewResolvedUpgrade) 200 } 201 202 func (s *DeploySuite) testPrepareSetCharmError(c *gc.C, newDeploy newDeploy) { 203 callbacks := &DeployCallbacks{ 204 MockClearResolvedFlag: &MockNoArgs{}, 205 MockGetArchiveInfo: &MockGetArchiveInfo{}, 206 MockSetCurrentCharm: &MockSetCurrentCharm{err: errors.New("blargh")}, 207 } 208 deployer := &MockDeployer{ 209 MockNotifyRevert: &MockNoArgs{}, 210 MockNotifyResolved: &MockNoArgs{}, 211 MockStage: &MockStage{}, 212 } 213 factory := operation.NewFactory(deployer, nil, callbacks, nil) 214 op, err := newDeploy(factory, curl("cs:quantal/hive-23")) 215 c.Assert(err, jc.ErrorIsNil) 216 217 newState, err := op.Prepare(operation.State{}) 218 c.Check(newState, gc.IsNil) 219 c.Check(err, gc.ErrorMatches, "blargh") 220 c.Check(callbacks.MockSetCurrentCharm.gotCharmURL, gc.DeepEquals, curl("cs:quantal/hive-23")) 221 } 222 223 func (s *DeploySuite) TestPrepareSetCharmError_Install(c *gc.C) { 224 s.testPrepareSetCharmError(c, (operation.Factory).NewInstall) 225 } 226 227 func (s *DeploySuite) TestPrepareSetCharmError_Upgrade(c *gc.C) { 228 s.testPrepareSetCharmError(c, (operation.Factory).NewUpgrade) 229 } 230 231 func (s *DeploySuite) TestPrepareSetCharmError_RevertUpgrade(c *gc.C) { 232 s.testPrepareSetCharmError(c, (operation.Factory).NewRevertUpgrade) 233 } 234 235 func (s *DeploySuite) TestPrepareSetCharmError_ResolvedUpgrade(c *gc.C) { 236 s.testPrepareSetCharmError(c, (operation.Factory).NewResolvedUpgrade) 237 } 238 239 func (s *DeploySuite) testPrepareSuccess(c *gc.C, newDeploy newDeploy, before, after operation.State) { 240 callbacks := NewDeployCallbacks() 241 deployer := &MockDeployer{ 242 MockNotifyRevert: &MockNoArgs{}, 243 MockNotifyResolved: &MockNoArgs{}, 244 MockStage: &MockStage{}, 245 } 246 factory := operation.NewFactory(deployer, nil, callbacks, nil) 247 op, err := newDeploy(factory, curl("cs:quantal/nyancat-4")) 248 c.Assert(err, jc.ErrorIsNil) 249 250 newState, err := op.Prepare(before) 251 c.Check(err, jc.ErrorIsNil) 252 c.Check(newState, gc.DeepEquals, &after) 253 c.Check(callbacks.MockSetCurrentCharm.gotCharmURL, gc.DeepEquals, curl("cs:quantal/nyancat-4")) 254 } 255 256 func (s *DeploySuite) TestPrepareSuccess_Install_BlankSlate(c *gc.C) { 257 s.testPrepareSuccess(c, 258 (operation.Factory).NewInstall, 259 operation.State{}, 260 operation.State{ 261 Kind: operation.Install, 262 Step: operation.Pending, 263 CharmURL: curl("cs:quantal/nyancat-4"), 264 }, 265 ) 266 } 267 268 func (s *DeploySuite) TestPrepareSuccess_Install_Queued(c *gc.C) { 269 s.testPrepareSuccess(c, 270 (operation.Factory).NewInstall, 271 operation.State{ 272 Kind: operation.Install, 273 Step: operation.Queued, 274 CharmURL: curl("cs:quantal/nyancat-4"), 275 }, 276 operation.State{ 277 Kind: operation.Install, 278 Step: operation.Pending, 279 CharmURL: curl("cs:quantal/nyancat-4"), 280 }, 281 ) 282 } 283 284 func (s *DeploySuite) TestPrepareSuccess_Upgrade_PreservePendingHook(c *gc.C) { 285 for i, newDeploy := range []newDeploy{ 286 (operation.Factory).NewUpgrade, 287 (operation.Factory).NewRevertUpgrade, 288 (operation.Factory).NewResolvedUpgrade, 289 } { 290 c.Logf("variant %d", i) 291 s.testPrepareSuccess(c, 292 newDeploy, 293 operation.State{ 294 Kind: operation.RunHook, 295 Step: operation.Pending, 296 Hook: &hook.Info{Kind: hooks.ConfigChanged}, 297 }, 298 operation.State{ 299 Kind: operation.Upgrade, 300 Step: operation.Pending, 301 CharmURL: curl("cs:quantal/nyancat-4"), 302 Hook: &hook.Info{Kind: hooks.ConfigChanged}, 303 }, 304 ) 305 } 306 } 307 308 func (s *DeploySuite) TestPrepareSuccess_Upgrade_PreserveOriginalPendingHook(c *gc.C) { 309 for i, newDeploy := range []newDeploy{ 310 (operation.Factory).NewUpgrade, 311 (operation.Factory).NewRevertUpgrade, 312 (operation.Factory).NewResolvedUpgrade, 313 } { 314 c.Logf("variant %d", i) 315 s.testPrepareSuccess(c, 316 newDeploy, 317 operation.State{ 318 Kind: operation.Upgrade, 319 Step: operation.Pending, 320 CharmURL: curl("cs:quantal/random-23"), 321 Hook: &hook.Info{Kind: hooks.ConfigChanged}, 322 }, 323 operation.State{ 324 Kind: operation.Upgrade, 325 Step: operation.Pending, 326 CharmURL: curl("cs:quantal/nyancat-4"), 327 Hook: &hook.Info{Kind: hooks.ConfigChanged}, 328 }, 329 ) 330 } 331 } 332 333 func (s *DeploySuite) TestPrepareSuccess_Upgrade_PreserveNoHook(c *gc.C) { 334 for i, newDeploy := range []newDeploy{ 335 (operation.Factory).NewUpgrade, 336 (operation.Factory).NewRevertUpgrade, 337 (operation.Factory).NewResolvedUpgrade, 338 } { 339 c.Logf("variant %d", i) 340 s.testPrepareSuccess(c, 341 newDeploy, 342 overwriteState, 343 operation.State{ 344 Kind: operation.Upgrade, 345 Step: operation.Pending, 346 CharmURL: curl("cs:quantal/nyancat-4"), 347 Started: true, 348 CollectMetricsTime: 1234567, 349 }, 350 ) 351 } 352 } 353 354 func (s *DeploySuite) testExecuteError(c *gc.C, newDeploy newDeploy) { 355 callbacks := NewDeployCallbacks() 356 deployer := &MockDeployer{ 357 MockNotifyRevert: &MockNoArgs{}, 358 MockNotifyResolved: &MockNoArgs{}, 359 MockStage: &MockStage{}, 360 MockDeploy: &MockNoArgs{err: errors.New("rasp")}, 361 } 362 factory := operation.NewFactory(deployer, nil, callbacks, nil) 363 op, err := newDeploy(factory, curl("cs:quantal/nyancat-4")) 364 c.Assert(err, jc.ErrorIsNil) 365 _, err = op.Prepare(operation.State{}) 366 c.Assert(err, jc.ErrorIsNil) 367 368 newState, err := op.Execute(operation.State{}) 369 c.Check(newState, gc.IsNil) 370 c.Check(err, gc.ErrorMatches, "rasp") 371 c.Check(deployer.MockDeploy.called, jc.IsTrue) 372 } 373 374 func (s *DeploySuite) TestExecuteError_Install(c *gc.C) { 375 s.testExecuteError(c, (operation.Factory).NewInstall) 376 } 377 378 func (s *DeploySuite) TestExecuteError_Upgrade(c *gc.C) { 379 s.testExecuteError(c, (operation.Factory).NewUpgrade) 380 } 381 382 func (s *DeploySuite) TestExecuteError_RevertUpgrade(c *gc.C) { 383 s.testExecuteError(c, (operation.Factory).NewRevertUpgrade) 384 } 385 386 func (s *DeploySuite) TestExecuteError_ResolvedUpgrade(c *gc.C) { 387 s.testExecuteError(c, (operation.Factory).NewResolvedUpgrade) 388 } 389 390 func (s *DeploySuite) testExecuteSuccess( 391 c *gc.C, newDeploy newDeploy, before, after operation.State, 392 ) { 393 deployer := NewMockDeployer() 394 callbacks := NewDeployCallbacks() 395 factory := operation.NewFactory(deployer, nil, callbacks, nil) 396 op, err := newDeploy(factory, curl("cs:quantal/lol-1")) 397 c.Assert(err, jc.ErrorIsNil) 398 399 midState, err := op.Prepare(before) 400 c.Assert(err, jc.ErrorIsNil) 401 c.Assert(midState, gc.NotNil) 402 403 newState, err := op.Execute(*midState) 404 c.Check(err, jc.ErrorIsNil) 405 c.Check(newState, gc.DeepEquals, &after) 406 c.Check(deployer.MockDeploy.called, jc.IsTrue) 407 } 408 409 func (s *DeploySuite) TestExecuteSuccess_Install_BlankSlate(c *gc.C) { 410 s.testExecuteSuccess(c, 411 (operation.Factory).NewInstall, 412 operation.State{}, 413 operation.State{ 414 Kind: operation.Install, 415 Step: operation.Done, 416 CharmURL: curl("cs:quantal/lol-1"), 417 }, 418 ) 419 } 420 421 func (s *DeploySuite) TestExecuteSuccess_Install_Queued(c *gc.C) { 422 s.testExecuteSuccess(c, 423 (operation.Factory).NewInstall, 424 operation.State{ 425 Kind: operation.Install, 426 Step: operation.Queued, 427 CharmURL: curl("cs:quantal/lol-1"), 428 }, 429 operation.State{ 430 Kind: operation.Install, 431 Step: operation.Done, 432 CharmURL: curl("cs:quantal/lol-1"), 433 }, 434 ) 435 } 436 437 func (s *DeploySuite) TestExecuteSuccess_Upgrade_PreservePendingHook(c *gc.C) { 438 for i, newDeploy := range []newDeploy{ 439 (operation.Factory).NewUpgrade, 440 (operation.Factory).NewRevertUpgrade, 441 (operation.Factory).NewResolvedUpgrade, 442 } { 443 c.Logf("variant %d", i) 444 s.testExecuteSuccess(c, 445 newDeploy, 446 operation.State{ 447 Kind: operation.RunHook, 448 Step: operation.Pending, 449 Hook: &hook.Info{Kind: hooks.ConfigChanged}, 450 }, 451 operation.State{ 452 Kind: operation.Upgrade, 453 Step: operation.Done, 454 CharmURL: curl("cs:quantal/lol-1"), 455 Hook: &hook.Info{Kind: hooks.ConfigChanged}, 456 }, 457 ) 458 } 459 } 460 461 func (s *DeploySuite) TestExecuteSuccess_Upgrade_PreserveOriginalPendingHook(c *gc.C) { 462 for i, newDeploy := range []newDeploy{ 463 (operation.Factory).NewUpgrade, 464 (operation.Factory).NewRevertUpgrade, 465 (operation.Factory).NewResolvedUpgrade, 466 } { 467 c.Logf("variant %d", i) 468 s.testExecuteSuccess(c, 469 newDeploy, 470 operation.State{ 471 Kind: operation.Upgrade, 472 Step: operation.Pending, 473 CharmURL: curl("cs:quantal/wild-9"), 474 Hook: &hook.Info{Kind: hooks.ConfigChanged}, 475 }, 476 operation.State{ 477 Kind: operation.Upgrade, 478 Step: operation.Done, 479 CharmURL: curl("cs:quantal/lol-1"), 480 Hook: &hook.Info{Kind: hooks.ConfigChanged}, 481 }, 482 ) 483 } 484 } 485 486 func (s *DeploySuite) TestExecuteSuccess_Upgrade_PreserveNoHook(c *gc.C) { 487 for i, newDeploy := range []newDeploy{ 488 (operation.Factory).NewUpgrade, 489 (operation.Factory).NewRevertUpgrade, 490 (operation.Factory).NewResolvedUpgrade, 491 } { 492 c.Logf("variant %d", i) 493 s.testExecuteSuccess(c, 494 newDeploy, 495 overwriteState, 496 operation.State{ 497 Kind: operation.Upgrade, 498 Step: operation.Done, 499 CharmURL: curl("cs:quantal/lol-1"), 500 Started: true, 501 CollectMetricsTime: 1234567, 502 }, 503 ) 504 } 505 } 506 507 func (s *DeploySuite) testCommitMetricsError(c *gc.C, newDeploy newDeploy) { 508 callbacks := NewDeployCommitCallbacks(errors.New("glukh")) 509 factory := operation.NewFactory(nil, nil, callbacks, nil) 510 op, err := newDeploy(factory, curl("cs:quantal/x-0")) 511 c.Assert(err, jc.ErrorIsNil) 512 newState, err := op.Commit(operation.State{}) 513 c.Check(err, gc.ErrorMatches, "glukh") 514 c.Check(newState, gc.IsNil) 515 } 516 517 func (s *DeploySuite) TestCommitMetricsError_Install(c *gc.C) { 518 s.testCommitMetricsError(c, (operation.Factory).NewInstall) 519 } 520 521 func (s *DeploySuite) TestCommitMetricsError_Upgrade(c *gc.C) { 522 s.testCommitMetricsError(c, (operation.Factory).NewUpgrade) 523 } 524 525 func (s *DeploySuite) TestCommitMetricsError_RevertUpgrade(c *gc.C) { 526 s.testCommitMetricsError(c, (operation.Factory).NewRevertUpgrade) 527 } 528 529 func (s *DeploySuite) TestCommitMetricsError_ResolvedUpgrade(c *gc.C) { 530 s.testCommitMetricsError(c, (operation.Factory).NewResolvedUpgrade) 531 } 532 533 func (s *DeploySuite) TestCommitQueueInstallHook(c *gc.C) { 534 callbacks := NewDeployCommitCallbacks(nil) 535 factory := operation.NewFactory(nil, nil, callbacks, nil) 536 op, err := factory.NewInstall(curl("cs:quantal/x-0")) 537 c.Assert(err, jc.ErrorIsNil) 538 newState, err := op.Commit(operation.State{ 539 Kind: operation.Install, 540 Step: operation.Done, 541 CharmURL: nil, // doesn't actually matter here 542 }) 543 c.Check(err, jc.ErrorIsNil) 544 c.Check(newState, gc.DeepEquals, &operation.State{ 545 Kind: operation.RunHook, 546 Step: operation.Queued, 547 Hook: &hook.Info{Kind: hooks.Install}, 548 }) 549 } 550 551 func (s *DeploySuite) testCommitQueueUpgradeHook(c *gc.C, newDeploy newDeploy) { 552 callbacks := NewDeployCommitCallbacks(nil) 553 factory := operation.NewFactory(nil, nil, callbacks, nil) 554 op, err := newDeploy(factory, curl("cs:quantal/x-0")) 555 c.Assert(err, jc.ErrorIsNil) 556 newState, err := op.Commit(operation.State{ 557 Kind: operation.Upgrade, 558 Step: operation.Done, 559 CharmURL: nil, // doesn't actually matter here 560 }) 561 c.Check(err, jc.ErrorIsNil) 562 c.Check(newState, gc.DeepEquals, &operation.State{ 563 Kind: operation.RunHook, 564 Step: operation.Queued, 565 Hook: &hook.Info{Kind: hooks.UpgradeCharm}, 566 }) 567 } 568 569 func (s *DeploySuite) TestCommitQueueUpgradeHook_Upgrade(c *gc.C) { 570 s.testCommitQueueUpgradeHook(c, (operation.Factory).NewUpgrade) 571 } 572 573 func (s *DeploySuite) TestCommitQueueUpgradeHook_RevertUpgrade(c *gc.C) { 574 s.testCommitQueueUpgradeHook(c, (operation.Factory).NewRevertUpgrade) 575 } 576 577 func (s *DeploySuite) TestCommitQueueUpgradeHook_ResolvedUpgrade(c *gc.C) { 578 s.testCommitQueueUpgradeHook(c, (operation.Factory).NewResolvedUpgrade) 579 } 580 581 func (s *DeploySuite) testCommitInterruptedHook(c *gc.C, newDeploy newDeploy) { 582 callbacks := NewDeployCommitCallbacks(nil) 583 factory := operation.NewFactory(nil, nil, callbacks, nil) 584 op, err := newDeploy(factory, curl("cs:quantal/x-0")) 585 c.Assert(err, jc.ErrorIsNil) 586 newState, err := op.Commit(operation.State{ 587 Kind: operation.Upgrade, 588 Step: operation.Done, 589 CharmURL: nil, // doesn't actually matter here 590 Hook: &hook.Info{Kind: hooks.ConfigChanged}, 591 }) 592 c.Check(err, jc.ErrorIsNil) 593 c.Check(newState, gc.DeepEquals, &operation.State{ 594 Kind: operation.RunHook, 595 Step: operation.Pending, 596 Hook: &hook.Info{Kind: hooks.ConfigChanged}, 597 }) 598 } 599 600 func (s *DeploySuite) TestCommitInterruptedHook_Upgrade(c *gc.C) { 601 s.testCommitInterruptedHook(c, (operation.Factory).NewUpgrade) 602 } 603 604 func (s *DeploySuite) TestCommitInterruptedHook_RevertUpgrade(c *gc.C) { 605 s.testCommitInterruptedHook(c, (operation.Factory).NewRevertUpgrade) 606 } 607 608 func (s *DeploySuite) TestCommitInterruptedHook_ResolvedUpgrade(c *gc.C) { 609 s.testCommitInterruptedHook(c, (operation.Factory).NewResolvedUpgrade) 610 }