summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorTushar Patil <tushar.vitthal.patil@gmail.com>2011-07-21 11:21:38 -0700
committerTushar Patil <tushar.vitthal.patil@gmail.com>2011-07-21 11:21:38 -0700
commita03210b262e258bb56377b5a2d46a1134cbe3450 (patch)
tree09bfe7297592e70fb2fe084fc6b79f15caadec65 /nova/tests
parent038565bdc735ff7a227a39d2ee21df0e8194929b (diff)
parent26ae789a7a3c4b8819368b7e148d1296124e6994 (diff)
Merged with trunk which includes ha-net changes
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/__init__.py3
-rw-r--r--nova/tests/api/openstack/test_faults.py5
-rw-r--r--nova/tests/api/openstack/test_servers.py51
-rw-r--r--nova/tests/test_cloud.py29
-rw-r--r--nova/tests/test_compute.py73
-rw-r--r--nova/tests/test_libvirt.py1
-rw-r--r--nova/tests/test_network.py19
7 files changed, 156 insertions, 25 deletions
diff --git a/nova/tests/__init__.py b/nova/tests/__init__.py
index e4ed75d37..7df6c06eb 100644
--- a/nova/tests/__init__.py
+++ b/nova/tests/__init__.py
@@ -59,6 +59,7 @@ def setup():
network.create_networks(ctxt,
label='test',
cidr=FLAGS.fixed_range,
+ multi_host=FLAGS.multi_host,
num_networks=FLAGS.num_networks,
network_size=FLAGS.network_size,
cidr_v6=FLAGS.fixed_range_v6,
@@ -68,7 +69,7 @@ def setup():
vpn_start=FLAGS.vpn_start,
vlan_start=FLAGS.vlan_start)
for net in db.network_get_all(ctxt):
- network.set_network_host(ctxt, net['id'])
+ network.set_network_host(ctxt, net)
cleandb = os.path.join(FLAGS.state_path, FLAGS.sqlite_clean_db)
shutil.copyfile(testdb, cleandb)
diff --git a/nova/tests/api/openstack/test_faults.py b/nova/tests/api/openstack/test_faults.py
index 4d86ffb26..927009e77 100644
--- a/nova/tests/api/openstack/test_faults.py
+++ b/nova/tests/api/openstack/test_faults.py
@@ -139,3 +139,8 @@ class TestFaults(test.TestCase):
self.assertEqual(resp.content_type, "application/xml")
self.assertEqual(resp.status_int, 404)
self.assertTrue('whut?' in resp.body)
+
+ def test_fault_has_status_int(self):
+ """Ensure the status_int is set correctly on faults"""
+ fault = faults.Fault(webob.exc.HTTPBadRequest(explanation='what?'))
+ self.assertEqual(fault.status_int, 400)
diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py
index ec7dedafc..cf9fe0c7a 100644
--- a/nova/tests/api/openstack/test_servers.py
+++ b/nova/tests/api/openstack/test_servers.py
@@ -433,6 +433,7 @@ class ServersTest(test.TestCase):
self.assertEquals(ip.getAttribute('addr'), private)
def test_get_server_by_id_with_addresses_v1_1(self):
+ FLAGS.use_ipv6 = True
interfaces = [
{
'network': {'label': 'network_1'},
@@ -447,6 +448,50 @@ class ServersTest(test.TestCase):
{'address': '172.19.0.1'},
{'address': '172.19.0.2'},
],
+ 'fixed_ipv6': '2001:4860::12',
+ },
+ ]
+ new_return_server = return_server_with_interfaces(interfaces)
+ self.stubs.Set(nova.db.api, 'instance_get', new_return_server)
+
+ req = webob.Request.blank('/v1.1/servers/1')
+ res = req.get_response(fakes.wsgi_app())
+
+ res_dict = json.loads(res.body)
+ self.assertEqual(res_dict['server']['id'], 1)
+ self.assertEqual(res_dict['server']['name'], 'server1')
+ addresses = res_dict['server']['addresses']
+ expected = {
+ 'network_1': [
+ {'addr': '192.168.0.3', 'version': 4},
+ {'addr': '192.168.0.4', 'version': 4},
+ ],
+ 'network_2': [
+ {'addr': '172.19.0.1', 'version': 4},
+ {'addr': '172.19.0.2', 'version': 4},
+ {'addr': '2001:4860::12', 'version': 6},
+ ],
+ }
+
+ self.assertEqual(addresses, expected)
+
+ def test_get_server_by_id_with_addresses_v1_1_ipv6_disabled(self):
+ FLAGS.use_ipv6 = False
+ interfaces = [
+ {
+ 'network': {'label': 'network_1'},
+ 'fixed_ips': [
+ {'address': '192.168.0.3'},
+ {'address': '192.168.0.4'},
+ ],
+ },
+ {
+ 'network': {'label': 'network_2'},
+ 'fixed_ips': [
+ {'address': '172.19.0.1'},
+ {'address': '172.19.0.2'},
+ ],
+ 'fixed_ipv6': '2001:4860::12',
},
]
new_return_server = return_server_with_interfaces(interfaces)
@@ -473,6 +518,7 @@ class ServersTest(test.TestCase):
self.assertEqual(addresses, expected)
def test_get_server_addresses_v1_1(self):
+ FLAGS.use_ipv6 = True
interfaces = [
{
'network': {'label': 'network_1'},
@@ -492,6 +538,7 @@ class ServersTest(test.TestCase):
},
{'address': '172.19.0.2'},
],
+ 'fixed_ipv6': '2001:4860::12',
},
]
@@ -514,6 +561,7 @@ class ServersTest(test.TestCase):
{'version': 4, 'addr': '172.19.0.1'},
{'version': 4, 'addr': '1.2.3.4'},
{'version': 4, 'addr': '172.19.0.2'},
+ {'version': 6, 'addr': '2001:4860::12'},
],
},
}
@@ -521,6 +569,7 @@ class ServersTest(test.TestCase):
self.assertEqual(res_dict, expected)
def test_get_server_addresses_single_network_v1_1(self):
+ FLAGS.use_ipv6 = True
interfaces = [
{
'network': {'label': 'network_1'},
@@ -540,6 +589,7 @@ class ServersTest(test.TestCase):
},
{'address': '172.19.0.2'},
],
+ 'fixed_ipv6': '2001:4860::12',
},
]
_return_vifs = return_virtual_interface_by_instance(interfaces)
@@ -556,6 +606,7 @@ class ServersTest(test.TestCase):
{'version': 4, 'addr': '172.19.0.1'},
{'version': 4, 'addr': '1.2.3.4'},
{'version': 4, 'addr': '172.19.0.2'},
+ {'version': 6, 'addr': '2001:4860::12'},
],
}
self.assertEqual(res_dict, expected)
diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py
index a0d50b287..8cdc73a66 100644
--- a/nova/tests/test_cloud.py
+++ b/nova/tests/test_cloud.py
@@ -15,6 +15,7 @@
# 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 base64 import b64decode
from M2Crypto import BIO
@@ -29,6 +30,7 @@ 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
@@ -132,6 +134,33 @@ class CloudTestCase(test.TestCase):
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)
+
@test.skip_test("Skipping this pending future merge")
def test_associate_disassociate_address(self):
"""Verifies associate runs cleanly without raising an exception"""
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index 2900c594e..4bda38d85 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -424,11 +424,12 @@ class ComputeTestCase(test.TestCase):
self.stubs.Set(self.compute.network_api, 'get_instance_nw_info', fake)
context = self.context.elevated()
instance_id = self._create_instance()
- self.compute.prep_resize(context, instance_id, 1)
+ instance_ref = db.instance_get(context, instance_id)
+ self.compute.prep_resize(context, instance_ref['uuid'], 1)
migration_ref = db.migration_get_by_instance_and_status(context,
- instance_id, 'pre-migrating')
+ instance_ref['uuid'], 'pre-migrating')
try:
- self.compute.finish_resize(context, instance_id,
+ self.compute.finish_resize(context, instance_ref['uuid'],
int(migration_ref['id']), {})
except KeyError, e:
# Only catch key errors. We want other reasons for the test to
@@ -441,14 +442,15 @@ class ComputeTestCase(test.TestCase):
"""Ensure notifications on instance migrate/resize"""
instance_id = self._create_instance()
context = self.context.elevated()
+ inst_ref = db.instance_get(context, instance_id)
self.compute.run_instance(self.context, instance_id)
test_notifier.NOTIFICATIONS = []
db.instance_update(self.context, instance_id, {'host': 'foo'})
- self.compute.prep_resize(context, instance_id, 1)
+ self.compute.prep_resize(context, inst_ref['uuid'], 1)
migration_ref = db.migration_get_by_instance_and_status(context,
- instance_id, 'pre-migrating')
+ inst_ref['uuid'], 'pre-migrating')
self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
msg = test_notifier.NOTIFICATIONS[0]
@@ -471,13 +473,15 @@ class ComputeTestCase(test.TestCase):
"""Ensure instance can be migrated/resized"""
instance_id = self._create_instance()
context = self.context.elevated()
+ inst_ref = db.instance_get(context, instance_id)
self.compute.run_instance(self.context, instance_id)
- db.instance_update(self.context, instance_id, {'host': 'foo'})
- self.compute.prep_resize(context, instance_id, 1)
+ db.instance_update(self.context, inst_ref['uuid'],
+ {'host': 'foo'})
+ self.compute.prep_resize(context, inst_ref['uuid'], 1)
migration_ref = db.migration_get_by_instance_and_status(context,
- instance_id, 'pre-migrating')
- self.compute.resize_instance(context, instance_id,
+ inst_ref['uuid'], 'pre-migrating')
+ self.compute.resize_instance(context, inst_ref['uuid'],
migration_ref['id'])
self.compute.terminate_instance(context, instance_id)
@@ -519,6 +523,57 @@ class ComputeTestCase(test.TestCase):
self.compute.terminate_instance(context, instance_id)
+ def test_finish_revert_resize(self):
+ """Ensure that the flavor is reverted to the original on revert"""
+ context = self.context.elevated()
+ instance_id = self._create_instance()
+
+ def fake(*args, **kwargs):
+ pass
+
+ self.stubs.Set(self.compute.driver, 'finish_resize', fake)
+ self.stubs.Set(self.compute.driver, 'revert_resize', fake)
+ self.stubs.Set(self.compute.network_api, 'get_instance_nw_info', fake)
+
+ self.compute.run_instance(self.context, instance_id)
+
+ # Confirm the instance size before the resize starts
+ inst_ref = db.instance_get(context, instance_id)
+ instance_type_ref = db.instance_type_get_by_id(context,
+ inst_ref['instance_type_id'])
+ self.assertEqual(instance_type_ref['flavorid'], 1)
+
+ db.instance_update(self.context, instance_id, {'host': 'foo'})
+
+ self.compute.prep_resize(context, inst_ref['uuid'], 3)
+
+ migration_ref = db.migration_get_by_instance_and_status(context,
+ inst_ref['uuid'], 'pre-migrating')
+
+ self.compute.resize_instance(context, inst_ref['uuid'],
+ migration_ref['id'])
+ self.compute.finish_resize(context, inst_ref['uuid'],
+ int(migration_ref['id']), {})
+
+ # Prove that the instance size is now the new size
+ inst_ref = db.instance_get(context, instance_id)
+ instance_type_ref = db.instance_type_get_by_id(context,
+ inst_ref['instance_type_id'])
+ self.assertEqual(instance_type_ref['flavorid'], 3)
+
+ # Finally, revert and confirm the old flavor has been applied
+ self.compute.revert_resize(context, inst_ref['uuid'],
+ migration_ref['id'])
+ self.compute.finish_revert_resize(context, inst_ref['uuid'],
+ migration_ref['id'])
+
+ inst_ref = db.instance_get(context, instance_id)
+ instance_type_ref = db.instance_type_get_by_id(context,
+ inst_ref['instance_type_id'])
+ self.assertEqual(instance_type_ref['flavorid'], 1)
+
+ self.compute.terminate_instance(context, instance_id)
+
def test_get_by_flavor_id(self):
type = instance_types.get_instance_type_by_flavor_id(1)
self.assertEqual(type['name'], 'm1.tiny')
diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py
index f99e1713d..6e2ec7ed6 100644
--- a/nova/tests/test_libvirt.py
+++ b/nova/tests/test_libvirt.py
@@ -58,6 +58,7 @@ def _create_network_info(count=1, ipv6=None):
'cidr': fake_ip,
'cidr_v6': fake_ip}
mapping = {'mac': fake,
+ 'dhcp_server': fake,
'gateway': fake,
'gateway6': fake,
'ips': [{'ip': fake_ip}, {'ip': fake_ip}]}
diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py
index fd4408831..017c6fe34 100644
--- a/nova/tests/test_network.py
+++ b/nova/tests/test_network.py
@@ -45,6 +45,7 @@ class FakeModel(dict):
networks = [{'id': 0,
'label': 'test0',
'injected': False,
+ 'multi_host': False,
'cidr': '192.168.0.0/24',
'cidr_v6': '2001:db8::/64',
'gateway_v6': '2001:db8::1',
@@ -62,6 +63,7 @@ networks = [{'id': 0,
{'id': 1,
'label': 'test1',
'injected': False,
+ 'multi_host': False,
'cidr': '192.168.1.0/24',
'cidr_v6': '2001:db9::/64',
'gateway_v6': '2001:db9::1',
@@ -122,20 +124,6 @@ class FlatNetworkTestCase(test.TestCase):
self.network = network_manager.FlatManager(host=HOST)
self.network.db = db
- def test_set_network_hosts(self):
- self.mox.StubOutWithMock(db, 'network_get_all')
- self.mox.StubOutWithMock(db, 'network_set_host')
- self.mox.StubOutWithMock(db, 'network_update')
-
- db.network_get_all(mox.IgnoreArg()).AndReturn([networks[0]])
- db.network_set_host(mox.IgnoreArg(),
- networks[0]['id'],
- mox.IgnoreArg()).AndReturn(HOST)
- db.network_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
- self.mox.ReplayAll()
-
- self.network.set_network_hosts(None)
-
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')
@@ -149,7 +137,7 @@ class FlatNetworkTestCase(test.TestCase):
mox.IgnoreArg()).AndReturn(flavor)
self.mox.ReplayAll()
- nw_info = self.network.get_instance_nw_info(None, 0, 0)
+ nw_info = self.network.get_instance_nw_info(None, 0, 0, None)
self.assertTrue(nw_info)
@@ -164,6 +152,7 @@ class FlatNetworkTestCase(test.TestCase):
self.assertDictMatch(nw[0], 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,