Use strtime() specific timestamp regexp

Any datetime objects that get serialized via jsonutils.dumps() get
stringified using strtime() which includes decimal seconds and is
timezone naive.

Use a specific regexp to check the use of this format.

Note that included in here is a fixup to the doc samples for the
instance actions extension - the sample shows it using the
str(datetime) format when in fact it is using strtime. This came
about because before commit 68288b9 we were using a pre-serialized
timestamp in the fake instance actions. I just regenerated the samples
for this.

Full context here:

  http://lists.openstack.org/pipermail/openstack-dev/2014-April/033971.html

Change-Id: If52a2a664eccc8aed8a39d1a9dfb0209337c3c79
This commit is contained in:
Mark McLoughlin 2014-04-29 12:28:51 +01:00
parent 41c45e4ba0
commit e6cfc7b890
47 changed files with 95 additions and 93 deletions

View File

@ -4,16 +4,16 @@
"events": [
{
"event": "schedule",
"finish_time": "2012-12-05 01:02:00.000000",
"finish_time": "2012-12-05T01:02:00.000000",
"result": "Success",
"start_time": "2012-12-05 01:00:02.000000",
"start_time": "2012-12-05T01:00:02.000000",
"traceback": ""
},
{
"event": "compute_create",
"finish_time": "2012-12-05 01:04:00.000000",
"finish_time": "2012-12-05T01:04:00.000000",
"result": "Success",
"start_time": "2012-12-05 01:03:00.000000",
"start_time": "2012-12-05T01:03:00.000000",
"traceback": ""
}
],
@ -21,7 +21,7 @@
"message": "",
"project_id": "147",
"request_id": "req-3293a3f1-b44c-4609-b8d2-d81b105636b8",
"start_time": "2012-12-05 00:00:00.000000",
"start_time": "2012-12-05T00:00:00.000000",
"user_id": "789"
}
}

View File

@ -6,7 +6,7 @@
"message": "",
"project_id": "842",
"request_id": "req-25517360-b757-47d3-be45-0e8d2a01b36a",
"start_time": "2012-12-05 01:00:00.000000",
"start_time": "2012-12-05T01:00:00.000000",
"user_id": "789"
},
{
@ -15,7 +15,7 @@
"message": "",
"project_id": "147",
"request_id": "req-3293a3f1-b44c-4609-b8d2-d81b105636b8",
"start_time": "2012-12-05 00:00:00.000000",
"start_time": "2012-12-05T00:00:00.000000",
"user_id": "789"
}
]

View File

@ -10,7 +10,7 @@
}
],
"availabilityZone": "zone1:host1",
"createdAt": "1999-01-01T01:01:01",
"createdAt": "1999-01-01T01:01:01.000000",
"displayDescription": "Volume Description",
"displayName": "Volume Name",
"id": "a26887c6-c47b-4654-abb5-dfadf7d3f803",
@ -21,4 +21,4 @@
"volumeType": "Backup"
}
]
}
}

View File

@ -1,6 +1,6 @@
{
"server": {
"OS-SRV-USG:launched_at": "%(timestamp)s",
"OS-SRV-USG:launched_at": "%(strtime)s",
"OS-SRV-USG:terminated_at": null,
"accessIPv4": "",
"accessIPv6": "",

View File

@ -3,7 +3,7 @@
{
"status": "ACTIVE",
"updated": "%(isotime)s",
"OS-SRV-USG:launched_at": "%(timestamp)s",
"OS-SRV-USG:launched_at": "%(strtime)s",
"user_id": "fake",
"addresses": {
"private": [

View File

@ -8,7 +8,7 @@
"OS-EXT-STS:power_state": 1,
"OS-EXT-STS:task_state": null,
"OS-EXT-STS:vm_state": "active",
"OS-SRV-USG:launched_at": "%(timestamp)s",
"OS-SRV-USG:launched_at": "%(strtime)s",
"OS-SRV-USG:terminated_at": null,
"accessIPv4": "",
"accessIPv6": "",

View File

@ -9,7 +9,7 @@
"OS-EXT-STS:power_state": 1,
"OS-EXT-STS:task_state": null,
"OS-EXT-STS:vm_state": "active",
"OS-SRV-USG:launched_at": "%(timestamp)s",
"OS-SRV-USG:launched_at": "%(strtime)s",
"OS-SRV-USG:terminated_at": null,
"accessIPv4": "",
"accessIPv6": "",

View File

@ -1,7 +1,7 @@
{
"aggregate": {
"availability_zone": "nova",
"created_at": "%(timestamp)s",
"created_at": "%(strtime)s",
"deleted": false,
"deleted_at": null,
"id": %(aggregate_id)s,

View File

@ -1,7 +1,7 @@
{
"aggregate": {
"availability_zone": "nova2",
"created_at": "%(timestamp)s",
"created_at": "%(strtime)s",
"deleted": false,
"deleted_at": null,
"hosts": [],
@ -10,6 +10,6 @@
"availability_zone": "nova2"
},
"name": "newname",
"updated_at": "%(timestamp)s"
"updated_at": "%(strtime)s"
}
}

View File

@ -1,7 +1,7 @@
{
"aggregate": {
"availability_zone": "nova",
"created_at": "%(timestamp)s",
"created_at": "%(strtime)s",
"deleted": false,
"deleted_at": null,
"hosts": [

View File

@ -1,7 +1,7 @@
{
"aggregate": {
"availability_zone": "nova",
"created_at": "%(timestamp)s",
"created_at": "%(strtime)s",
"deleted": false,
"deleted_at": null,
"hosts": [],

View File

@ -2,7 +2,7 @@
"aggregates": [
{
"availability_zone": "nova",
"created_at": "%(timestamp)s",
"created_at": "%(strtime)s",
"deleted": false,
"deleted_at": null,
"hosts": [],

View File

@ -1,7 +1,7 @@
{
"aggregate": {
"availability_zone": "nova",
"created_at": "%(timestamp)s",
"created_at": "%(strtime)s",
"deleted": false,
"deleted_at": null,
"hosts": [],

View File

@ -1,7 +1,7 @@
{
"aggregate": {
"availability_zone": "nova",
"created_at": "%(timestamp)s",
"created_at": "%(strtime)s",
"deleted": false,
"deleted_at": null,
"hosts": [],

View File

@ -6,7 +6,7 @@
"host": "host1",
"state": "up",
"status": "disabled",
"updated_at": "%(timestamp)s",
"updated_at": "%(strtime)s",
"zone": "internal"
},
{
@ -15,7 +15,7 @@
"host": "host1",
"state": "up",
"status": "disabled",
"updated_at": "%(timestamp)s",
"updated_at": "%(strtime)s",
"zone": "nova"
},
{
@ -24,7 +24,7 @@
"host": "host2",
"state": "down",
"status": "enabled",
"updated_at": "%(timestamp)s",
"updated_at": "%(strtime)s",
"zone": "internal"
},
{
@ -33,7 +33,7 @@
"host": "host2",
"state": "down",
"status": "disabled",
"updated_at": "%(timestamp)s",
"updated_at": "%(strtime)s",
"zone": "nova"
}
]

View File

@ -5,20 +5,20 @@
"request_id": "%(request_id)s",
"user_id": "%(integer_id)s",
"project_id": "%(integer_id)s",
"start_time": "%(timestamp)s",
"start_time": "%(strtime)s",
"message": "",
"events": [
{
"event": "%(event)s",
"start_time": "%(timestamp)s",
"finish_time": "%(timestamp)s",
"start_time": "%(strtime)s",
"finish_time": "%(strtime)s",
"result": "%(result)s",
"traceback": ""
},
{
"event": "%(event)s",
"start_time": "%(timestamp)s",
"finish_time": "%(timestamp)s",
"start_time": "%(strtime)s",
"finish_time": "%(strtime)s",
"result": "%(result)s",
"traceback": ""
}

View File

@ -6,7 +6,7 @@
"request_id": "%(request_id)s",
"user_id": "%(integer_id)s",
"project_id": "%(integer_id)s",
"start_time": "%(timestamp)s",
"start_time": "%(strtime)s",
"message": ""
},
{
@ -15,7 +15,7 @@
"request_id": "%(request_id)s",
"user_id": "%(integer_id)s",
"project_id": "%(integer_id)s",
"start_time": "%(timestamp)s",
"start_time": "%(strtime)s",
"message": ""
}
]

View File

@ -6,7 +6,7 @@
"broadcast": "%(ip)s",
"cidr": "10.0.0.0/29",
"cidr_v6": null,
"created_at": "%(timestamp)s",
"created_at": "%(strtime)s",
"deleted": false,
"deleted_at": null,
"dhcp_start": "%(ip)s",
@ -24,7 +24,7 @@
"priority": null,
"project_id": "1234",
"rxtx_base": null,
"updated_at": "%(timestamp)s",
"updated_at": "%(strtime)s",
"vlan": 100,
"vpn_private_address": "%(ip)s",
"vpn_public_address": "%(ip)s",

View File

@ -6,7 +6,7 @@
"broadcast": "%(ip)s",
"cidr": "10.0.0.0/29",
"cidr_v6": null,
"created_at": "%(timestamp)s",
"created_at": "%(strtime)s",
"deleted": false,
"deleted_at": null,
"dhcp_start": "%(ip)s",
@ -24,7 +24,7 @@
"priority": null,
"project_id": "1234",
"rxtx_base": null,
"updated_at": "%(timestamp)s",
"updated_at": "%(strtime)s",
"vlan": 100,
"vpn_private_address": "%(ip)s",
"vpn_public_address": "%(ip)s",
@ -36,7 +36,7 @@
"broadcast": "%(ip)s",
"cidr": "10.0.0.10/29",
"cidr_v6": null,
"created_at": "%(timestamp)s",
"created_at": "%(strtime)s",
"deleted": false,
"deleted_at": null,
"dhcp_start": "%(ip)s",

View File

@ -6,7 +6,7 @@
"disabled_reason": "test1",
"state": "up",
"status": "disabled",
"updated_at": "%(timestamp)s",
"updated_at": "%(strtime)s",
"zone": "internal"
},
{
@ -15,7 +15,7 @@
"disabled_reason": "test2",
"state": "up",
"status": "disabled",
"updated_at": "%(timestamp)s",
"updated_at": "%(strtime)s",
"zone": "nova"
},
{
@ -24,7 +24,7 @@
"disabled_reason": "",
"state": "down",
"status": "enabled",
"updated_at": "%(timestamp)s",
"updated_at": "%(strtime)s",
"zone": "internal"
},
{
@ -33,7 +33,7 @@
"disabled_reason": "test4",
"state": "down",
"status": "disabled",
"updated_at": "%(timestamp)s",
"updated_at": "%(strtime)s",
"zone": "nova"
}
]

View File

@ -5,7 +5,7 @@
"host": "host1",
"state": "up",
"status": "disabled",
"updated_at": "%(timestamp)s",
"updated_at": "%(strtime)s",
"zone": "internal"
},
{
@ -13,7 +13,7 @@
"host": "host1",
"state": "up",
"status": "disabled",
"updated_at": "%(timestamp)s",
"updated_at": "%(strtime)s",
"zone": "nova"
},
{
@ -21,7 +21,7 @@
"host": "host2",
"state": "down",
"status": "enabled",
"updated_at": "%(timestamp)s",
"updated_at": "%(strtime)s",
"zone": "internal"
},
{
@ -29,7 +29,7 @@
"host": "host2",
"state": "down",
"status": "disabled",
"updated_at": "%(timestamp)s",
"updated_at": "%(strtime)s",
"zone": "nova"
}
]

View File

@ -9,15 +9,15 @@
"local_gb": 1,
"memory_mb": 512,
"name": "new-server-test",
"started_at": "%(timestamp)s",
"started_at": "%(strtime)s",
"state": "active",
"tenant_id": "openstack",
"uptime": 3600,
"vcpus": 1
}
],
"start": "%(timestamp)s",
"stop": "%(timestamp)s",
"start": "%(strtime)s",
"stop": "%(strtime)s",
"tenant_id": "openstack",
"total_hours": 1.0,
"total_local_gb_usage": 1.0,

View File

@ -1,8 +1,8 @@
{
"tenant_usages": [
{
"start": "%(timestamp)s",
"stop": "%(timestamp)s",
"start": "%(strtime)s",
"stop": "%(strtime)s",
"tenant_id": "openstack",
"total_hours": 1.0,
"total_local_gb_usage": 1.0,

View File

@ -10,7 +10,7 @@
}
],
"availabilityZone": "zone1:host1",
"createdAt": "%(timestamp)s",
"createdAt": "%(strtime)s",
"displayDescription": "%(volume_desc)s",
"displayName": "%(volume_name)s",
"id": "%(uuid)s",

View File

@ -9,7 +9,7 @@
}
],
"availabilityZone": "zone1:host1",
"createdAt": "%(timestamp)s",
"createdAt": "%(strtime)s",
"displayDescription": "%(volume_desc)s",
"displayName": "%(volume_name)s",
"id": "%(uuid)s",

View File

@ -10,7 +10,7 @@
}
],
"availabilityZone": "zone1:host1",
"createdAt": "%(timestamp)s",
"createdAt": "%(strtime)s",
"displayDescription": "%(volume_desc)s",
"displayName": "%(volume_name)s",
"id": "%(uuid)s",

View File

@ -15,7 +15,7 @@
"snapshotId": null,
"metadata": {},
"id": "%(uuid)s",
"createdAt": "%(timestamp)s",
"createdAt": "%(strtime)s",
"size": 100
}
}

View File

@ -1,6 +1,6 @@
{
"snapshot": {
"createdAt": "%(timestamp)s",
"createdAt": "%(strtime)s",
"displayDescription": "%(description)s",
"displayName": "%(snapshot_name)s",
"id": 100,

View File

@ -1,7 +1,7 @@
{
"snapshots": [
{
"createdAt": "%(timestamp)s",
"createdAt": "%(strtime)s",
"displayDescription": "Default description",
"displayName": "Default name",
"id": 100,
@ -10,7 +10,7 @@
"volumeId": 12
},
{
"createdAt": "%(timestamp)s",
"createdAt": "%(strtime)s",
"displayDescription": "Default description",
"displayName": "Default name",
"id": 101,
@ -19,7 +19,7 @@
"volumeId": 12
},
{
"createdAt": "%(timestamp)s",
"createdAt": "%(strtime)s",
"displayDescription": "Default description",
"displayName": "Default name",
"id": 102,

View File

@ -1,7 +1,7 @@
{
"snapshots": [
{
"createdAt": "%(timestamp)s",
"createdAt": "%(strtime)s",
"displayDescription": "%(text)s",
"displayName": "%(text)s",
"id": 100,
@ -10,7 +10,7 @@
"volumeId": 12
},
{
"createdAt": "%(timestamp)s",
"createdAt": "%(strtime)s",
"displayDescription": "%(text)s",
"displayName": "%(text)s",
"id": 101,
@ -19,7 +19,7 @@
"volumeId": 12
},
{
"createdAt": "%(timestamp)s",
"createdAt": "%(strtime)s",
"displayDescription": "%(text)s",
"displayName": "%(text)s",
"id": 102,

View File

@ -1,6 +1,6 @@
{
"snapshot": {
"createdAt": "%(timestamp)s",
"createdAt": "%(strtime)s",
"displayDescription": "%(description)s",
"displayName": "%(snapshot_name)s",
"id": "100",

View File

@ -267,6 +267,7 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
else:
text = r'[^<]*'
isotime_re = '\d{4}-[0,1]\d-[0-3]\dT\d{2}:\d{2}:\d{2}Z'
strtime_re = '\d{4}-[0,1]\d-[0-3]\dT\d{2}:\d{2}:\d{2}\.\d{6}'
# NOTE(treinish): Could result in a false positive, but it
# shouldn't be an issue for this case.
timestamp_re = ('\d{4}-[0,1]\d-[0-3]\d[ ,T]'
@ -274,8 +275,9 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
'(Z|(\+|-)\d{2}:\d{2}|\.\d{6}|)')
return {
'isotime': isotime_re,
'strtime': strtime_re,
'strtime_or_none': r'None|%s' % strtime_re,
'timestamp': timestamp_re,
'timestamp_or_none': r'None|%s' % timestamp_re,
'password': '[0-9a-zA-Z]{1,12}',
'ip': '[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}',
'ip6': '([0-9a-zA-Z]{1,4}:){1,7}:?[0-9a-zA-Z]{1,4}',

View File

@ -59,7 +59,7 @@
"os-extended-status:vm_state": "active",
"os-extended-volumes:volumes_attached": [],
"os-pci:pci_devices": [{"id": 1}],
"os-server-usage:launched_at": "%(timestamp)s",
"os-server-usage:launched_at": "%(strtime)s",
"os-server-usage:terminated_at": null,
"progress": 0,
"os-security-groups:security_groups": [

View File

@ -60,7 +60,7 @@
"os-extended-status:vm_state": "active",
"os-extended-volumes:volumes_attached": [],
"os-pci:pci_devices": [{"id": 1}],
"os-server-usage:launched_at": "%(timestamp)s",
"os-server-usage:launched_at": "%(strtime)s",
"os-server-usage:terminated_at": null,
"progress": 0,
"os-security-groups:security_groups": [

View File

@ -1,7 +1,7 @@
{
"aggregate": {
"availability_zone": "nova",
"created_at": "%(timestamp)s",
"created_at": "%(strtime)s",
"deleted": 0,
"deleted_at": null,
"id": %(aggregate_id)s,

View File

@ -1,7 +1,7 @@
{
"aggregate": {
"availability_zone": "nova2",
"created_at": "%(timestamp)s",
"created_at": "%(strtime)s",
"deleted": 0,
"deleted_at": null,
"hosts": [],
@ -10,6 +10,6 @@
"availability_zone": "nova2"
},
"name": "newname",
"updated_at": "%(timestamp)s"
"updated_at": "%(strtime)s"
}
}

View File

@ -1,7 +1,7 @@
{
"aggregate": {
"availability_zone": "nova",
"created_at": "%(timestamp)s",
"created_at": "%(strtime)s",
"deleted": 0,
"deleted_at": null,
"hosts": [

View File

@ -1,7 +1,7 @@
{
"aggregate": {
"availability_zone": "nova",
"created_at": "%(timestamp)s",
"created_at": "%(strtime)s",
"deleted": 0,
"deleted_at": null,
"hosts": [],

View File

@ -2,7 +2,7 @@
"aggregates": [
{
"availability_zone": "nova",
"created_at": "%(timestamp)s",
"created_at": "%(strtime)s",
"deleted": 0,
"deleted_at": null,
"hosts": [],

View File

@ -1,7 +1,7 @@
{
"aggregate": {
"availability_zone": "nova",
"created_at": "%(timestamp)s",
"created_at": "%(strtime)s",
"deleted": 0,
"deleted_at": null,
"hosts": [],

View File

@ -1,7 +1,7 @@
{
"aggregate": {
"availability_zone": "nova",
"created_at": "%(timestamp)s",
"created_at": "%(strtime)s",
"deleted": 0,
"deleted_at": null,
"hosts": [],

View File

@ -6,42 +6,42 @@
"nova-consoleauth": {
"active": true,
"available": true,
"updated_at": %(timestamp_or_none)s
"updated_at": %(strtime_or_none)s
}
},
"cert": {
"nova-cert": {
"active": true,
"available": true,
"updated_at": %(timestamp_or_none)s
"updated_at": %(strtime_or_none)s
}
},
"conductor": {
"nova-conductor": {
"active": true,
"available": true,
"updated_at": %(timestamp_or_none)s
"updated_at": %(strtime_or_none)s
}
},
"cells": {
"nova-cells": {
"active": true,
"available": true,
"updated_at": %(timestamp_or_none)s
"updated_at": %(strtime_or_none)s
}
},
"scheduler": {
"nova-scheduler": {
"active": true,
"available": true,
"updated_at": %(timestamp_or_none)s
"updated_at": %(strtime_or_none)s
}
},
"network": {
"nova-network": {
"active": true,
"available": true,
"updated_at": %(timestamp_or_none)s
"updated_at": %(strtime_or_none)s
}
}
},
@ -56,7 +56,7 @@
"nova-compute": {
"active": true,
"available": true,
"updated_at": %(timestamp_or_none)s
"updated_at": %(strtime_or_none)s
}
}
},

View File

@ -5,20 +5,20 @@
"request_id": "%(request_id)s",
"user_id": "%(integer_id)s",
"project_id": "%(integer_id)s",
"start_time": "%(timestamp)s",
"start_time": "%(strtime)s",
"message": "",
"events": [
{
"event": "%(event)s",
"start_time": "%(timestamp)s",
"finish_time": "%(timestamp)s",
"start_time": "%(strtime)s",
"finish_time": "%(strtime)s",
"result": "%(result)s",
"traceback": ""
},
{
"event": "%(event)s",
"start_time": "%(timestamp)s",
"finish_time": "%(timestamp)s",
"start_time": "%(strtime)s",
"finish_time": "%(strtime)s",
"result": "%(result)s",
"traceback": ""
}

View File

@ -6,7 +6,7 @@
"request_id": "%(request_id)s",
"user_id": "%(integer_id)s",
"project_id": "%(integer_id)s",
"start_time": "%(timestamp)s",
"start_time": "%(strtime)s",
"message": ""
},
{
@ -15,7 +15,7 @@
"request_id": "%(request_id)s",
"user_id": "%(integer_id)s",
"project_id": "%(integer_id)s",
"start_time": "%(timestamp)s",
"start_time": "%(strtime)s",
"message": ""
}
]

View File

@ -1,6 +1,6 @@
{
"server": {
"os-server-usage:launched_at": "%(timestamp)s",
"os-server-usage:launched_at": "%(strtime)s",
"os-server-usage:terminated_at": null,
"addresses": {
"private": [

View File

@ -3,7 +3,7 @@
{
"status": "ACTIVE",
"created": "%(isotime)s",
"os-server-usage:launched_at": "%(timestamp)s",
"os-server-usage:launched_at": "%(strtime)s",
"user_id": "fake",
"addresses": {
"private": [

View File

@ -7,7 +7,7 @@
"id": 1,
"state": "up",
"status": "disabled",
"updated_at": "%(timestamp)s",
"updated_at": "%(strtime)s",
"zone": "internal"
},
{
@ -17,7 +17,7 @@
"id": 2,
"state": "up",
"status": "disabled",
"updated_at": "%(timestamp)s",
"updated_at": "%(strtime)s",
"zone": "nova"
},
{
@ -27,7 +27,7 @@
"id": 3,
"state": "down",
"status": "enabled",
"updated_at": "%(timestamp)s",
"updated_at": "%(strtime)s",
"zone": "internal"
},
{
@ -37,7 +37,7 @@
"id": 4,
"state": "down",
"status": "disabled",
"updated_at": "%(timestamp)s",
"updated_at": "%(strtime)s",
"zone": "nova"
}
]