summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/fakes.py6
-rw-r--r--nova/tests/api/openstack/test_api.py8
-rw-r--r--nova/tests/api/openstack/test_auth.py4
-rw-r--r--nova/tests/api/openstack/test_servers.py31
-rw-r--r--nova/tests/compute_unittest.py29
-rw-r--r--nova/tests/misc_unittest.py26
-rw-r--r--nova/tests/quota_unittest.py16
7 files changed, 75 insertions, 45 deletions
diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py
index 639a2ebe4..c3f129a32 100644
--- a/nova/tests/api/openstack/fakes.py
+++ b/nova/tests/api/openstack/fakes.py
@@ -54,7 +54,6 @@ def fake_auth_init(self):
self.db = FakeAuthDatabase()
self.context = Context()
self.auth = FakeAuthManager()
- self.host = 'foo'
@webob.dec.wsgify
@@ -68,12 +67,11 @@ def fake_wsgi(self, req):
def stub_out_key_pair_funcs(stubs):
def key_pair(context, user_id):
return [dict(name='key', public_key='public_key')]
- stubs.Set(nova.db.api, 'key_pair_get_all_by_user',
- key_pair)
+ stubs.Set(nova.db, 'key_pair_get_all_by_user', key_pair)
def stub_out_image_service(stubs):
- def fake_image_show(meh, id):
+ def fake_image_show(meh, context, id):
return dict(kernelId=1, ramdiskId=1)
stubs.Set(nova.image.local.LocalImageService, 'show', fake_image_show)
diff --git a/nova/tests/api/openstack/test_api.py b/nova/tests/api/openstack/test_api.py
index dd83991b9..d8b202e21 100644
--- a/nova/tests/api/openstack/test_api.py
+++ b/nova/tests/api/openstack/test_api.py
@@ -50,12 +50,12 @@ class APITest(unittest.TestCase):
api.application = succeed
resp = Request.blank('/').get_response(api)
- self.assertFalse('cloudServersFault' in resp.body, resp.body)
+ self.assertFalse('computeFault' in resp.body, resp.body)
self.assertEqual(resp.status_int, 200, resp.body)
api.application = raise_webob_exc
resp = Request.blank('/').get_response(api)
- self.assertFalse('cloudServersFault' in resp.body, resp.body)
+ self.assertFalse('computeFault' in resp.body, resp.body)
self.assertEqual(resp.status_int, 404, resp.body)
api.application = raise_api_fault
@@ -65,10 +65,10 @@ class APITest(unittest.TestCase):
api.application = fail
resp = Request.blank('/').get_response(api)
- self.assertTrue('{"cloudServersFault' in resp.body, resp.body)
+ self.assertTrue('{"computeFault' in resp.body, resp.body)
self.assertEqual(resp.status_int, 500, resp.body)
api.application = fail
resp = Request.blank('/.xml').get_response(api)
- self.assertTrue('<cloudServersFault' in resp.body, resp.body)
+ self.assertTrue('<computeFault' in resp.body, resp.body)
self.assertEqual(resp.status_int, 500, resp.body)
diff --git a/nova/tests/api/openstack/test_auth.py b/nova/tests/api/openstack/test_auth.py
index 29f4b8874..14e720be4 100644
--- a/nova/tests/api/openstack/test_auth.py
+++ b/nova/tests/api/openstack/test_auth.py
@@ -62,14 +62,14 @@ class Test(unittest.TestCase):
f = fakes.FakeAuthManager()
f.add_user('derp', nova.auth.manager.User(1, 'herp', None, None, None))
- req = webob.Request.blank('/v1.0/')
+ req = webob.Request.blank('/v1.0/', {'HTTP_HOST': 'foo'})
req.headers['X-Auth-User'] = 'herp'
req.headers['X-Auth-Key'] = 'derp'
result = req.get_response(nova.api.API('os'))
self.assertEqual(result.status, '204 No Content')
self.assertEqual(len(result.headers['X-Auth-Token']), 40)
self.assertEqual(result.headers['X-Server-Management-Url'],
- "https://foo/v1.0/")
+ "http://foo/v1.0/")
self.assertEqual(result.headers['X-CDN-Management-Url'],
"")
self.assertEqual(result.headers['X-Storage-Url'], "")
diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py
index 8cfc6c45a..8444b6fce 100644
--- a/nova/tests/api/openstack/test_servers.py
+++ b/nova/tests/api/openstack/test_servers.py
@@ -43,9 +43,21 @@ def return_servers(context, user_id=1):
return [stub_instance(i, user_id) for i in xrange(5)]
+def return_security_group(context, instance_id, security_group_id):
+ pass
+
+
+def instance_update(context, instance_id, kwargs):
+ return stub_instance(instance_id)
+
+
+def instance_address(context, instance_id):
+ return None
+
+
def stub_instance(id, user_id=1):
- return Instance(id=id, state=0, image_id=10, server_name='server%s' % id,
- user_id=user_id)
+ return Instance(id=id + 123456, state=0, image_id=10, user_id=user_id,
+ display_name='server%s' % id, internal_id=id)
class ServersTest(unittest.TestCase):
@@ -63,6 +75,13 @@ class ServersTest(unittest.TestCase):
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',
+ return_security_group)
+ self.stubs.Set(nova.db.api, 'instance_update', instance_update)
+ self.stubs.Set(nova.db.api, 'instance_get_fixed_address',
+ instance_address)
+ self.stubs.Set(nova.db.api, 'instance_get_floating_address',
+ instance_address)
def tearDown(self):
self.stubs.UnsetAll()
@@ -87,11 +106,11 @@ class ServersTest(unittest.TestCase):
i += 1
def test_create_instance(self):
- def server_update(context, id, params):
- pass
-
def instance_create(context, inst):
- return {'id': 1, 'internal_id': 1}
+ return {'id': 1, 'internal_id': 1, 'display_name': ''}
+
+ def server_update(context, id, params):
+ return instance_create(context, id)
def fake_method(*args, **kwargs):
pass
diff --git a/nova/tests/compute_unittest.py b/nova/tests/compute_unittest.py
index 71a1a4457..6f3ef96cb 100644
--- a/nova/tests/compute_unittest.py
+++ b/nova/tests/compute_unittest.py
@@ -31,6 +31,7 @@ from nova import flags
from nova import test
from nova import utils
from nova.auth import manager
+from nova.compute import api as compute_api
FLAGS = flags.FLAGS
@@ -43,6 +44,7 @@ class ComputeTestCase(test.TrialTestCase):
self.flags(connection_type='fake',
network_manager='nova.network.manager.FlatManager')
self.compute = utils.import_object(FLAGS.compute_manager)
+ self.compute_api = compute_api.ComputeAPI()
self.manager = manager.AuthManager()
self.user = self.manager.create_user('fake', 'fake', 'fake')
self.project = self.manager.create_project('fake', 'fake', 'fake')
@@ -66,26 +68,31 @@ class ComputeTestCase(test.TrialTestCase):
inst['ami_launch_index'] = 0
return db.instance_create(self.context, inst)['id']
+ def test_create_instance_defaults_display_name(self):
+ """Verify that an instance cannot be created without a display_name."""
+ cases = [dict(), dict(display_name=None)]
+ for instance in cases:
+ ref = self.compute_api.create_instances(self.context,
+ FLAGS.default_instance_type, None, **instance)
+ try:
+ self.assertNotEqual(ref[0].display_name, None)
+ finally:
+ db.instance_destroy(self.context, ref[0]['id'])
+
def test_create_instance_associates_security_groups(self):
- """Make sure create_instance associates security groups"""
- inst = {}
- inst['user_id'] = self.user.id
- inst['project_id'] = self.project.id
+ """Make sure create_instances associates security groups"""
values = {'name': 'default',
'description': 'default',
'user_id': self.user.id,
'project_id': self.project.id}
group = db.security_group_create(self.context, values)
- ref = self.compute.create_instance(self.context,
- security_groups=[group['id']],
- **inst)
- # reload to get groups
- instance_ref = db.instance_get(self.context, ref['id'])
+ ref = self.compute_api.create_instances(self.context,
+ FLAGS.default_instance_type, None, security_group=['default'])
try:
- self.assertEqual(len(instance_ref['security_groups']), 1)
+ self.assertEqual(len(ref[0]['security_groups']), 1)
finally:
db.security_group_destroy(self.context, group['id'])
- db.instance_destroy(self.context, instance_ref['id'])
+ db.instance_destroy(self.context, ref[0]['id'])
@defer.inlineCallbacks
def test_run_terminate(self):
diff --git a/nova/tests/misc_unittest.py b/nova/tests/misc_unittest.py
index 856060afa..667c63ad0 100644
--- a/nova/tests/misc_unittest.py
+++ b/nova/tests/misc_unittest.py
@@ -15,7 +15,6 @@
# under the License.
import os
-import subprocess
from nova import test
from nova.utils import parse_mailmap, str_dict_replace
@@ -24,18 +23,23 @@ from nova.utils import parse_mailmap, str_dict_replace
class ProjectTestCase(test.TrialTestCase):
def test_authors_up_to_date(self):
if os.path.exists('../.bzr'):
- log_cmd = subprocess.Popen(["bzr", "log", "-n0"],
- stdout=subprocess.PIPE)
- changelog = log_cmd.communicate()[0]
+ contributors = set()
+
mailmap = parse_mailmap('../.mailmap')
- contributors = set()
- for l in changelog.split('\n'):
- l = l.strip()
- if (l.startswith('author:') or l.startswith('committer:')
- and not l == 'committer: Tarmac'):
- email = l.split(' ')[-1]
- contributors.add(str_dict_replace(email, mailmap))
+ import bzrlib.workingtree
+ tree = bzrlib.workingtree.WorkingTree.open('..')
+ tree.lock_read()
+ parents = tree.get_parent_ids()
+ g = tree.branch.repository.get_graph()
+ for p in parents[1:]:
+ rev_ids = [r for r, _ in g.iter_ancestry(parents)
+ if r != "null:"]
+ revs = tree.branch.repository.get_revisions(rev_ids)
+ for r in revs:
+ for author in r.get_apparent_authors():
+ email = author.split(' ')[-1]
+ contributors.add(str_dict_replace(email, mailmap))
authors_file = open('../Authors', 'r').read()
diff --git a/nova/tests/quota_unittest.py b/nova/tests/quota_unittest.py
index b7c1d2acc..1966b51f7 100644
--- a/nova/tests/quota_unittest.py
+++ b/nova/tests/quota_unittest.py
@@ -94,11 +94,12 @@ class QuotaTestCase(test.TrialTestCase):
for i in range(FLAGS.quota_instances):
instance_id = self._create_instance()
instance_ids.append(instance_id)
- self.assertRaises(cloud.QuotaError, self.cloud.run_instances,
+ self.assertRaises(quota.QuotaError, self.cloud.run_instances,
self.context,
min_count=1,
max_count=1,
- instance_type='m1.small')
+ instance_type='m1.small',
+ image_id='fake')
for instance_id in instance_ids:
db.instance_destroy(self.context, instance_id)
@@ -106,11 +107,12 @@ class QuotaTestCase(test.TrialTestCase):
instance_ids = []
instance_id = self._create_instance(cores=4)
instance_ids.append(instance_id)
- self.assertRaises(cloud.QuotaError, self.cloud.run_instances,
+ self.assertRaises(quota.QuotaError, self.cloud.run_instances,
self.context,
min_count=1,
max_count=1,
- instance_type='m1.small')
+ instance_type='m1.small',
+ image_id='fake')
for instance_id in instance_ids:
db.instance_destroy(self.context, instance_id)
@@ -119,7 +121,7 @@ class QuotaTestCase(test.TrialTestCase):
for i in range(FLAGS.quota_volumes):
volume_id = self._create_volume()
volume_ids.append(volume_id)
- self.assertRaises(cloud.QuotaError, self.cloud.create_volume,
+ self.assertRaises(quota.QuotaError, self.cloud.create_volume,
self.context,
size=10)
for volume_id in volume_ids:
@@ -129,7 +131,7 @@ class QuotaTestCase(test.TrialTestCase):
volume_ids = []
volume_id = self._create_volume(size=20)
volume_ids.append(volume_id)
- self.assertRaises(cloud.QuotaError,
+ self.assertRaises(quota.QuotaError,
self.cloud.create_volume,
self.context,
size=10)
@@ -146,6 +148,6 @@ class QuotaTestCase(test.TrialTestCase):
# make an rpc.call, the test just finishes with OK. It
# appears to be something in the magic inline callbacks
# that is breaking.
- self.assertRaises(cloud.QuotaError, self.cloud.allocate_address,
+ self.assertRaises(quota.QuotaError, self.cloud.allocate_address,
self.context)
db.floating_ip_destroy(context.get_admin_context(), address)