Change metadata_int's value field to type bigint

Change-Id: Icac8bd1cf55da9f645b5e27c45b6c2c918dcdab3
Closes-Bug: 1254604
This commit is contained in:
Lianhao Lu 2013-11-25 15:34:41 +08:00
parent ff20b3986f
commit 75c382141c
4 changed files with 57 additions and 5 deletions

View File

@ -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}

View File

@ -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)

View File

@ -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):

View File

@ -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)