From 36d83ab6f4b6d933241bec4133539bcfbbf1f33a Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 19 Aug 2011 16:12:33 -0500 Subject: [PATCH 001/100] initial committ --- nova/tests/test_compute.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 4f5d36f1..925ac733 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -35,6 +35,7 @@ from nova import rpc from nova import test from nova import utils from nova.notifier import test_notifier +from nova.tests import fake_network_info LOG = logging.getLogger('nova.tests.compute') FLAGS = flags.FLAGS @@ -133,6 +134,9 @@ class ComputeTestCase(test.TestCase): def test_create_instance_defaults_display_name(self): """Verify that an instance cannot be created without a display_name.""" + import pretty_print as pp + pp(fake_get_instance_nw_info(self.stubs, 1, 2)) + self.assertEqual(True, False) cases = [dict(), dict(display_name=None)] for instance in cases: ref = self.compute_api.create(self.context, From 998ecdc1205ad97114f2a56f7135462270a7de91 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 19 Aug 2011 16:41:02 -0500 Subject: [PATCH 002/100] added fake network info --- nova/tests/fake_network_info.py | 107 ++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 nova/tests/fake_network_info.py diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py new file mode 100644 index 00000000..f5bc0368 --- /dev/null +++ b/nova/tests/fake_network_info.py @@ -0,0 +1,107 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2011 Rackspace +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# 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 nova import db +from nova import test +from nova.network import manager as network_manager + + +HOST = "testhost" + + +class FakeModel(dict): + """Represent a model from the db""" + def __init__(self, *args, **kwargs): + self.update(kwargs) + + def __getattr__(self, name): + return self[name] + + +def fake_network(n): + return {'id': n, + 'label': 'test%d' % n, + 'injected': False, + 'multi_host': False, + 'cidr': '192.168.%d.0/24' % n, + 'cidr_v6': '2001:db8:0:%x::/64' % n, + 'gateway_v6': '2001:db8:0:%x::1' % n, + 'netmask_v6': '64', + 'netmask': '255.255.255.0', + 'bridge': 'fa%d' % n, + 'bridge_interface': 'fake_br%d' % n, + 'gateway': '192.168.%d.1' % n, + 'broadcast': '192.168.%d.255' % n, + 'dns1': '192.168.%d.3' % n, + 'dns2': '192.168.%d.4' % n, + 'vlan': None, + 'host': None, + 'project_id': 'fake_project', + 'vpn_public_address': '192.168.%d.2' % n} + + +def fixed_ips(num_networks, num_ips): + for network in xrange(num_networks): + for ip in xrange(num_ips): + yield {'id': network * ip, + 'network_id': network, + 'address': '192.168.%d.100' % network, + 'instance_id': 0, + 'allocated': False, + # and since network_id and vif_id happen to be equivalent + 'virtual_interface_id': network, + 'floating_ips': [FakeModel(**floating_ip)]} + + +flavor = {'id': 0, + 'rxtx_cap': 3} + + +floating_ip = {'id': 0, + 'address': '10.10.10.10', + 'fixed_ip_id': 0, + 'project_id': None, + 'auto_assigned': False} + + +def vifs(n): + for x in xrange(n): + yield {'id': x, + 'address': 'DE:AD:BE:EF:00:%2x' % x, + 'uuid': '00000000-0000-0000-0000-00000000000000%2d' % x, + 'network_id': x, + 'network': FakeModel(**fake_network(x)), + 'instance_id': 0} + + +def fake_get_instance_nw_info(stubs, n=1, ips_per_vif=2): + network = network_manager.FlatManager(host=HOST) + + def fixed_ips_fake(*args, **kwargs): + return fixed_ips() + + def virtual_interfaces_fake(*args, **kwargs): + return [vif for vif in vifs(n)] + + def instance_type_fake(*args, **kwargs): + return flavor + + stubs.Set(db, 'fixed_ip_get_by_instance', fixed_ips_fake) + stubs.Set(db, 'virtual_interface_get_by_instance', virtual_interface_fake) + stubs.Set(db, 'instance_type_get', instance_type_fake) + + nw_info = self.network.get_instance_nw_info(None, 0, 0, None) From 2791ddb47d62ccb8a7101c71f7d6ca5e021e03d0 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 19 Aug 2011 16:42:52 -0500 Subject: [PATCH 003/100] typo --- nova/tests/fake_network_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index f5bc0368..99159998 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -101,7 +101,7 @@ def fake_get_instance_nw_info(stubs, n=1, ips_per_vif=2): return flavor stubs.Set(db, 'fixed_ip_get_by_instance', fixed_ips_fake) - stubs.Set(db, 'virtual_interface_get_by_instance', virtual_interface_fake) + stubs.Set(db, 'virtual_interface_get_by_instance', virtual_interfaces_fake) stubs.Set(db, 'instance_type_get', instance_type_fake) nw_info = self.network.get_instance_nw_info(None, 0, 0, None) From f471f96074d2321d98cd44d261477c5be2b0ae0a Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 19 Aug 2011 16:44:23 -0500 Subject: [PATCH 004/100] typo --- nova/tests/fake_network_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index 99159998..61b35a9d 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -104,4 +104,4 @@ def fake_get_instance_nw_info(stubs, n=1, ips_per_vif=2): stubs.Set(db, 'virtual_interface_get_by_instance', virtual_interfaces_fake) stubs.Set(db, 'instance_type_get', instance_type_fake) - nw_info = self.network.get_instance_nw_info(None, 0, 0, None) + nw_info = network_manager.get_instance_nw_info(None, 0, 0, None) From d6b17e2f3359df86179175a712766a5f80eb4399 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 19 Aug 2011 16:47:10 -0500 Subject: [PATCH 005/100] typo --- nova/tests/fake_network_info.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index 61b35a9d..1fb3584d 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -18,6 +18,7 @@ from nova import db from nova import test from nova.network import manager as network_manager +from network_ HOST = "testhost" @@ -104,4 +105,4 @@ def fake_get_instance_nw_info(stubs, n=1, ips_per_vif=2): stubs.Set(db, 'virtual_interface_get_by_instance', virtual_interfaces_fake) stubs.Set(db, 'instance_type_get', instance_type_fake) - nw_info = network_manager.get_instance_nw_info(None, 0, 0, None) + nw_info = network.get_instance_nw_info(None, 0, 0, None) From 5d9d818c2b9a69a44c7aad6cd038e6803935b8f3 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 19 Aug 2011 16:48:01 -0500 Subject: [PATCH 006/100] typo --- nova/tests/fake_network_info.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index 1fb3584d..87f6b9c5 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -18,7 +18,6 @@ from nova import db from nova import test from nova.network import manager as network_manager -from network_ HOST = "testhost" From 19f2824e3cbc0ab7cd662b2beb5110c4e295c19a Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 19 Aug 2011 16:58:39 -0500 Subject: [PATCH 007/100] typo --- nova/tests/fake_network_info.py | 1 + nova/tests/test_compute.py | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index 87f6b9c5..3360675d 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -90,6 +90,7 @@ def vifs(n): def fake_get_instance_nw_info(stubs, n=1, ips_per_vif=2): network = network_manager.FlatManager(host=HOST) + network.db = db def fixed_ips_fake(*args, **kwargs): return fixed_ips() diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 925ac733..dd65d81c 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -134,8 +134,7 @@ class ComputeTestCase(test.TestCase): def test_create_instance_defaults_display_name(self): """Verify that an instance cannot be created without a display_name.""" - import pretty_print as pp - pp(fake_get_instance_nw_info(self.stubs, 1, 2)) + print fake_network_info.fake_get_instance_nw_info(self.stubs, 1, 2) self.assertEqual(True, False) cases = [dict(), dict(display_name=None)] for instance in cases: From 8085c7db0e860e7144304df98a5223c3958e7ec9 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 19 Aug 2011 17:00:13 -0500 Subject: [PATCH 008/100] typo --- nova/tests/fake_network_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index 3360675d..d920ab1a 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -93,7 +93,7 @@ def fake_get_instance_nw_info(stubs, n=1, ips_per_vif=2): network.db = db def fixed_ips_fake(*args, **kwargs): - return fixed_ips() + return fixed_ips(n, ips_per_vif) def virtual_interfaces_fake(*args, **kwargs): return [vif for vif in vifs(n)] From 5b809446196f137c5dea58aa277916c5ace6f526 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 19 Aug 2011 17:02:21 -0500 Subject: [PATCH 009/100] fixed formatting string --- nova/tests/fake_network_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index d920ab1a..e0ff71c2 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -81,7 +81,7 @@ floating_ip = {'id': 0, def vifs(n): for x in xrange(n): yield {'id': x, - 'address': 'DE:AD:BE:EF:00:%2x' % x, + 'address': 'DE:AD:BE:EF:00:%02x' % x, 'uuid': '00000000-0000-0000-0000-00000000000000%2d' % x, 'network_id': x, 'network': FakeModel(**fake_network(x)), From e83e740fa237efe4a1b5153088a416af4bfdbe5f Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 19 Aug 2011 17:05:29 -0500 Subject: [PATCH 010/100] added return --- nova/tests/fake_network_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index e0ff71c2..53785635 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -105,4 +105,4 @@ def fake_get_instance_nw_info(stubs, n=1, ips_per_vif=2): stubs.Set(db, 'virtual_interface_get_by_instance', virtual_interfaces_fake) stubs.Set(db, 'instance_type_get', instance_type_fake) - nw_info = network.get_instance_nw_info(None, 0, 0, None) + return network.get_instance_nw_info(None, 0, 0, None) From bd2f356ef99609159a6ad38f7c49367aa9aaf04d Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 19 Aug 2011 17:18:57 -0500 Subject: [PATCH 011/100] who cares --- nova/tests/test_compute.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index dd65d81c..fcb86e32 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -134,7 +134,7 @@ class ComputeTestCase(test.TestCase): def test_create_instance_defaults_display_name(self): """Verify that an instance cannot be created without a display_name.""" - print fake_network_info.fake_get_instance_nw_info(self.stubs, 1, 2) + print fake_network_info.fake_get_instance_nw_info(self.stubs, 2, 1) self.assertEqual(True, False) cases = [dict(), dict(display_name=None)] for instance in cases: From 0cca64a11e27989f8cd52c1ed22d38582814a5e7 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 19 Aug 2011 17:36:52 -0500 Subject: [PATCH 012/100] updated a maths --- nova/tests/fake_network_info.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index 53785635..e73fe044 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -57,7 +57,7 @@ def fake_network(n): def fixed_ips(num_networks, num_ips): for network in xrange(num_networks): for ip in xrange(num_ips): - yield {'id': network * ip, + yield {'id': network * num_ips + ip, 'network_id': network, 'address': '192.168.%d.100' % network, 'instance_id': 0, @@ -82,7 +82,7 @@ def vifs(n): for x in xrange(n): yield {'id': x, 'address': 'DE:AD:BE:EF:00:%02x' % x, - 'uuid': '00000000-0000-0000-0000-00000000000000%2d' % x, + 'uuid': '00000000-0000-0000-0000-00000000000000%02d' % x, 'network_id': x, 'network': FakeModel(**fake_network(x)), 'instance_id': 0} @@ -93,7 +93,7 @@ def fake_get_instance_nw_info(stubs, n=1, ips_per_vif=2): network.db = db def fixed_ips_fake(*args, **kwargs): - return fixed_ips(n, ips_per_vif) + return list(fixed_ips(n, ips_per_vif)) def virtual_interfaces_fake(*args, **kwargs): return [vif for vif in vifs(n)] From 62a662c8bcf1c83194018ffb1b2ba8c8a19181fd Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 19 Aug 2011 17:51:14 -0500 Subject: [PATCH 013/100] updated a maths --- nova/tests/fake_network_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index e73fe044..0c33898c 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -59,7 +59,7 @@ def fixed_ips(num_networks, num_ips): for ip in xrange(num_ips): yield {'id': network * num_ips + ip, 'network_id': network, - 'address': '192.168.%d.100' % network, + 'address': '192.168.%d.1%02d' % (network, ip), 'instance_id': 0, 'allocated': False, # and since network_id and vif_id happen to be equivalent From d38b7d8982f532be4265a51c38244dd09f1769f2 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 19 Aug 2011 18:04:08 -0500 Subject: [PATCH 014/100] finished fake network info, removed testing shims --- nova/tests/test_compute.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index fcb86e32..4f5d36f1 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -35,7 +35,6 @@ from nova import rpc from nova import test from nova import utils from nova.notifier import test_notifier -from nova.tests import fake_network_info LOG = logging.getLogger('nova.tests.compute') FLAGS = flags.FLAGS @@ -134,8 +133,6 @@ class ComputeTestCase(test.TestCase): def test_create_instance_defaults_display_name(self): """Verify that an instance cannot be created without a display_name.""" - print fake_network_info.fake_get_instance_nw_info(self.stubs, 2, 1) - self.assertEqual(True, False) cases = [dict(), dict(display_name=None)] for instance in cases: ref = self.compute_api.create(self.context, From 5d6e617eca00e884c3670fd53769925e47018414 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Mon, 22 Aug 2011 17:46:47 -0500 Subject: [PATCH 015/100] update test_network test_get_instance_nw_info() --- nova/tests/fake_network_info.py | 21 +++++----- nova/tests/test_network.py | 71 ++++++++++++++------------------- 2 files changed, 42 insertions(+), 50 deletions(-) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index 0c33898c..07258519 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -42,8 +42,8 @@ def fake_network(n): 'gateway_v6': '2001:db8:0:%x::1' % n, 'netmask_v6': '64', 'netmask': '255.255.255.0', - 'bridge': 'fa%d' % n, - 'bridge_interface': 'fake_br%d' % n, + 'bridge': 'fake_br%d' % n, + 'bridge_interface': 'fake_eth%d' % n, 'gateway': '192.168.%d.1' % n, 'broadcast': '192.168.%d.255' % n, 'dns1': '192.168.%d.3' % n, @@ -54,26 +54,29 @@ def fake_network(n): 'vpn_public_address': '192.168.%d.2' % n} -def fixed_ips(num_networks, num_ips): +def fixed_ips(num_networks, num_ips, num_floating_ips=0): for network in xrange(num_networks): for ip in xrange(num_ips): - yield {'id': network * num_ips + ip, + id = network * num_ips + ip + f_ips = [floating_ips(id).next() for i in xrange(num_floating_ips)] + yield {'id': id, 'network_id': network, 'address': '192.168.%d.1%02d' % (network, ip), 'instance_id': 0, 'allocated': False, # and since network_id and vif_id happen to be equivalent 'virtual_interface_id': network, - 'floating_ips': [FakeModel(**floating_ip)]} + 'floating_ips': [FakeModel(**ip) for ip in f_ips]} flavor = {'id': 0, 'rxtx_cap': 3} - -floating_ip = {'id': 0, - 'address': '10.10.10.10', - 'fixed_ip_id': 0, +def floating_ips(fixed_ip_id): + for i in xrange(154): + yield {'id': 0, + 'address': '10.10.10.%d' % (i + 100), + 'fixed_ip_id': fixed_ip_id, 'project_id': None, 'auto_assigned': False} diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py index e5c80b6f..7822fbc7 100644 --- a/nova/tests/test_network.py +++ b/nova/tests/test_network.py @@ -14,15 +14,14 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +import mox from nova import db from nova import exception from nova import log as logging from nova import test from nova.network import manager as network_manager - - -import mox +from nova.tests import fake_network_info LOG = logging.getLogger('nova.tests.network') @@ -128,60 +127,50 @@ class FlatNetworkTestCase(test.TestCase): self.network.db = db def test_get_instance_nw_info(self): - self.mox.StubOutWithMock(db, 'fixed_ip_get_by_instance') - self.mox.StubOutWithMock(db, 'virtual_interface_get_by_instance') - self.mox.StubOutWithMock(db, 'instance_type_get') + fake_get_instance_nw_info = fake_network_info.fake_get_instance_nw_info - db.fixed_ip_get_by_instance(mox.IgnoreArg(), - mox.IgnoreArg()).AndReturn(fixed_ips) - db.virtual_interface_get_by_instance(mox.IgnoreArg(), - mox.IgnoreArg()).AndReturn(vifs) - db.instance_type_get(mox.IgnoreArg(), - mox.IgnoreArg()).AndReturn(flavor) - self.mox.ReplayAll() + nw_info = fake_get_instance_nw_info(self.stubs, 0, 2) + self.assertFalse(nw_info) - nw_info = self.network.get_instance_nw_info(None, 0, 0, None) - - self.assertTrue(nw_info) - - for i, nw in enumerate(nw_info): - i8 = i + 8 - check = {'bridge': 'fa%s' % i, + for i, (nw, info) in enumerate(nw_info): + check = {'bridge': 'fake_br%d' % i, 'cidr': '192.168.%s.0/24' % i, - 'cidr_v6': '2001:db%s::/64' % i8, + 'cidr_v6': '2001:db8:0:%x::/64' % i, 'id': i, 'multi_host': False, - 'injected': 'DONTCARE', - 'bridge_interface': 'fake_fa%s' % i, + 'injected': False, + 'bridge_interface': 'fake_eth%d' % i, 'vlan': None} - self.assertDictMatch(nw[0], check) + self.assertDictMatch(nw, check) - check = {'broadcast': '192.168.%s.255' % i, - 'dhcp_server': '192.168.%s.1' % i, - 'dns': 'DONTCARE', - 'gateway': '192.168.%s.1' % i, - 'gateway6': '2001:db%s::1' % i8, + check = {'broadcast': '192.168.%d.255' % i, + 'dhcp_server': '192.168.%d.1' % i, + 'dns': ['192.168.%d.3' % n, '192.168.%d.4' % n] + 'gateway': '192.168.%d.1' % i, + 'gateway6': '2001:db8:0:%x::1' % i, 'ip6s': 'DONTCARE', 'ips': 'DONTCARE', - 'label': 'test%s' % i, - 'mac': 'DE:AD:BE:EF:00:0%s' % i, - 'vif_uuid': ('00000000-0000-0000-0000-000000000000000%s' % - i), - 'rxtx_cap': 'DONTCARE', + 'label': 'test%d' % i, + 'mac': 'DE:AD:BE:EF:00:%02x' % i, + 'vif_uuid': + '00000000-0000-0000-0000-00000000000000%02d' % i, + 'rxtx_cap': 3, 'should_create_vlan': False, 'should_create_bridge': False} - self.assertDictMatch(nw[1], check) + self.assertDictMatch(info, check) check = [{'enabled': 'DONTCARE', - 'ip': '2001:db%s::dcad:beff:feef:%s' % (i8, i), + 'ip': '2001:db8::dcad:beff:feef:%s' % i, 'netmask': '64'}] - self.assertDictListMatch(nw[1]['ip6s'], check) + self.assertDictListMatch(info['ip6s'], check) - check = [{'enabled': '1', - 'ip': '192.168.%s.100' % i, - 'netmask': '255.255.255.0'}] - self.assertDictListMatch(nw[1]['ips'], check) + num_fixed_ips = len(info['ips']) + check = [{'enabled': 'DONTCARE', + 'ip': '192.168.%d.1%02d' % (i, ip_num), + 'netmask': '255.255.255.0'} + for ip_num in xrange(num_fixed_ips)] + self.assertDictListMatch(info['ips'], check) class VlanNetworkTestCase(test.TestCase): From 5b87df82786c394cac225c096bcd4fe57ce3ede9 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Mon, 22 Aug 2011 17:52:54 -0500 Subject: [PATCH 016/100] syntax --- nova/tests/test_network.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py index 7822fbc7..91105ece 100644 --- a/nova/tests/test_network.py +++ b/nova/tests/test_network.py @@ -146,7 +146,7 @@ class FlatNetworkTestCase(test.TestCase): check = {'broadcast': '192.168.%d.255' % i, 'dhcp_server': '192.168.%d.1' % i, - 'dns': ['192.168.%d.3' % n, '192.168.%d.4' % n] + 'dns': ['192.168.%d.3' % n, '192.168.%d.4' % n], 'gateway': '192.168.%d.1' % i, 'gateway6': '2001:db8:0:%x::1' % i, 'ip6s': 'DONTCARE', From a94ba30aaf92e49aef6a3d09a7567cb0795fcccb Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Wed, 24 Aug 2011 15:53:23 +0100 Subject: [PATCH 017/100] Do not require --bridge_interface for FlatDHCPManager Unlike VlanManager, FlatDHCPManager actually works fine without a bridge interface on single host deployments. --- bin/nova-manage | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index 2e0bd0ec..bd42c24d 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -714,8 +714,7 @@ class NetworkCommands(object): bridge_interface = bridge_interface or FLAGS.flat_interface or \ FLAGS.vlan_interface if not bridge_interface: - interface_required = ['nova.network.manager.FlatDHCPManager', - 'nova.network.manager.VlanManager'] + interface_required = ['nova.network.manager.VlanManager'] if FLAGS.network_manager in interface_required: raise exception.NetworkNotCreated(req='--bridge_interface') From d1c4eef4cf07664189434d1ee3db0919313949a2 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 25 Aug 2011 15:53:13 -0500 Subject: [PATCH 018/100] updated libvirt tests to use fake_network_info --- nova/tests/fake_network_info.py | 30 ++++++++++++++++---- nova/tests/test_libvirt.py | 49 ++++++++++++++++++--------------- 2 files changed, 52 insertions(+), 27 deletions(-) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index 07258519..0bf117a9 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -16,11 +16,13 @@ # under the License. from nova import db +from nova import flags from nova import test from nova.network import manager as network_manager HOST = "testhost" +FLAGS = flags.FLAGS class FakeModel(dict): @@ -32,15 +34,14 @@ class FakeModel(dict): return self[name] -def fake_network(n): - return {'id': n, +def fake_network(n, ipv6=None): + if ipv6 = None: + ipv6 = Flags.use_ipv6 + rval = {'id': n, 'label': 'test%d' % n, 'injected': False, 'multi_host': False, 'cidr': '192.168.%d.0/24' % n, - 'cidr_v6': '2001:db8:0:%x::/64' % n, - 'gateway_v6': '2001:db8:0:%x::1' % n, - 'netmask_v6': '64', 'netmask': '255.255.255.0', 'bridge': 'fake_br%d' % n, 'bridge_interface': 'fake_eth%d' % n, @@ -52,6 +53,10 @@ def fake_network(n): 'host': None, 'project_id': 'fake_project', 'vpn_public_address': '192.168.%d.2' % n} + if ipv6: + rval['cidr_v6'] = '2001:db8:0:%x::/64' % n + rval['gateway_v6'] = '2001:db8:0:%x::1' % n + rval['netmask_v6'] = '64' def fixed_ips(num_networks, num_ips, num_floating_ips=0): @@ -91,7 +96,22 @@ def vifs(n): 'instance_id': 0} +def ipv4_like(ip, s): + ip = ip.split('.') + s = s.split('.') + + for i, octet in enumerate(s): + if octet == '*': + continue + if octet != ip[i]: + return False + return True + + def fake_get_instance_nw_info(stubs, n=1, ips_per_vif=2): + # 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 diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 6a213b4f..1b5a2d55 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -36,6 +36,7 @@ from nova.api.ec2 import cloud from nova.compute import power_state from nova.virt.libvirt import connection from nova.virt.libvirt import firewall +from nova.tests import fake_network_info libvirt = None FLAGS = flags.FLAGS @@ -45,7 +46,8 @@ def _concurrency(wait, done, target): wait.wait() done.send() - +_fake_network_info = fake_network_info.fake_get_instance_nw_info +_ipv4_like = fake_network_info.ipv4_like def _create_network_info(count=1, ipv6=None): if ipv6 is None: ipv6 = FLAGS.use_ipv6 @@ -276,12 +278,12 @@ class LibvirtConnTestCase(test.TestCase): instance_ref = db.instance_create(self.context, self.test_instance) result = conn._prepare_xml_info(instance_ref, - _create_network_info(), + _fake_network_info(self.stubs, 1), False) self.assertTrue(len(result['nics']) == 1) result = conn._prepare_xml_info(instance_ref, - _create_network_info(2), + _fake_network_info(self.stubs, 2), False) self.assertTrue(len(result['nics']) == 2) @@ -406,7 +408,7 @@ class LibvirtConnTestCase(test.TestCase): def test_multi_nic(self): instance_data = dict(self.test_instance) - network_info = _create_network_info(2) + network_info = _fake_network_info(self.stubs, 2) conn = connection.LibvirtConnection(True) instance_ref = db.instance_create(self.context, instance_data) xml = conn.to_xml(instance_ref, network_info, False) @@ -416,9 +418,9 @@ class LibvirtConnTestCase(test.TestCase): parameters = interfaces[0].findall('./filterref/parameter') self.assertEquals(interfaces[0].get('type'), 'bridge') self.assertEquals(parameters[0].get('name'), 'IP') - self.assertEquals(parameters[0].get('value'), '10.11.12.13') + self.assertTrue(_ipv4_like(parameters[0].get('value'), '192.168') self.assertEquals(parameters[1].get('name'), 'DHCPSERVER') - self.assertEquals(parameters[1].get('value'), '10.0.0.1') + self.assertTrue(_ipv4_like(parameters[1].get('value'), '192.168.*.1') def _check_xml_and_container(self, instance): user_context = context.RequestContext(self.user_id, @@ -432,7 +434,7 @@ class LibvirtConnTestCase(test.TestCase): uri = conn.get_uri() self.assertEquals(uri, 'lxc:///') - network_info = _create_network_info() + network_info = _fake_network_info(self.stubs, 1) xml = conn.to_xml(instance_ref, network_info) tree = xml_to_tree(xml) @@ -503,9 +505,11 @@ class LibvirtConnTestCase(test.TestCase): common_checks = [ (lambda t: t.find('.').tag, 'domain'), (lambda t: t.find(parameter).get('name'), 'IP'), - (lambda t: t.find(parameter).get('value'), '10.11.12.13'), + (lambda t: _ipv4_like(t.find(parameter).get('value'), '192.168'), + True), (lambda t: t.findall(parameter)[1].get('name'), 'DHCPSERVER'), - (lambda t: t.findall(parameter)[1].get('value'), '10.0.0.1'), + (lambda t: _ipv4_like(t.findall(parameter)[1].get('value'), + '192.168.*.1'), True), (lambda t: t.find('./devices/serial/source').get( 'path').split('/')[1], 'console.log'), (lambda t: t.find('./memory').text, '2097152')] @@ -530,7 +534,7 @@ class LibvirtConnTestCase(test.TestCase): uri = conn.get_uri() self.assertEquals(uri, expected_uri) - network_info = _create_network_info() + network_info = _fake_network_info(self.stubs, 1) xml = conn.to_xml(instance_ref, network_info, rescue) tree = xml_to_tree(xml) for i, (check, expected_result) in enumerate(checks): @@ -645,7 +649,7 @@ class LibvirtConnTestCase(test.TestCase): self.create_fake_libvirt_mock() instance_ref = db.instance_create(self.context, self.test_instance) - network_info = _create_network_info() + network_info = _fake_network_info(self.stubs, 1) # Start test self.mox.ReplayAll() @@ -828,7 +832,7 @@ class LibvirtConnTestCase(test.TestCase): conn.firewall_driver.setattr('setup_basic_filtering', fake_none) conn.firewall_driver.setattr('prepare_instance_filter', fake_none) - network_info = _create_network_info() + network_info = _fake_network_info(self.stubs, 1) try: conn.spawn(self.context, instance, network_info) @@ -1062,7 +1066,7 @@ class IptablesFirewallTestCase(test.TestCase): from nova.network import linux_net linux_net.iptables_manager.execute = fake_iptables_execute - network_info = _create_network_info() + network_info = _fake_network_info(self.stubs, 1) self.fw.prepare_instance_filter(instance_ref, network_info) self.fw.apply_instance_filter(instance_ref, network_info) @@ -1076,7 +1080,8 @@ class IptablesFirewallTestCase(test.TestCase): instance_chain = None for rule in self.out_rules: # This is pretty crude, but it'll do for now - if '-d 10.11.12.13 -j' in rule: + # last two octets change + if re.search('-d 192.168.[0-9]{1,3}.[0-9]{1,3} -j', rule): instance_chain = rule.split(' ')[-1] break self.assertTrue(instance_chain, "The instance chain wasn't added") @@ -1112,14 +1117,14 @@ class IptablesFirewallTestCase(test.TestCase): def test_filters_for_instance_with_ip_v6(self): self.flags(use_ipv6=True) - network_info = _create_network_info() + network_info = _fake_network_info(self.stubs, 1) rulesv4, rulesv6 = self.fw._filters_for_instance("fake", network_info) self.assertEquals(len(rulesv4), 2) self.assertEquals(len(rulesv6), 3) def test_filters_for_instance_without_ip_v6(self): self.flags(use_ipv6=False) - network_info = _create_network_info() + network_info = _fake_network_info(self.stubs, 1) rulesv4, rulesv6 = self.fw._filters_for_instance("fake", network_info) self.assertEquals(len(rulesv4), 2) self.assertEquals(len(rulesv6), 0) @@ -1129,7 +1134,7 @@ class IptablesFirewallTestCase(test.TestCase): ipv6_rules_per_network = 3 networks_count = 5 instance_ref = self._create_instance_ref() - network_info = _create_network_info(networks_count) + network_info = _fake_network_info(self.stubs, networks_count) ipv4_len = len(self.fw.iptables.ipv4['filter'].rules) ipv6_len = len(self.fw.iptables.ipv6['filter'].rules) inst_ipv4, inst_ipv6 = self.fw.instance_rules(instance_ref, @@ -1169,7 +1174,7 @@ class IptablesFirewallTestCase(test.TestCase): instance_ref = self._create_instance_ref() _setup_networking(instance_ref['id'], self.test_ip) - network_info = _create_network_info() + network_info = _fake_network_info(self.stubs, 1) self.fw.setup_basic_filtering(instance_ref, network_info) self.fw.prepare_instance_filter(instance_ref, network_info) self.fw.apply_instance_filter(instance_ref, network_info) @@ -1190,7 +1195,7 @@ class IptablesFirewallTestCase(test.TestCase): # create a firewall via setup_basic_filtering like libvirt_conn.spawn # should have a chain with 0 rules - network_info = _create_network_info(1) + network_info = _fake_network_info(self.stubs, 1) self.fw.setup_basic_filtering(instance_ref, network_info) self.assertTrue('provider' in self.fw.iptables.ipv4['filter'].chains) rules = [rule for rule in self.fw.iptables.ipv4['filter'].rules @@ -1390,7 +1395,7 @@ class NWFilterTestCase(test.TestCase): self.security_group.id) instance = db.instance_get(self.context, inst_id) - network_info = _create_network_info() + network_info = _fake_network_info(self.stubs, 1) self.fw.setup_basic_filtering(instance, network_info) self.fw.prepare_instance_filter(instance, network_info) self.fw.apply_instance_filter(instance, network_info) @@ -1400,7 +1405,7 @@ class NWFilterTestCase(test.TestCase): def test_create_network_filters(self): instance_ref = self._create_instance() - network_info = _create_network_info(3) + network_info = _fake_network_info(self.stubs, 3) result = self.fw._create_network_filters(instance_ref, network_info, "fake") @@ -1424,7 +1429,7 @@ class NWFilterTestCase(test.TestCase): instance = db.instance_get(self.context, inst_id) _setup_networking(instance_ref['id'], self.test_ip) - network_info = _create_network_info() + network_info = _fake_network_info(self.stubs, 1) self.fw.setup_basic_filtering(instance, network_info) self.fw.prepare_instance_filter(instance, network_info) self.fw.apply_instance_filter(instance, network_info) From 06fdc8efecf09c86f174b88026e8b46b4716cc25 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 25 Aug 2011 16:02:52 -0500 Subject: [PATCH 019/100] fixed a couple of syntax errors --- nova/tests/fake_network_info.py | 2 +- nova/tests/test_libvirt.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index 0bf117a9..113647d7 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -35,7 +35,7 @@ class FakeModel(dict): def fake_network(n, ipv6=None): - if ipv6 = None: + if ipv6 == None: ipv6 = Flags.use_ipv6 rval = {'id': n, 'label': 'test%d' % n, diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 1b5a2d55..06ad7d13 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -418,9 +418,9 @@ class LibvirtConnTestCase(test.TestCase): parameters = interfaces[0].findall('./filterref/parameter') self.assertEquals(interfaces[0].get('type'), 'bridge') self.assertEquals(parameters[0].get('name'), 'IP') - self.assertTrue(_ipv4_like(parameters[0].get('value'), '192.168') + self.assertTrue(_ipv4_like(parameters[0].get('value'), '192.168')) self.assertEquals(parameters[1].get('name'), 'DHCPSERVER') - self.assertTrue(_ipv4_like(parameters[1].get('value'), '192.168.*.1') + self.assertTrue(_ipv4_like(parameters[1].get('value'), '192.168.*.1')) def _check_xml_and_container(self, instance): user_context = context.RequestContext(self.user_id, From 92a81a9f67c0b52ba4aee56ca5b56088a0621d6e Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 25 Aug 2011 16:10:25 -0500 Subject: [PATCH 020/100] typo --- nova/tests/fake_network_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index 113647d7..295ac8a9 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -36,7 +36,7 @@ class FakeModel(dict): def fake_network(n, ipv6=None): if ipv6 == None: - ipv6 = Flags.use_ipv6 + ipv6 = FLAGS.use_ipv6 rval = {'id': n, 'label': 'test%d' % n, 'injected': False, From 77c8bd05d3e4fbd4c232dbbb6219aca3456f4942 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 25 Aug 2011 16:49:09 -0500 Subject: [PATCH 021/100] forget a return --- nova/tests/fake_network_info.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index 295ac8a9..b05cf7c9 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -58,6 +58,8 @@ def fake_network(n, ipv6=None): rval['gateway_v6'] = '2001:db8:0:%x::1' % n rval['netmask_v6'] = '64' + return rval + def fixed_ips(num_networks, num_ips, num_floating_ips=0): for network in xrange(num_networks): From b907aca9b7acb7032a42f3b7c6bc8e55cb4f486e Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 25 Aug 2011 17:04:26 -0500 Subject: [PATCH 022/100] altered fake network model --- nova/tests/fake_network_info.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index b05cf7c9..47f9abd0 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -42,10 +42,13 @@ def fake_network(n, ipv6=None): 'injected': False, 'multi_host': False, 'cidr': '192.168.%d.0/24' % n, + 'cidr_v6': None, 'netmask': '255.255.255.0', + 'netmask_v6': None, 'bridge': 'fake_br%d' % n, 'bridge_interface': 'fake_eth%d' % n, 'gateway': '192.168.%d.1' % n, + 'gateway_v6': None, 'broadcast': '192.168.%d.255' % n, 'dns1': '192.168.%d.3' % n, 'dns2': '192.168.%d.4' % n, From 9f69ecf95c77f7b26162916fcbb97de2b7d6bf74 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 26 Aug 2011 12:24:35 -0500 Subject: [PATCH 023/100] misplaced comma... --- nova/tests/fake_network_info.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index 47f9abd0..81edd998 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -60,6 +60,8 @@ def fake_network(n, ipv6=None): rval['cidr_v6'] = '2001:db8:0:%x::/64' % n rval['gateway_v6'] = '2001:db8:0:%x::1' % n rval['netmask_v6'] = '64' + print 'asdf %s' % rval['cidr_v6'] + print type(rval['cidr_v6']) return rval From 5f2d01f5127c0d690707501138bd79babdd0f4cf Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 26 Aug 2011 12:26:09 -0500 Subject: [PATCH 024/100] forgot test print statements --- nova/tests/fake_network_info.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index 81edd998..47f9abd0 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -60,8 +60,6 @@ def fake_network(n, ipv6=None): rval['cidr_v6'] = '2001:db8:0:%x::/64' % n rval['gateway_v6'] = '2001:db8:0:%x::1' % n rval['netmask_v6'] = '64' - print 'asdf %s' % rval['cidr_v6'] - print type(rval['cidr_v6']) return rval From ad542589bbef3c4093cdfa222d74b36e37e5e476 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 26 Aug 2011 12:28:14 -0500 Subject: [PATCH 025/100] added memory_mb to instance flavor test model --- nova/tests/fake_network_info.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index 47f9abd0..6feb1e8f 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -80,7 +80,8 @@ def fixed_ips(num_networks, num_ips, num_floating_ips=0): flavor = {'id': 0, - 'rxtx_cap': 3} + 'rxtx_cap': 3, + 'memory_mb': 512} def floating_ips(fixed_ip_id): for i in xrange(154): From f3e4e0734414e08943acd9bd17e81f76f593fed3 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 26 Aug 2011 12:29:44 -0500 Subject: [PATCH 026/100] added vcpus to instance flavor test model --- nova/tests/fake_network_info.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index 6feb1e8f..d89ddbe9 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -81,7 +81,8 @@ def fixed_ips(num_networks, num_ips, num_floating_ips=0): flavor = {'id': 0, 'rxtx_cap': 3, - 'memory_mb': 512} + 'memory_mb': 512, + 'vcpus': 2} def floating_ips(fixed_ip_id): for i in xrange(154): From 7f4e3e45d7b77fb8a2406729b27a789a6e51d057 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 26 Aug 2011 12:33:08 -0500 Subject: [PATCH 027/100] updated instance type fake model --- nova/tests/fake_network_info.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index d89ddbe9..a8e36c06 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -80,9 +80,14 @@ def fixed_ips(num_networks, num_ips, num_floating_ips=0): flavor = {'id': 0, - 'rxtx_cap': 3, + 'name': 'fake_flavor', 'memory_mb': 512, - 'vcpus': 2} + '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): From 00a7b06d10a858bbad1301819847bc2d2629509e Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 26 Aug 2011 13:26:33 -0500 Subject: [PATCH 028/100] update libvirt tests --- nova/tests/test_libvirt.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 06ad7d13..02b2f0cf 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -1377,9 +1377,9 @@ class NWFilterTestCase(test.TestCase): _setup_networking(instance_ref['id'], self.test_ip) - def _ensure_all_called(): + def _ensure_all_called(mac): instance_filter = 'nova-instance-%s-%s' % (instance_ref['name'], - 'fake') + mac.translate(None, ':') secgroup_filter = 'nova-secgroup-%s' % self.security_group['id'] for required in [secgroup_filter, 'allow-dhcp-server', 'no-arp-spoofing', 'no-ip-spoofing', @@ -1396,10 +1396,15 @@ class NWFilterTestCase(test.TestCase): instance = db.instance_get(self.context, inst_id) network_info = _fake_network_info(self.stubs, 1) + # since there is one (network_info) there is one vif + # pass this vif's mac to _ensure_all_called() + # to set the instance_filter properly + mac = network_info[0][1]['mac'] + self.fw.setup_basic_filtering(instance, network_info) self.fw.prepare_instance_filter(instance, network_info) self.fw.apply_instance_filter(instance, network_info) - _ensure_all_called() + _ensure_all_called(mac) self.teardown_security_group() db.instance_destroy(context.get_admin_context(), instance_ref['id']) From bdffad1bfd2c461ef47089ae6cc7144dba4e9e49 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 26 Aug 2011 13:28:17 -0500 Subject: [PATCH 029/100] forgot ) --- nova/tests/test_libvirt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 02b2f0cf..ded5a99a 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -1379,7 +1379,7 @@ class NWFilterTestCase(test.TestCase): def _ensure_all_called(mac): instance_filter = 'nova-instance-%s-%s' % (instance_ref['name'], - mac.translate(None, ':') + mac.translate(None, ':')) secgroup_filter = 'nova-secgroup-%s' % self.security_group['id'] for required in [secgroup_filter, 'allow-dhcp-server', 'no-arp-spoofing', 'no-ip-spoofing', From a8c249a706ca5dff175b1a4048c3a41c66effde3 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 26 Aug 2011 13:32:16 -0500 Subject: [PATCH 030/100] updated fake values --- nova/tests/fake_network_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index a8e36c06..079cf539 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -81,7 +81,7 @@ def fixed_ips(num_networks, num_ips, num_floating_ips=0): flavor = {'id': 0, 'name': 'fake_flavor', - 'memory_mb': 512, + 'memory_mb': 2048, 'vcpus': 2, 'local_gb': 10, 'flavor_id': 0, From 437d411c62714422d9c6e8601f06e6801894f7e9 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 26 Aug 2011 13:37:25 -0500 Subject: [PATCH 031/100] updated fake values --- nova/tests/test_libvirt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index ded5a99a..6947a70b 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -1120,7 +1120,7 @@ class IptablesFirewallTestCase(test.TestCase): network_info = _fake_network_info(self.stubs, 1) rulesv4, rulesv6 = self.fw._filters_for_instance("fake", network_info) self.assertEquals(len(rulesv4), 2) - self.assertEquals(len(rulesv6), 3) + self.assertEquals(len(rulesv6), 1) def test_filters_for_instance_without_ip_v6(self): self.flags(use_ipv6=False) From b3ec3ae1c4ee43d2729b7af3f81643312ea51661 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 26 Aug 2011 13:44:26 -0500 Subject: [PATCH 032/100] updated fake values --- nova/tests/test_libvirt.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 6947a70b..1b09a330 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -1130,11 +1130,14 @@ class IptablesFirewallTestCase(test.TestCase): self.assertEquals(len(rulesv6), 0) def test_multinic_iptables(self): - ipv4_rules_per_network = 2 - ipv6_rules_per_network = 3 + ipv4_rules_per_addr = 1 + ipv4_addr_per_network = 2 + ipv6_rules_per_addr = 1 + ipv6_addr_per_network = 1 networks_count = 5 instance_ref = self._create_instance_ref() - network_info = _fake_network_info(self.stubs, networks_count) + network_info = _fake_network_info(self.stubs, networks_count, + ipv4_addr_per_network) ipv4_len = len(self.fw.iptables.ipv4['filter'].rules) ipv6_len = len(self.fw.iptables.ipv6['filter'].rules) inst_ipv4, inst_ipv6 = self.fw.instance_rules(instance_ref, @@ -1145,9 +1148,9 @@ class IptablesFirewallTestCase(test.TestCase): ipv4_network_rules = len(ipv4) - len(inst_ipv4) - ipv4_len ipv6_network_rules = len(ipv6) - len(inst_ipv6) - ipv6_len self.assertEquals(ipv4_network_rules, - ipv4_rules_per_network * networks_count) + ipv4_rules_per_addr * ipv4_addr_per_network * networks_count) self.assertEquals(ipv6_network_rules, - ipv6_rules_per_network * networks_count) + ipv6_rules_per_addr * ipv4_addr_per_network * networks_count) def test_do_refresh_security_group_rules(self): instance_ref = self._create_instance_ref() From faa065e49f92133ba3c4d2f84e24ac5726e1a562 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 26 Aug 2011 13:47:54 -0500 Subject: [PATCH 033/100] updated fake values --- nova/tests/test_libvirt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 1b09a330..d8bc9575 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -1150,7 +1150,7 @@ class IptablesFirewallTestCase(test.TestCase): self.assertEquals(ipv4_network_rules, ipv4_rules_per_addr * ipv4_addr_per_network * networks_count) self.assertEquals(ipv6_network_rules, - ipv6_rules_per_addr * ipv4_addr_per_network * networks_count) + ipv6_rules_per_addr * ipv6_addr_per_network * networks_count) def test_do_refresh_security_group_rules(self): instance_ref = self._create_instance_ref() From 6ab29be957da0a00840bab1938363ca3884f5f36 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 26 Aug 2011 15:09:39 -0500 Subject: [PATCH 034/100] couple of pep8s --- nova/tests/fake_network_info.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py index 079cf539..2e8cf60e 100644 --- a/nova/tests/fake_network_info.py +++ b/nova/tests/fake_network_info.py @@ -89,6 +89,7 @@ flavor = {'id': 0, 'rxtx_quota': 0, 'rxtx_cap': 3} + def floating_ips(fixed_ip_id): for i in xrange(154): yield {'id': 0, From d921bdf1568c646c1dd416a32c6d2afa9c8eb662 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 26 Aug 2011 16:55:52 -0500 Subject: [PATCH 035/100] stubbed some stuff in test_libvirt --- nova/tests/test_libvirt.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index d8bc9575..58e78daf 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -1063,10 +1063,17 @@ class IptablesFirewallTestCase(test.TestCase): return '', '' print cmd, kwargs + def get_fixed_ips(*args, **kwargs): + ips = [] + for network, info in network_info: + ips.extend(info['ips']) + return [ip['ip'] for ip in ips] + from nova.network import linux_net linux_net.iptables_manager.execute = fake_iptables_execute network_info = _fake_network_info(self.stubs, 1) + self.stubs.Set(self.db, 'instance_get_fixed_addresses', get_fixed_ips) self.fw.prepare_instance_filter(instance_ref, network_info) self.fw.apply_instance_filter(instance_ref, network_info) From 97e95b98927dba486fe1601cbc6b49a5cfc88a2b Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 26 Aug 2011 17:00:06 -0500 Subject: [PATCH 036/100] updated libvirt test --- nova/tests/test_libvirt.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 58e78daf..2ff6b395 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -1073,7 +1073,7 @@ class IptablesFirewallTestCase(test.TestCase): linux_net.iptables_manager.execute = fake_iptables_execute network_info = _fake_network_info(self.stubs, 1) - self.stubs.Set(self.db, 'instance_get_fixed_addresses', get_fixed_ips) + self.stubs.Set(db, 'instance_get_fixed_addresses', get_fixed_ips) self.fw.prepare_instance_filter(instance_ref, network_info) self.fw.apply_instance_filter(instance_ref, network_info) @@ -1111,10 +1111,11 @@ class IptablesFirewallTestCase(test.TestCase): self.assertTrue(len(filter(regex.match, self.out_rules)) > 0, "ICMP Echo Request acceptance rule wasn't added") - regex = re.compile('-A .* -j ACCEPT -p tcp -m multiport ' - '--dports 80:81 -s %s' % (src_ip,)) - self.assertTrue(len(filter(regex.match, self.out_rules)) > 0, - "TCP port 80/81 acceptance rule wasn't added") + for ip in get_fixed_ips(): + regex = re.compile('-A .* -j ACCEPT -p tcp -m multiport ' + '--dports 80:81 -s %s' % ip) + self.assertTrue(len(filter(regex.match, self.out_rules)) > 0, + "TCP port 80/81 acceptance rule wasn't added") regex = re.compile('-A .* -j ACCEPT -p tcp ' '-m multiport --dports 80:81 -s 192.168.10.0/24') From d97974ec9f7a6503e037f4efa0f8a2081ebf0081 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 26 Aug 2011 17:04:30 -0500 Subject: [PATCH 037/100] removed self.test ip and _setup_networking from libvirt --- nova/tests/test_libvirt.py | 64 ++------------------------------------ 1 file changed, 3 insertions(+), 61 deletions(-) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 2ff6b395..fe5470a6 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -41,57 +41,14 @@ from nova.tests import fake_network_info libvirt = None FLAGS = flags.FLAGS +_fake_network_info = fake_network_info.fake_get_instance_nw_info +_ipv4_like = fake_network_info.ipv4_like + def _concurrency(wait, done, target): wait.wait() done.send() -_fake_network_info = fake_network_info.fake_get_instance_nw_info -_ipv4_like = fake_network_info.ipv4_like -def _create_network_info(count=1, ipv6=None): - if ipv6 is None: - ipv6 = FLAGS.use_ipv6 - fake = 'fake' - fake_ip = '10.11.12.13' - fake_ip_2 = '0.0.0.1' - fake_ip_3 = '0.0.0.1' - fake_vlan = 100 - fake_bridge_interface = 'eth0' - network = {'bridge': fake, - 'cidr': fake_ip, - 'cidr_v6': fake_ip, - 'gateway_v6': fake, - 'vlan': fake_vlan, - 'bridge_interface': fake_bridge_interface} - mapping = {'mac': fake, - 'dhcp_server': '10.0.0.1', - 'gateway': fake, - 'gateway6': fake, - 'ips': [{'ip': fake_ip}, {'ip': fake_ip}]} - if ipv6: - mapping['ip6s'] = [{'ip': fake_ip}, - {'ip': fake_ip_2}, - {'ip': fake_ip_3}] - return [(network, mapping) for x in xrange(0, count)] - - -def _setup_networking(instance_id, ip='1.2.3.4', mac='56:12:12:12:12:12'): - ctxt = context.get_admin_context() - network_ref = db.project_get_networks(ctxt, - 'fake', - associate=True)[0] - vif = {'address': mac, - 'network_id': network_ref['id'], - 'instance_id': instance_id} - vif_ref = db.virtual_interface_create(ctxt, vif) - - fixed_ip = {'address': ip, - 'network_id': network_ref['id'], - 'virtual_interface_id': vif_ref['id']} - db.fixed_ip_create(ctxt, fixed_ip) - db.fixed_ip_update(ctxt, ip, {'allocated': True, - 'instance_id': instance_id}) - class CacheConcurrencyTestCase(test.TestCase): def setUp(self): @@ -164,7 +121,6 @@ class LibvirtConnTestCase(test.TestCase): self.context = context.get_admin_context() self.flags(instances_path='') self.call_libvirt_dependant_setup = False - self.test_ip = '10.11.12.13' test_instance = {'memory_kb': '1024000', 'basepath': '/some/path', @@ -426,7 +382,6 @@ class LibvirtConnTestCase(test.TestCase): user_context = context.RequestContext(self.user_id, self.project_id) instance_ref = db.instance_create(user_context, instance) - _setup_networking(instance_ref['id'], self.test_ip) self.flags(libvirt_type='lxc') conn = connection.LibvirtConnection(True) @@ -458,8 +413,6 @@ class LibvirtConnTestCase(test.TestCase): network_ref = db.project_get_networks(context.get_admin_context(), self.project_id)[0] - _setup_networking(instance_ref['id'], self.test_ip) - type_uri_map = {'qemu': ('qemu:///system', [(lambda t: t.find('.').get('type'), 'qemu'), (lambda t: t.find('./os/type').text, 'hvm'), @@ -925,7 +878,6 @@ class IptablesFirewallTestCase(test.TestCase): """setup_basic_rules in nwfilter calls this.""" pass self.fake_libvirt_connection = FakeLibvirtConnection() - self.test_ip = '10.11.12.13' self.fw = firewall.IptablesFirewallDriver( get_connection=lambda: self.fake_libvirt_connection) @@ -989,10 +941,6 @@ class IptablesFirewallTestCase(test.TestCase): def test_static_filters(self): instance_ref = self._create_instance_ref() src_instance_ref = self._create_instance_ref() - src_ip = '10.11.12.14' - src_mac = '56:12:12:12:12:13' - _setup_networking(instance_ref['id'], self.test_ip, src_mac) - _setup_networking(src_instance_ref['id'], src_ip) admin_ctxt = context.get_admin_context() secgroup = db.security_group_create(admin_ctxt, @@ -1184,7 +1132,6 @@ class IptablesFirewallTestCase(test.TestCase): fakefilter.nwfilterLookupByName instance_ref = self._create_instance_ref() - _setup_networking(instance_ref['id'], self.test_ip) network_info = _fake_network_info(self.stubs, 1) self.fw.setup_basic_filtering(instance_ref, network_info) self.fw.prepare_instance_filter(instance_ref, network_info) @@ -1200,7 +1147,6 @@ class IptablesFirewallTestCase(test.TestCase): def test_provider_firewall_rules(self): # setup basic instance data instance_ref = self._create_instance_ref() - _setup_networking(instance_ref['id'], self.test_ip) # FRAGILE: peeks at how the firewall names chains chain_name = 'inst-%s' % instance_ref['id'] @@ -1270,7 +1216,6 @@ class NWFilterTestCase(test.TestCase): self.fake_libvirt_connection = Mock() - self.test_ip = '10.11.12.13' self.fw = firewall.NWFilterFirewall( lambda: self.fake_libvirt_connection) @@ -1386,8 +1331,6 @@ class NWFilterTestCase(test.TestCase): instance_ref = self._create_instance() inst_id = instance_ref['id'] - _setup_networking(instance_ref['id'], self.test_ip) - def _ensure_all_called(mac): instance_filter = 'nova-instance-%s-%s' % (instance_ref['name'], mac.translate(None, ':')) @@ -1444,7 +1387,6 @@ class NWFilterTestCase(test.TestCase): instance = db.instance_get(self.context, inst_id) - _setup_networking(instance_ref['id'], self.test_ip) network_info = _fake_network_info(self.stubs, 1) self.fw.setup_basic_filtering(instance, network_info) self.fw.prepare_instance_filter(instance, network_info) From 499df1d358c34df44093344be4ba8790fde186c8 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 1 Sep 2011 15:50:38 -0500 Subject: [PATCH 038/100] renamed fake_network_info.py --- nova/tests/fake_network_info.py | 144 -------------------------------- nova/tests/test_libvirt.py | 6 +- nova/tests/test_network.py | 4 +- 3 files changed, 5 insertions(+), 149 deletions(-) delete mode 100644 nova/tests/fake_network_info.py diff --git a/nova/tests/fake_network_info.py b/nova/tests/fake_network_info.py deleted file mode 100644 index 2e8cf60e..00000000 --- a/nova/tests/fake_network_info.py +++ /dev/null @@ -1,144 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2011 Rackspace -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# 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 nova import db -from nova import flags -from nova import test -from nova.network import manager as network_manager - - -HOST = "testhost" -FLAGS = flags.FLAGS - - -class FakeModel(dict): - """Represent a model from the db""" - def __init__(self, *args, **kwargs): - self.update(kwargs) - - def __getattr__(self, name): - return self[name] - - -def fake_network(n, ipv6=None): - if ipv6 == None: - ipv6 = FLAGS.use_ipv6 - rval = {'id': n, - 'label': 'test%d' % n, - 'injected': False, - 'multi_host': False, - 'cidr': '192.168.%d.0/24' % n, - 'cidr_v6': None, - 'netmask': '255.255.255.0', - 'netmask_v6': None, - 'bridge': 'fake_br%d' % n, - 'bridge_interface': 'fake_eth%d' % n, - 'gateway': '192.168.%d.1' % n, - 'gateway_v6': None, - 'broadcast': '192.168.%d.255' % n, - 'dns1': '192.168.%d.3' % n, - 'dns2': '192.168.%d.4' % n, - 'vlan': None, - 'host': None, - 'project_id': 'fake_project', - 'vpn_public_address': '192.168.%d.2' % n} - if ipv6: - rval['cidr_v6'] = '2001:db8:0:%x::/64' % n - rval['gateway_v6'] = '2001:db8:0:%x::1' % n - rval['netmask_v6'] = '64' - - return rval - - -def fixed_ips(num_networks, num_ips, num_floating_ips=0): - for network in xrange(num_networks): - for ip in xrange(num_ips): - id = network * num_ips + ip - f_ips = [floating_ips(id).next() for i in xrange(num_floating_ips)] - yield {'id': id, - 'network_id': network, - 'address': '192.168.%d.1%02d' % (network, ip), - 'instance_id': 0, - 'allocated': False, - # and since network_id and vif_id happen to be equivalent - 'virtual_interface_id': network, - 'floating_ips': [FakeModel(**ip) for ip in 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': 0, - 'address': '10.10.10.%d' % (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, - 'address': 'DE:AD:BE:EF:00:%02x' % x, - 'uuid': '00000000-0000-0000-0000-00000000000000%02d' % x, - 'network_id': x, - 'network': FakeModel(**fake_network(x)), - 'instance_id': 0} - - -def ipv4_like(ip, s): - ip = ip.split('.') - s = s.split('.') - - for i, octet in enumerate(s): - if octet == '*': - continue - if octet != ip[i]: - return False - return True - - -def fake_get_instance_nw_info(stubs, n=1, ips_per_vif=2): - # 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 - - def fixed_ips_fake(*args, **kwargs): - return list(fixed_ips(n, ips_per_vif)) - - def virtual_interfaces_fake(*args, **kwargs): - return [vif for vif in vifs(n)] - - def instance_type_fake(*args, **kwargs): - return flavor - - stubs.Set(db, 'fixed_ip_get_by_instance', fixed_ips_fake) - stubs.Set(db, 'virtual_interface_get_by_instance', virtual_interfaces_fake) - stubs.Set(db, 'instance_type_get', instance_type_fake) - - return network.get_instance_nw_info(None, 0, 0, None) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index fe5470a6..190e197f 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -36,13 +36,13 @@ from nova.api.ec2 import cloud from nova.compute import power_state from nova.virt.libvirt import connection from nova.virt.libvirt import firewall -from nova.tests import fake_network_info +from nova.tests import fake_network libvirt = None FLAGS = flags.FLAGS -_fake_network_info = fake_network_info.fake_get_instance_nw_info -_ipv4_like = fake_network_info.ipv4_like +_fake_network_info = fake_network.fake_get_instance_nw_info +_ipv4_like = fake_network.ipv4_like def _concurrency(wait, done, target): diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py index 803868cd..a0079e12 100644 --- a/nova/tests/test_network.py +++ b/nova/tests/test_network.py @@ -22,7 +22,7 @@ from nova import exception from nova import log as logging from nova import test from nova.network import manager as network_manager -from nova.tests import fake_network_info +from nova.tests import fake_network LOG = logging.getLogger('nova.tests.network') @@ -132,7 +132,7 @@ class FlatNetworkTestCase(test.TestCase): is_admin=False) def test_get_instance_nw_info(self): - fake_get_instance_nw_info = fake_network_info.fake_get_instance_nw_info + fake_get_instance_nw_info = fake_network.fake_get_instance_nw_info nw_info = fake_get_instance_nw_info(self.stubs, 0, 2) self.assertFalse(nw_info) From 15a424a554e0a89bcd3a8b68fa2433734c1a2dcb Mon Sep 17 00:00:00 2001 From: Soren Hansen Date: Fri, 2 Sep 2011 13:44:10 +0200 Subject: [PATCH 039/100] Fix protocol-less security groups. --- nova/tests/test_libvirt.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 8c6775b2..f0aa2a91 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -1033,6 +1033,13 @@ class IptablesFirewallTestCase(test.TestCase): 'to_port': 81, 'group_id': src_secgroup['id']}) + db.security_group_rule_create(admin_ctxt, + {'parent_group_id': secgroup['id'], + 'group_id': src_secgroup['id']}) + + db.instance_add_security_group(admin_ctxt, instance_ref['id'], + secgroup['id']) + db.instance_add_security_group(admin_ctxt, instance_ref['id'], secgroup['id']) db.instance_add_security_group(admin_ctxt, src_instance_ref['id'], @@ -1106,6 +1113,10 @@ class IptablesFirewallTestCase(test.TestCase): self.assertTrue(len(filter(regex.match, self.out_rules)) > 0, "TCP port 80/81 acceptance rule wasn't added") + regex = re.compile('-A .* -j ACCEPT -s %s' % (src_ip,)) + self.assertTrue(len(filter(regex.match, self.out_rules)) > 0, + "TCP port 80/81 acceptance rule wasn't added") + regex = re.compile('-A .* -j ACCEPT -p tcp ' '-m multiport --dports 80:81 -s 192.168.10.0/24') self.assertTrue(len(filter(regex.match, self.out_rules)) > 0, From 7b531ab4a28a820f75afa83825991bd4e9c2e132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thuleau=20=C3=89douard?= Date: Fri, 2 Sep 2011 17:49:45 +0200 Subject: [PATCH 040/100] Add tests for flags 'snapshot_image_format'. --- nova/tests/test_libvirt.py | 41 +++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 8c6775b2..a7b24c1b 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -321,7 +321,7 @@ class LibvirtConnTestCase(test.TestCase): instance_data = dict(self.test_instance) self._check_xml_and_container(instance_data) - def test_snapshot(self): + def test_snapshot_in_raw_format(self): if not self.lazy_load_library_exists(): return @@ -354,8 +354,47 @@ class LibvirtConnTestCase(test.TestCase): snapshot = image_service.show(context, recv_meta['id']) self.assertEquals(snapshot['properties']['image_state'], 'available') self.assertEquals(snapshot['status'], 'active') + self.assertEquals(snapshot['disk_format'], FLAGS.snapshot_image_format) self.assertEquals(snapshot['name'], snapshot_name) + def test_snapshot_in_qcow2_format(self): + if not self.lazy_load_library_exists(): + return + + self.flags(image_service='nova.image.fake.FakeImageService') + self.flags(snapshot_image_format='qcow2') + + # Start test + image_service = utils.import_object(FLAGS.image_service) + + # Assuming that base image already exists in image_service + instance_ref = db.instance_create(self.context, self.test_instance) + properties = {'instance_id': instance_ref['id'], + 'user_id': str(self.context.user_id)} + snapshot_name = 'test-snap' + sent_meta = {'name': snapshot_name, 'is_public': False, + 'status': 'creating', 'properties': properties} + # Create new image. It will be updated in snapshot method + # To work with it from snapshot, the single image_service is needed + recv_meta = image_service.create(context, sent_meta) + + self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn') + connection.LibvirtConnection._conn.lookupByName = self.fake_lookup + self.mox.StubOutWithMock(connection.utils, 'execute') + connection.utils.execute = self.fake_execute + + self.mox.ReplayAll() + + conn = connection.LibvirtConnection(False) + conn.snapshot(self.context, instance_ref, recv_meta['id']) + + snapshot = image_service.show(context, recv_meta['id']) + self.assertEquals(snapshot['properties']['image_state'], 'available') + self.assertEquals(snapshot['status'], 'active') + self.assertEquals(snapshot['disk_format'], FLAGS.snapshot_image_format) + self.assertEquals(snapshot['name'], snapshot_name) + + def test_snapshot_no_image_architecture(self): if not self.lazy_load_library_exists(): return From 03177f928385c6894aac5edd074ff4a4474e80e2 Mon Sep 17 00:00:00 2001 From: Tushar Patil Date: Fri, 2 Sep 2011 12:34:14 -0700 Subject: [PATCH 041/100] Fix for LP Bug #839269 --- nova/tests/test_network.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py index 25ff940f..2347544d 100644 --- a/nova/tests/test_network.py +++ b/nova/tests/test_network.py @@ -264,7 +264,8 @@ class VlanNetworkTestCase(test.TestCase): db.fixed_ip_associate(mox.IgnoreArg(), mox.IgnoreArg(), - mox.IgnoreArg()).AndReturn('192.168.0.1') + mox.IgnoreArg(), + reserved=True).AndReturn('192.168.0.1') db.fixed_ip_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()) From ce9635bbf5c33b77816130502e51c08b00b39f44 Mon Sep 17 00:00:00 2001 From: Soren Hansen Date: Sun, 4 Sep 2011 21:06:10 +0200 Subject: [PATCH 042/100] Accidentally added instance to security group twice in the test. Fixed. --- nova/tests/test_libvirt.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index f0aa2a91..1254c329 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -1037,9 +1037,6 @@ class IptablesFirewallTestCase(test.TestCase): {'parent_group_id': secgroup['id'], 'group_id': src_secgroup['id']}) - db.instance_add_security_group(admin_ctxt, instance_ref['id'], - secgroup['id']) - db.instance_add_security_group(admin_ctxt, instance_ref['id'], secgroup['id']) db.instance_add_security_group(admin_ctxt, src_instance_ref['id'], From 2bf9c55af3091128636473a42d6349de78d4ba9c Mon Sep 17 00:00:00 2001 From: sateesh Date: Mon, 5 Sep 2011 12:51:07 +0530 Subject: [PATCH 043/100] Multi-NIC support for vmwareapi virt driver in nova. Does injection of Multi-NIC information to instances with Operating system flavors Ubuntu, Windows and RHEL. vmwareapi virt driver now relies on calls to network manager instead of nova db calls for network configuration information of instance. Ensure if port group is properly associated with vlan_interface specified in case of VLAN networking for instances. Re-oranized VMWareVlanBridgeDriver and added session parmeter to methods to use existing session. Also removed session creation code as session comes as argument. Added check for flat_inject flag before attempting an inject operation. Removed stale code from vmwareapi stubs. Also updated some comments to be more meaningful. Did pep8 and pylint checks. Tried to improve pylint score for newly added lines of code. --- nova/tests/vmwareapi/stubs.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/nova/tests/vmwareapi/stubs.py b/nova/tests/vmwareapi/stubs.py index 0ed5e9b6..7de10e61 100644 --- a/nova/tests/vmwareapi/stubs.py +++ b/nova/tests/vmwareapi/stubs.py @@ -45,8 +45,6 @@ def set_stubs(stubs): stubs.Set(vmware_images, 'get_vmdk_size_and_properties', fake.fake_get_vmdk_size_and_properties) stubs.Set(vmware_images, 'upload_image', fake.fake_upload_image) - stubs.Set(vmwareapi_conn.VMWareAPISession, "_get_vim_object", - fake_get_vim_object) stubs.Set(vmwareapi_conn.VMWareAPISession, "_get_vim_object", fake_get_vim_object) stubs.Set(vmwareapi_conn.VMWareAPISession, "_is_vim_object", From 406637b93b4cc6aabd7041762ca0871265a03a4a Mon Sep 17 00:00:00 2001 From: Soren Hansen Date: Mon, 5 Sep 2011 09:32:14 +0200 Subject: [PATCH 044/100] Make a security group rule that references another security group return ipPermission for each of tcp, udp, and icmp. --- nova/tests/test_cloud.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index 3fe6a9b4..f5a99fa2 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -305,6 +305,36 @@ class CloudTestCase(test.TestCase): 'ip_protocol': u'tcp'}]} self.assertTrue(authz(self.context, group_name=sec['name'], **kwargs)) + def test_describe_security_group_ingress_groups(self): + kwargs = {'project_id': self.context.project_id, 'name': 'test'} + sec = db.security_group_create(self.context, + {'project_id': 'someuser', + 'name': 'somegroup1'}) + sec = db.security_group_create(self.context, + {'project_id': 'someuser', + 'name': 'othergroup2'}) + sec = db.security_group_create(self.context, kwargs) + authz = self.cloud.authorize_security_group_ingress + kwargs = {'ip_permissions': [{ + 'groups': {'1': {'user_id': u'someuser', + 'group_name': u'somegroup1'}, + '2': {'user_id': u'someuser', + 'group_name': u'othergroup2'}}}]} + self.assertTrue(authz(self.context, group_name=sec['name'], **kwargs)) + describe = self.cloud.describe_security_groups + groups = describe(self.context, group_name=['test']) + self.assertEquals(len(groups['securityGroupInfo']), 1) + for proto, min_port, max_port in (('icmp', -1, -1), + ('udp', 1, 65536), + ('tcp', 1, 65535)): + rules = filter(lambda g:g['ipProtocol'] == proto, + groups['securityGroupInfo'][0]['ipPermissions']) + self.assertEquals(len(rules), 2, + "Expected 2 rules for protocol %s" % proto) + for rule in rules: + self.assertEquals(rule['fromPort'], min_port) + self.assertEquals(rule['toPort'], max_port) + def test_revoke_security_group_ingress(self): kwargs = {'project_id': self.context.project_id, 'name': 'test'} sec = db.security_group_create(self.context, kwargs) From 6e4e053f5332368435e9a923169a60a8ce02ead3 Mon Sep 17 00:00:00 2001 From: Soren Hansen Date: Mon, 5 Sep 2011 12:05:47 +0200 Subject: [PATCH 045/100] Clean up security groups after use --- nova/tests/test_cloud.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index f5a99fa2..c5bfdd0f 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -307,20 +307,20 @@ class CloudTestCase(test.TestCase): def test_describe_security_group_ingress_groups(self): kwargs = {'project_id': self.context.project_id, 'name': 'test'} - sec = db.security_group_create(self.context, + sec1 = db.security_group_create(self.context, kwargs) + sec2 = db.security_group_create(self.context, {'project_id': 'someuser', 'name': 'somegroup1'}) - sec = db.security_group_create(self.context, + sec3 = db.security_group_create(self.context, {'project_id': 'someuser', 'name': 'othergroup2'}) - sec = db.security_group_create(self.context, kwargs) authz = self.cloud.authorize_security_group_ingress kwargs = {'ip_permissions': [{ 'groups': {'1': {'user_id': u'someuser', 'group_name': u'somegroup1'}, '2': {'user_id': u'someuser', 'group_name': u'othergroup2'}}}]} - self.assertTrue(authz(self.context, group_name=sec['name'], **kwargs)) + self.assertTrue(authz(self.context, group_name=sec1['name'], **kwargs)) describe = self.cloud.describe_security_groups groups = describe(self.context, group_name=['test']) self.assertEquals(len(groups['securityGroupInfo']), 1) @@ -334,6 +334,9 @@ class CloudTestCase(test.TestCase): for rule in rules: self.assertEquals(rule['fromPort'], min_port) self.assertEquals(rule['toPort'], max_port) + db.security_group_destroy(self.context, sec3['id']) + db.security_group_destroy(self.context, sec2['id']) + db.security_group_destroy(self.context, sec1['id']) def test_revoke_security_group_ingress(self): kwargs = {'project_id': self.context.project_id, 'name': 'test'} From 83ae9ec2aab3d0e70c6e809471bed46137bbf476 Mon Sep 17 00:00:00 2001 From: Soren Hansen Date: Mon, 5 Sep 2011 12:06:13 +0200 Subject: [PATCH 046/100] Adjust test_api to account to multiple rules getting returned for a single set rule. --- nova/tests/test_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/test_api.py b/nova/tests/test_api.py index 526d1c49..e9f1145d 100644 --- a/nova/tests/test_api.py +++ b/nova/tests/test_api.py @@ -515,7 +515,7 @@ class ApiEc2TestCase(test.TestCase): # be good enough for that. for group in rv: if group.name == security_group_name: - self.assertEquals(len(group.rules), 1) + self.assertEquals(len(group.rules), 3) self.assertEquals(len(group.rules[0].grants), 1) self.assertEquals(str(group.rules[0].grants[0]), '%s-%s' % (other_security_group_name, 'fake')) From 359cbc7c8d5647472acbd2d8995ce706ad48af44 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Tue, 6 Sep 2011 07:31:39 -0400 Subject: [PATCH 047/100] Update the v1.0 rescue admin action and the v1.1 rescue extension to generate 'adminPass'. Fixes an issue where rescue commands were broken on XenServer. lp#838518 --- nova/flags.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nova/flags.py b/nova/flags.py index aa76defe..971e7880 100644 --- a/nova/flags.py +++ b/nova/flags.py @@ -421,6 +421,9 @@ DEFINE_string('root_helper', 'sudo', DEFINE_bool('use_ipv6', False, 'use ipv6') +DEFINE_integer('password_length', 12, + 'Length of generated instance admin passwords') + DEFINE_bool('monkey_patch', False, 'Whether to log monkey patching') From aaf5991536270518a765c9013ad2ba5e3a0fd6ac Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Tue, 6 Sep 2011 15:16:40 -0400 Subject: [PATCH 048/100] further cleanup --- nova/tests/test_xenapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 45dad351..27a8a979 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -745,7 +745,7 @@ class XenAPIMigrateInstance(test.TestCase): fake_utils.stub_out_utils_execute(self.stubs) stubs.stub_out_migration_methods(self.stubs) stubs.stubout_get_this_vm_uuid(self.stubs) - glance_stubs.stubout_glance_client(self.stubs) + #glance_stubs.stubout_glance_client(self.stubs) def test_migrate_disk_and_power_off(self): instance = db.instance_create(self.context, self.values) From 73e7e102ae37fd482e1427c2be101ddcc52abfab Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Tue, 6 Sep 2011 16:28:34 -0400 Subject: [PATCH 049/100] reverting xenapi change --- nova/tests/test_xenapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 27a8a979..45dad351 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -745,7 +745,7 @@ class XenAPIMigrateInstance(test.TestCase): fake_utils.stub_out_utils_execute(self.stubs) stubs.stub_out_migration_methods(self.stubs) stubs.stubout_get_this_vm_uuid(self.stubs) - #glance_stubs.stubout_glance_client(self.stubs) + glance_stubs.stubout_glance_client(self.stubs) def test_migrate_disk_and_power_off(self): instance = db.instance_create(self.context, self.values) From 4c6b59ac925d4e91a20ed22745bb5eb6b4325f57 Mon Sep 17 00:00:00 2001 From: "Kevin L. Mitchell" Date: Wed, 7 Sep 2011 18:01:52 -0500 Subject: [PATCH 050/100] spread-first strategy --- nova/scheduler/abstract_scheduler.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nova/scheduler/abstract_scheduler.py b/nova/scheduler/abstract_scheduler.py index 7f17b642..a81fa53c 100644 --- a/nova/scheduler/abstract_scheduler.py +++ b/nova/scheduler/abstract_scheduler.py @@ -20,8 +20,9 @@ customize the behavior: filter_hosts() and weigh_hosts(). The default behavior is to simply select all hosts and weight them the same. """ -import operator import json +import operator +import random import M2Crypto @@ -40,6 +41,8 @@ from nova.scheduler import api from nova.scheduler import driver FLAGS = flags.FLAGS +flags.DEFINE_boolean('spread_first', False, + 'Use a spread-first zone scheduler strategy') LOG = logging.getLogger('nova.scheduler.abstract_scheduler') From 4f956e17eff4695f9af4d101f4b7e88b6cd2cf24 Mon Sep 17 00:00:00 2001 From: "Kevin L. Mitchell" Date: Wed, 7 Sep 2011 18:08:39 -0500 Subject: [PATCH 051/100] actually shuffle the weighted_hosts list... --- nova/scheduler/abstract_scheduler.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nova/scheduler/abstract_scheduler.py b/nova/scheduler/abstract_scheduler.py index a81fa53c..b4c2bf4f 100644 --- a/nova/scheduler/abstract_scheduler.py +++ b/nova/scheduler/abstract_scheduler.py @@ -295,6 +295,8 @@ class AbstractScheduler(driver.Scheduler): "child_zone": child_zone, "child_blob": weighting["blob"]} weighted_hosts.append(host_dict) + if FLAGS.spread_first: + random.shuffle(weighted_hosts) weighted_hosts.sort(key=operator.itemgetter('weight')) return weighted_hosts From 98306182ba43e8e78216fffe8f4599ae3a88b411 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Thu, 8 Sep 2011 04:45:04 -0700 Subject: [PATCH 052/100] fixes vncproxy service listening on rabbit --- bin/nova-vncproxy | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/bin/nova-vncproxy b/bin/nova-vncproxy index dc08e243..8e75451c 100755 --- a/bin/nova-vncproxy +++ b/bin/nova-vncproxy @@ -107,10 +107,13 @@ if __name__ == "__main__": else: with_auth = auth.VNCNovaAuthMiddleware(with_logging) - server = wsgi.Server("VNC Proxy", - with_auth, - host=FLAGS.vncproxy_host, - port=FLAGS.vncproxy_port) - server.start_tcp(handle_flash_socket_policy, 843, host=FLAGS.vncproxy_host) - service.serve(server) + wsgi_server = wsgi.Server("VNC Proxy", + with_auth, + host=FLAGS.vncproxy_host, + port=FLAGS.vncproxy_port) + wsgi_server.start_tcp(handle_flash_socket_policy, + 843, + host=FLAGS.vncproxy_host) + server = service.Service.create(binary='nova-vncproxy') + service.serve(wsgi_server, server) service.wait() From 8ea8600e612b70f77c6d32db6464ffabd1c77078 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Thu, 8 Sep 2011 15:26:44 -0400 Subject: [PATCH 053/100] converting fix to just address ec2; updating test --- nova/tests/test_cloud.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index 3fe6a9b4..7fe353b3 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -486,11 +486,9 @@ class CloudTestCase(test.TestCase): inst2 = db.instance_create(self.context, args2) db.instance_destroy(self.context, inst1.id) result = self.cloud.describe_instances(self.context) + self.assertEqual(len(result['reservationSet']), 1) result1 = result['reservationSet'][0]['instancesSet'] self.assertEqual(result1[0]['instanceId'], - ec2utils.id_to_ec2_id(inst1.id)) - result2 = result['reservationSet'][1]['instancesSet'] - self.assertEqual(result2[0]['instanceId'], ec2utils.id_to_ec2_id(inst2.id)) def _block_device_mapping_create(self, instance_id, mappings): From ef0d488fd81b13b33a0c4a607cf3d36bc5b3cbc2 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Thu, 8 Sep 2011 16:10:03 -0500 Subject: [PATCH 054/100] First pass at adding reboot_type to reboot codepath. --- nova/tests/test_compute.py | 15 ++++++++++++--- nova/tests/test_virt_drivers.py | 3 ++- nova/tests/test_vmwareapi.py | 3 ++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 65fdffbd..4d463572 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -300,11 +300,20 @@ class ComputeTestCase(test.TestCase): self.compute.resume_instance(self.context, instance_id) self.compute.terminate_instance(self.context, instance_id) - def test_reboot(self): - """Ensure instance can be rebooted""" + def test_soft_reboot(self): + """Ensure instance can be soft rebooted""" instance_id = self._create_instance() + reboot_type = "SOFT" self.compute.run_instance(self.context, instance_id) - self.compute.reboot_instance(self.context, instance_id) + self.compute.reboot_instance(self.context, instance_id, reboot_type) + self.compute.terminate_instance(self.context, instance_id) + + def test_hard_reboot(self): + """Ensure instance can be hard rebooted""" + instance_id = self._create_instance() + reboot_type = "HARD" + self.compute.run_instance(self.context, instance_id) + self.compute.reboot_instance(self.context, instance_id, reboot_type) self.compute.terminate_instance(self.context, instance_id) def test_set_admin_password(self): diff --git a/nova/tests/test_virt_drivers.py b/nova/tests/test_virt_drivers.py index 480247c9..440d3401 100644 --- a/nova/tests/test_virt_drivers.py +++ b/nova/tests/test_virt_drivers.py @@ -103,8 +103,9 @@ class _VirtDriverTestCase(test.TestCase): def test_reboot(self): instance_ref = test_utils.get_test_instance() network_info = test_utils.get_test_network_info() + reboot_type = "SOFT" self.connection.spawn(self.ctxt, instance_ref, network_info) - self.connection.reboot(instance_ref, network_info) + self.connection.reboot(instance_ref, network_info, reboot_type) @catch_notimplementederror def test_get_host_ip_addr(self): diff --git a/nova/tests/test_vmwareapi.py b/nova/tests/test_vmwareapi.py index 06daf46e..e6da1690 100644 --- a/nova/tests/test_vmwareapi.py +++ b/nova/tests/test_vmwareapi.py @@ -170,7 +170,8 @@ class VMWareAPIVMTestCase(test.TestCase): self._create_vm() info = self.conn.get_info(1) self._check_vm_info(info, power_state.RUNNING) - self.conn.reboot(self.instance, self.network_info) + reboot_type = "SOFT" + self.conn.reboot(self.instance, self.network_info, reboot_type) info = self.conn.get_info(1) self._check_vm_info(info, power_state.RUNNING) From c9f670d795cceecb2fdb3d99157ef0f1d9d20b0c Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Fri, 9 Sep 2011 10:44:06 -0700 Subject: [PATCH 055/100] remove extra line for pep8 --- nova/tests/test_libvirt.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index a7b24c1b..61f98f63 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -394,7 +394,6 @@ class LibvirtConnTestCase(test.TestCase): self.assertEquals(snapshot['disk_format'], FLAGS.snapshot_image_format) self.assertEquals(snapshot['name'], snapshot_name) - def test_snapshot_no_image_architecture(self): if not self.lazy_load_library_exists(): return From e319727722654da8e993a7589c608b40004c246d Mon Sep 17 00:00:00 2001 From: "Kevin L. Mitchell" Date: Fri, 9 Sep 2011 14:35:38 -0500 Subject: [PATCH 056/100] Add comment to document why random.shuffle() works --- nova/scheduler/abstract_scheduler.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nova/scheduler/abstract_scheduler.py b/nova/scheduler/abstract_scheduler.py index b4c2bf4f..e4f615b9 100644 --- a/nova/scheduler/abstract_scheduler.py +++ b/nova/scheduler/abstract_scheduler.py @@ -296,6 +296,13 @@ class AbstractScheduler(driver.Scheduler): "child_blob": weighting["blob"]} weighted_hosts.append(host_dict) if FLAGS.spread_first: + # NOTE(Vek): If all the weights are unique, then the sort + # below undoes this shuffle; however, if + # several responses from several zones have the + # same weight, then this shuffle serves to + # break up the monolithic blocks and cause the + # instances to be uniformly spread across the + # zones. random.shuffle(weighted_hosts) weighted_hosts.sort(key=operator.itemgetter('weight')) return weighted_hosts From e70f2209c663a4a239ed9abc8ea44936919d0d45 Mon Sep 17 00:00:00 2001 From: "Kevin L. Mitchell" Date: Fri, 9 Sep 2011 20:27:22 +0000 Subject: [PATCH 057/100] don't need random in abstract_scheduler.py anymore... --- nova/scheduler/abstract_scheduler.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nova/scheduler/abstract_scheduler.py b/nova/scheduler/abstract_scheduler.py index 76329bbc..6e8c7d71 100644 --- a/nova/scheduler/abstract_scheduler.py +++ b/nova/scheduler/abstract_scheduler.py @@ -22,7 +22,6 @@ behavior is to simply select all hosts and weight them the same. import json import operator -import random import M2Crypto From 1096b9ab931e9c37b73bee16467f9e220838c453 Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Sat, 10 Sep 2011 17:11:21 +0900 Subject: [PATCH 058/100] api/ec2: make get_metadata() return correct mappings The entries corresponding to volumes are in the form of ebs': --- nova/tests/test_cloud.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index 7fe353b3..7bdae055 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -1540,7 +1540,9 @@ class CloudTestCase(test.TestCase): 'ephemeral0': '/dev/sdb', 'swap': '/dev/sdc', 'ephemeral1': '/dev/sdd', - 'ephemeral2': '/dev/sd3'} + 'ephemeral2': '/dev/sd3', + 'ebs0': '/dev/sdh', + 'ebs1': '/dev/sdi'} self.assertEqual(self.cloud._format_instance_mapping(ctxt, instance_ref0), From af0d05ef818b90a6c13fa3e30b0a9593e885bd69 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Sat, 10 Sep 2011 13:56:54 -0400 Subject: [PATCH 059/100] Update GlanceClient, GlanceImageService, and Glance Xen plugin to work with Glance keystone. --- nova/tests/test_xenapi.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 91b4161b..4a83d139 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -932,8 +932,9 @@ class XenAPIDetermineDiskImageTestCase(test.TestCase): self.fake_instance.architecture = 'x86-64' def assert_disk_type(self, disk_type): + ctx = context.RequestContext('fake', 'fake') dt = vm_utils.VMHelper.determine_disk_image_type( - self.fake_instance) + self.fake_instance, ctx) self.assertEqual(disk_type, dt) def test_instance_disk(self): From 03114209dd0b112cabd37f26334b47813f522d08 Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Mon, 12 Sep 2011 14:30:56 +0200 Subject: [PATCH 060/100] Fix rogue usage of 'sudo' bypassing the run_as_root=True method --- nova/tests/test_libvirt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 8c6775b2..fea2b7cd 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -743,7 +743,7 @@ class LibvirtConnTestCase(test.TestCase): # qemu-img should be mockd since test environment might not have # large disk space. self.mox.StubOutWithMock(utils, "execute") - utils.execute('sudo', 'qemu-img', 'create', '-f', 'raw', + utils.execute('qemu-img', 'create', '-f', 'raw', '%s/%s/disk' % (tmpdir, instance_ref.name), '10G') self.mox.ReplayAll() @@ -795,7 +795,7 @@ class LibvirtConnTestCase(test.TestCase): os.path.getsize("/test/disk").AndReturn(10 * 1024 * 1024 * 1024) # another is qcow image, so qemu-img should be mocked. self.mox.StubOutWithMock(utils, "execute") - utils.execute('sudo', 'qemu-img', 'info', '/test/disk.local').\ + utils.execute('qemu-img', 'info', '/test/disk.local').\ AndReturn((ret, '')) self.mox.ReplayAll() From ec555e5f485e187e7234e3b0573a817be96ed3df Mon Sep 17 00:00:00 2001 From: Anthony Young Date: Mon, 12 Sep 2011 08:00:30 -0700 Subject: [PATCH 061/100] add test for method sig --- nova/tests/test_libvirt.py | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 93967cee..d776a386 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -16,6 +16,7 @@ import copy import eventlet +import inspect import mox import os import re @@ -35,6 +36,7 @@ from nova import utils from nova.api.ec2 import cloud from nova.compute import power_state from nova.compute import vm_states +from nova.virt import driver from nova.virt.libvirt import connection from nova.virt.libvirt import firewall from nova.tests import fake_network @@ -840,6 +842,50 @@ class LibvirtConnTestCase(test.TestCase): _assert_volume_in_mapping('sdg', False) _assert_volume_in_mapping('sdh1', False) + def test_reboot_signature(self): + """Test that libvirt driver method sig matches interface""" + def fake_reboot_with_correct_sig(ignore, instance, + network_info, reboot_type): + pass + + def fake_destroy(instance, network_info, cleanup=False): + pass + + def fake_plug_vifs(instance, network_info): + pass + + def fake_create_new_domain(xml): + return + + def fake_none(self, instance): + return + + instance = db.instance_create(self.context, self.test_instance) + network_info = _fake_network_info(self.stubs, 1) + + self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn') + connection.LibvirtConnection._conn.lookupByName = self.fake_lookup + + conn = connection.LibvirtConnection(False) + self.stubs.Set(conn, 'destroy', fake_destroy) + self.stubs.Set(conn, 'plug_vifs', fake_plug_vifs) + self.stubs.Set(conn.firewall_driver, + 'setup_basic_filtering', + fake_none) + self.stubs.Set(conn.firewall_driver, + 'prepare_instance_filter', + fake_none) + self.stubs.Set(conn, '_create_new_domain', fake_create_new_domain) + self.stubs.Set(conn.firewall_driver, + 'apply_instance_filter', + fake_none) + + args = [instance, network_info, 'SOFT'] + conn.reboot(*args) + + compute_driver = driver.ComputeDriver() + self.assertRaises(NotImplementedError, compute_driver.reboot, *args) + class NWFilterFakes: def __init__(self): From 1d63c507b322faf57eeb89f92c22c50e41873ede Mon Sep 17 00:00:00 2001 From: Anthony Young Date: Mon, 12 Sep 2011 09:15:31 -0700 Subject: [PATCH 062/100] remove unused dep --- nova/tests/test_libvirt.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index d776a386..5346e089 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -16,7 +16,6 @@ import copy import eventlet -import inspect import mox import os import re From f619529afac107ab4eee1145a0f14939ad9ca61e Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Mon, 12 Sep 2011 18:17:32 -0400 Subject: [PATCH 064/100] relocating ec2 tests --- nova/tests/public_key/dummy.fingerprint | 1 - nova/tests/public_key/dummy.pub | 1 - nova/tests/test_cloud.py | 1623 ----------------------- 3 files changed, 1625 deletions(-) delete mode 100644 nova/tests/public_key/dummy.fingerprint delete mode 100644 nova/tests/public_key/dummy.pub delete mode 100644 nova/tests/test_cloud.py diff --git a/nova/tests/public_key/dummy.fingerprint b/nova/tests/public_key/dummy.fingerprint deleted file mode 100644 index 715bca27..00000000 --- a/nova/tests/public_key/dummy.fingerprint +++ /dev/null @@ -1 +0,0 @@ -1c:87:d1:d9:32:fd:62:3c:78:2b:c0:ad:c0:15:88:df diff --git a/nova/tests/public_key/dummy.pub b/nova/tests/public_key/dummy.pub deleted file mode 100644 index d4cf2bc0..00000000 --- a/nova/tests/public_key/dummy.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-dss AAAAB3NzaC1kc3MAAACBAMGJlY9XEIm2X234pdO5yFWMp2JuOQx8U0E815IVXhmKxYCBK9ZakgZOIQmPbXoGYyV+mziDPp6HJ0wKYLQxkwLEFr51fAZjWQvRss0SinURRuLkockDfGFtD4pYJthekr/rlqMKlBSDUSpGq8jUWW60UJ18FGooFpxR7ESqQRx/AAAAFQC96LRglaUeeP+E8U/yblEJocuiWwAAAIA3XiMR8Skiz/0aBm5K50SeQznQuMJTyzt9S9uaz5QZWiFu69hOyGSFGw8fqgxEkXFJIuHobQQpGYQubLW0NdaYRqyE/Vud3JUJUb8Texld6dz8vGemyB5d1YvtSeHIo8/BGv2msOqR3u5AZTaGCBD9DhpSGOKHEdNjTtvpPd8S8gAAAIBociGZ5jf09iHLVENhyXujJbxfGRPsyNTyARJfCOGl0oFV6hEzcQyw8U/ePwjgvjc2UizMWLl8tsb2FXKHRdc2v+ND3Us+XqKQ33X3ADP4FZ/+Oj213gMyhCmvFTP0u5FmHog9My4CB7YcIWRuUR42WlhQ2IfPvKwUoTk3R+T6Og== www-data@mk diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py deleted file mode 100644 index 7fe353b3..00000000 --- a/nova/tests/test_cloud.py +++ /dev/null @@ -1,1623 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2010 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -import mox - -import functools - -from base64 import b64decode -from M2Crypto import BIO -from M2Crypto import RSA -import os - -from eventlet import greenthread - -from nova import context -from nova import crypto -from nova import db -from nova import exception -from nova import flags -from nova import log as logging -from nova import network -from nova import rpc -from nova import test -from nova import utils -from nova.api.ec2 import cloud -from nova.api.ec2 import ec2utils -from nova.compute import vm_states -from nova.image import fake - - -FLAGS = flags.FLAGS -LOG = logging.getLogger('nova.tests.cloud') - - -class CloudTestCase(test.TestCase): - def setUp(self): - super(CloudTestCase, self).setUp() - self.flags(connection_type='fake', - stub_network=True) - - # set up our cloud - self.cloud = cloud.CloudController() - - # set up services - self.compute = self.start_service('compute') - self.scheduter = self.start_service('scheduler') - self.network = self.start_service('network') - self.volume = self.start_service('volume') - self.image_service = utils.import_object(FLAGS.image_service) - - self.user_id = 'fake' - self.project_id = 'fake' - self.context = context.RequestContext(self.user_id, - self.project_id, - True) - - def fake_show(meh, context, id): - return {'id': 1, 'container_format': 'ami', - 'properties': {'kernel_id': 1, 'ramdisk_id': 1, - 'type': 'machine', 'image_state': 'available'}} - - self.stubs.Set(fake._FakeImageService, 'show', fake_show) - self.stubs.Set(fake._FakeImageService, 'show_by_name', fake_show) - - # NOTE(vish): set up a manual wait so rpc.cast has a chance to finish - rpc_cast = rpc.cast - - def finish_cast(*args, **kwargs): - rpc_cast(*args, **kwargs) - greenthread.sleep(0.2) - - self.stubs.Set(rpc, 'cast', finish_cast) - - def _create_key(self, name): - # NOTE(vish): create depends on pool, so just call helper directly - return cloud._gen_key(self.context, self.context.user_id, name) - - def test_describe_regions(self): - """Makes sure describe regions runs without raising an exception""" - result = self.cloud.describe_regions(self.context) - self.assertEqual(len(result['regionInfo']), 1) - self.flags(region_list=["one=test_host1", "two=test_host2"]) - result = self.cloud.describe_regions(self.context) - self.assertEqual(len(result['regionInfo']), 2) - - def test_describe_addresses(self): - """Makes sure describe addresses runs without raising an exception""" - address = "10.10.10.10" - db.floating_ip_create(self.context, - {'address': address, - 'host': self.network.host}) - self.cloud.allocate_address(self.context) - self.cloud.describe_addresses(self.context) - self.cloud.release_address(self.context, - public_ip=address) - db.floating_ip_destroy(self.context, address) - - def test_allocate_address(self): - address = "10.10.10.10" - allocate = self.cloud.allocate_address - db.floating_ip_create(self.context, - {'address': address, - 'host': self.network.host}) - self.assertEqual(allocate(self.context)['publicIp'], address) - db.floating_ip_destroy(self.context, address) - self.assertRaises(exception.NoMoreFloatingIps, - allocate, - self.context) - - def test_release_address(self): - address = "10.10.10.10" - allocate = self.cloud.allocate_address - db.floating_ip_create(self.context, - {'address': address, - 'host': self.network.host}) - result = self.cloud.release_address(self.context, address) - self.assertEqual(result['releaseResponse'], ['Address released.']) - - def test_release_address_still_associated(self): - address = "10.10.10.10" - fixed_ip = {'instance': {'id': 1}} - floating_ip = {'id': 0, - 'address': address, - 'fixed_ip_id': 0, - 'fixed_ip': fixed_ip, - 'project_id': None, - 'auto_assigned': False} - network_api = network.api.API() - self.mox.StubOutWithMock(network_api.db, 'floating_ip_get_by_address') - network_api.db.floating_ip_get_by_address(mox.IgnoreArg(), - mox.IgnoreArg()).AndReturn(floating_ip) - self.mox.ReplayAll() - release = self.cloud.release_address - # ApiError: Floating ip is in use. Disassociate it before releasing. - self.assertRaises(exception.ApiError, release, self.context, address) - - def test_associate_disassociate_address(self): - """Verifies associate runs cleanly without raising an exception""" - address = "10.10.10.10" - db.floating_ip_create(self.context, {'address': address}) - self.cloud.allocate_address(self.context) - # TODO(jkoelker) Probably need to query for instance_type_id and - # make sure we get a valid one - inst = db.instance_create(self.context, {'host': self.compute.host, - 'instance_type_id': 1}) - networks = db.network_get_all(self.context) - for network in networks: - db.network_update(self.context, network['id'], - {'host': self.network.host}) - project_id = self.context.project_id - type_id = inst['instance_type_id'] - ips = self.network.allocate_for_instance(self.context, - instance_id=inst['id'], - host=inst['host'], - vpn=None, - instance_type_id=type_id, - project_id=project_id) - # TODO(jkoelker) Make this mas bueno - self.assertTrue(ips) - self.assertTrue('ips' in ips[0][1]) - self.assertTrue(ips[0][1]['ips']) - self.assertTrue('ip' in ips[0][1]['ips'][0]) - - fixed = ips[0][1]['ips'][0]['ip'] - - ec2_id = ec2utils.id_to_ec2_id(inst['id']) - self.cloud.associate_address(self.context, - instance_id=ec2_id, - public_ip=address) - self.cloud.disassociate_address(self.context, - public_ip=address) - self.cloud.release_address(self.context, - public_ip=address) - self.network.deallocate_fixed_ip(self.context, fixed) - db.instance_destroy(self.context, inst['id']) - db.floating_ip_destroy(self.context, address) - - def test_describe_security_groups(self): - """Makes sure describe_security_groups works and filters results.""" - sec = db.security_group_create(self.context, - {'project_id': self.context.project_id, - 'name': 'test'}) - result = self.cloud.describe_security_groups(self.context) - # NOTE(vish): should have the default group as well - self.assertEqual(len(result['securityGroupInfo']), 2) - result = self.cloud.describe_security_groups(self.context, - group_name=[sec['name']]) - self.assertEqual(len(result['securityGroupInfo']), 1) - self.assertEqual( - result['securityGroupInfo'][0]['groupName'], - sec['name']) - db.security_group_destroy(self.context, sec['id']) - - def test_describe_security_groups_by_id(self): - sec = db.security_group_create(self.context, - {'project_id': self.context.project_id, - 'name': 'test'}) - result = self.cloud.describe_security_groups(self.context, - group_id=[sec['id']]) - self.assertEqual(len(result['securityGroupInfo']), 1) - self.assertEqual( - result['securityGroupInfo'][0]['groupName'], - sec['name']) - default = db.security_group_get_by_name(self.context, - self.context.project_id, - 'default') - result = self.cloud.describe_security_groups(self.context, - group_id=[default['id']]) - self.assertEqual(len(result['securityGroupInfo']), 1) - self.assertEqual( - result['securityGroupInfo'][0]['groupName'], - 'default') - db.security_group_destroy(self.context, sec['id']) - - def test_create_delete_security_group(self): - descript = 'test description' - create = self.cloud.create_security_group - result = create(self.context, 'testgrp', descript) - group_descript = result['securityGroupSet'][0]['groupDescription'] - self.assertEqual(descript, group_descript) - delete = self.cloud.delete_security_group - self.assertTrue(delete(self.context, 'testgrp')) - - def test_delete_security_group_by_id(self): - sec = db.security_group_create(self.context, - {'project_id': self.context.project_id, - 'name': 'test'}) - delete = self.cloud.delete_security_group - self.assertTrue(delete(self.context, group_id=sec['id'])) - - def test_delete_security_group_with_bad_name(self): - delete = self.cloud.delete_security_group - notfound = exception.SecurityGroupNotFound - self.assertRaises(notfound, delete, self.context, 'badname') - - def test_delete_security_group_with_bad_group_id(self): - delete = self.cloud.delete_security_group - notfound = exception.SecurityGroupNotFound - self.assertRaises(notfound, delete, self.context, group_id=999) - - def test_delete_security_group_no_params(self): - delete = self.cloud.delete_security_group - self.assertRaises(exception.ApiError, delete, self.context) - - def test_authorize_security_group_ingress(self): - kwargs = {'project_id': self.context.project_id, 'name': 'test'} - sec = db.security_group_create(self.context, kwargs) - authz = self.cloud.authorize_security_group_ingress - kwargs = {'to_port': '999', 'from_port': '999', 'ip_protocol': 'tcp'} - self.assertTrue(authz(self.context, group_name=sec['name'], **kwargs)) - - def test_authorize_security_group_ingress_ip_permissions_ip_ranges(self): - kwargs = {'project_id': self.context.project_id, 'name': 'test'} - sec = db.security_group_create(self.context, kwargs) - authz = self.cloud.authorize_security_group_ingress - kwargs = {'ip_permissions': [{'to_port': 81, 'from_port': 81, - 'ip_ranges': - {'1': {'cidr_ip': u'0.0.0.0/0'}, - '2': {'cidr_ip': u'10.10.10.10/32'}}, - 'ip_protocol': u'tcp'}]} - self.assertTrue(authz(self.context, group_name=sec['name'], **kwargs)) - - def test_authorize_security_group_fail_missing_source_group(self): - kwargs = {'project_id': self.context.project_id, 'name': 'test'} - sec = db.security_group_create(self.context, kwargs) - authz = self.cloud.authorize_security_group_ingress - kwargs = {'ip_permissions': [{'to_port': 81, 'from_port': 81, - 'ip_ranges':{'1': {'cidr_ip': u'0.0.0.0/0'}, - '2': {'cidr_ip': u'10.10.10.10/32'}}, - 'groups': {'1': {'user_id': u'someuser', - 'group_name': u'somegroup1'}}, - 'ip_protocol': u'tcp'}]} - self.assertRaises(exception.SecurityGroupNotFound, authz, - self.context, group_name=sec['name'], **kwargs) - - def test_authorize_security_group_ingress_ip_permissions_groups(self): - kwargs = {'project_id': self.context.project_id, 'name': 'test'} - sec = db.security_group_create(self.context, - {'project_id': 'someuser', - 'name': 'somegroup1'}) - sec = db.security_group_create(self.context, - {'project_id': 'someuser', - 'name': 'othergroup2'}) - sec = db.security_group_create(self.context, kwargs) - authz = self.cloud.authorize_security_group_ingress - kwargs = {'ip_permissions': [{'to_port': 81, 'from_port': 81, - 'groups': {'1': {'user_id': u'someuser', - 'group_name': u'somegroup1'}, - '2': {'user_id': u'someuser', - 'group_name': u'othergroup2'}}, - 'ip_protocol': u'tcp'}]} - self.assertTrue(authz(self.context, group_name=sec['name'], **kwargs)) - - def test_revoke_security_group_ingress(self): - kwargs = {'project_id': self.context.project_id, 'name': 'test'} - sec = db.security_group_create(self.context, kwargs) - authz = self.cloud.authorize_security_group_ingress - kwargs = {'to_port': '999', 'from_port': '999', 'ip_protocol': 'tcp'} - authz(self.context, group_id=sec['id'], **kwargs) - revoke = self.cloud.revoke_security_group_ingress - self.assertTrue(revoke(self.context, group_name=sec['name'], **kwargs)) - - def test_authorize_revoke_security_group_ingress_by_id(self): - sec = db.security_group_create(self.context, - {'project_id': self.context.project_id, - 'name': 'test'}) - authz = self.cloud.authorize_security_group_ingress - kwargs = {'to_port': '999', 'from_port': '999', 'ip_protocol': 'tcp'} - authz(self.context, group_id=sec['id'], **kwargs) - revoke = self.cloud.revoke_security_group_ingress - self.assertTrue(revoke(self.context, group_id=sec['id'], **kwargs)) - - def test_authorize_security_group_ingress_missing_protocol_params(self): - sec = db.security_group_create(self.context, - {'project_id': self.context.project_id, - 'name': 'test'}) - authz = self.cloud.authorize_security_group_ingress - self.assertRaises(exception.ApiError, authz, self.context, 'test') - - def test_authorize_security_group_ingress_missing_group_name_or_id(self): - kwargs = {'project_id': self.context.project_id, 'name': 'test'} - authz = self.cloud.authorize_security_group_ingress - self.assertRaises(exception.ApiError, authz, self.context, **kwargs) - - def test_authorize_security_group_ingress_already_exists(self): - kwargs = {'project_id': self.context.project_id, 'name': 'test'} - sec = db.security_group_create(self.context, kwargs) - authz = self.cloud.authorize_security_group_ingress - kwargs = {'to_port': '999', 'from_port': '999', 'ip_protocol': 'tcp'} - authz(self.context, group_name=sec['name'], **kwargs) - self.assertRaises(exception.ApiError, authz, self.context, - group_name=sec['name'], **kwargs) - - def test_revoke_security_group_ingress_missing_group_name_or_id(self): - kwargs = {'to_port': '999', 'from_port': '999', 'ip_protocol': 'tcp'} - revoke = self.cloud.revoke_security_group_ingress - self.assertRaises(exception.ApiError, revoke, self.context, **kwargs) - - def test_describe_volumes(self): - """Makes sure describe_volumes works and filters results.""" - vol1 = db.volume_create(self.context, {}) - vol2 = db.volume_create(self.context, {}) - result = self.cloud.describe_volumes(self.context) - self.assertEqual(len(result['volumeSet']), 2) - volume_id = ec2utils.id_to_ec2_vol_id(vol2['id']) - result = self.cloud.describe_volumes(self.context, - volume_id=[volume_id]) - self.assertEqual(len(result['volumeSet']), 1) - self.assertEqual( - ec2utils.ec2_id_to_id(result['volumeSet'][0]['volumeId']), - vol2['id']) - db.volume_destroy(self.context, vol1['id']) - db.volume_destroy(self.context, vol2['id']) - - def test_create_volume_from_snapshot(self): - """Makes sure create_volume works when we specify a snapshot.""" - vol = db.volume_create(self.context, {'size': 1}) - snap = db.snapshot_create(self.context, {'volume_id': vol['id'], - 'volume_size': vol['size'], - 'status': "available"}) - snapshot_id = ec2utils.id_to_ec2_snap_id(snap['id']) - - result = self.cloud.create_volume(self.context, - snapshot_id=snapshot_id) - volume_id = result['volumeId'] - result = self.cloud.describe_volumes(self.context) - self.assertEqual(len(result['volumeSet']), 2) - self.assertEqual(result['volumeSet'][1]['volumeId'], volume_id) - - db.volume_destroy(self.context, ec2utils.ec2_id_to_id(volume_id)) - db.snapshot_destroy(self.context, snap['id']) - db.volume_destroy(self.context, vol['id']) - - def test_describe_availability_zones(self): - """Makes sure describe_availability_zones works and filters results.""" - service1 = db.service_create(self.context, {'host': 'host1_zones', - 'binary': "nova-compute", - 'topic': 'compute', - 'report_count': 0, - 'availability_zone': "zone1"}) - service2 = db.service_create(self.context, {'host': 'host2_zones', - 'binary': "nova-compute", - 'topic': 'compute', - 'report_count': 0, - 'availability_zone': "zone2"}) - result = self.cloud.describe_availability_zones(self.context) - self.assertEqual(len(result['availabilityZoneInfo']), 3) - db.service_destroy(self.context, service1['id']) - db.service_destroy(self.context, service2['id']) - - def test_describe_snapshots(self): - """Makes sure describe_snapshots works and filters results.""" - vol = db.volume_create(self.context, {}) - snap1 = db.snapshot_create(self.context, {'volume_id': vol['id']}) - snap2 = db.snapshot_create(self.context, {'volume_id': vol['id']}) - result = self.cloud.describe_snapshots(self.context) - self.assertEqual(len(result['snapshotSet']), 2) - snapshot_id = ec2utils.id_to_ec2_snap_id(snap2['id']) - result = self.cloud.describe_snapshots(self.context, - snapshot_id=[snapshot_id]) - self.assertEqual(len(result['snapshotSet']), 1) - self.assertEqual( - ec2utils.ec2_id_to_id(result['snapshotSet'][0]['snapshotId']), - snap2['id']) - db.snapshot_destroy(self.context, snap1['id']) - db.snapshot_destroy(self.context, snap2['id']) - db.volume_destroy(self.context, vol['id']) - - def test_create_snapshot(self): - """Makes sure create_snapshot works.""" - vol = db.volume_create(self.context, {'status': "available"}) - volume_id = ec2utils.id_to_ec2_vol_id(vol['id']) - - result = self.cloud.create_snapshot(self.context, - volume_id=volume_id) - snapshot_id = result['snapshotId'] - result = self.cloud.describe_snapshots(self.context) - self.assertEqual(len(result['snapshotSet']), 1) - self.assertEqual(result['snapshotSet'][0]['snapshotId'], snapshot_id) - - db.snapshot_destroy(self.context, ec2utils.ec2_id_to_id(snapshot_id)) - db.volume_destroy(self.context, vol['id']) - - def test_delete_snapshot(self): - """Makes sure delete_snapshot works.""" - vol = db.volume_create(self.context, {'status': "available"}) - snap = db.snapshot_create(self.context, {'volume_id': vol['id'], - 'status': "available"}) - snapshot_id = ec2utils.id_to_ec2_snap_id(snap['id']) - - result = self.cloud.delete_snapshot(self.context, - snapshot_id=snapshot_id) - self.assertTrue(result) - - db.volume_destroy(self.context, vol['id']) - - def test_describe_instances(self): - """Makes sure describe_instances works and filters results.""" - inst1 = db.instance_create(self.context, {'reservation_id': 'a', - 'image_ref': 1, - 'host': 'host1'}) - inst2 = db.instance_create(self.context, {'reservation_id': 'a', - 'image_ref': 1, - 'host': 'host2'}) - comp1 = db.service_create(self.context, {'host': 'host1', - 'availability_zone': 'zone1', - 'topic': "compute"}) - comp2 = db.service_create(self.context, {'host': 'host2', - 'availability_zone': 'zone2', - 'topic': "compute"}) - result = self.cloud.describe_instances(self.context) - result = result['reservationSet'][0] - self.assertEqual(len(result['instancesSet']), 2) - instance_id = ec2utils.id_to_ec2_id(inst2['id']) - result = self.cloud.describe_instances(self.context, - instance_id=[instance_id]) - result = result['reservationSet'][0] - self.assertEqual(len(result['instancesSet']), 1) - self.assertEqual(result['instancesSet'][0]['instanceId'], - instance_id) - self.assertEqual(result['instancesSet'][0] - ['placement']['availabilityZone'], 'zone2') - db.instance_destroy(self.context, inst1['id']) - db.instance_destroy(self.context, inst2['id']) - db.service_destroy(self.context, comp1['id']) - db.service_destroy(self.context, comp2['id']) - - def test_describe_instances_deleted(self): - args1 = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1'} - inst1 = db.instance_create(self.context, args1) - args2 = {'reservation_id': 'b', 'image_ref': 1, 'host': 'host1'} - inst2 = db.instance_create(self.context, args2) - db.instance_destroy(self.context, inst1.id) - result = self.cloud.describe_instances(self.context) - self.assertEqual(len(result['reservationSet']), 1) - result1 = result['reservationSet'][0]['instancesSet'] - self.assertEqual(result1[0]['instanceId'], - ec2utils.id_to_ec2_id(inst2.id)) - - def _block_device_mapping_create(self, instance_id, mappings): - volumes = [] - for bdm in mappings: - db.block_device_mapping_create(self.context, bdm) - if 'volume_id' in bdm: - values = {'id': bdm['volume_id']} - for bdm_key, vol_key in [('snapshot_id', 'snapshot_id'), - ('snapshot_size', 'volume_size'), - ('delete_on_termination', - 'delete_on_termination')]: - if bdm_key in bdm: - values[vol_key] = bdm[bdm_key] - vol = db.volume_create(self.context, values) - db.volume_attached(self.context, vol['id'], - instance_id, bdm['device_name']) - volumes.append(vol) - return volumes - - def _setUpBlockDeviceMapping(self): - inst1 = db.instance_create(self.context, - {'image_ref': 1, - 'root_device_name': '/dev/sdb1'}) - inst2 = db.instance_create(self.context, - {'image_ref': 2, - 'root_device_name': '/dev/sdc1'}) - - instance_id = inst1['id'] - mappings0 = [ - {'instance_id': instance_id, - 'device_name': '/dev/sdb1', - 'snapshot_id': '1', - 'volume_id': '2'}, - {'instance_id': instance_id, - 'device_name': '/dev/sdb2', - 'volume_id': '3', - 'volume_size': 1}, - {'instance_id': instance_id, - 'device_name': '/dev/sdb3', - 'delete_on_termination': True, - 'snapshot_id': '4', - 'volume_id': '5'}, - {'instance_id': instance_id, - 'device_name': '/dev/sdb4', - 'delete_on_termination': False, - 'snapshot_id': '6', - 'volume_id': '7'}, - {'instance_id': instance_id, - 'device_name': '/dev/sdb5', - 'snapshot_id': '8', - 'volume_id': '9', - 'volume_size': 0}, - {'instance_id': instance_id, - 'device_name': '/dev/sdb6', - 'snapshot_id': '10', - 'volume_id': '11', - 'volume_size': 1}, - {'instance_id': instance_id, - 'device_name': '/dev/sdb7', - 'no_device': True}, - {'instance_id': instance_id, - 'device_name': '/dev/sdb8', - 'virtual_name': 'swap'}, - {'instance_id': instance_id, - 'device_name': '/dev/sdb9', - 'virtual_name': 'ephemeral3'}] - - volumes = self._block_device_mapping_create(instance_id, mappings0) - return (inst1, inst2, volumes) - - def _tearDownBlockDeviceMapping(self, inst1, inst2, volumes): - for vol in volumes: - db.volume_destroy(self.context, vol['id']) - for id in (inst1['id'], inst2['id']): - for bdm in db.block_device_mapping_get_all_by_instance( - self.context, id): - db.block_device_mapping_destroy(self.context, bdm['id']) - db.instance_destroy(self.context, inst2['id']) - db.instance_destroy(self.context, inst1['id']) - - _expected_instance_bdm1 = { - 'instanceId': 'i-00000001', - 'rootDeviceName': '/dev/sdb1', - 'rootDeviceType': 'ebs'} - - _expected_block_device_mapping0 = [ - {'deviceName': '/dev/sdb1', - 'ebs': {'status': 'in-use', - 'deleteOnTermination': False, - 'volumeId': 2, - }}, - {'deviceName': '/dev/sdb2', - 'ebs': {'status': 'in-use', - 'deleteOnTermination': False, - 'volumeId': 3, - }}, - {'deviceName': '/dev/sdb3', - 'ebs': {'status': 'in-use', - 'deleteOnTermination': True, - 'volumeId': 5, - }}, - {'deviceName': '/dev/sdb4', - 'ebs': {'status': 'in-use', - 'deleteOnTermination': False, - 'volumeId': 7, - }}, - {'deviceName': '/dev/sdb5', - 'ebs': {'status': 'in-use', - 'deleteOnTermination': False, - 'volumeId': 9, - }}, - {'deviceName': '/dev/sdb6', - 'ebs': {'status': 'in-use', - 'deleteOnTermination': False, - 'volumeId': 11, }}] - # NOTE(yamahata): swap/ephemeral device case isn't supported yet. - - _expected_instance_bdm2 = { - 'instanceId': 'i-00000002', - 'rootDeviceName': '/dev/sdc1', - 'rootDeviceType': 'instance-store'} - - def test_format_instance_bdm(self): - (inst1, inst2, volumes) = self._setUpBlockDeviceMapping() - - result = {} - self.cloud._format_instance_bdm(self.context, inst1['id'], '/dev/sdb1', - result) - self.assertSubDictMatch( - {'rootDeviceType': self._expected_instance_bdm1['rootDeviceType']}, - result) - self._assertEqualBlockDeviceMapping( - self._expected_block_device_mapping0, result['blockDeviceMapping']) - - result = {} - self.cloud._format_instance_bdm(self.context, inst2['id'], '/dev/sdc1', - result) - self.assertSubDictMatch( - {'rootDeviceType': self._expected_instance_bdm2['rootDeviceType']}, - result) - - self._tearDownBlockDeviceMapping(inst1, inst2, volumes) - - def _assertInstance(self, instance_id): - ec2_instance_id = ec2utils.id_to_ec2_id(instance_id) - result = self.cloud.describe_instances(self.context, - instance_id=[ec2_instance_id]) - result = result['reservationSet'][0] - self.assertEqual(len(result['instancesSet']), 1) - result = result['instancesSet'][0] - self.assertEqual(result['instanceId'], ec2_instance_id) - return result - - def _assertEqualBlockDeviceMapping(self, expected, result): - self.assertEqual(len(expected), len(result)) - for x in expected: - found = False - for y in result: - if x['deviceName'] == y['deviceName']: - self.assertSubDictMatch(x, y) - found = True - break - self.assertTrue(found) - - def test_describe_instances_bdm(self): - """Make sure describe_instances works with root_device_name and - block device mappings - """ - (inst1, inst2, volumes) = self._setUpBlockDeviceMapping() - - result = self._assertInstance(inst1['id']) - self.assertSubDictMatch(self._expected_instance_bdm1, result) - self._assertEqualBlockDeviceMapping( - self._expected_block_device_mapping0, result['blockDeviceMapping']) - - result = self._assertInstance(inst2['id']) - self.assertSubDictMatch(self._expected_instance_bdm2, result) - - self._tearDownBlockDeviceMapping(inst1, inst2, volumes) - - def test_describe_images(self): - describe_images = self.cloud.describe_images - - def fake_detail(meh, context): - return [{'id': 1, 'container_format': 'ami', - 'properties': {'kernel_id': 1, 'ramdisk_id': 1, - 'type': 'machine'}}] - - def fake_show_none(meh, context, id): - raise exception.ImageNotFound(image_id='bad_image_id') - - self.stubs.Set(fake._FakeImageService, 'detail', fake_detail) - # list all - result1 = describe_images(self.context) - result1 = result1['imagesSet'][0] - self.assertEqual(result1['imageId'], 'ami-00000001') - # provided a valid image_id - result2 = describe_images(self.context, ['ami-00000001']) - self.assertEqual(1, len(result2['imagesSet'])) - # provide more than 1 valid image_id - result3 = describe_images(self.context, ['ami-00000001', - 'ami-00000002']) - self.assertEqual(2, len(result3['imagesSet'])) - # provide an non-existing image_id - self.stubs.UnsetAll() - self.stubs.Set(fake._FakeImageService, 'show', fake_show_none) - self.stubs.Set(fake._FakeImageService, 'show_by_name', fake_show_none) - self.assertRaises(exception.ImageNotFound, describe_images, - self.context, ['ami-fake']) - - def assertDictListUnorderedMatch(self, L1, L2, key): - self.assertEqual(len(L1), len(L2)) - for d1 in L1: - self.assertTrue(key in d1) - for d2 in L2: - self.assertTrue(key in d2) - if d1[key] == d2[key]: - self.assertDictMatch(d1, d2) - - def _setUpImageSet(self, create_volumes_and_snapshots=False): - mappings1 = [ - {'device': '/dev/sda1', 'virtual': 'root'}, - - {'device': 'sdb0', 'virtual': 'ephemeral0'}, - {'device': 'sdb1', 'virtual': 'ephemeral1'}, - {'device': 'sdb2', 'virtual': 'ephemeral2'}, - {'device': 'sdb3', 'virtual': 'ephemeral3'}, - {'device': 'sdb4', 'virtual': 'ephemeral4'}, - - {'device': 'sdc0', 'virtual': 'swap'}, - {'device': 'sdc1', 'virtual': 'swap'}, - {'device': 'sdc2', 'virtual': 'swap'}, - {'device': 'sdc3', 'virtual': 'swap'}, - {'device': 'sdc4', 'virtual': 'swap'}] - block_device_mapping1 = [ - {'device_name': '/dev/sdb1', 'snapshot_id': 01234567}, - {'device_name': '/dev/sdb2', 'volume_id': 01234567}, - {'device_name': '/dev/sdb3', 'virtual_name': 'ephemeral5'}, - {'device_name': '/dev/sdb4', 'no_device': True}, - - {'device_name': '/dev/sdc1', 'snapshot_id': 12345678}, - {'device_name': '/dev/sdc2', 'volume_id': 12345678}, - {'device_name': '/dev/sdc3', 'virtual_name': 'ephemeral6'}, - {'device_name': '/dev/sdc4', 'no_device': True}] - image1 = { - 'id': 1, - 'properties': { - 'kernel_id': 1, - 'type': 'machine', - 'image_state': 'available', - 'mappings': mappings1, - 'block_device_mapping': block_device_mapping1, - } - } - - mappings2 = [{'device': '/dev/sda1', 'virtual': 'root'}] - block_device_mapping2 = [{'device_name': '/dev/sdb1', - 'snapshot_id': 01234567}] - image2 = { - 'id': 2, - 'properties': { - 'kernel_id': 2, - 'type': 'machine', - 'root_device_name': '/dev/sdb1', - 'mappings': mappings2, - 'block_device_mapping': block_device_mapping2}} - - def fake_show(meh, context, image_id): - for i in [image1, image2]: - if i['id'] == image_id: - return i - raise exception.ImageNotFound(image_id=image_id) - - def fake_detail(meh, context): - return [image1, image2] - - self.stubs.Set(fake._FakeImageService, 'show', fake_show) - self.stubs.Set(fake._FakeImageService, 'detail', fake_detail) - - volumes = [] - snapshots = [] - if create_volumes_and_snapshots: - for bdm in block_device_mapping1: - if 'volume_id' in bdm: - vol = self._volume_create(bdm['volume_id']) - volumes.append(vol['id']) - if 'snapshot_id' in bdm: - snap = db.snapshot_create(self.context, - {'id': bdm['snapshot_id'], - 'volume_id': 76543210, - 'status': "available", - 'volume_size': 1}) - snapshots.append(snap['id']) - return (volumes, snapshots) - - def _assertImageSet(self, result, root_device_type, root_device_name): - self.assertEqual(1, len(result['imagesSet'])) - result = result['imagesSet'][0] - self.assertTrue('rootDeviceType' in result) - self.assertEqual(result['rootDeviceType'], root_device_type) - self.assertTrue('rootDeviceName' in result) - self.assertEqual(result['rootDeviceName'], root_device_name) - self.assertTrue('blockDeviceMapping' in result) - - return result - - _expected_root_device_name1 = '/dev/sda1' - # NOTE(yamahata): noDevice doesn't make sense when returning mapping - # It makes sense only when user overriding existing - # mapping. - _expected_bdms1 = [ - {'deviceName': '/dev/sdb0', 'virtualName': 'ephemeral0'}, - {'deviceName': '/dev/sdb1', 'ebs': {'snapshotId': - 'snap-00053977'}}, - {'deviceName': '/dev/sdb2', 'ebs': {'snapshotId': - 'vol-00053977'}}, - {'deviceName': '/dev/sdb3', 'virtualName': 'ephemeral5'}, - # {'deviceName': '/dev/sdb4', 'noDevice': True}, - - {'deviceName': '/dev/sdc0', 'virtualName': 'swap'}, - {'deviceName': '/dev/sdc1', 'ebs': {'snapshotId': - 'snap-00bc614e'}}, - {'deviceName': '/dev/sdc2', 'ebs': {'snapshotId': - 'vol-00bc614e'}}, - {'deviceName': '/dev/sdc3', 'virtualName': 'ephemeral6'}, - # {'deviceName': '/dev/sdc4', 'noDevice': True} - ] - - _expected_root_device_name2 = '/dev/sdb1' - _expected_bdms2 = [{'deviceName': '/dev/sdb1', - 'ebs': {'snapshotId': 'snap-00053977'}}] - - # NOTE(yamahata): - # InstanceBlockDeviceMappingItemType - # rootDeviceType - # rootDeviceName - # blockDeviceMapping - # deviceName - # virtualName - # ebs - # snapshotId - # volumeSize - # deleteOnTermination - # noDevice - def test_describe_image_mapping(self): - """test for rootDeviceName and blockDeiceMapping""" - describe_images = self.cloud.describe_images - self._setUpImageSet() - - result = describe_images(self.context, ['ami-00000001']) - result = self._assertImageSet(result, 'instance-store', - self._expected_root_device_name1) - - self.assertDictListUnorderedMatch(result['blockDeviceMapping'], - self._expected_bdms1, 'deviceName') - - result = describe_images(self.context, ['ami-00000002']) - result = self._assertImageSet(result, 'ebs', - self._expected_root_device_name2) - - self.assertDictListUnorderedMatch(result['blockDeviceMapping'], - self._expected_bdms2, 'deviceName') - - self.stubs.UnsetAll() - - def test_describe_image_attribute(self): - describe_image_attribute = self.cloud.describe_image_attribute - - def fake_show(meh, context, id): - return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1, - 'type': 'machine'}, 'container_format': 'ami', - 'is_public': True} - - self.stubs.Set(fake._FakeImageService, 'show', fake_show) - self.stubs.Set(fake._FakeImageService, 'show_by_name', fake_show) - result = describe_image_attribute(self.context, 'ami-00000001', - 'launchPermission') - self.assertEqual([{'group': 'all'}], result['launchPermission']) - - def test_describe_image_attribute_root_device_name(self): - describe_image_attribute = self.cloud.describe_image_attribute - self._setUpImageSet() - - result = describe_image_attribute(self.context, 'ami-00000001', - 'rootDeviceName') - self.assertEqual(result['rootDeviceName'], - self._expected_root_device_name1) - result = describe_image_attribute(self.context, 'ami-00000002', - 'rootDeviceName') - self.assertEqual(result['rootDeviceName'], - self._expected_root_device_name2) - - def test_describe_image_attribute_block_device_mapping(self): - describe_image_attribute = self.cloud.describe_image_attribute - self._setUpImageSet() - - result = describe_image_attribute(self.context, 'ami-00000001', - 'blockDeviceMapping') - self.assertDictListUnorderedMatch(result['blockDeviceMapping'], - self._expected_bdms1, 'deviceName') - result = describe_image_attribute(self.context, 'ami-00000002', - 'blockDeviceMapping') - self.assertDictListUnorderedMatch(result['blockDeviceMapping'], - self._expected_bdms2, 'deviceName') - - def test_modify_image_attribute(self): - modify_image_attribute = self.cloud.modify_image_attribute - - fake_metadata = {'id': 1, 'container_format': 'ami', - 'properties': {'kernel_id': 1, 'ramdisk_id': 1, - 'type': 'machine'}, 'is_public': False} - - def fake_show(meh, context, id): - return fake_metadata - - def fake_update(meh, context, image_id, metadata, data=None): - fake_metadata.update(metadata) - return fake_metadata - - self.stubs.Set(fake._FakeImageService, 'show', fake_show) - self.stubs.Set(fake._FakeImageService, 'show_by_name', fake_show) - self.stubs.Set(fake._FakeImageService, 'update', fake_update) - result = modify_image_attribute(self.context, 'ami-00000001', - 'launchPermission', 'add', - user_group=['all']) - self.assertEqual(True, result['is_public']) - - def test_deregister_image(self): - deregister_image = self.cloud.deregister_image - - def fake_delete(self, context, id): - return None - - self.stubs.Set(fake._FakeImageService, 'delete', fake_delete) - # valid image - result = deregister_image(self.context, 'ami-00000001') - self.assertEqual(result['imageId'], 'ami-00000001') - # invalid image - self.stubs.UnsetAll() - - def fake_detail_empty(self, context): - return [] - - self.stubs.Set(fake._FakeImageService, 'detail', fake_detail_empty) - self.assertRaises(exception.ImageNotFound, deregister_image, - self.context, 'ami-bad001') - - def test_deregister_image_wrong_container_type(self): - deregister_image = self.cloud.deregister_image - - def fake_delete(self, context, id): - return None - - self.stubs.Set(fake._FakeImageService, 'delete', fake_delete) - self.assertRaises(exception.NotFound, deregister_image, self.context, - 'aki-00000001') - - def _run_instance(self, **kwargs): - rv = self.cloud.run_instances(self.context, **kwargs) - instance_id = rv['instancesSet'][0]['instanceId'] - return instance_id - - def _run_instance_wait(self, **kwargs): - ec2_instance_id = self._run_instance(**kwargs) - self._wait_for_running(ec2_instance_id) - return ec2_instance_id - - def test_console_output(self): - instance_id = self._run_instance( - image_id='ami-1', - instance_type=FLAGS.default_instance_type, - max_count=1) - output = self.cloud.get_console_output(context=self.context, - instance_id=[instance_id]) - self.assertEquals(b64decode(output['output']), 'FAKE CONSOLE?OUTPUT') - # TODO(soren): We need this until we can stop polling in the rpc code - # for unit tests. - rv = self.cloud.terminate_instances(self.context, [instance_id]) - - def test_ajax_console(self): - instance_id = self._run_instance(image_id='ami-1') - output = self.cloud.get_ajax_console(context=self.context, - instance_id=[instance_id]) - self.assertEquals(output['url'], - '%s/?token=FAKETOKEN' % FLAGS.ajax_console_proxy_url) - # TODO(soren): We need this until we can stop polling in the rpc code - # for unit tests. - rv = self.cloud.terminate_instances(self.context, [instance_id]) - - def test_key_generation(self): - result = self._create_key('test') - private_key = result['private_key'] - key = RSA.load_key_string(private_key, callback=lambda: None) - bio = BIO.MemoryBuffer() - public_key = db.key_pair_get(self.context, - self.context.user_id, - 'test')['public_key'] - key.save_pub_key_bio(bio) - converted = crypto.ssl_pub_to_ssh_pub(bio.read()) - # assert key fields are equal - self.assertEqual(public_key.split(" ")[1].strip(), - converted.split(" ")[1].strip()) - - def test_describe_key_pairs(self): - self._create_key('test1') - self._create_key('test2') - result = self.cloud.describe_key_pairs(self.context) - keys = result["keySet"] - self.assertTrue(filter(lambda k: k['keyName'] == 'test1', keys)) - self.assertTrue(filter(lambda k: k['keyName'] == 'test2', keys)) - - def test_import_public_key(self): - # test when user provides all values - result1 = self.cloud.import_public_key(self.context, - 'testimportkey1', - 'mytestpubkey', - 'mytestfprint') - self.assertTrue(result1) - keydata = db.key_pair_get(self.context, - self.context.user_id, - 'testimportkey1') - self.assertEqual('mytestpubkey', keydata['public_key']) - self.assertEqual('mytestfprint', keydata['fingerprint']) - # test when user omits fingerprint - pubkey_path = os.path.join(os.path.dirname(__file__), 'public_key') - f = open(pubkey_path + '/dummy.pub', 'r') - dummypub = f.readline().rstrip() - f.close - f = open(pubkey_path + '/dummy.fingerprint', 'r') - dummyfprint = f.readline().rstrip() - f.close - result2 = self.cloud.import_public_key(self.context, - 'testimportkey2', - dummypub) - self.assertTrue(result2) - keydata = db.key_pair_get(self.context, - self.context.user_id, - 'testimportkey2') - self.assertEqual(dummypub, keydata['public_key']) - self.assertEqual(dummyfprint, keydata['fingerprint']) - - def test_delete_key_pair(self): - self._create_key('test') - self.cloud.delete_key_pair(self.context, 'test') - - def test_run_instances(self): - kwargs = {'image_id': FLAGS.default_image, - 'instance_type': FLAGS.default_instance_type, - 'max_count': 1} - run_instances = self.cloud.run_instances - result = run_instances(self.context, **kwargs) - instance = result['instancesSet'][0] - self.assertEqual(instance['imageId'], 'ami-00000001') - self.assertEqual(instance['displayName'], 'Server 1') - self.assertEqual(instance['instanceId'], 'i-00000001') - self.assertEqual(instance['instanceState']['name'], 'running') - self.assertEqual(instance['instanceType'], 'm1.small') - - def test_run_instances_image_state_none(self): - kwargs = {'image_id': FLAGS.default_image, - 'instance_type': FLAGS.default_instance_type, - 'max_count': 1} - run_instances = self.cloud.run_instances - - def fake_show_no_state(self, context, id): - return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1, - 'type': 'machine'}, 'container_format': 'ami'} - - self.stubs.UnsetAll() - self.stubs.Set(fake._FakeImageService, 'show', fake_show_no_state) - self.assertRaises(exception.ApiError, run_instances, - self.context, **kwargs) - - def test_run_instances_image_state_invalid(self): - kwargs = {'image_id': FLAGS.default_image, - 'instance_type': FLAGS.default_instance_type, - 'max_count': 1} - run_instances = self.cloud.run_instances - - def fake_show_decrypt(self, context, id): - return {'id': 1, 'container_format': 'ami', - 'properties': {'kernel_id': 1, 'ramdisk_id': 1, - 'type': 'machine', 'image_state': 'decrypting'}} - - self.stubs.UnsetAll() - self.stubs.Set(fake._FakeImageService, 'show', fake_show_decrypt) - self.assertRaises(exception.ApiError, run_instances, - self.context, **kwargs) - - def test_run_instances_image_status_active(self): - kwargs = {'image_id': FLAGS.default_image, - 'instance_type': FLAGS.default_instance_type, - 'max_count': 1} - run_instances = self.cloud.run_instances - - def fake_show_stat_active(self, context, id): - return {'id': 1, 'container_format': 'ami', - 'properties': {'kernel_id': 1, 'ramdisk_id': 1, - 'type': 'machine'}, 'status': 'active'} - - self.stubs.Set(fake._FakeImageService, 'show', fake_show_stat_active) - - result = run_instances(self.context, **kwargs) - self.assertEqual(len(result['instancesSet']), 1) - - def test_terminate_instances(self): - inst1 = db.instance_create(self.context, {'reservation_id': 'a', - 'image_ref': 1, - 'host': 'host1'}) - terminate_instances = self.cloud.terminate_instances - # valid instance_id - result = terminate_instances(self.context, ['i-00000001']) - self.assertTrue(result) - # non-existing instance_id - self.assertRaises(exception.InstanceNotFound, terminate_instances, - self.context, ['i-2']) - db.instance_destroy(self.context, inst1['id']) - - def test_update_of_instance_display_fields(self): - inst = db.instance_create(self.context, {}) - ec2_id = ec2utils.id_to_ec2_id(inst['id']) - self.cloud.update_instance(self.context, ec2_id, - display_name='c00l 1m4g3') - inst = db.instance_get(self.context, inst['id']) - self.assertEqual('c00l 1m4g3', inst['display_name']) - db.instance_destroy(self.context, inst['id']) - - def test_update_of_instance_wont_update_private_fields(self): - inst = db.instance_create(self.context, {}) - host = inst['host'] - ec2_id = ec2utils.id_to_ec2_id(inst['id']) - self.cloud.update_instance(self.context, ec2_id, - display_name='c00l 1m4g3', - host='otherhost') - inst = db.instance_get(self.context, inst['id']) - self.assertEqual(host, inst['host']) - db.instance_destroy(self.context, inst['id']) - - def test_update_of_volume_display_fields(self): - vol = db.volume_create(self.context, {}) - self.cloud.update_volume(self.context, - ec2utils.id_to_ec2_vol_id(vol['id']), - display_name='c00l v0lum3') - vol = db.volume_get(self.context, vol['id']) - self.assertEqual('c00l v0lum3', vol['display_name']) - db.volume_destroy(self.context, vol['id']) - - def test_update_of_volume_wont_update_private_fields(self): - vol = db.volume_create(self.context, {}) - self.cloud.update_volume(self.context, - ec2utils.id_to_ec2_vol_id(vol['id']), - mountpoint='/not/here') - vol = db.volume_get(self.context, vol['id']) - self.assertEqual(None, vol['mountpoint']) - db.volume_destroy(self.context, vol['id']) - - def _restart_compute_service(self, periodic_interval=None): - """restart compute service. NOTE: fake driver forgets all instances.""" - self.compute.kill() - if periodic_interval: - self.compute = self.start_service( - 'compute', periodic_interval=periodic_interval) - else: - self.compute = self.start_service('compute') - - def _wait_for_state(self, ctxt, instance_id, predicate): - """Wait for a stopped instance to be a given state""" - id = ec2utils.ec2_id_to_id(instance_id) - while True: - info = self.cloud.compute_api.get(context=ctxt, instance_id=id) - LOG.debug(info) - if predicate(info): - break - greenthread.sleep(1) - - def _wait_for_running(self, instance_id): - def is_running(info): - vm_state = info["vm_state"] - task_state = info["task_state"] - return vm_state == vm_states.ACTIVE and task_state == None - self._wait_for_state(self.context, instance_id, is_running) - - def _wait_for_stopped(self, instance_id): - def is_stopped(info): - vm_state = info["vm_state"] - task_state = info["task_state"] - return vm_state == vm_states.STOPPED and task_state == None - self._wait_for_state(self.context, instance_id, is_stopped) - - def _wait_for_terminate(self, instance_id): - def is_deleted(info): - return info['deleted'] - elevated = self.context.elevated(read_deleted=True) - self._wait_for_state(elevated, instance_id, is_deleted) - - def test_stop_start_instance(self): - """Makes sure stop/start instance works""" - # enforce periodic tasks run in short time to avoid wait for 60s. - self._restart_compute_service(periodic_interval=0.3) - - kwargs = {'image_id': 'ami-1', - 'instance_type': FLAGS.default_instance_type, - 'max_count': 1, } - instance_id = self._run_instance_wait(**kwargs) - - # a running instance can't be started. It is just ignored. - result = self.cloud.start_instances(self.context, [instance_id]) - greenthread.sleep(0.3) - self.assertTrue(result) - - result = self.cloud.stop_instances(self.context, [instance_id]) - greenthread.sleep(0.3) - self.assertTrue(result) - self._wait_for_stopped(instance_id) - - result = self.cloud.start_instances(self.context, [instance_id]) - greenthread.sleep(0.3) - self.assertTrue(result) - self._wait_for_running(instance_id) - - result = self.cloud.stop_instances(self.context, [instance_id]) - greenthread.sleep(0.3) - self.assertTrue(result) - self._wait_for_stopped(instance_id) - - result = self.cloud.terminate_instances(self.context, [instance_id]) - greenthread.sleep(0.3) - self.assertTrue(result) - - self._restart_compute_service() - - def _volume_create(self, volume_id=None): - kwargs = {'status': 'available', - 'host': self.volume.host, - 'size': 1, - 'attach_status': 'detached', } - if volume_id: - kwargs['id'] = volume_id - return db.volume_create(self.context, kwargs) - - def _assert_volume_attached(self, vol, instance_id, mountpoint): - self.assertEqual(vol['instance_id'], instance_id) - self.assertEqual(vol['mountpoint'], mountpoint) - self.assertEqual(vol['status'], "in-use") - self.assertEqual(vol['attach_status'], "attached") - - def _assert_volume_detached(self, vol): - self.assertEqual(vol['instance_id'], None) - self.assertEqual(vol['mountpoint'], None) - self.assertEqual(vol['status'], "available") - self.assertEqual(vol['attach_status'], "detached") - - def test_stop_start_with_volume(self): - """Make sure run instance with block device mapping works""" - - # enforce periodic tasks run in short time to avoid wait for 60s. - self._restart_compute_service(periodic_interval=0.3) - - vol1 = self._volume_create() - vol2 = self._volume_create() - kwargs = {'image_id': 'ami-1', - 'instance_type': FLAGS.default_instance_type, - 'max_count': 1, - 'block_device_mapping': [{'device_name': '/dev/vdb', - 'volume_id': vol1['id'], - 'delete_on_termination': False}, - {'device_name': '/dev/vdc', - 'volume_id': vol2['id'], - 'delete_on_termination': True}, - ]} - ec2_instance_id = self._run_instance_wait(**kwargs) - instance_id = ec2utils.ec2_id_to_id(ec2_instance_id) - - vols = db.volume_get_all_by_instance(self.context, instance_id) - self.assertEqual(len(vols), 2) - for vol in vols: - self.assertTrue(vol['id'] == vol1['id'] or vol['id'] == vol2['id']) - - vol = db.volume_get(self.context, vol1['id']) - self._assert_volume_attached(vol, instance_id, '/dev/vdb') - - vol = db.volume_get(self.context, vol2['id']) - self._assert_volume_attached(vol, instance_id, '/dev/vdc') - - result = self.cloud.stop_instances(self.context, [ec2_instance_id]) - self.assertTrue(result) - self._wait_for_stopped(ec2_instance_id) - - vol = db.volume_get(self.context, vol1['id']) - self._assert_volume_detached(vol) - vol = db.volume_get(self.context, vol2['id']) - self._assert_volume_detached(vol) - - self.cloud.start_instances(self.context, [ec2_instance_id]) - self._wait_for_running(ec2_instance_id) - vols = db.volume_get_all_by_instance(self.context, instance_id) - self.assertEqual(len(vols), 2) - for vol in vols: - self.assertTrue(vol['id'] == vol1['id'] or vol['id'] == vol2['id']) - self.assertTrue(vol['mountpoint'] == '/dev/vdb' or - vol['mountpoint'] == '/dev/vdc') - self.assertEqual(vol['instance_id'], instance_id) - self.assertEqual(vol['status'], "in-use") - self.assertEqual(vol['attach_status'], "attached") - - self.cloud.terminate_instances(self.context, [ec2_instance_id]) - greenthread.sleep(0.3) - - admin_ctxt = context.get_admin_context(read_deleted=False) - vol = db.volume_get(admin_ctxt, vol1['id']) - self.assertFalse(vol['deleted']) - db.volume_destroy(self.context, vol1['id']) - - greenthread.sleep(0.3) - admin_ctxt = context.get_admin_context(read_deleted=True) - vol = db.volume_get(admin_ctxt, vol2['id']) - self.assertTrue(vol['deleted']) - - self._restart_compute_service() - - def test_stop_with_attached_volume(self): - """Make sure attach info is reflected to block device mapping""" - # enforce periodic tasks run in short time to avoid wait for 60s. - self._restart_compute_service(periodic_interval=0.3) - - vol1 = self._volume_create() - vol2 = self._volume_create() - kwargs = {'image_id': 'ami-1', - 'instance_type': FLAGS.default_instance_type, - 'max_count': 1, - 'block_device_mapping': [{'device_name': '/dev/vdb', - 'volume_id': vol1['id'], - 'delete_on_termination': True}]} - ec2_instance_id = self._run_instance_wait(**kwargs) - instance_id = ec2utils.ec2_id_to_id(ec2_instance_id) - - vols = db.volume_get_all_by_instance(self.context, instance_id) - self.assertEqual(len(vols), 1) - for vol in vols: - self.assertEqual(vol['id'], vol1['id']) - self._assert_volume_attached(vol, instance_id, '/dev/vdb') - - vol = db.volume_get(self.context, vol2['id']) - self._assert_volume_detached(vol) - - self.cloud.compute_api.attach_volume(self.context, - instance_id=instance_id, - volume_id=vol2['id'], - device='/dev/vdc') - greenthread.sleep(0.3) - vol = db.volume_get(self.context, vol2['id']) - self._assert_volume_attached(vol, instance_id, '/dev/vdc') - - self.cloud.compute_api.detach_volume(self.context, - volume_id=vol1['id']) - greenthread.sleep(0.3) - vol = db.volume_get(self.context, vol1['id']) - self._assert_volume_detached(vol) - - result = self.cloud.stop_instances(self.context, [ec2_instance_id]) - self.assertTrue(result) - self._wait_for_stopped(ec2_instance_id) - - for vol_id in (vol1['id'], vol2['id']): - vol = db.volume_get(self.context, vol_id) - self._assert_volume_detached(vol) - - self.cloud.start_instances(self.context, [ec2_instance_id]) - self._wait_for_running(ec2_instance_id) - vols = db.volume_get_all_by_instance(self.context, instance_id) - self.assertEqual(len(vols), 1) - for vol in vols: - self.assertEqual(vol['id'], vol2['id']) - self._assert_volume_attached(vol, instance_id, '/dev/vdc') - - vol = db.volume_get(self.context, vol1['id']) - self._assert_volume_detached(vol) - - self.cloud.terminate_instances(self.context, [ec2_instance_id]) - greenthread.sleep(0.3) - - for vol_id in (vol1['id'], vol2['id']): - vol = db.volume_get(self.context, vol_id) - self.assertEqual(vol['id'], vol_id) - self._assert_volume_detached(vol) - db.volume_destroy(self.context, vol_id) - - self._restart_compute_service() - - def _create_snapshot(self, ec2_volume_id): - result = self.cloud.create_snapshot(self.context, - volume_id=ec2_volume_id) - greenthread.sleep(0.3) - return result['snapshotId'] - - def test_run_with_snapshot(self): - """Makes sure run/stop/start instance with snapshot works.""" - vol = self._volume_create() - ec2_volume_id = ec2utils.id_to_ec2_vol_id(vol['id']) - - ec2_snapshot1_id = self._create_snapshot(ec2_volume_id) - snapshot1_id = ec2utils.ec2_id_to_id(ec2_snapshot1_id) - ec2_snapshot2_id = self._create_snapshot(ec2_volume_id) - snapshot2_id = ec2utils.ec2_id_to_id(ec2_snapshot2_id) - - kwargs = {'image_id': 'ami-1', - 'instance_type': FLAGS.default_instance_type, - 'max_count': 1, - 'block_device_mapping': [{'device_name': '/dev/vdb', - 'snapshot_id': snapshot1_id, - 'delete_on_termination': False, }, - {'device_name': '/dev/vdc', - 'snapshot_id': snapshot2_id, - 'delete_on_termination': True}]} - ec2_instance_id = self._run_instance_wait(**kwargs) - instance_id = ec2utils.ec2_id_to_id(ec2_instance_id) - - vols = db.volume_get_all_by_instance(self.context, instance_id) - self.assertEqual(len(vols), 2) - vol1_id = None - vol2_id = None - for vol in vols: - snapshot_id = vol['snapshot_id'] - if snapshot_id == snapshot1_id: - vol1_id = vol['id'] - mountpoint = '/dev/vdb' - elif snapshot_id == snapshot2_id: - vol2_id = vol['id'] - mountpoint = '/dev/vdc' - else: - self.fail() - - self._assert_volume_attached(vol, instance_id, mountpoint) - - self.assertTrue(vol1_id) - self.assertTrue(vol2_id) - - self.cloud.terminate_instances(self.context, [ec2_instance_id]) - greenthread.sleep(0.3) - self._wait_for_terminate(ec2_instance_id) - - greenthread.sleep(0.3) - admin_ctxt = context.get_admin_context(read_deleted=False) - vol = db.volume_get(admin_ctxt, vol1_id) - self._assert_volume_detached(vol) - self.assertFalse(vol['deleted']) - db.volume_destroy(self.context, vol1_id) - - greenthread.sleep(0.3) - admin_ctxt = context.get_admin_context(read_deleted=True) - vol = db.volume_get(admin_ctxt, vol2_id) - self.assertTrue(vol['deleted']) - - for snapshot_id in (ec2_snapshot1_id, ec2_snapshot2_id): - self.cloud.delete_snapshot(self.context, snapshot_id) - greenthread.sleep(0.3) - db.volume_destroy(self.context, vol['id']) - - def test_create_image(self): - """Make sure that CreateImage works""" - # enforce periodic tasks run in short time to avoid wait for 60s. - self._restart_compute_service(periodic_interval=0.3) - - (volumes, snapshots) = self._setUpImageSet( - create_volumes_and_snapshots=True) - - kwargs = {'image_id': 'ami-1', - 'instance_type': FLAGS.default_instance_type, - 'max_count': 1} - ec2_instance_id = self._run_instance_wait(**kwargs) - - # TODO(yamahata): s3._s3_create() can't be tested easily by unit test - # as there is no unit test for s3.create() - ## result = self.cloud.create_image(self.context, ec2_instance_id, - ## no_reboot=True) - ## ec2_image_id = result['imageId'] - ## created_image = self.cloud.describe_images(self.context, - ## [ec2_image_id]) - - self.cloud.terminate_instances(self.context, [ec2_instance_id]) - for vol in volumes: - db.volume_destroy(self.context, vol) - for snap in snapshots: - db.snapshot_destroy(self.context, snap) - # TODO(yamahata): clean up snapshot created by CreateImage. - - self._restart_compute_service() - - @staticmethod - def _fake_bdm_get(ctxt, id): - return [{'volume_id': 87654321, - 'snapshot_id': None, - 'no_device': None, - 'virtual_name': None, - 'delete_on_termination': True, - 'device_name': '/dev/sdh'}, - {'volume_id': None, - 'snapshot_id': 98765432, - 'no_device': None, - 'virtual_name': None, - 'delete_on_termination': True, - 'device_name': '/dev/sdi'}, - {'volume_id': None, - 'snapshot_id': None, - 'no_device': True, - 'virtual_name': None, - 'delete_on_termination': None, - 'device_name': None}, - {'volume_id': None, - 'snapshot_id': None, - 'no_device': None, - 'virtual_name': 'ephemeral0', - 'delete_on_termination': None, - 'device_name': '/dev/sdb'}, - {'volume_id': None, - 'snapshot_id': None, - 'no_device': None, - 'virtual_name': 'swap', - 'delete_on_termination': None, - 'device_name': '/dev/sdc'}, - {'volume_id': None, - 'snapshot_id': None, - 'no_device': None, - 'virtual_name': 'ephemeral1', - 'delete_on_termination': None, - 'device_name': '/dev/sdd'}, - {'volume_id': None, - 'snapshot_id': None, - 'no_device': None, - 'virtual_name': 'ephemeral2', - 'delete_on_termination': None, - 'device_name': '/dev/sd3'}, - ] - - def test_get_instance_mapping(self): - """Make sure that _get_instance_mapping works""" - ctxt = None - instance_ref0 = {'id': 0, - 'root_device_name': None} - instance_ref1 = {'id': 0, - 'root_device_name': '/dev/sda1'} - - self.stubs.Set(db, 'block_device_mapping_get_all_by_instance', - self._fake_bdm_get) - - expected = {'ami': 'sda1', - 'root': '/dev/sda1', - 'ephemeral0': '/dev/sdb', - 'swap': '/dev/sdc', - 'ephemeral1': '/dev/sdd', - 'ephemeral2': '/dev/sd3'} - - self.assertEqual(self.cloud._format_instance_mapping(ctxt, - instance_ref0), - cloud._DEFAULT_MAPPINGS) - self.assertEqual(self.cloud._format_instance_mapping(ctxt, - instance_ref1), - expected) - - def test_describe_instance_attribute(self): - """Make sure that describe_instance_attribute works""" - self.stubs.Set(db, 'block_device_mapping_get_all_by_instance', - self._fake_bdm_get) - - def fake_get(ctxt, instance_id): - return { - 'id': 0, - 'root_device_name': '/dev/sdh', - 'security_groups': [{'name': 'fake0'}, {'name': 'fake1'}], - 'vm_state': vm_states.STOPPED, - 'instance_type': {'name': 'fake_type'}, - 'kernel_id': 1, - 'ramdisk_id': 2, - 'user_data': 'fake-user data', - } - self.stubs.Set(self.cloud.compute_api, 'get', fake_get) - - def fake_volume_get(ctxt, volume_id, session=None): - if volume_id == 87654321: - return {'id': volume_id, - 'attach_time': '13:56:24', - 'status': 'in-use'} - raise exception.VolumeNotFound(volume_id=volume_id) - self.stubs.Set(db.api, 'volume_get', fake_volume_get) - - get_attribute = functools.partial( - self.cloud.describe_instance_attribute, - self.context, 'i-12345678') - - bdm = get_attribute('blockDeviceMapping') - bdm['blockDeviceMapping'].sort() - - expected_bdm = {'instance_id': 'i-12345678', - 'rootDeviceType': 'ebs', - 'blockDeviceMapping': [ - {'deviceName': '/dev/sdh', - 'ebs': {'status': 'in-use', - 'deleteOnTermination': True, - 'volumeId': 87654321, - 'attachTime': '13:56:24'}}]} - expected_bdm['blockDeviceMapping'].sort() - self.assertEqual(bdm, expected_bdm) - # NOTE(yamahata): this isn't supported - # get_attribute('disableApiTermination') - groupSet = get_attribute('groupSet') - groupSet['groupSet'].sort() - expected_groupSet = {'instance_id': 'i-12345678', - 'groupSet': [{'groupId': 'fake0'}, - {'groupId': 'fake1'}]} - expected_groupSet['groupSet'].sort() - self.assertEqual(groupSet, expected_groupSet) - self.assertEqual(get_attribute('instanceInitiatedShutdownBehavior'), - {'instance_id': 'i-12345678', - 'instanceInitiatedShutdownBehavior': 'stopped'}) - self.assertEqual(get_attribute('instanceType'), - {'instance_id': 'i-12345678', - 'instanceType': 'fake_type'}) - self.assertEqual(get_attribute('kernel'), - {'instance_id': 'i-12345678', - 'kernel': 'aki-00000001'}) - self.assertEqual(get_attribute('ramdisk'), - {'instance_id': 'i-12345678', - 'ramdisk': 'ari-00000002'}) - self.assertEqual(get_attribute('rootDeviceName'), - {'instance_id': 'i-12345678', - 'rootDeviceName': '/dev/sdh'}) - # NOTE(yamahata): this isn't supported - # get_attribute('sourceDestCheck') - self.assertEqual(get_attribute('userData'), - {'instance_id': 'i-12345678', - 'userData': '}\xa9\x1e\xba\xc7\xabu\xabZ'}) From c8f08a089a16a50e549f7e442136e4519f474753 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Mon, 12 Sep 2011 18:23:46 -0400 Subject: [PATCH 065/100] fixing import --- nova/tests/test_direct.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/test_direct.py b/nova/tests/test_direct.py index 4ed0c2aa..8d856dc4 100644 --- a/nova/tests/test_direct.py +++ b/nova/tests/test_direct.py @@ -30,7 +30,7 @@ from nova import test from nova import volume from nova import utils from nova.api import direct -from nova.tests import test_cloud +from nova.tests.api.ec2 import test_cloud class ArbitraryObject(object): From 78850f699c5bb0df75e96ce0a61eac9d916bf595 Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Tue, 13 Sep 2011 15:09:10 +0200 Subject: [PATCH 066/100] Update MANIFEST.in to match directory moves from rev1559 --- MANIFEST.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index 883aba8a..5451ace4 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -37,7 +37,7 @@ include nova/tests/bundle/1mb.manifest.xml include nova/tests/bundle/1mb.no_kernel_or_ramdisk.manifest.xml include nova/tests/bundle/1mb.part.0 include nova/tests/bundle/1mb.part.1 -include nova/tests/public_key/* +include nova/tests/api/ec2/public_key/* include nova/tests/db/nova.austin.sqlite include plugins/xenapi/README include plugins/xenapi/etc/xapi.d/plugins/objectstore From d96e650c06517384acb9fe03722dcc40b789052b Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Tue, 13 Sep 2011 15:48:10 -0400 Subject: [PATCH 067/100] Update test_libvirt so that flags and fakes are used instead of mocks for utils.import_class and utils.import_object. Fixes #lp849329. --- nova/tests/test_libvirt.py | 87 ++++++++++++++------------------------ 1 file changed, 32 insertions(+), 55 deletions(-) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 233ee14d..8193d6ec 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -51,6 +51,32 @@ def _concurrency(wait, done, target): done.send() +class FakeVirtDomain(object): + + def __init__(self, fake_xml=None): + if fake_xml: + self._fake_dom_xml = fake_xml + else: + self._fake_dom_xml=""" + + + + + + + + """ + + def snapshotCreateXML(self, *args): + return None + + def createWithFlags(self, launch_flags): + pass + + def XMLDesc(self, *args): + return self._fake_dom_xml + + class CacheConcurrencyTestCase(test.TestCase): def setUp(self): super(CacheConcurrencyTestCase, self).setUp() @@ -152,70 +178,23 @@ class LibvirtConnTestCase(test.TestCase): # A fake libvirt.virConnect class FakeLibvirtConnection(object): - pass - - # A fake connection.IptablesFirewallDriver - class FakeIptablesFirewallDriver(object): - - def __init__(self, **kwargs): - pass - - def setattr(self, key, val): - self.__setattr__(key, val) - - # A fake VIF driver - class FakeVIFDriver(object): - - def __init__(self, **kwargs): - pass - - def setattr(self, key, val): - self.__setattr__(key, val) - - def plug(self, instance, network, mapping): - return { - 'id': 'fake', - 'bridge_name': 'fake', - 'mac_address': 'fake', - 'ip_address': 'fake', - 'dhcp_server': 'fake', - 'extra_params': 'fake', - } + def defineXML(self, xml): + return FakeVirtDomain() # Creating mocks fake = FakeLibvirtConnection() - fakeip = FakeIptablesFirewallDriver - fakevif = FakeVIFDriver() # Customizing above fake if necessary for key, val in kwargs.items(): fake.__setattr__(key, val) - # Inevitable mocks for connection.LibvirtConnection - self.mox.StubOutWithMock(connection.utils, 'import_class') - connection.utils.import_class(mox.IgnoreArg()).AndReturn(fakeip) - self.mox.StubOutWithMock(connection.utils, 'import_object') - connection.utils.import_object(mox.IgnoreArg()).AndReturn(fakevif) + self.flags(image_service='nova.image.fake.FakeImageService') + self.flags(firewall_driver="nova.tests.fake_network.FakeIptablesFirewallDriver") + self.flags(libvirt_vif_driver="nova.tests.fake_network.FakeVIFDriver") + self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn') connection.LibvirtConnection._conn = fake def fake_lookup(self, instance_name): - - class FakeVirtDomain(object): - - def snapshotCreateXML(self, *args): - return None - - def XMLDesc(self, *args): - return """ - - - - - - - - """ - return FakeVirtDomain() def fake_execute(self, *args): @@ -797,8 +776,6 @@ class LibvirtConnTestCase(test.TestCase): shutil.rmtree(os.path.join(FLAGS.instances_path, instance.name)) shutil.rmtree(os.path.join(FLAGS.instances_path, '_base')) - self.assertTrue(count) - def test_get_host_ip_addr(self): conn = connection.LibvirtConnection(False) ip = conn.get_host_ip_addr() From cbcc55e42992629234679b11af2cab61f5a18117 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Tue, 13 Sep 2011 15:33:34 -0500 Subject: [PATCH 068/100] Only allow up to 15 chars for a Windows hostname. --- nova/tests/test_xenapi.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 4a83d139..47c6a3c9 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -364,7 +364,7 @@ class XenAPIVMTestCase(test.TestCase): def _test_spawn(self, image_ref, kernel_id, ramdisk_id, instance_type_id="3", os_type="linux", - architecture="x86-64", instance_id=1, + hostname="test", architecture="x86-64", instance_id=1, check_injection=False, create_record=True, empty_dns=False): stubs.stubout_loopingcall_start(self.stubs) @@ -377,6 +377,7 @@ class XenAPIVMTestCase(test.TestCase): 'ramdisk_id': ramdisk_id, 'instance_type_id': instance_type_id, 'os_type': os_type, + 'hostname': hostname, 'architecture': architecture} instance = db.instance_create(self.context, values) else: From 9ad09d1be938b9754f2a5d675a983dfabfb95262 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Tue, 13 Sep 2011 20:38:26 -0400 Subject: [PATCH 069/100] pep8 fixes. --- nova/tests/test_libvirt.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 8193d6ec..a30b00db 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -57,7 +57,7 @@ class FakeVirtDomain(object): if fake_xml: self._fake_dom_xml = fake_xml else: - self._fake_dom_xml=""" + self._fake_dom_xml = """ @@ -188,7 +188,8 @@ class LibvirtConnTestCase(test.TestCase): fake.__setattr__(key, val) self.flags(image_service='nova.image.fake.FakeImageService') - self.flags(firewall_driver="nova.tests.fake_network.FakeIptablesFirewallDriver") + fw_driver = "nova.tests.fake_network.FakeIptablesFirewallDriver" + self.flags(firewall_driver=fw_driver) self.flags(libvirt_vif_driver="nova.tests.fake_network.FakeVIFDriver") self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn') From b0686ad5d4140c51aa4b22f02b40ae480ad3888b Mon Sep 17 00:00:00 2001 From: Jason Koelker Date: Wed, 14 Sep 2011 10:17:25 -0500 Subject: [PATCH 070/100] skip a bunch of tests for the moment since we will need to rework them --- nova/tests/test_compute.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 4d463572..886ace1a 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -1002,6 +1002,7 @@ class ComputeTestCase(test.TestCase): db.instance_destroy(c, instance_id2) db.instance_destroy(c, instance_id3) + @test.skip_test("need to fix/move") def test_get_by_fixed_ip(self): """Test getting 1 instance by Fixed IP""" c = context.get_admin_context() @@ -1051,6 +1052,7 @@ class ComputeTestCase(test.TestCase): db.instance_destroy(c, instance_id1) db.instance_destroy(c, instance_id2) + @test.skip_test("need to move/fix") def test_get_all_by_ip_regexp(self): """Test searching by Floating and Fixed IP""" c = context.get_admin_context() @@ -1125,6 +1127,7 @@ class ComputeTestCase(test.TestCase): db.instance_destroy(c, instance_id2) db.instance_destroy(c, instance_id3) + @test.skip_test("need to move/fix") def test_get_all_by_ipv6_regexp(self): """Test searching by IPv6 address""" @@ -1182,6 +1185,7 @@ class ComputeTestCase(test.TestCase): db.instance_destroy(c, instance_id2) db.instance_destroy(c, instance_id3) + @test.skip_test("need to fix/move") def test_get_all_by_multiple_options_at_once(self): """Test searching by multiple options at once""" c = context.get_admin_context() From c1a18a0633126fe6f8842497d03b9b3dd38d7bdb Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Wed, 14 Sep 2011 09:37:24 -0700 Subject: [PATCH 071/100] fixed tests --- nova/tests/test_libvirt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 61f98f63..9b349dd4 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -354,7 +354,7 @@ class LibvirtConnTestCase(test.TestCase): snapshot = image_service.show(context, recv_meta['id']) self.assertEquals(snapshot['properties']['image_state'], 'available') self.assertEquals(snapshot['status'], 'active') - self.assertEquals(snapshot['disk_format'], FLAGS.snapshot_image_format) + self.assertEquals(snapshot['disk_format'], 'raw') self.assertEquals(snapshot['name'], snapshot_name) def test_snapshot_in_qcow2_format(self): @@ -391,7 +391,7 @@ class LibvirtConnTestCase(test.TestCase): snapshot = image_service.show(context, recv_meta['id']) self.assertEquals(snapshot['properties']['image_state'], 'available') self.assertEquals(snapshot['status'], 'active') - self.assertEquals(snapshot['disk_format'], FLAGS.snapshot_image_format) + self.assertEquals(snapshot['disk_format'], 'qcow2') self.assertEquals(snapshot['name'], snapshot_name) def test_snapshot_no_image_architecture(self): From adec6c4e21c1fa1e71df11b398b60449a5fde564 Mon Sep 17 00:00:00 2001 From: "paul@openstack.org" <> Date: Wed, 14 Sep 2011 12:10:33 -0500 Subject: [PATCH 072/100] exporting auth to keystone (users, projects/tenants, roles, credentials) --- bin/nova-manage | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/bin/nova-manage b/bin/nova-manage index 089b2eea..5f0c5471 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -61,6 +61,7 @@ import math import netaddr from optparse import OptionParser import os +import StringIO import sys import time @@ -274,6 +275,50 @@ class ShellCommands(object): arguments: path""" exec(compile(open(path).read(), path, 'exec'), locals(), globals()) + @args('--filename', dest='filename', metavar='', help='Export path') + def export(self, filename): + """Export Nova users into a file that can be consumed by Keystone""" + def create_file(filename): + data = generate_file() + with open(filename, 'w') as f: + f.write(data.getvalue()) + + def tenants(data, am): + for project in am.get_projects(): + print >> data, ("tenant add '%s'" % + (project.name)) + for u in project.member_ids: + user = am.get_user(u) + print >> data, ("user add '%s' '%s' '%s'" % + (user.name, user.access, project.name)) + print >> data, ("credentials add 'EC2' '%s' '%s'" % + (user.access, user.secret)) + + def roles(data, am): + for role in am.get_roles(): + print >> data, ("role add '%s'" % (role)) + + def grant_roles(data, am): + roles = am.get_roles() + for project in am.get_projects(): + for u in project.member_ids: + user = am.get_user(u) + for role in roles: + if user.has_role(role): + print >> data, ("role grant '%s', '%s', '%s')," % + (user.name, role, project.name)) + print >> data, footer + + def generate_file(): + data = StringIO.StringIO() + am = manager.AuthManager() + tenants(data, am) + roles(data, am) + data.seek(0) + return data + + create_file(filename) + class RoleCommands(object): """Class for managing roles.""" From 4abab66462bc06ee51f7053322af1a9b4c9b5c58 Mon Sep 17 00:00:00 2001 From: Jason Koelker Date: Wed, 14 Sep 2011 12:54:08 -0500 Subject: [PATCH 073/100] add stubs for future tests that need to be written --- nova/tests/test_network.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py index 926ea065..ed77ccea 100644 --- a/nova/tests/test_network.py +++ b/nova/tests/test_network.py @@ -4,8 +4,7 @@ # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at +# not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # @@ -661,3 +660,12 @@ class CommonNetworkTestCase(test.TestCase): args = [None, 'foo', cidr, None, 10, 256, 'fd00::/48', None, None, None] self.assertTrue(manager.create_networks(*args)) + + def get_instance_ids_by_ip_regex(self): + pass + + def get_instance_ids_by_ipv6_regex(self): + pass + + def get_instance_ids_by_ip(self): + pass From f6017c07ff27e403d94ed5a37d63a539cba0985a Mon Sep 17 00:00:00 2001 From: "paul@openstack.org" <> Date: Wed, 14 Sep 2011 13:20:16 -0500 Subject: [PATCH 074/100] minor changes to credentials for the correct format --- bin/nova-manage | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index 5f0c5471..60799024 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -286,13 +286,13 @@ class ShellCommands(object): def tenants(data, am): for project in am.get_projects(): print >> data, ("tenant add '%s'" % - (project.name)) + (project.name)) for u in project.member_ids: user = am.get_user(u) print >> data, ("user add '%s' '%s' '%s'" % - (user.name, user.access, project.name)) - print >> data, ("credentials add 'EC2' '%s' '%s'" % - (user.access, user.secret)) + (user.name, user.access, project.name)) + print >> data, ("credentials add 'EC2' '%s:%s' '%s' '%s'" % + (user.access, project.id, user.secret, project.id)) def roles(data, am): for role in am.get_roles(): From 2e239d30de20683dd1328afabdd4baaa95a679f1 Mon Sep 17 00:00:00 2001 From: Jason Koelker Date: Wed, 14 Sep 2011 14:13:26 -0500 Subject: [PATCH 075/100] pep8 --- nova/tests/test_network.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py index ed77ccea..6644a739 100644 --- a/nova/tests/test_network.py +++ b/nova/tests/test_network.py @@ -4,7 +4,8 @@ # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain # a copy of the License at +# not use this file except in compliance with the License. You may obtain +# a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # @@ -662,10 +663,11 @@ class CommonNetworkTestCase(test.TestCase): self.assertTrue(manager.create_networks(*args)) def get_instance_ids_by_ip_regex(self): - pass + manager = self.FakeNetworkManager() + self.mox.StubOutWithMock(manager.db, 'virtual_interface_get_all') def get_instance_ids_by_ipv6_regex(self): - pass + manager = self.FakeNetworkManager() def get_instance_ids_by_ip(self): - pass + manager = self.FakeNetworkManager() From 3ffc2da35bd9fd62902dc2652b4ff516875a98d2 Mon Sep 17 00:00:00 2001 From: Jason Koelker Date: Wed, 14 Sep 2011 15:47:41 -0500 Subject: [PATCH 076/100] add tests --- nova/tests/test_network.py | 132 +++++++++++++++++++++++++++++++++++-- 1 file changed, 126 insertions(+), 6 deletions(-) diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py index 6644a739..30673050 100644 --- a/nova/tests/test_network.py +++ b/nova/tests/test_network.py @@ -460,6 +460,26 @@ class CommonNetworkTestCase(test.TestCase): def network_get_all(self, context): raise exception.NoNetworksFound() + def virtual_interface_get_all(self, context): + floats = [{'address': '172.16.1.1'}, + {'address': '172.16.1.2'}, + {'address': '173.16.1.2'}] + + vifs = [{'instance_id': 0, + 'fixed_ipv6': '2001:db8::dcad:beff:feef:1', + 'fixed_ips': [{'address': '172.16.0.1', + 'floating_ips': [floats[0]]}]}, + {'instance_id': 1, + 'fixed_ipv6': '2001:db8::dcad:beff:feef:2', + 'fixed_ips': [{'address': '172.16.0.2', + 'floating_ips': [floats[1]]}]}, + {'instance_id': 2, + 'fixed_ipv6': '2002:db8::dcad:beff:feef:2', + 'fixed_ips': [{'address': '173.16.0.2', + 'floating_ips': [floats[2]]}]}] + return vifs + + def __init__(self): self.db = self.FakeDB() self.deallocate_called = None @@ -639,7 +659,6 @@ class CommonNetworkTestCase(test.TestCase): self.fake_create_fixed_ips) args = [None, 'foo', cidr, None, 1, 256, 'fd00::/48', None, None, None] - result = manager.create_networks(*args) self.assertTrue(manager.create_networks(*args)) def test_create_networks_cidr_already_used(self): @@ -662,12 +681,113 @@ class CommonNetworkTestCase(test.TestCase): None] self.assertTrue(manager.create_networks(*args)) - def get_instance_ids_by_ip_regex(self): - manager = self.FakeNetworkManager() - self.mox.StubOutWithMock(manager.db, 'virtual_interface_get_all') - def get_instance_ids_by_ipv6_regex(self): + def test_get_instance_ids_by_ip_regex(self): manager = self.FakeNetworkManager() + _vifs = manager.db.virtual_interface_get_all(None) - def get_instance_ids_by_ip(self): + # Greedy get eveything + res = manager.get_instance_ids_by_ip_filter(None, {'ip': '.*'}) + self.assertEqual(len(res), len(_vifs)) + + # Doesn't exist + res = manager.get_instance_ids_by_ip_filter(None, {'ip': '10.0.0.1'}) + self.assertFalse(res) + + # Get instance 1 + res = manager.get_instance_ids_by_ip_filter(None, + {'ip': '172.16.0.2'}) + self.assertTrue(res) + self.assertEqual(len(res), 1) + self.assertEqual(res[0]['instance_id'], _vifs[1]['instance_id']) + + # Get instance 2 + res = manager.get_instance_ids_by_ip_filter(None, + {'ip': '173.16.0.2'}) + self.assertTrue(res) + self.assertEqual(len(res), 1) + self.assertEqual(res[0]['instance_id'], _vifs[2]['instance_id']) + + # Get instance 0 and 1 + res = manager.get_instance_ids_by_ip_filter(None, + {'ip': '172.16.0.*'}) + self.assertTrue(res) + self.assertEqual(len(res), 2) + self.assertEqual(res[0]['instance_id'], _vifs[0]['instance_id']) + self.assertEqual(res[1]['instance_id'], _vifs[1]['instance_id']) + + # Get instance 1 and 2 + res = manager.get_instance_ids_by_ip_filter(None, + {'ip': '17..16.0.2'}) + self.assertTrue(res) + self.assertEqual(len(res), 2) + self.assertEqual(res[0]['instance_id'], _vifs[1]['instance_id']) + self.assertEqual(res[1]['instance_id'], _vifs[2]['instance_id']) + + def test_get_instance_ids_by_ipv6_regex(self): manager = self.FakeNetworkManager() + _vifs = manager.db.virtual_interface_get_all(None) + + # Greedy get eveything + res = manager.get_instance_ids_by_ip_filter(None, {'ip6': '.*'}) + self.assertEqual(len(res), len(_vifs)) + + # Doesn't exist + res = manager.get_instance_ids_by_ip_filter(None, {'ip6': '.*1034.*'}) + self.assertFalse(res) + + # Get instance 1 + res = manager.get_instance_ids_by_ip_filter(None, + {'ip6': '2001:.*:2'}) + self.assertTrue(res) + self.assertEqual(len(res), 1) + self.assertEqual(res[0]['instance_id'], _vifs[1]['instance_id']) + + # Get instance 2 + ip6 = '2002:db8::dcad:beff:feef:2' + res = manager.get_instance_ids_by_ip_filter(None, {'ip6': ip6}) + self.assertTrue(res) + self.assertEqual(len(res), 1) + self.assertEqual(res[0]['instance_id'], _vifs[2]['instance_id']) + + # Get instance 0 and 1 + res = manager.get_instance_ids_by_ip_filter(None, {'ip6': '2001:.*'}) + self.assertTrue(res) + self.assertEqual(len(res), 2) + self.assertEqual(res[0]['instance_id'], _vifs[0]['instance_id']) + self.assertEqual(res[1]['instance_id'], _vifs[1]['instance_id']) + + # Get instance 1 and 2 + ip6 = '200.:db8::dcad:beff:feef:2' + res = manager.get_instance_ids_by_ip_filter(None, {'ip6': ip6}) + self.assertTrue(res) + self.assertEqual(len(res), 2) + self.assertEqual(res[0]['instance_id'], _vifs[1]['instance_id']) + self.assertEqual(res[1]['instance_id'], _vifs[2]['instance_id']) + + def test_get_instance_ids_by_ip(self): + manager = self.FakeNetworkManager() + _vifs = manager.db.virtual_interface_get_all(None) + + # No regex for you! + res = manager.get_instance_ids_by_ip_filter(None, {'fixed_ip': '.*'}) + self.assertFalse(res) + + # Doesn't exist + ip = '10.0.0.1' + res = manager.get_instance_ids_by_ip_filter(None, {'fixed_ip': ip}) + self.assertFalse(res) + + # Get instance 1 + ip = '172.16.0.2' + res = manager.get_instance_ids_by_ip_filter(None, {'fixed_ip': ip}) + self.assertTrue(res) + self.assertEqual(len(res), 1) + self.assertEqual(res[0]['instance_id'], _vifs[1]['instance_id']) + + # Get instance 2 + ip = '173.16.0.2' + res = manager.get_instance_ids_by_ip_filter(None, {'fixed_ip': ip}) + self.assertTrue(res) + self.assertEqual(len(res), 1) + self.assertEqual(res[0]['instance_id'], _vifs[2]['instance_id']) From 6478e35a72a3e6df0a6bfbe5d38718338dfeafca Mon Sep 17 00:00:00 2001 From: Jason Koelker Date: Wed, 14 Sep 2011 15:49:10 -0500 Subject: [PATCH 077/100] ip tests were moved to networking --- nova/tests/test_compute.py | 183 ------------------------------------- 1 file changed, 183 deletions(-) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 886ace1a..a63433a4 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -1002,189 +1002,6 @@ class ComputeTestCase(test.TestCase): db.instance_destroy(c, instance_id2) db.instance_destroy(c, instance_id3) - @test.skip_test("need to fix/move") - def test_get_by_fixed_ip(self): - """Test getting 1 instance by Fixed IP""" - c = context.get_admin_context() - instance_id1 = self._create_instance() - instance_id2 = self._create_instance({'id': 20}) - instance_id3 = self._create_instance({'id': 30}) - - vif_ref1 = db.virtual_interface_create(c, - {'address': '12:34:56:78:90:12', - 'instance_id': instance_id1, - 'network_id': 1}) - vif_ref2 = db.virtual_interface_create(c, - {'address': '90:12:34:56:78:90', - 'instance_id': instance_id2, - 'network_id': 1}) - - db.fixed_ip_create(c, - {'address': '1.1.1.1', - 'instance_id': instance_id1, - 'virtual_interface_id': vif_ref1['id']}) - db.fixed_ip_create(c, - {'address': '1.1.2.1', - 'instance_id': instance_id2, - 'virtual_interface_id': vif_ref2['id']}) - - # regex not allowed - instances = self.compute_api.get_all(c, - search_opts={'fixed_ip': '.*'}) - self.assertEqual(len(instances), 0) - - instances = self.compute_api.get_all(c, - search_opts={'fixed_ip': '1.1.3.1'}) - self.assertEqual(len(instances), 0) - - instances = self.compute_api.get_all(c, - search_opts={'fixed_ip': '1.1.1.1'}) - self.assertEqual(len(instances), 1) - self.assertEqual(instances[0].id, instance_id1) - - instances = self.compute_api.get_all(c, - search_opts={'fixed_ip': '1.1.2.1'}) - self.assertEqual(len(instances), 1) - self.assertEqual(instances[0].id, instance_id2) - - db.virtual_interface_delete(c, vif_ref1['id']) - db.virtual_interface_delete(c, vif_ref2['id']) - db.instance_destroy(c, instance_id1) - db.instance_destroy(c, instance_id2) - - @test.skip_test("need to move/fix") - def test_get_all_by_ip_regexp(self): - """Test searching by Floating and Fixed IP""" - c = context.get_admin_context() - instance_id1 = self._create_instance({'display_name': 'woot'}) - instance_id2 = self._create_instance({ - 'display_name': 'woo', - 'id': 20}) - instance_id3 = self._create_instance({ - 'display_name': 'not-woot', - 'id': 30}) - - vif_ref1 = db.virtual_interface_create(c, - {'address': '12:34:56:78:90:12', - 'instance_id': instance_id1, - 'network_id': 1}) - vif_ref2 = db.virtual_interface_create(c, - {'address': '90:12:34:56:78:90', - 'instance_id': instance_id2, - 'network_id': 1}) - vif_ref3 = db.virtual_interface_create(c, - {'address': '34:56:78:90:12:34', - 'instance_id': instance_id3, - 'network_id': 1}) - - db.fixed_ip_create(c, - {'address': '1.1.1.1', - 'instance_id': instance_id1, - 'virtual_interface_id': vif_ref1['id']}) - db.fixed_ip_create(c, - {'address': '1.1.2.1', - 'instance_id': instance_id2, - 'virtual_interface_id': vif_ref2['id']}) - fix_addr = db.fixed_ip_create(c, - {'address': '1.1.3.1', - 'instance_id': instance_id3, - 'virtual_interface_id': vif_ref3['id']}) - fix_ref = db.fixed_ip_get_by_address(c, fix_addr) - flo_ref = db.floating_ip_create(c, - {'address': '10.0.0.2', - 'fixed_ip_id': fix_ref['id']}) - - # ends up matching 2nd octet here.. so all 3 match - instances = self.compute_api.get_all(c, - search_opts={'ip': '.*\.1'}) - self.assertEqual(len(instances), 3) - - instances = self.compute_api.get_all(c, - search_opts={'ip': '1.*'}) - self.assertEqual(len(instances), 3) - - instances = self.compute_api.get_all(c, - search_opts={'ip': '.*\.1.\d+$'}) - self.assertEqual(len(instances), 1) - instance_ids = [instance.id for instance in instances] - self.assertTrue(instance_id1 in instance_ids) - - instances = self.compute_api.get_all(c, - search_opts={'ip': '.*\.2.+'}) - self.assertEqual(len(instances), 1) - self.assertEqual(instances[0].id, instance_id2) - - instances = self.compute_api.get_all(c, - search_opts={'ip': '10.*'}) - self.assertEqual(len(instances), 1) - self.assertEqual(instances[0].id, instance_id3) - - db.virtual_interface_delete(c, vif_ref1['id']) - db.virtual_interface_delete(c, vif_ref2['id']) - db.virtual_interface_delete(c, vif_ref3['id']) - db.floating_ip_destroy(c, '10.0.0.2') - db.instance_destroy(c, instance_id1) - db.instance_destroy(c, instance_id2) - db.instance_destroy(c, instance_id3) - - @test.skip_test("need to move/fix") - def test_get_all_by_ipv6_regexp(self): - """Test searching by IPv6 address""" - - c = context.get_admin_context() - instance_id1 = self._create_instance({'display_name': 'woot'}) - instance_id2 = self._create_instance({ - 'display_name': 'woo', - 'id': 20}) - instance_id3 = self._create_instance({ - 'display_name': 'not-woot', - 'id': 30}) - - vif_ref1 = db.virtual_interface_create(c, - {'address': '12:34:56:78:90:12', - 'instance_id': instance_id1, - 'network_id': 1}) - vif_ref2 = db.virtual_interface_create(c, - {'address': '90:12:34:56:78:90', - 'instance_id': instance_id2, - 'network_id': 1}) - vif_ref3 = db.virtual_interface_create(c, - {'address': '34:56:78:90:12:34', - 'instance_id': instance_id3, - 'network_id': 1}) - - # This will create IPv6 addresses of: - # 1: fd00::1034:56ff:fe78:9012 - # 20: fd00::9212:34ff:fe56:7890 - # 30: fd00::3656:78ff:fe90:1234 - - instances = self.compute_api.get_all(c, - search_opts={'ip6': '.*1034.*'}) - self.assertEqual(len(instances), 1) - self.assertEqual(instances[0].id, instance_id1) - - instances = self.compute_api.get_all(c, - search_opts={'ip6': '^fd00.*'}) - self.assertEqual(len(instances), 3) - instance_ids = [instance.id for instance in instances] - self.assertTrue(instance_id1 in instance_ids) - self.assertTrue(instance_id2 in instance_ids) - self.assertTrue(instance_id3 in instance_ids) - - instances = self.compute_api.get_all(c, - search_opts={'ip6': '^.*12.*34.*'}) - self.assertEqual(len(instances), 2) - instance_ids = [instance.id for instance in instances] - self.assertTrue(instance_id2 in instance_ids) - self.assertTrue(instance_id3 in instance_ids) - - db.virtual_interface_delete(c, vif_ref1['id']) - db.virtual_interface_delete(c, vif_ref2['id']) - db.virtual_interface_delete(c, vif_ref3['id']) - db.instance_destroy(c, instance_id1) - db.instance_destroy(c, instance_id2) - db.instance_destroy(c, instance_id3) - @test.skip_test("need to fix/move") def test_get_all_by_multiple_options_at_once(self): """Test searching by multiple options at once""" From 3970e1dd388db32452c6fad280abd12318d4440f Mon Sep 17 00:00:00 2001 From: Jason Koelker Date: Wed, 14 Sep 2011 15:59:12 -0500 Subject: [PATCH 078/100] move the FakeNetworkManager into fake_network --- nova/tests/test_network.py | 92 +++++++++----------------------------- 1 file changed, 20 insertions(+), 72 deletions(-) diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py index 30673050..19ccd8c1 100644 --- a/nova/tests/test_network.py +++ b/nova/tests/test_network.py @@ -438,75 +438,23 @@ class VlanNetworkTestCase(test.TestCase): class CommonNetworkTestCase(test.TestCase): - - class FakeNetworkManager(network_manager.NetworkManager): - """This NetworkManager doesn't call the base class so we can bypass all - inherited service cruft and just perform unit tests. - """ - - class FakeDB: - def fixed_ip_get_by_instance(self, context, instance_id): - return [dict(address='10.0.0.0'), dict(address='10.0.0.1'), - dict(address='10.0.0.2')] - - def network_get_by_cidr(self, context, cidr): - raise exception.NetworkNotFoundForCidr() - - def network_create_safe(self, context, net): - fakenet = dict(net) - fakenet['id'] = 999 - return fakenet - - def network_get_all(self, context): - raise exception.NoNetworksFound() - - def virtual_interface_get_all(self, context): - floats = [{'address': '172.16.1.1'}, - {'address': '172.16.1.2'}, - {'address': '173.16.1.2'}] - - vifs = [{'instance_id': 0, - 'fixed_ipv6': '2001:db8::dcad:beff:feef:1', - 'fixed_ips': [{'address': '172.16.0.1', - 'floating_ips': [floats[0]]}]}, - {'instance_id': 1, - 'fixed_ipv6': '2001:db8::dcad:beff:feef:2', - 'fixed_ips': [{'address': '172.16.0.2', - 'floating_ips': [floats[1]]}]}, - {'instance_id': 2, - 'fixed_ipv6': '2002:db8::dcad:beff:feef:2', - 'fixed_ips': [{'address': '173.16.0.2', - 'floating_ips': [floats[2]]}]}] - return vifs - - - def __init__(self): - self.db = self.FakeDB() - self.deallocate_called = None - - def deallocate_fixed_ip(self, context, address): - self.deallocate_called = address - - def _create_fixed_ips(self, context, network_id): - pass - def fake_create_fixed_ips(self, context, network_id): return None def test_remove_fixed_ip_from_instance(self): - manager = self.FakeNetworkManager() + manager = fake_network.FakeNetworkManager() manager.remove_fixed_ip_from_instance(None, 99, '10.0.0.1') self.assertEquals(manager.deallocate_called, '10.0.0.1') def test_remove_fixed_ip_from_instance_bad_input(self): - manager = self.FakeNetworkManager() + manager = fake_network.FakeNetworkManager() self.assertRaises(exception.FixedIpNotFoundForSpecificInstance, manager.remove_fixed_ip_from_instance, None, 99, 'bad input') def test_validate_cidrs(self): - manager = self.FakeNetworkManager() + manager = fake_network.FakeNetworkManager() nets = manager.create_networks(None, 'fake', '192.168.0.0/24', False, 1, 256, None, None, None, None) @@ -515,7 +463,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertTrue('192.168.0.0/24' in cidrs) def test_validate_cidrs_split_exact_in_half(self): - manager = self.FakeNetworkManager() + manager = fake_network.FakeNetworkManager() nets = manager.create_networks(None, 'fake', '192.168.0.0/24', False, 2, 128, None, None, None, None) @@ -525,7 +473,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertTrue('192.168.0.128/25' in cidrs) def test_validate_cidrs_split_cidr_in_use_middle_of_range(self): - manager = self.FakeNetworkManager() + manager = fake_network.FakeNetworkManager() self.mox.StubOutWithMock(manager.db, 'network_get_all') ctxt = mox.IgnoreArg() manager.db.network_get_all(ctxt).AndReturn([{'id': 1, @@ -543,7 +491,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertFalse('192.168.2.0/24' in cidrs) def test_validate_cidrs_smaller_subnet_in_use(self): - manager = self.FakeNetworkManager() + manager = fake_network.FakeNetworkManager() self.mox.StubOutWithMock(manager.db, 'network_get_all') ctxt = mox.IgnoreArg() manager.db.network_get_all(ctxt).AndReturn([{'id': 1, @@ -556,7 +504,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertRaises(ValueError, manager.create_networks, *args) def test_validate_cidrs_split_smaller_cidr_in_use(self): - manager = self.FakeNetworkManager() + manager = fake_network.FakeNetworkManager() self.mox.StubOutWithMock(manager.db, 'network_get_all') ctxt = mox.IgnoreArg() manager.db.network_get_all(ctxt).AndReturn([{'id': 1, @@ -573,7 +521,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertFalse('192.168.2.0/24' in cidrs) def test_validate_cidrs_split_smaller_cidr_in_use2(self): - manager = self.FakeNetworkManager() + manager = fake_network.FakeNetworkManager() self.mox.StubOutWithMock(manager.db, 'network_get_all') ctxt = mox.IgnoreArg() manager.db.network_get_all(ctxt).AndReturn([{'id': 1, @@ -589,7 +537,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertFalse('192.168.2.0/27' in cidrs) def test_validate_cidrs_split_all_in_use(self): - manager = self.FakeNetworkManager() + manager = fake_network.FakeNetworkManager() self.mox.StubOutWithMock(manager.db, 'network_get_all') ctxt = mox.IgnoreArg() in_use = [{'id': 1, 'cidr': '192.168.2.9/29'}, @@ -605,14 +553,14 @@ class CommonNetworkTestCase(test.TestCase): self.assertRaises(ValueError, manager.create_networks, *args) def test_validate_cidrs_one_in_use(self): - manager = self.FakeNetworkManager() + manager = fake_network.FakeNetworkManager() args = (None, 'fake', '192.168.0.0/24', False, 2, 256, None, None, None, None) # ValueError: network_size * num_networks exceeds cidr size self.assertRaises(ValueError, manager.create_networks, *args) def test_validate_cidrs_already_used(self): - manager = self.FakeNetworkManager() + manager = fake_network.FakeNetworkManager() self.mox.StubOutWithMock(manager.db, 'network_get_all') ctxt = mox.IgnoreArg() manager.db.network_get_all(ctxt).AndReturn([{'id': 1, @@ -624,7 +572,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertRaises(ValueError, manager.create_networks, *args) def test_validate_cidrs_too_many(self): - manager = self.FakeNetworkManager() + manager = fake_network.FakeNetworkManager() args = (None, 'fake', '192.168.0.0/24', False, 200, 256, None, None, None, None) # ValueError: Not enough subnets avail to satisfy requested @@ -632,7 +580,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertRaises(ValueError, manager.create_networks, *args) def test_validate_cidrs_split_partial(self): - manager = self.FakeNetworkManager() + manager = fake_network.FakeNetworkManager() nets = manager.create_networks(None, 'fake', '192.168.0.0/16', False, 2, 256, None, None, None, None) returned_cidrs = [str(net['cidr']) for net in nets] @@ -640,7 +588,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertTrue('192.168.1.0/24' in returned_cidrs) def test_validate_cidrs_conflict_existing_supernet(self): - manager = self.FakeNetworkManager() + manager = fake_network.FakeNetworkManager() self.mox.StubOutWithMock(manager.db, 'network_get_all') ctxt = mox.IgnoreArg() fakecidr = [{'id': 1, 'cidr': '192.168.0.0/8'}] @@ -654,7 +602,7 @@ class CommonNetworkTestCase(test.TestCase): def test_create_networks(self): cidr = '192.168.0.0/24' - manager = self.FakeNetworkManager() + manager = fake_network.FakeNetworkManager() self.stubs.Set(manager, '_create_fixed_ips', self.fake_create_fixed_ips) args = [None, 'foo', cidr, None, 1, 256, 'fd00::/48', None, None, @@ -662,7 +610,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertTrue(manager.create_networks(*args)) def test_create_networks_cidr_already_used(self): - manager = self.FakeNetworkManager() + manager = fake_network.FakeNetworkManager() self.mox.StubOutWithMock(manager.db, 'network_get_all') ctxt = mox.IgnoreArg() fakecidr = [{'id': 1, 'cidr': '192.168.0.0/24'}] @@ -674,7 +622,7 @@ class CommonNetworkTestCase(test.TestCase): def test_create_networks_many(self): cidr = '192.168.0.0/16' - manager = self.FakeNetworkManager() + manager = fake_network.FakeNetworkManager() self.stubs.Set(manager, '_create_fixed_ips', self.fake_create_fixed_ips) args = [None, 'foo', cidr, None, 10, 256, 'fd00::/48', None, None, @@ -683,7 +631,7 @@ class CommonNetworkTestCase(test.TestCase): def test_get_instance_ids_by_ip_regex(self): - manager = self.FakeNetworkManager() + manager = fake_network.FakeNetworkManager() _vifs = manager.db.virtual_interface_get_all(None) # Greedy get eveything @@ -725,7 +673,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertEqual(res[1]['instance_id'], _vifs[2]['instance_id']) def test_get_instance_ids_by_ipv6_regex(self): - manager = self.FakeNetworkManager() + manager = fake_network.FakeNetworkManager() _vifs = manager.db.virtual_interface_get_all(None) # Greedy get eveything @@ -766,7 +714,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertEqual(res[1]['instance_id'], _vifs[2]['instance_id']) def test_get_instance_ids_by_ip(self): - manager = self.FakeNetworkManager() + manager = fake_network.FakeNetworkManager() _vifs = manager.db.virtual_interface_get_all(None) # No regex for you! From a9b7ae6d65c7f5fa837f5ac5b112bc1ccac87ecf Mon Sep 17 00:00:00 2001 From: Soren Hansen Date: Thu, 15 Sep 2011 18:15:19 +0200 Subject: [PATCH 079/100] Return three rules for describe_security_groups if a rule refers to a foreign group, but does not specify protocol/port. --- nova/tests/test_cloud.py | 52 ++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index c5bfdd0f..96aebdd5 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -315,25 +315,47 @@ class CloudTestCase(test.TestCase): {'project_id': 'someuser', 'name': 'othergroup2'}) authz = self.cloud.authorize_security_group_ingress - kwargs = {'ip_permissions': [{ - 'groups': {'1': {'user_id': u'someuser', - 'group_name': u'somegroup1'}, - '2': {'user_id': u'someuser', - 'group_name': u'othergroup2'}}}]} + kwargs = {'ip_permissions': [ + {'groups': {'1': {'user_id': u'someuser', + 'group_name': u'somegroup1'}}}, + {'ip_protocol': 'tcp', + 'from_port': 80, + 'to_port': 80, + 'groups': {'1': {'user_id': u'someuser', + 'group_name': u'othergroup2'}}}]} self.assertTrue(authz(self.context, group_name=sec1['name'], **kwargs)) describe = self.cloud.describe_security_groups groups = describe(self.context, group_name=['test']) self.assertEquals(len(groups['securityGroupInfo']), 1) - for proto, min_port, max_port in (('icmp', -1, -1), - ('udp', 1, 65536), - ('tcp', 1, 65535)): - rules = filter(lambda g:g['ipProtocol'] == proto, - groups['securityGroupInfo'][0]['ipPermissions']) - self.assertEquals(len(rules), 2, - "Expected 2 rules for protocol %s" % proto) - for rule in rules: - self.assertEquals(rule['fromPort'], min_port) - self.assertEquals(rule['toPort'], max_port) + actual_rules = groups['securityGroupInfo'][0]['ipPermissions'] + self.assertEquals(len(actual_rules), 4) + expected_rules = [{'fromPort': -1, + 'groups': [{'groupName': 'somegroup1', + 'userId': 'someuser'}], + 'ipProtocol': 'icmp', + 'ipRanges': [], + 'toPort': -1}, + {'fromPort': 1, + 'groups': [{'groupName': u'somegroup1', + 'userId': u'someuser'}], + 'ipProtocol': 'tcp', + 'ipRanges': [], + 'toPort': 65535}, + {'fromPort': 1, + 'groups': [{'groupName': u'somegroup1', + 'userId': u'someuser'}], + 'ipProtocol': 'udp', + 'ipRanges': [], + 'toPort': 65536}, + {'fromPort': 80, + 'groups': [{'groupName': u'othergroup2', + 'userId': u'someuser'}], + 'ipProtocol': u'tcp', + 'ipRanges': [], + 'toPort': 80}] + for rule in expected_rules: + self.assertTrue(rule in actual_rules) + db.security_group_destroy(self.context, sec3['id']) db.security_group_destroy(self.context, sec2['id']) db.security_group_destroy(self.context, sec1['id']) From 104d6c134dcc9a406d41d0d501d650836fbd0185 Mon Sep 17 00:00:00 2001 From: Jason Koelker Date: Thu, 15 Sep 2011 13:29:37 -0500 Subject: [PATCH 080/100] update tests --- nova/tests/test_compute.py | 74 +++++++++++++------------------------- 1 file changed, 25 insertions(+), 49 deletions(-) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index a63433a4..5960bd22 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -21,22 +21,24 @@ Tests For Compute """ from nova import compute -from nova.compute import instance_types -from nova.compute import manager as compute_manager -from nova.compute import power_state -from nova.compute import vm_states from nova import context from nova import db -from nova.db.sqlalchemy import models -from nova.db.sqlalchemy import api as sqlalchemy_api from nova import exception from nova import flags -import nova.image.fake from nova import log as logging from nova import rpc from nova import test from nova import utils + +from nova.compute import instance_types +from nova.compute import manager as compute_manager +from nova.compute import power_state +from nova.compute import vm_states +from nova.db.sqlalchemy import models +from nova.image import fake as fake_image from nova.notifier import test_notifier +from nova.tests import fake_network + LOG = logging.getLogger('nova.tests.compute') FLAGS = flags.FLAGS @@ -74,7 +76,7 @@ class ComputeTestCase(test.TestCase): def fake_show(meh, context, id): return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1}} - self.stubs.Set(nova.image.fake._FakeImageService, 'show', fake_show) + self.stubs.Set(fake_image._FakeImageService, 'show', fake_show) def _create_instance(self, params=None): """Create a test instance""" @@ -1002,11 +1004,19 @@ class ComputeTestCase(test.TestCase): db.instance_destroy(c, instance_id2) db.instance_destroy(c, instance_id3) - @test.skip_test("need to fix/move") def test_get_all_by_multiple_options_at_once(self): """Test searching by multiple options at once""" c = context.get_admin_context() - instance_id1 = self._create_instance({'display_name': 'woot'}) + network_manager = fake_network.FakeNetworkManager() + self.stubs.Set(self.compute_api.network_api, + 'get_instance_uuids_by_ip_filter', + network_manager.get_instance_uuids_by_ip_filter) + self.stubs.Set(network_manager.db, + 'instance_get_uuids_by_ids', + db.instance_get_uuids_by_ids) + + instance_id1 = self._create_instance({'display_name': 'woot', + 'id': 0}) instance_id2 = self._create_instance({ 'display_name': 'woo', 'id': 20}) @@ -1014,36 +1024,6 @@ class ComputeTestCase(test.TestCase): 'display_name': 'not-woot', 'id': 30}) - vif_ref1 = db.virtual_interface_create(c, - {'address': '12:34:56:78:90:12', - 'instance_id': instance_id1, - 'network_id': 1}) - vif_ref2 = db.virtual_interface_create(c, - {'address': '90:12:34:56:78:90', - 'instance_id': instance_id2, - 'network_id': 1}) - vif_ref3 = db.virtual_interface_create(c, - {'address': '34:56:78:90:12:34', - 'instance_id': instance_id3, - 'network_id': 1}) - - db.fixed_ip_create(c, - {'address': '1.1.1.1', - 'instance_id': instance_id1, - 'virtual_interface_id': vif_ref1['id']}) - db.fixed_ip_create(c, - {'address': '1.1.2.1', - 'instance_id': instance_id2, - 'virtual_interface_id': vif_ref2['id']}) - fix_addr = db.fixed_ip_create(c, - {'address': '1.1.3.1', - 'instance_id': instance_id3, - 'virtual_interface_id': vif_ref3['id']}) - fix_ref = db.fixed_ip_get_by_address(c, fix_addr) - flo_ref = db.floating_ip_create(c, - {'address': '10.0.0.2', - 'fixed_ip_id': fix_ref['id']}) - # ip ends up matching 2nd octet here.. so all 3 match ip # but 'name' only matches one instances = self.compute_api.get_all(c, @@ -1051,18 +1031,18 @@ class ComputeTestCase(test.TestCase): self.assertEqual(len(instances), 1) self.assertEqual(instances[0].id, instance_id3) - # ip ends up matching any ip with a '2' in it.. so instance - # 2 and 3.. but name should only match #2 + # ip ends up matching any ip with a '1' in the last octet.. + # so instance 1 and 3.. but name should only match #1 # but 'name' only matches one instances = self.compute_api.get_all(c, - search_opts={'ip': '.*2', 'name': '^woo.*'}) + search_opts={'ip': '.*\.1$', 'name': '^woo.*'}) self.assertEqual(len(instances), 1) - self.assertEqual(instances[0].id, instance_id2) + self.assertEqual(instances[0].id, instance_id1) # same as above but no match on name (name matches instance_id1 # but the ip query doesn't instances = self.compute_api.get_all(c, - search_opts={'ip': '.*2.*', 'name': '^woot.*'}) + search_opts={'ip': '.*\.2$', 'name': '^woot.*'}) self.assertEqual(len(instances), 0) # ip matches all 3... ipv6 matches #2+#3...name matches #3 @@ -1073,10 +1053,6 @@ class ComputeTestCase(test.TestCase): self.assertEqual(len(instances), 1) self.assertEqual(instances[0].id, instance_id3) - db.virtual_interface_delete(c, vif_ref1['id']) - db.virtual_interface_delete(c, vif_ref2['id']) - db.virtual_interface_delete(c, vif_ref3['id']) - db.floating_ip_destroy(c, '10.0.0.2') db.instance_destroy(c, instance_id1) db.instance_destroy(c, instance_id2) db.instance_destroy(c, instance_id3) From c2e2019c5a9ea05b8b55fab6344a4300ad5dd044 Mon Sep 17 00:00:00 2001 From: Jason Koelker Date: Thu, 15 Sep 2011 13:44:29 -0500 Subject: [PATCH 081/100] build the query with the query builder --- nova/tests/test_db_api.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index 60d7abd8..c791eec2 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -91,6 +91,8 @@ class DbApiTestCase(test.TestCase): inst2 = db.instance_create(self.context, args2) db.instance_destroy(self.context, inst1.id) result = db.instance_get_all_by_filters(self.context.elevated(), {}) + print str(dict(result[0])) + print str(dict(result[1])) self.assertEqual(2, len(result)) self.assertEqual(result[0].id, inst2.id) self.assertEqual(result[1].id, inst1.id) From 14aec21d701609d289e08bc5f1efeab6df6daf6d Mon Sep 17 00:00:00 2001 From: Jason Koelker Date: Thu, 15 Sep 2011 13:47:26 -0500 Subject: [PATCH 082/100] fix test --- nova/tests/test_db_api.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index c791eec2..5ebab9cc 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -91,9 +91,7 @@ class DbApiTestCase(test.TestCase): inst2 = db.instance_create(self.context, args2) db.instance_destroy(self.context, inst1.id) result = db.instance_get_all_by_filters(self.context.elevated(), {}) - print str(dict(result[0])) - print str(dict(result[1])) self.assertEqual(2, len(result)) - self.assertEqual(result[0].id, inst2.id) - self.assertEqual(result[1].id, inst1.id) - self.assertTrue(result[1].deleted) + self.assertEqual(result[0].id, inst1.id) + self.assertEqual(result[1].id, inst2.id) + self.assertTrue(result[0].deleted) From 312d97eddfafbe79fd5c61baac6b3ed4779cc305 Mon Sep 17 00:00:00 2001 From: Jason Koelker Date: Thu, 15 Sep 2011 14:02:24 -0500 Subject: [PATCH 083/100] update for the id->uuid flip --- nova/tests/test_network.py | 42 +++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py index 19ccd8c1..9ef9bd96 100644 --- a/nova/tests/test_network.py +++ b/nova/tests/test_network.py @@ -630,34 +630,34 @@ class CommonNetworkTestCase(test.TestCase): self.assertTrue(manager.create_networks(*args)) - def test_get_instance_ids_by_ip_regex(self): + def test_get_instance_uuids_by_ip_regex(self): manager = fake_network.FakeNetworkManager() _vifs = manager.db.virtual_interface_get_all(None) # Greedy get eveything - res = manager.get_instance_ids_by_ip_filter(None, {'ip': '.*'}) + res = manager.get_instance_uuids_by_ip_filter(None, {'ip': '.*'}) self.assertEqual(len(res), len(_vifs)) # Doesn't exist - res = manager.get_instance_ids_by_ip_filter(None, {'ip': '10.0.0.1'}) + res = manager.get_instance_uuids_by_ip_filter(None, {'ip': '10.0.0.1'}) self.assertFalse(res) # Get instance 1 - res = manager.get_instance_ids_by_ip_filter(None, + res = manager.get_instance_uuids_by_ip_filter(None, {'ip': '172.16.0.2'}) self.assertTrue(res) self.assertEqual(len(res), 1) self.assertEqual(res[0]['instance_id'], _vifs[1]['instance_id']) # Get instance 2 - res = manager.get_instance_ids_by_ip_filter(None, + res = manager.get_instance_uuids_by_ip_filter(None, {'ip': '173.16.0.2'}) self.assertTrue(res) self.assertEqual(len(res), 1) self.assertEqual(res[0]['instance_id'], _vifs[2]['instance_id']) # Get instance 0 and 1 - res = manager.get_instance_ids_by_ip_filter(None, + res = manager.get_instance_uuids_by_ip_filter(None, {'ip': '172.16.0.*'}) self.assertTrue(res) self.assertEqual(len(res), 2) @@ -665,27 +665,27 @@ class CommonNetworkTestCase(test.TestCase): self.assertEqual(res[1]['instance_id'], _vifs[1]['instance_id']) # Get instance 1 and 2 - res = manager.get_instance_ids_by_ip_filter(None, + res = manager.get_instance_uuids_by_ip_filter(None, {'ip': '17..16.0.2'}) self.assertTrue(res) self.assertEqual(len(res), 2) self.assertEqual(res[0]['instance_id'], _vifs[1]['instance_id']) self.assertEqual(res[1]['instance_id'], _vifs[2]['instance_id']) - def test_get_instance_ids_by_ipv6_regex(self): + def test_get_instance_uuids_by_ipv6_regex(self): manager = fake_network.FakeNetworkManager() _vifs = manager.db.virtual_interface_get_all(None) # Greedy get eveything - res = manager.get_instance_ids_by_ip_filter(None, {'ip6': '.*'}) + res = manager.get_instance_uuids_by_ip_filter(None, {'ip6': '.*'}) self.assertEqual(len(res), len(_vifs)) # Doesn't exist - res = manager.get_instance_ids_by_ip_filter(None, {'ip6': '.*1034.*'}) + res = manager.get_instance_uuids_by_ip_filter(None, {'ip6': '.*1034.*'}) self.assertFalse(res) # Get instance 1 - res = manager.get_instance_ids_by_ip_filter(None, + res = manager.get_instance_uuids_by_ip_filter(None, {'ip6': '2001:.*:2'}) self.assertTrue(res) self.assertEqual(len(res), 1) @@ -693,13 +693,13 @@ class CommonNetworkTestCase(test.TestCase): # Get instance 2 ip6 = '2002:db8::dcad:beff:feef:2' - res = manager.get_instance_ids_by_ip_filter(None, {'ip6': ip6}) + res = manager.get_instance_uuids_by_ip_filter(None, {'ip6': ip6}) self.assertTrue(res) self.assertEqual(len(res), 1) self.assertEqual(res[0]['instance_id'], _vifs[2]['instance_id']) # Get instance 0 and 1 - res = manager.get_instance_ids_by_ip_filter(None, {'ip6': '2001:.*'}) + res = manager.get_instance_uuids_by_ip_filter(None, {'ip6': '2001:.*'}) self.assertTrue(res) self.assertEqual(len(res), 2) self.assertEqual(res[0]['instance_id'], _vifs[0]['instance_id']) @@ -707,35 +707,39 @@ class CommonNetworkTestCase(test.TestCase): # Get instance 1 and 2 ip6 = '200.:db8::dcad:beff:feef:2' - res = manager.get_instance_ids_by_ip_filter(None, {'ip6': ip6}) + res = manager.get_instance_uuids_by_ip_filter(None, {'ip6': ip6}) self.assertTrue(res) self.assertEqual(len(res), 2) self.assertEqual(res[0]['instance_id'], _vifs[1]['instance_id']) self.assertEqual(res[1]['instance_id'], _vifs[2]['instance_id']) - def test_get_instance_ids_by_ip(self): + def test_get_instance_uuids_by_ip(self): manager = fake_network.FakeNetworkManager() _vifs = manager.db.virtual_interface_get_all(None) # No regex for you! - res = manager.get_instance_ids_by_ip_filter(None, {'fixed_ip': '.*'}) + res = manager.get_instance_uuids_by_ip_filter(None, + {'fixed_ip': '.*'}) self.assertFalse(res) # Doesn't exist ip = '10.0.0.1' - res = manager.get_instance_ids_by_ip_filter(None, {'fixed_ip': ip}) + res = manager.get_instance_uuids_by_ip_filter(None, + {'fixed_ip': ip}) self.assertFalse(res) # Get instance 1 ip = '172.16.0.2' - res = manager.get_instance_ids_by_ip_filter(None, {'fixed_ip': ip}) + res = manager.get_instance_uuids_by_ip_filter(None, + {'fixed_ip': ip}) self.assertTrue(res) self.assertEqual(len(res), 1) self.assertEqual(res[0]['instance_id'], _vifs[1]['instance_id']) # Get instance 2 ip = '173.16.0.2' - res = manager.get_instance_ids_by_ip_filter(None, {'fixed_ip': ip}) + res = manager.get_instance_uuids_by_ip_filter(None, + {'fixed_ip': ip}) self.assertTrue(res) self.assertEqual(len(res), 1) self.assertEqual(res[0]['instance_id'], _vifs[2]['instance_id']) From a9d9f5d1f6486fe8370ac5e845a1b6bf6cee305c Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Thu, 15 Sep 2011 14:09:14 -0500 Subject: [PATCH 084/100] Added a unit test. --- nova/tests/test_virt_drivers.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nova/tests/test_virt_drivers.py b/nova/tests/test_virt_drivers.py index 440d3401..8e20e999 100644 --- a/nova/tests/test_virt_drivers.py +++ b/nova/tests/test_virt_drivers.py @@ -176,6 +176,10 @@ class _VirtDriverTestCase(test.TestCase): def test_poll_rescued_instances(self): self.connection.poll_rescued_instances(10) + @catch_notimplementederror + def test_poll_unconfirmed_resizes(self): + self.connection.poll_unconfirmed_resizes(10) + @catch_notimplementederror def test_migrate_disk_and_power_off(self): instance_ref = test_utils.get_test_instance() From 473b8d2dff261a29c64eab6a15c48b3edb98004d Mon Sep 17 00:00:00 2001 From: Jason Koelker Date: Thu, 15 Sep 2011 14:25:52 -0500 Subject: [PATCH 085/100] remove undedded imports and skips --- nova/tests/test_network.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py index 9ef9bd96..15c17917 100644 --- a/nova/tests/test_network.py +++ b/nova/tests/test_network.py @@ -629,7 +629,6 @@ class CommonNetworkTestCase(test.TestCase): None] self.assertTrue(manager.create_networks(*args)) - def test_get_instance_uuids_by_ip_regex(self): manager = fake_network.FakeNetworkManager() _vifs = manager.db.virtual_interface_get_all(None) @@ -681,7 +680,8 @@ class CommonNetworkTestCase(test.TestCase): self.assertEqual(len(res), len(_vifs)) # Doesn't exist - res = manager.get_instance_uuids_by_ip_filter(None, {'ip6': '.*1034.*'}) + res = manager.get_instance_uuids_by_ip_filter(None, + {'ip6': '.*1034.*'}) self.assertFalse(res) # Get instance 1 From 1760819084d37c22ee31736b4a7f5234c1bda316 Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Fri, 16 Sep 2011 17:04:27 +0900 Subject: [PATCH 087/100] compute/api: swap size issue When --block-device-mapping swap= is specified, its swap size is wrongly set to 0. Thus swap device will be missing. This is reported by https://bugs.launchpad.net/bugs/851218 This patch fixes it. --- nova/tests/test_compute.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 4d463572..d600c9f1 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -1563,12 +1563,16 @@ class ComputeTestCase(test.TestCase): db.block_device_mapping_destroy(self.context, bdm['id']) self.compute.terminate_instance(self.context, instance_id) - def test_ephemeral_size(self): + def test_volume_size(self): local_size = 2 - inst_type = {'local_gb': local_size} - self.assertEqual(self.compute_api._ephemeral_size(inst_type, + swap_size = 3 + inst_type = {'local_gb': local_size, 'swap': swap_size} + self.assertEqual(self.compute_api._volume_size(inst_type, 'ephemeral0'), local_size) - self.assertEqual(self.compute_api._ephemeral_size(inst_type, - 'ephemeral1'), + self.assertEqual(self.compute_api._volume_size(inst_type, + 'ephemeral1'), 0) + self.assertEqual(self.compute_api._volume_size(inst_type, + 'swap'), + swap_size) From 824428e0f2a3f4e33c84474145ba24305d6a5d98 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Fri, 16 Sep 2011 09:40:24 -0400 Subject: [PATCH 088/100] Add a FakeVirDomainSnapshot and return it from snapshotCreateXML. Fixes libvirt snapshot tests. --- nova/tests/test_libvirt.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index b7c1ef1a..1924ae05 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -52,6 +52,15 @@ def _concurrency(wait, done, target): done.send() +class FakeVirDomainSnapshot(object): + + def __init__(self, dom=None): + self.dom = dom + + def delete(self, flags): + pass + + class FakeVirtDomain(object): def __init__(self, fake_xml=None): @@ -69,7 +78,7 @@ class FakeVirtDomain(object): """ def snapshotCreateXML(self, *args): - return None + return FakeVirDomainSnapshot(self) def createWithFlags(self, launch_flags): pass From 7863dee4fa8aeca1933aaf9f51ef85ae5fe6eaf2 Mon Sep 17 00:00:00 2001 From: Jason Koelker Date: Fri, 16 Sep 2011 13:44:16 -0500 Subject: [PATCH 089/100] update tests to return fake_nw_info that is valid for the pre_live_migrate --- nova/tests/test_compute.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 4d463572..2de2ce38 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -647,7 +647,6 @@ class ComputeTestCase(test.TestCase): dbmock = self.mox.CreateMock(db) dbmock.instance_get(c, i_id).AndReturn(instance_ref) - dbmock.instance_get_fixed_addresses(c, i_id).AndReturn(None) self.compute.db = dbmock self.mox.ReplayAll() @@ -657,6 +656,9 @@ class ComputeTestCase(test.TestCase): def test_pre_live_migration_instance_has_volume(self): """Confirm setup_compute_volume is called when volume is mounted.""" + def fake_nw_info(*args, **kwargs): + return [(0, {'ips':['dummy']})] + i_ref = self._get_dummy_instance() c = context.get_admin_context() @@ -666,13 +668,13 @@ class ComputeTestCase(test.TestCase): drivermock = self.mox.CreateMock(self.compute_driver) dbmock.instance_get(c, i_ref['id']).AndReturn(i_ref) - dbmock.instance_get_fixed_addresses(c, i_ref['id']).AndReturn('dummy') for i in range(len(i_ref['volumes'])): vid = i_ref['volumes'][i]['id'] volmock.setup_compute_volume(c, vid).InAnyOrder('g1') - drivermock.plug_vifs(i_ref, []) - drivermock.ensure_filtering_rules_for_instance(i_ref, []) + drivermock.plug_vifs(i_ref, fake_nw_info()) + drivermock.ensure_filtering_rules_for_instance(i_ref, fake_nw_info()) + self.stubs.Set(self.compute, '_get_instance_nw_info', fake_nw_info) self.compute.db = dbmock self.compute.volume_manager = volmock self.compute.driver = drivermock @@ -683,6 +685,9 @@ class ComputeTestCase(test.TestCase): def test_pre_live_migration_instance_has_no_volume(self): """Confirm log meg when instance doesn't mount any volumes.""" + def fake_nw_info(*args, **kwargs): + return [(0, {'ips':['dummy']})] + i_ref = self._get_dummy_instance() i_ref['volumes'] = [] c = context.get_admin_context() @@ -692,12 +697,12 @@ class ComputeTestCase(test.TestCase): drivermock = self.mox.CreateMock(self.compute_driver) dbmock.instance_get(c, i_ref['id']).AndReturn(i_ref) - dbmock.instance_get_fixed_addresses(c, i_ref['id']).AndReturn('dummy') self.mox.StubOutWithMock(compute_manager.LOG, 'info') compute_manager.LOG.info(_("%s has no volume."), i_ref['hostname']) - drivermock.plug_vifs(i_ref, []) - drivermock.ensure_filtering_rules_for_instance(i_ref, []) + drivermock.plug_vifs(i_ref, fake_nw_info()) + drivermock.ensure_filtering_rules_for_instance(i_ref, fake_nw_info()) + self.stubs.Set(self.compute, '_get_instance_nw_info', fake_nw_info) self.compute.db = dbmock self.compute.driver = drivermock @@ -711,6 +716,9 @@ class ComputeTestCase(test.TestCase): It retries and raise exception when timeout exceeded. """ + def fake_nw_info(*args, **kwargs): + return [(0, {'ips':['dummy']})] + i_ref = self._get_dummy_instance() c = context.get_admin_context() @@ -722,13 +730,13 @@ class ComputeTestCase(test.TestCase): drivermock = self.mox.CreateMock(self.compute_driver) dbmock.instance_get(c, i_ref['id']).AndReturn(i_ref) - dbmock.instance_get_fixed_addresses(c, i_ref['id']).AndReturn('dummy') for i in range(len(i_ref['volumes'])): volmock.setup_compute_volume(c, i_ref['volumes'][i]['id']) for i in range(FLAGS.live_migration_retry_count): - drivermock.plug_vifs(i_ref, []).\ + drivermock.plug_vifs(i_ref, fake_nw_info()).\ AndRaise(exception.ProcessExecutionError()) + self.stubs.Set(self.compute, '_get_instance_nw_info', fake_nw_info) self.compute.db = dbmock self.compute.network_manager = netmock self.compute.volume_manager = volmock From 9cf7faaed840e07e9cf57e3c666f52e2486e55ba Mon Sep 17 00:00:00 2001 From: Jason Koelker Date: Fri, 16 Sep 2011 13:52:06 -0500 Subject: [PATCH 090/100] pep8 --- nova/tests/test_compute.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 2de2ce38..2fd812cf 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -719,7 +719,6 @@ class ComputeTestCase(test.TestCase): def fake_nw_info(*args, **kwargs): return [(0, {'ips':['dummy']})] - i_ref = self._get_dummy_instance() c = context.get_admin_context() From 80f4fb86c24a8537f00406805c40b24539309122 Mon Sep 17 00:00:00 2001 From: Soren Hansen Date: Fri, 16 Sep 2011 21:27:25 +0200 Subject: [PATCH 091/100] Fix failing test. --- nova/tests/test_libvirt.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 769bc529..b7c1ef1a 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -1008,10 +1008,6 @@ class IptablesFirewallTestCase(test.TestCase): 'to_port': 81, 'group_id': src_secgroup['id']}) - db.security_group_rule_create(admin_ctxt, - {'parent_group_id': secgroup['id'], - 'group_id': src_secgroup['id']}) - db.instance_add_security_group(admin_ctxt, instance_ref['id'], secgroup['id']) db.instance_add_security_group(admin_ctxt, src_instance_ref['id'], @@ -1094,10 +1090,6 @@ class IptablesFirewallTestCase(test.TestCase): self.assertTrue(len(filter(regex.match, self.out_rules)) > 0, "TCP port 80/81 acceptance rule wasn't added") - regex = re.compile('-A .* -j ACCEPT -s %s' % (src_ip,)) - self.assertTrue(len(filter(regex.match, self.out_rules)) > 0, - "TCP port 80/81 acceptance rule wasn't added") - regex = re.compile('-A .* -j ACCEPT -p tcp ' '-m multiport --dports 80:81 -s 192.168.10.0/24') self.assertTrue(len(filter(regex.match, self.out_rules)) > 0, From 4dc2a091bd9d503aee8b89ea5cb4dfd8ece0f0ab Mon Sep 17 00:00:00 2001 From: "paul@openstack.org" <> Date: Fri, 16 Sep 2011 21:12:50 -0500 Subject: [PATCH 092/100] fixed grant user, added stdout support --- bin/nova-manage | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index 60799024..4e930727 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -275,11 +275,13 @@ class ShellCommands(object): arguments: path""" exec(compile(open(path).read(), path, 'exec'), locals(), globals()) - @args('--filename', dest='filename', metavar='', help='Export path') + @args('--filename', dest='filename', metavar='', default=False, + help='Export file path') def export(self, filename): """Export Nova users into a file that can be consumed by Keystone""" + def create_file(filename): - data = generate_file() + data = generate_data() with open(filename, 'w') as f: f.write(data.getvalue()) @@ -303,21 +305,27 @@ class ShellCommands(object): for project in am.get_projects(): for u in project.member_ids: user = am.get_user(u) - for role in roles: - if user.has_role(role): - print >> data, ("role grant '%s', '%s', '%s')," % - (user.name, role, project.name)) - print >> data, footer + for role in db.user_get_roles_for_project(ctxt, u, + project.id): + print >> data, ("role grant '%s', '%s', '%s')," % + (user.name, role, project.name)) + print >> data - def generate_file(): + def generate_data(): data = StringIO.StringIO() am = manager.AuthManager() tenants(data, am) roles(data, am) + grant_roles(data, am) data.seek(0) return data - create_file(filename) + ctxt = context.get_admin_context() + if filename: + create_file(filename) + else: + data = generate_data() + print data.getvalue() class RoleCommands(object): From 5f81e6b730db3f3dc29191d8e7ae3b9df0633dc4 Mon Sep 17 00:00:00 2001 From: Christopher MacGown Date: Sat, 17 Sep 2011 13:05:42 -0700 Subject: [PATCH 093/100] Fix user_id, project_id reference for config_drive with imageRefs --- nova/tests/test_compute.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 65fdffbd..d5ee25e8 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -174,6 +174,20 @@ class ComputeTestCase(test.TestCase): self.assertEqual(pre_build_len, len(db.instance_get_all(context.get_admin_context()))) + def test_create_instance_with_img_ref_associates_config_drive(self): + """Make sure create associates a config drive.""" + + instance_id = self._create_instance(params={'config_drive': '1234', }) + + try: + self.compute.run_instance(self.context, instance_id) + instances = db.instance_get_all(context.get_admin_context()) + instance = instances[0] + + self.assertTrue(instance.config_drive) + finally: + db.instance_destroy(self.context, instance_id) + def test_create_instance_associates_config_drive(self): """Make sure create associates a config drive.""" From ccc25f83f4068a10a2edb28deb8c35a73ebadd13 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Mon, 19 Sep 2011 11:58:20 -0500 Subject: [PATCH 094/100] Added unit test. --- nova/tests/test_db_api.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index 60d7abd8..c99709ff 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -18,6 +18,8 @@ """Unit tests for the DB API""" +import datetime + from nova import test from nova import context from nova import db @@ -95,3 +97,26 @@ class DbApiTestCase(test.TestCase): self.assertEqual(result[0].id, inst2.id) self.assertEqual(result[1].id, inst1.id) self.assertTrue(result[1].deleted) + + def test_migration_get_all_unconfirmed(self): + ctxt = context.get_admin_context() + + # Ensure no migrations are returned. + results = db.migration_get_all_unconfirmed(ctxt, 10) + self.assertEqual(0, len(results)) + + # Ensure one migration older than 10 seconds is returned. + updated_at = datetime.datetime(2000, 01, 01, 12, 00, 00) + values = {"status": "FINISHED", "updated_at": updated_at} + migration = db.migration_create(ctxt, values) + results = db.migration_get_all_unconfirmed(ctxt, 10) + self.assertEqual(1, len(results)) + db.migration_update(ctxt, migration.id, {"status": "CONFIRMED"}) + + # Ensure the new migration is not returned. + updated_at = datetime.datetime.utcnow() + values = {"status": "FINISHED", "updated_at": updated_at} + migration = db.migration_create(ctxt, values) + results = db.migration_get_all_unconfirmed(ctxt, 10) + self.assertEqual(0, len(results)) + db.migration_update(ctxt, migration.id, {"status": "CONFIRMED"}) From f2a25f938b50fdac3931a936f6af27d5d5f7ddc4 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Mon, 19 Sep 2011 15:56:42 -0500 Subject: [PATCH 095/100] now raising instead of setting bridge to br100 and warning as was noted --- bin/nova-manage | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index 089b2eea..4d90dd1b 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -710,16 +710,7 @@ class NetworkCommands(object): bridge_required = ['nova.network.manager.FlatManager', 'nova.network.manager.FlatDHCPManager'] if FLAGS.network_manager in bridge_required: - # TODO(tr3buchet) - swap print statement and following line for - # raise statement in diablo 4 - print _('--bridge parameter required or FLAG ' - 'flat_network_bridge must be set to create networks\n' - 'WARNING! ACHTUNG! Setting the bridge to br100 ' - 'automatically is deprecated and will be removed in ' - 'Diablo milestone 4. Prepare yourself accordingly.') - time.sleep(10) - bridge = 'br100' - #raise exception.NetworkNotCreated(req='--bridge') + raise exception.NetworkNotCreated(req='--bridge') bridge_interface = bridge_interface or FLAGS.flat_interface or \ FLAGS.vlan_interface From 78e068ca2d2235bd5b7fb75b9a56b95f90e7b1f9 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Mon, 19 Sep 2011 14:53:17 -0700 Subject: [PATCH 096/100] Removed the extra code added to support filtering instances by instance uuids. Instead, added 'uuid' to the list of exact_filter_match names. Updated the caller to add 'uuid: uuid_list' to the filters dictionary, instead of passing it in as another argument. Updated the ID to UUID mapping code to return a dictionary, which allows the caller to be more efficient... It removes an extra loop there. A couple of typo fixes. --- nova/tests/test_compute.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 4ef57b76..948c7ad4 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -1033,8 +1033,8 @@ class ComputeTestCase(test.TestCase): 'get_instance_uuids_by_ip_filter', network_manager.get_instance_uuids_by_ip_filter) self.stubs.Set(network_manager.db, - 'instance_get_uuids_by_ids', - db.instance_get_uuids_by_ids) + 'instance_get_id_to_uuid_mapping', + db.instance_get_id_to_uuid_mapping) instance_id1 = self._create_instance({'display_name': 'woot', 'id': 0}) From d2f78b1b708b4c5de0ecf68ce3246a14163383b0 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Mon, 19 Sep 2011 15:08:25 -0700 Subject: [PATCH 097/100] fix a test where list order was assumed --- nova/tests/test_db_api.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index 5ebab9cc..aaf5212d 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -92,6 +92,9 @@ class DbApiTestCase(test.TestCase): db.instance_destroy(self.context, inst1.id) result = db.instance_get_all_by_filters(self.context.elevated(), {}) self.assertEqual(2, len(result)) - self.assertEqual(result[0].id, inst1.id) - self.assertEqual(result[1].id, inst2.id) - self.assertTrue(result[0].deleted) + self.assertIn(inst1.id, [result[0].id, result[1].id]) + self.assertIn(inst2.id, [result[0].id, result[1].id]) + if inst1.id == result[0].id: + self.assertTrue(result[0].deleted) + else: + self.assertTrue(result[1].deleted) From 6c2e48f447962cd76a59f33f1eec35c1e5fa8029 Mon Sep 17 00:00:00 2001 From: "Brad McConnell bmcconne@rackspace.com" <> Date: Mon, 19 Sep 2011 21:35:47 -0500 Subject: [PATCH 098/100] Fixed --uuid network command in nova-manage to desc to "uuid" instead of "net_uuid" --- bin/nova-manage | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/nova-manage b/bin/nova-manage index 4e930727..8a1a8537 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -738,7 +738,7 @@ class NetworkCommands(object): help='Multi host') @args('--dns1', dest="dns1", metavar="", help='First DNS') @args('--dns2', dest="dns2", metavar="", help='Second DNS') - @args('--uuid', dest="net_uuid", metavar="", + @args('--uuid', dest="uuid", metavar="", help='Network UUID') @args('--project_id', dest="project_id", metavar="", help='Project id') From e2b5dcd3316fde1a06b27e8724a9cef39b778a95 Mon Sep 17 00:00:00 2001 From: "Brad McConnell bmcconne@rackspace.com" <> Date: Mon, 19 Sep 2011 22:21:10 -0500 Subject: [PATCH 099/100] added to authors cuz trey said I cant patch otherwise! --- Authors | 1 + 1 file changed, 1 insertion(+) diff --git a/Authors b/Authors index 4e084869..8d6837ea 100644 --- a/Authors +++ b/Authors @@ -12,6 +12,7 @@ Armando Migliaccio Arvind Somya Bilal Akhtar Brad Hall +Brad McConnell Brian Lamar Brian Schott Brian Waldon