From 03a24cabb1faeb542e3de6f41ccc9b7b73752f0f Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 2 Jun 2015 16:24:58 +0200 Subject: [PATCH] Stop using deprecated oslo_utils.timeutils.strtime() This function has been deprecated in oslo.utils. Let's replace it with a proper ISO8601 version. Change-Id: I1f4c44fc86b1ee45f7e2e3cb6b4347d3c2f91a1a --- .../openstack/heat/software_deployment.py | 2 +- heat/engine/service_software_config.py | 2 +- heat/scaling/cooldown.py | 2 +- heat/tests/autoscaling/test_heat_scaling_policy.py | 14 +++++++------- heat/tests/autoscaling/test_scaling_policy.py | 14 +++++++------- heat/tests/engine/test_software_config.py | 6 +++--- heat/tests/test_swift_client.py | 3 +-- 7 files changed, 21 insertions(+), 22 deletions(-) diff --git a/heat/engine/resources/openstack/heat/software_deployment.py b/heat/engine/resources/openstack/heat/software_deployment.py index 53e0549c71..321a931127 100644 --- a/heat/engine/resources/openstack/heat/software_deployment.py +++ b/heat/engine/resources/openstack/heat/software_deployment.py @@ -534,7 +534,7 @@ class SoftwareDeployment(signal_responder.SignalResponder): def handle_signal(self, details): return self.rpc_client().signal_software_deployment( self.context, self.resource_id, details, - timeutils.strtime()) + timeutils.utcnow().isoformat()) def FnGetAtt(self, key, *path): ''' diff --git a/heat/engine/service_software_config.py b/heat/engine/service_software_config.py index 19d01dbd00..1783566bd5 100644 --- a/heat/engine/service_software_config.py +++ b/heat/engine/service_software_config.py @@ -131,7 +131,7 @@ class SoftwareConfigService(service.Service): if obj: self.signal_software_deployment( cnxt, sd.id, jsonutils.loads(obj), - timeutils.strtime(last_modified)) + last_modified.isoformat()) return software_deployment_object.SoftwareDeployment.get_by_id( cnxt, sd.id) diff --git a/heat/scaling/cooldown.py b/heat/scaling/cooldown.py index ef4fdc78d6..75a55b9bbf 100644 --- a/heat/scaling/cooldown.py +++ b/heat/scaling/cooldown.py @@ -41,5 +41,5 @@ class CooldownMixin(object): # If we wanted to implement the AutoScaling API like AWS does, # we could maintain event history here, but since we only need # the latest event for cooldown, just store that for now - metadata = {timeutils.strtime(): reason} + metadata = {timeutils.utcnow().isoformat(): reason} self.metadata_set(metadata) diff --git a/heat/tests/autoscaling/test_heat_scaling_policy.py b/heat/tests/autoscaling/test_heat_scaling_policy.py index e81329cef2..eaeccc4f17 100644 --- a/heat/tests/autoscaling/test_heat_scaling_policy.py +++ b/heat/tests/autoscaling/test_heat_scaling_policy.py @@ -146,7 +146,7 @@ class TestCooldownMixin(common.HeatTestCase): pol = self.create_scaling_policy(t, stack, 'my-policy') now = timeutils.utcnow() - previous_meta = {timeutils.strtime(now): 'ChangeInCapacity : 1'} + previous_meta = {now.isoformat(): 'ChangeInCapacity : 1'} self.patchobject(pol, 'metadata_get', return_value=previous_meta) self.assertTrue(pol._cooldown_inprogress()) @@ -156,7 +156,7 @@ class TestCooldownMixin(common.HeatTestCase): pol = self.create_scaling_policy(t, stack, 'my-policy') awhile_ago = timeutils.utcnow() - datetime.timedelta(seconds=100) - previous_meta = {timeutils.strtime(awhile_ago): 'ChangeInCapacity : 1'} + previous_meta = {awhile_ago.isoformat(): 'ChangeInCapacity : 1'} self.patchobject(pol, 'metadata_get', return_value=previous_meta) self.assertFalse(pol._cooldown_inprogress()) @@ -171,7 +171,7 @@ class TestCooldownMixin(common.HeatTestCase): pol = self.create_scaling_policy(t, stack, 'my-policy') now = timeutils.utcnow() - previous_meta = {timeutils.strtime(now): 'ChangeInCapacity : 1'} + previous_meta = {now.isoformat(): 'ChangeInCapacity : 1'} self.patchobject(pol, 'metadata_get', return_value=previous_meta) self.assertFalse(pol._cooldown_inprogress()) @@ -187,7 +187,7 @@ class TestCooldownMixin(common.HeatTestCase): pol = self.create_scaling_policy(t, stack, 'my-policy') now = timeutils.utcnow() - previous_meta = {timeutils.strtime(now): 'ChangeInCapacity : 1'} + previous_meta = {now.isoformat(): 'ChangeInCapacity : 1'} self.patchobject(pol, 'metadata_get', return_value=previous_meta) self.assertFalse(pol._cooldown_inprogress()) @@ -196,12 +196,12 @@ class TestCooldownMixin(common.HeatTestCase): stack = utils.parse_stack(t, params=as_params) pol = self.create_scaling_policy(t, stack, 'my-policy') - nowish = timeutils.strtime() + nowish = timeutils.utcnow() reason = 'cool as' meta_set = self.patchobject(pol, 'metadata_set') - self.patchobject(timeutils, 'strtime', return_value=nowish) + self.patchobject(timeutils, 'utcnow', return_value=nowish) pol._cooldown_timestamp(reason) - meta_set.assert_called_once_with({nowish: reason}) + meta_set.assert_called_once_with({nowish.isoformat(): reason}) class ScalingPolicyAttrTest(common.HeatTestCase): diff --git a/heat/tests/autoscaling/test_scaling_policy.py b/heat/tests/autoscaling/test_scaling_policy.py index 6074053910..61f6dc7aec 100644 --- a/heat/tests/autoscaling/test_scaling_policy.py +++ b/heat/tests/autoscaling/test_scaling_policy.py @@ -146,7 +146,7 @@ class TestCooldownMixin(common.HeatTestCase): pol = self.create_scaling_policy(t, stack, 'WebServerScaleUpPolicy') now = timeutils.utcnow() - previous_meta = {timeutils.strtime(now): 'ChangeInCapacity : 1'} + previous_meta = {now.isoformat(): 'ChangeInCapacity : 1'} self.patchobject(pol, 'metadata_get', return_value=previous_meta) self.assertTrue(pol._cooldown_inprogress()) @@ -156,7 +156,7 @@ class TestCooldownMixin(common.HeatTestCase): pol = self.create_scaling_policy(t, stack, 'WebServerScaleUpPolicy') awhile_ago = timeutils.utcnow() - datetime.timedelta(seconds=100) - previous_meta = {timeutils.strtime(awhile_ago): 'ChangeInCapacity : 1'} + previous_meta = {awhile_ago.isoformat(): 'ChangeInCapacity : 1'} self.patchobject(pol, 'metadata_get', return_value=previous_meta) self.assertFalse(pol._cooldown_inprogress()) @@ -171,7 +171,7 @@ class TestCooldownMixin(common.HeatTestCase): pol = self.create_scaling_policy(t, stack, 'WebServerScaleUpPolicy') now = timeutils.utcnow() - previous_meta = {timeutils.strtime(now): 'ChangeInCapacity : 1'} + previous_meta = {now.isoformat(): 'ChangeInCapacity : 1'} self.patchobject(pol, 'metadata_get', return_value=previous_meta) self.assertFalse(pol._cooldown_inprogress()) @@ -187,7 +187,7 @@ class TestCooldownMixin(common.HeatTestCase): pol = self.create_scaling_policy(t, stack, 'WebServerScaleUpPolicy') now = timeutils.utcnow() - previous_meta = {timeutils.strtime(now): 'ChangeInCapacity : 1'} + previous_meta = {now.isoformat(): 'ChangeInCapacity : 1'} self.patchobject(pol, 'metadata_get', return_value=previous_meta) self.assertFalse(pol._cooldown_inprogress()) @@ -196,12 +196,12 @@ class TestCooldownMixin(common.HeatTestCase): stack = utils.parse_stack(t, params=as_params) pol = self.create_scaling_policy(t, stack, 'WebServerScaleUpPolicy') - nowish = timeutils.strtime() + nowish = timeutils.utcnow() reason = 'cool as' meta_set = self.patchobject(pol, 'metadata_set') - self.patchobject(timeutils, 'strtime', return_value=nowish) + self.patchobject(timeutils, 'utcnow', return_value=nowish) pol._cooldown_timestamp(reason) - meta_set.assert_called_once_with({nowish: reason}) + meta_set.assert_called_once_with({nowish.isoformat(): reason}) class ScalingPolicyAttrTest(common.HeatTestCase): diff --git a/heat/tests/engine/test_software_config.py b/heat/tests/engine/test_software_config.py index fd3ac879a6..d996df59a9 100644 --- a/heat/tests/engine/test_software_config.py +++ b/heat/tests/engine/test_software_config.py @@ -635,7 +635,7 @@ class SoftwareConfigServiceTest(common.HeatTestCase): sc.get_object.assert_called_once_with(container, object_name) # signal_software_deployment called with signal ssd.assert_called_once_with(self.ctx, deployment_id, {u"foo": u"bar"}, - timeutils.strtime(then)) + then.isoformat()) # second poll updated_at populated with first poll last-modified software_deployment_object.SoftwareDeployment.update_by_id( @@ -648,7 +648,7 @@ class SoftwareConfigServiceTest(common.HeatTestCase): sc.get_object.assert_called_once_with(container, object_name) # signal_software_deployment has not been called again ssd.assert_called_once_with(self.ctx, deployment_id, {"foo": "bar"}, - timeutils.strtime(then)) + then.isoformat()) # third poll last-modified changed, new signal headers['last-modified'] = last_modified_2 @@ -660,7 +660,7 @@ class SoftwareConfigServiceTest(common.HeatTestCase): # two calls to signal_software_deployment, for then and now self.assertEqual(2, len(ssd.mock_calls)) ssd.assert_called_with(self.ctx, deployment_id, {"bar": "baz"}, - timeutils.strtime(now)) + now.isoformat()) # four polls result in only two signals, for then and now software_deployment_object.SoftwareDeployment.update_by_id( diff --git a/heat/tests/test_swift_client.py b/heat/tests/test_swift_client.py index aeb95596b3..ba5177e338 100644 --- a/heat/tests/test_swift_client.py +++ b/heat/tests/test_swift_client.py @@ -14,7 +14,6 @@ import datetime import mock -from oslo_utils import timeutils import pytz from testtools import matchers @@ -131,7 +130,7 @@ class SwiftUtilsTests(SwiftClientPluginTestCase): 2015, 2, 5, 1, 4, 40, 0, pytz.timezone('GMT')) now_naive = datetime.datetime( 2015, 2, 5, 1, 4, 40, 0) - last_modified = timeutils.strtime(now, '%a, %d %b %Y %H:%M:%S %Z') + last_modified = now.strftime('%a, %d %b %Y %H:%M:%S %Z') self.assertEqual('Thu, 05 Feb 2015 01:04:40 GMT', last_modified) self.assertEqual( now_naive,