Generate create_at date in usage in isoformat for backups/snapshots
Change the format of the dates when generating notifications for snapshots and backups. This was generating a format problem when inserting events into Elasticsearch via Panko, due to an invalid format (YYYY-MM-DD HH:mm:ssZ to YYYY-MM-DDTHH:mm:ssZ) Change-Id: I651699e42c28c05fc8fd71cfeef54d98839c1a29
This commit is contained in:
parent
68c668cfc8
commit
ba8dc73cd2
@ -13,9 +13,11 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import datetime
|
||||
import ddt
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
import pytz
|
||||
from six.moves import http_client
|
||||
from six.moves.urllib import parse as urllib
|
||||
import webob
|
||||
@ -203,6 +205,7 @@ class SnapshotApiTest(test.TestCase):
|
||||
'id': UUID,
|
||||
'volume_id': fake.VOLUME_ID,
|
||||
'status': fields.SnapshotStatus.AVAILABLE,
|
||||
'created_at': "2014-01-01 00:00:00",
|
||||
'volume_size': 100,
|
||||
'display_name': 'Default name',
|
||||
'display_description': 'Default description',
|
||||
@ -226,7 +229,8 @@ class SnapshotApiTest(test.TestCase):
|
||||
'volume_id': fake.VOLUME_ID,
|
||||
'status': fields.SnapshotStatus.AVAILABLE,
|
||||
'size': 100,
|
||||
'created_at': None,
|
||||
'created_at': datetime.datetime(2014, 1, 1, 0, 0, 0,
|
||||
tzinfo=pytz.utc),
|
||||
'updated_at': None,
|
||||
'name': u'Updated Test Name',
|
||||
'description': u'Default description',
|
||||
|
@ -162,7 +162,7 @@ class NotifyUsageTestCase(test.TestCase):
|
||||
'volume_size': 1,
|
||||
'snapshot_id': fake.SNAPSHOT_ID,
|
||||
'display_name': '11',
|
||||
'created_at': mock.ANY,
|
||||
'created_at': '2014-12-11T10:10:00+00:00',
|
||||
'status': fields.SnapshotStatus.ERROR,
|
||||
'deleted': '',
|
||||
'metadata': six.text_type({'fake_snap_meta_key':
|
||||
@ -371,8 +371,7 @@ class NotifyUsageTestCase(test.TestCase):
|
||||
expected_backup = raw_backup.copy()
|
||||
expected_backup['tenant_id'] = expected_backup.pop('project_id')
|
||||
expected_backup['backup_id'] = expected_backup.pop('id')
|
||||
expected_backup['created_at'] = (
|
||||
six.text_type(expected_backup['created_at']) + '+00:00')
|
||||
expected_backup['created_at'] = '2015-01-01T01:01:01+00:00'
|
||||
|
||||
usage_info = volume_utils._usage_from_backup(backup_obj)
|
||||
self.assertDictEqual(expected_backup, usage_info)
|
||||
|
@ -109,7 +109,7 @@ def _usage_from_backup(backup, **kw):
|
||||
backup_id=backup.id,
|
||||
host=backup.host,
|
||||
display_name=backup.display_name,
|
||||
created_at=str(backup.created_at),
|
||||
created_at=backup.created_at.isoformat(),
|
||||
status=backup.status,
|
||||
volume_id=backup.volume_id,
|
||||
size=backup.size,
|
||||
@ -171,7 +171,7 @@ def _usage_from_snapshot(snapshot, context, **extra_usage_info):
|
||||
'volume_size': snapshot.volume_size,
|
||||
'snapshot_id': snapshot.id,
|
||||
'display_name': snapshot.display_name,
|
||||
'created_at': str(snapshot.created_at),
|
||||
'created_at': snapshot.created_at.isoformat(),
|
||||
'status': snapshot.status,
|
||||
'deleted': null_safe_str(snapshot.deleted),
|
||||
'metadata': null_safe_str(snapshot.metadata),
|
||||
|
Loading…
x
Reference in New Issue
Block a user