summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorJosh Kearney <josh.kearney@rackspace.com>2011-01-31 09:23:57 -0600
committerJosh Kearney <josh.kearney@rackspace.com>2011-01-31 09:23:57 -0600
commit87932046edbc01f99460c1745e8ea6dd4590955a (patch)
tree8fc28883bc554ab6302a2f607f0a41bbb11ef5fd /nova/tests
parent134421176e011d815a06d421f9475fc04468a1e1 (diff)
parent1cd4dfe34acaec06c96925c7903a9d8dc25fe34f (diff)
Merged trunk
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/test_images.py1
-rw-r--r--nova/tests/api/openstack/test_servers.py2
-rw-r--r--nova/tests/db/nova.austin.sqlitebin0 -> 44032 bytes
-rw-r--r--nova/tests/test_api.py34
-rw-r--r--nova/tests/test_localization.py100
-rw-r--r--nova/tests/test_virt.py20
6 files changed, 149 insertions, 8 deletions
diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py
index 5d9ddefbe..8ab4d7569 100644
--- a/nova/tests/api/openstack/test_images.py
+++ b/nova/tests/api/openstack/test_images.py
@@ -143,6 +143,7 @@ class LocalImageServiceTest(unittest.TestCase,
def tearDown(self):
self.service.delete_all()
+ self.service.delete_imagedir()
self.stubs.UnsetAll()
diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py
index 29883e7c8..724f14f19 100644
--- a/nova/tests/api/openstack/test_servers.py
+++ b/nova/tests/api/openstack/test_servers.py
@@ -76,7 +76,7 @@ class ServersTest(unittest.TestCase):
fakes.stub_out_key_pair_funcs(self.stubs)
fakes.stub_out_image_service(self.stubs)
self.stubs.Set(nova.db.api, 'instance_get_all', return_servers)
- self.stubs.Set(nova.db.api, 'instance_get_by_id', return_server)
+ self.stubs.Set(nova.db.api, 'instance_get', return_server)
self.stubs.Set(nova.db.api, 'instance_get_all_by_user',
return_servers)
self.stubs.Set(nova.db.api, 'instance_add_security_group',
diff --git a/nova/tests/db/nova.austin.sqlite b/nova/tests/db/nova.austin.sqlite
new file mode 100644
index 000000000..ad1326bce
--- /dev/null
+++ b/nova/tests/db/nova.austin.sqlite
Binary files differ
diff --git a/nova/tests/test_api.py b/nova/tests/test_api.py
index 66a16b0cb..2569e262b 100644
--- a/nova/tests/test_api.py
+++ b/nova/tests/test_api.py
@@ -36,6 +36,7 @@ from nova.auth import manager
class FakeHttplibSocket(object):
"""a fake socket implementation for httplib.HTTPResponse, trivial"""
def __init__(self, response_string):
+ self.response_string = response_string
self._buffer = StringIO.StringIO(response_string)
def makefile(self, _mode, _other):
@@ -66,13 +67,16 @@ class FakeHttplibConnection(object):
# For some reason, the response doesn't have "HTTP/1.0 " prepended; I
# guess that's a function the web server usually provides.
resp = "HTTP/1.0 %s" % resp
- sock = FakeHttplibSocket(resp)
- self.http_response = httplib.HTTPResponse(sock)
+ self.sock = FakeHttplibSocket(resp)
+ self.http_response = httplib.HTTPResponse(self.sock)
self.http_response.begin()
def getresponse(self):
return self.http_response
+ def getresponsebody(self):
+ return self.sock.response_string
+
def close(self):
"""Required for compatibility with boto/tornado"""
pass
@@ -104,7 +108,7 @@ class ApiEc2TestCase(test.TestCase):
self.app = ec2.Authenticate(ec2.Requestify(ec2.Executor(),
'nova.api.ec2.cloud.CloudController'))
- def expect_http(self, host=None, is_secure=False):
+ def expect_http(self, host=None, is_secure=False, api_version=None):
"""Returns a new EC2 connection"""
self.ec2 = boto.connect_ec2(
aws_access_key_id='fake',
@@ -113,13 +117,31 @@ class ApiEc2TestCase(test.TestCase):
region=regioninfo.RegionInfo(None, 'test', self.host),
port=8773,
path='/services/Cloud')
+ if api_version:
+ self.ec2.APIVersion = api_version
self.mox.StubOutWithMock(self.ec2, 'new_http_connection')
- http = FakeHttplibConnection(
+ self.http = FakeHttplibConnection(
self.app, '%s:8773' % (self.host), False)
# pylint: disable-msg=E1103
- self.ec2.new_http_connection(host, is_secure).AndReturn(http)
- return http
+ self.ec2.new_http_connection(host, is_secure).AndReturn(self.http)
+ return self.http
+
+ def test_xmlns_version_matches_request_version(self):
+ self.expect_http(api_version='2010-10-30')
+ self.mox.ReplayAll()
+
+ user = self.manager.create_user('fake', 'fake', 'fake')
+ project = self.manager.create_project('fake', 'fake', 'fake')
+
+ # Any request should be fine
+ self.ec2.get_all_instances()
+ self.assertTrue(self.ec2.APIVersion in self.http.getresponsebody(),
+ 'The version in the xmlns of the response does '
+ 'not match the API version given in the request.')
+
+ self.manager.delete_project(project)
+ self.manager.delete_user(user)
def test_describe_instances(self):
"""Test that, after creating a user and a project, the describe
diff --git a/nova/tests/test_localization.py b/nova/tests/test_localization.py
new file mode 100644
index 000000000..6992773f5
--- /dev/null
+++ b/nova/tests/test_localization.py
@@ -0,0 +1,100 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+#
+# 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 glob
+import logging
+import os
+import re
+import sys
+import unittest
+
+import nova
+
+
+class LocalizationTestCase(unittest.TestCase):
+ def test_multiple_positional_format_placeholders(self):
+ pat = re.compile("\W_\(")
+ single_pat = re.compile("\W%\W")
+ root_path = os.path.dirname(nova.__file__)
+ problems = {}
+ for root, dirs, files in os.walk(root_path):
+ for fname in files:
+ if not fname.endswith(".py"):
+ continue
+ pth = os.path.join(root, fname)
+ txt = fulltext = file(pth).read()
+ txt_lines = fulltext.splitlines()
+ if not pat.search(txt):
+ continue
+ problems[pth] = []
+ pos = txt.find("_(")
+ while pos > -1:
+ # Make sure that this isn't part of a dunder;
+ # e.g., __init__(...
+ # or something like 'self.assert_(...'
+ test_txt = txt[pos - 1: pos + 10]
+ if not (pat.search(test_txt)):
+ txt = txt[pos + 2:]
+ pos = txt.find("_(")
+ continue
+ pos += 2
+ txt = txt[pos:]
+ innerChars = []
+ # Count pairs of open/close parens until _() closing
+ # paren is found.
+ parenCount = 1
+ pos = 0
+ while parenCount > 0:
+ char = txt[pos]
+ if char == "(":
+ parenCount += 1
+ elif char == ")":
+ parenCount -= 1
+ innerChars.append(char)
+ pos += 1
+ inner_all = "".join(innerChars)
+ # Filter out '%%' and '%('
+ inner = inner_all.replace("%%", "").replace("%(", "")
+ # Filter out the single '%' operators
+ inner = single_pat.sub("", inner)
+ # Within the remaining content, count %
+ fmtCount = inner.count("%")
+ if fmtCount > 1:
+ inner_first = inner_all.splitlines()[0]
+ lns = ["%s" % (p + 1)
+ for p, t in enumerate(txt_lines)
+ if inner_first in t]
+ lnums = ", ".join(lns)
+ # Using ugly string concatenation to avoid having
+ # this test fail itself.
+ inner_all = "_" + "(" + "%s" % inner_all
+ problems[pth].append("Line: %s Text: %s" %
+ (lnums, inner_all))
+ # Look for more
+ pos = txt.find("_(")
+ if not problems[pth]:
+ del problems[pth]
+ if problems:
+ out = ["Problem(s) found in localized string formatting",
+ "(see http://www.gnu.org/software/hello/manual/"
+ "gettext/Python.html for more information)",
+ "",
+ " ------------ Files to fix ------------"]
+ for pth in problems:
+ out.append(" %s:" % pth)
+ for val in set(problems[pth]):
+ out.append(" %s" % val)
+ raise AssertionError("\n".join(out))
diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py
index 0b9b847a0..6e5a0114b 100644
--- a/nova/tests/test_virt.py
+++ b/nova/tests/test_virt.py
@@ -221,7 +221,12 @@ class IptablesFirewallTestCase(test.TestCase):
self.project = self.manager.create_project('fake', 'fake', 'fake')
self.context = context.RequestContext('fake', 'fake')
self.network = utils.import_object(FLAGS.network_manager)
- self.fw = libvirt_conn.IptablesFirewallDriver()
+
+ class FakeLibvirtConnection(object):
+ pass
+ self.fake_libvirt_connection = FakeLibvirtConnection()
+ self.fw = libvirt_conn.IptablesFirewallDriver(
+ get_connection=lambda: self.fake_libvirt_connection)
def tearDown(self):
self.manager.delete_project(self.project)
@@ -474,6 +479,19 @@ class NWFilterTestCase(test.TestCase):
'project_id': 'fake'})
inst_id = instance_ref['id']
+ ip = '10.11.12.13'
+
+ network_ref = db.project_get_network(self.context,
+ 'fake')
+
+ fixed_ip = {'address': ip,
+ 'network_id': network_ref['id']}
+
+ admin_ctxt = context.get_admin_context()
+ db.fixed_ip_create(admin_ctxt, fixed_ip)
+ db.fixed_ip_update(admin_ctxt, ip, {'allocated': True,
+ 'instance_id': instance_ref['id']})
+
def _ensure_all_called():
instance_filter = 'nova-instance-%s' % instance_ref['name']
secgroup_filter = 'nova-secgroup-%s' % self.security_group['id']