Update to latest gomaasapi for MAAS 2 work #5094

Merged
merged 10 commits into from Apr 13, 2016
View
@@ -20,7 +20,7 @@ github.com/juju/go4 git 40d72ab9641a2a8c36a9c46a51e28367115c8e59 2016-02-22T16:3
github.com/juju/gojsonpointer git afe8b77aa08f272b49e01b82de78510c11f61500 2015-02-04T19:46:29Z
github.com/juju/gojsonreference git f0d24ac5ee330baa21721cdff56d45e4ee42628e 2015-02-04T19:46:33Z
github.com/juju/gojsonschema git e1ad140384f254c82f89450d9a7c8dd38a632838 2015-03-12T17:00:16Z
-github.com/juju/gomaasapi git e7bc20c748a7194f20cdf0b6578e4797b3765faf 2016-04-04T03:37:13Z
+github.com/juju/gomaasapi git 87a4495f27a7876fed2bf2e6faf07cca1ea2e2da 2016-04-12T03:42:01Z
github.com/juju/govmomi git 4354a88d4b34abe467215f77c2fc1cb9f78b66f7 2015-04-24T01:54:48Z
github.com/juju/httpprof git 14bf14c307672fd2456bdbf35d19cf0ccd3cf565 2014-12-17T16:00:36Z
github.com/juju/httprequest git 89d547093c45e293599088cc63e805c6f1205dc0 2016-03-02T10:09:58Z
@@ -170,21 +170,29 @@ func addInterfaces(
return errors.Trace(err)
}
if len(combinedBindings) > 0 {
- params.Add("interfaces", strings.Join(combinedBindings, ";"))
+ combinedBindingsString := make([]string, len(combinedBindings))
+ for i, binding := range combinedBindings {
+ combinedBindingsString[i] = fmt.Sprintf("%s:space=%s", binding.Name, binding.SpaceProviderId)
+ }
+ params.Add("interfaces", strings.Join(combinedBindingsString, ";"))
}
if len(negatives) > 0 {
- params.Add("not_networks", strings.Join(negatives, ","))
+ negativesString := make([]string, len(negatives))
+ for i, binding := range negatives {
+ negativesString[i] = fmt.Sprintf("space:%s", binding.SpaceProviderId)
+ }
+ params.Add("not_networks", strings.Join(negativesString, ","))
}
return nil
}
func getBindings(
bindings []interfaceBinding,
positiveSpaces, negativeSpaces []network.SpaceInfo,
-) ([]string, []string, error) {
+) ([]interfaceBinding, []interfaceBinding, error) {
var (
index uint
- combinedBindings []string
+ combinedBindings []interfaceBinding
)
namesSet := set.NewStrings()
spacesSet := set.NewStrings()
@@ -206,8 +214,7 @@ func getBindings(
namesSet.Add(binding.Name)
spacesSet.Add(binding.SpaceProviderId)
- item := fmt.Sprintf("%s:space=%s", binding.Name, binding.SpaceProviderId)
- combinedBindings = append(combinedBindings, item)
+ combinedBindings = append(combinedBindings, binding)
}
for _, space := range positiveSpaces {
@@ -229,20 +236,32 @@ func getBindings(
index++
}
namesSet.Add(label)
- item := fmt.Sprintf("%s:space=%s", label, space.ProviderId)
- combinedBindings = append(combinedBindings, item)
+ combinedBindings = append(combinedBindings, interfaceBinding{label, string(space.ProviderId)})
index++
}
- var negatives []string
+ var negatives []interfaceBinding
for _, space := range negativeSpaces {
if spacesSet.Contains(string(space.ProviderId)) {
return nil, nil, errors.NewNotValid(nil, fmt.Sprintf(
"negative space %q from constraints clashes with interface bindings",
space.Name,
))
}
- negatives = append(negatives, fmt.Sprintf("space:%s", space.ProviderId))
+ var label string
+ for {
+ label = fmt.Sprintf("%v", index)
+ if !namesSet.Contains(label) {
+ break
+ }
+ if index > numericLabelLimit { // ...just to make sure we won't loop forever.
+ return nil, nil, errors.Errorf("too many conflicting numeric labels, giving up.")
+ }
+ index++
+ }
+ namesSet.Add(label)
+ negatives = append(negatives, interfaceBinding{label, string(space.ProviderId)})
+ index++
}
return combinedBindings, negatives, nil
}
@@ -258,12 +277,18 @@ func addInterfaces2(
}
if len(combinedBindings) > 0 {
- // TODO (mfoord): uncomment once gomaasapi supports the Interfaces
- // parameter
- //params.Interfaces = combinedBindings
+ interfaceSpecs := make([]gomaasapi.InterfaceSpec, len(combinedBindings))
+ for i, space := range combinedBindings {
+ interfaceSpecs[i] = gomaasapi.InterfaceSpec{space.Name, space.SpaceProviderId}
+ }
+ params.Interfaces = interfaceSpecs
}
if len(negatives) > 0 {
- params.NotNetworks = negatives
+ negativeStrings := make([]string, len(negatives))
+ for i, space := range negatives {
+ negativeStrings[i] = space.SpaceProviderId
+ }
+ params.NotSpace = negativeStrings
}
return nil
}
@@ -797,7 +797,8 @@ func (environ *maasEnviron) acquireNode2(
"no architecture was specified, acquiring an arbitrary node",
)
}
- machine, err := environ.maasController.AllocateMachine(acquireParams)
+ // Currently not using the constraints match returned here.
+ machine, _, err := environ.maasController.AllocateMachine(acquireParams)
if err != nil {
return nil, errors.Trace(err)
@@ -5,7 +5,6 @@ package maas
import (
"net/http"
- "strings"
"github.com/juju/errors"
"github.com/juju/gomaasapi"
@@ -374,7 +373,11 @@ func getFourSpaces() []gomaasapi.Space {
func (suite *maas2EnvironSuite) TestAcquireNodePassesPositiveAndNegativeSpaces(c *gc.C) {
expected := gomaasapi.AllocateMachineArgs{
- NotNetworks: []string{"space:6", "space:8"},
+ NotSpace: []string{"6", "8"},
+ Interfaces: []gomaasapi.InterfaceSpec{
+ {Label: "0", Space: "5"},
+ {Label: "1", Space: "7"},
+ },
}
env := suite.injectControllerWithSpacesAndCheck(c, getFourSpaces(), expected)
@@ -451,12 +454,13 @@ func (suite *maas2EnvironSuite) DONTTestAcquireNodeStorage(c *gc.C) {
func (suite *maas2EnvironSuite) TestAcquireNodeInterfaces(c *gc.C) {
var env *maasEnviron
var getNegatives func() []string
+ var getPositives func() []gomaasapi.InterfaceSpec
suite.injectController(&fakeController{
allocateMachineArgsCheck: func(args gomaasapi.AllocateMachineArgs) {
c.Assert(args, jc.DeepEquals, gomaasapi.AllocateMachineArgs{
- AgentName: env.ecfg().maasAgentName(),
- // Should have Interfaces too
- NotNetworks: getNegatives(),
+ AgentName: env.ecfg().maasAgentName(),
+ Interfaces: getPositives(),
+ NotSpace: getNegatives(),
})
},
allocateMachine: &fakeMachine{
@@ -474,26 +478,26 @@ func (suite *maas2EnvironSuite) TestAcquireNodeInterfaces(c *gc.C) {
// In the tests below "space:5" means foo, "space:6" means bar.
for i, test := range []struct {
interfaces []interfaceBinding
- expectedPositives string
- expectedNegatives string
+ expectedPositives []gomaasapi.InterfaceSpec
+ expectedNegatives []string
expectedError string
}{{ // without specified bindings, spaces constraints are used instead.
interfaces: nil,
- expectedPositives: "0:space=5",
- expectedNegatives: "space:3",
+ expectedPositives: []gomaasapi.InterfaceSpec{{"0", "2"}},
+ expectedNegatives: []string{"3"},
expectedError: "",
}, {
interfaces: []interfaceBinding{{"name-1", "space-1"}},
- expectedPositives: "name-1:space=space-1;0:space=5",
- expectedNegatives: "space:3",
+ expectedPositives: []gomaasapi.InterfaceSpec{{"name-1", "space-1"}, {"0", "2"}},
+ expectedNegatives: []string{"3"},
}, {
interfaces: []interfaceBinding{
{"name-1", "7"},
{"name-2", "8"},
{"name-3", "9"},
},
- expectedPositives: "name-1:space=1;name-2:space=2;name-3:space=3;0:space=5",
- expectedNegatives: "space:3",
+ expectedPositives: []gomaasapi.InterfaceSpec{{"name-1", "7"}, {"name-2", "8"}, {"name-3", "9"}, {"0", "2"}},
+ expectedNegatives: []string{"3"},
}, {
interfaces: []interfaceBinding{{"", "anything"}},
expectedError: "interface bindings cannot have empty names",
@@ -505,8 +509,8 @@ func (suite *maas2EnvironSuite) TestAcquireNodeInterfaces(c *gc.C) {
{"shared-db", "1"},
{"db", "1"},
},
- expectedPositives: "shared-db:space=1;db:space=1;0:space=5",
- expectedNegatives: "space:3",
+ expectedPositives: []gomaasapi.InterfaceSpec{{"shared-db", "1"}, {"db", "1"}, {"0", "2"}},
+ expectedNegatives: []string{"3"},
}, {
interfaces: []interfaceBinding{{"", ""}},
expectedError: "interface bindings cannot have empty names",
@@ -546,9 +550,11 @@ func (suite *maas2EnvironSuite) TestAcquireNodeInterfaces(c *gc.C) {
}} {
c.Logf("test #%d: interfaces=%v", i, test.interfaces)
env = makeEnviron(c)
- // TODO (mfoord): need getPositives as well.
getNegatives = func() []string {
- return strings.Split(test.expectedNegatives, ";")
+ return test.expectedNegatives
+ }
+ getPositives = func() []gomaasapi.InterfaceSpec {
+ return test.expectedPositives
}
_, err := env.acquireNode2("", "", cons, test.interfaces, nil)
if test.expectedError != "" {
@@ -576,9 +582,11 @@ func getTwoSpaces() []gomaasapi.Space {
}
func (suite *maas2EnvironSuite) TestAcquireNodeConvertsSpaceNames(c *gc.C) {
- // Expected args should have Interfaces set
- // Interfaces: 0:space=2,
- env := suite.injectControllerWithSpacesAndCheck(c, getTwoSpaces(), gomaasapi.AllocateMachineArgs{NotNetworks: []string{"space:3"}})
+ expected := gomaasapi.AllocateMachineArgs{
+ NotSpace: []string{"3"},
+ Interfaces: []gomaasapi.InterfaceSpec{{Label: "0", Space: "2"}},
+ }
+ env := suite.injectControllerWithSpacesAndCheck(c, getTwoSpaces(), expected)
cons := constraints.Value{
Spaces: stringslicep("foo", "^bar"),
}
@@ -587,7 +595,11 @@ func (suite *maas2EnvironSuite) TestAcquireNodeConvertsSpaceNames(c *gc.C) {
}
func (suite *maas2EnvironSuite) TestAcquireNodeTranslatesSpaceNames(c *gc.C) {
- env := suite.injectControllerWithSpacesAndCheck(c, getTwoSpaces(), gomaasapi.AllocateMachineArgs{NotNetworks: []string{"space:3"}})
+ expected := gomaasapi.AllocateMachineArgs{
+ NotSpace: []string{"3"},
+ Interfaces: []gomaasapi.InterfaceSpec{{Label: "0", Space: "2"}},
+ }
+ env := suite.injectControllerWithSpacesAndCheck(c, getTwoSpaces(), expected)
cons := constraints.Value{
Spaces: stringslicep("foo-1", "^bar-3"),
}
@@ -33,14 +33,15 @@ func (c *fakeController) Machines(args gomaasapi.MachinesArgs) ([]gomaasapi.Mach
return c.machines, nil
}
-func (c *fakeController) AllocateMachine(args gomaasapi.AllocateMachineArgs) (gomaasapi.Machine, error) {
+func (c *fakeController) AllocateMachine(args gomaasapi.AllocateMachineArgs) (gomaasapi.Machine, gomaasapi.ConstraintMatches, error) {
+ matches := gomaasapi.ConstraintMatches{}
if c.allocateMachineArgsCheck != nil {
c.allocateMachineArgsCheck(args)
}
if c.allocateMachineError != nil {
- return nil, c.allocateMachineError
+ return nil, matches, c.allocateMachineError
}
- return c.allocateMachine, nil
+ return c.allocateMachine, matches, nil
}
func (c *fakeController) BootResources() ([]gomaasapi.BootResource, error) {