summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorTushar Patil <tushar.vitthal.patil@gmail.com>2011-08-20 13:15:05 -0700
committerTushar Patil <tushar.vitthal.patil@gmail.com>2011-08-20 13:15:05 -0700
commit71ae1f16312371fee810221e81c2bcb0fcb5a4ef (patch)
treea3831d99867136776f8a287fbc0dbb554cde4108 /nova/tests
parentc3ef50fd4b866ec6dc90ad114e36b16c857ca206 (diff)
parent7924fb7899b02d3cb7420c916e035094d5c90194 (diff)
Merged from trunk
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/contrib/test_floating_ips.py110
-rw-r--r--nova/tests/api/openstack/contrib/test_rescue.py55
-rw-r--r--nova/tests/api/openstack/contrib/test_virtual_interfaces.py55
-rw-r--r--nova/tests/api/openstack/fakes.py5
-rw-r--r--nova/tests/api/openstack/test_extensions.py2
-rw-r--r--nova/tests/api/openstack/test_image_metadata.py4
-rw-r--r--nova/tests/api/openstack/test_server_actions.py4
-rw-r--r--nova/tests/api/openstack/test_server_metadata.py4
-rw-r--r--nova/tests/api/openstack/test_servers.py121
-rw-r--r--nova/tests/scheduler/test_abstract_scheduler.py3
-rw-r--r--nova/tests/scheduler/test_host_filter.py29
-rw-r--r--nova/tests/scheduler/test_least_cost_scheduler.py18
-rw-r--r--nova/tests/test_api.py3
-rw-r--r--nova/tests/test_cloud.py11
-rw-r--r--nova/tests/test_db_api.py17
-rw-r--r--nova/tests/test_host_filter.py200
-rw-r--r--nova/tests/test_libvirt.py1
-rw-r--r--nova/tests/test_metadata.py40
-rw-r--r--nova/tests/test_network.py5
-rw-r--r--nova/tests/test_service.py2
20 files changed, 418 insertions, 271 deletions
diff --git a/nova/tests/api/openstack/contrib/test_floating_ips.py b/nova/tests/api/openstack/contrib/test_floating_ips.py
index 704d06582..d2ca9c365 100644
--- a/nova/tests/api/openstack/contrib/test_floating_ips.py
+++ b/nova/tests/api/openstack/contrib/test_floating_ips.py
@@ -17,6 +17,7 @@ import json
import stubout
import webob
+from nova import compute
from nova import context
from nova import db
from nova import test
@@ -30,6 +31,11 @@ from nova.api.openstack.contrib.floating_ips import _translate_floating_ip_view
def network_api_get_floating_ip(self, context, id):
return {'id': 1, 'address': '10.10.10.10',
+ 'fixed_ip': None}
+
+
+def network_api_get_floating_ip_by_ip(self, context, address):
+ return {'id': 1, 'address': '10.10.10.10',
'fixed_ip': {'address': '11.0.0.1'}}
@@ -50,7 +56,7 @@ def network_api_release(self, context, address):
pass
-def network_api_associate(self, context, floating_ip, fixed_ip):
+def compute_api_associate(self, context, instance_id, floating_ip):
pass
@@ -78,14 +84,16 @@ class FloatingIpTest(test.TestCase):
fakes.stub_out_rate_limiting(self.stubs)
self.stubs.Set(network.api.API, "get_floating_ip",
network_api_get_floating_ip)
+ self.stubs.Set(network.api.API, "get_floating_ip_by_ip",
+ network_api_get_floating_ip)
self.stubs.Set(network.api.API, "list_floating_ips",
network_api_list_floating_ips)
self.stubs.Set(network.api.API, "allocate_floating_ip",
network_api_allocate)
self.stubs.Set(network.api.API, "release_floating_ip",
network_api_release)
- self.stubs.Set(network.api.API, "associate_floating_ip",
- network_api_associate)
+ self.stubs.Set(compute.api.API, "associate_floating_ip",
+ compute_api_associate)
self.stubs.Set(network.api.API, "disassociate_floating_ip",
network_api_disassociate)
self.context = context.get_admin_context()
@@ -133,7 +141,6 @@ class FloatingIpTest(test.TestCase):
res_dict = json.loads(res.body)
self.assertEqual(res_dict['floating_ip']['id'], 1)
self.assertEqual(res_dict['floating_ip']['ip'], '10.10.10.10')
- self.assertEqual(res_dict['floating_ip']['fixed_ip'], '11.0.0.1')
self.assertEqual(res_dict['floating_ip']['instance_id'], None)
def test_floating_ip_allocate(self):
@@ -141,51 +148,78 @@ class FloatingIpTest(test.TestCase):
req.method = 'POST'
req.headers['Content-Type'] = 'application/json'
res = req.get_response(fakes.wsgi_app())
- print res
self.assertEqual(res.status_int, 200)
- ip = json.loads(res.body)['allocated']
+ ip = json.loads(res.body)['floating_ip']
+
expected = {
"id": 1,
- "floating_ip": '10.10.10.10'}
+ "instance_id": None,
+ "ip": "10.10.10.10",
+ "fixed_ip": None}
self.assertEqual(ip, expected)
def test_floating_ip_release(self):
req = webob.Request.blank('/v1.1/os-floating-ips/1')
req.method = 'DELETE'
res = req.get_response(fakes.wsgi_app())
- self.assertEqual(res.status_int, 200)
- actual = json.loads(res.body)['released']
- expected = {
- "id": 1,
- "floating_ip": '10.10.10.10'}
- self.assertEqual(actual, expected)
+ self.assertEqual(res.status_int, 202)
- def test_floating_ip_associate(self):
- body = dict(associate_address=dict(fixed_ip='1.2.3.4'))
- req = webob.Request.blank('/v1.1/os-floating-ips/1/associate')
- req.method = 'POST'
+ def test_add_floating_ip_to_instance(self):
+ body = dict(addFloatingIp=dict(address='11.0.0.1'))
+ req = webob.Request.blank('/v1.1/servers/test_inst/action')
+ req.method = "POST"
req.body = json.dumps(body)
req.headers["content-type"] = "application/json"
- res = req.get_response(fakes.wsgi_app())
- self.assertEqual(res.status_int, 200)
- actual = json.loads(res.body)['associated']
- expected = {
- "floating_ip_id": '1',
- "floating_ip": "10.10.10.10",
- "fixed_ip": "1.2.3.4"}
- self.assertEqual(actual, expected)
-
- def test_floating_ip_disassociate(self):
- body = dict()
- req = webob.Request.blank('/v1.1/os-floating-ips/1/disassociate')
- req.method = 'POST'
+ resp = req.get_response(fakes.wsgi_app())
+ self.assertEqual(resp.status_int, 202)
+
+ def test_remove_floating_ip_from_instance(self):
+ body = dict(removeFloatingIp=dict(address='11.0.0.1'))
+ req = webob.Request.blank('/v1.1/servers/test_inst/action')
+ req.method = "POST"
req.body = json.dumps(body)
- req.headers['Content-Type'] = 'application/json'
- res = req.get_response(fakes.wsgi_app())
- self.assertEqual(res.status_int, 200)
- ip = json.loads(res.body)['disassociated']
- expected = {
- "floating_ip": '10.10.10.10',
- "fixed_ip": '11.0.0.1'}
- self.assertEqual(ip, expected)
+ req.headers["content-type"] = "application/json"
+
+ resp = req.get_response(fakes.wsgi_app())
+ self.assertEqual(resp.status_int, 202)
+
+ def test_bad_address_param_in_remove_floating_ip(self):
+ body = dict(removeFloatingIp=dict(badparam='11.0.0.1'))
+ req = webob.Request.blank('/v1.1/servers/test_inst/action')
+ req.method = "POST"
+ req.body = json.dumps(body)
+ req.headers["content-type"] = "application/json"
+
+ resp = req.get_response(fakes.wsgi_app())
+ self.assertEqual(resp.status_int, 400)
+
+ def test_missing_dict_param_in_remove_floating_ip(self):
+ body = dict(removeFloatingIp='11.0.0.1')
+ req = webob.Request.blank('/v1.1/servers/test_inst/action')
+ req.method = "POST"
+ req.body = json.dumps(body)
+ req.headers["content-type"] = "application/json"
+
+ resp = req.get_response(fakes.wsgi_app())
+ self.assertEqual(resp.status_int, 400)
+
+ def test_bad_address_param_in_add_floating_ip(self):
+ body = dict(addFloatingIp=dict(badparam='11.0.0.1'))
+ req = webob.Request.blank('/v1.1/servers/test_inst/action')
+ req.method = "POST"
+ req.body = json.dumps(body)
+ req.headers["content-type"] = "application/json"
+
+ resp = req.get_response(fakes.wsgi_app())
+ self.assertEqual(resp.status_int, 400)
+
+ def test_missing_dict_param_in_add_floating_ip(self):
+ body = dict(addFloatingIp='11.0.0.1')
+ req = webob.Request.blank('/v1.1/servers/test_inst/action')
+ req.method = "POST"
+ req.body = json.dumps(body)
+ req.headers["content-type"] = "application/json"
+
+ resp = req.get_response(fakes.wsgi_app())
+ self.assertEqual(resp.status_int, 400)
diff --git a/nova/tests/api/openstack/contrib/test_rescue.py b/nova/tests/api/openstack/contrib/test_rescue.py
new file mode 100644
index 000000000..fc8e4be4e
--- /dev/null
+++ b/nova/tests/api/openstack/contrib/test_rescue.py
@@ -0,0 +1,55 @@
+# Copyright 2011 OpenStack LLC.
+#
+# 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 json
+import webob
+
+from nova import compute
+from nova import test
+from nova.tests.api.openstack import fakes
+
+
+def rescue(self, context, instance_id):
+ pass
+
+
+def unrescue(self, context, instance_id):
+ pass
+
+
+class RescueTest(test.TestCase):
+ def setUp(self):
+ super(RescueTest, self).setUp()
+ self.stubs.Set(compute.api.API, "rescue", rescue)
+ self.stubs.Set(compute.api.API, "unrescue", unrescue)
+
+ def test_rescue(self):
+ body = dict(rescue=None)
+ req = webob.Request.blank('/v1.1/servers/test_inst/action')
+ req.method = "POST"
+ req.body = json.dumps(body)
+ req.headers["content-type"] = "application/json"
+
+ resp = req.get_response(fakes.wsgi_app())
+ self.assertEqual(resp.status_int, 200)
+
+ def test_unrescue(self):
+ body = dict(unrescue=None)
+ req = webob.Request.blank('/v1.1/servers/test_inst/action')
+ req.method = "POST"
+ req.body = json.dumps(body)
+ req.headers["content-type"] = "application/json"
+
+ resp = req.get_response(fakes.wsgi_app())
+ self.assertEqual(resp.status_int, 200)
diff --git a/nova/tests/api/openstack/contrib/test_virtual_interfaces.py b/nova/tests/api/openstack/contrib/test_virtual_interfaces.py
new file mode 100644
index 000000000..d541a9e95
--- /dev/null
+++ b/nova/tests/api/openstack/contrib/test_virtual_interfaces.py
@@ -0,0 +1,55 @@
+# Copyright (C) 2011 Midokura KK
+# 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 json
+import stubout
+import webob
+
+from nova import test
+from nova import compute
+from nova.tests.api.openstack import fakes
+from nova.api.openstack.contrib.virtual_interfaces import \
+ ServerVirtualInterfaceController
+
+
+def compute_api_get(self, context, server_id):
+ return {'virtual_interfaces': [
+ {'uuid': '00000000-0000-0000-0000-00000000000000000',
+ 'address': '00-00-00-00-00-00'},
+ {'uuid': '11111111-1111-1111-1111-11111111111111111',
+ 'address': '11-11-11-11-11-11'}]}
+
+
+class ServerVirtualInterfaceTest(test.TestCase):
+
+ def setUp(self):
+ super(ServerVirtualInterfaceTest, self).setUp()
+ self.controller = ServerVirtualInterfaceController()
+ self.stubs.Set(compute.api.API, "get", compute_api_get)
+
+ def tearDown(self):
+ super(ServerVirtualInterfaceTest, self).tearDown()
+
+ def test_get_virtual_interfaces_list(self):
+ req = webob.Request.blank('/v1.1/servers/1/os-virtual-interfaces')
+ res = req.get_response(fakes.wsgi_app())
+ self.assertEqual(res.status_int, 200)
+ res_dict = json.loads(res.body)
+ response = {'virtual_interfaces': [
+ {'id': '00000000-0000-0000-0000-00000000000000000',
+ 'mac_address': '00-00-00-00-00-00'},
+ {'id': '11111111-1111-1111-1111-11111111111111111',
+ 'mac_address': '11-11-11-11-11-11'}]}
+ self.assertEqual(res_dict, response)
diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py
index d11fbf788..a095dd90a 100644
--- a/nova/tests/api/openstack/fakes.py
+++ b/nova/tests/api/openstack/fakes.py
@@ -32,6 +32,7 @@ from nova import utils
from nova import wsgi
import nova.api.openstack.auth
from nova.api import openstack
+from nova.api import auth as api_auth
from nova.api.openstack import auth
from nova.api.openstack import extensions
from nova.api.openstack import versions
@@ -83,9 +84,9 @@ def wsgi_app(inner_app10=None, inner_app11=None, fake_auth=True,
ctxt = fake_auth_context
else:
ctxt = context.RequestContext('fake', 'fake')
- api10 = openstack.FaultWrapper(wsgi.InjectContext(ctxt,
+ api10 = openstack.FaultWrapper(api_auth.InjectContext(ctxt,
limits.RateLimitingMiddleware(inner_app10)))
- api11 = openstack.FaultWrapper(wsgi.InjectContext(ctxt,
+ api11 = openstack.FaultWrapper(api_auth.InjectContext(ctxt,
limits.RateLimitingMiddleware(
extensions.ExtensionMiddleware(inner_app11))))
else:
diff --git a/nova/tests/api/openstack/test_extensions.py b/nova/tests/api/openstack/test_extensions.py
index 5d3208e10..d89cb28d6 100644
--- a/nova/tests/api/openstack/test_extensions.py
+++ b/nova/tests/api/openstack/test_extensions.py
@@ -92,7 +92,9 @@ class ExtensionControllerTest(test.TestCase):
"Keypairs",
"Multinic",
"Quotas",
+ "Rescue",
"SecurityGroups",
+ "VirtualInterfaces",
"Volumes",
]
self.ext_list.sort()
diff --git a/nova/tests/api/openstack/test_image_metadata.py b/nova/tests/api/openstack/test_image_metadata.py
index 56a0932e7..21743eeef 100644
--- a/nova/tests/api/openstack/test_image_metadata.py
+++ b/nova/tests/api/openstack/test_image_metadata.py
@@ -230,7 +230,7 @@ class ImageMetaDataTest(test.TestCase):
req.body = json_string
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
- self.assertEqual(400, res.status_int)
+ self.assertEqual(413, res.status_int)
def test_too_many_metadata_items_on_put(self):
req = webob.Request.blank('/v1.1/images/3/metadata/blah')
@@ -238,4 +238,4 @@ class ImageMetaDataTest(test.TestCase):
req.body = '{"meta": {"blah": "blah"}}'
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
- self.assertEqual(400, res.status_int)
+ self.assertEqual(413, res.status_int)
diff --git a/nova/tests/api/openstack/test_server_actions.py b/nova/tests/api/openstack/test_server_actions.py
index 687a19390..80a27e30f 100644
--- a/nova/tests/api/openstack/test_server_actions.py
+++ b/nova/tests/api/openstack/test_server_actions.py
@@ -392,7 +392,7 @@ class ServerActionsTest(test.TestCase):
req.body = json.dumps(body)
req.headers["content-type"] = "application/json"
response = req.get_response(fakes.wsgi_app())
- self.assertEqual(400, response.status_int)
+ self.assertEqual(413, response.status_int)
def test_create_backup_no_name(self):
"""Name is required for backups"""
@@ -865,7 +865,7 @@ class ServerActionsTestV11(test.TestCase):
req.body = json.dumps(body)
req.headers["content-type"] = "application/json"
response = req.get_response(fakes.wsgi_app())
- self.assertEqual(400, response.status_int)
+ self.assertEqual(413, response.status_int)
def test_create_image_no_name(self):
body = {
diff --git a/nova/tests/api/openstack/test_server_metadata.py b/nova/tests/api/openstack/test_server_metadata.py
index ec446f0f0..8512bd518 100644
--- a/nova/tests/api/openstack/test_server_metadata.py
+++ b/nova/tests/api/openstack/test_server_metadata.py
@@ -417,9 +417,9 @@ class ServerMetaDataTest(test.TestCase):
req.body = json_string
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
- self.assertEqual(400, res.status_int)
+ self.assertEqual(413, res.status_int)
- def test_to_many_metadata_items_on_update_item(self):
+ def test_too_many_metadata_items_on_update_item(self):
self.stubs.Set(nova.db.api, 'instance_metadata_update',
return_create_instance_metadata_max)
req = webob.Request.blank('/v1.1/servers/1/metadata/key1')
diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py
index a510d7d97..437620854 100644
--- a/nova/tests/api/openstack/test_servers.py
+++ b/nova/tests/api/openstack/test_servers.py
@@ -3740,3 +3740,124 @@ class ServerXMLSerializationTest(test.TestCase):
""".replace(" ", "") % (locals()))
self.assertEqual(expected.toxml(), actual.toxml())
+
+ def test_update(self):
+ serializer = servers.ServerXMLSerializer()
+
+ fixture = {
+ "server": {
+ "id": 1,
+ "uuid": FAKE_UUID,
+ 'created': self.TIMESTAMP,
+ 'updated': self.TIMESTAMP,
+ "progress": 0,
+ "name": "test_server",
+ "status": "BUILD",
+ "hostId": 'e4d909c290d0fb1ca068ffaddf22cbd0',
+ "image": {
+ "id": "5",
+ "links": [
+ {
+ "rel": "bookmark",
+ "href": self.IMAGE_BOOKMARK,
+ },
+ ],
+ },
+ "flavor": {
+ "id": "1",
+ "links": [
+ {
+ "rel": "bookmark",
+ "href": self.FLAVOR_BOOKMARK,
+ },
+ ],
+ },
+ "addresses": {
+ "network_one": [
+ {
+ "version": 4,
+ "addr": "67.23.10.138",
+ },
+ {
+ "version": 6,
+ "addr": "::babe:67.23.10.138",
+ },
+ ],
+ "network_two": [
+ {
+ "version": 4,
+ "addr": "67.23.10.139",
+ },
+ {
+ "version": 6,
+ "addr": "::babe:67.23.10.139",
+ },
+ ],
+ },
+ "metadata": {
+ "Open": "Stack",
+ "Number": "1",
+ },
+ 'links': [
+ {
+ 'href': self.SERVER_HREF,
+ 'rel': 'self',
+ },
+ {
+ 'href': self.SERVER_BOOKMARK,
+ 'rel': 'bookmark',
+ },
+ ],
+ }
+ }
+
+ output = serializer.serialize(fixture, 'update')
+ actual = minidom.parseString(output.replace(" ", ""))
+
+ expected_server_href = self.SERVER_HREF
+ expected_server_bookmark = self.SERVER_BOOKMARK
+ expected_image_bookmark = self.IMAGE_BOOKMARK
+ expected_flavor_bookmark = self.FLAVOR_BOOKMARK
+ expected_now = self.TIMESTAMP
+ expected_uuid = FAKE_UUID
+ expected = minidom.parseString("""
+ <server id="1"
+ uuid="%(expected_uuid)s"
+ xmlns="http://docs.openstack.org/compute/api/v1.1"
+ xmlns:atom="http://www.w3.org/2005/Atom"
+ name="test_server"
+ updated="%(expected_now)s"
+ created="%(expected_now)s"
+ hostId="e4d909c290d0fb1ca068ffaddf22cbd0"
+ status="BUILD"
+ progress="0">
+ <atom:link href="%(expected_server_href)s" rel="self"/>
+ <atom:link href="%(expected_server_bookmark)s" rel="bookmark"/>
+ <image id="5">
+ <atom:link rel="bookmark" href="%(expected_image_bookmark)s"/>
+ </image>
+ <flavor id="1">
+ <atom:link rel="bookmark" href="%(expected_flavor_bookmark)s"/>
+ </flavor>
+ <metadata>
+ <meta key="Open">
+ Stack
+ </meta>
+ <meta key="Number">
+ 1
+ </meta>
+ </metadata>
+ <addresses>
+ <network id="network_one">
+ <ip version="4" addr="67.23.10.138"/>
+ <ip version="6" addr="::babe:67.23.10.138"/>
+ </network>
+ <network id="network_two">
+ <ip version="4" addr="67.23.10.139"/>
+ <ip version="6" addr="::babe:67.23.10.139"/>
+ </network>
+ </addresses>
+ </server>
+ """.replace(" ", "") % (locals()))
+
+ self.assertEqual(expected.toxml(), actual.toxml())
diff --git a/nova/tests/scheduler/test_abstract_scheduler.py b/nova/tests/scheduler/test_abstract_scheduler.py
index f4f5cc233..aa97e2344 100644
--- a/nova/tests/scheduler/test_abstract_scheduler.py
+++ b/nova/tests/scheduler/test_abstract_scheduler.py
@@ -77,6 +77,9 @@ class FakeZoneManager(zone_manager.ZoneManager):
'host3': {
'compute': {'host_memory_free': 3221225472},
},
+ 'host4': {
+ 'compute': {'host_memory_free': 999999999},
+ },
}
diff --git a/nova/tests/scheduler/test_host_filter.py b/nova/tests/scheduler/test_host_filter.py
index 7e664d3f9..17431fc7e 100644
--- a/nova/tests/scheduler/test_host_filter.py
+++ b/nova/tests/scheduler/test_host_filter.py
@@ -21,6 +21,7 @@ import json
from nova import exception
from nova import test
from nova.scheduler import host_filter
+from nova.scheduler import filters
class FakeZoneManager:
@@ -55,7 +56,7 @@ class HostFilterTestCase(test.TestCase):
def setUp(self):
super(HostFilterTestCase, self).setUp()
- default_host_filter = 'nova.scheduler.host_filter.AllHostsFilter'
+ default_host_filter = 'AllHostsFilter'
self.flags(default_host_filter=default_host_filter)
self.instance_type = dict(name='tiny',
memory_mb=50,
@@ -98,13 +99,10 @@ class HostFilterTestCase(test.TestCase):
def test_choose_filter(self):
# Test default filter ...
hf = host_filter.choose_host_filter()
- self.assertEquals(hf._full_name(),
- 'nova.scheduler.host_filter.AllHostsFilter')
+ self.assertEquals(hf._full_name().split(".")[-1], 'AllHostsFilter')
# Test valid filter ...
- hf = host_filter.choose_host_filter(
- 'nova.scheduler.host_filter.InstanceTypeFilter')
- self.assertEquals(hf._full_name(),
- 'nova.scheduler.host_filter.InstanceTypeFilter')
+ hf = host_filter.choose_host_filter('InstanceTypeFilter')
+ self.assertEquals(hf._full_name().split(".")[-1], 'InstanceTypeFilter')
# Test invalid filter ...
try:
host_filter.choose_host_filter('does not exist')
@@ -113,7 +111,7 @@ class HostFilterTestCase(test.TestCase):
pass
def test_all_host_filter(self):
- hf = host_filter.AllHostsFilter()
+ hf = filters.AllHostsFilter()
cooked = hf.instance_type_to_filter(self.instance_type)
hosts = hf.filter_hosts(self.zone_manager, cooked)
self.assertEquals(10, len(hosts))
@@ -121,11 +119,10 @@ class HostFilterTestCase(test.TestCase):
self.assertTrue(host.startswith('host'))
def test_instance_type_filter(self):
- hf = host_filter.InstanceTypeFilter()
+ hf = filters.InstanceTypeFilter()
# filter all hosts that can support 50 ram and 500 disk
name, cooked = hf.instance_type_to_filter(self.instance_type)
- self.assertEquals('nova.scheduler.host_filter.InstanceTypeFilter',
- name)
+ self.assertEquals(name.split(".")[-1], 'InstanceTypeFilter')
hosts = hf.filter_hosts(self.zone_manager, cooked)
self.assertEquals(6, len(hosts))
just_hosts = [host for host, caps in hosts]
@@ -134,21 +131,20 @@ class HostFilterTestCase(test.TestCase):
self.assertEquals('host10', just_hosts[5])
def test_instance_type_filter_extra_specs(self):
- hf = host_filter.InstanceTypeFilter()
+ hf = filters.InstanceTypeFilter()
# filter all hosts that can support 50 ram and 500 disk
name, cooked = hf.instance_type_to_filter(self.gpu_instance_type)
- self.assertEquals('nova.scheduler.host_filter.InstanceTypeFilter',
- name)
+ self.assertEquals(name.split(".")[-1], 'InstanceTypeFilter')
hosts = hf.filter_hosts(self.zone_manager, cooked)
self.assertEquals(1, len(hosts))
just_hosts = [host for host, caps in hosts]
self.assertEquals('host07', just_hosts[0])
def test_json_filter(self):
- hf = host_filter.JsonFilter()
+ hf = filters.JsonFilter()
# filter all hosts that can support 50 ram and 500 disk
name, cooked = hf.instance_type_to_filter(self.instance_type)
- self.assertEquals('nova.scheduler.host_filter.JsonFilter', name)
+ self.assertEquals(name.split(".")[-1], 'JsonFilter')
hosts = hf.filter_hosts(self.zone_manager, cooked)
self.assertEquals(6, len(hosts))
just_hosts = [host for host, caps in hosts]
@@ -192,7 +188,6 @@ class HostFilterTestCase(test.TestCase):
raw = ['in', '$compute.host_memory_free', 20, 40, 60, 80, 100]
cooked = json.dumps(raw)
hosts = hf.filter_hosts(self.zone_manager, cooked)
-
self.assertEquals(5, len(hosts))
just_hosts = [host for host, caps in hosts]
just_hosts.sort()
diff --git a/nova/tests/scheduler/test_least_cost_scheduler.py b/nova/tests/scheduler/test_least_cost_scheduler.py
index de7581d0a..af58de527 100644
--- a/nova/tests/scheduler/test_least_cost_scheduler.py
+++ b/nova/tests/scheduler/test_least_cost_scheduler.py
@@ -15,6 +15,7 @@
"""
Tests For Least Cost Scheduler
"""
+import copy
from nova import test
from nova.scheduler import least_cost
@@ -81,7 +82,7 @@ class LeastCostSchedulerTestCase(test.TestCase):
super(LeastCostSchedulerTestCase, self).tearDown()
def assertWeights(self, expected, num, request_spec, hosts):
- weighted = self.sched.weigh_hosts(num, request_spec, hosts)
+ weighted = self.sched.weigh_hosts("compute", request_spec, hosts)
self.assertDictListMatch(weighted, expected, approx_equal=True)
def test_no_hosts(self):
@@ -122,19 +123,24 @@ class LeastCostSchedulerTestCase(test.TestCase):
self.flags(least_cost_scheduler_cost_functions=[
'nova.scheduler.least_cost.compute_fill_first_cost_fn'],
compute_fill_first_cost_fn_weight=1)
-
num = 1
instance_type = {'memory_mb': 1024}
request_spec = {'instance_type': instance_type}
- hosts = self.sched.filter_hosts('compute', request_spec, None)
+ svc_states = self.sched.zone_manager.service_states.iteritems()
+ all_hosts = [(host, services["compute"])
+ for host, services in svc_states
+ if "compute" in services]
+ hosts = self.sched.filter_hosts('compute', request_spec, all_hosts)
expected = []
- for idx, (hostname, caps) in enumerate(hosts):
+ for idx, (hostname, services) in enumerate(hosts):
+ caps = copy.deepcopy(services["compute"])
# Costs are normalized so over 10 hosts, each host with increasing
# free ram will cost 1/N more. Since the lowest cost host has some
# free ram, we add in the 1/N for the base_cost
weight = 0.1 + (0.1 * idx)
- weight_dict = dict(weight=weight, hostname=hostname)
- expected.append(weight_dict)
+ wtd_dict = dict(hostname=hostname, weight=weight,
+ capabilities=caps)
+ expected.append(wtd_dict)
self.assertWeights(expected, num, request_spec, hosts)
diff --git a/nova/tests/test_api.py b/nova/tests/test_api.py
index 2011ae756..526d1c490 100644
--- a/nova/tests/test_api.py
+++ b/nova/tests/test_api.py
@@ -32,6 +32,7 @@ from nova import context
from nova import exception
from nova import test
from nova import wsgi
+from nova.api import auth
from nova.api import ec2
from nova.api.ec2 import apirequest
from nova.api.ec2 import cloud
@@ -199,7 +200,7 @@ class ApiEc2TestCase(test.TestCase):
# NOTE(vish): skipping the Authorizer
roles = ['sysadmin', 'netadmin']
ctxt = context.RequestContext('fake', 'fake', roles=roles)
- self.app = wsgi.InjectContext(ctxt,
+ self.app = auth.InjectContext(ctxt,
ec2.Requestify(ec2.Authorizer(ec2.Executor()),
'nova.api.ec2.cloud.CloudController'))
diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py
index b2afc53c9..0793784f8 100644
--- a/nova/tests/test_cloud.py
+++ b/nova/tests/test_cloud.py
@@ -487,6 +487,17 @@ class CloudTestCase(test.TestCase):
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)
+ result = result['reservationSet'][0]['instancesSet']
+ self.assertEqual(result[0]['instanceId'],
+ ec2utils.id_to_ec2_id(inst2.id))
+
def _block_device_mapping_create(self, instance_id, mappings):
volumes = []
for bdm in mappings:
diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py
index 0c07cbb7c..038c07f40 100644
--- a/nova/tests/test_db_api.py
+++ b/nova/tests/test_db_api.py
@@ -76,3 +76,20 @@ class DbApiTestCase(test.TestCase):
self.assertEqual(instance['id'], result['id'])
self.assertEqual(result['fixed_ips'][0]['floating_ips'][0].address,
'1.2.1.2')
+
+ def test_instance_get_all_by_filters(self):
+ args = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1'}
+ inst1 = db.instance_create(self.context, args)
+ inst2 = db.instance_create(self.context, args)
+ result = db.instance_get_all_by_filters(self.context, {})
+ self.assertTrue(2, len(result))
+
+ def test_instance_get_all_by_filters_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 = db.instance_get_all_by_filters(self.context.elevated(), {})
+ self.assertEqual(1, len(result))
+ self.assertEqual(result[0].id, inst2.id)
diff --git a/nova/tests/test_host_filter.py b/nova/tests/test_host_filter.py
deleted file mode 100644
index 3a1389a49..000000000
--- a/nova/tests/test_host_filter.py
+++ /dev/null
@@ -1,200 +0,0 @@
-# Copyright 2011 OpenStack LLC.
-# 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.
-"""
-Tests For Scheduler Host Filters.
-"""
-
-import json
-
-from nova import exception
-from nova import test
-from nova.scheduler import host_filter
-
-
-class FakeZoneManager:
- pass
-
-
-class HostFilterTestCase(test.TestCase):
- """Test case for host filters."""
-
- def _host_caps(self, multiplier):
- # Returns host capabilities in the following way:
- # host1 = memory:free 10 (100max)
- # disk:available 100 (1000max)
- # hostN = memory:free 10 + 10N
- # disk:available 100 + 100N
- # in other words: hostN has more resources than host0
- # which means ... don't go above 10 hosts.
- return {'host_name-description': 'XenServer %s' % multiplier,
- 'host_hostname': 'xs-%s' % multiplier,
- 'host_memory_total': 100,
- 'host_memory_overhead': 10,
- 'host_memory_free': 10 + multiplier * 10,
- 'host_memory_free-computed': 10 + multiplier * 10,
- 'host_other-config': {},
- 'host_ip_address': '192.168.1.%d' % (100 + multiplier),
- 'host_cpu_info': {},
- 'disk_available': 100 + multiplier * 100,
- 'disk_total': 1000,
- 'disk_used': 0,
- 'host_uuid': 'xxx-%d' % multiplier,
- 'host_name-label': 'xs-%s' % multiplier}
-
- def setUp(self):
- super(HostFilterTestCase, self).setUp()
- default_host_filter = 'nova.scheduler.host_filter.AllHostsFilter'
- self.flags(default_host_filter=default_host_filter)
- self.instance_type = dict(name='tiny',
- memory_mb=50,
- vcpus=10,
- local_gb=500,
- flavorid=1,
- swap=500,
- rxtx_quota=30000,
- rxtx_cap=200,
- extra_specs={})
-
- self.zone_manager = FakeZoneManager()
- states = {}
- for x in xrange(10):
- states['host%02d' % (x + 1)] = {'compute': self._host_caps(x)}
- self.zone_manager.service_states = states
-
- def test_choose_filter(self):
- # Test default filter ...
- hf = host_filter.choose_host_filter()
- self.assertEquals(hf._full_name(),
- 'nova.scheduler.host_filter.AllHostsFilter')
- # Test valid filter ...
- hf = host_filter.choose_host_filter(
- 'nova.scheduler.host_filter.InstanceTypeFilter')
- self.assertEquals(hf._full_name(),
- 'nova.scheduler.host_filter.InstanceTypeFilter')
- # Test invalid filter ...
- try:
- host_filter.choose_host_filter('does not exist')
- self.fail("Should not find host filter.")
- except exception.SchedulerHostFilterNotFound:
- pass
-
- def test_all_host_filter(self):
- hf = host_filter.AllHostsFilter()
- cooked = hf.instance_type_to_filter(self.instance_type)
- hosts = hf.filter_hosts(self.zone_manager, cooked)
- self.assertEquals(10, len(hosts))
- for host, capabilities in hosts:
- self.assertTrue(host.startswith('host'))
-
- def test_instance_type_filter(self):
- hf = host_filter.InstanceTypeFilter()
- # filter all hosts that can support 50 ram and 500 disk
- name, cooked = hf.instance_type_to_filter(self.instance_type)
- self.assertEquals('nova.scheduler.host_filter.InstanceTypeFilter',
- name)
- hosts = hf.filter_hosts(self.zone_manager, cooked)
- self.assertEquals(6, len(hosts))
- just_hosts = [host for host, caps in hosts]
- just_hosts.sort()
- self.assertEquals('host05', just_hosts[0])
- self.assertEquals('host10', just_hosts[5])
-
- def test_json_filter(self):
- hf = host_filter.JsonFilter()
- # filter all hosts that can support 50 ram and 500 disk
- name, cooked = hf.instance_type_to_filter(self.instance_type)
- self.assertEquals('nova.scheduler.host_filter.JsonFilter', name)
- hosts = hf.filter_hosts(self.zone_manager, cooked)
- self.assertEquals(6, len(hosts))
- just_hosts = [host for host, caps in hosts]
- just_hosts.sort()
- self.assertEquals('host05', just_hosts[0])
- self.assertEquals('host10', just_hosts[5])
-
- # Try some custom queries
-
- raw = ['or',
- ['and',
- ['<', '$compute.host_memory_free', 30],
- ['<', '$compute.disk_available', 300],
- ],
- ['and',
- ['>', '$compute.host_memory_free', 70],
- ['>', '$compute.disk_available', 700],
- ],
- ]
-
- cooked = json.dumps(raw)
- hosts = hf.filter_hosts(self.zone_manager, cooked)
-
- self.assertEquals(5, len(hosts))
- just_hosts = [host for host, caps in hosts]
- just_hosts.sort()
- for index, host in zip([1, 2, 8, 9, 10], just_hosts):
- self.assertEquals('host%02d' % index, host)
-
- raw = ['not',
- ['=', '$compute.host_memory_free', 30],
- ]
- cooked = json.dumps(raw)
- hosts = hf.filter_hosts(self.zone_manager, cooked)
-
- self.assertEquals(9, len(hosts))
- just_hosts = [host for host, caps in hosts]
- just_hosts.sort()
- for index, host in zip([1, 2, 4, 5, 6, 7, 8, 9, 10], just_hosts):
- self.assertEquals('host%02d' % index, host)
-
- raw = ['in', '$compute.host_memory_free', 20, 40, 60, 80, 100]
- cooked = json.dumps(raw)
- hosts = hf.filter_hosts(self.zone_manager, cooked)
-
- self.assertEquals(5, len(hosts))
- just_hosts = [host for host, caps in hosts]
- just_hosts.sort()
- for index, host in zip([2, 4, 6, 8, 10], just_hosts):
- self.assertEquals('host%02d' % index, host)
-
- # Try some bogus input ...
- raw = ['unknown command', ]
- cooked = json.dumps(raw)
- try:
- hf.filter_hosts(self.zone_manager, cooked)
- self.fail("Should give KeyError")
- except KeyError, e:
- pass
-
- self.assertTrue(hf.filter_hosts(self.zone_manager, json.dumps([])))
- self.assertTrue(hf.filter_hosts(self.zone_manager, json.dumps({})))
- self.assertTrue(hf.filter_hosts(self.zone_manager, json.dumps(
- ['not', True, False, True, False])))
-
- try:
- hf.filter_hosts(self.zone_manager, json.dumps(
- 'not', True, False, True, False))
- self.fail("Should give KeyError")
- except KeyError, e:
- pass
-
- self.assertFalse(hf.filter_hosts(self.zone_manager,
- json.dumps(['=', '$foo', 100])))
- self.assertFalse(hf.filter_hosts(self.zone_manager,
- json.dumps(['=', '$.....', 100])))
- self.assertFalse(hf.filter_hosts(self.zone_manager,
- json.dumps(
- ['>', ['and', ['or', ['not', ['<', ['>=', ['<=', ['in', ]]]]]]]])))
-
- self.assertFalse(hf.filter_hosts(self.zone_manager,
- json.dumps(['=', {}, ['>', '$missing....foo']])))
diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py
index 688518bb8..6a213b4f0 100644
--- a/nova/tests/test_libvirt.py
+++ b/nova/tests/test_libvirt.py
@@ -836,6 +836,7 @@ class LibvirtConnTestCase(test.TestCase):
count = (0 <= str(e.message).find('Unexpected method call'))
shutil.rmtree(os.path.join(FLAGS.instances_path, instance.name))
+ shutil.rmtree(os.path.join(FLAGS.instances_path, '_base'))
self.assertTrue(count)
diff --git a/nova/tests/test_metadata.py b/nova/tests/test_metadata.py
index bfc7a6d44..b06e5c136 100644
--- a/nova/tests/test_metadata.py
+++ b/nova/tests/test_metadata.py
@@ -23,12 +23,21 @@ import httplib
import webob
+from nova import exception
from nova import test
from nova import wsgi
from nova.api.ec2 import metadatarequesthandler
from nova.db.sqlalchemy import api
+USER_DATA_STRING = ("This is an encoded string")
+ENCODE_USER_DATA_STRING = base64.b64encode(USER_DATA_STRING)
+
+
+def return_non_existing_server_by_address(context, address):
+ raise exception.NotFound()
+
+
class MetadataTestCase(test.TestCase):
"""Test that metadata is returning proper values."""
@@ -79,3 +88,34 @@ class MetadataTestCase(test.TestCase):
self.stubs.Set(api, 'security_group_get_by_instance', sg_get)
self.assertEqual(self.request('/meta-data/security-groups'),
'default\nother')
+
+ def test_user_data_non_existing_fixed_address(self):
+ self.stubs.Set(api, 'instance_get_all_by_filters',
+ return_non_existing_server_by_address)
+ request = webob.Request.blank('/user-data')
+ request.remote_addr = "127.1.1.1"
+ response = request.get_response(self.app)
+ self.assertEqual(response.status_int, 404)
+
+ def test_user_data_none_fixed_address(self):
+ self.stubs.Set(api, 'instance_get_all_by_filters',
+ return_non_existing_server_by_address)
+ request = webob.Request.blank('/user-data')
+ request.remote_addr = None
+ response = request.get_response(self.app)
+ self.assertEqual(response.status_int, 500)
+
+ def test_user_data_invalid_url(self):
+ request = webob.Request.blank('/user-data-invalid')
+ request.remote_addr = "127.0.0.1"
+ response = request.get_response(self.app)
+ self.assertEqual(response.status_int, 404)
+
+ def test_user_data_with_use_forwarded_header(self):
+ self.instance['user_data'] = ENCODE_USER_DATA_STRING
+ self.flags(use_forwarded_for=True)
+ request = webob.Request.blank('/user-data')
+ request.remote_addr = "127.0.0.1"
+ response = request.get_response(self.app)
+ self.assertEqual(response.status_int, 200)
+ self.assertEqual(response.body, USER_DATA_STRING)
diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py
index 0ead680ee..e5c80b6f6 100644
--- a/nova/tests/test_network.py
+++ b/nova/tests/test_network.py
@@ -108,11 +108,14 @@ floating_ip_fields = {'id': 0,
vifs = [{'id': 0,
'address': 'DE:AD:BE:EF:00:00',
+ 'uuid': '00000000-0000-0000-0000-0000000000000000',
'network_id': 0,
'network': FakeModel(**networks[0]),
'instance_id': 0},
{'id': 1,
'address': 'DE:AD:BE:EF:00:01',
+ 'uuid': '00000000-0000-0000-0000-0000000000000001',
+ 'network_id': 0,
'network_id': 1,
'network': FakeModel(**networks[1]),
'instance_id': 0}]
@@ -163,6 +166,8 @@ class FlatNetworkTestCase(test.TestCase):
'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',
'should_create_vlan': False,
'should_create_bridge': False}
diff --git a/nova/tests/test_service.py b/nova/tests/test_service.py
index 8f92406ff..760b150be 100644
--- a/nova/tests/test_service.py
+++ b/nova/tests/test_service.py
@@ -205,6 +205,6 @@ class TestLauncher(test.TestCase):
def test_launch_app(self):
self.assertEquals(0, self.service.port)
launcher = service.Launcher()
- launcher.launch_service(self.service)
+ launcher.launch_server(self.service)
self.assertEquals(0, self.service.port)
launcher.stop()