Consistent resource.prop for timestamps and booleans (block store)

This patch set updates all block store objects to use consistent
resource.prop for timestamps and booleans. In particular, the
following changes were made:
  - Clarify documentation for timestamp and boolean attributes
  - Use 'is_' prefix and boolean type for boolean attributes
  - Use '_at' suffix and timestamp type for timestamp attributes

Change-Id: I5b37f669d8ac96e76f1c7da718bd863148d86d4b
Partial-Bug: #1544584
This commit is contained in:
Richard Theis 2016-03-07 14:25:40 -06:00
parent 1417c9a3a3
commit f569141164
4 changed files with 31 additions and 18 deletions

View File

@ -11,6 +11,7 @@
# under the License.
from openstack.block_store import block_store_service
from openstack import format
from openstack import resource
@ -38,16 +39,17 @@ class Snapshot(resource.Resource):
#: Description of snapshot. Default is None.
description = resource.prop("description")
#: The timestamp of this snapshot creation.
created_at = resource.prop("created_at")
#: *Type: datetime object parsed from ISO 8601 formatted string*
created_at = resource.prop("created_at", type=format.ISO8601)
#: Metadata associated with this snapshot.
metadata = resource.prop("metadata", type=dict)
#: The ID of the volume this snapshot was taken of.
volume_id = resource.prop("volume_id")
#: The size of the volume, in GBs.
size = resource.prop("size", type=int)
#: Indicate whether to snapshot, even if the volume is attached.
#: Default is False.
force = resource.prop("force", type=bool)
#: Indicate whether to create snapshot, even if the volume is attached.
#: Default is ``False``. *Type: bool*
is_forced = resource.prop("force", type=format.BoolStr)
class SnapshotDetail(Snapshot):

View File

@ -11,6 +11,7 @@
# under the License.
from openstack.block_store import block_store_service
from openstack import format
from openstack import resource
@ -55,7 +56,7 @@ class Volume(resource.Resource):
volume_type = resource.prop("volume_type")
#: Enables or disables the bootable attribute. You can boot an
#: instance from a bootable volume. *Type: bool*
bootable = resource.prop("bootable", type=bool)
is_bootable = resource.prop("bootable", type=format.BoolStr)
#: One or more metadata key and value pairs to associate with the volume.
metadata = resource.prop("metadata")
@ -66,8 +67,9 @@ class Volume(resource.Resource):
status = resource.prop("status")
#: TODO(briancurtin): This is currently undocumented in the API.
attachments = resource.prop("attachments")
#: The time this volume was created at.
created = resource.prop("created_at")
#: The timestamp of this volume creation.
#: *Type: datetime object parsed from ISO 8601 formatted string*
created_at = resource.prop("created_at", type=format.ISO8601)
class VolumeDetail(Volume):
@ -93,5 +95,6 @@ class VolumeDetail(Volume):
#: Data set by the replication driver
replication_driver_data = resource.prop(
"os-volume-replication:driver_data")
#: ``True`` if this volume is encrypted, ``False`` if not. *Type: bool*
encrypted = resource.prop("encrypted", type=bool)
#: ``True`` if this volume is encrypted, ``False`` if not.
#: *Type: bool*
is_encrypted = resource.prop("encrypted", type=format.BoolStr)

View File

@ -9,6 +9,7 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import datetime
import testtools
@ -19,12 +20,13 @@ FAKE_ID = "ffa9bc5e-1172-4021-acaf-cdcd78a9584d"
SNAPSHOT = {
"status": "creating",
"description": "Daily backup",
"created_at": "2013-02-25T03:56:53.081642",
"created_at": "2015-03-09T12:14:57.233772",
"metadata": {},
"volume_id": "5aa119a8-d25b-45a7-8d1b-88e127885635",
"size": 1,
"id": FAKE_ID,
"name": "snap-001"
"name": "snap-001",
"force": "true",
}
DETAILS = {
@ -56,11 +58,14 @@ class TestSnapshot(testtools.TestCase):
sot = snapshot.Snapshot(SNAPSHOT)
self.assertEqual(SNAPSHOT["id"], sot.id)
self.assertEqual(SNAPSHOT["status"], sot.status)
self.assertEqual(SNAPSHOT["created_at"], sot.created_at)
dt = datetime.datetime(2015, 3, 9, 12, 14, 57, 233772).replace(
tzinfo=None)
self.assertEqual(dt, sot.created_at.replace(tzinfo=None))
self.assertEqual(SNAPSHOT["metadata"], sot.metadata)
self.assertEqual(SNAPSHOT["volume_id"], sot.volume_id)
self.assertEqual(SNAPSHOT["size"], sot.size)
self.assertEqual(SNAPSHOT["name"], sot.name)
self.assertTrue(sot.is_forced)
class TestSnapshotDetail(testtools.TestCase):

View File

@ -11,6 +11,7 @@
# under the License.
import copy
import datetime
import testtools
@ -23,8 +24,8 @@ VOLUME = {
"name": "my_volume",
"attachments": [],
"availability_zone": "nova",
"bootable": False,
"created_at": "2014-02-21T19:52:04.949734",
"bootable": "false",
"created_at": "2015-03-09T12:14:57.233772",
"description": "something",
"volume_type": "some_type",
"snapshot_id": "93c2e2aa-7744-4fd6-a31a-80c4726b08d7",
@ -45,7 +46,7 @@ DETAILS = {
"consistencygroup_id": "123asf-asdf123",
"os-volume-replication:driver_data": "ahasadfasdfasdfasdfsdf",
"snapshot_id": "93c2e2aa-7744-4fd6-a31a-80c4726b08d7",
"encrypted": False,
"encrypted": "false",
}
VOLUME_DETAIL = copy.copy(VOLUME)
@ -72,8 +73,10 @@ class TestVolume(testtools.TestCase):
self.assertEqual(VOLUME["status"], sot.status)
self.assertEqual(VOLUME["attachments"], sot.attachments)
self.assertEqual(VOLUME["availability_zone"], sot.availability_zone)
self.assertEqual(VOLUME["bootable"], sot.bootable)
self.assertEqual(VOLUME["created_at"], sot.created)
self.assertFalse(sot.is_bootable)
dt = datetime.datetime(2015, 3, 9, 12, 14, 57, 233772).replace(
tzinfo=None)
self.assertEqual(dt, sot.created_at.replace(tzinfo=None))
self.assertEqual(VOLUME["description"], sot.description)
self.assertEqual(VOLUME["volume_type"], sot.volume_type)
self.assertEqual(VOLUME["snapshot_id"], sot.snapshot_id)
@ -108,4 +111,4 @@ class TestVolumeDetail(testtools.TestCase):
sot.consistency_group_id)
self.assertEqual(VOLUME_DETAIL["os-volume-replication:driver_data"],
sot.replication_driver_data)
self.assertEqual(VOLUME_DETAIL["encrypted"], sot.encrypted)
self.assertFalse(sot.is_encrypted)