Merge lp:~jtran/nova/lp740810 into lp:~hudson-openstack/nova/trunk

Proposed by John Tran
Status: Merged
Approved by: Vish Ishaya
Approved revision: 1317
Merged at revision: 1380
Proposed branch: lp:~jtran/nova/lp740810
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 30 lines (+12/-1)
1 file modified
bin/nova-manage (+12/-1)
To merge this branch: bzr merge lp:~jtran/nova/lp740810
Reviewer Review Type Date Requested Status
Trey Morris (community) Approve
Vish Ishaya (community) Approve
Brian Waldon (community) Approve
Review via email: mp+69326@code.launchpad.net

Commit message

For nova-manage network create cmd, added warning when size of subnet(s) being created are larger than FLAG.network_size, in attempt to alleviate confusion. For example, currently when 'nova-manage network create foo 192.168.0.0/16', the result is that it creates a 192.168.0.0/24 instead without any indication to why

Description of the change

For nova-manage network create cmd, added warning when size of subnet(s) being created are larger than FLAG.network_size, in attempt to alleviate confusion. For example, currently when 'nova-manage network create foo 192.168.0.0/16', the result is that it creates a 192.168.0.0/24 instead without any indication to why

To post a comment you must log in.
Revision history for this message
Brian Waldon (bcwaldon) wrote :

Good catch, John. One thing:

22: you need to put '% subnet' outside of the i18n parentheses

review: Needs Fixing
Revision history for this message
John Tran (jtran) wrote :

> Good catch, John. One thing:
>
> 22: you need to put '% subnet' outside of the i18n parentheses

Brian, thanks for catching that. I've pushed the revision but just curious - why is it preferred to be outside of the parentheses?

Revision history for this message
Brian Waldon (bcwaldon) wrote :

> > Good catch, John. One thing:
> >
> > 22: you need to put '% subnet' outside of the i18n parentheses
>
> Brian, thanks for catching that. I've pushed the revision but just curious -
> why is it preferred to be outside of the parentheses?

The best way to explain is through an example. The msgid below is what is found in nova within the i18n parens, and the msgstr is an example japanese translation:

msgid "Quota exceeeded for %(pid)s, tried to create %(size)sG volume"
msgstr "サイズ %(size)s GB のボリューム作成を行おうとしましたが、%(pid)s のサイ>ズ制限を超えています。"

If the substitutions were placed inside of the i18n parens, we would have to match every possible combination of pid and volume:

msgid "Quota exceeeded for 1234, tried to create 10G volume"
msgstr "サイズ 10 GB のボリューム作成を行おうとしましたが、1234 のサイ>ズ制限を超えています。"

msgid "Quota exceeeded for 5678, tried to create 20G volume"
msgstr "サイズ 20 GB のボリューム作成を行おうとしましたが、5678 のサイ>ズ制限を超えています。"

msgid "Quota exceeeded for 1029, tried to create 30G volume"
msgstr "サイズ 30 GB のボリューム作成を行おうとしましたが、1029 のサイ>ズ制限を超えています。"

In addition to placing the substitution arguments outside of the i18n parens, we also want to use keyword params when we have more than one value to place within the string. That allows the translator to change the order of the params as needed. I hope this makes sense!

review: Approve
Revision history for this message
Trey Morris (tr3buchet) wrote :

John, this bug does need fixing but this is not the place for it. We don't want to be doing anything in nova-manage besides collecting the arguments together to pass off to the code that does the real work. In this case the real work is done in nova/network/manager.py by a couple of functions both called "create_networks".

In this case it looks as though there is a paragraph of code in the vlanmanager version of that function that should be moved into the superclass version:

875 # check that num networks and network size fits in fixed_net
876 fixed_net = netaddr.IPNetwork(kwargs['cidr'])
877 if len(fixed_net) < kwargs['num_networks'] * kwargs['network_size']:
878 raise ValueError(_('The network range is not big enough to fit '
879 '%(num_networks)s. Network size is %(network_size)s') %
880 kwargs)

review: Disapprove
Revision history for this message
John Tran (jtran) wrote :

> John, this bug does need fixing but this is not the place for it. We don't
> want to be doing anything in nova-manage besides collecting the arguments
> together to pass off to the code that does the real work. In this case the
> real work is done in nova/network/manager.py by a couple of functions both
> called "create_networks".
>
> In this case it looks as though there is a paragraph of code in the
> vlanmanager version of that function that should be moved into the superclass
> version:
>
>
> 875 # check that num networks and network size fits in fixed_net
> 876 fixed_net = netaddr.IPNetwork(kwargs['cidr'])
> 877 if len(fixed_net) < kwargs['num_networks'] *
> kwargs['network_size']:
> 878 raise ValueError(_('The network range is not big enough to fit
> '
> 879 '%(num_networks)s. Network size is %(network_size)s') %
> 880 kwargs)

Try, the intention for the bug fix doesn't address the same issue you've highlighted. The server side bug you've highlighted is meant to address subnet size calculation issues. The bug I'm fixing is when using the nova-manage script, if you specify to create a network '192.168.0.0/16' , it'll automatically default back to '192.168.0.0/24' (or whatever is specified in the flags file. That causes confusion. The logic that does the reverting to default flag exists only in the nova-manage client and is there for developer preference as far as I understand it. The bug fix I added simply gives some verbosity so that end users using the nova-manage client understand why their cidr specified got converted.

Revision history for this message
Trey Morris (tr3buchet) wrote :

I see. This is a flags problem you fixed. I think this is all a bit silly, I don't like when arguments to a command come from multiple sources, especially when some are hidden within the code. This could easily be solved by removing the flags for num_networks and network_size and requiring the user pass in these values via commandline to nova-manage network create. This way there would be no surprises.

Alternatively, we could remove the default values for the 2 flags. In this way the user would at least be responsible for setting values that make sense in their implementation, and again no surprises.

Due to the fact that networks will probably be added in many different sizes through the course of time, I'd like to suggest we remove these two flags. They are very minimally referred to in code, each is used only once in nova-manage network create, and if I'm right about adding networks of different sizes, the values for these flags will rarely be used as well. I've tweaked this command before, I'll gladly update it to work without those two flags if this is acceptable.

Otherwise, I have no problems with your fix. I think it will work great if keeping the flags is the way we end up going. Please merge trunk as this particular command is greatly changed from how it appears in your branch.

Revision history for this message
Vish Ishaya (vishvananda) wrote :

setting to WIP until trunk is merged.

review: Approve
Revision history for this message
John Tran (jtran) wrote :

> setting to WIP until trunk is merged.

I've merged from trunk. Thanks!

lp:~jtran/nova/lp740810 updated
1317. By John Tran

forgot to remove comment

Revision history for this message
Soren Hansen (soren) wrote :

I would love to see some tests for this.

Revision history for this message
Trey Morris (tr3buchet) wrote :

soren, i'd like to see some too, but i don't think there are any tests for the nova-manage commands... Maybe a blueprint is the proper place for this?

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/nova-manage'
2--- bin/nova-manage 2011-07-29 21:10:45 +0000
3+++ bin/nova-manage 2011-08-03 07:17:47 +0000
4@@ -56,6 +56,7 @@
5 import gettext
6 import glob
7 import json
8+import math
9 import netaddr
10 import os
11 import sys
12@@ -694,7 +695,17 @@
13 if not num_networks:
14 num_networks = FLAGS.num_networks
15 if not network_size:
16- network_size = FLAGS.network_size
17+ fixnet = netaddr.IPNetwork(fixed_range_v4)
18+ each_subnet_size = fixnet.size / int(num_networks)
19+ if each_subnet_size > FLAGS.network_size:
20+ network_size = FLAGS.network_size
21+ subnet = 32 - int(math.log(network_size, 2))
22+ oversize_msg = _('Subnet(s) too large, defaulting to /%s.'
23+ ' To override, specify network_size flag.'
24+ ) % subnet
25+ print oversize_msg
26+ else:
27+ network_size = fixnet.size
28 if not multi_host:
29 multi_host = FLAGS.multi_host
30 else: