~dstroppa/juju-core/joyent-provider-storage

« back to all changes in this revision

Viewing changes to state/api/provisioner/provisioner_test.go

  • Committer: Daniele Stroppa
  • Date: 2014-01-08 15:58:10 UTC
  • mfrom: (1953.1.231 juju-core)
  • Revision ID: daniele.stroppa@joyent.com-20140108155810-xecbwrqkb5i0fyoe
Merging trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
202
202
 
203
203
func (s *provisionerSuite) TestConstraints(c *gc.C) {
204
204
        // Create a fresh machine with some constraints.
205
 
        args := state.AddMachineParams{
 
205
        template := state.MachineTemplate{
206
206
                Series:      "quantal",
207
207
                Jobs:        []state.MachineJob{state.JobHostUnits},
208
208
                Constraints: constraints.MustParse("cpu-cores=12", "mem=8G"),
209
209
        }
210
 
        consMachine, err := s.State.AddMachineWithConstraints(&args)
 
210
        consMachine, err := s.State.AddOneMachine(template)
211
211
        c.Assert(err, gc.IsNil)
212
212
 
213
213
        apiMachine, err := s.provisioner.Machine(consMachine.Tag())
214
214
        c.Assert(err, gc.IsNil)
215
215
        cons, err := apiMachine.Constraints()
216
216
        c.Assert(err, gc.IsNil)
217
 
        c.Assert(cons, gc.DeepEquals, args.Constraints)
 
217
        c.Assert(cons, gc.DeepEquals, template.Constraints)
218
218
 
219
219
        // Now try machine 0.
220
220
        apiMachine, err = s.provisioner.Machine(s.machine.Tag())
229
229
        c.Assert(err, gc.IsNil)
230
230
 
231
231
        // Add one LXC container.
232
 
        args := state.AddMachineParams{
233
 
                Series:        "quantal",
234
 
                ParentId:      s.machine.Id(),
235
 
                Jobs:          []state.MachineJob{state.JobHostUnits},
236
 
                ContainerType: instance.LXC,
 
232
        template := state.MachineTemplate{
 
233
                Series: "quantal",
 
234
                Jobs:   []state.MachineJob{state.JobHostUnits},
237
235
        }
238
 
        container, err := s.State.AddMachineWithConstraints(&args)
 
236
        container, err := s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.LXC)
239
237
        c.Assert(err, gc.IsNil)
240
238
 
241
239
        w, err := apiMachine.WatchContainers(instance.LXC)
253
251
        wc.AssertNoChange()
254
252
 
255
253
        // Add a KVM container and make sure it's not detected.
256
 
        args.ContainerType = instance.KVM
257
 
        container, err = s.State.AddMachineWithConstraints(&args)
 
254
        container, err = s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.KVM)
258
255
        c.Assert(err, gc.IsNil)
259
256
        wc.AssertNoChange()
260
257
 
261
258
        // Add another LXC container and make sure it's detected.
262
 
        args.ContainerType = instance.LXC
263
 
        container, err = s.State.AddMachineWithConstraints(&args)
 
259
        container, err = s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.LXC)
264
260
        c.Assert(err, gc.IsNil)
265
261
        wc.AssertChange(container.Id())
266
262
 
268
264
        wc.AssertClosed()
269
265
}
270
266
 
 
267
func (s *provisionerSuite) TestWatchContainersAcceptsSupportedContainers(c *gc.C) {
 
268
        apiMachine, err := s.provisioner.Machine(s.machine.Tag())
 
269
        c.Assert(err, gc.IsNil)
 
270
 
 
271
        for _, ctype := range instance.ContainerTypes {
 
272
                w, err := apiMachine.WatchContainers(ctype)
 
273
                c.Assert(w, gc.NotNil)
 
274
                c.Assert(err, gc.IsNil)
 
275
        }
 
276
}
 
277
 
 
278
func (s *provisionerSuite) TestWatchContainersErrors(c *gc.C) {
 
279
        apiMachine, err := s.provisioner.Machine(s.machine.Tag())
 
280
        c.Assert(err, gc.IsNil)
 
281
 
 
282
        _, err = apiMachine.WatchContainers(instance.NONE)
 
283
        c.Assert(err, gc.ErrorMatches, `unsupported container type "none"`)
 
284
 
 
285
        _, err = apiMachine.WatchContainers("")
 
286
        c.Assert(err, gc.ErrorMatches, "container type must be specified")
 
287
}
 
288
 
271
289
func (s *provisionerSuite) TestWatchEnvironMachines(c *gc.C) {
272
290
        w, err := s.provisioner.WatchEnvironMachines()
273
291
        c.Assert(err, gc.IsNil)
290
308
        wc.AssertChange("2")
291
309
 
292
310
        // Add a container and make sure it's not detected.
293
 
        args := state.AddMachineParams{
294
 
                Series:        "quantal",
295
 
                ParentId:      s.machine.Id(),
296
 
                Jobs:          []state.MachineJob{state.JobHostUnits},
297
 
                ContainerType: instance.LXC,
 
311
        template := state.MachineTemplate{
 
312
                Series: "quantal",
 
313
                Jobs:   []state.MachineJob{state.JobHostUnits},
298
314
        }
299
 
        _, err = s.State.AddMachineWithConstraints(&args)
 
315
        _, err = s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.LXC)
300
316
        c.Assert(err, gc.IsNil)
301
317
        wc.AssertNoChange()
302
318
 
330
346
        attrs["type"] = "blah"
331
347
        newConfig, err := config.New(config.NoDefaults, attrs)
332
348
        c.Assert(err, gc.IsNil)
333
 
        err = s.State.SetEnvironConfig(newConfig)
 
349
        err = s.State.SetEnvironConfig(newConfig, envConfig)
334
350
        c.Assert(err, gc.IsNil)
335
351
        wc.AssertOneChange()
336
352
 
337
353
        // Change it back to the original config.
338
 
        err = s.State.SetEnvironConfig(envConfig)
 
354
        err = s.State.SetEnvironConfig(envConfig, newConfig)
339
355
        c.Assert(err, gc.IsNil)
340
356
        wc.AssertOneChange()
341
357
 
377
393
        c.Assert(result.ProviderType, gc.Equals, "dummy")
378
394
        c.Assert(result.AuthorizedKeys, gc.Equals, "my-keys")
379
395
        c.Assert(result.SSLHostnameVerification, jc.IsTrue)
 
396
        c.Assert(result.SyslogPort, gc.Equals, 2345)
380
397
}
381
398
 
382
399
func (s *provisionerSuite) TestCACert(c *gc.C) {
405
422
        c.Assert(stateTools.URL, gc.Not(gc.Equals), "")
406
423
}
407
424
 
408
 
func (s *provisionerSuite) TestAddSupportedContainers(c *gc.C) {
 
425
func (s *provisionerSuite) TestSetSupportedContainers(c *gc.C) {
409
426
        apiMachine, err := s.provisioner.Machine(s.machine.Tag())
410
427
        c.Assert(err, gc.IsNil)
411
 
        err = apiMachine.AddSupportedContainers(instance.LXC, instance.KVM)
 
428
        err = apiMachine.SetSupportedContainers(instance.LXC, instance.KVM)
412
429
        c.Assert(err, gc.IsNil)
413
430
 
414
431
        err = s.machine.Refresh()
417
434
        c.Assert(ok, jc.IsTrue)
418
435
        c.Assert(containers, gc.DeepEquals, []instance.ContainerType{instance.LXC, instance.KVM})
419
436
}
 
437
 
 
438
func (s *provisionerSuite) TestSupportsNoContainers(c *gc.C) {
 
439
        apiMachine, err := s.provisioner.Machine(s.machine.Tag())
 
440
        c.Assert(err, gc.IsNil)
 
441
        err = apiMachine.SupportsNoContainers()
 
442
        c.Assert(err, gc.IsNil)
 
443
 
 
444
        err = s.machine.Refresh()
 
445
        c.Assert(err, gc.IsNil)
 
446
        containers, ok := s.machine.SupportedContainers()
 
447
        c.Assert(ok, jc.IsTrue)
 
448
        c.Assert(containers, gc.DeepEquals, []instance.ContainerType{})
 
449
}