Replace tests.base part2
It is the next step to replace using ceilometer.tests.base with openstack.common.test. In this patch is changed for using openstack.common.test and added needed fixtures in test classes. Change-Id: I091fbf1419e78bf69491f5787deb93306d933c27
This commit is contained in:
parent
9da986953d
commit
517a0eeaa5
@ -20,11 +20,11 @@
|
||||
"""
|
||||
import mock
|
||||
|
||||
from ceilometer.openstack.common import test
|
||||
from ceilometer.openstack.common import timeutils
|
||||
from ceilometer.tests import base
|
||||
|
||||
|
||||
class TestEvaluatorBase(base.TestCase):
|
||||
class TestEvaluatorBase(test.BaseTestCase):
|
||||
def setUp(self):
|
||||
super(TestEvaluatorBase, self).setUp()
|
||||
self.api_client = mock.Mock()
|
||||
|
@ -19,11 +19,10 @@ import urlparse
|
||||
import mock
|
||||
import requests
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.alarm import service
|
||||
from ceilometer.openstack.common import context
|
||||
from ceilometer.tests import base
|
||||
from ceilometer.openstack.common import test
|
||||
from ceilometer.openstack.common.fixture import config
|
||||
|
||||
|
||||
DATA_JSON = ('{"current": "ALARM", "alarm_id": "foobar",'
|
||||
@ -35,10 +34,11 @@ NOTIFICATION = dict(alarm_id='foobar',
|
||||
current='ALARM')
|
||||
|
||||
|
||||
class TestAlarmNotifier(base.TestCase):
|
||||
class TestAlarmNotifier(test.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAlarmNotifier, self).setUp()
|
||||
self.CONF = self.useFixture(config.Config()).conf
|
||||
self.service = service.AlarmNotifierService('somehost', 'sometopic')
|
||||
|
||||
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
|
||||
@ -102,8 +102,8 @@ class TestAlarmNotifier(base.TestCase):
|
||||
action = 'https://host/action'
|
||||
certificate = "/etc/ssl/cert/whatever.pem"
|
||||
|
||||
cfg.CONF.set_override("rest_notifier_certificate_file", certificate,
|
||||
group='alarm')
|
||||
self.CONF.set_override("rest_notifier_certificate_file", certificate,
|
||||
group='alarm')
|
||||
|
||||
with mock.patch('eventlet.spawn_n', self._fake_spawn_n):
|
||||
with mock.patch.object(requests, 'post') as poster:
|
||||
@ -117,10 +117,10 @@ class TestAlarmNotifier(base.TestCase):
|
||||
certificate = "/etc/ssl/cert/whatever.pem"
|
||||
key = "/etc/ssl/cert/whatever.key"
|
||||
|
||||
cfg.CONF.set_override("rest_notifier_certificate_file", certificate,
|
||||
group='alarm')
|
||||
cfg.CONF.set_override("rest_notifier_certificate_key", key,
|
||||
group='alarm')
|
||||
self.CONF.set_override("rest_notifier_certificate_file", certificate,
|
||||
group='alarm')
|
||||
self.CONF.set_override("rest_notifier_certificate_key", key,
|
||||
group='alarm')
|
||||
|
||||
with mock.patch('eventlet.spawn_n', self._fake_spawn_n):
|
||||
with mock.patch.object(requests, 'post') as poster:
|
||||
@ -132,8 +132,8 @@ class TestAlarmNotifier(base.TestCase):
|
||||
def test_notify_alarm_rest_action_with_ssl_verify_disable_by_cfg(self):
|
||||
action = 'https://host/action'
|
||||
|
||||
cfg.CONF.set_override("rest_notifier_ssl_verify", False,
|
||||
group='alarm')
|
||||
self.CONF.set_override("rest_notifier_ssl_verify", False,
|
||||
group='alarm')
|
||||
|
||||
with mock.patch('eventlet.spawn_n', self._fake_spawn_n):
|
||||
with mock.patch.object(requests, 'post') as poster:
|
||||
@ -155,8 +155,8 @@ class TestAlarmNotifier(base.TestCase):
|
||||
def test_notify_alarm_rest_action_with_ssl_verify_enable_by_user(self):
|
||||
action = 'https://host/action?ceilometer-alarm-ssl-verify=1'
|
||||
|
||||
cfg.CONF.set_override("rest_notifier_ssl_verify", False,
|
||||
group='alarm')
|
||||
self.CONF.set_override("rest_notifier_ssl_verify", False,
|
||||
group='alarm')
|
||||
|
||||
with mock.patch('eventlet.spawn_n', self._fake_spawn_n):
|
||||
with mock.patch.object(requests, 'post') as poster:
|
||||
|
@ -20,23 +20,25 @@
|
||||
import uuid
|
||||
import mock
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.alarm import rpc as rpc_alarm
|
||||
from ceilometer.openstack.common import rpc
|
||||
from ceilometer.openstack.common import test
|
||||
from ceilometer.openstack.common import timeutils
|
||||
from ceilometer.openstack.common.fixture import config
|
||||
from ceilometer.openstack.common.fixture import moxstubout
|
||||
from ceilometer.storage.models import Alarm as AlarmModel
|
||||
from ceilometer.tests import base
|
||||
from ceilometerclient.v2.alarms import Alarm as AlarmClient
|
||||
|
||||
|
||||
class TestRPCAlarmNotifier(base.TestCase):
|
||||
class TestRPCAlarmNotifier(test.BaseTestCase):
|
||||
def faux_cast(self, context, topic, msg):
|
||||
self.notified.append((topic, msg))
|
||||
self.CONF = self.useFixture(config.Config()).conf
|
||||
|
||||
def setUp(self):
|
||||
super(TestRPCAlarmNotifier, self).setUp()
|
||||
self.notified = []
|
||||
self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
|
||||
self.stubs.Set(rpc, 'cast', self.faux_cast)
|
||||
self.notifier = rpc_alarm.RPCAlarmNotifier()
|
||||
self.alarms = [
|
||||
@ -82,7 +84,7 @@ class TestRPCAlarmNotifier(base.TestCase):
|
||||
for i, a in enumerate(self.alarms):
|
||||
actions = getattr(a, AlarmModel.ALARM_ACTIONS_MAP[a.state])
|
||||
self.assertEqual(self.notified[i][0],
|
||||
cfg.CONF.alarm.notifier_rpc_topic)
|
||||
self.CONF.alarm.notifier_rpc_topic)
|
||||
self.assertEqual(self.notified[i][1]["args"]["data"]["alarm_id"],
|
||||
self.alarms[i].alarm_id)
|
||||
self.assertEqual(self.notified[i][1]["args"]["data"]["actions"],
|
||||
@ -120,13 +122,14 @@ class TestRPCAlarmNotifier(base.TestCase):
|
||||
self.assertEqual(len(self.notified), 0)
|
||||
|
||||
|
||||
class TestRPCAlarmPartitionCoordination(base.TestCase):
|
||||
class TestRPCAlarmPartitionCoordination(test.BaseTestCase):
|
||||
def faux_fanout_cast(self, context, topic, msg):
|
||||
self.notified.append((topic, msg))
|
||||
|
||||
def setUp(self):
|
||||
super(TestRPCAlarmPartitionCoordination, self).setUp()
|
||||
self.notified = []
|
||||
self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
|
||||
self.stubs.Set(rpc, 'fanout_cast', self.faux_fanout_cast)
|
||||
self.ordination = rpc_alarm.RPCAlarmPartitionCoordination()
|
||||
self.alarms = [mock.MagicMock(), mock.MagicMock()]
|
||||
|
@ -25,10 +25,10 @@ from stevedore import extension
|
||||
from stevedore.tests import manager as extension_tests
|
||||
|
||||
from ceilometer.alarm import service
|
||||
from ceilometer.tests import base
|
||||
from ceilometer.openstack.common import test
|
||||
|
||||
|
||||
class TestSingletonAlarmService(base.TestCase):
|
||||
class TestSingletonAlarmService(test.BaseTestCase):
|
||||
def setUp(self):
|
||||
super(TestSingletonAlarmService, self).setUp()
|
||||
self.threshold_eval = mock.Mock()
|
||||
|
@ -22,11 +22,12 @@ import mock
|
||||
from keystoneclient.v2_0 import client as ksclient
|
||||
|
||||
from ceilometer.central import manager
|
||||
from ceilometer.tests import base
|
||||
from ceilometer.openstack.common import test
|
||||
from ceilometer.openstack.common.fixture import moxstubout
|
||||
from tests import agentbase
|
||||
|
||||
|
||||
class TestManager(base.TestCase):
|
||||
class TestManager(test.BaseTestCase):
|
||||
|
||||
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
|
||||
def test_load_plugins(self):
|
||||
@ -41,6 +42,7 @@ class TestRunTasks(agentbase.BaseAgentManagerTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestRunTasks, self).setUp()
|
||||
self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
|
||||
self.stubs.Set(ksclient, 'Client', lambda *args, **kwargs: None)
|
||||
|
||||
def tearDown(self):
|
||||
|
@ -18,20 +18,23 @@
|
||||
"""Tests for ceilometer/collector/dispatcher/database.py
|
||||
"""
|
||||
from datetime import datetime
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.openstack.common import test
|
||||
from ceilometer.openstack.common.fixture import config
|
||||
from ceilometer.openstack.common.fixture import moxstubout
|
||||
from ceilometer.collector.dispatcher import database
|
||||
from ceilometer.publisher import rpc
|
||||
from ceilometer.storage import base
|
||||
from ceilometer.tests import base as tests_base
|
||||
|
||||
|
||||
class TestDispatcherDB(tests_base.TestCase):
|
||||
class TestDispatcherDB(test.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestDispatcherDB, self).setUp()
|
||||
self.dispatcher = database.DatabaseDispatcher(cfg.CONF)
|
||||
self.CONF = self.useFixture(config.Config()).conf
|
||||
self.dispatcher = database.DatabaseDispatcher(self.CONF)
|
||||
self.ctx = None
|
||||
self.mox = self.useFixture(moxstubout.MoxStubout()).mox
|
||||
|
||||
def test_valid_message(self):
|
||||
msg = {'counter_name': 'test',
|
||||
@ -40,7 +43,7 @@ class TestDispatcherDB(tests_base.TestCase):
|
||||
}
|
||||
msg['message_signature'] = rpc.compute_signature(
|
||||
msg,
|
||||
cfg.CONF.publisher_rpc.metering_secret,
|
||||
self.CONF.publisher_rpc.metering_secret,
|
||||
)
|
||||
|
||||
self.dispatcher.storage_conn = self.mox.CreateMock(base.Connection)
|
||||
@ -79,7 +82,7 @@ class TestDispatcherDB(tests_base.TestCase):
|
||||
}
|
||||
msg['message_signature'] = rpc.compute_signature(
|
||||
msg,
|
||||
cfg.CONF.publisher_rpc.metering_secret,
|
||||
self.CONF.publisher_rpc.metering_secret,
|
||||
)
|
||||
|
||||
expected = {}
|
||||
@ -100,7 +103,7 @@ class TestDispatcherDB(tests_base.TestCase):
|
||||
}
|
||||
msg['message_signature'] = rpc.compute_signature(
|
||||
msg,
|
||||
cfg.CONF.publisher_rpc.metering_secret,
|
||||
self.CONF.publisher_rpc.metering_secret,
|
||||
)
|
||||
|
||||
expected = {}
|
||||
|
@ -21,17 +21,18 @@
|
||||
import os
|
||||
import tempfile
|
||||
import logging.handlers
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector.dispatcher import file
|
||||
from ceilometer.openstack.common import test
|
||||
from ceilometer.openstack.common.fixture import config
|
||||
from ceilometer.publisher import rpc
|
||||
from ceilometer.tests import base as tests_base
|
||||
|
||||
|
||||
class TestDispatcherFile(tests_base.TestCase):
|
||||
class TestDispatcherFile(test.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestDispatcherFile, self).setUp()
|
||||
self.CONF = self.useFixture(config.Config()).conf
|
||||
|
||||
def test_file_dispatcher_with_all_config(self):
|
||||
# Create a temporaryFile to get a file name
|
||||
@ -39,10 +40,10 @@ class TestDispatcherFile(tests_base.TestCase):
|
||||
filename = tf.name
|
||||
tf.close()
|
||||
|
||||
cfg.CONF.dispatcher_file.file_path = filename
|
||||
cfg.CONF.dispatcher_file.max_bytes = 50
|
||||
cfg.CONF.dispatcher_file.backup_count = 5
|
||||
dispatcher = file.FileDispatcher(cfg.CONF)
|
||||
self.CONF.dispatcher_file.file_path = filename
|
||||
self.CONF.dispatcher_file.max_bytes = 50
|
||||
self.CONF.dispatcher_file.backup_count = 5
|
||||
dispatcher = file.FileDispatcher(self.CONF)
|
||||
|
||||
# The number of the handlers should be 1
|
||||
self.assertEqual(1, len(dispatcher.log.handlers))
|
||||
@ -57,7 +58,7 @@ class TestDispatcherFile(tests_base.TestCase):
|
||||
}
|
||||
msg['message_signature'] = rpc.compute_signature(
|
||||
msg,
|
||||
cfg.CONF.publisher_rpc.metering_secret,
|
||||
self.CONF.publisher_rpc.metering_secret,
|
||||
)
|
||||
|
||||
# The record_metering_data method should exist and not produce errors.
|
||||
@ -71,10 +72,10 @@ class TestDispatcherFile(tests_base.TestCase):
|
||||
filename = tf.name
|
||||
tf.close()
|
||||
|
||||
cfg.CONF.dispatcher_file.file_path = filename
|
||||
cfg.CONF.dispatcher_file.max_bytes = None
|
||||
cfg.CONF.dispatcher_file.backup_count = None
|
||||
dispatcher = file.FileDispatcher(cfg.CONF)
|
||||
self.CONF.dispatcher_file.file_path = filename
|
||||
self.CONF.dispatcher_file.max_bytes = None
|
||||
self.CONF.dispatcher_file.backup_count = None
|
||||
dispatcher = file.FileDispatcher(self.CONF)
|
||||
|
||||
# The number of the handlers should be 1
|
||||
self.assertEqual(1, len(dispatcher.log.handlers))
|
||||
@ -89,7 +90,7 @@ class TestDispatcherFile(tests_base.TestCase):
|
||||
}
|
||||
msg['message_signature'] = rpc.compute_signature(
|
||||
msg,
|
||||
cfg.CONF.publisher_rpc.metering_secret,
|
||||
self.CONF.publisher_rpc.metering_secret,
|
||||
)
|
||||
|
||||
# The record_metering_data method should exist and not produce errors.
|
||||
@ -98,8 +99,8 @@ class TestDispatcherFile(tests_base.TestCase):
|
||||
self.assertTrue(os.path.exists(handler.baseFilename))
|
||||
|
||||
def test_file_dispatcher_with_no_path(self):
|
||||
cfg.CONF.dispatcher_file.file_path = None
|
||||
dispatcher = file.FileDispatcher(cfg.CONF)
|
||||
self.CONF.dispatcher_file.file_path = None
|
||||
dispatcher = file.FileDispatcher(self.CONF)
|
||||
|
||||
# The log should be None
|
||||
self.assertIsNone(dispatcher.log)
|
||||
|
@ -18,11 +18,11 @@
|
||||
|
||||
import mock
|
||||
|
||||
from ceilometer.tests import base
|
||||
from ceilometer.image import glance
|
||||
from ceilometer.central import manager
|
||||
from ceilometer.openstack.common import context
|
||||
|
||||
from ceilometer.openstack.common import test
|
||||
from ceilometer.openstack.common.fixture import moxstubout
|
||||
|
||||
IMAGE_LIST = [
|
||||
type('Image', (object,),
|
||||
@ -116,7 +116,7 @@ class TestManager(manager.AgentManager):
|
||||
self.keystone = None
|
||||
|
||||
|
||||
class TestImagePollster(base.TestCase):
|
||||
class TestImagePollster(test.BaseTestCase):
|
||||
|
||||
def fake_get_glance_client(self, ksclient):
|
||||
glanceclient = _BaseObject()
|
||||
@ -128,6 +128,7 @@ class TestImagePollster(base.TestCase):
|
||||
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
|
||||
def setUp(self):
|
||||
super(TestImagePollster, self).setUp()
|
||||
self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
|
||||
self.context = context.get_admin_context()
|
||||
self.manager = TestManager()
|
||||
self.stubs.Set(glance._Base, 'get_glance_client',
|
||||
|
@ -21,7 +21,7 @@ from datetime import datetime
|
||||
|
||||
from ceilometer.image import notifications
|
||||
from ceilometer import sample
|
||||
from ceilometer.tests import base
|
||||
from ceilometer.openstack.common import test
|
||||
|
||||
|
||||
def fake_uuid(x):
|
||||
@ -89,7 +89,7 @@ NOTIFICATION_DELETE = {"message_id": "0c65cb9c-018c-11e2-bc91-5453ed1bbb5f",
|
||||
"timestamp": NOW}
|
||||
|
||||
|
||||
class TestNotification(base.TestCase):
|
||||
class TestNotification(test.BaseTestCase):
|
||||
|
||||
def _verify_common_counter(self, c, name, volume):
|
||||
self.assertFalse(c is None)
|
||||
|
@ -10,8 +10,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from ceilometer.openstack.common import test
|
||||
from ceilometer.volume import notifications
|
||||
from ceilometer.tests import base
|
||||
|
||||
NOTIFICATION_VOLUME_EXISTS = {
|
||||
u'_context_roles': [u'admin'],
|
||||
@ -100,7 +100,7 @@ NOTIFICATION_VOLUME_RESIZE = {
|
||||
u'priority': u'INFO'}
|
||||
|
||||
|
||||
class TestNotifications(base.TestCase):
|
||||
class TestNotifications(test.BaseTestCase):
|
||||
|
||||
def _verify_common_sample(self, s, name, notification):
|
||||
self.assertFalse(s is None)
|
||||
|
Loading…
x
Reference in New Issue
Block a user