Reviewers: mp+213989_code.launchpad.net,
Message: Please take a look.
Description: state: no pre-checks for injected machines
We should not be second guessing the bootstrap agent or manual provisioning. If the instance-id is non-empty when adding a machine to state, do not check SupportsUnitPlacement.
https://code.launchpad.net/~axwalk/juju-core/fix-supportsunitplacement-injectmachine/+merge/213989
(do not edit description out of merge proposal)
Please review this at https://codereview.appspot.com/83940043/
Affected files (+20, -2 lines): A [revision details] M state/addmachine.go M state/environcapability_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-20140403093134-znbl1cwzwu3cb3es +New revision: <email address hidden>
Index: state/addmachine.go === modified file 'state/addmachine.go' --- state/addmachine.go 2014-04-03 04:03:00 +0000 +++ state/addmachine.go 2014-04-03 09:52:10 +0000 @@ -135,7 +135,7 @@ for _, template := range templates { // Adding a machine without any principals is // only permitted unit placement is supported. - if len(template.principals) == 0 { + if len(template.principals) == 0 && template.InstanceId == "" { if err := st.supportsUnitPlacement(); err != nil { return nil, err }
Index: state/environcapability_test.go === modified file 'state/environcapability_test.go' --- state/environcapability_test.go 2014-04-03 03:37:45 +0000 +++ state/environcapability_test.go 2014-04-03 09:52:10 +0000 @@ -52,6 +52,15 @@ }) }
+func (s *EnvironCapabilitySuite) addOneMachineWithInstanceId(c *gc.C) (*state.Machine, error) { + return s.State.AddOneMachine(state.MachineTemplate{ + Series: "quantal", + Jobs: []state.MachineJob{state.JobHostUnits}, + InstanceId: "i-rate", + Nonce: "ya", + }) +} + func (s *EnvironCapabilitySuite) addMachineInsideNewMachine(c *gc.C) error { template := state.MachineTemplate{ Series: "quantal", @@ -62,7 +71,7 @@ }
func (s *EnvironCapabilitySuite) TestSupportsUnitPlacementAddMachine(c *gc.C) { - // Ensure that AddOneMachine fails when PrecheckInstance returns an error. + // Ensure that AddOneMachine fails when SupportsUnitPlacement returns an error. s.capability.supportsUnitPlacementError = fmt.Errorf("no add-machine for you") _, err := s.addOneMachine(c) c.Assert(err, gc.ErrorMatches, ".*no add-machine for you") @@ -76,6 +85,13 @@ c.Assert(err, gc.ErrorMatches, ".*incapable of EnvironCapability") }
+func (s *EnvironCapabilitySuite) TestSupportsUnitPlacementAddMachineInstanceId(c *gc.C) { + // Ensure that AddOneMachine with a non-empty InstanceId does not fail. + s.capability.supportsUnitPlacementError = fmt.Errorf("no add-machine for you") + _, err := s.addOneMachineWithInstanceId(c) + c.Assert(err, gc.IsNil) +} + func (s *EnvironCapabilitySuite) TestSupportsUnitPlacementUnitAssignment(c *gc.C) { m, err := s.addOneMachine(c) c.Assert(err, gc.IsNil)
« Back to merge proposal
Reviewers: mp+213989_ code.launchpad. net,
Message:
Please take a look.
Description:
state: no pre-checks for injected machines
We should not be second guessing the bootstrap agent or cement.
manual provisioning. If the instance-id is non-empty when
adding a machine to state, do not check SupportsUnitPla
https:/ /code.launchpad .net/~axwalk/ juju-core/ fix-supportsuni tplacement- injectmachine/ +merge/ 213989
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/83940043/
Affected files (+20, -2 lines): pability_ test.go
A [revision details]
M state/addmachine.go
M state/environca
Index: [revision details] 20140403093134- znbl1cwzwu3cb3e s
=== 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-
+New revision: <email address hidden>
Index: state/addmachine.go addmachine. go' principals) == 0 { principals) == 0 && template.InstanceId == "" { Placement( ); err != nil {
=== modified file 'state/
--- state/addmachine.go 2014-04-03 04:03:00 +0000
+++ state/addmachine.go 2014-04-03 09:52:10 +0000
@@ -135,7 +135,7 @@
for _, template := range templates {
// Adding a machine without any principals is
// only permitted unit placement is supported.
- if len(template.
+ if len(template.
if err := st.supportsUnit
return nil, err
}
Index: state/environca pability_ test.go environcapabili ty_test. go' pability_ test.go 2014-04-03 03:37:45 +0000 pability_ test.go 2014-04-03 09:52:10 +0000
=== modified file 'state/
--- state/environca
+++ state/environca
@@ -52,6 +52,15 @@
})
}
+func (s *EnvironCapabil itySuite) addOneMachineWi thInstanceId( c *gc.C) AddOneMachine( state.MachineTe mplate{ MachineJob{ state.JobHostUn its}, itySuite) addMachineInsid eNewMachine( c *gc.C) error mplate{
(*state.Machine, error) {
+ return s.State.
+ Series: "quantal",
+ Jobs: []state.
+ InstanceId: "i-rate",
+ Nonce: "ya",
+ })
+}
+
func (s *EnvironCapabil
{
template := state.MachineTe
Series: "quantal",
@@ -62,7 +71,7 @@
}
func (s *EnvironCapabil itySuite) TestSupportsUni tPlacementAddMa chine(c cement returns an .supportsUnitPl acementError = fmt.Errorf("no add-machine for
*gc.C) {
- // Ensure that AddOneMachine fails when PrecheckInstance returns an error.
+ // Ensure that AddOneMachine fails when SupportsUnitPla
error.
s.capability
you")
_, err := s.addOneMachine(c)
c.Assert(err, gc.ErrorMatches, ".*no add-machine for you")
@@ -76,6 +85,13 @@
c.Assert(err, gc.ErrorMatches, ".*incapable of EnvironCapability")
}
+func (s *EnvironCapabil itySuite) tPlacementAddMa chineInstanceId (c *gc.C) { supportsUnitPla cementError = fmt.Errorf("no add-machine for WithInstanceId( c) itySuite) TestSupportsUni tPlacementUnitA ssignment( c
TestSupportsUni
+ // Ensure that AddOneMachine with a non-empty InstanceId does not fail.
+ s.capability.
you")
+ _, err := s.addOneMachine
+ c.Assert(err, gc.IsNil)
+}
+
func (s *EnvironCapabil
*gc.C) {
m, err := s.addOneMachine(c)
c.Assert(err, gc.IsNil)