From 53e442a8b47bdb1a9f407e194b37ce16a6837a66 Mon Sep 17 00:00:00 2001 From: Dina Belova Date: Fri, 25 Jul 2014 14:42:40 +0400 Subject: [PATCH] basestring replaced with six.string_types That's needed to move further in py3 compatibility. Partially-Implements: blueprint ceilometer-py33-support Change-Id: I5796de3b3f359c95ddc059374e19f7e7154e45c6 --- ceilometer/api/controllers/v2.py | 2 +- ceilometer/compute/util.py | 3 ++- .../migrate_repo/versions/020_add_metadata_tables.py | 3 ++- ceilometer/tests/alarm/test_rpc.py | 3 ++- ceilometer/transformer/conversions.py | 4 +++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ceilometer/api/controllers/v2.py b/ceilometer/api/controllers/v2.py index 646d02ee..34fb4bb7 100644 --- a/ceilometer/api/controllers/v2.py +++ b/ceilometer/api/controllers/v2.py @@ -661,7 +661,7 @@ class OldSample(_Base): counter_volume = float(counter_volume) resource_metadata = _flatten_metadata(resource_metadata) # this is to make it easier for clients to pass a timestamp in - if timestamp and isinstance(timestamp, basestring): + if timestamp and isinstance(timestamp, six.string_types): timestamp = timeutils.parse_isotime(timestamp) super(OldSample, self).__init__(counter_volume=counter_volume, diff --git a/ceilometer/compute/util.py b/ceilometer/compute/util.py index fbf21454..56b3b1f5 100644 --- a/ceilometer/compute/util.py +++ b/ceilometer/compute/util.py @@ -16,6 +16,7 @@ # under the License. from oslo.config import cfg +import six OPTS = [ @@ -36,7 +37,7 @@ def add_reserved_user_metadata(src_metadata, dest_metadata): for prefix in cfg.CONF.reserved_metadata_namespace: md = dict( (k[len(prefix):].replace('.', '_'), - v[:limit] if isinstance(v, basestring) else v) + v[:limit] if isinstance(v, six.string_types) else v) for k, v in src_metadata.items() if (k.startswith(prefix) and k[len(prefix):].replace('.', '_') not in dest_metadata) diff --git a/ceilometer/storage/sqlalchemy/migrate_repo/versions/020_add_metadata_tables.py b/ceilometer/storage/sqlalchemy/migrate_repo/versions/020_add_metadata_tables.py index e22fe5d0..058a317d 100644 --- a/ceilometer/storage/sqlalchemy/migrate_repo/versions/020_add_metadata_tables.py +++ b/ceilometer/storage/sqlalchemy/migrate_repo/versions/020_add_metadata_tables.py @@ -15,6 +15,7 @@ # under the License. import json +import six from sqlalchemy import Boolean from sqlalchemy import Column from sqlalchemy import Float @@ -55,7 +56,7 @@ def upgrade(migrate_engine): rmeta = json.loads(row['resource_metadata']) for key, v in utils.dict_to_keyval(rmeta): ins = None - if isinstance(v, basestring) or v is None: + if isinstance(v, six.string_types) or v is None: ins = meta_tables['metadata_text'].insert() elif isinstance(v, bool): ins = meta_tables['metadata_bool'].insert() diff --git a/ceilometer/tests/alarm/test_rpc.py b/ceilometer/tests/alarm/test_rpc.py index 292c5158..3b286761 100644 --- a/ceilometer/tests/alarm/test_rpc.py +++ b/ceilometer/tests/alarm/test_rpc.py @@ -19,6 +19,7 @@ import uuid from ceilometerclient.v2 import alarms import eventlet +import six from ceilometer.alarm import rpc as rpc_alarm from ceilometer.alarm.storage import models @@ -122,7 +123,7 @@ class TestRPCAlarmNotifier(tests_base.BaseTestCase): self.notifier.notify(self.alarms[0], 'ok', 42, {}) self.notifier_server.rpc.wait() reason = self.notifier_server.notified[0]['reason'] - self.assertIsInstance(reason, basestring) + self.assertIsInstance(reason, six.string_types) def test_notify_no_actions(self): alarm = alarms.Alarm(None, info={ diff --git a/ceilometer/transformer/conversions.py b/ceilometer/transformer/conversions.py index 7e1cbb6f..960297a5 100644 --- a/ceilometer/transformer/conversions.py +++ b/ceilometer/transformer/conversions.py @@ -17,6 +17,8 @@ import re +import six + from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log from ceilometer.openstack.common import timeutils @@ -56,7 +58,7 @@ class ScalingTransformer(transformer.TransformerBase): ns = transformer.Namespace(s.as_dict()) scale = self.scale - return ((eval(scale, {}, ns) if isinstance(scale, basestring) + return ((eval(scale, {}, ns) if isinstance(scale, six.string_types) else s.volume * scale) if scale else s.volume) def _map(self, s, attr):