tests: remove testscenario usage for storage drivers
We test only one driver at a time, so there is no need to leverage scenarios here. Change-Id: Ieff6e52d5efe46fc7ad5fa66b3fe199b1ac8c460
This commit is contained in:
parent
867ad8d6ab
commit
656da0a6c9
@ -26,7 +26,6 @@ from oslotest import mockpatch
|
|||||||
import six
|
import six
|
||||||
from six.moves.urllib import parse as urlparse
|
from six.moves.urllib import parse as urlparse
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
import testscenarios.testcase
|
|
||||||
from testtools import testcase
|
from testtools import testcase
|
||||||
|
|
||||||
from ceilometer import storage
|
from ceilometer import storage
|
||||||
@ -173,7 +172,8 @@ class SQLiteManager(fixtures.Fixture):
|
|||||||
self.url, 'ceilometer.event.storage')
|
self.url, 'ceilometer.event.storage')
|
||||||
|
|
||||||
|
|
||||||
class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase):
|
@six.add_metaclass(test_base.SkipNotImplementedMeta)
|
||||||
|
class TestBase(test_base.BaseTestCase):
|
||||||
|
|
||||||
DRIVER_MANAGERS = {
|
DRIVER_MANAGERS = {
|
||||||
'mongodb': MongoDbManager,
|
'mongodb': MongoDbManager,
|
||||||
@ -186,11 +186,12 @@ class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase):
|
|||||||
if mocks is not None:
|
if mocks is not None:
|
||||||
DRIVER_MANAGERS['hbase'] = HBaseManager
|
DRIVER_MANAGERS['hbase'] = HBaseManager
|
||||||
|
|
||||||
db_url = 'sqlite://' # NOTE(Alexei_987) Set default db url
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestBase, self).setUp()
|
super(TestBase, self).setUp()
|
||||||
engine = urlparse.urlparse(self.db_url).scheme
|
db_url = os.environ.get('CEILOMETER_TEST_STORAGE_URL',
|
||||||
|
"sqlite://")
|
||||||
|
|
||||||
|
engine = urlparse.urlparse(db_url).scheme
|
||||||
# in case some drivers have additional specification, for example:
|
# in case some drivers have additional specification, for example:
|
||||||
# PyMySQL will have scheme mysql+pymysql
|
# PyMySQL will have scheme mysql+pymysql
|
||||||
engine = engine.split('+')[0]
|
engine = engine.split('+')[0]
|
||||||
@ -205,10 +206,12 @@ class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase):
|
|||||||
self.CONF = self.useFixture(fixture_config.Config()).conf
|
self.CONF = self.useFixture(fixture_config.Config()).conf
|
||||||
self.CONF([], project='ceilometer', validate_default_values=True)
|
self.CONF([], project='ceilometer', validate_default_values=True)
|
||||||
|
|
||||||
try:
|
manager = self.DRIVER_MANAGERS.get(engine)
|
||||||
self.db_manager = self._get_driver_manager(engine)(self.db_url)
|
if not manager:
|
||||||
except ValueError as exc:
|
self.skipTest("missing driver manager: %s" % engine)
|
||||||
self.skipTest("missing driver manager: %s" % exc)
|
|
||||||
|
self.db_manager = manager(db_url)
|
||||||
|
|
||||||
self.useFixture(self.db_manager)
|
self.useFixture(self.db_manager)
|
||||||
|
|
||||||
self.conn = self.db_manager.connection
|
self.conn = self.db_manager.connection
|
||||||
@ -241,12 +244,6 @@ class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase):
|
|||||||
return self.event_conn
|
return self.event_conn
|
||||||
return self.conn
|
return self.conn
|
||||||
|
|
||||||
def _get_driver_manager(self, engine):
|
|
||||||
manager = self.DRIVER_MANAGERS.get(engine)
|
|
||||||
if not manager:
|
|
||||||
raise ValueError('No manager available for %s' % engine)
|
|
||||||
return manager
|
|
||||||
|
|
||||||
|
|
||||||
def run_with(*drivers):
|
def run_with(*drivers):
|
||||||
"""Used to mark tests that are only applicable for certain db driver.
|
"""Used to mark tests that are only applicable for certain db driver.
|
||||||
@ -267,31 +264,3 @@ def run_with(*drivers):
|
|||||||
test._run_with = drivers
|
test._run_with = drivers
|
||||||
return test
|
return test
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
@six.add_metaclass(test_base.SkipNotImplementedMeta)
|
|
||||||
class MixinTestsWithBackendScenarios(object):
|
|
||||||
|
|
||||||
scenarios = [
|
|
||||||
('sqlite', {'db_url': 'sqlite://'}),
|
|
||||||
]
|
|
||||||
|
|
||||||
for db in ('MONGODB', 'MYSQL', 'PGSQL', 'HBASE', 'DB2', 'ES'):
|
|
||||||
if os.environ.get('CEILOMETER_TEST_%s_URL' % db):
|
|
||||||
scenarios.append(
|
|
||||||
(db.lower(), {'db_url': os.environ.get(
|
|
||||||
'CEILOMETER_TEST_%s_URL' % db)}))
|
|
||||||
|
|
||||||
scenarios_db = [db for db, _ in scenarios]
|
|
||||||
|
|
||||||
# Insert default value for hbase test
|
|
||||||
if 'hbase' not in scenarios_db:
|
|
||||||
scenarios.append(
|
|
||||||
('hbase', {'db_url': 'hbase://__test__'}))
|
|
||||||
|
|
||||||
# Insert default value for db2 test
|
|
||||||
if 'mongodb' in scenarios_db and 'db2' not in scenarios_db:
|
|
||||||
scenarios.append(
|
|
||||||
('db2', {'db_url': os.environ.get('CEILOMETER_TEST_MONGODB_URL',
|
|
||||||
'').replace('mongodb://',
|
|
||||||
'db2://')}))
|
|
||||||
|
@ -27,7 +27,6 @@ import webtest
|
|||||||
from ceilometer.api import app
|
from ceilometer.api import app
|
||||||
from ceilometer.publisher import utils
|
from ceilometer.publisher import utils
|
||||||
from ceilometer import sample
|
from ceilometer import sample
|
||||||
from ceilometer.tests import db as tests_db
|
|
||||||
from ceilometer.tests.functional import api as acl
|
from ceilometer.tests.functional import api as acl
|
||||||
from ceilometer.tests.functional.api import v2
|
from ceilometer.tests.functional.api import v2
|
||||||
|
|
||||||
@ -79,8 +78,7 @@ class FakeMemcache(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestAPIACL(v2.FunctionalTest,
|
class TestAPIACL(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestAPIACL, self).setUp()
|
super(TestAPIACL, self).setUp()
|
||||||
@ -228,8 +226,7 @@ class TestAPIEventACL(TestAPIACL):
|
|||||||
self.assertEqual(401, data.status_int)
|
self.assertEqual(401, data.status_int)
|
||||||
|
|
||||||
|
|
||||||
class TestApiEventRBAC(v2.FunctionalTest,
|
class TestApiEventRBAC(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
PATH = '/events'
|
PATH = '/events'
|
||||||
|
|
||||||
|
@ -14,17 +14,10 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import testscenarios
|
|
||||||
|
|
||||||
from ceilometer.tests import db as tests_db
|
|
||||||
from ceilometer.tests.functional.api import v2 as tests_api
|
from ceilometer.tests.functional.api import v2 as tests_api
|
||||||
|
|
||||||
load_tests = testscenarios.load_tests_apply_scenarios
|
|
||||||
|
|
||||||
|
class TestCapabilitiesController(tests_api.FunctionalTest):
|
||||||
class TestCapabilitiesController(tests_api.FunctionalTest,
|
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestCapabilitiesController, self).setUp()
|
super(TestCapabilitiesController, self).setUp()
|
||||||
|
@ -24,7 +24,6 @@ from oslo_utils import timeutils
|
|||||||
|
|
||||||
from ceilometer.publisher import utils
|
from ceilometer.publisher import utils
|
||||||
from ceilometer import sample
|
from ceilometer import sample
|
||||||
from ceilometer.tests import db as tests_db
|
|
||||||
from ceilometer.tests.functional.api import v2 as tests_api
|
from ceilometer.tests.functional.api import v2 as tests_api
|
||||||
|
|
||||||
|
|
||||||
@ -36,9 +35,7 @@ non_admin_header = {"X-Roles": "Member",
|
|||||||
"project-id1"}
|
"project-id1"}
|
||||||
|
|
||||||
|
|
||||||
class TestQueryMetersController(tests_api.FunctionalTest,
|
class TestQueryMetersController(tests_api.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestQueryMetersController, self).setUp()
|
super(TestQueryMetersController, self).setUp()
|
||||||
self.url = '/query/samples'
|
self.url = '/query/samples'
|
||||||
|
@ -21,12 +21,10 @@ import mock
|
|||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
|
|
||||||
from ceilometer.storage import models
|
from ceilometer.storage import models
|
||||||
from ceilometer.tests import db as tests_db
|
|
||||||
from ceilometer.tests.functional.api import v2
|
from ceilometer.tests.functional.api import v2
|
||||||
|
|
||||||
|
|
||||||
class TestComputeDurationByResource(v2.FunctionalTest,
|
class TestComputeDurationByResource(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestComputeDurationByResource, self).setUp()
|
super(TestComputeDurationByResource, self).setUp()
|
||||||
|
@ -30,8 +30,7 @@ HEADERS = {"X-Roles": "admin",
|
|||||||
"X-Project-Id": PROJ_ID}
|
"X-Project-Id": PROJ_ID}
|
||||||
|
|
||||||
|
|
||||||
class EventTestBase(v2.FunctionalTest,
|
class EventTestBase(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(EventTestBase, self).setUp()
|
super(EventTestBase, self).setUp()
|
||||||
@ -466,8 +465,7 @@ class TestEventAPI(EventTestBase):
|
|||||||
'op': 'el'}])
|
'op': 'el'}])
|
||||||
|
|
||||||
|
|
||||||
class AclRestrictedEventTestBase(v2.FunctionalTest,
|
class AclRestrictedEventTestBase(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(AclRestrictedEventTestBase, self).setUp()
|
super(AclRestrictedEventTestBase, self).setUp()
|
||||||
@ -595,8 +593,7 @@ class AclRestrictedEventTestBase(v2.FunctionalTest,
|
|||||||
self.assertEqual(0, len(data))
|
self.assertEqual(0, len(data))
|
||||||
|
|
||||||
|
|
||||||
class EventRestrictionTestBase(v2.FunctionalTest,
|
class EventRestrictionTestBase(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(EventRestrictionTestBase, self).setUp()
|
super(EventRestrictionTestBase, self).setUp()
|
||||||
|
@ -25,20 +25,17 @@ import webtest.app
|
|||||||
|
|
||||||
from ceilometer.publisher import utils
|
from ceilometer.publisher import utils
|
||||||
from ceilometer import sample
|
from ceilometer import sample
|
||||||
from ceilometer.tests import db as tests_db
|
|
||||||
from ceilometer.tests.functional.api import v2
|
from ceilometer.tests.functional.api import v2
|
||||||
|
|
||||||
|
|
||||||
class TestListEmptyMeters(v2.FunctionalTest,
|
class TestListEmptyMeters(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def test_empty(self):
|
def test_empty(self):
|
||||||
data = self.get_json('/meters')
|
data = self.get_json('/meters')
|
||||||
self.assertEqual([], data)
|
self.assertEqual([], data)
|
||||||
|
|
||||||
|
|
||||||
class TestValidateUserInput(v2.FunctionalTest,
|
class TestValidateUserInput(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def test_list_meters_query_float_metadata(self):
|
def test_list_meters_query_float_metadata(self):
|
||||||
self.assertRaises(webtest.app.AppError, self.get_json,
|
self.assertRaises(webtest.app.AppError, self.get_json,
|
||||||
@ -61,8 +58,7 @@ class TestValidateUserInput(v2.FunctionalTest,
|
|||||||
'type': 'integer'}])
|
'type': 'integer'}])
|
||||||
|
|
||||||
|
|
||||||
class TestListMetersRestriction(v2.FunctionalTest,
|
class TestListMetersRestriction(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestListMetersRestriction, self).setUp()
|
super(TestListMetersRestriction, self).setUp()
|
||||||
@ -141,8 +137,7 @@ class TestListMetersRestriction(v2.FunctionalTest,
|
|||||||
self.assertEqual(3, len(data))
|
self.assertEqual(3, len(data))
|
||||||
|
|
||||||
|
|
||||||
class TestListMeters(v2.FunctionalTest,
|
class TestListMeters(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestListMeters, self).setUp()
|
super(TestListMeters, self).setUp()
|
||||||
|
@ -23,12 +23,10 @@ import webtest.app
|
|||||||
|
|
||||||
from ceilometer.publisher import utils
|
from ceilometer.publisher import utils
|
||||||
from ceilometer import sample
|
from ceilometer import sample
|
||||||
from ceilometer.tests import db as tests_db
|
|
||||||
from ceilometer.tests.functional.api import v2
|
from ceilometer.tests.functional.api import v2
|
||||||
|
|
||||||
|
|
||||||
class TestListResources(v2.FunctionalTest,
|
class TestListResources(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def test_empty(self):
|
def test_empty(self):
|
||||||
data = self.get_json('/resources')
|
data = self.get_json('/resources')
|
||||||
@ -519,9 +517,7 @@ class TestListResources(v2.FunctionalTest,
|
|||||||
in links[0]['href'])
|
in links[0]['href'])
|
||||||
|
|
||||||
|
|
||||||
class TestListResourcesRestriction(v2.FunctionalTest,
|
class TestListResourcesRestriction(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestListResourcesRestriction, self).setUp()
|
super(TestListResourcesRestriction, self).setUp()
|
||||||
self.CONF.set_override('default_api_return_limit', 10, group='api')
|
self.CONF.set_override('default_api_return_limit', 10, group='api')
|
||||||
|
@ -23,12 +23,10 @@ import six
|
|||||||
|
|
||||||
from ceilometer.publisher import utils
|
from ceilometer.publisher import utils
|
||||||
from ceilometer import sample
|
from ceilometer import sample
|
||||||
from ceilometer.tests import db as tests_db
|
|
||||||
from ceilometer.tests.functional.api import v2
|
from ceilometer.tests.functional.api import v2
|
||||||
|
|
||||||
|
|
||||||
class TestListSamples(v2.FunctionalTest,
|
class TestListSamples(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestListSamples, self).setUp()
|
super(TestListSamples, self).setUp()
|
||||||
|
@ -22,12 +22,10 @@ import mock
|
|||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
from oslotest import mockpatch
|
from oslotest import mockpatch
|
||||||
|
|
||||||
from ceilometer.tests import db as tests_db
|
|
||||||
from ceilometer.tests.functional.api import v2
|
from ceilometer.tests.functional.api import v2
|
||||||
|
|
||||||
|
|
||||||
class TestPostSamples(v2.FunctionalTest,
|
class TestPostSamples(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
def fake_notifier_sample(self, ctxt, event_type, payload):
|
def fake_notifier_sample(self, ctxt, event_type, payload):
|
||||||
samples = payload['samples']
|
samples = payload['samples']
|
||||||
for m in samples:
|
for m in samples:
|
||||||
|
@ -22,9 +22,7 @@ from ceilometer.tests import db as tests_db
|
|||||||
from ceilometer.tests.functional.api import v2
|
from ceilometer.tests.functional.api import v2
|
||||||
|
|
||||||
|
|
||||||
class TestMaxProjectVolume(v2.FunctionalTest,
|
class TestMaxProjectVolume(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
PATH = '/meters/volume.size/statistics'
|
PATH = '/meters/volume.size/statistics'
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -119,9 +117,7 @@ class TestMaxProjectVolume(v2.FunctionalTest,
|
|||||||
self.assertEqual(1, data[0]['count'])
|
self.assertEqual(1, data[0]['count'])
|
||||||
|
|
||||||
|
|
||||||
class TestMaxResourceVolume(v2.FunctionalTest,
|
class TestMaxResourceVolume(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
PATH = '/meters/volume.size/statistics'
|
PATH = '/meters/volume.size/statistics'
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -248,8 +244,7 @@ class TestMaxResourceVolume(v2.FunctionalTest,
|
|||||||
self.assertEqual(1, data[0]['count'])
|
self.assertEqual(1, data[0]['count'])
|
||||||
|
|
||||||
|
|
||||||
class TestSumProjectVolume(v2.FunctionalTest,
|
class TestSumProjectVolume(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
PATH = '/meters/volume.size/statistics'
|
PATH = '/meters/volume.size/statistics'
|
||||||
|
|
||||||
@ -347,8 +342,7 @@ class TestSumProjectVolume(v2.FunctionalTest,
|
|||||||
self.assertEqual(1, data[0]['count'])
|
self.assertEqual(1, data[0]['count'])
|
||||||
|
|
||||||
|
|
||||||
class TestSumResourceVolume(v2.FunctionalTest,
|
class TestSumResourceVolume(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
PATH = '/meters/volume.size/statistics'
|
PATH = '/meters/volume.size/statistics'
|
||||||
|
|
||||||
@ -472,8 +466,7 @@ class TestSumResourceVolume(v2.FunctionalTest,
|
|||||||
self.assertEqual(1, data[0]['count'])
|
self.assertEqual(1, data[0]['count'])
|
||||||
|
|
||||||
|
|
||||||
class TestGroupByInstance(v2.FunctionalTest,
|
class TestGroupByInstance(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
PATH = '/meters/instance/statistics'
|
PATH = '/meters/instance/statistics'
|
||||||
|
|
||||||
@ -1216,8 +1209,7 @@ class TestGroupByInstance(v2.FunctionalTest,
|
|||||||
|
|
||||||
|
|
||||||
@tests_db.run_with('mongodb', 'hbase', 'db2')
|
@tests_db.run_with('mongodb', 'hbase', 'db2')
|
||||||
class TestGroupBySource(v2.FunctionalTest,
|
class TestGroupBySource(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
# FIXME(terriyu): We have to put test_group_by_source in its own class
|
# FIXME(terriyu): We have to put test_group_by_source in its own class
|
||||||
# because SQLAlchemy currently doesn't support group by source statistics.
|
# because SQLAlchemy currently doesn't support group by source statistics.
|
||||||
@ -1319,8 +1311,7 @@ class TestGroupBySource(v2.FunctionalTest,
|
|||||||
self.assertEqual(4, r['avg'])
|
self.assertEqual(4, r['avg'])
|
||||||
|
|
||||||
|
|
||||||
class TestSelectableAggregates(v2.FunctionalTest,
|
class TestSelectableAggregates(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
PATH = '/meters/instance/statistics'
|
PATH = '/meters/instance/statistics'
|
||||||
|
|
||||||
@ -1561,8 +1552,7 @@ class TestSelectableAggregates(v2.FunctionalTest,
|
|||||||
|
|
||||||
|
|
||||||
@tests_db.run_with('mongodb', 'hbase', 'db2')
|
@tests_db.run_with('mongodb', 'hbase', 'db2')
|
||||||
class TestUnparameterizedAggregates(v2.FunctionalTest,
|
class TestUnparameterizedAggregates(v2.FunctionalTest):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
# We put the stddev test case in a separate class so that we
|
# We put the stddev test case in a separate class so that we
|
||||||
# can easily exclude the sqlalchemy scenario, as sqlite doesn't
|
# can easily exclude the sqlalchemy scenario, as sqlite doesn't
|
||||||
|
@ -24,6 +24,7 @@ import uuid
|
|||||||
from gabbi import fixture
|
from gabbi import fixture
|
||||||
from oslo_config import fixture as fixture_config
|
from oslo_config import fixture as fixture_config
|
||||||
from oslo_policy import opts
|
from oslo_policy import opts
|
||||||
|
from six.moves.urllib import parse as urlparse
|
||||||
|
|
||||||
from ceilometer.event.storage import models
|
from ceilometer.event.storage import models
|
||||||
from ceilometer.publisher import utils
|
from ceilometer.publisher import utils
|
||||||
@ -31,11 +32,10 @@ from ceilometer import sample
|
|||||||
from ceilometer import service
|
from ceilometer import service
|
||||||
from ceilometer import storage
|
from ceilometer import storage
|
||||||
|
|
||||||
|
|
||||||
# TODO(chdent): For now only MongoDB is supported, because of easy
|
# TODO(chdent): For now only MongoDB is supported, because of easy
|
||||||
# database name handling and intentional focus on the API, not the
|
# database name handling and intentional focus on the API, not the
|
||||||
# data store.
|
# data store.
|
||||||
ENGINES = ['MONGODB']
|
ENGINES = ['mongodb']
|
||||||
|
|
||||||
|
|
||||||
class ConfigFixture(fixture.GabbiFixture):
|
class ConfigFixture(fixture.GabbiFixture):
|
||||||
@ -47,15 +47,14 @@ class ConfigFixture(fixture.GabbiFixture):
|
|||||||
self.conf = None
|
self.conf = None
|
||||||
|
|
||||||
# Determine the database connection.
|
# Determine the database connection.
|
||||||
db_url = None
|
db_url = os.environ.get('CEILOMETER_TEST_STORAGE_URL')
|
||||||
for engine in ENGINES:
|
if not db_url:
|
||||||
try:
|
|
||||||
db_url = os.environ['CEILOMETER_TEST_%s_URL' % engine]
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
if db_url is None:
|
|
||||||
raise case.SkipTest('No database connection configured')
|
raise case.SkipTest('No database connection configured')
|
||||||
|
|
||||||
|
engine = urlparse.urlparse(db_url).scheme
|
||||||
|
if engine not in ENGINES:
|
||||||
|
raise case.SkipTest('Database engine not supported')
|
||||||
|
|
||||||
service.prepare_service(argv=[], config_files=[])
|
service.prepare_service(argv=[], config_files=[])
|
||||||
conf = fixture_config.Config().conf
|
conf = fixture_config.Config().conf
|
||||||
self.conf = conf
|
self.conf = conf
|
||||||
|
@ -26,8 +26,7 @@ from ceilometer import sample
|
|||||||
from ceilometer.tests import db as tests_db
|
from ceilometer.tests import db as tests_db
|
||||||
|
|
||||||
|
|
||||||
class TestDirectPublisher(tests_db.TestBase,
|
class TestDirectPublisher(tests_db.TestBase):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
resource_id = str(uuid.uuid4())
|
resource_id = str(uuid.uuid4())
|
||||||
|
|
||||||
@ -83,9 +82,7 @@ class TestDirectPublisher(tests_db.TestBase,
|
|||||||
self.assertEqual(['alpha', 'beta', 'gamma'], names)
|
self.assertEqual(['alpha', 'beta', 'gamma'], names)
|
||||||
|
|
||||||
|
|
||||||
class TestEventDirectPublisher(tests_db.TestBase,
|
class TestEventDirectPublisher(tests_db.TestBase):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
test_data = [event.Event(message_id=str(uuid.uuid4()),
|
test_data = [event.Event(message_id=str(uuid.uuid4()),
|
||||||
event_type='event_%d' % i,
|
event_type='event_%d' % i,
|
||||||
generated=datetime.datetime.utcnow(),
|
generated=datetime.datetime.utcnow(),
|
||||||
|
@ -35,8 +35,7 @@ from ceilometer.tests import base as test_base
|
|||||||
from ceilometer.tests import db as tests_db
|
from ceilometer.tests import db as tests_db
|
||||||
|
|
||||||
|
|
||||||
class ConnectionTest(tests_db.TestBase,
|
class ConnectionTest(tests_db.TestBase):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
@tests_db.run_with('hbase')
|
@tests_db.run_with('hbase')
|
||||||
def test_hbase_connection(self):
|
def test_hbase_connection(self):
|
||||||
|
@ -28,8 +28,7 @@ from ceilometer.tests import db as tests_db
|
|||||||
|
|
||||||
|
|
||||||
@tests_db.run_with('mongodb')
|
@tests_db.run_with('mongodb')
|
||||||
class MongoDBConnection(tests_db.TestBase,
|
class MongoDBConnection(tests_db.TestBase):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
def test_connection_pooling(self):
|
def test_connection_pooling(self):
|
||||||
test_conn = impl_mongodb.Connection(self.db_manager.url)
|
test_conn = impl_mongodb.Connection(self.db_manager.url)
|
||||||
self.assertEqual(self.conn.conn, test_conn.conn)
|
self.assertEqual(self.conn.conn, test_conn.conn)
|
||||||
@ -51,8 +50,7 @@ class MongoDBConnection(tests_db.TestBase,
|
|||||||
|
|
||||||
|
|
||||||
@tests_db.run_with('mongodb')
|
@tests_db.run_with('mongodb')
|
||||||
class IndexTest(tests_db.TestBase,
|
class IndexTest(tests_db.TestBase):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def _test_ttl_index_absent(self, conn, coll_name, ttl_opt):
|
def _test_ttl_index_absent(self, conn, coll_name, ttl_opt):
|
||||||
# create a fake index and check it is deleted
|
# create a fake index and check it is deleted
|
||||||
|
@ -24,8 +24,7 @@ from ceilometer.tests.functional.storage import test_storage_scenarios
|
|||||||
|
|
||||||
|
|
||||||
@tests_db.run_with('mongodb', 'db2')
|
@tests_db.run_with('mongodb', 'db2')
|
||||||
class CompatibilityTest(test_storage_scenarios.DBTestBase,
|
class CompatibilityTest(test_storage_scenarios.DBTestBase):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def prepare_data(self):
|
def prepare_data(self):
|
||||||
def old_record_metering_data(self, data):
|
def old_record_metering_data(self, data):
|
||||||
|
@ -128,8 +128,7 @@ class DBTestBase(tests_db.TestBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ResourceTest(DBTestBase,
|
class ResourceTest(DBTestBase):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
def prepare_data(self):
|
def prepare_data(self):
|
||||||
super(ResourceTest, self).prepare_data()
|
super(ResourceTest, self).prepare_data()
|
||||||
|
|
||||||
@ -307,8 +306,7 @@ class ResourceTest(DBTestBase,
|
|||||||
self.assertEqual(expected_tag, resource.metadata['tag'])
|
self.assertEqual(expected_tag, resource.metadata['tag'])
|
||||||
|
|
||||||
|
|
||||||
class ResourceTestOrdering(DBTestBase,
|
class ResourceTestOrdering(DBTestBase):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
def prepare_data(self):
|
def prepare_data(self):
|
||||||
sample_timings = [('resource-id-1', [(2013, 8, 10, 10, 43),
|
sample_timings = [('resource-id-1', [(2013, 8, 10, 10, 43),
|
||||||
(2013, 8, 10, 10, 44),
|
(2013, 8, 10, 10, 44),
|
||||||
@ -358,9 +356,7 @@ class ResourceTestOrdering(DBTestBase,
|
|||||||
self.assertEqual('sample-8', resource.metadata['tag'])
|
self.assertEqual('sample-8', resource.metadata['tag'])
|
||||||
|
|
||||||
|
|
||||||
class MeterTest(DBTestBase,
|
class MeterTest(DBTestBase):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def test_get_meters(self):
|
def test_get_meters(self):
|
||||||
msgs_sources = [msg['source'] for msg in self.msgs]
|
msgs_sources = [msg['source'] for msg in self.msgs]
|
||||||
results = list(self.conn.get_meters())
|
results = list(self.conn.get_meters())
|
||||||
@ -387,8 +383,7 @@ class MeterTest(DBTestBase,
|
|||||||
self.assertEqual(9, len(results))
|
self.assertEqual(9, len(results))
|
||||||
|
|
||||||
|
|
||||||
class RawSampleTest(DBTestBase,
|
class RawSampleTest(DBTestBase):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def prepare_data(self):
|
def prepare_data(self):
|
||||||
super(RawSampleTest, self).prepare_data()
|
super(RawSampleTest, self).prepare_data()
|
||||||
@ -678,8 +673,7 @@ class RawSampleTest(DBTestBase,
|
|||||||
self.assertEqual(3, retry_sleep.call_count)
|
self.assertEqual(3, retry_sleep.call_count)
|
||||||
|
|
||||||
|
|
||||||
class ComplexSampleQueryTest(DBTestBase,
|
class ComplexSampleQueryTest(DBTestBase):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(ComplexSampleQueryTest, self).setUp()
|
super(ComplexSampleQueryTest, self).setUp()
|
||||||
self.complex_filter = {
|
self.complex_filter = {
|
||||||
@ -1079,9 +1073,7 @@ class ComplexSampleQueryTest(DBTestBase,
|
|||||||
[0.41, 0.8, 0.81])
|
[0.41, 0.8, 0.81])
|
||||||
|
|
||||||
|
|
||||||
class StatisticsTest(DBTestBase,
|
class StatisticsTest(DBTestBase):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def prepare_data(self):
|
def prepare_data(self):
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
c = sample.Sample(
|
c = sample.Sample(
|
||||||
@ -1335,9 +1327,7 @@ class StatisticsTest(DBTestBase,
|
|||||||
self.assertEqual([], results)
|
self.assertEqual([], results)
|
||||||
|
|
||||||
|
|
||||||
class StatisticsGroupByTest(DBTestBase,
|
class StatisticsGroupByTest(DBTestBase):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def prepare_data(self):
|
def prepare_data(self):
|
||||||
test_sample_data = (
|
test_sample_data = (
|
||||||
{'volume': 2, 'user': 'user-1', 'project': 'project-1',
|
{'volume': 2, 'user': 'user-1', 'project': 'project-1',
|
||||||
@ -2569,8 +2559,7 @@ class StatisticsGroupByTest(DBTestBase,
|
|||||||
[r.groupby, r.period_start])
|
[r.groupby, r.period_start])
|
||||||
|
|
||||||
|
|
||||||
class CounterDataTypeTest(DBTestBase,
|
class CounterDataTypeTest(DBTestBase):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
def prepare_data(self):
|
def prepare_data(self):
|
||||||
c = sample.Sample(
|
c = sample.Sample(
|
||||||
'dummyBigCounter',
|
'dummyBigCounter',
|
||||||
@ -2645,8 +2634,7 @@ class CounterDataTypeTest(DBTestBase,
|
|||||||
self.assertEqual(1938495037.53697, results[0].counter_volume)
|
self.assertEqual(1938495037.53697, results[0].counter_volume)
|
||||||
|
|
||||||
|
|
||||||
class EventTestBase(tests_db.TestBase,
|
class EventTestBase(tests_db.TestBase):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
"""Separate test base class.
|
"""Separate test base class.
|
||||||
|
|
||||||
We don't want to inherit all the Meter stuff.
|
We don't want to inherit all the Meter stuff.
|
||||||
@ -3079,8 +3067,7 @@ class GetEventTest(EventTestBase):
|
|||||||
options.remove((trait.dtype, trait.value))
|
options.remove((trait.dtype, trait.value))
|
||||||
|
|
||||||
|
|
||||||
class BigIntegerTest(tests_db.TestBase,
|
class BigIntegerTest(tests_db.TestBase):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
def test_metadata_bigint(self):
|
def test_metadata_bigint(self):
|
||||||
metadata = {'bigint': 99999999999999}
|
metadata = {'bigint': 99999999999999}
|
||||||
s = sample.Sample(name='name',
|
s = sample.Sample(name='name',
|
||||||
@ -3098,9 +3085,7 @@ class BigIntegerTest(tests_db.TestBase,
|
|||||||
|
|
||||||
|
|
||||||
@tests_db.run_with('mongodb')
|
@tests_db.run_with('mongodb')
|
||||||
class MongoAutoReconnectTest(DBTestBase,
|
class MongoAutoReconnectTest(DBTestBase):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(MongoAutoReconnectTest, self).setUp()
|
super(MongoAutoReconnectTest, self).setUp()
|
||||||
self.CONF.set_override('retry_interval', 0, group='database')
|
self.CONF.set_override('retry_interval', 0, group='database')
|
||||||
@ -3172,7 +3157,7 @@ class MongoAutoReconnectTest(DBTestBase,
|
|||||||
|
|
||||||
|
|
||||||
@tests_db.run_with('mongodb')
|
@tests_db.run_with('mongodb')
|
||||||
class MongoTimeToLiveTest(DBTestBase, tests_db.MixinTestsWithBackendScenarios):
|
class MongoTimeToLiveTest(DBTestBase):
|
||||||
|
|
||||||
def test_ensure_index(self):
|
def test_ensure_index(self):
|
||||||
cfg.CONF.set_override('metering_time_to_live', 5, group='database')
|
cfg.CONF.set_override('metering_time_to_live', 5, group='database')
|
||||||
@ -3193,8 +3178,7 @@ class MongoTimeToLiveTest(DBTestBase, tests_db.MixinTestsWithBackendScenarios):
|
|||||||
['meter_ttl']['expireAfterSeconds'])
|
['meter_ttl']['expireAfterSeconds'])
|
||||||
|
|
||||||
|
|
||||||
class TestRecordUnicodeSamples(DBTestBase,
|
class TestRecordUnicodeSamples(DBTestBase):
|
||||||
tests_db.MixinTestsWithBackendScenarios):
|
|
||||||
def prepare_data(self):
|
def prepare_data(self):
|
||||||
self.msgs = []
|
self.msgs = []
|
||||||
self.msgs.append(self.create_and_store_sample(
|
self.msgs.append(self.create_and_store_sample(
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
function clean_exit(){
|
function clean_exit(){
|
||||||
local error_code="$?"
|
local error_code="$?"
|
||||||
if test -n "$CEILOMETER_TEST_HBASE_URL"
|
|
||||||
then
|
|
||||||
python tools/test_hbase_table_utils.py --clear
|
|
||||||
fi
|
|
||||||
rm -rf "$1"
|
rm -rf "$1"
|
||||||
kill $(jobs -p)
|
kill $(jobs -p)
|
||||||
return $error_code
|
return $error_code
|
||||||
|
@ -32,7 +32,7 @@ elasticsearch -p ${ES_PID} -Des.http.port=${ES_PORT} -Des.path.logs=${ES_DATA}/l
|
|||||||
# Wait for ElasticSearch to start listening to connections
|
# Wait for ElasticSearch to start listening to connections
|
||||||
sleep 3
|
sleep 3
|
||||||
wait_for_line "started" ${ES_DATA}/out
|
wait_for_line "started" ${ES_DATA}/out
|
||||||
export CEILOMETER_TEST_ES_URL="es://localhost:${ES_PORT}"
|
export CEILOMETER_TEST_STORAGE_URL="es://localhost:${ES_PORT}"
|
||||||
|
|
||||||
# Yield execution to venv command
|
# Yield execution to venv command
|
||||||
$*
|
$*
|
||||||
|
@ -21,12 +21,7 @@ mongod --maxConns 32 --nojournal --noprealloc --smallfiles --quiet --noauth --po
|
|||||||
wait_for_line "waiting for connections on port ${MONGO_PORT}" ${MONGO_DATA}/out
|
wait_for_line "waiting for connections on port ${MONGO_PORT}" ${MONGO_DATA}/out
|
||||||
# Read the fifo for ever otherwise mongod would block
|
# Read the fifo for ever otherwise mongod would block
|
||||||
cat ${MONGO_DATA}/out > /dev/null &
|
cat ${MONGO_DATA}/out > /dev/null &
|
||||||
export CEILOMETER_TEST_MONGODB_URL="mongodb://localhost:${MONGO_PORT}/ceilometer"
|
export CEILOMETER_TEST_STORAGE_URL="mongodb://localhost:${MONGO_PORT}/ceilometer"
|
||||||
if test -n "$CEILOMETER_TEST_HBASE_URL"
|
|
||||||
then
|
|
||||||
export CEILOMETER_TEST_HBASE_TABLE_PREFIX=$(hexdump -n 16 -v -e '/1 "%02X"' /dev/urandom)
|
|
||||||
python tools/test_hbase_table_utils.py --upgrade
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Yield execution to venv command
|
# Yield execution to venv command
|
||||||
$*
|
$*
|
||||||
|
@ -22,7 +22,7 @@ mkfifo ${MYSQL_DATA}/out
|
|||||||
mysqld --datadir=${MYSQL_DATA} --pid-file=${MYSQL_DATA}/mysql.pid --socket=${MYSQL_DATA}/mysql.socket --skip-networking --skip-grant-tables &> ${MYSQL_DATA}/out &
|
mysqld --datadir=${MYSQL_DATA} --pid-file=${MYSQL_DATA}/mysql.pid --socket=${MYSQL_DATA}/mysql.socket --skip-networking --skip-grant-tables &> ${MYSQL_DATA}/out &
|
||||||
# Wait for MySQL to start listening to connections
|
# Wait for MySQL to start listening to connections
|
||||||
wait_for_line "mysqld: ready for connections." ${MYSQL_DATA}/out
|
wait_for_line "mysqld: ready for connections." ${MYSQL_DATA}/out
|
||||||
export CEILOMETER_TEST_MYSQL_URL="mysql+pymysql://root@localhost/template1?unix_socket=${MYSQL_DATA}/mysql.socket&charset=utf8"
|
export CEILOMETER_TEST_STORAGE_URL="mysql+pymysql://root@localhost/template1?unix_socket=${MYSQL_DATA}/mysql.socket&charset=utf8"
|
||||||
|
|
||||||
# Yield execution to venv command
|
# Yield execution to venv command
|
||||||
$*
|
$*
|
||||||
|
@ -28,7 +28,7 @@ ${PGSQL_PATH}/initdb -E UTF8 ${PGSQL_DATA}
|
|||||||
trap "clean_exit_pgsql ${PGSQL_PATH} ${PGSQL_DATA} ${PGSQL_PORT}" EXIT
|
trap "clean_exit_pgsql ${PGSQL_PATH} ${PGSQL_DATA} ${PGSQL_PORT}" EXIT
|
||||||
|
|
||||||
LANGUAGE=C ${PGSQL_PATH}/pg_ctl -w -D ${PGSQL_DATA} -o "-F -k ${PGSQL_DATA} -p ${PGSQL_PORT}" start
|
LANGUAGE=C ${PGSQL_PATH}/pg_ctl -w -D ${PGSQL_DATA} -o "-F -k ${PGSQL_DATA} -p ${PGSQL_PORT}" start
|
||||||
export CEILOMETER_TEST_PGSQL_URL="postgresql:///?host=${PGSQL_DATA}&port=${PGSQL_PORT}&dbname=template1"
|
export CEILOMETER_TEST_STORAGE_URL="postgresql:///?host=${PGSQL_DATA}&port=${PGSQL_PORT}&dbname=template1"
|
||||||
|
|
||||||
# Yield execution to venv command
|
# Yield execution to venv command
|
||||||
$*
|
$*
|
||||||
|
@ -22,9 +22,9 @@ from ceilometer import storage
|
|||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
cfg.CONF([], project='ceilometer')
|
cfg.CONF([], project='ceilometer')
|
||||||
if os.getenv("CEILOMETER_TEST_HBASE_URL"):
|
if os.getenv("CEILOMETER_TEST_STORAGE_URL", "").startswith("hbase://"):
|
||||||
url = ("%s?table_prefix=%s" %
|
url = ("%s?table_prefix=%s" %
|
||||||
(os.getenv("CEILOMETER_TEST_HBASE_URL"),
|
(os.getenv("CEILOMETER_TEST_STORAGE_URL"),
|
||||||
os.getenv("CEILOMETER_TEST_HBASE_TABLE_PREFIX", "test")))
|
os.getenv("CEILOMETER_TEST_HBASE_TABLE_PREFIX", "test")))
|
||||||
conn = storage.get_connection(url, 'ceilometer.metering.storage')
|
conn = storage.get_connection(url, 'ceilometer.metering.storage')
|
||||||
event_conn = storage.get_connection(url, 'ceilometer.event.storage')
|
event_conn = storage.get_connection(url, 'ceilometer.event.storage')
|
||||||
|
Loading…
Reference in New Issue
Block a user