summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorRyu Ishimoto <ryu@midokura.jp>2011-08-19 10:22:24 +0900
committerRyu Ishimoto <ryu@midokura.jp>2011-08-19 10:22:24 +0900
commit93bf9b46a8ca28063752bc9e6c14ed59e91c50a9 (patch)
treeaf112b10f3e1a352afea8eea25cdcd59d9ce87b9 /nova/tests
parent54883a4ca07fe6b2f966a604f84e1127477d9a55 (diff)
parent862dc7acaf86bcfaebfce423c8198ea18b5e07c4 (diff)
Merged trunk
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/contrib/test_rescue.py55
-rw-r--r--nova/tests/api/openstack/test_extensions.py3
-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_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_service.py2
15 files changed, 281 insertions, 231 deletions
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/test_extensions.py b/nova/tests/api/openstack/test_extensions.py
index 0207487ef..d89cb28d6 100644
--- a/nova/tests/api/openstack/test_extensions.py
+++ b/nova/tests/api/openstack/test_extensions.py
@@ -92,9 +92,10 @@ class ExtensionControllerTest(test.TestCase):
"Keypairs",
"Multinic",
"Quotas",
+ "Rescue",
"SecurityGroups",
- "Volumes",
"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_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_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()