Skip to content

Commit

Permalink
Allow machines without pools to be properly parsed.
Browse files Browse the repository at this point in the history
  • Loading branch information
hmlanigan committed Aug 26, 2019
1 parent 7f9373c commit a10219a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 6 additions & 5 deletions machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ func machine_2_0(source map[string]interface{}) (*machine, error) {
"boot_interface": schema.OneOf(schema.Nil(""), schema.StringMap(schema.Any())),
"interface_set": schema.List(schema.StringMap(schema.Any())),
"zone": schema.StringMap(schema.Any()),
"pool": schema.StringMap(schema.Any()),
"pool": schema.OneOf(schema.Nil(""), schema.Any()),

"physicalblockdevice_set": schema.List(schema.StringMap(schema.Any())),
"blockdevice_set": schema.List(schema.StringMap(schema.Any())),
Expand Down Expand Up @@ -556,10 +556,11 @@ func machine_2_0(source map[string]interface{}) (*machine, error) {
return nil, errors.Trace(err)
}

pool, err := pool_2_0(valid["pool"].(map[string]interface{}))
if err != nil {

return nil, errors.Trace(err)
var pool *pool
if valid["pool"] != nil {
if pool, err = pool_2_0(valid["pool"].(map[string]interface{})); err != nil {
return nil, errors.Trace(err)
}
}

physicalBlockDevices, err := readBlockDeviceList(valid["physicalblockdevice_set"].([]interface{}), blockdevice_2_0)
Expand Down
6 changes: 6 additions & 0 deletions machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func (*machineSuite) TestReadMachines(c *gc.C) {
id = blockDevices[0].ID()
c.Assert(machine.PhysicalBlockDevice(id), jc.DeepEquals, blockDevices[0])
c.Assert(machine.PhysicalBlockDevice(id+5), gc.IsNil)

pool := machine.Pool()
c.Check(pool, gc.NotNil)
c.Check(pool.Name(), gc.Equals, "default")
}

func (*machineSuite) TestReadMachinesNilValues(c *gc.C) {
Expand All @@ -102,13 +106,15 @@ func (*machineSuite) TestReadMachinesNilValues(c *gc.C) {
data["architecture"] = nil
data["status_message"] = nil
data["boot_interface"] = nil
data["pool"] = nil
machines, err := readMachines(twoDotOh, json)
c.Assert(err, jc.ErrorIsNil)
c.Assert(machines, gc.HasLen, 3)
machine := machines[0]
c.Check(machine.Architecture(), gc.Equals, "")
c.Check(machine.StatusMessage(), gc.Equals, "")
c.Check(machine.BootInterface(), gc.IsNil)
c.Check(machine.Pool(), gc.IsNil)
}

func (*machineSuite) TestLowVersion(c *gc.C) {
Expand Down

0 comments on commit a10219a

Please sign in to comment.