Skip to content

Commit

Permalink
Merge pull request #82 from hmlanigan/machine_pr81
Browse files Browse the repository at this point in the history
#82

Allow machines without pools to be properly parsed. Make changes for machines, as done for devices in #81 .
  • Loading branch information
jujubot authored Aug 26, 2019
2 parents 7f9373c + 5cac788 commit 0ab1eb6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 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
3 changes: 1 addition & 2 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var poolDeserializationFuncs = map[version.Number]poolDeserializationFunc{
}

func pool_2_0(source map[string]interface{}) (*pool, error) {
fields := schema.Fields {
fields := schema.Fields{
"name": schema.String(),
"description": schema.String(),
"resource_uri": schema.String(),
Expand All @@ -103,4 +103,3 @@ func pool_2_0(source map[string]interface{}) (*pool, error) {
}
return result, nil
}

1 change: 0 additions & 1 deletion pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,3 @@ var poolResponse = `
}
]
`

0 comments on commit 0ab1eb6

Please sign in to comment.