forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setmodels_test.go
189 lines (164 loc) · 6.48 KB
/
setmodels_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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Copyright 2017 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package jujuclient_test
import (
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/juju/core/model"
"github.com/juju/juju/jujuclient"
"github.com/juju/juju/testing"
)
type SetModelsSuite struct {
testing.FakeJujuXDGDataHomeSuite
store jujuclient.ClientStore
controllerName string
controller jujuclient.ControllerDetails
}
var _ = gc.Suite(&SetModelsSuite{})
func (s *SetModelsSuite) SetUpTest(c *gc.C) {
s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
s.store = jujuclient.NewFileClientStore()
s.controllerName = "test.controller"
s.controller = jujuclient.ControllerDetails{
ControllerUUID: "test.uuid",
APIEndpoints: []string{"test.api.endpoint"},
CACert: "test.ca.cert",
Cloud: "aws",
CloudRegion: "southeastasia",
}
err := s.store.AddController(s.controllerName, s.controller)
c.Assert(err, jc.ErrorIsNil)
_, err = s.store.AllModels(s.controllerName)
c.Assert(err, gc.ErrorMatches, "models for controller test.controller not found")
}
func (s *SetModelsSuite) TearDownTest(c *gc.C) {
s.controller = jujuclient.ControllerDetails{}
s.controllerName = ""
s.store = nil
s.FakeJujuXDGDataHomeSuite.TearDownTest(c)
}
func (s *SetModelsSuite) TestSetModelsUnknownController(c *gc.C) {
err := s.store.SetModels("some-kontroller-not-in-store", nil)
c.Assert(err, jc.ErrorIsNil)
}
func (s *SetModelsSuite) TestSetModelsNoControllerModels(c *gc.C) {
err := s.store.SetModels(s.controllerName, nil)
c.Assert(err, jc.ErrorIsNil)
_, err = s.store.AllModels(s.controllerName)
c.Assert(err, gc.ErrorMatches, "models for controller test.controller not found")
}
func (s *SetModelsSuite) TestSetModelsAddOne(c *gc.C) {
modelDetails := s.assertUpdateModel(c, "admin/new-model", "test.model.uuid")
expected := map[string]jujuclient.ModelDetails{"admin/new-model": modelDetails}
s.assertSetModels(c, expected)
}
func (s *SetModelsSuite) TestSetModelsAddMany(c *gc.C) {
expected := map[string]jujuclient.ModelDetails{
"admin/new-model": s.assertUpdateModel(c, "admin/new-model", "test.model.uuid"),
"admin/another-model": s.assertUpdateModel(c, "admin/another-model", "test.model.uuid.2"),
}
s.assertSetModels(c, expected)
}
func (s *SetModelsSuite) TestControllerModelsUpdate(c *gc.C) {
expected := map[string]jujuclient.ModelDetails{
"admin/new-model": s.assertUpdateModel(c, "admin/new-model", "test.model.uuid"),
"admin/another-model": s.assertUpdateModel(c, "admin/another-model", "test.model.uuid.2"),
}
s.assertSetModels(c, expected)
// Make another call to ensure that we still have the same models information.
s.assertSetModels(c, expected)
}
func (s *SetModelsSuite) TestSetModelsDeleteOne(c *gc.C) {
detailsToLeave := s.assertUpdateModel(c, "admin/new-model", "test.model.uuid")
before := map[string]jujuclient.ModelDetails{
"admin/new-model": detailsToLeave,
"admin/another-model": s.assertUpdateModel(c, "admin/another-model", "test.model.uuid.2"),
}
after := map[string]jujuclient.ModelDetails{
"admin/new-model": detailsToLeave,
}
storedModels, err := s.store.AllModels(s.controllerName)
c.Assert(err, jc.ErrorIsNil)
c.Assert(storedModels, gc.DeepEquals, before)
s.assertSetModels(c, after)
}
func (s *SetModelsSuite) TestSetModelsDeleteAll(c *gc.C) {
before := map[string]jujuclient.ModelDetails{
"admin/new-model": s.assertUpdateModel(c, "admin/new-model", "test.model.uuid"),
"admin/another-model": s.assertUpdateModel(c, "admin/another-model", "test.model.uuid.2"),
}
storedModels, err := s.store.AllModels(s.controllerName)
c.Assert(err, jc.ErrorIsNil)
c.Assert(storedModels, gc.DeepEquals, before)
s.assertSetModels(c, nil)
}
func (s *SetModelsSuite) TestSetModelsAddUpdateDeleteCombination(c *gc.C) {
detailsToUpdate := s.assertUpdateModel(c, "admin/update-model", "test.model.uuid.2")
before := map[string]jujuclient.ModelDetails{
"admin/delete-model": s.assertUpdateModel(c, "admin/delete-model", "test.model.uuid"),
"admin/update-model": detailsToUpdate,
}
after := map[string]jujuclient.ModelDetails{
"admin/new-model": {
ModelUUID: "test.model.uuid",
ModelType: model.IAAS,
ActiveBranch: model.GenerationMaster,
},
"admin/update-model": detailsToUpdate,
}
storedModels, err := s.store.AllModels(s.controllerName)
c.Assert(err, jc.ErrorIsNil)
c.Assert(storedModels, gc.DeepEquals, before)
s.assertSetModels(c, after)
}
func (s *SetModelsSuite) TestSetModelsDoesNotUpdateCurrentModel(c *gc.C) {
before := map[string]jujuclient.ModelDetails{
"admin/delete-model": s.assertUpdateModel(c, "admin/delete-model", "test.model.uuid"),
}
s.store.SetCurrentModel(s.controllerName, "admin/delete-model")
storedModels, err := s.store.AllModels(s.controllerName)
c.Assert(err, jc.ErrorIsNil)
c.Assert(storedModels, gc.DeepEquals, before)
s.assertSetModels(c, nil)
currentModel, err := s.store.CurrentModel(s.controllerName)
c.Assert(err, jc.ErrorIsNil)
c.Assert(currentModel, gc.DeepEquals, "admin/delete-model")
}
func (s *SetModelsSuite) TestSetModelsControllerIsolated(c *gc.C) {
before := map[string]jujuclient.ModelDetails{
"admin/new-model": s.assertUpdateModel(c, "admin/new-model", "test.model.uuid"),
}
s.controller.ControllerUUID = "another.test.kontroller.uuid"
err := s.store.AddController("another-kontroller", s.controller)
c.Assert(err, jc.ErrorIsNil)
otherModels := map[string]jujuclient.ModelDetails{
"admin/foreign-model": {
ModelUUID: "test.foreign.model.uuid",
ModelType: model.IAAS,
ActiveBranch: model.GenerationMaster,
},
}
err = s.store.SetModels("another-kontroller", otherModels)
c.Assert(err, jc.ErrorIsNil)
// initial controller un-touched
storedModels, err := s.store.AllModels(s.controllerName)
c.Assert(err, jc.ErrorIsNil)
c.Assert(storedModels, gc.DeepEquals, before)
}
func (s *SetModelsSuite) assertSetModels(c *gc.C, models map[string]jujuclient.ModelDetails) {
err := s.store.SetModels(s.controllerName, models)
c.Assert(err, jc.ErrorIsNil)
storedModels, err := s.store.AllModels(s.controllerName)
c.Assert(err, jc.ErrorIsNil)
c.Assert(storedModels, gc.DeepEquals, models)
}
func (s *SetModelsSuite) assertUpdateModel(c *gc.C, modelName, modelUUID string) jujuclient.ModelDetails {
modelDetails := jujuclient.ModelDetails{
ModelUUID: modelUUID,
ModelType: model.IAAS,
ActiveBranch: model.GenerationMaster,
}
err := s.store.UpdateModel(s.controllerName, modelName, modelDetails)
c.Assert(err, jc.ErrorIsNil)
return modelDetails
}