summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorTushar Patil <tushar.vitthal.patil@gmail.com>2011-08-18 13:41:02 -0700
committerTushar Patil <tushar.vitthal.patil@gmail.com>2011-08-18 13:41:02 -0700
commitae3da99ae46f8966f20c0d8ee90239c376e8147f (patch)
tree05e3daff1b8c0d466a77ce56c2cd2a1d4926d1d8 /nova/tests
parent9a4b1deb5f9abdc88809ff80bccdfb503e66dccd (diff)
parentabf7e2f767e1e535f40550945af466436d0cf541 (diff)
Merged with trunk
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/contrib/test_floating_ips.py18
-rw-r--r--nova/tests/api/openstack/contrib/test_quotas.py152
-rw-r--r--nova/tests/api/openstack/test_extensions.py120
-rw-r--r--nova/tests/api/openstack/test_image_metadata.py4
-rw-r--r--nova/tests/api/openstack/test_limits.py178
-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.py3
-rw-r--r--nova/tests/integrated/test_servers.py5
-rw-r--r--nova/tests/scheduler/test_abstract_scheduler.py (renamed from nova/tests/scheduler/test_zone_aware_scheduler.py)43
-rw-r--r--nova/tests/scheduler/test_host_filter.py29
-rw-r--r--nova/tests/scheduler/test_least_cost_scheduler.py22
-rw-r--r--nova/tests/scheduler/test_scheduler.py59
-rw-r--r--nova/tests/test_compute.py97
-rw-r--r--nova/tests/test_host_filter.py200
-rw-r--r--nova/tests/test_libvirt.py195
-rw-r--r--nova/tests/test_metadata.py2
-rw-r--r--nova/tests/test_network.py72
-rw-r--r--nova/tests/xenapi/stubs.py4
19 files changed, 667 insertions, 544 deletions
diff --git a/nova/tests/api/openstack/contrib/test_floating_ips.py b/nova/tests/api/openstack/contrib/test_floating_ips.py
index ab7ae2e54..704d06582 100644
--- a/nova/tests/api/openstack/contrib/test_floating_ips.py
+++ b/nova/tests/api/openstack/contrib/test_floating_ips.py
@@ -116,14 +116,14 @@ class FloatingIpTest(test.TestCase):
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
res_dict = json.loads(res.body)
- response = {'floating_ips': [{'floating_ip': {'instance_id': 11,
- 'ip': '10.10.10.10',
- 'fixed_ip': '10.0.0.1',
- 'id': 1}},
- {'floating_ip': {'instance_id': None,
- 'ip': '10.10.10.11',
- 'fixed_ip': None,
- 'id': 2}}]}
+ response = {'floating_ips': [{'instance_id': 11,
+ 'ip': '10.10.10.10',
+ 'fixed_ip': '10.0.0.1',
+ 'id': 1},
+ {'instance_id': None,
+ 'ip': '10.10.10.11',
+ 'fixed_ip': None,
+ 'id': 2}]}
self.assertEqual(res_dict, response)
def test_floating_ip_show(self):
@@ -177,8 +177,10 @@ class FloatingIpTest(test.TestCase):
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'
+ req.body = json.dumps(body)
req.headers['Content-Type'] = 'application/json'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
diff --git a/nova/tests/api/openstack/contrib/test_quotas.py b/nova/tests/api/openstack/contrib/test_quotas.py
new file mode 100644
index 000000000..f6a25385f
--- /dev/null
+++ b/nova/tests/api/openstack/contrib/test_quotas.py
@@ -0,0 +1,152 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# 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.
+
+import json
+import webob
+
+from nova import context
+from nova import test
+from nova.tests.api.openstack import fakes
+
+from nova.api.openstack.contrib.quotas import QuotaSetsController
+
+
+def quota_set(id):
+ return {'quota_set': {'id': id, 'metadata_items': 128, 'volumes': 10,
+ 'gigabytes': 1000, 'ram': 51200, 'floating_ips': 10,
+ 'instances': 10, 'injected_files': 5, 'cores': 20,
+ 'injected_file_content_bytes': 10240}}
+
+
+def quota_set_list():
+ return {'quota_set_list': [quota_set('1234'), quota_set('5678'),
+ quota_set('update_me')]}
+
+
+class QuotaSetsTest(test.TestCase):
+
+ def setUp(self):
+ super(QuotaSetsTest, self).setUp()
+ self.controller = QuotaSetsController()
+ self.user_id = 'fake'
+ self.project_id = 'fake'
+ self.user_context = context.RequestContext(self.user_id,
+ self.project_id)
+ self.admin_context = context.RequestContext(self.user_id,
+ self.project_id,
+ is_admin=True)
+
+ def test_format_quota_set(self):
+ raw_quota_set = {
+ 'instances': 10,
+ 'cores': 20,
+ 'ram': 51200,
+ 'volumes': 10,
+ 'floating_ips': 10,
+ 'metadata_items': 128,
+ 'gigabytes': 1000,
+ 'injected_files': 5,
+ 'injected_file_content_bytes': 10240}
+
+ quota_set = QuotaSetsController()._format_quota_set('1234',
+ raw_quota_set)
+ qs = quota_set['quota_set']
+
+ self.assertEqual(qs['id'], '1234')
+ self.assertEqual(qs['instances'], 10)
+ self.assertEqual(qs['cores'], 20)
+ self.assertEqual(qs['ram'], 51200)
+ self.assertEqual(qs['volumes'], 10)
+ self.assertEqual(qs['gigabytes'], 1000)
+ self.assertEqual(qs['floating_ips'], 10)
+ self.assertEqual(qs['metadata_items'], 128)
+ self.assertEqual(qs['injected_files'], 5)
+ self.assertEqual(qs['injected_file_content_bytes'], 10240)
+
+ def test_quotas_defaults(self):
+ req = webob.Request.blank('/v1.1/os-quota-sets/fake_tenant/defaults')
+ req.method = 'GET'
+ req.headers['Content-Type'] = 'application/json'
+ res = req.get_response(fakes.wsgi_app())
+
+ self.assertEqual(res.status_int, 200)
+ expected = {'quota_set': {
+ 'id': 'fake_tenant',
+ 'instances': 10,
+ 'cores': 20,
+ 'ram': 51200,
+ 'volumes': 10,
+ 'gigabytes': 1000,
+ 'floating_ips': 10,
+ 'metadata_items': 128,
+ 'injected_files': 5,
+ 'injected_file_content_bytes': 10240}}
+
+ self.assertEqual(json.loads(res.body), expected)
+
+ def test_quotas_show_as_admin(self):
+ req = webob.Request.blank('/v1.1/os-quota-sets/1234')
+ req.method = 'GET'
+ req.headers['Content-Type'] = 'application/json'
+ res = req.get_response(fakes.wsgi_app(
+ fake_auth_context=self.admin_context))
+
+ self.assertEqual(res.status_int, 200)
+ self.assertEqual(json.loads(res.body), quota_set('1234'))
+
+ def test_quotas_show_as_unauthorized_user(self):
+ req = webob.Request.blank('/v1.1/os-quota-sets/1234')
+ req.method = 'GET'
+ req.headers['Content-Type'] = 'application/json'
+ res = req.get_response(fakes.wsgi_app(
+ fake_auth_context=self.user_context))
+
+ self.assertEqual(res.status_int, 403)
+
+ def test_quotas_update_as_admin(self):
+ updated_quota_set = {'quota_set': {'instances': 50,
+ 'cores': 50, 'ram': 51200, 'volumes': 10,
+ 'gigabytes': 1000, 'floating_ips': 10,
+ 'metadata_items': 128, 'injected_files': 5,
+ 'injected_file_content_bytes': 10240}}
+
+ req = webob.Request.blank('/v1.1/os-quota-sets/update_me')
+ req.method = 'PUT'
+ req.body = json.dumps(updated_quota_set)
+ req.headers['Content-Type'] = 'application/json'
+
+ res = req.get_response(fakes.wsgi_app(
+ fake_auth_context=self.admin_context))
+
+ self.assertEqual(json.loads(res.body), updated_quota_set)
+
+ def test_quotas_update_as_user(self):
+ updated_quota_set = {'quota_set': {'instances': 50,
+ 'cores': 50, 'ram': 51200, 'volumes': 10,
+ 'gigabytes': 1000, 'floating_ips': 10,
+ 'metadata_items': 128, 'injected_files': 5,
+ 'injected_file_content_bytes': 10240}}
+
+ req = webob.Request.blank('/v1.1/os-quota-sets/update_me')
+ req.method = 'PUT'
+ req.body = json.dumps(updated_quota_set)
+ req.headers['Content-Type'] = 'application/json'
+
+ res = req.get_response(fakes.wsgi_app(
+ fake_auth_context=self.user_context))
+
+ self.assertEqual(res.status_int, 403)
diff --git a/nova/tests/api/openstack/test_extensions.py b/nova/tests/api/openstack/test_extensions.py
index 03aa82f3d..5d3208e10 100644
--- a/nova/tests/api/openstack/test_extensions.py
+++ b/nova/tests/api/openstack/test_extensions.py
@@ -84,6 +84,18 @@ class ExtensionControllerTest(test.TestCase):
super(ExtensionControllerTest, self).setUp()
ext_path = os.path.join(os.path.dirname(__file__), "extensions")
self.flags(osapi_extensions_path=ext_path)
+ self.ext_list = [
+ "FlavorExtraSpecs",
+ "Floating_ips",
+ "Fox In Socks",
+ "Hosts",
+ "Keypairs",
+ "Multinic",
+ "Quotas",
+ "SecurityGroups",
+ "Volumes",
+ ]
+ self.ext_list.sort()
def test_list_extensions_json(self):
app = openstack.APIRouterV11()
@@ -96,12 +108,10 @@ class ExtensionControllerTest(test.TestCase):
data = json.loads(response.body)
names = [x['name'] for x in data['extensions']]
names.sort()
- self.assertEqual(names, ["FlavorExtraSpecs", "Floating_ips",
- "Fox In Socks", "Hosts", "Keypairs", "Multinic", "SecurityGroups",
- "Volumes"])
+ self.assertEqual(names, self.ext_list)
# Make sure that at least Fox in Sox is correct.
- (fox_ext,) = [
+ (fox_ext, ) = [
x for x in data['extensions'] if x['alias'] == 'FOXNSOX']
self.assertEqual(fox_ext, {
'namespace': 'http://www.fox.in.socks/api/ext/pie/v1.0',
@@ -127,9 +137,7 @@ class ExtensionControllerTest(test.TestCase):
"updated": "2011-01-22T13:25:27-06:00",
"description": "The Fox In Socks Extension",
"alias": "FOXNSOX",
- "links": [],
- },
- )
+ "links": []})
def test_list_extensions_xml(self):
app = openstack.APIRouterV11()
@@ -145,10 +153,10 @@ class ExtensionControllerTest(test.TestCase):
# Make sure we have all the extensions.
exts = root.findall('{0}extension'.format(NS))
- self.assertEqual(len(exts), 8)
+ self.assertEqual(len(exts), len(self.ext_list))
# Make sure that at least Fox in Sox is correct.
- (fox_ext,) = [x for x in exts if x.get('alias') == 'FOXNSOX']
+ (fox_ext, ) = [x for x in exts if x.get('alias') == 'FOXNSOX']
self.assertEqual(fox_ext.get('name'), 'Fox In Socks')
self.assertEqual(fox_ext.get('namespace'),
'http://www.fox.in.socks/api/ext/pie/v1.0')
@@ -220,6 +228,7 @@ class ResourceExtensionTest(test.TestCase):
class InvalidExtension(object):
+
def get_alias(self):
return "THIRD"
@@ -336,27 +345,18 @@ class ExtensionsXMLSerializerTest(test.TestCase):
def test_serialize_extenstion(self):
serializer = extensions.ExtensionsXMLSerializer()
- data = {
- 'extension': {
- 'name': 'ext1',
- 'namespace': 'http://docs.rack.com/servers/api/ext/pie/v1.0',
- 'alias': 'RS-PIE',
- 'updated': '2011-01-22T13:25:27-06:00',
- 'description': 'Adds the capability to share an image.',
- 'links': [
- {
- 'rel': 'describedby',
- 'type': 'application/pdf',
- 'href': 'http://docs.rack.com/servers/api/ext/cs.pdf',
- },
- {
- 'rel': 'describedby',
- 'type': 'application/vnd.sun.wadl+xml',
- 'href': 'http://docs.rack.com/servers/api/ext/cs.wadl',
- },
- ],
- },
- }
+ data = {'extension': {
+ 'name': 'ext1',
+ 'namespace': 'http://docs.rack.com/servers/api/ext/pie/v1.0',
+ 'alias': 'RS-PIE',
+ 'updated': '2011-01-22T13:25:27-06:00',
+ 'description': 'Adds the capability to share an image.',
+ 'links': [{'rel': 'describedby',
+ 'type': 'application/pdf',
+ 'href': 'http://docs.rack.com/servers/api/ext/cs.pdf'},
+ {'rel': 'describedby',
+ 'type': 'application/vnd.sun.wadl+xml',
+ 'href': 'http://docs.rack.com/servers/api/ext/cs.wadl'}]}}
xml = serializer.serialize(data, 'show')
print xml
@@ -378,48 +378,30 @@ class ExtensionsXMLSerializerTest(test.TestCase):
def test_serialize_extensions(self):
serializer = extensions.ExtensionsXMLSerializer()
- data = {
- "extensions": [
- {
- "name": "Public Image Extension",
- "namespace": "http://foo.com/api/ext/pie/v1.0",
- "alias": "RS-PIE",
- "updated": "2011-01-22T13:25:27-06:00",
- "description": "Adds the capability to share an image.",
- "links": [
- {
- "rel": "describedby",
+ data = {"extensions": [{
+ "name": "Public Image Extension",
+ "namespace": "http://foo.com/api/ext/pie/v1.0",
+ "alias": "RS-PIE",
+ "updated": "2011-01-22T13:25:27-06:00",
+ "description": "Adds the capability to share an image.",
+ "links": [{"rel": "describedby",
"type": "application/pdf",
- "href": "http://foo.com/api/ext/cs-pie.pdf",
- },
- {
- "rel": "describedby",
"type": "application/vnd.sun.wadl+xml",
- "href": "http://foo.com/api/ext/cs-pie.wadl",
- },
- ],
- },
- {
- "name": "Cloud Block Storage",
- "namespace": "http://foo.com/api/ext/cbs/v1.0",
- "alias": "RS-CBS",
- "updated": "2011-01-12T11:22:33-06:00",
- "description": "Allows mounting cloud block storage.",
- "links": [
- {
- "rel": "describedby",
- "type": "application/pdf",
- "href": "http://foo.com/api/ext/cs-cbs.pdf",
- },
- {
- "rel": "describedby",
+ "href": "http://foo.com/api/ext/cs-pie.pdf"},
+ {"rel": "describedby",
"type": "application/vnd.sun.wadl+xml",
- "href": "http://foo.com/api/ext/cs-cbs.wadl",
- },
- ],
- },
- ],
- }
+ "href": "http://foo.com/api/ext/cs-pie.wadl"}]},
+ {"name": "Cloud Block Storage",
+ "namespace": "http://foo.com/api/ext/cbs/v1.0",
+ "alias": "RS-CBS",
+ "updated": "2011-01-12T11:22:33-06:00",
+ "description": "Allows mounting cloud block storage.",
+ "links": [{"rel": "describedby",
+ "type": "application/pdf",
+ "href": "http://foo.com/api/ext/cs-cbs.pdf"},
+ {"rel": "describedby",
+ "type": "application/vnd.sun.wadl+xml",
+ "href": "http://foo.com/api/ext/cs-cbs.wadl"}]}]}
xml = serializer.serialize(data, 'index')
print xml
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_limits.py b/nova/tests/api/openstack/test_limits.py
index 1dc3c3a17..801b06230 100644
--- a/nova/tests/api/openstack/test_limits.py
+++ b/nova/tests/api/openstack/test_limits.py
@@ -915,86 +915,56 @@ class LimitsViewBuilderV11Test(test.TestCase):
def setUp(self):
self.view_builder = views.limits.ViewBuilderV11()
- self.rate_limits = [
- {
- "URI": "*",
- "regex": ".*",
- "value": 10,
- "verb": "POST",
- "remaining": 2,
- "unit": "MINUTE",
- "resetTime": 1311272226,
- },
- {
- "URI": "*/servers",
- "regex": "^/servers",
- "value": 50,
- "verb": "POST",
- "remaining": 10,
- "unit": "DAY",
- "resetTime": 1311272226,
- },
- ]
- self.absolute_limits = {
- "metadata_items": 1,
- "injected_files": 5,
- "injected_file_content_bytes": 5,
- }
+ self.rate_limits = [{"URI": "*",
+ "regex": ".*",
+ "value": 10,
+ "verb": "POST",
+ "remaining": 2,
+ "unit": "MINUTE",
+ "resetTime": 1311272226},
+ {"URI": "*/servers",
+ "regex": "^/servers",
+ "value": 50,
+ "verb": "POST",
+ "remaining": 10,
+ "unit": "DAY",
+ "resetTime": 1311272226}]
+ self.absolute_limits = {"metadata_items": 1,
+ "injected_files": 5,
+ "injected_file_content_bytes": 5}
def tearDown(self):
pass
def test_build_limits(self):
- expected_limits = {
- "limits": {
- "rate": [
- {
- "uri": "*",
- "regex": ".*",
- "limit": [
- {
- "value": 10,
- "verb": "POST",
- "remaining": 2,
- "unit": "MINUTE",
- "next-available": "2011-07-21T18:17:06Z",
- },
- ]
- },
- {
- "uri": "*/servers",
- "regex": "^/servers",
- "limit": [
- {
- "value": 50,
- "verb": "POST",
- "remaining": 10,
- "unit": "DAY",
- "next-available": "2011-07-21T18:17:06Z",
- },
- ]
- },
- ],
- "absolute": {
- "maxServerMeta": 1,
- "maxImageMeta": 1,
- "maxPersonality": 5,
- "maxPersonalitySize": 5
- }
- }
- }
+ expected_limits = {"limits": {
+ "rate": [{
+ "uri": "*",
+ "regex": ".*",
+ "limit": [{"value": 10,
+ "verb": "POST",
+ "remaining": 2,
+ "unit": "MINUTE",
+ "next-available": "2011-07-21T18:17:06Z"}]},
+ {"uri": "*/servers",
+ "regex": "^/servers",
+ "limit": [{"value": 50,
+ "verb": "POST",
+ "remaining": 10,
+ "unit": "DAY",
+ "next-available": "2011-07-21T18:17:06Z"}]}],
+ "absolute": {"maxServerMeta": 1,
+ "maxImageMeta": 1,
+ "maxPersonality": 5,
+ "maxPersonalitySize": 5}}}
output = self.view_builder.build(self.rate_limits,
self.absolute_limits)
self.assertDictMatch(output, expected_limits)
def test_build_limits_empty_limits(self):
- expected_limits = {
- "limits": {
- "rate": [],
- "absolute": {},
- }
- }
+ expected_limits = {"limits": {"rate": [],
+ "absolute": {}}}
abs_limits = {}
rate_limits = []
@@ -1012,45 +982,28 @@ class LimitsXMLSerializationTest(test.TestCase):
def test_index(self):
serializer = limits.LimitsXMLSerializer()
-
- fixture = {
- "limits": {
- "rate": [
- {
- "uri": "*",
- "regex": ".*",
- "limit": [
- {
- "value": 10,
- "verb": "POST",
- "remaining": 2,
- "unit": "MINUTE",
- "next-available": "2011-12-15T22:42:45Z",
- },
- ]
- },
- {
- "uri": "*/servers",
- "regex": "^/servers",
- "limit": [
- {
- "value": 50,
- "verb": "POST",
- "remaining": 10,
- "unit": "DAY",
- "next-available": "2011-12-15T22:42:45Z"
- },
- ]
- },
- ],
- "absolute": {
- "maxServerMeta": 1,
- "maxImageMeta": 1,
- "maxPersonality": 5,
- "maxPersonalitySize": 10240
- }
- }
- }
+ fixture = {"limits": {
+ "rate": [{
+ "uri": "*",
+ "regex": ".*",
+ "limit": [{
+ "value": 10,
+ "verb": "POST",
+ "remaining": 2,
+ "unit": "MINUTE",
+ "next-available": "2011-12-15T22:42:45Z"}]},
+ {"uri": "*/servers",
+ "regex": "^/servers",
+ "limit": [{
+ "value": 50,
+ "verb": "POST",
+ "remaining": 10,
+ "unit": "DAY",
+ "next-available": "2011-12-15T22:42:45Z"}]}],
+ "absolute": {"maxServerMeta": 1,
+ "maxImageMeta": 1,
+ "maxPersonality": 5,
+ "maxPersonalitySize": 10240}}}
output = serializer.serialize(fixture, 'index')
actual = minidom.parseString(output.replace(" ", ""))
@@ -1083,12 +1036,9 @@ class LimitsXMLSerializationTest(test.TestCase):
def test_index_no_limits(self):
serializer = limits.LimitsXMLSerializer()
- fixture = {
- "limits": {
- "rate": [],
- "absolute": {},
- }
- }
+ fixture = {"limits": {
+ "rate": [],
+ "absolute": {}}}
output = serializer.serialize(fixture, 'index')
actual = minidom.parseString(output.replace(" ", ""))
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 1a4288ae7..a510d7d97 100644
--- a/nova/tests/api/openstack/test_servers.py
+++ b/nova/tests/api/openstack/test_servers.py
@@ -3056,8 +3056,7 @@ class ServersViewBuilderV11Test(test.TestCase):
address_builder,
flavor_builder,
image_builder,
- base_url,
- )
+ base_url)
return view_builder
def test_build_server(self):
diff --git a/nova/tests/integrated/test_servers.py b/nova/tests/integrated/test_servers.py
index 150279a95..725f6d529 100644
--- a/nova/tests/integrated/test_servers.py
+++ b/nova/tests/integrated/test_servers.py
@@ -27,6 +27,7 @@ LOG = logging.getLogger('nova.tests.integrated')
class ServersTest(integrated_helpers._IntegratedTestBase):
+
def test_get_servers(self):
"""Simple check that listing servers works."""
servers = self.api.get_servers()
@@ -103,6 +104,10 @@ class ServersTest(integrated_helpers._IntegratedTestBase):
# It should be available...
# TODO(justinsb): Mock doesn't yet do this...
#self.assertEqual('available', found_server['status'])
+ servers = self.api.get_servers(detail=True)
+ for server in servers:
+ self.assertTrue("image" in server)
+ self.assertTrue("flavor" in server)
self._delete_server(created_server_id)
diff --git a/nova/tests/scheduler/test_zone_aware_scheduler.py b/nova/tests/scheduler/test_abstract_scheduler.py
index 788efca52..aa97e2344 100644
--- a/nova/tests/scheduler/test_zone_aware_scheduler.py
+++ b/nova/tests/scheduler/test_abstract_scheduler.py
@@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
"""
-Tests For Zone Aware Scheduler.
+Tests For Abstract Scheduler.
"""
import json
@@ -25,7 +25,7 @@ from nova import rpc
from nova import test
from nova.compute import api as compute_api
from nova.scheduler import driver
-from nova.scheduler import zone_aware_scheduler
+from nova.scheduler import abstract_scheduler
from nova.scheduler import zone_manager
@@ -60,7 +60,7 @@ def fake_zone_manager_service_states(num_hosts):
return states
-class FakeZoneAwareScheduler(zone_aware_scheduler.ZoneAwareScheduler):
+class FakeAbstractScheduler(abstract_scheduler.AbstractScheduler):
# No need to stub anything at the moment
pass
@@ -77,6 +77,9 @@ class FakeZoneManager(zone_manager.ZoneManager):
'host3': {
'compute': {'host_memory_free': 3221225472},
},
+ 'host4': {
+ 'compute': {'host_memory_free': 999999999},
+ },
}
@@ -161,15 +164,15 @@ def fake_zone_get_all(context):
]
-class ZoneAwareSchedulerTestCase(test.TestCase):
- """Test case for Zone Aware Scheduler."""
+class AbstractSchedulerTestCase(test.TestCase):
+ """Test case for Abstract Scheduler."""
- def test_zone_aware_scheduler(self):
+ def test_abstract_scheduler(self):
"""
Create a nested set of FakeZones, try to build multiple instances
and ensure that a select call returns the appropriate build plan.
"""
- sched = FakeZoneAwareScheduler()
+ sched = FakeAbstractScheduler()
self.stubs.Set(sched, '_call_zone_method', fake_call_zone_method)
self.stubs.Set(nova.db, 'zone_get_all', fake_zone_get_all)
@@ -194,7 +197,7 @@ class ZoneAwareSchedulerTestCase(test.TestCase):
properly adjusted based on the scale/offset in the zone
db entries.
"""
- sched = FakeZoneAwareScheduler()
+ sched = FakeAbstractScheduler()
child_results = fake_call_zone_method(None, None, None, None)
zones = fake_zone_get_all(None)
sched._adjust_child_weights(child_results, zones)
@@ -209,11 +212,11 @@ class ZoneAwareSchedulerTestCase(test.TestCase):
if zone == 'zone3': # Scale x1000
self.assertEqual(scaled.pop(0), w)
- def test_empty_zone_aware_scheduler(self):
+ def test_empty_abstract_scheduler(self):
"""
Ensure empty hosts & child_zones result in NoValidHosts exception.
"""
- sched = FakeZoneAwareScheduler()
+ sched = FakeAbstractScheduler()
self.stubs.Set(sched, '_call_zone_method', fake_empty_call_zone_method)
self.stubs.Set(nova.db, 'zone_get_all', fake_zone_get_all)
@@ -231,7 +234,7 @@ class ZoneAwareSchedulerTestCase(test.TestCase):
If the zone_blob hint was passed in, don't re-schedule.
"""
global was_called
- sched = FakeZoneAwareScheduler()
+ sched = FakeAbstractScheduler()
was_called = False
self.stubs.Set(sched, '_provision_resource', fake_provision_resource)
request_spec = {
@@ -248,7 +251,7 @@ class ZoneAwareSchedulerTestCase(test.TestCase):
def test_provision_resource_local(self):
"""Provision a resource locally or remotely."""
global was_called
- sched = FakeZoneAwareScheduler()
+ sched = FakeAbstractScheduler()
was_called = False
self.stubs.Set(sched, '_provision_resource_locally',
fake_provision_resource_locally)
@@ -260,7 +263,7 @@ class ZoneAwareSchedulerTestCase(test.TestCase):
def test_provision_resource_remote(self):
"""Provision a resource locally or remotely."""
global was_called
- sched = FakeZoneAwareScheduler()
+ sched = FakeAbstractScheduler()
was_called = False
self.stubs.Set(sched, '_provision_resource_from_blob',
fake_provision_resource_from_blob)
@@ -272,9 +275,9 @@ class ZoneAwareSchedulerTestCase(test.TestCase):
def test_provision_resource_from_blob_empty(self):
"""Provision a resource locally or remotely given no hints."""
global was_called
- sched = FakeZoneAwareScheduler()
+ sched = FakeAbstractScheduler()
request_spec = {}
- self.assertRaises(zone_aware_scheduler.InvalidBlob,
+ self.assertRaises(abstract_scheduler.InvalidBlob,
sched._provision_resource_from_blob,
None, {}, 1, {}, {})
@@ -283,7 +286,7 @@ class ZoneAwareSchedulerTestCase(test.TestCase):
Provision a resource locally or remotely when blob hint passed in.
"""
global was_called
- sched = FakeZoneAwareScheduler()
+ sched = FakeAbstractScheduler()
was_called = False
def fake_create_db_entry_for_new_instance(self, context,
@@ -317,7 +320,7 @@ class ZoneAwareSchedulerTestCase(test.TestCase):
passed in.
"""
global was_called
- sched = FakeZoneAwareScheduler()
+ sched = FakeAbstractScheduler()
self.stubs.Set(sched, '_decrypt_blob',
fake_decrypt_blob_returns_child_info)
was_called = False
@@ -336,7 +339,7 @@ class ZoneAwareSchedulerTestCase(test.TestCase):
from an immediate child.
"""
global was_called
- sched = FakeZoneAwareScheduler()
+ sched = FakeAbstractScheduler()
was_called = False
self.stubs.Set(sched, '_ask_child_zone_to_create_instance',
fake_ask_child_zone_to_create_instance)
@@ -350,14 +353,14 @@ class ZoneAwareSchedulerTestCase(test.TestCase):
def test_decrypt_blob(self):
"""Test that the decrypt method works."""
- fixture = FakeZoneAwareScheduler()
+ fixture = FakeAbstractScheduler()
test_data = {"foo": "bar"}
class StubDecryptor(object):
def decryptor(self, key):
return lambda blob: blob
- self.stubs.Set(zone_aware_scheduler, 'crypto',
+ self.stubs.Set(abstract_scheduler, 'crypto',
StubDecryptor())
self.assertEqual(fixture._decrypt_blob(test_data),
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 fbe6b2f77..af58de527 100644
--- a/nova/tests/scheduler/test_least_cost_scheduler.py
+++ b/nova/tests/scheduler/test_least_cost_scheduler.py
@@ -15,10 +15,11 @@
"""
Tests For Least Cost Scheduler
"""
+import copy
from nova import test
from nova.scheduler import least_cost
-from nova.tests.scheduler import test_zone_aware_scheduler
+from nova.tests.scheduler import test_abstract_scheduler
MB = 1024 * 1024
@@ -70,7 +71,7 @@ class LeastCostSchedulerTestCase(test.TestCase):
zone_manager = FakeZoneManager()
- states = test_zone_aware_scheduler.fake_zone_manager_service_states(
+ states = test_abstract_scheduler.fake_zone_manager_service_states(
num_hosts=10)
zone_manager.service_states = states
@@ -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/scheduler/test_scheduler.py b/nova/tests/scheduler/test_scheduler.py
index d70a6779f..158df2a27 100644
--- a/nova/tests/scheduler/test_scheduler.py
+++ b/nova/tests/scheduler/test_scheduler.py
@@ -257,7 +257,9 @@ class SimpleDriverTestCase(test.TestCase):
def _create_instance(self, **kwargs):
"""Create a test instance"""
inst = {}
- inst['image_id'] = 1
+ # NOTE(jk0): If an integer is passed as the image_ref, the image
+ # service will use the default image service (in this case, the fake).
+ inst['image_ref'] = '1'
inst['reservation_id'] = 'r-fakeres'
inst['user_id'] = self.user_id
inst['project_id'] = self.project_id
@@ -644,10 +646,13 @@ class SimpleDriverTestCase(test.TestCase):
self.mox.StubOutWithMock(driver_i, '_live_migration_dest_check')
self.mox.StubOutWithMock(driver_i, '_live_migration_common_check')
driver_i._live_migration_src_check(nocare, nocare)
- driver_i._live_migration_dest_check(nocare, nocare, i_ref['host'])
- driver_i._live_migration_common_check(nocare, nocare, i_ref['host'])
+ driver_i._live_migration_dest_check(nocare, nocare,
+ i_ref['host'], False)
+ driver_i._live_migration_common_check(nocare, nocare,
+ i_ref['host'], False)
self.mox.StubOutWithMock(rpc, 'cast', use_mock_anything=True)
- kwargs = {'instance_id': instance_id, 'dest': i_ref['host']}
+ kwargs = {'instance_id': instance_id, 'dest': i_ref['host'],
+ 'block_migration': False}
rpc.cast(self.context,
db.queue_get_for(nocare, FLAGS.compute_topic, i_ref['host']),
{"method": 'live_migration', "args": kwargs})
@@ -655,7 +660,8 @@ class SimpleDriverTestCase(test.TestCase):
self.mox.ReplayAll()
self.scheduler.live_migration(self.context, FLAGS.compute_topic,
instance_id=instance_id,
- dest=i_ref['host'])
+ dest=i_ref['host'],
+ block_migration=False)
i_ref = db.instance_get(self.context, instance_id)
self.assertTrue(i_ref['state_description'] == 'migrating')
@@ -736,7 +742,7 @@ class SimpleDriverTestCase(test.TestCase):
self.assertRaises(exception.ComputeServiceUnavailable,
self.scheduler.driver._live_migration_dest_check,
- self.context, i_ref, i_ref['host'])
+ self.context, i_ref, i_ref['host'], False)
db.instance_destroy(self.context, instance_id)
db.service_destroy(self.context, s_ref['id'])
@@ -749,7 +755,7 @@ class SimpleDriverTestCase(test.TestCase):
self.assertRaises(exception.UnableToMigrateToSelf,
self.scheduler.driver._live_migration_dest_check,
- self.context, i_ref, i_ref['host'])
+ self.context, i_ref, i_ref['host'], False)
db.instance_destroy(self.context, instance_id)
db.service_destroy(self.context, s_ref['id'])
@@ -757,15 +763,33 @@ class SimpleDriverTestCase(test.TestCase):
def test_live_migration_dest_check_service_lack_memory(self):
"""Confirms exception raises when dest doesn't have enough memory."""
instance_id = self._create_instance()
+ instance_id2 = self._create_instance(host='somewhere',
+ memory_mb=12)
i_ref = db.instance_get(self.context, instance_id)
- s_ref = self._create_compute_service(host='somewhere',
- memory_mb_used=12)
+ s_ref = self._create_compute_service(host='somewhere')
+
+ self.assertRaises(exception.MigrationError,
+ self.scheduler.driver._live_migration_dest_check,
+ self.context, i_ref, 'somewhere', False)
+
+ db.instance_destroy(self.context, instance_id)
+ db.instance_destroy(self.context, instance_id2)
+ db.service_destroy(self.context, s_ref['id'])
+
+ def test_block_migration_dest_check_service_lack_disk(self):
+ """Confirms exception raises when dest doesn't have enough disk."""
+ instance_id = self._create_instance()
+ instance_id2 = self._create_instance(host='somewhere',
+ local_gb=70)
+ i_ref = db.instance_get(self.context, instance_id)
+ s_ref = self._create_compute_service(host='somewhere')
self.assertRaises(exception.MigrationError,
self.scheduler.driver._live_migration_dest_check,
- self.context, i_ref, 'somewhere')
+ self.context, i_ref, 'somewhere', True)
db.instance_destroy(self.context, instance_id)
+ db.instance_destroy(self.context, instance_id2)
db.service_destroy(self.context, s_ref['id'])
def test_live_migration_dest_check_service_works_correctly(self):
@@ -777,7 +801,8 @@ class SimpleDriverTestCase(test.TestCase):
ret = self.scheduler.driver._live_migration_dest_check(self.context,
i_ref,
- 'somewhere')
+ 'somewhere',
+ False)
self.assertTrue(ret is None)
db.instance_destroy(self.context, instance_id)
db.service_destroy(self.context, s_ref['id'])
@@ -810,9 +835,10 @@ class SimpleDriverTestCase(test.TestCase):
"args": {'filename': fpath}})
self.mox.ReplayAll()
- self.assertRaises(exception.SourceHostUnavailable,
+ #self.assertRaises(exception.SourceHostUnavailable,
+ self.assertRaises(exception.FileNotFound,
self.scheduler.driver._live_migration_common_check,
- self.context, i_ref, dest)
+ self.context, i_ref, dest, False)
db.instance_destroy(self.context, instance_id)
db.service_destroy(self.context, s_ref['id'])
@@ -836,7 +862,7 @@ class SimpleDriverTestCase(test.TestCase):
self.mox.ReplayAll()
self.assertRaises(exception.InvalidHypervisorType,
self.scheduler.driver._live_migration_common_check,
- self.context, i_ref, dest)
+ self.context, i_ref, dest, False)
db.instance_destroy(self.context, instance_id)
db.service_destroy(self.context, s_ref['id'])
@@ -862,7 +888,7 @@ class SimpleDriverTestCase(test.TestCase):
self.mox.ReplayAll()
self.assertRaises(exception.DestinationHypervisorTooOld,
self.scheduler.driver._live_migration_common_check,
- self.context, i_ref, dest)
+ self.context, i_ref, dest, False)
db.instance_destroy(self.context, instance_id)
db.service_destroy(self.context, s_ref['id'])
@@ -894,7 +920,8 @@ class SimpleDriverTestCase(test.TestCase):
try:
self.scheduler.driver._live_migration_common_check(self.context,
i_ref,
- dest)
+ dest,
+ False)
except rpc.RemoteError, e:
c = (e.message.find(_("doesn't have compatibility to")) >= 0)
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index 73c9bd78d..4f5d36f14 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -632,7 +632,7 @@ class ComputeTestCase(test.TestCase):
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.ensure_filtering_rules_for_instance(i_ref, [])
self.compute.db = dbmock
self.compute.volume_manager = volmock
@@ -657,7 +657,7 @@ class ComputeTestCase(test.TestCase):
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.ensure_filtering_rules_for_instance(i_ref, [])
self.compute.db = dbmock
self.compute.driver = drivermock
@@ -714,11 +714,15 @@ class ComputeTestCase(test.TestCase):
dbmock.queue_get_for(c, FLAGS.compute_topic, i_ref['host']).\
AndReturn(topic)
rpc.call(c, topic, {"method": "pre_live_migration",
- "args": {'instance_id': i_ref['id']}})
+ "args": {'instance_id': i_ref['id'],
+ 'block_migration': False,
+ 'disk': None}})
+
self.mox.StubOutWithMock(self.compute.driver, 'live_migration')
self.compute.driver.live_migration(c, i_ref, i_ref['host'],
self.compute.post_live_migration,
- self.compute.recover_live_migration)
+ self.compute.rollback_live_migration,
+ False)
self.compute.db = dbmock
self.mox.ReplayAll()
@@ -739,13 +743,18 @@ class ComputeTestCase(test.TestCase):
dbmock.queue_get_for(c, FLAGS.compute_topic, i_ref['host']).\
AndReturn(topic)
rpc.call(c, topic, {"method": "pre_live_migration",
- "args": {'instance_id': i_ref['id']}}).\
+ "args": {'instance_id': i_ref['id'],
+ 'block_migration': False,
+ 'disk': None}}).\
AndRaise(rpc.RemoteError('', '', ''))
dbmock.instance_update(c, i_ref['id'], {'state_description': 'running',
'state': power_state.RUNNING,
'host': i_ref['host']})
for v in i_ref['volumes']:
dbmock.volume_update(c, v['id'], {'status': 'in-use'})
+ # mock for volume_api.remove_from_compute
+ rpc.call(c, topic, {"method": "remove_volume",
+ "args": {'volume_id': v['id']}})
self.compute.db = dbmock
self.mox.ReplayAll()
@@ -766,7 +775,9 @@ class ComputeTestCase(test.TestCase):
AndReturn(topic)
self.mox.StubOutWithMock(rpc, 'call')
rpc.call(c, topic, {"method": "pre_live_migration",
- "args": {'instance_id': i_ref['id']}}).\
+ "args": {'instance_id': i_ref['id'],
+ 'block_migration': False,
+ 'disk': None}}).\
AndRaise(rpc.RemoteError('', '', ''))
dbmock.instance_update(c, i_ref['id'], {'state_description': 'running',
'state': power_state.RUNNING,
@@ -791,11 +802,14 @@ class ComputeTestCase(test.TestCase):
dbmock.queue_get_for(c, FLAGS.compute_topic, i_ref['host']).\
AndReturn(topic)
rpc.call(c, topic, {"method": "pre_live_migration",
- "args": {'instance_id': i_ref['id']}})
+ "args": {'instance_id': i_ref['id'],
+ 'block_migration': False,
+ 'disk': None}})
self.mox.StubOutWithMock(self.compute.driver, 'live_migration')
self.compute.driver.live_migration(c, i_ref, i_ref['host'],
self.compute.post_live_migration,
- self.compute.recover_live_migration)
+ self.compute.rollback_live_migration,
+ False)
self.compute.db = dbmock
self.mox.ReplayAll()
@@ -829,6 +843,10 @@ class ComputeTestCase(test.TestCase):
self.compute.volume_manager.remove_compute_volume(c, v['id'])
self.mox.StubOutWithMock(self.compute.driver, 'unfilter_instance')
self.compute.driver.unfilter_instance(i_ref, [])
+ self.mox.StubOutWithMock(rpc, 'call')
+ rpc.call(c, db.queue_get_for(c, FLAGS.compute_topic, dest),
+ {"method": "post_live_migration_at_destination",
+ "args": {'instance_id': i_ref['id'], 'block_migration': False}})
# executing
self.mox.ReplayAll()
@@ -1323,6 +1341,69 @@ class ComputeTestCase(test.TestCase):
db.instance_destroy(c, instance_id2)
db.instance_destroy(c, instance_id3)
+ def test_get_all_by_metadata(self):
+ """Test searching instances by metadata"""
+
+ c = context.get_admin_context()
+ instance_id0 = self._create_instance()
+ instance_id1 = self._create_instance({
+ 'metadata': {'key1': 'value1'}})
+ instance_id2 = self._create_instance({
+ 'metadata': {'key2': 'value2'}})
+ instance_id3 = self._create_instance({
+ 'metadata': {'key3': 'value3'}})
+ instance_id4 = self._create_instance({
+ 'metadata': {'key3': 'value3',
+ 'key4': 'value4'}})
+
+ # get all instances
+ instances = self.compute_api.get_all(c,
+ search_opts={'metadata': {}})
+ self.assertEqual(len(instances), 5)
+
+ # wrong key/value combination
+ instances = self.compute_api.get_all(c,
+ search_opts={'metadata': {'key1': 'value3'}})
+ self.assertEqual(len(instances), 0)
+
+ # non-existing keys
+ instances = self.compute_api.get_all(c,
+ search_opts={'metadata': {'key5': 'value1'}})
+ self.assertEqual(len(instances), 0)
+
+ # find existing instance
+ instances = self.compute_api.get_all(c,
+ search_opts={'metadata': {'key2': 'value2'}})
+ self.assertEqual(len(instances), 1)
+ self.assertEqual(instances[0].id, instance_id2)
+
+ instances = self.compute_api.get_all(c,
+ search_opts={'metadata': {'key3': 'value3'}})
+ self.assertEqual(len(instances), 2)
+ instance_ids = [instance.id for instance in instances]
+ self.assertTrue(instance_id3 in instance_ids)
+ self.assertTrue(instance_id4 in instance_ids)
+
+ # multiple criterias as a dict
+ instances = self.compute_api.get_all(c,
+ search_opts={'metadata': {'key3': 'value3',
+ 'key4': 'value4'}})
+ self.assertEqual(len(instances), 1)
+ self.assertEqual(instances[0].id, instance_id4)
+
+ # multiple criterias as a list
+ instances = self.compute_api.get_all(c,
+ search_opts={'metadata': [{'key4': 'value4'},
+ {'key3': 'value3'}]})
+ self.assertEqual(len(instances), 1)
+ self.assertEqual(instances[0].id, instance_id4)
+
+ db.instance_destroy(c, instance_id0)
+ db.instance_destroy(c, instance_id1)
+ db.instance_destroy(c, instance_id2)
+ db.instance_destroy(c, instance_id3)
+ db.instance_destroy(c, instance_id4)
+
@staticmethod
def _parse_db_block_device_mapping(bdm_ref):
attr_list = ('delete_on_termination', 'device_name', 'no_device',
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 8bdfd71b4..688518bb8 100644
--- a/nova/tests/test_libvirt.py
+++ b/nova/tests/test_libvirt.py
@@ -21,6 +21,7 @@ import os
import re
import shutil
import sys
+import tempfile
from xml.etree.ElementTree import fromstring as xml_to_tree
from xml.dom.minidom import parseString as xml_to_dom
@@ -49,18 +50,19 @@ def _create_network_info(count=1, ipv6=None):
if ipv6 is None:
ipv6 = FLAGS.use_ipv6
fake = 'fake'
- fake_ip = '0.0.0.0/0'
- fake_ip_2 = '0.0.0.1/0'
- fake_ip_3 = '0.0.0.1/0'
+ 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': fake,
+ 'dhcp_server': '10.0.0.1',
'gateway': fake,
'gateway6': fake,
'ips': [{'ip': fake_ip}, {'ip': fake_ip}]}
@@ -273,15 +275,14 @@ class LibvirtConnTestCase(test.TestCase):
conn = connection.LibvirtConnection(True)
instance_ref = db.instance_create(self.context, self.test_instance)
- result = conn._prepare_xml_info(instance_ref, False)
- self.assertFalse(result['nics'])
-
- result = conn._prepare_xml_info(instance_ref, False,
- _create_network_info())
+ result = conn._prepare_xml_info(instance_ref,
+ _create_network_info(),
+ False)
self.assertTrue(len(result['nics']) == 1)
- result = conn._prepare_xml_info(instance_ref, False,
- _create_network_info(2))
+ result = conn._prepare_xml_info(instance_ref,
+ _create_network_info(2),
+ False)
self.assertTrue(len(result['nics']) == 2)
def test_xml_and_uri_no_ramdisk_no_kernel(self):
@@ -408,16 +409,16 @@ class LibvirtConnTestCase(test.TestCase):
network_info = _create_network_info(2)
conn = connection.LibvirtConnection(True)
instance_ref = db.instance_create(self.context, instance_data)
- xml = conn.to_xml(instance_ref, False, network_info)
+ xml = conn.to_xml(instance_ref, network_info, False)
tree = xml_to_tree(xml)
interfaces = tree.findall("./devices/interface")
self.assertEquals(len(interfaces), 2)
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'), '0.0.0.0/0')
+ self.assertEquals(parameters[0].get('value'), '10.11.12.13')
self.assertEquals(parameters[1].get('name'), 'DHCPSERVER')
- self.assertEquals(parameters[1].get('value'), 'fake')
+ self.assertEquals(parameters[1].get('value'), '10.0.0.1')
def _check_xml_and_container(self, instance):
user_context = context.RequestContext(self.user_id,
@@ -431,7 +432,8 @@ class LibvirtConnTestCase(test.TestCase):
uri = conn.get_uri()
self.assertEquals(uri, 'lxc:///')
- xml = conn.to_xml(instance_ref)
+ network_info = _create_network_info()
+ xml = conn.to_xml(instance_ref, network_info)
tree = xml_to_tree(xml)
check = [
@@ -528,17 +530,20 @@ class LibvirtConnTestCase(test.TestCase):
uri = conn.get_uri()
self.assertEquals(uri, expected_uri)
- xml = conn.to_xml(instance_ref, rescue)
+ network_info = _create_network_info()
+ xml = conn.to_xml(instance_ref, network_info, rescue)
tree = xml_to_tree(xml)
for i, (check, expected_result) in enumerate(checks):
self.assertEqual(check(tree),
expected_result,
- '%s failed check %d' % (xml, i))
+ '%s != %s failed check %d' %
+ (check(tree), expected_result, i))
for i, (check, expected_result) in enumerate(common_checks):
self.assertEqual(check(tree),
expected_result,
- '%s failed common check %d' % (xml, i))
+ '%s != %s failed common check %d' %
+ (check(tree), expected_result, i))
# This test is supposed to make sure we don't
# override a specifically set uri
@@ -623,7 +628,7 @@ class LibvirtConnTestCase(test.TestCase):
return
# Preparing mocks
- def fake_none(self):
+ def fake_none(self, *args):
return
def fake_raise(self):
@@ -640,6 +645,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()
# Start test
self.mox.ReplayAll()
@@ -649,6 +655,7 @@ class LibvirtConnTestCase(test.TestCase):
conn.firewall_driver.setattr('prepare_instance_filter', fake_none)
conn.firewall_driver.setattr('instance_filter_exists', fake_none)
conn.ensure_filtering_rules_for_instance(instance_ref,
+ network_info,
time=fake_timer)
except exception.Error, e:
c1 = (0 <= e.message.find('Timeout migrating for'))
@@ -690,17 +697,20 @@ class LibvirtConnTestCase(test.TestCase):
return vdmock
self.create_fake_libvirt_mock(lookupByName=fake_lookup)
- self.mox.StubOutWithMock(self.compute, "recover_live_migration")
- self.compute.recover_live_migration(self.context, instance_ref,
- dest='dest')
-
- # Start test
+# self.mox.StubOutWithMock(self.compute, "recover_live_migration")
+ self.mox.StubOutWithMock(self.compute, "rollback_live_migration")
+# self.compute.recover_live_migration(self.context, instance_ref,
+# dest='dest')
+ self.compute.rollback_live_migration(self.context, instance_ref,
+ 'dest', False)
+
+ #start test
self.mox.ReplayAll()
conn = connection.LibvirtConnection(False)
self.assertRaises(libvirt.libvirtError,
conn._live_migration,
- self.context, instance_ref, 'dest', '',
- self.compute.recover_live_migration)
+ self.context, instance_ref, 'dest', False,
+ self.compute.rollback_live_migration)
instance_ref = db.instance_get(self.context, instance_ref['id'])
self.assertTrue(instance_ref['state_description'] == 'running')
@@ -711,6 +721,95 @@ class LibvirtConnTestCase(test.TestCase):
db.volume_destroy(self.context, volume_ref['id'])
db.instance_destroy(self.context, instance_ref['id'])
+ def test_pre_block_migration_works_correctly(self):
+ """Confirms pre_block_migration works correctly."""
+
+ # Skip if non-libvirt environment
+ if not self.lazy_load_library_exists():
+ return
+
+ # Replace instances_path since this testcase creates tmpfile
+ tmpdir = tempfile.mkdtemp()
+ store = FLAGS.instances_path
+ FLAGS.instances_path = tmpdir
+
+ # Test data
+ instance_ref = db.instance_create(self.context, self.test_instance)
+ dummyjson = '[{"path": "%s/disk", "local_gb": "10G", "type": "raw"}]'
+
+ # Preparing mocks
+ # 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',
+ '%s/%s/disk' % (tmpdir, instance_ref.name), '10G')
+
+ self.mox.ReplayAll()
+ conn = connection.LibvirtConnection(False)
+ conn.pre_block_migration(self.context, instance_ref,
+ dummyjson % tmpdir)
+
+ self.assertTrue(os.path.exists('%s/%s/' %
+ (tmpdir, instance_ref.name)))
+
+ shutil.rmtree(tmpdir)
+ db.instance_destroy(self.context, instance_ref['id'])
+ # Restore FLAGS.instances_path
+ FLAGS.instances_path = store
+
+ def test_get_instance_disk_info_works_correctly(self):
+ """Confirms pre_block_migration works correctly."""
+ # Skip if non-libvirt environment
+ if not self.lazy_load_library_exists():
+ return
+
+ # Test data
+ instance_ref = db.instance_create(self.context, self.test_instance)
+ dummyxml = ("<domain type='kvm'><name>instance-0000000a</name>"
+ "<devices>"
+ "<disk type='file'><driver name='qemu' type='raw'/>"
+ "<source file='/test/disk'/>"
+ "<target dev='vda' bus='virtio'/></disk>"
+ "<disk type='file'><driver name='qemu' type='qcow2'/>"
+ "<source file='/test/disk.local'/>"
+ "<target dev='vdb' bus='virtio'/></disk>"
+ "</devices></domain>")
+
+ ret = ("image: /test/disk\nfile format: raw\n"
+ "virtual size: 20G (21474836480 bytes)\ndisk size: 3.1G\n")
+
+ # Preparing mocks
+ vdmock = self.mox.CreateMock(libvirt.virDomain)
+ self.mox.StubOutWithMock(vdmock, "XMLDesc")
+ vdmock.XMLDesc(0).AndReturn(dummyxml)
+
+ def fake_lookup(instance_name):
+ if instance_name == instance_ref.name:
+ return vdmock
+ self.create_fake_libvirt_mock(lookupByName=fake_lookup)
+
+ self.mox.StubOutWithMock(os.path, "getsize")
+ # based on above testdata, one is raw image, so getsize is mocked.
+ 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').\
+ AndReturn((ret, ''))
+
+ self.mox.ReplayAll()
+ conn = connection.LibvirtConnection(False)
+ info = conn.get_instance_disk_info(self.context, instance_ref)
+ info = utils.loads(info)
+
+ self.assertTrue(info[0]['type'] == 'raw' and
+ info[1]['type'] == 'qcow2' and
+ info[0]['path'] == '/test/disk' and
+ info[1]['path'] == '/test/disk.local' and
+ info[0]['local_gb'] == '10G' and
+ info[1]['local_gb'] == '20G')
+
+ db.instance_destroy(self.context, instance_ref['id'])
+
def test_spawn_with_network_info(self):
# Skip if non-libvirt environment
if not self.lazy_load_library_exists():
@@ -962,8 +1061,9 @@ class IptablesFirewallTestCase(test.TestCase):
from nova.network import linux_net
linux_net.iptables_manager.execute = fake_iptables_execute
- self.fw.prepare_instance_filter(instance_ref)
- self.fw.apply_instance_filter(instance_ref)
+ network_info = _create_network_info()
+ self.fw.prepare_instance_filter(instance_ref, network_info)
+ self.fw.apply_instance_filter(instance_ref, network_info)
in_rules = filter(lambda l: not l.startswith('#'),
self.in_filter_rules)
@@ -1033,7 +1133,7 @@ class IptablesFirewallTestCase(test.TestCase):
ipv6_len = len(self.fw.iptables.ipv6['filter'].rules)
inst_ipv4, inst_ipv6 = self.fw.instance_rules(instance_ref,
network_info)
- self.fw.add_filters_for_instance(instance_ref, network_info)
+ self.fw.prepare_instance_filter(instance_ref, network_info)
ipv4 = self.fw.iptables.ipv4['filter'].rules
ipv6 = self.fw.iptables.ipv6['filter'].rules
ipv4_network_rules = len(ipv4) - len(inst_ipv4) - ipv4_len
@@ -1048,7 +1148,7 @@ class IptablesFirewallTestCase(test.TestCase):
self.mox.StubOutWithMock(self.fw,
'add_filters_for_instance',
use_mock_anything=True)
- self.fw.add_filters_for_instance(instance_ref, mox.IgnoreArg())
+ self.fw.prepare_instance_filter(instance_ref, mox.IgnoreArg())
self.fw.instances[instance_ref['id']] = instance_ref
self.mox.ReplayAll()
self.fw.do_refresh_security_group_rules("fake")
@@ -1068,11 +1168,12 @@ class IptablesFirewallTestCase(test.TestCase):
instance_ref = self._create_instance_ref()
_setup_networking(instance_ref['id'], self.test_ip)
- self.fw.setup_basic_filtering(instance_ref)
- self.fw.prepare_instance_filter(instance_ref)
- self.fw.apply_instance_filter(instance_ref)
+ network_info = _create_network_info()
+ 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)
original_filter_count = len(fakefilter.filters)
- self.fw.unfilter_instance(instance_ref)
+ self.fw.unfilter_instance(instance_ref, network_info)
# should undefine just the instance filter
self.assertEqual(original_filter_count - len(fakefilter.filters), 1)
@@ -1082,14 +1183,14 @@ class IptablesFirewallTestCase(test.TestCase):
def test_provider_firewall_rules(self):
# setup basic instance data
instance_ref = self._create_instance_ref()
- nw_info = _create_network_info(1)
_setup_networking(instance_ref['id'], self.test_ip)
# FRAGILE: peeks at how the firewall names chains
chain_name = 'inst-%s' % instance_ref['id']
# create a firewall via setup_basic_filtering like libvirt_conn.spawn
# should have a chain with 0 rules
- self.fw.setup_basic_filtering(instance_ref, network_info=nw_info)
+ network_info = _create_network_info(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
if rule.chain == 'provider']
@@ -1119,8 +1220,8 @@ class IptablesFirewallTestCase(test.TestCase):
self.assertEqual(2, len(rules))
# create the instance filter and make sure it has a jump rule
- self.fw.prepare_instance_filter(instance_ref, network_info=nw_info)
- self.fw.apply_instance_filter(instance_ref)
+ self.fw.prepare_instance_filter(instance_ref, network_info)
+ self.fw.apply_instance_filter(instance_ref, network_info)
inst_rules = [rule for rule in self.fw.iptables.ipv4['filter'].rules
if rule.chain == chain_name]
jump_rules = [rule for rule in inst_rules if '-j' in rule.rule]
@@ -1272,7 +1373,7 @@ class NWFilterTestCase(test.TestCase):
def _ensure_all_called():
instance_filter = 'nova-instance-%s-%s' % (instance_ref['name'],
- '561212121212')
+ 'fake')
secgroup_filter = 'nova-secgroup-%s' % self.security_group['id']
for required in [secgroup_filter, 'allow-dhcp-server',
'no-arp-spoofing', 'no-ip-spoofing',
@@ -1288,9 +1389,10 @@ class NWFilterTestCase(test.TestCase):
self.security_group.id)
instance = db.instance_get(self.context, inst_id)
- self.fw.setup_basic_filtering(instance)
- self.fw.prepare_instance_filter(instance)
- self.fw.apply_instance_filter(instance)
+ network_info = _create_network_info()
+ 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()
self.teardown_security_group()
db.instance_destroy(context.get_admin_context(), instance_ref['id'])
@@ -1321,11 +1423,12 @@ class NWFilterTestCase(test.TestCase):
instance = db.instance_get(self.context, inst_id)
_setup_networking(instance_ref['id'], self.test_ip)
- self.fw.setup_basic_filtering(instance)
- self.fw.prepare_instance_filter(instance)
- self.fw.apply_instance_filter(instance)
+ network_info = _create_network_info()
+ self.fw.setup_basic_filtering(instance, network_info)
+ self.fw.prepare_instance_filter(instance, network_info)
+ self.fw.apply_instance_filter(instance, network_info)
original_filter_count = len(fakefilter.filters)
- self.fw.unfilter_instance(instance)
+ self.fw.unfilter_instance(instance, network_info)
# should undefine 2 filters: instance and instance-secgroup
self.assertEqual(original_filter_count - len(fakefilter.filters), 2)
diff --git a/nova/tests/test_metadata.py b/nova/tests/test_metadata.py
index ad678714e..bfc7a6d44 100644
--- a/nova/tests/test_metadata.py
+++ b/nova/tests/test_metadata.py
@@ -39,7 +39,7 @@ class MetadataTestCase(test.TestCase):
'key_name': None,
'host': 'test',
'launch_index': 1,
- 'instance_type': 'm1.tiny',
+ 'instance_type': {'name': 'm1.tiny'},
'reservation_id': 'r-xxxxxxxx',
'user_data': '',
'image_ref': 7,
diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py
index c673f5d06..0ead680ee 100644
--- a/nova/tests/test_network.py
+++ b/nova/tests/test_network.py
@@ -255,7 +255,7 @@ class CommonNetworkTestCase(test.TestCase):
raise exception.NetworkNotFoundForCidr()
def network_create_safe(self, context, net):
- fakenet = {}
+ fakenet = dict(net)
fakenet['id'] = 999
return fakenet
@@ -269,6 +269,9 @@ class CommonNetworkTestCase(test.TestCase):
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
@@ -286,16 +289,20 @@ class CommonNetworkTestCase(test.TestCase):
def test_validate_cidrs(self):
manager = self.FakeNetworkManager()
- nets = manager._validate_cidrs(None, '192.168.0.0/24', 1, 256)
+ nets = manager.create_networks(None, 'fake', '192.168.0.0/24',
+ False, 1, 256, None, None, None,
+ None)
self.assertEqual(1, len(nets))
- cidrs = [str(net) for net in nets]
+ cidrs = [str(net['cidr']) for net in nets]
self.assertTrue('192.168.0.0/24' in cidrs)
def test_validate_cidrs_split_exact_in_half(self):
manager = self.FakeNetworkManager()
- nets = manager._validate_cidrs(None, '192.168.0.0/24', 2, 128)
+ nets = manager.create_networks(None, 'fake', '192.168.0.0/24',
+ False, 2, 128, None, None, None,
+ None)
self.assertEqual(2, len(nets))
- cidrs = [str(net) for net in nets]
+ cidrs = [str(net['cidr']) for net in nets]
self.assertTrue('192.168.0.0/25' in cidrs)
self.assertTrue('192.168.0.128/25' in cidrs)
@@ -306,9 +313,11 @@ class CommonNetworkTestCase(test.TestCase):
manager.db.network_get_all(ctxt).AndReturn([{'id': 1,
'cidr': '192.168.2.0/24'}])
self.mox.ReplayAll()
- nets = manager._validate_cidrs(None, '192.168.0.0/16', 4, 256)
+ nets = manager.create_networks(None, 'fake', '192.168.0.0/16',
+ False, 4, 256, None, None, None,
+ None)
self.assertEqual(4, len(nets))
- cidrs = [str(net) for net in nets]
+ cidrs = [str(net['cidr']) for net in nets]
exp_cidrs = ['192.168.0.0/24', '192.168.1.0/24', '192.168.3.0/24',
'192.168.4.0/24']
for exp_cidr in exp_cidrs:
@@ -324,8 +333,9 @@ class CommonNetworkTestCase(test.TestCase):
self.mox.ReplayAll()
# ValueError: requested cidr (192.168.2.0/24) conflicts with
# existing smaller cidr
- args = [None, '192.168.2.0/24', 1, 256]
- self.assertRaises(ValueError, manager._validate_cidrs, *args)
+ args = (None, 'fake', '192.168.2.0/24', False, 1, 256, None, None,
+ None, None)
+ self.assertRaises(ValueError, manager.create_networks, *args)
def test_validate_cidrs_split_smaller_cidr_in_use(self):
manager = self.FakeNetworkManager()
@@ -334,9 +344,10 @@ class CommonNetworkTestCase(test.TestCase):
manager.db.network_get_all(ctxt).AndReturn([{'id': 1,
'cidr': '192.168.2.0/25'}])
self.mox.ReplayAll()
- nets = manager._validate_cidrs(None, '192.168.0.0/16', 4, 256)
+ nets = manager.create_networks(None, 'fake', '192.168.0.0/16',
+ False, 4, 256, None, None, None, None)
self.assertEqual(4, len(nets))
- cidrs = [str(net) for net in nets]
+ cidrs = [str(net['cidr']) for net in nets]
exp_cidrs = ['192.168.0.0/24', '192.168.1.0/24', '192.168.3.0/24',
'192.168.4.0/24']
for exp_cidr in exp_cidrs:
@@ -350,9 +361,10 @@ class CommonNetworkTestCase(test.TestCase):
manager.db.network_get_all(ctxt).AndReturn([{'id': 1,
'cidr': '192.168.2.9/29'}])
self.mox.ReplayAll()
- nets = manager._validate_cidrs(None, '192.168.2.0/24', 3, 32)
+ nets = manager.create_networks(None, 'fake', '192.168.2.0/24',
+ False, 3, 32, None, None, None, None)
self.assertEqual(3, len(nets))
- cidrs = [str(net) for net in nets]
+ cidrs = [str(net['cidr']) for net in nets]
exp_cidrs = ['192.168.2.32/27', '192.168.2.64/27', '192.168.2.96/27']
for exp_cidr in exp_cidrs:
self.assertTrue(exp_cidr in cidrs)
@@ -367,17 +379,19 @@ class CommonNetworkTestCase(test.TestCase):
{'id': 3, 'cidr': '192.168.2.128/26'}]
manager.db.network_get_all(ctxt).AndReturn(in_use)
self.mox.ReplayAll()
- args = [None, '192.168.2.0/24', 3, 64]
+ args = (None, 'fake', '192.168.2.0/24', False, 3, 64, None, None,
+ None, None)
# ValueError: Not enough subnets avail to satisfy requested num_
# networks - some subnets in requested range already
# in use
- self.assertRaises(ValueError, manager._validate_cidrs, *args)
+ self.assertRaises(ValueError, manager.create_networks, *args)
def test_validate_cidrs_one_in_use(self):
manager = self.FakeNetworkManager()
- args = [None, '192.168.0.0/24', 2, 256]
+ 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._validate_cidrs, *args)
+ self.assertRaises(ValueError, manager.create_networks, *args)
def test_validate_cidrs_already_used(self):
manager = self.FakeNetworkManager()
@@ -387,20 +401,23 @@ class CommonNetworkTestCase(test.TestCase):
'cidr': '192.168.0.0/24'}])
self.mox.ReplayAll()
# ValueError: cidr already in use
- args = [None, '192.168.0.0/24', 1, 256]
- self.assertRaises(ValueError, manager._validate_cidrs, *args)
+ args = (None, 'fake', '192.168.0.0/24', False, 1, 256, None, None,
+ None, None)
+ self.assertRaises(ValueError, manager.create_networks, *args)
def test_validate_cidrs_too_many(self):
manager = self.FakeNetworkManager()
- args = [None, '192.168.0.0/24', 200, 256]
+ args = (None, 'fake', '192.168.0.0/24', False, 200, 256, None, None,
+ None, None)
# ValueError: Not enough subnets avail to satisfy requested
# num_networks
- self.assertRaises(ValueError, manager._validate_cidrs, *args)
+ self.assertRaises(ValueError, manager.create_networks, *args)
def test_validate_cidrs_split_partial(self):
manager = self.FakeNetworkManager()
- nets = manager._validate_cidrs(None, '192.168.0.0/16', 2, 256)
- returned_cidrs = [str(net) for net in nets]
+ 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]
self.assertTrue('192.168.0.0/24' in returned_cidrs)
self.assertTrue('192.168.1.0/24' in returned_cidrs)
@@ -411,10 +428,11 @@ class CommonNetworkTestCase(test.TestCase):
fakecidr = [{'id': 1, 'cidr': '192.168.0.0/8'}]
manager.db.network_get_all(ctxt).AndReturn(fakecidr)
self.mox.ReplayAll()
- args = [None, '192.168.0.0/24', 1, 256]
+ args = (None, 'fake', '192.168.0.0/24', False, 1, 256, None, None,
+ None, None)
# ValueError: requested cidr (192.168.0.0/24) conflicts
# with existing supernet
- self.assertRaises(ValueError, manager._validate_cidrs, *args)
+ self.assertRaises(ValueError, manager.create_networks, *args)
def test_create_networks(self):
cidr = '192.168.0.0/24'
@@ -424,7 +442,7 @@ class CommonNetworkTestCase(test.TestCase):
args = [None, 'foo', cidr, None, 1, 256, 'fd00::/48', None, None,
None]
result = manager.create_networks(*args)
- self.assertEqual(manager.create_networks(*args), None)
+ self.assertTrue(manager.create_networks(*args))
def test_create_networks_cidr_already_used(self):
manager = self.FakeNetworkManager()
@@ -444,4 +462,4 @@ class CommonNetworkTestCase(test.TestCase):
self.fake_create_fixed_ips)
args = [None, 'foo', cidr, None, 10, 256, 'fd00::/48', None, None,
None]
- self.assertEqual(manager.create_networks(*args), None)
+ self.assertTrue(manager.create_networks(*args))
diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py
index 0d0f84e32..a6a1febd6 100644
--- a/nova/tests/xenapi/stubs.py
+++ b/nova/tests/xenapi/stubs.py
@@ -28,10 +28,10 @@ from nova import utils
def stubout_instance_snapshot(stubs):
@classmethod
- def fake_fetch_image(cls, context, session, instance_id, image, user,
+ def fake_fetch_image(cls, context, session, instance, image, user,
project, type):
from nova.virt.xenapi.fake import create_vdi
- name_label = "instance-%s" % instance_id
+ name_label = "instance-%s" % instance.id
#TODO: create fake SR record
sr_ref = "fakesr"
vdi_ref = create_vdi(name_label=name_label, read_only=False,