~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/worker/migrationmaster/worker_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
var _ = gc.Suite(&Suite{})
42
42
 
43
43
var (
44
 
        fakeModelBytes = []byte("model")
45
 
        modelUUID      = "model-uuid"
46
 
        modelTag       = names.NewModelTag(modelUUID)
47
 
        modelTagString = modelTag.String()
48
 
        modelName      = "model-name"
49
 
        ownerTag       = names.NewUserTag("owner")
50
 
        modelVersion   = version.MustParse("1.2.4")
 
44
        fakeModelBytes      = []byte("model")
 
45
        targetControllerTag = names.NewControllerTag("controller-uuid")
 
46
        modelUUID           = "model-uuid"
 
47
        modelTag            = names.NewModelTag(modelUUID)
 
48
        modelName           = "model-name"
 
49
        ownerTag            = names.NewUserTag("owner")
 
50
        modelVersion        = version.MustParse("1.2.4")
51
51
 
52
52
        // Define stub calls that commonly appear in tests here to allow reuse.
53
 
        apiOpenCallController = jujutesting.StubCall{
 
53
        apiOpenControllerCall = jujutesting.StubCall{
54
54
                "apiOpen",
55
55
                []interface{}{
56
56
                        &api.Info{
59
59
                                Tag:      names.NewUserTag("admin"),
60
60
                                Password: "secret",
61
61
                        },
62
 
                        api.DialOpts{},
 
62
                        migration.ControllerDialOpts(),
63
63
                },
64
64
        }
65
 
        apiOpenCallModel = jujutesting.StubCall{
 
65
        apiOpenModelCall = jujutesting.StubCall{
66
66
                "apiOpen",
67
67
                []interface{}{
68
68
                        &api.Info{
72
72
                                Password: "secret",
73
73
                                ModelTag: modelTag,
74
74
                        },
75
 
                        api.DialOpts{},
 
75
                        migration.ControllerDialOpts(),
76
76
                },
77
77
        }
78
78
        importCall = jujutesting.StubCall{
84
84
        activateCall = jujutesting.StubCall{
85
85
                "MigrationTarget.Activate",
86
86
                []interface{}{
87
 
                        params.ModelArgs{ModelTag: modelTagString},
 
87
                        params.ModelArgs{ModelTag: modelTag.String()},
88
88
                },
89
89
        }
90
 
        connCloseCall = jujutesting.StubCall{"Connection.Close", nil}
91
 
        abortCall     = jujutesting.StubCall{
 
90
        apiCloseCall = jujutesting.StubCall{"Connection.Close", nil}
 
91
        abortCall    = jujutesting.StubCall{
92
92
                "MigrationTarget.Abort",
93
93
                []interface{}{
94
 
                        params.ModelArgs{ModelTag: modelTagString},
 
94
                        params.ModelArgs{ModelTag: modelTag.String()},
95
95
                },
96
96
        }
97
97
        watchStatusLockdownCalls = []jujutesting.StubCall{
102
102
        prechecksCalls = []jujutesting.StubCall{
103
103
                {"facade.Prechecks", nil},
104
104
                {"facade.ModelInfo", nil},
105
 
                apiOpenCallController,
 
105
                apiOpenControllerCall,
106
106
                {"MigrationTarget.Prechecks", []interface{}{params.MigrationModelInfo{
107
107
                        UUID:         modelUUID,
108
108
                        Name:         modelName,
109
109
                        OwnerTag:     ownerTag.String(),
110
110
                        AgentVersion: modelVersion,
111
111
                }}},
112
 
                connCloseCall,
 
112
                apiCloseCall,
113
113
        }
114
114
        abortCalls = []jujutesting.StubCall{
115
115
                {"facade.SetPhase", []interface{}{coremigration.ABORT}},
116
 
                apiOpenCallController,
 
116
                apiOpenControllerCall,
117
117
                abortCall,
118
 
                connCloseCall,
 
118
                apiCloseCall,
119
119
                {"facade.SetPhase", []interface{}{coremigration.ABORTDONE}},
120
120
        }
121
121
)
125
125
 
126
126
        s.clock = jujutesting.NewClock(time.Now())
127
127
        s.stub = new(jujutesting.Stub)
128
 
        s.connection = &stubConnection{stub: s.stub}
 
128
        s.connection = &stubConnection{
 
129
                stub:          s.stub,
 
130
                controllerTag: targetControllerTag,
 
131
        }
129
132
        s.connectionErr = nil
130
133
 
131
134
        s.facade = newStubMasterFacade(s.stub, s.clock.Now())
159
162
                Phase:            phase,
160
163
                PhaseChangedTime: s.clock.Now(),
161
164
                TargetInfo: coremigration.TargetInfo{
162
 
                        ControllerTag: names.NewModelTag("controller-uuid"),
 
165
                        ControllerTag: targetControllerTag,
163
166
                        Addrs:         []string{"1.2.3.4:5"},
164
167
                        CACert:        "cert",
165
168
                        AuthTag:       names.NewUserTag("admin"),
193
196
 
194
197
                        //IMPORT
195
198
                        {"facade.Export", nil},
196
 
                        apiOpenCallController,
 
199
                        apiOpenControllerCall,
197
200
                        importCall,
198
 
                        apiOpenCallModel,
 
201
                        apiOpenModelCall,
199
202
                        {"UploadBinaries", []interface{}{
200
203
                                []string{"charm0", "charm1"},
201
204
                                fakeCharmDownloader,
204
207
                                },
205
208
                                fakeToolsDownloader,
206
209
                        }},
207
 
                        connCloseCall, // for target model
208
 
                        connCloseCall, // for target controller
 
210
                        apiCloseCall, // for target model
 
211
                        apiCloseCall, // for target controller
209
212
                        {"facade.SetPhase", []interface{}{coremigration.VALIDATION}},
210
213
 
211
214
                        // VALIDATION
212
215
                        {"facade.WatchMinionReports", nil},
213
216
                        {"facade.MinionReports", nil},
214
 
                        apiOpenCallController,
 
217
                        apiOpenControllerCall,
215
218
                        activateCall,
216
 
                        connCloseCall,
 
219
                        apiCloseCall,
217
220
                        {"facade.SetPhase", []interface{}{coremigration.SUCCESS}},
218
221
 
219
222
                        // SUCCESS
357
360
        ))
358
361
}
359
362
 
 
363
func (s *Suite) TestQUIESCEWrongController(c *gc.C) {
 
364
        s.facade.queueStatus(s.makeStatus(coremigration.QUIESCE))
 
365
        s.connection.controllerTag = names.NewControllerTag("another-controller")
 
366
 
 
367
        s.checkWorkerReturns(c, migrationmaster.ErrInactive)
 
368
        s.stub.CheckCalls(c, joinCalls(
 
369
                watchStatusLockdownCalls,
 
370
                []jujutesting.StubCall{
 
371
                        {"facade.Prechecks", nil},
 
372
                        {"facade.ModelInfo", nil},
 
373
                        apiOpenControllerCall,
 
374
                        apiCloseCall,
 
375
                },
 
376
                abortCalls,
 
377
        ))
 
378
}
 
379
 
360
380
func (s *Suite) TestQUIESCESourceChecksFail(c *gc.C) {
361
381
        s.facade.queueStatus(s.makeStatus(coremigration.QUIESCE))
362
382
        s.facade.prechecksErr = errors.New("boom")
419
439
                watchStatusLockdownCalls,
420
440
                []jujutesting.StubCall{
421
441
                        {"facade.Export", nil},
422
 
                        apiOpenCallController,
 
442
                        apiOpenControllerCall,
423
443
                        {"facade.SetPhase", []interface{}{coremigration.ABORT}},
424
 
                        apiOpenCallController,
 
444
                        apiOpenControllerCall,
425
445
                        {"facade.SetPhase", []interface{}{coremigration.ABORTDONE}},
426
446
                },
427
447
        ))
436
456
                watchStatusLockdownCalls,
437
457
                []jujutesting.StubCall{
438
458
                        {"facade.Export", nil},
439
 
                        apiOpenCallController,
 
459
                        apiOpenControllerCall,
440
460
                        importCall,
441
 
                        connCloseCall,
 
461
                        apiCloseCall,
442
462
                },
443
463
                abortCalls,
444
464
        ))
614
634
                                                Tag:       names.NewUserTag("admin"),
615
635
                                                Macaroons: macs, // <---
616
636
                                        },
617
 
                                        api.DialOpts{},
 
637
                                        migration.ControllerDialOpts(),
618
638
                                },
619
639
                        },
620
640
                        abortCall,
621
 
                        connCloseCall,
 
641
                        apiCloseCall,
622
642
                        {"facade.SetPhase", []interface{}{coremigration.ABORTDONE}},
623
643
                },
624
644
        ))
903
923
 
904
924
type stubConnection struct {
905
925
        api.Connection
906
 
        stub         *jujutesting.Stub
907
 
        prechecksErr error
908
 
        importErr    error
 
926
        stub          *jujutesting.Stub
 
927
        prechecksErr  error
 
928
        importErr     error
 
929
        controllerTag names.ControllerTag
909
930
}
910
931
 
911
932
func (c *stubConnection) BestFacadeVersion(string) int {
939
960
        return nil
940
961
}
941
962
 
 
963
func (c *stubConnection) ControllerTag() names.ControllerTag {
 
964
        return c.controllerTag
 
965
}
 
966
 
942
967
func makeStubUploadBinaries(stub *jujutesting.Stub) func(migration.UploadBinariesConfig) error {
943
968
        return func(config migration.UploadBinariesConfig) error {
944
969
                stub.AddCall(