Fixed the blocking unittest issues.

1. Fixed the bug #1153921 introduced by the nova changeset
https://github.com/openstack/nova/commit/bd5a9b87.

2. Adapted to the latest keystoneclient middleware change introduced by
https://github.com/openstack/python-keystoneclient/commit/d782a998.

We must explicit set auth_version to prevent the middleware to
automatically detect its api version from remote keystone server in
unittest.

Change-Id: I439a74a7f9a8a62369ae50dc1d5e50e20f4d3574
This commit is contained in:
Lianhao Lu 2013-03-12 14:38:21 +08:00
parent e7fc028e2b
commit d4eb73682c
4 changed files with 15 additions and 5 deletions

View File

@ -27,6 +27,7 @@ from oslo.config import cfg
import pecan import pecan
import pecan.testing import pecan.testing
from ceilometer.api import acl
from ceilometer.api.v1 import app as v1_app from ceilometer.api.v1 import app as v1_app
from ceilometer.api.v1 import blueprint as v1_blueprint from ceilometer.api.v1 import blueprint as v1_blueprint
from ceilometer import storage from ceilometer import storage
@ -40,6 +41,7 @@ class TestBase(db_test_base.TestBase):
def setUp(self): def setUp(self):
super(TestBase, self).setUp() super(TestBase, self).setUp()
cfg.CONF.set_override("auth_version", "v2.0", group=acl.OPT_GROUP_NAME)
self.app = v1_app.make_app(cfg.CONF, self.app = v1_app.make_app(cfg.CONF,
enable_acl=False, enable_acl=False,
attach_storage=False) attach_storage=False)
@ -79,6 +81,7 @@ class FunctionalTest(db_test_base.TestBase):
def setUp(self): def setUp(self):
super(FunctionalTest, self).setUp() super(FunctionalTest, self).setUp()
cfg.CONF.set_override("auth_version", "v2.0", group=acl.OPT_GROUP_NAME)
self.app = self._make_app() self.app = self._make_app()
def _make_app(self, enable_acl=False): def _make_app(self, enable_acl=False):

View File

@ -39,14 +39,15 @@ from stevedore.tests import manager as test_manager
## alphabetical order, but they are in the order that actually ## alphabetical order, but they are in the order that actually
## works. Please don't change them. ## works. Please don't change them.
from nova import config
from nova import db
from nova import context
from nova.tests import fake_network
from nova.compute import vm_states from nova.compute import vm_states
from nova.openstack.common.notifier import api as notifier_api from nova.compute import instance_types
from nova import config
from nova import context
from nova import db
from nova.openstack.common import importutils from nova.openstack.common import importutils
from nova.openstack.common import log as logging from nova.openstack.common import log as logging
from nova.openstack.common.notifier import api as notifier_api
from nova.tests import fake_network
# For nova_CONF.compute_manager, used in the nova_notifier module. # For nova_CONF.compute_manager, used in the nova_notifier module.
from nova import service from nova import service
@ -136,6 +137,8 @@ class TestNovaNotifier(base.TestCase):
self.stubs.Set(db, 'instance_update_and_get_original', self.stubs.Set(db, 'instance_update_and_get_original',
lambda context, uuid, kwargs: (self.instance, lambda context, uuid, kwargs: (self.instance,
self.instance)) self.instance))
self.stubs.Set(instance_types, 'extract_instance_type',
lambda ref: {})
# Set up to capture the notification messages generated by the # Set up to capture the notification messages generated by the
# plugin and to invoke our notifier plugin. # plugin and to invoke our notifier plugin.

View File

@ -36,6 +36,7 @@ class TestApp(unittest.TestCase):
def test_keystone_middleware_conf(self): def test_keystone_middleware_conf(self):
cfg.CONF.set_override("auth_protocol", "foottp", cfg.CONF.set_override("auth_protocol", "foottp",
group=acl.OPT_GROUP_NAME) group=acl.OPT_GROUP_NAME)
cfg.CONF.set_override("auth_version", "v2.0", group=acl.OPT_GROUP_NAME)
api_app = app.make_app(cfg.CONF, attach_storage=False) api_app = app.make_app(cfg.CONF, attach_storage=False)
self.assertEqual(api_app.wsgi_app.auth_protocol, 'foottp') self.assertEqual(api_app.wsgi_app.auth_protocol, 'foottp')
@ -43,6 +44,7 @@ class TestApp(unittest.TestCase):
tmpfile = tempfile.mktemp() tmpfile = tempfile.mktemp()
with open(tmpfile, "w") as f: with open(tmpfile, "w") as f:
f.write("[%s]\nauth_protocol = barttp" % acl.OPT_GROUP_NAME) f.write("[%s]\nauth_protocol = barttp" % acl.OPT_GROUP_NAME)
f.write("\nauth_version = v2.0")
service.prepare_service(['ceilometer-api', service.prepare_service(['ceilometer-api',
'--config-file=%s' % tmpfile]) '--config-file=%s' % tmpfile])
api_app = app.make_app(cfg.CONF, attach_storage=False) api_app = app.make_app(cfg.CONF, attach_storage=False)

View File

@ -36,6 +36,7 @@ class TestApp(unittest.TestCase):
def test_keystone_middleware_conf(self): def test_keystone_middleware_conf(self):
cfg.CONF.set_override("auth_protocol", "foottp", cfg.CONF.set_override("auth_protocol", "foottp",
group=acl.OPT_GROUP_NAME) group=acl.OPT_GROUP_NAME)
cfg.CONF.set_override("auth_version", "v2.0", group=acl.OPT_GROUP_NAME)
api_app = app.setup_app() api_app = app.setup_app()
self.assertEqual(api_app.auth_protocol, 'foottp') self.assertEqual(api_app.auth_protocol, 'foottp')
@ -43,6 +44,7 @@ class TestApp(unittest.TestCase):
tmpfile = tempfile.mktemp() tmpfile = tempfile.mktemp()
with open(tmpfile, "w") as f: with open(tmpfile, "w") as f:
f.write("[%s]\nauth_protocol = barttp" % acl.OPT_GROUP_NAME) f.write("[%s]\nauth_protocol = barttp" % acl.OPT_GROUP_NAME)
f.write("\nauth_version = v2.0")
service.prepare_service(['ceilometer-api', service.prepare_service(['ceilometer-api',
'--config-file=%s' % tmpfile]) '--config-file=%s' % tmpfile])
api_app = app.setup_app() api_app = app.setup_app()