Fixed various import issues exposed by unittest

Tried running the unit test stand-alone(e.g. using testtools.run), and
it exposed various 'import' issues about the oslo.config options and the
modules, in both the test cases themselves and the ceilometer module.
This patch fixed those import issues.

Change-Id: I68f30d335ee8d0d63c451116274632287a9ec77f
Closes-Bug: #1328796
This commit is contained in:
Lianhao Lu 2014-06-11 14:55:54 +08:00
parent a7bf563696
commit acf7f5189e
9 changed files with 18 additions and 8 deletions

View File

@ -35,6 +35,8 @@ UNKNOWN = 'insufficient data'
OK = 'ok'
ALARM = 'alarm'
cfg.CONF.import_group('service_credentials', 'ceilometer.service')
@six.add_metaclass(abc.ABCMeta)
class Evaluator(object):

View File

@ -132,9 +132,6 @@ class SingletonAlarmService(AlarmService, os_service.Service):
'value': True}])
cfg.CONF.import_opt('host', 'ceilometer.service')
class PartitionedAlarmService(AlarmService, os_service.Service):
def __init__(self):

View File

@ -96,6 +96,7 @@ def cleanup():
def get_rpc_server(transport, topic, endpoint):
"""Return a configured oslo.messaging rpc server."""
cfg.CONF.import_opt('host', 'ceilometer.service')
target = oslo.messaging.Target(server=cfg.CONF.host, topic=topic)
serializer = RequestContextSerializer(JsonPayloadSerializer())
return oslo.messaging.get_rpc_server(transport, target,

View File

@ -55,6 +55,9 @@ class TestCoordinate(tests_base.BaseTestCase):
self.setup_messaging(self.CONF)
self.test_interval = 120
self.CONF.import_opt('evaluation_interval',
'ceilometer.alarm.service',
group='alarm')
self.CONF.set_override('evaluation_interval',
self.test_interval,
group='alarm')

View File

@ -26,6 +26,7 @@ from ceilometer.tests import db as db_test_base
OPT_GROUP_NAME = 'keystone_authtoken'
cfg.CONF.import_group(OPT_GROUP_NAME, "keystoneclient.middleware.auth_token")
cfg.CONF.import_opt("policy_file", "ceilometer.openstack.common.policy")
class FunctionalTest(db_test_base.TestBase):

View File

@ -17,6 +17,7 @@
# under the License.
"""Test the methods related to complex query."""
import datetime
import fixtures
import jsonschema
import mock
@ -25,7 +26,7 @@ import wsme
from ceilometer.alarm.storage import models as alarm_models
from ceilometer.api.controllers import v2 as api
from ceilometer.openstack.common import test
from ceilometer import storage
from ceilometer.storage import models
class FakeComplexQuery(api.ValidatedComplexQuery):
@ -49,7 +50,7 @@ class TestComplexQuery(test.BaseTestCase):
super(TestComplexQuery, self).setUp()
self.useFixture(fixtures.MonkeyPatch(
'pecan.response', mock.MagicMock()))
self.query = FakeComplexQuery(storage.models.Sample,
self.query = FakeComplexQuery(models.Sample,
sample_name_mapping,
True)
self.query_alarm = FakeComplexQuery(alarm_models.Alarm)
@ -235,7 +236,7 @@ class TestComplexQuery(test.BaseTestCase):
class TestFilterSyntaxValidation(test.BaseTestCase):
def setUp(self):
super(TestFilterSyntaxValidation, self).setUp()
self.query = FakeComplexQuery(storage.models.Sample,
self.query = FakeComplexQuery(models.Sample,
sample_name_mapping,
True)

View File

@ -23,6 +23,7 @@ import six
import eventlet
import oslo.messaging
import oslo.messaging.conffixture
from testtools import testcase
from ceilometer import messaging

View File

@ -43,6 +43,9 @@ class TestCollector(tests_base.BaseTestCase):
def setUp(self):
super(TestCollector, self).setUp()
self.CONF = self.useFixture(config.Config()).conf
self.CONF.import_opt("connection",
"ceilometer.openstack.common.db.options",
group="database")
self.CONF.set_override("connection", "log://", group='database')
self.CONF.set_override('metering_secret', 'not-so-secret',
group='publisher')

View File

@ -19,7 +19,7 @@ import mock
from ceilometer import middleware
from ceilometer.openstack.common.fixture import config
from ceilometer.openstack.common import test
from ceilometer.tests import base
HTTP_REQUEST = {
@ -68,11 +68,12 @@ HTTP_RESPONSE = {
}
class TestNotifications(test.BaseTestCase):
class TestNotifications(base.BaseTestCase):
def setUp(self):
super(TestNotifications, self).setUp()
self.CONF = self.useFixture(config.Config()).conf
self.setup_messaging(self.CONF)
def test_process_request_notification(self):
sample = list(middleware.HTTPRequest(mock.Mock()).process_notification(