From 0a76fd04cc84bca121c0d7ff3802c8052ce6d787 Mon Sep 17 00:00:00 2001 From: lizheming Date: Sat, 18 Jan 2014 14:23:02 +0800 Subject: [PATCH] use six.move.xrange replace xrange in python3.x, there is no method named xrange(), it has replaced by range(),which is equal to xrange() in python2.x. so we must fix this issue. we use six moduleto fix this issue. Closes-Bug: #1268439 Change-Id: I7aa8fe80155710cd639721d4b3d5bd9b4219e27d --- ceilometer/storage/base.py | 4 ++- .../tests/alarm/evaluator/test_threshold.py | 34 ++++++++++--------- .../alarm/partition/test_coordination.py | 23 +++++++------ .../tests/api/v2/test_alarm_scenarios.py | 6 ++-- 4 files changed, 37 insertions(+), 30 deletions(-) diff --git a/ceilometer/storage/base.py b/ceilometer/storage/base.py index b7abf354d..e65811b58 100644 --- a/ceilometer/storage/base.py +++ b/ceilometer/storage/base.py @@ -23,6 +23,8 @@ import datetime import math import six +from six import moves + from ceilometer.openstack.common.gettextutils import _ # noqa from ceilometer.openstack.common import timeutils @@ -39,7 +41,7 @@ def iter_period(start, end, period): """ period_start = start increment = datetime.timedelta(seconds=period) - for i in xrange(int(math.ceil( + for i in moves.xrange(int(math.ceil( timeutils.delta_seconds(start, end) / float(period)))): next_start = period_start + increment diff --git a/ceilometer/tests/alarm/evaluator/test_threshold.py b/ceilometer/tests/alarm/evaluator/test_threshold.py index 86def6879..fae63d191 100644 --- a/ceilometer/tests/alarm/evaluator/test_threshold.py +++ b/ceilometer/tests/alarm/evaluator/test_threshold.py @@ -21,6 +21,8 @@ import datetime import mock import uuid +from six import moves + from ceilometer.alarm.evaluator import threshold from ceilometer.openstack.common import timeutils from ceilometer.storage import models @@ -102,9 +104,9 @@ class TestEvaluate(base.TestEvaluatorBase): return_value=self.api_client): broken = exc.CommunicationError(message='broken') avgs = [self._get_stat('avg', self.alarms[0].rule['threshold'] - v) - for v in xrange(5)] + for v in moves.xrange(5)] maxs = [self._get_stat('max', self.alarms[1].rule['threshold'] + v) - for v in xrange(1, 4)] + for v in moves.xrange(1, 4)] self.api_client.statistics.list.side_effect = [broken, broken, avgs, @@ -137,9 +139,9 @@ class TestEvaluate(base.TestEvaluatorBase): with mock.patch('ceilometerclient.client.get_client', return_value=self.api_client): avgs = [self._get_stat('avg', self.alarms[0].rule['threshold'] + v) - for v in xrange(1, 6)] + for v in moves.xrange(1, 6)] maxs = [self._get_stat('max', self.alarms[1].rule['threshold'] - v) - for v in xrange(4)] + for v in moves.xrange(4)] self.api_client.statistics.list.side_effect = [avgs, maxs] self._evaluate_all_alarms() self._assert_all_alarms('alarm') @@ -160,9 +162,9 @@ class TestEvaluate(base.TestEvaluatorBase): with mock.patch('ceilometerclient.client.get_client', return_value=self.api_client): avgs = [self._get_stat('avg', self.alarms[0].rule['threshold'] - v) - for v in xrange(5)] + for v in moves.xrange(5)] maxs = [self._get_stat('max', self.alarms[1].rule['threshold'] + v) - for v in xrange(1, 5)] + for v in moves.xrange(1, 5)] self.api_client.statistics.list.side_effect = [avgs, maxs] self._evaluate_all_alarms() self._assert_all_alarms('ok') @@ -183,9 +185,9 @@ class TestEvaluate(base.TestEvaluatorBase): with mock.patch('ceilometerclient.client.get_client', return_value=self.api_client): avgs = [self._get_stat('avg', self.alarms[0].rule['threshold'] + v) - for v in xrange(5)] + for v in moves.xrange(5)] maxs = [self._get_stat('max', self.alarms[1].rule['threshold'] - v) - for v in xrange(-1, 3)] + for v in moves.xrange(-1, 3)] self.api_client.statistics.list.side_effect = [avgs, maxs] self._evaluate_all_alarms() self._assert_all_alarms('ok') @@ -199,9 +201,9 @@ class TestEvaluate(base.TestEvaluatorBase): with mock.patch('ceilometerclient.client.get_client', return_value=self.api_client): avgs = [self._get_stat('avg', self.alarms[0].rule['threshold'] + v) - for v in xrange(5)] + for v in moves.xrange(5)] maxs = [self._get_stat('max', self.alarms[1].rule['threshold'] - v) - for v in xrange(-1, 3)] + for v in moves.xrange(-1, 3)] self.api_client.statistics.list.side_effect = [avgs, maxs] self._evaluate_all_alarms() self._assert_all_alarms('ok') @@ -218,9 +220,9 @@ class TestEvaluate(base.TestEvaluatorBase): with mock.patch('ceilometerclient.client.get_client', return_value=self.api_client): avgs = [self._get_stat('avg', self.alarms[0].rule['threshold'] + v) - for v in xrange(1, 6)] + for v in moves.xrange(1, 6)] maxs = [self._get_stat('max', self.alarms[1].rule['threshold'] - v) - for v in xrange(4)] + for v in moves.xrange(4)] self.api_client.statistics.list.side_effect = [avgs, maxs] self._evaluate_all_alarms() self._assert_all_alarms('alarm') @@ -238,9 +240,9 @@ class TestEvaluate(base.TestEvaluatorBase): with mock.patch('ceilometerclient.client.get_client', return_value=self.api_client): avgs = [self._get_stat('avg', self.alarms[0].rule['threshold'] + v) - for v in xrange(1, 6)] + for v in moves.xrange(1, 6)] maxs = [self._get_stat('max', self.alarms[1].rule['threshold'] - v) - for v in xrange(4)] + for v in moves.xrange(4)] self.api_client.statistics.list.side_effect = [avgs, maxs] self._evaluate_all_alarms() self._assert_all_alarms('alarm') @@ -261,9 +263,9 @@ class TestEvaluate(base.TestEvaluatorBase): with mock.patch('ceilometerclient.client.get_client', return_value=self.api_client): avgs = [self._get_stat('avg', self.alarms[0].rule['threshold'] + v) - for v in xrange(1, 6)] + for v in moves.xrange(1, 6)] maxs = [self._get_stat('max', self.alarms[1].rule['threshold'] - v) - for v in xrange(4)] + for v in moves.xrange(4)] self.api_client.statistics.list.side_effect = [avgs, maxs] self._evaluate_all_alarms() self._assert_all_alarms('alarm') diff --git a/ceilometer/tests/alarm/partition/test_coordination.py b/ceilometer/tests/alarm/partition/test_coordination.py index 98be94c33..e0c7a99b6 100644 --- a/ceilometer/tests/alarm/partition/test_coordination.py +++ b/ceilometer/tests/alarm/partition/test_coordination.py @@ -23,6 +23,7 @@ import StringIO import uuid import mock +from six import moves from ceilometer.alarm.partition import coordination from ceilometer.openstack.common.fixture import config @@ -60,7 +61,7 @@ class TestCoordinate(test.BaseTestCase): self.api_client.alarms.list.return_value = [] def _some_alarms(self, count): - alarm_ids = [str(uuid.uuid4()) for _ in xrange(count)] + alarm_ids = [str(uuid.uuid4()) for _ in moves.xrange(count)] alarms = [self._make_alarm(aid) for aid in alarm_ids] self.api_client.alarms.list.return_value = alarms return alarm_ids @@ -76,7 +77,7 @@ class TestCoordinate(test.BaseTestCase): return alarm_ids def _add_alarms(self, boost): - new_alarm_ids = [str(uuid.uuid4()) for _ in xrange(boost)] + new_alarm_ids = [str(uuid.uuid4()) for _ in moves.xrange(boost)] alarms = self.api_client.alarms.list.return_value for aid in new_alarm_ids: alarms.append(self._make_alarm(aid)) @@ -167,7 +168,7 @@ class TestCoordinate(test.BaseTestCase): def test_mastership_not_assumed_during_warmup(self): self._no_alarms() - for _ in xrange(7): + for _ in moves.xrange(7): # still warming up self._advance_time(0.25) self._check_mastership(False) @@ -188,7 +189,7 @@ class TestCoordinate(test.BaseTestCase): self._advance_time(3) - for offset in xrange(1, 5): + for offset in moves.xrange(1, 5): younger = self._younger_by(offset) self.partition_coordinator.presence(uuid.uuid4(), younger) @@ -230,7 +231,7 @@ class TestCoordinate(test.BaseTestCase): self._advance_time(3) - others = [self._new_partition(i) for i in xrange(1, 5)] + others = [self._new_partition(i) for i in moves.xrange(1, 5)] self._check_mastership(True) @@ -243,7 +244,7 @@ class TestCoordinate(test.BaseTestCase): self._advance_time(3) - others = [self._new_partition(i) for i in xrange(1, 5)] + others = [self._new_partition(i) for i in moves.xrange(1, 5)] self._check_mastership(True) @@ -261,7 +262,7 @@ class TestCoordinate(test.BaseTestCase): self._advance_time(3) - others = [self._new_partition(i) for i in xrange(1, 5)] + others = [self._new_partition(i) for i in moves.xrange(1, 5)] self._check_mastership(True) @@ -284,7 +285,7 @@ class TestCoordinate(test.BaseTestCase): self._advance_time(3) - others = [self._new_partition(i) for i in xrange(1, 5)] + others = [self._new_partition(i) for i in moves.xrange(1, 5)] self._check_mastership(True) @@ -303,7 +304,7 @@ class TestCoordinate(test.BaseTestCase): self._advance_time(3) - others = [self._new_partition(i) for i in xrange(1, 5)] + others = [self._new_partition(i) for i in moves.xrange(1, 5)] self._check_mastership(True) @@ -321,7 +322,7 @@ class TestCoordinate(test.BaseTestCase): self._advance_time(3) - others = [self._new_partition(i) for i in xrange(1, 5)] + others = [self._new_partition(i) for i in moves.xrange(1, 5)] self._check_mastership(True) @@ -342,7 +343,7 @@ class TestCoordinate(test.BaseTestCase): self._advance_time(3) - for i in xrange(1, 5): + for i in moves.xrange(1, 5): self._new_partition(i) def overtake(*args): diff --git a/ceilometer/tests/api/v2/test_alarm_scenarios.py b/ceilometer/tests/api/v2/test_alarm_scenarios.py index 067827cf5..0df669bd9 100644 --- a/ceilometer/tests/api/v2/test_alarm_scenarios.py +++ b/ceilometer/tests/api/v2/test_alarm_scenarios.py @@ -26,6 +26,8 @@ import logging import uuid import mock + +from six import moves import testscenarios from ceilometer.storage import models @@ -1177,7 +1179,7 @@ class TestAlarms(FunctionalTest, def test_get_alarm_history_ordered_by_recentness(self): alarm = self._get_alarm('a') - for i in xrange(10): + for i in moves.xrange(10): self._update_alarm(alarm, dict(name='%s' % i)) alarm = self._get_alarm('a') self._delete_alarm(alarm) @@ -1189,7 +1191,7 @@ class TestAlarms(FunctionalTest, alarm['rule'] = alarm['threshold_rule'] del alarm['threshold_rule'] self._assert_in_json(alarm, history[0]['detail']) - for i in xrange(1, 10): + for i in moves.xrange(1, 10): detail = '{"name": "%s"}' % (10 - i) self._assert_is_subset(dict(alarm_id=alarm['alarm_id'], detail=detail,