From d4eb73682c57f5830a2113f7da5c479dcbb1c8e8 Mon Sep 17 00:00:00 2001
From: Lianhao Lu <lianhao.lu@intel.com>
Date: Tue, 12 Mar 2013 14:38:21 +0800
Subject: [PATCH] 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
---
 ceilometer/tests/api.py    |  3 +++
 nova_tests/test_grizzly.py | 13 ++++++++-----
 tests/api/v1/test_app.py   |  2 ++
 tests/api/v2/test_app.py   |  2 ++
 4 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/ceilometer/tests/api.py b/ceilometer/tests/api.py
index 33692aac2..36b377e36 100644
--- a/ceilometer/tests/api.py
+++ b/ceilometer/tests/api.py
@@ -27,6 +27,7 @@ from oslo.config import cfg
 import pecan
 import pecan.testing
 
+from ceilometer.api import acl
 from ceilometer.api.v1 import app as v1_app
 from ceilometer.api.v1 import blueprint as v1_blueprint
 from ceilometer import storage
@@ -40,6 +41,7 @@ class TestBase(db_test_base.TestBase):
 
     def setUp(self):
         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,
                                    enable_acl=False,
                                    attach_storage=False)
@@ -79,6 +81,7 @@ class FunctionalTest(db_test_base.TestBase):
 
     def setUp(self):
         super(FunctionalTest, self).setUp()
+        cfg.CONF.set_override("auth_version", "v2.0", group=acl.OPT_GROUP_NAME)
         self.app = self._make_app()
 
     def _make_app(self, enable_acl=False):
diff --git a/nova_tests/test_grizzly.py b/nova_tests/test_grizzly.py
index e742a055a..b611590bc 100644
--- a/nova_tests/test_grizzly.py
+++ b/nova_tests/test_grizzly.py
@@ -39,14 +39,15 @@ from stevedore.tests import manager as test_manager
 ## alphabetical order, but they are in the order that actually
 ## 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.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 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.
 from nova import service
@@ -136,6 +137,8 @@ class TestNovaNotifier(base.TestCase):
         self.stubs.Set(db, 'instance_update_and_get_original',
                        lambda context, uuid, kwargs: (self.instance,
                                                       self.instance))
+        self.stubs.Set(instance_types, 'extract_instance_type',
+                       lambda ref: {})
 
         # Set up to capture the notification messages generated by the
         # plugin and to invoke our notifier plugin.
diff --git a/tests/api/v1/test_app.py b/tests/api/v1/test_app.py
index e64c20b83..c38356ac1 100644
--- a/tests/api/v1/test_app.py
+++ b/tests/api/v1/test_app.py
@@ -36,6 +36,7 @@ class TestApp(unittest.TestCase):
     def test_keystone_middleware_conf(self):
         cfg.CONF.set_override("auth_protocol", "foottp",
                               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)
         self.assertEqual(api_app.wsgi_app.auth_protocol, 'foottp')
 
@@ -43,6 +44,7 @@ class TestApp(unittest.TestCase):
         tmpfile = tempfile.mktemp()
         with open(tmpfile, "w") as f:
             f.write("[%s]\nauth_protocol = barttp" % acl.OPT_GROUP_NAME)
+            f.write("\nauth_version = v2.0")
         service.prepare_service(['ceilometer-api',
                                  '--config-file=%s' % tmpfile])
         api_app = app.make_app(cfg.CONF, attach_storage=False)
diff --git a/tests/api/v2/test_app.py b/tests/api/v2/test_app.py
index f3f8b5cd1..ebb9974f6 100644
--- a/tests/api/v2/test_app.py
+++ b/tests/api/v2/test_app.py
@@ -36,6 +36,7 @@ class TestApp(unittest.TestCase):
     def test_keystone_middleware_conf(self):
         cfg.CONF.set_override("auth_protocol", "foottp",
                               group=acl.OPT_GROUP_NAME)
+        cfg.CONF.set_override("auth_version", "v2.0", group=acl.OPT_GROUP_NAME)
         api_app = app.setup_app()
         self.assertEqual(api_app.auth_protocol, 'foottp')
 
@@ -43,6 +44,7 @@ class TestApp(unittest.TestCase):
         tmpfile = tempfile.mktemp()
         with open(tmpfile, "w") as f:
             f.write("[%s]\nauth_protocol = barttp" % acl.OPT_GROUP_NAME)
+            f.write("\nauth_version = v2.0")
         service.prepare_service(['ceilometer-api',
                                  '--config-file=%s' % tmpfile])
         api_app = app.setup_app()