diff --git a/ceilometer/storage/impl_sqlalchemy.py b/ceilometer/storage/impl_sqlalchemy.py index d0f6f0c4f..fabd5095a 100644 --- a/ceilometer/storage/impl_sqlalchemy.py +++ b/ceilometer/storage/impl_sqlalchemy.py @@ -96,8 +96,8 @@ META_TYPE_MAP = {bool: models.MetaBool, str: models.MetaText, unicode: models.MetaText, types.NoneType: models.MetaText, - int: models.MetaInt, - long: models.MetaInt, + int: models.MetaBigInt, + long: models.MetaBigInt, float: models.MetaFloat} diff --git a/ceilometer/storage/sqlalchemy/migrate_repo/versions/022_metadata_int_is_bigint.py b/ceilometer/storage/sqlalchemy/migrate_repo/versions/022_metadata_int_is_bigint.py new file mode 100644 index 000000000..aaa438f2d --- /dev/null +++ b/ceilometer/storage/sqlalchemy/migrate_repo/versions/022_metadata_int_is_bigint.py @@ -0,0 +1,34 @@ +# -*- encoding: utf-8 -*- + +# Copyright 2013 OpenStack Foundation +# All Rights Reserved. +# Copyright 2013 IBM Corp. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from sqlalchemy import BigInteger +from sqlalchemy import Integer +from sqlalchemy import MetaData +from sqlalchemy import Table + + +def upgrade(migrate_engine): + meta = MetaData(bind=migrate_engine) + resource = Table('metadata_int', meta, autoload=True) + resource.c.value.alter(type=BigInteger) + + +def downgrade(migrate_engine): + meta = MetaData(bind=migrate_engine) + resource = Table('metadata_int', meta, autoload=True) + resource.c.value.alter(type=Integer) diff --git a/ceilometer/storage/sqlalchemy/models.py b/ceilometer/storage/sqlalchemy/models.py index faa8f26b5..6c20434ca 100644 --- a/ceilometer/storage/sqlalchemy/models.py +++ b/ceilometer/storage/sqlalchemy/models.py @@ -23,7 +23,7 @@ import urlparse from oslo.config import cfg from sqlalchemy import Column, Integer, String, Table, ForeignKey, DateTime, \ - Index, UniqueConstraint + Index, UniqueConstraint, BigInteger from sqlalchemy import Float, Boolean, Text from sqlalchemy.dialects.mysql import DECIMAL from sqlalchemy.ext.declarative import declarative_base @@ -165,7 +165,7 @@ class MetaBool(Base): value = Column(Boolean) -class MetaInt(Base): +class MetaBigInt(Base): """Metering integer metadata.""" __tablename__ = 'metadata_int' @@ -174,7 +174,7 @@ class MetaInt(Base): ) id = Column(Integer, ForeignKey('meter.id'), primary_key=True) meta_key = Column(String(255), primary_key=True) - value = Column(Integer, default=False) + value = Column(BigInteger, default=False) class MetaFloat(Base): diff --git a/ceilometer/tests/storage/test_storage_scenarios.py b/ceilometer/tests/storage/test_storage_scenarios.py index df30fae5f..374cc653e 100644 --- a/ceilometer/tests/storage/test_storage_scenarios.py +++ b/ceilometer/tests/storage/test_storage_scenarios.py @@ -2161,3 +2161,21 @@ class GetEventTest(EventTestBase): self.assertEqual(events[0].message_id, "id_notraits") self.assertEqual(events[0].event_type, "NoTraits") self.assertEqual(0, len(events[0].traits)) + + +class BigIntegerTest(tests_db.TestBase, + tests_db.MixinTestsWithBackendScenarios): + def test_metadata_bigint(self): + metadata = {'bigint': 99999999999999} + s = sample.Sample(name='name', + type=sample.TYPE_GAUGE, + unit='B', + volume=1, + user_id='user-id', + project_id='project-id', + resource_id='resource-id', + timestamp=datetime.datetime.utcnow(), + resource_metadata=metadata) + msg = rpc.meter_message_from_counter( + s, self.CONF.publisher_rpc.metering_secret) + self.conn.record_metering_data(msg)