Merge "Replace tests.base part4"

This commit is contained in:
Jenkins 2013-10-29 07:28:28 +00:00 committed by Gerrit Code Review
commit 8b403fbd49
9 changed files with 60 additions and 36 deletions

View File

@ -24,7 +24,8 @@ import testscenarios
from ceilometer.central import manager from ceilometer.central import manager
from ceilometer.objectstore import swift from ceilometer.objectstore import swift
from ceilometer.tests import base from ceilometer.openstack.common import test
from ceilometer.openstack.common.fixture import moxstubout
from keystoneclient import exceptions from keystoneclient import exceptions
from swiftclient import client as swift_client from swiftclient import client as swift_client
@ -48,7 +49,7 @@ class TestManager(manager.AgentManager):
self.keystone = mock.MagicMock() self.keystone = mock.MagicMock()
class TestSwiftPollster(base.TestCase): class TestSwiftPollster(test.BaseTestCase):
# Define scenarios to run all of the tests against all of the # Define scenarios to run all of the tests against all of the
# pollsters. # pollsters.
@ -72,6 +73,7 @@ class TestSwiftPollster(base.TestCase):
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock()) @mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def setUp(self): def setUp(self):
super(TestSwiftPollster, self).setUp() super(TestSwiftPollster, self).setUp()
self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
self.pollster = self.factory() self.pollster = self.factory()
self.manager = TestManager() self.manager = TestManager()

View File

@ -20,11 +20,12 @@
import cStringIO as StringIO import cStringIO as StringIO
import mock import mock
from oslo.config import cfg
from webob import Request from webob import Request
from ceilometer.tests import base
from ceilometer.objectstore import swift_middleware from ceilometer.objectstore import swift_middleware
from ceilometer.openstack.common import test
from ceilometer.openstack.common.fixture import config
from ceilometer.openstack.common.fixture import moxstubout
from ceilometer import pipeline from ceilometer import pipeline
@ -42,7 +43,7 @@ class FakeApp(object):
return self.body return self.body
class TestSwiftMiddleware(base.TestCase): class TestSwiftMiddleware(test.BaseTestCase):
class _faux_pipeline_manager(pipeline.PipelineManager): class _faux_pipeline_manager(pipeline.PipelineManager):
class _faux_pipeline(object): class _faux_pipeline(object):
@ -64,8 +65,10 @@ class TestSwiftMiddleware(base.TestCase):
def setUp(self): def setUp(self):
super(TestSwiftMiddleware, self).setUp() super(TestSwiftMiddleware, self).setUp()
self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
self.pipeline_manager = self._faux_pipeline_manager() self.pipeline_manager = self._faux_pipeline_manager()
self.stubs.Set(pipeline, 'setup_pipeline', self._faux_setup_pipeline) self.stubs.Set(pipeline, 'setup_pipeline', self._faux_setup_pipeline)
self.CONF = self.useFixture(config.Config()).conf
@staticmethod @staticmethod
def start_response(*args): def start_response(*args):
@ -73,7 +76,7 @@ class TestSwiftMiddleware(base.TestCase):
def test_rpc_setup(self): def test_rpc_setup(self):
swift_middleware.CeilometerMiddleware(FakeApp(), {}) swift_middleware.CeilometerMiddleware(FakeApp(), {})
self.assertEqual(cfg.CONF.control_exchange, 'ceilometer') self.assertEqual(self.CONF.control_exchange, 'ceilometer')
def test_get(self): def test_get(self):
app = swift_middleware.CeilometerMiddleware(FakeApp(), {}) app = swift_middleware.CeilometerMiddleware(FakeApp(), {})

View File

@ -22,13 +22,15 @@ import datetime
import os import os
import logging import logging
import logging.handlers import logging.handlers
import tempfile
from ceilometer import sample from ceilometer import sample
from ceilometer.publisher import file from ceilometer.publisher import file
from ceilometer.tests import base from ceilometer.openstack.common import test
from ceilometer.openstack.common.network_utils import urlsplit from ceilometer.openstack.common.network_utils import urlsplit
class TestFilePublisher(base.TestCase): class TestFilePublisher(test.BaseTestCase):
test_data = [ test_data = [
sample.Sample( sample.Sample(
@ -68,8 +70,10 @@ class TestFilePublisher(base.TestCase):
def test_file_publisher_maxbytes(self): def test_file_publisher_maxbytes(self):
# Test valid configurations # Test valid configurations
name = '%s/log_file' % self.tempdir.path tempdir = tempfile.mkdtemp()
parsed_url = urlsplit('file://%s?max_bytes=50&backup_count=3' % name) name = '%s/log_file' % tempdir
parsed_url = urlsplit('file://%s?max_bytes=50&backup_count=3'
% name)
publisher = file.FilePublisher(parsed_url) publisher = file.FilePublisher(parsed_url)
publisher.publish_samples(None, publisher.publish_samples(None,
self.test_data) self.test_data)
@ -85,7 +89,8 @@ class TestFilePublisher(base.TestCase):
def test_file_publisher(self): def test_file_publisher(self):
# Test missing max bytes, backup count configurations # Test missing max bytes, backup count configurations
name = '%s/log_file_plain' % self.tempdir.path tempdir = tempfile.mkdtemp()
name = '%s/log_file_plain' % tempdir
parsed_url = urlsplit('file://%s' % name) parsed_url = urlsplit('file://%s' % name)
publisher = file.FilePublisher(parsed_url) publisher = file.FilePublisher(parsed_url)
publisher.publish_samples(None, publisher.publish_samples(None,
@ -107,9 +112,10 @@ class TestFilePublisher(base.TestCase):
def test_file_publisher_invalid(self): def test_file_publisher_invalid(self):
# Test invalid max bytes, backup count configurations # Test invalid max bytes, backup count configurations
tempdir = tempfile.mkdtemp()
parsed_url = urlsplit( parsed_url = urlsplit(
'file://%s/log_file_bad' 'file://%s/log_file_bad'
'?max_bytes=yus&backup_count=5y' % self.tempdir.path) '?max_bytes=yus&backup_count=5y' % tempdir)
publisher = file.FilePublisher(parsed_url) publisher = file.FilePublisher(parsed_url)
publisher.publish_samples(None, publisher.publish_samples(None,
self.test_data) self.test_data)

View File

@ -21,17 +21,18 @@
import eventlet import eventlet
import datetime import datetime
from oslo.config import cfg
from ceilometer import sample from ceilometer import sample
from ceilometer.openstack.common import jsonutils from ceilometer.openstack.common import jsonutils
from ceilometer.openstack.common import network_utils from ceilometer.openstack.common import network_utils
from ceilometer.openstack.common import rpc as oslo_rpc from ceilometer.openstack.common import rpc as oslo_rpc
from ceilometer.openstack.common import test
from ceilometer.openstack.common.fixture import config
from ceilometer.openstack.common.fixture import moxstubout
from ceilometer.publisher import rpc from ceilometer.publisher import rpc
from ceilometer.tests import base
class TestSignature(base.TestCase): class TestSignature(test.BaseTestCase):
def test_compute_signature_change_key(self): def test_compute_signature_change_key(self):
sig1 = rpc.compute_signature({'a': 'A', 'b': 'B'}, sig1 = rpc.compute_signature({'a': 'A', 'b': 'B'},
@ -110,7 +111,7 @@ class TestSignature(base.TestCase):
self.assertTrue(rpc.verify_signature(jsondata, 'not-so-secret')) self.assertTrue(rpc.verify_signature(jsondata, 'not-so-secret'))
class TestCounter(base.TestCase): class TestCounter(test.BaseTestCase):
TEST_COUNTER = sample.Sample(name='name', TEST_COUNTER = sample.Sample(name='name',
type='typ', type='typ',
@ -142,7 +143,7 @@ class TestCounter(base.TestCase):
yield compare, f, getattr(self.TEST_COUNTER, f), msg_f, msg[msg_f] yield compare, f, getattr(self.TEST_COUNTER, f), msg_f, msg[msg_f]
class TestPublish(base.TestCase): class TestPublish(test.BaseTestCase):
test_data = [ test_data = [
sample.Sample( sample.Sample(
@ -214,8 +215,10 @@ class TestPublish(base.TestCase):
def setUp(self): def setUp(self):
super(TestPublish, self).setUp() super(TestPublish, self).setUp()
self.CONF = self.useFixture(config.Config()).conf
self.published = [] self.published = []
self.rpc_unreachable = False self.rpc_unreachable = False
self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
self.stubs.Set(oslo_rpc, 'cast', self.faux_cast) self.stubs.Set(oslo_rpc, 'cast', self.faux_cast)
def test_published(self): def test_published(self):
@ -225,7 +228,7 @@ class TestPublish(base.TestCase):
self.test_data) self.test_data)
self.assertEqual(len(self.published), 1) self.assertEqual(len(self.published), 1)
self.assertEqual(self.published[0][0], self.assertEqual(self.published[0][0],
cfg.CONF.publisher_rpc.metering_topic) self.CONF.publisher_rpc.metering_topic)
self.assertIsInstance(self.published[0][1]['args']['data'], list) self.assertIsInstance(self.published[0][1]['args']['data'], list)
self.assertEqual(self.published[0][1]['method'], self.assertEqual(self.published[0][1]['method'],
'record_metering_data') 'record_metering_data')
@ -237,7 +240,7 @@ class TestPublish(base.TestCase):
self.test_data) self.test_data)
self.assertEqual(len(self.published), 1) self.assertEqual(len(self.published), 1)
self.assertEqual(self.published[0][0], self.assertEqual(self.published[0][0],
cfg.CONF.publisher_rpc.metering_topic) self.CONF.publisher_rpc.metering_topic)
self.assertIsInstance(self.published[0][1]['args']['data'], list) self.assertIsInstance(self.published[0][1]['args']['data'], list)
self.assertEqual(self.published[0][1]['method'], self.assertEqual(self.published[0][1]['method'],
'custom_procedure_call') 'custom_procedure_call')
@ -251,20 +254,20 @@ class TestPublish(base.TestCase):
for topic, rpc_call in self.published: for topic, rpc_call in self.published:
meters = rpc_call['args']['data'] meters = rpc_call['args']['data']
self.assertIsInstance(meters, list) self.assertIsInstance(meters, list)
if topic != cfg.CONF.publisher_rpc.metering_topic: if topic != self.CONF.publisher_rpc.metering_topic:
self.assertEqual(len(set(meter['counter_name'] self.assertEqual(len(set(meter['counter_name']
for meter in meters)), for meter in meters)),
1, 1,
"Meter are published grouped by name") "Meter are published grouped by name")
topics = [topic for topic, meter in self.published] topics = [topic for topic, meter in self.published]
self.assertIn(cfg.CONF.publisher_rpc.metering_topic, topics) self.assertIn(self.CONF.publisher_rpc.metering_topic, topics)
self.assertIn( self.assertIn(
cfg.CONF.publisher_rpc.metering_topic + '.' + 'test', topics) self.CONF.publisher_rpc.metering_topic + '.' + 'test', topics)
self.assertIn( self.assertIn(
cfg.CONF.publisher_rpc.metering_topic + '.' + 'test2', topics) self.CONF.publisher_rpc.metering_topic + '.' + 'test2', topics)
self.assertIn( self.assertIn(
cfg.CONF.publisher_rpc.metering_topic + '.' + 'test3', topics) self.CONF.publisher_rpc.metering_topic + '.' + 'test3', topics)
def test_published_concurrency(self): def test_published_concurrency(self):
"""This test the concurrent access to the local queue """This test the concurrent access to the local queue

View File

@ -21,18 +21,19 @@
import datetime import datetime
import mock import mock
import msgpack import msgpack
from oslo.config import cfg
from ceilometer import sample from ceilometer import sample
from ceilometer.publisher import udp from ceilometer.publisher import udp
from ceilometer.tests import base from ceilometer.openstack.common import test
from ceilometer.openstack.common import network_utils from ceilometer.openstack.common import network_utils
from ceilometer.openstack.common.fixture import config
from ceilometer.openstack.common.fixture import moxstubout
COUNTER_SOURCE = 'testsource' COUNTER_SOURCE = 'testsource'
class TestUDPPublisher(base.TestCase): class TestUDPPublisher(test.BaseTestCase):
test_data = [ test_data = [
sample.Sample( sample.Sample(
@ -107,6 +108,11 @@ class TestUDPPublisher(base.TestCase):
return udp_socket return udp_socket
return _fake_socket_socket return _fake_socket_socket
def setUp(self):
super(TestUDPPublisher, self).setUp()
self.mox = self.useFixture(moxstubout.MoxStubout()).mox
self.CONF = self.useFixture(config.Config()).conf
def test_published(self): def test_published(self):
self.data_sent = [] self.data_sent = []
with mock.patch('socket.socket', with mock.patch('socket.socket',
@ -126,7 +132,7 @@ class TestUDPPublisher(base.TestCase):
# Check destination # Check destination
self.assertEqual(dest, ('somehost', self.assertEqual(dest, ('somehost',
cfg.CONF.collector.udp_port)) self.CONF.collector.udp_port))
# Check that counters are equal # Check that counters are equal
self.assertEqual(sorted(sent_counters), self.assertEqual(sorted(sent_counters),

View File

@ -18,11 +18,11 @@
import datetime import datetime
import math import math
from ceilometer.openstack.common import test
from ceilometer.storage import base from ceilometer.storage import base
from ceilometer.tests import base as test_base
class BaseTest(test_base.TestCase): class BaseTest(test.BaseTestCase):
def test_iter_period(self): def test_iter_period(self):
times = list(base.iter_period( times = list(base.iter_period(

View File

@ -19,13 +19,13 @@
""" """
import mox import mox
import testtools
from ceilometer import storage from ceilometer import storage
from ceilometer.openstack.common import test
from ceilometer.storage import impl_log from ceilometer.storage import impl_log
class EngineTest(testtools.TestCase): class EngineTest(test.BaseTestCase):
def test_get_engine(self): def test_get_engine(self):
conf = mox.Mox().CreateMockAnything() conf = mox.Mox().CreateMockAnything()

View File

@ -17,11 +17,15 @@
# under the License. # under the License.
"""Tests for ceilometer/storage/impl_log.py """Tests for ceilometer/storage/impl_log.py
""" """
from ceilometer.tests import base from ceilometer.openstack.common import test
from ceilometer.openstack.common.fixture import moxstubout
from ceilometer.storage import impl_log from ceilometer.storage import impl_log
class ConnectionTest(base.TestCase): class ConnectionTest(test.BaseTestCase):
def setUp(self):
super(ConnectionTest, self).setUp()
self.mox = self.useFixture(moxstubout.MoxStubout()).mox
def test_get_connection(self): def test_get_connection(self):
conf = self.mox.CreateMockAnything() conf = self.mox.CreateMockAnything()

View File

@ -16,8 +16,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from ceilometer.openstack.common import test
from ceilometer.storage import models from ceilometer.storage import models
from ceilometer.tests import base
class FakeModel(models.Model): class FakeModel(models.Model):
@ -25,7 +25,7 @@ class FakeModel(models.Model):
models.Model.__init__(self, arg1=arg1, arg2=arg2) models.Model.__init__(self, arg1=arg1, arg2=arg2)
class ModelTest(base.TestCase): class ModelTest(test.BaseTestCase):
def test_create_attributes(self): def test_create_attributes(self):
m = FakeModel(1, 2) m = FakeModel(1, 2)