Merge lp:~hduran-8/juju-core/add_network_check_on_specified_machine into lp:~go-bot/juju-core/trunk

Proposed by Horacio Durán
Status: Work in progress
Proposed branch: lp:~hduran-8/juju-core/add_network_check_on_specified_machine
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 301 lines (+147/-2)
13 files modified
cmd/juju/deploy.go (+2/-1)
environs/interface.go (+4/-0)
juju/deploy.go (+21/-0)
provider/azure/environ.go (+5/-0)
provider/dummy/environs.go (+5/-0)
provider/ec2/ec2.go (+5/-0)
provider/joyent/environ.go (+5/-0)
provider/local/environ.go (+5/-0)
provider/maas/environ.go (+44/-1)
provider/maas/environ_whitebox_test.go (+21/-0)
provider/manual/environ.go (+5/-0)
provider/openstack/provider.go (+5/-0)
state/apiserver/client/client.go (+20/-0)
To merge this branch: bzr merge lp:~hduran-8/juju-core/add_network_check_on_specified_machine
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+214463@code.launchpad.net

Description of the change

Added --not/network compat verification for --to

I added ValidateNetworksForInstance to Environ
This method checks if te requested networks are
available in the instance selected with --to
and if the excluded networks are not in conflict
with already existing ones.
I added this to the Environ interface and mocked
the method in all the available providers.
This method is only required when SupportNetworks
from EnvironCapability is true

https://codereview.appspot.com/84880045/

To post a comment you must log in.
Revision history for this message
Horacio Durán (hduran-8) wrote :

Reviewers: mp+214463_code.launchpad.net,

Message:
Please take a look.

Description:
Added --not/network compat verification for --to

I added ValidateNetworksForInstance to Environ
This method checks if te requested networks are
available in the instance selected with --to
and if the excluded networks are not in conflict
with already existing ones.
I added this to the Environ interface and mocked
the method in all the available providers.
This method is only required when SupportNetworks
from EnvironCapability is true

https://code.launchpad.net/~hduran-8/juju-core/add_network_check_on_specified_machine/+merge/214463

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/84880045/

Affected files (+149, -2 lines):
   A [revision details]
   M cmd/juju/deploy.go
   M environs/interface.go
   M juju/deploy.go
   M provider/azure/environ.go
   M provider/dummy/environs.go
   M provider/ec2/ec2.go
   M provider/joyent/environ.go
   M provider/local/environ.go
   M provider/maas/environ.go
   M provider/maas/environ_whitebox_test.go
   M provider/manual/environ.go
   M provider/openstack/provider.go
   M state/apiserver/client/client.go

Revision history for this message
Dimiter Naydenov (dimitern) wrote :
Download full text (4.1 KiB)

Good direction, but I have some concerns and suggestions to make it
better.

https://codereview.appspot.com/84880045/diff/1/cmd/juju/deploy.go
File cmd/juju/deploy.go (right):

https://codereview.appspot.com/84880045/diff/1/cmd/juju/deploy.go#newcode195
cmd/juju/deploy.go:195:
d

https://codereview.appspot.com/84880045/diff/1/environs/interface.go
File environs/interface.go (right):

https://codereview.appspot.com/84880045/diff/1/environs/interface.go#newcode168
environs/interface.go:168: // ValidateNetworksForInstance returns nil if
the networks are
// ValidateNetworksForInstance returns and error if the given networks
// are not compatible for the given instance id.

s/instance_id string/instanceId instance.Id/

https://codereview.appspot.com/84880045/diff/1/juju/deploy.go
File juju/deploy.go (right):

https://codereview.appspot.com/84880045/diff/1/juju/deploy.go#newcode37
juju/deploy.go:37: func (parms *DeployServiceParams) ClearMachineSpecs()
(string, instance.ContainerType) {
s/parms/args/ ?

https://codereview.appspot.com/84880045/diff/1/juju/deploy.go#newcode38
juju/deploy.go:38: // TODO: Add this to AddUnit and replace wherever
required
// TODO(hduran-8) ...

https://codereview.appspot.com/84880045/diff/1/provider/maas/environ.go
File provider/maas/environ.go (right):

https://codereview.appspot.com/84880045/diff/1/provider/maas/environ.go#newcode568
provider/maas/environ.go:568: maasObj_list, err :=
e.instances([]instance.Id{instance.Id(instance_id)})
s/maasObj_list/maasObjList/ (no underscores please)

https://codereview.appspot.com/84880045/diff/1/provider/maas/environ.go#newcode574
provider/maas/environ.go:574: return fmt.Errorf("Found unexpected amunt
of instances with the given id")
return fmt.Errorf("expected one result, got %d", len(maasObjList)) ?

https://codereview.appspot.com/84880045/diff/1/provider/maas/environ.go#newcode580
provider/maas/environ.go:580: fmt.Print(networks)
logger.Debugf("got networks from MAAS: %v", networks) ?

https://codereview.appspot.com/84880045/diff/1/provider/maas/environ.go#newcode586
provider/maas/environ.go:586: for _, i_network := range includedNetworks
{
s/i_network/network/

https://codereview.appspot.com/84880045/diff/1/provider/maas/environ.go#newcode588
provider/maas/environ.go:588: fmt.Print(netmap)
logger.Debugf("got networks map from MAAS: %v", netmap)

https://codereview.appspot.com/84880045/diff/1/provider/maas/environ.go#newcode589
provider/maas/environ.go:589: return fmt.Errorf("Ip %q is not present in
the requested unit", i_network)
Why IP ? We're getting network names in the command and we should check
for that in maas result list, not IPs.

return fmt.Errorf("network %q not found for instance %q in MAAS",
network, instanceId)

https://codereview.appspot.com/84880045/diff/1/provider/maas/environ.go#newcode595
provider/maas/environ.go:595: return fmt.Errorf("Ip %q is set up in the
requested unit and can not be excluded", i_network)
Similarly, return fmt.Errorf("network %q is required for instance %q and
cannot be excluded", network, instanceId)

https://codereview.appspot.com/84880045/diff/1/provider/maas/environ_whitebox_test.go
File provider/maas/environ_whitebox_test.go (rig...

Read more...

Revision history for this message
Dimiter Naydenov (dimitern) wrote :

Also, the kanban card mentioned deploy and add-unit for --to, and I
can't see the changes to the latter (add --(exclude)-networks args and
check them if --to is given, otherwise return an error if networks are
specified I think). Finally, we need to make sure if the user specifies
networks for both commands, all given networks must be in
include/excludeNetworks for the service itself (i.e. you cannot
add/remove networks from the service when deploying new units, just
restrict what networks will be enabled out of the initially given
networks for the service).

https://codereview.appspot.com/84880045/

Revision history for this message
William Reade (fwereade) wrote :

As it stands, this does not lgtm. I think this needs to happen inside
state, based on the contents of state, at unit assignment time, and in a
txn that checks against the current service networks -- doing it that
way should make it possible to correctly handle both deploy and
add-unit.

https://codereview.appspot.com/84880045/diff/1/environs/interface.go
File environs/interface.go (right):

https://codereview.appspot.com/84880045/diff/1/environs/interface.go#newcode170
environs/interface.go:170: ValidateNetworksForInstance(includedNetworks,
excludedNetworks []string, instance_id string) error
Not 100%sure about this direction -- I'd rather not talk to the provider
if we have the info available in state. Dimitern, what's the status of
the pipeline that sets actual networks on machines?

https://codereview.appspot.com/84880045/diff/1/juju/deploy.go
File juju/deploy.go (right):

https://codereview.appspot.com/84880045/diff/1/juju/deploy.go#newcode37
juju/deploy.go:37: func (parms *DeployServiceParams) ClearMachineSpecs()
(string, instance.ContainerType) {
Needs documentation, intent is not clear from the name IMO.

https://codereview.appspot.com/84880045/diff/1/juju/deploy.go#newcode49
juju/deploy.go:49: if containerType, err =
instance.ParseContainerType(firstPart); err == nil {
You surely didn't have the context to know this, but this is *not* a
container type -- the stuff in --to is a "placement directive", of which
the only one implemented is "lxc".

Haven't looked further; so, if this is consolidating the couple of bits
of code that already do this sort of thing, +1, because it reduces the
number of places we need to fix as we do placement directives properly;
if it's further duplication, -1.

https://codereview.appspot.com/84880045/diff/1/provider/maas/environ.go
File provider/maas/environ.go (right):

https://codereview.appspot.com/84880045/diff/1/provider/maas/environ.go#newcode85
provider/maas/environ.go:85: return nil
This needs to return an error; but I have a pretty serious problem with
the existence of this exported method in the first place. We really
shouldn't be casting Environs like this...

https://codereview.appspot.com/84880045/diff/1/provider/maas/environ.go#newcode572
provider/maas/environ.go:572: if len(maasObj_list) == 0 {
!= 1?

but... again, I don't think this should be an environ method anyway.

https://codereview.appspot.com/84880045/diff/1/state/apiserver/client/client.go
File state/apiserver/client/client.go (right):

https://codereview.appspot.com/84880045/diff/1/state/apiserver/client/client.go#newcode315
state/apiserver/client/client.go:315: err =
env.ValidateNetworksForInstance(args.IncludeNetworks,
args.ExcludeNetworks, mid)
If I were happy with the environ method, I'd still rather keep this
check inside state, so we can keep ensuring db integrity as networks
become dynamic -- not directly relevant for *deploy*, I guess, but
trying to do the same job in different layers at different times should
generally be avoided ;).

https://codereview.appspot.com/84880045/

Revision history for this message
Dimiter Naydenov (dimitern) wrote :

https://codereview.appspot.com/84880045/diff/1/environs/interface.go
File environs/interface.go (right):

https://codereview.appspot.com/84880045/diff/1/environs/interface.go#newcode170
environs/interface.go:170: ValidateNetworksForInstance(includedNetworks,
excludedNetworks []string, instance_id string) error
On 2014/04/07 09:29:40, fwereade wrote:
> Not 100%sure about this direction -- I'd rather not talk to the
provider if we
> have the info available in state. Dimitern, what's the status of the
pipeline
> that sets actual networks on machines?

We can set networks and NICs on machines in state, but the provisioner
does not do it yet - it will some time later today I hope.

https://codereview.appspot.com/84880045/

Unmerged revisions

2549. By Horacio Durán

Ran GoFmt on files

2548. By Horacio Durán

Fixed ValidateNetworksForInstance after testing and added tests

2547. By Horacio Durán

Finished implementing ValidateNetworksForInstance in environs, still missing tests

2546. By Horacio Durán

Added most of the required methods to check if requested methods are possible
on the requierd environ

2545. By Horacio Durán

Did a base implementtion for checking netowrk compatibility on --to

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmd/juju/deploy.go'
2--- cmd/juju/deploy.go 2014-04-03 04:46:51 +0000
3+++ cmd/juju/deploy.go 2014-04-07 02:15:57 +0000
4@@ -76,7 +76,7 @@
5 juju deploy mysql --to 23 (Deploy to machine 23)
6 juju deploy mysql --to 24/lxc/3 (Deploy to lxc container 3 on host machine 24)
7 juju deploy mysql --to lxc:25 (Deploy to a new lxc container on host machine 25)
8-
9+
10 juju deploy mysql -n 5 --constraints mem=8G (deploy 5 instances of mysql with at least 8 GB of RAM each)
11
12 juju deploy mysql --networks=storage,mynet --exclude-networks=logging
13@@ -194,6 +194,7 @@
14 if !env.SupportNetworks() {
15 return errors.New("cannot use --networks/--exclude-networks: not supported by the environment")
16 }
17+
18 }
19
20 charmInfo, err := client.CharmInfo(curl.String())
21
22=== modified file 'environs/interface.go'
23--- environs/interface.go 2014-04-03 03:37:45 +0000
24+++ environs/interface.go 2014-04-07 02:15:57 +0000
25@@ -153,6 +153,10 @@
26 // FwGlobal firewall mode.
27 Ports() ([]instance.Port, error)
28
29+ // ValidateNetworksForInstance returns nil if the networks are
30+ // compatible with the given insance or error in case they arent
31+ ValidateNetworksForInstance(includedNetworks, excludedNetworks []string, instance_id string) error
32+
33 // Provider returns the EnvironProvider that created this Environ.
34 Provider() EnvironProvider
35
36
37=== modified file 'juju/deploy.go'
38--- juju/deploy.go 2014-04-03 09:10:10 +0000
39+++ juju/deploy.go 2014-04-07 02:15:57 +0000
40@@ -34,6 +34,27 @@
41 ExcludeNetworks []string
42 }
43
44+func (parms *DeployServiceParams) ClearMachineSpecs() (string, instance.ContainerType) {
45+ // TODO: Add this to AddUnit and replace wherever required
46+ // machineIdSpec may be an existing machine or container, eg 3/lxc/2
47+ // or a new container on a machine, eg lxc:3
48+
49+ mid := parms.ToMachineSpec
50+ var containerType instance.ContainerType
51+ specParts := strings.SplitN(mid, ":", 2)
52+ if len(specParts) > 1 {
53+ firstPart := specParts[0]
54+ var err error
55+ // If the type is present in the first part, the seccond is the id
56+ if containerType, err = instance.ParseContainerType(firstPart); err == nil {
57+ mid = specParts[1]
58+ } else {
59+ mid = parms.ToMachineSpec
60+ }
61+ }
62+ return mid, containerType
63+}
64+
65 // DeployService takes a charm and various parameters and deploys it.
66 func DeployService(st *state.State, args DeployServiceParams) (*state.Service, error) {
67 if args.NumUnits > 1 && args.ToMachineSpec != "" {
68
69=== modified file 'provider/azure/environ.go'
70--- provider/azure/environ.go 2014-04-03 09:07:57 +0000
71+++ provider/azure/environ.go 2014-04-07 02:15:57 +0000
72@@ -387,6 +387,11 @@
73 return env.supportedArchitectures, err
74 }
75
76+func (e *azureEnviron) ValidateNetworksForInstance(includedNetworks, excludedNetworks []string, instance_id string) error {
77+ // If SupportNetworks is true, this should be implemented
78+ return nil
79+}
80+
81 // SupportNetworks is specified on the EnvironCapability interface.
82 func (env *azureEnviron) SupportNetworks() bool {
83 return false
84
85=== modified file 'provider/dummy/environs.go'
86--- provider/dummy/environs.go 2014-04-04 16:52:41 +0000
87+++ provider/dummy/environs.go 2014-04-07 02:15:57 +0000
88@@ -536,6 +536,11 @@
89 return []string{arch.AMD64, arch.PPC64}, nil
90 }
91
92+func (e *environ) ValidateNetworksForInstance(includedNetworks, excludedNetworks []string, instance_id string) error {
93+ // TODO: Actually check if networks are compatible with the instace
94+ return nil
95+}
96+
97 // SupportNetworks is specified on the EnvironCapability interface.
98 func (*environ) SupportNetworks() bool {
99 return true
100
101=== modified file 'provider/ec2/ec2.go'
102--- provider/ec2/ec2.go 2014-04-03 04:46:51 +0000
103+++ provider/ec2/ec2.go 2014-04-07 02:15:57 +0000
104@@ -350,6 +350,11 @@
105 return e.supportedArchitectures, err
106 }
107
108+func (e *environ) ValidateNetworksForInstance(includedNetworks, excludedNetworks []string, instance_id string) error {
109+ // If SupportNetworks is true, this should be implemented
110+ return nil
111+}
112+
113 // SupportNetworks is specified on the EnvironCapability interface.
114 func (e *environ) SupportNetworks() bool {
115 // TODO(dimitern) Once we have support for VPCs and advanced
116
117=== modified file 'provider/joyent/environ.go'
118--- provider/joyent/environ.go 2014-04-03 20:05:38 +0000
119+++ provider/joyent/environ.go 2014-04-07 02:15:57 +0000
120@@ -96,6 +96,11 @@
121 return env.supportedArchitectures, err
122 }
123
124+func (e *joyentEnviron) ValidateNetworksForInstance(includedNetworks, excludedNetworks []string, instance_id string) error {
125+ // If SupportNetworks is true, this should be implemented
126+ return nil
127+}
128+
129 // SupportNetworks is specified on the EnvironCapability interface.
130 func (e *joyentEnviron) SupportNetworks() bool {
131 return false
132
133=== modified file 'provider/local/environ.go'
134--- provider/local/environ.go 2014-04-03 03:37:45 +0000
135+++ provider/local/environ.go 2014-04-07 02:15:57 +0000
136@@ -81,6 +81,11 @@
137 return []string{localArch}, nil
138 }
139
140+func (e *localEnviron) ValidateNetworksForInstance(includedNetworks, excludedNetworks []string, instance_id string) error {
141+ // If SupportNetworks is true, this should be implemented
142+ return nil
143+}
144+
145 // SupportNetworks is specified on the EnvironCapability interface.
146 func (*localEnviron) SupportNetworks() bool {
147 return false
148
149=== modified file 'provider/maas/environ.go'
150--- provider/maas/environ.go 2014-04-03 03:37:45 +0000
151+++ provider/maas/environ.go 2014-04-07 02:15:57 +0000
152@@ -81,6 +81,15 @@
153 return env, nil
154 }
155
156+func GetFromEnvironInterface(interfaceEnv environs.Environ) *maasEnviron {
157+ maasEnv, ok := interfaceEnv.(*maasEnviron)
158+
159+ if !ok {
160+ return nil
161+ }
162+ return maasEnv
163+}
164+
165 // Name is specified in the Environ interface.
166 func (env *maasEnviron) Name() string {
167 return env.name
168@@ -558,7 +567,41 @@
169 Description string
170 }
171
172-// GetNetworksList returns a list of strings which contain networks for a gien maas node instance.
173+func (e *maasEnviron) ValidateNetworksForInstance(includedNetworks, ExcludeNetworks []string, instance_id string) error {
174+ maasObj_list, err := e.instances([]instance.Id{instance.Id(instance_id)})
175+ if err != nil {
176+ return err
177+ }
178+ if len(maasObj_list) == 0 {
179+ //XXX: I am not sure this can actually happen
180+ return fmt.Errorf("Found unexpected amunt of instances with the given id")
181+ }
182+ maasObj := maasObj_list[0]
183+
184+ networks, _ := e.GetNetworksList(maasObj)
185+ netmap := make(map[string]string)
186+ fmt.Print(networks)
187+
188+ for _, value := range networks {
189+ netmap[value.Ip] = ""
190+ }
191+
192+ for _, i_network := range includedNetworks {
193+ if _, ok := netmap[i_network]; !ok {
194+ fmt.Print(netmap)
195+ return fmt.Errorf("Ip %q is not present in the requested unit", i_network)
196+ }
197+ }
198+
199+ for _, i_network := range ExcludeNetworks {
200+ if _, ok := netmap[i_network]; ok {
201+ return fmt.Errorf("Ip %q is set up in the requested unit and can not be excluded", i_network)
202+ }
203+ }
204+ return nil
205+}
206+
207+// GetNetworksList returns a list of strings which contain networks for a given maas node instance.
208 func (e *maasEnviron) GetNetworksList(inst instance.Instance) ([]MAASNetworkDetails, error) {
209 maasInst := inst.(*maasInstance)
210 maasObj := maasInst.maasObject
211
212=== modified file 'provider/maas/environ_whitebox_test.go'
213--- provider/maas/environ_whitebox_test.go 2014-04-02 07:50:15 +0000
214+++ provider/maas/environ_whitebox_test.go 2014-04-07 02:15:57 +0000
215@@ -542,3 +542,24 @@
216 // once gomaasapi testing server supports networks.
217 c.Assert(env.SupportNetworks(), jc.IsFalse)
218 }
219+
220+func (suite *environSuite) TestValidateNetworksForNode(c *gc.C) {
221+ test_environ := suite.makeEnviron()
222+ suite.getNetwork("test_network")
223+ suite.getInstance("instance_for_network")
224+ suite.testMAASObject.TestServer.ConnectNodeToNetwork("instance_for_network", "test_network")
225+
226+ err := test_environ.ValidateNetworksForInstance([]string{"127.0.0.1"}, []string{}, "instance_for_network")
227+ c.Assert(err, gc.IsNil)
228+
229+ err = test_environ.ValidateNetworksForInstance([]string{}, []string{"127.0.0.2"}, "instance_for_network")
230+ c.Assert(err, gc.IsNil)
231+
232+ expected_err := fmt.Errorf("Ip %q is set up in the requested unit and can not be excluded", "127.0.0.1")
233+ err = test_environ.ValidateNetworksForInstance([]string{}, []string{"127.0.0.1"}, "instance_for_network")
234+ c.Check(err, gc.DeepEquals, expected_err)
235+
236+ expected_err = fmt.Errorf("Ip %q is not present in the requested unit", "127.0.0.2")
237+ err = test_environ.ValidateNetworksForInstance([]string{"127.0.0.2"}, []string{}, "instance_for_network")
238+ c.Check(err, gc.DeepEquals, expected_err)
239+}
240
241=== modified file 'provider/manual/environ.go'
242--- provider/manual/environ.go 2014-04-03 04:03:00 +0000
243+++ provider/manual/environ.go 2014-04-07 02:15:57 +0000
244@@ -96,6 +96,11 @@
245 return arch.AllSupportedArches, nil
246 }
247
248+func (e *manualEnviron) ValidateNetworksForInstance(includedNetworks, excludedNetworks []string, instance_id string) error {
249+ // If SupportNetworks is true, this should be implemented
250+ return nil
251+}
252+
253 // SupportNetworks is specified on the EnvironCapability interface.
254 func (e *manualEnviron) SupportNetworks() bool {
255 return false
256
257=== modified file 'provider/openstack/provider.go'
258--- provider/openstack/provider.go 2014-04-03 04:46:51 +0000
259+++ provider/openstack/provider.go 2014-04-07 02:15:57 +0000
260@@ -515,6 +515,11 @@
261 return e.supportedArchitectures, err
262 }
263
264+func (e *environ) ValidateNetworksForInstance(includedNetworks, excludedNetworks []string, instance_id string) error {
265+ // If SupportNetworks is true, this should be implemented
266+ return nil
267+}
268+
269 // SupportNetworks is specified on the EnvironCapability interface.
270 func (e *environ) SupportNetworks() bool {
271 // TODO(dimitern) Once we have support for networking, inquire
272
273=== modified file 'state/apiserver/client/client.go'
274--- state/apiserver/client/client.go 2014-04-04 10:00:45 +0000
275+++ state/apiserver/client/client.go 2014-04-07 02:15:57 +0000
276@@ -298,6 +298,26 @@
277 // allows specifying networks to include or exclude on the machine
278 // where the charm gets deployed.
279 func (c *Client) ServiceDeployWithNetworks(args params.ServiceDeploy) error {
280+ // XXX Get the actual node
281+ parms := juju.DeployServiceParams{
282+ ToMachineSpec: args.ToMachineSpec,
283+ IncludeNetworks: args.IncludeNetworks,
284+ ExcludeNetworks: args.ExcludeNetworks}
285+
286+ mid, _ := parms.ClearMachineSpecs()
287+
288+ conn, err := juju.NewConnFromState(c.api.state)
289+ env := conn.Environ
290+ if env == nil {
291+ return err
292+ }
293+
294+ err = env.ValidateNetworksForInstance(args.IncludeNetworks, args.ExcludeNetworks, mid)
295+
296+ if err != nil {
297+ return err
298+ }
299+
300 return c.ServiceDeploy(args)
301 }
302

Subscribers

People subscribed via source and target branches

to status/vote changes: