Merge lp:~rogpeppe/juju-core/453-maas-instance-uuid into lp:~go-bot/juju-core/trunk

Proposed by Roger Peppe
Status: Merged
Approved by: Roger Peppe
Approved revision: no longer in the source branch.
Merged at revision: 1990
Proposed branch: lp:~rogpeppe/juju-core/453-maas-instance-uuid
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 323 lines (+76/-57)
9 files modified
provider/maas/config.go (+12/-6)
provider/maas/config_test.go (+23/-7)
provider/maas/environ.go (+2/-2)
provider/maas/environ_test.go (+2/-2)
provider/maas/environprovider.go (+12/-15)
provider/maas/environprovider_test.go (+11/-11)
provider/maas/maas_test.go (+6/-6)
provider/maas/storage.go (+2/-2)
provider/maas/storage_test.go (+6/-6)
To merge this branch: bzr merge lp:~rogpeppe/juju-core/453-maas-instance-uuid
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+191367@code.launchpad.net

Commit message

provider/maas: do not use environ-uuid

As pointed out by fwereade, it could be
confusing to have two things in the system
that both purport to be a uuid for the environ.

Also make the MAAS EnvironProvider.Validate
check that we're not changing the maas-agent-name.

https://codereview.appspot.com/14741045/

Description of the change

provider/maas: do not use environ-uuid

As pointed out by fwereade, it could be
confusing to have two things in the system
that both purport to be a uuid for the environ.

Also make the MAAS EnvironProvider.Validate
check that we're not changing the maas-instance-uuid.

https://codereview.appspot.com/14741045/

To post a comment you must log in.
Revision history for this message
Roger Peppe (rogpeppe) wrote :
Download full text (7.9 KiB)

Reviewers: mp+191367_code.launchpad.net,

Message:
Please take a look.

Description:
provider/maas: do not use environ-uuid

As pointed out by fwereade, it could be
confusing to have two things in the system
that both purport to be a uuid for the environ.

Also make the MAAS EnvironProvider.Validate
check that we're not changing the maas-instance-uuid.

https://code.launchpad.net/~rogpeppe/juju-core/453-maas-instance-uuid/+merge/191367

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/14741045/

Affected files (+58, -37 lines):
   A [revision details]
   M provider/maas/config.go
   M provider/maas/config_test.go
   M provider/maas/environprovider.go
   M provider/maas/environprovider_test.go
   M provider/maas/maas_test.go
   M provider/maas/storage_test.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-20131016061150-dqoy06taxa0edywm
+New revision: <email address hidden>

Index: provider/maas/config.go
=== modified file 'provider/maas/config.go'
--- provider/maas/config.go 2013-10-15 16:18:32 +0000
+++ provider/maas/config.go 2013-10-16 10:29:29 +0000
@@ -18,14 +18,14 @@
   // maas-oauth is a colon-separated triplet of:
   // consumer-key:resource-token:resource-secret
   "maas-oauth": schema.String(),
- // environment-uuid is an optional UUID to group the machines
+ // maas-instance-uuid is an optional UUID to group the instances
   // acquired from MAAS, to support multiple environments per MAAS user.
- "environment-uuid": schema.String(),
+ "maas-instance-uuid": schema.String(),
  }
  var configDefaults = schema.Defaults{
- // For backward-compatibility, environment-uuid is the empty string
+ // For backward-compatibility, maas-instance-uuid is the empty string
   // by default. However, new environments should all use a UUID.
- "environment-uuid": "",
+ "maas-instance-uuid": "",
  }

  type maasEnvironConfig struct {
@@ -42,7 +42,7 @@
  }

  func (cfg *maasEnvironConfig) maasEnvironmentUUID() string {
- if uuid, ok := cfg.attrs["environment-uuid"].(string); ok {
+ if uuid, ok := cfg.attrs["maas-instance-uuid"].(string); ok {
    return uuid
   }
   return ""
@@ -72,6 +72,12 @@
   if err != nil {
    return nil, err
   }
+ if oldCfg != nil {
+ oldAttrs := oldCfg.UnknownAttrs()
+ if validated["maas-instance-uuid"] != oldAttrs["maas-instance-uuid"] {
+ return nil, fmt.Errorf("cannot change maas-instance-uuid")
+ }
+ }
   envCfg := new(maasEnvironConfig)
   envCfg.Config = cfg
   envCfg.attrs = validated

Index: provider/maas/config_test.go
=== modified file 'provider/maas/config_test.go'
--- provider/maas/config_test.go 2013-10-15 16:52:58 +0000
+++ provider/maas/config_test.go 2013-10-16 10:42:01 +0000
@@ -47,10 +47,10 @@
   uuid, err := utils.NewUUID()
   c.Assert(err, gc.IsNil)
   ecfg, err := newConfig(map[string]interface{}{
- "maas-server": server,
- "maas-oauth": oauth,
- "environment-uuid": uuid.String(),
- "future-key": future,
+ "maas-server": server,
+ "ma...

Read more...

Revision history for this message
Martin Packman (gz) wrote :

LGTM. We will need to be careful when we fiddle with this mechanism in
future to make sure upgrades don't start using a new name for instances
as it needs to be stable across the lifetime of the environment.

https://codereview.appspot.com/14741045/

Revision history for this message
Nate Finch (natefinch) wrote :

LGTM, although I'd prefer if someone factored out all the magic strings.

https://codereview.appspot.com/14741045/

Revision history for this message
Roger Peppe (rogpeppe) wrote :
Revision history for this message
Roger Peppe (rogpeppe) wrote :
Revision history for this message
Raphaël Badin (rvb) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'provider/maas/config.go'
2--- provider/maas/config.go 2013-10-15 16:18:32 +0000
3+++ provider/maas/config.go 2013-10-16 12:45:44 +0000
4@@ -18,14 +18,14 @@
5 // maas-oauth is a colon-separated triplet of:
6 // consumer-key:resource-token:resource-secret
7 "maas-oauth": schema.String(),
8- // environment-uuid is an optional UUID to group the machines
9+ // maas-agent-name is an optional UUID to group the instances
10 // acquired from MAAS, to support multiple environments per MAAS user.
11- "environment-uuid": schema.String(),
12+ "maas-agent-name": schema.String(),
13 }
14 var configDefaults = schema.Defaults{
15- // For backward-compatibility, environment-uuid is the empty string
16+ // For backward-compatibility, maas-agent-name is the empty string
17 // by default. However, new environments should all use a UUID.
18- "environment-uuid": "",
19+ "maas-agent-name": "",
20 }
21
22 type maasEnvironConfig struct {
23@@ -41,8 +41,8 @@
24 return cfg.attrs["maas-oauth"].(string)
25 }
26
27-func (cfg *maasEnvironConfig) maasEnvironmentUUID() string {
28- if uuid, ok := cfg.attrs["environment-uuid"].(string); ok {
29+func (cfg *maasEnvironConfig) maasAgentName() string {
30+ if uuid, ok := cfg.attrs["maas-agent-name"].(string); ok {
31 return uuid
32 }
33 return ""
34@@ -72,6 +72,12 @@
35 if err != nil {
36 return nil, err
37 }
38+ if oldCfg != nil {
39+ oldAttrs := oldCfg.UnknownAttrs()
40+ if validated["maas-agent-name"] != oldAttrs["maas-agent-name"] {
41+ return nil, fmt.Errorf("cannot change maas-agent-name")
42+ }
43+ }
44 envCfg := new(maasEnvironConfig)
45 envCfg.Config = cfg
46 envCfg.attrs = validated
47
48=== modified file 'provider/maas/config_test.go'
49--- provider/maas/config_test.go 2013-10-15 16:52:58 +0000
50+++ provider/maas/config_test.go 2013-10-16 12:45:44 +0000
51@@ -47,25 +47,25 @@
52 uuid, err := utils.NewUUID()
53 c.Assert(err, gc.IsNil)
54 ecfg, err := newConfig(map[string]interface{}{
55- "maas-server": server,
56- "maas-oauth": oauth,
57- "environment-uuid": uuid.String(),
58- "future-key": future,
59+ "maas-server": server,
60+ "maas-oauth": oauth,
61+ "maas-agent-name": uuid.String(),
62+ "future-key": future,
63 })
64 c.Assert(err, gc.IsNil)
65 c.Check(ecfg.maasServer(), gc.Equals, server)
66 c.Check(ecfg.maasOAuth(), gc.DeepEquals, oauth)
67- c.Check(ecfg.maasEnvironmentUUID(), gc.Equals, uuid.String())
68+ c.Check(ecfg.maasAgentName(), gc.Equals, uuid.String())
69 c.Check(ecfg.UnknownAttrs()["future-key"], gc.DeepEquals, future)
70 }
71
72-func (*configSuite) TestEnvironmentUUIDDefault(c *gc.C) {
73+func (*configSuite) TestMaasAgentNameDefault(c *gc.C) {
74 ecfg, err := newConfig(map[string]interface{}{
75 "maas-server": "http://maas.testing.invalid/maas/",
76 "maas-oauth": "consumer-key:resource-token:resource-secret",
77 })
78 c.Assert(err, gc.IsNil)
79- c.Check(ecfg.maasEnvironmentUUID(), gc.Equals, "")
80+ c.Check(ecfg.maasAgentName(), gc.Equals, "")
81 }
82
83 func (*configSuite) TestChecksWellFormedMaasServer(c *gc.C) {
84@@ -105,3 +105,19 @@
85 c.Assert(err, gc.NotNil)
86 c.Check(err, gc.ErrorMatches, ".*cannot change name.*")
87 }
88+
89+func (*configSuite) TestValidateCannotChangeAgentName(c *gc.C) {
90+ baseAttrs := map[string]interface{}{
91+ "maas-server": "http://maas.testing.invalid/maas/",
92+ "maas-oauth": "consumer-key:resource-token:resource-secret",
93+ "maas-agent-name": "1234-5678",
94+ }
95+ oldCfg, err := newConfig(baseAttrs)
96+ c.Assert(err, gc.IsNil)
97+ newCfg, err := oldCfg.Apply(map[string]interface{}{
98+ "maas-agent-name": "9876-5432",
99+ })
100+ c.Assert(err, gc.IsNil)
101+ _, err = maasEnvironProvider{}.Validate(newCfg, oldCfg.Config)
102+ c.Assert(err, gc.ErrorMatches, "cannot change maas-agent-name")
103+}
104
105=== modified file 'provider/maas/environ.go'
106--- provider/maas/environ.go 2013-10-15 16:09:23 +0000
107+++ provider/maas/environ.go 2013-10-16 12:45:44 +0000
108@@ -171,7 +171,7 @@
109 // acquireNode allocates a node from the MAAS.
110 func (environ *maasEnviron) acquireNode(cons constraints.Value, possibleTools tools.List) (gomaasapi.MAASObject, *tools.Tools, error) {
111 acquireParams := convertConstraints(cons)
112- acquireParams.Add("agent_name", environ.ecfg().maasEnvironmentUUID())
113+ acquireParams.Add("agent_name", environ.ecfg().maasAgentName())
114 var result gomaasapi.JSONObject
115 var err error
116 for a := shortAttempt.Start(); a.Next(); {
117@@ -323,7 +323,7 @@
118 func (environ *maasEnviron) instances(ids []instance.Id) ([]instance.Instance, error) {
119 nodeListing := environ.getMAASClient().GetSubObject("nodes")
120 filter := getSystemIdValues(ids)
121- filter.Add("agent_name", environ.ecfg().maasEnvironmentUUID())
122+ filter.Add("agent_name", environ.ecfg().maasAgentName())
123 listNodeObjects, err := nodeListing.CallGet("list", filter)
124 if err != nil {
125 return nil, err
126
127=== modified file 'provider/maas/environ_test.go'
128--- provider/maas/environ_test.go 2013-10-16 05:21:12 +0000
129+++ provider/maas/environ_test.go 2013-10-16 12:45:44 +0000
130@@ -310,7 +310,7 @@
131 c.Assert(nodeRequestValues[0].Get("mem"), gc.Equals, "1024")
132 }
133
134-func (suite *environSuite) TestAcquireNodePassedEnvironmentUUID(c *gc.C) {
135+func (suite *environSuite) TestAcquireNodePassedAgentName(c *gc.C) {
136 stor := NewStorage(suite.makeEnviron())
137 fakeTools := envtesting.MustUploadFakeToolsVersions(stor, version.Current)[0]
138 env := suite.makeEnviron()
139@@ -322,7 +322,7 @@
140 requestValues := suite.testMAASObject.TestServer.NodeOperationRequestValues()
141 nodeRequestValues, found := requestValues["node0"]
142 c.Assert(found, gc.Equals, true)
143- c.Assert(nodeRequestValues[0].Get("agent_name"), gc.Equals, exampleUUID)
144+ c.Assert(nodeRequestValues[0].Get("agent_name"), gc.Equals, exampleAgentName)
145 }
146
147 func (*environSuite) TestConvertConstraints(c *gc.C) {
148
149=== modified file 'provider/maas/environprovider.go'
150--- provider/maas/environprovider.go 2013-10-15 16:36:59 +0000
151+++ provider/maas/environprovider.go 2013-10-16 12:45:44 +0000
152@@ -38,24 +38,21 @@
153 return env, nil
154 }
155
156-var errUUIDAlreadySet = errors.New(
157- "environment-uuid is already set; this should not be set by hand")
158+var errAgentNameAlreadySet = errors.New(
159+ "maas-agent-name is already set; this should not be set by hand")
160
161 func (p maasEnvironProvider) Prepare(cfg *config.Config) (environs.Environ, error) {
162 attrs := cfg.UnknownAttrs()
163- uuid, found := attrs["environment-uuid"]
164- if found {
165- if uuid != "" {
166- return nil, errUUIDAlreadySet
167- }
168- } else {
169- uuid, err := utils.NewUUID()
170- if err != nil {
171- return nil, err
172- }
173- attrs["environment-uuid"] = uuid.String()
174- }
175- cfg, err := cfg.Apply(attrs)
176+ oldName, found := attrs["maas-agent-name"]
177+ if found && oldName != "" {
178+ return nil, errAgentNameAlreadySet
179+ }
180+ uuid, err := utils.NewUUID()
181+ if err != nil {
182+ return nil, err
183+ }
184+ attrs["maas-agent-name"] = uuid.String()
185+ cfg, err = cfg.Apply(attrs)
186 if err != nil {
187 return nil, err
188 }
189
190=== modified file 'provider/maas/environprovider_test.go'
191--- provider/maas/environprovider_test.go 2013-10-15 16:36:59 +0000
192+++ provider/maas/environprovider_test.go 2013-10-16 12:45:44 +0000
193@@ -11,6 +11,7 @@
194
195 "launchpad.net/juju-core/environs/config"
196 "launchpad.net/juju-core/testing"
197+ jc "launchpad.net/juju-core/testing/checkers"
198 "launchpad.net/juju-core/utils"
199 )
200
201@@ -39,7 +40,7 @@
202 c.Check(secretAttrs, gc.DeepEquals, expectedAttrs)
203 }
204
205-func (suite *EnvironProviderSuite) TestUnknownAttrsContainEnvironmentUUID(c *gc.C) {
206+func (suite *EnvironProviderSuite) TestUnknownAttrsContainAgentName(c *gc.C) {
207 testJujuHome := c.MkDir()
208 defer config.SetJujuHome(config.SetJujuHome(testJujuHome))
209 attrs := testing.FakeConfig().Merge(testing.Attrs{
210@@ -56,27 +57,26 @@
211 preparedConfig := environ.Config()
212 unknownAttrs := preparedConfig.UnknownAttrs()
213
214- uuid, ok := unknownAttrs["environment-uuid"]
215- c.Assert(ok, gc.Equals, true)
216+ uuid, ok := unknownAttrs["maas-agent-name"]
217
218- _, err = utils.UUIDFromString(uuid.(string))
219- c.Assert(err, gc.IsNil)
220+ c.Assert(ok, jc.IsTrue)
221+ c.Assert(uuid, jc.Satisfies, utils.IsValidUUIDString)
222 }
223
224-func (suite *EnvironProviderSuite) TestEnvironmentUUIDShouldNotBeSetByHand(c *gc.C) {
225+func (suite *EnvironProviderSuite) TestAgentNameShouldNotBeSetByHand(c *gc.C) {
226 testJujuHome := c.MkDir()
227 defer config.SetJujuHome(config.SetJujuHome(testJujuHome))
228 attrs := testing.FakeConfig().Merge(testing.Attrs{
229- "type": "maas",
230- "maas-oauth": "aa:bb:cc",
231- "maas-server": "http://maas.testing.invalid/maas/",
232- "environment-uuid": "foobar",
233+ "type": "maas",
234+ "maas-oauth": "aa:bb:cc",
235+ "maas-server": "http://maas.testing.invalid/maas/",
236+ "maas-agent-name": "foobar",
237 })
238 config, err := config.New(config.NoDefaults, attrs)
239 c.Assert(err, gc.IsNil)
240
241 _, err = suite.makeEnviron().Provider().Prepare(config)
242- c.Assert(err, gc.Equals, errUUIDAlreadySet)
243+ c.Assert(err, gc.Equals, errAgentNameAlreadySet)
244 }
245
246 // create a temporary file with the given content. The file will be cleaned
247
248=== modified file 'provider/maas/maas_test.go'
249--- provider/maas/maas_test.go 2013-10-15 16:52:58 +0000
250+++ provider/maas/maas_test.go 2013-10-16 12:45:44 +0000
251@@ -52,16 +52,16 @@
252 s.LoggingSuite.TearDownSuite(c)
253 }
254
255-const exampleUUID = "dfb69555-0bc4-4d1f-85f2-4ee390974984"
256+const exampleAgentName = "dfb69555-0bc4-4d1f-85f2-4ee390974984"
257
258 // makeEnviron creates a functional maasEnviron for a test.
259 func (suite *providerSuite) makeEnviron() *maasEnviron {
260 attrs := coretesting.FakeConfig().Merge(coretesting.Attrs{
261- "name": "test env",
262- "type": "maas",
263- "maas-oauth": "a:b:c",
264- "maas-server": suite.testMAASObject.TestServer.URL,
265- "environment-uuid": exampleUUID,
266+ "name": "test env",
267+ "type": "maas",
268+ "maas-oauth": "a:b:c",
269+ "maas-server": suite.testMAASObject.TestServer.URL,
270+ "maas-agent-name": exampleAgentName,
271 })
272 cfg, err := config.New(config.NoDefaults, attrs)
273 if err != nil {
274
275=== modified file 'provider/maas/storage.go'
276--- provider/maas/storage.go 2013-10-16 05:21:12 +0000
277+++ provider/maas/storage.go 2013-10-16 12:45:44 +0000
278@@ -91,10 +91,10 @@
279
280 // All filenames need to be namespaced so they are private to this environment.
281 // This prevents different environments from interfering with each other.
282-// We're using the environment's UUID here.
283+// We're using the agent name UUID here.
284 func (stor *maasStorage) prefixWithPrivateNamespace(name string) string {
285 env := stor.getSnapshot().environUnlocked
286- prefix := env.ecfg().maasEnvironmentUUID()
287+ prefix := env.ecfg().maasAgentName()
288 if prefix != "" {
289 return prefix + "-" + name
290 }
291
292=== modified file 'provider/maas/storage_test.go'
293--- provider/maas/storage_test.go 2013-10-16 05:21:12 +0000
294+++ provider/maas/storage_test.go 2013-10-16 12:45:44 +0000
295@@ -398,22 +398,22 @@
296 c.Assert(listing, gc.DeepEquals, []string{})
297 }
298
299-func (s *storageSuite) TestprefixWithPrivateNamespacePrefixesWithUUID(c *gc.C) {
300+func (s *storageSuite) TestprefixWithPrivateNamespacePrefixesWithAgentName(c *gc.C) {
301 sstor := NewStorage(s.makeEnviron())
302 stor := sstor.(*maasStorage)
303- uuid := stor.environUnlocked.ecfg().maasEnvironmentUUID()
304- c.Assert(uuid, gc.Not(gc.Equals), "")
305- expectedPrefix := uuid + "-"
306+ agentName := stor.environUnlocked.ecfg().maasAgentName()
307+ c.Assert(agentName, gc.Not(gc.Equals), "")
308+ expectedPrefix := agentName + "-"
309 const name = "myname"
310 expectedResult := expectedPrefix + name
311 c.Assert(stor.prefixWithPrivateNamespace(name), gc.Equals, expectedResult)
312 }
313
314-func (s *storageSuite) TesttprefixWithPrivateNamespaceIgnoresEmptyUUID(c *gc.C) {
315+func (s *storageSuite) TesttprefixWithPrivateNamespaceIgnoresAgentName(c *gc.C) {
316 sstor := NewStorage(s.makeEnviron())
317 stor := sstor.(*maasStorage)
318 ecfg := stor.environUnlocked.ecfg()
319- ecfg.attrs["environment-uuid"] = ""
320+ ecfg.attrs["maas-agent-name"] = ""
321
322 const name = "myname"
323 c.Assert(stor.prefixWithPrivateNamespace(name), gc.Equals, name)

Subscribers

People subscribed via source and target branches

to status/vote changes: