diff options
-rw-r--r-- | nova/tests/fake_network.py | 110 |
1 files changed, 71 insertions, 39 deletions
diff --git a/nova/tests/fake_network.py b/nova/tests/fake_network.py index 19be83bc9..ee1a4a7c7 100644 --- a/nova/tests/fake_network.py +++ b/nova/tests/fake_network.py @@ -14,7 +14,6 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from itertools import islice from nova import db from nova import flags @@ -35,6 +34,17 @@ class FakeModel(dict): return self[name] +flavor = {'id': 0, + 'name': 'fake_flavor', + 'memory_mb': 2048, + 'vcpus': 2, + 'local_gb': 10, + 'flavor_id': 0, + 'swap': 0, + 'rxtx_quota': 0, + 'rxtx_cap': 3} + + def fake_network(network_id, ipv6=None): if ipv6 is None: ipv6 = FLAGS.use_ipv6 @@ -65,42 +75,6 @@ def fake_network(network_id, ipv6=None): return fake_network -def fixed_ips(num_networks, num_ips, num_floating_ips=0): - for network_index in xrange(num_networks): - for ip_index in xrange(num_ips): - fixed_ip_id = network_index * num_ips + ip_index - f_ips = [FakeModel(**floating_ip_dict) for floating_ip_dict - in islice(floating_ips(fixed_ip_id), num_floating_ips)] - yield {'id': fixed_ip_id, - 'network_id': network_index, - 'address': '192.168.%d.1%02d' % (network_index, ip_index), - 'instance_id': 0, - 'allocated': False, - # and since network_id and vif_id happen to be equivalent - 'virtual_interface_id': network_index, - 'floating_ips': f_ips} - - -flavor = {'id': 0, - 'name': 'fake_flavor', - 'memory_mb': 2048, - 'vcpus': 2, - 'local_gb': 10, - 'flavor_id': 0, - 'swap': 0, - 'rxtx_quota': 0, - 'rxtx_cap': 3} - - -def floating_ips(fixed_ip_id): - for i in xrange(154): - yield {'id': i, - 'address': '10.10.%d.%d' % (fixed_ip_id, i + 100), - 'fixed_ip_id': fixed_ip_id, - 'project_id': None, - 'auto_assigned': False} - - def vifs(n): for x in xrange(n): yield {'id': x, @@ -111,6 +85,58 @@ def vifs(n): 'instance_id': 0} +#def fixed_ips(num_networks, num_ips, num_floating_ips=0): +# for network_index in xrange(num_networks): +# for ip_index in xrange(num_ips): +# fixed_ip_id = network_index * num_ips + ip_index +# islice = itertools.islice +# yield {'id': fixed_ip_id, +# 'network_id': network_index, +# 'address': '192.168.%d.1%02d' % (network_index, ip_index), +# 'instance_id': 0, +# 'allocated': False, +# # and since network_id and vif_id happen to be equivalent +# 'virtual_interface_id': network_index, +# 'floating_ips': f_ips} + + +def floating_ip_ids(): + for i in xrange(99): + yield i + + +def fixed_ip_ids(): + for i in xrange(99): + yield i + + +floating_ip_id = floating_ip_ids() +fixed_ip_id = fixed_ip_ids() + + +def next_fixed_ip(network_id, num_floating_ips=0): + next_id = fixed_ip_id.next() + f_ips = [FakeModel(**next_floating_ip(fixed_ip_id)) + for i in xrange(num_floating_ips)] + return {'id': next, + 'network_id': network_id, + 'address': '192.168.%d.1%02d' % (network_id, next_id), + 'instance_id': 0, + 'allocated': False, + # and since network_id and vif_id happen to be equivalent + 'virtual_interface_id': network_id, + 'floating_ips': f_ips} + + +def next_floating_ip(fixed_ip_id): + next_id = floating_ip_id.next() + return {'id': next_id, + 'address': '10.10.10.1%02d' % next_id, + 'fixed_ip_id': fixed_ip_id, + 'project_id': None, + 'auto_assigned': False} + + def ipv4_like(ip, match_string): ip = ip.split('.') match_octets = match_string.split('.') @@ -123,15 +149,21 @@ def ipv4_like(ip, match_string): return True -def fake_get_instance_nw_info(stubs, num_networks=1, ips_per_vif=2): +def fake_get_instance_nw_info(stubs, num_networks=1, ips_per_vif=2, + floating_ips_per_fixed_ip=0): # stubs is the self.stubs from the test # ips_per_vif is the number of ips each vif will have # num_floating_ips is number of float ips for each fixed ip network = network_manager.FlatManager(host=HOST) network.db = db + # reset the fixed and floating ip generators + floating_ip_id = floating_ip_ids() + fixed_ip_id = fixed_ip_ids() + def fixed_ips_fake(*args, **kwargs): - return list(fixed_ips(num_networks, ips_per_vif)) + return [next_fixed_ip(i, floating_ips_per_fixed_ip) + for i in xrange(num_networks) for j in xrange(ips_per_vif)] def virtual_interfaces_fake(*args, **kwargs): return [vif for vif in vifs(num_networks)] |