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
This commit is contained in:
Julien Danjou 2015-06-02 16:24:58 +02:00
parent a54c655141
commit 03a24cabb1
7 changed files with 21 additions and 22 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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