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:
parent
1417c9a3a3
commit
f569141164
@ -11,6 +11,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from openstack.block_store import block_store_service
|
from openstack.block_store import block_store_service
|
||||||
|
from openstack import format
|
||||||
from openstack import resource
|
from openstack import resource
|
||||||
|
|
||||||
|
|
||||||
@ -38,16 +39,17 @@ class Snapshot(resource.Resource):
|
|||||||
#: Description of snapshot. Default is None.
|
#: Description of snapshot. Default is None.
|
||||||
description = resource.prop("description")
|
description = resource.prop("description")
|
||||||
#: The timestamp of this snapshot creation.
|
#: 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 associated with this snapshot.
|
||||||
metadata = resource.prop("metadata", type=dict)
|
metadata = resource.prop("metadata", type=dict)
|
||||||
#: The ID of the volume this snapshot was taken of.
|
#: The ID of the volume this snapshot was taken of.
|
||||||
volume_id = resource.prop("volume_id")
|
volume_id = resource.prop("volume_id")
|
||||||
#: The size of the volume, in GBs.
|
#: The size of the volume, in GBs.
|
||||||
size = resource.prop("size", type=int)
|
size = resource.prop("size", type=int)
|
||||||
#: Indicate whether to snapshot, even if the volume is attached.
|
#: Indicate whether to create snapshot, even if the volume is attached.
|
||||||
#: Default is False.
|
#: Default is ``False``. *Type: bool*
|
||||||
force = resource.prop("force", type=bool)
|
is_forced = resource.prop("force", type=format.BoolStr)
|
||||||
|
|
||||||
|
|
||||||
class SnapshotDetail(Snapshot):
|
class SnapshotDetail(Snapshot):
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from openstack.block_store import block_store_service
|
from openstack.block_store import block_store_service
|
||||||
|
from openstack import format
|
||||||
from openstack import resource
|
from openstack import resource
|
||||||
|
|
||||||
|
|
||||||
@ -55,7 +56,7 @@ class Volume(resource.Resource):
|
|||||||
volume_type = resource.prop("volume_type")
|
volume_type = resource.prop("volume_type")
|
||||||
#: Enables or disables the bootable attribute. You can boot an
|
#: Enables or disables the bootable attribute. You can boot an
|
||||||
#: instance from a bootable volume. *Type: bool*
|
#: 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.
|
#: One or more metadata key and value pairs to associate with the volume.
|
||||||
metadata = resource.prop("metadata")
|
metadata = resource.prop("metadata")
|
||||||
|
|
||||||
@ -66,8 +67,9 @@ class Volume(resource.Resource):
|
|||||||
status = resource.prop("status")
|
status = resource.prop("status")
|
||||||
#: TODO(briancurtin): This is currently undocumented in the API.
|
#: TODO(briancurtin): This is currently undocumented in the API.
|
||||||
attachments = resource.prop("attachments")
|
attachments = resource.prop("attachments")
|
||||||
#: The time this volume was created at.
|
#: The timestamp of this volume creation.
|
||||||
created = resource.prop("created_at")
|
#: *Type: datetime object parsed from ISO 8601 formatted string*
|
||||||
|
created_at = resource.prop("created_at", type=format.ISO8601)
|
||||||
|
|
||||||
|
|
||||||
class VolumeDetail(Volume):
|
class VolumeDetail(Volume):
|
||||||
@ -93,5 +95,6 @@ class VolumeDetail(Volume):
|
|||||||
#: Data set by the replication driver
|
#: Data set by the replication driver
|
||||||
replication_driver_data = resource.prop(
|
replication_driver_data = resource.prop(
|
||||||
"os-volume-replication:driver_data")
|
"os-volume-replication:driver_data")
|
||||||
#: ``True`` if this volume is encrypted, ``False`` if not. *Type: bool*
|
#: ``True`` if this volume is encrypted, ``False`` if not.
|
||||||
encrypted = resource.prop("encrypted", type=bool)
|
#: *Type: bool*
|
||||||
|
is_encrypted = resource.prop("encrypted", type=format.BoolStr)
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
import datetime
|
||||||
|
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
@ -19,12 +20,13 @@ FAKE_ID = "ffa9bc5e-1172-4021-acaf-cdcd78a9584d"
|
|||||||
SNAPSHOT = {
|
SNAPSHOT = {
|
||||||
"status": "creating",
|
"status": "creating",
|
||||||
"description": "Daily backup",
|
"description": "Daily backup",
|
||||||
"created_at": "2013-02-25T03:56:53.081642",
|
"created_at": "2015-03-09T12:14:57.233772",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"volume_id": "5aa119a8-d25b-45a7-8d1b-88e127885635",
|
"volume_id": "5aa119a8-d25b-45a7-8d1b-88e127885635",
|
||||||
"size": 1,
|
"size": 1,
|
||||||
"id": FAKE_ID,
|
"id": FAKE_ID,
|
||||||
"name": "snap-001"
|
"name": "snap-001",
|
||||||
|
"force": "true",
|
||||||
}
|
}
|
||||||
|
|
||||||
DETAILS = {
|
DETAILS = {
|
||||||
@ -56,11 +58,14 @@ class TestSnapshot(testtools.TestCase):
|
|||||||
sot = snapshot.Snapshot(SNAPSHOT)
|
sot = snapshot.Snapshot(SNAPSHOT)
|
||||||
self.assertEqual(SNAPSHOT["id"], sot.id)
|
self.assertEqual(SNAPSHOT["id"], sot.id)
|
||||||
self.assertEqual(SNAPSHOT["status"], sot.status)
|
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["metadata"], sot.metadata)
|
||||||
self.assertEqual(SNAPSHOT["volume_id"], sot.volume_id)
|
self.assertEqual(SNAPSHOT["volume_id"], sot.volume_id)
|
||||||
self.assertEqual(SNAPSHOT["size"], sot.size)
|
self.assertEqual(SNAPSHOT["size"], sot.size)
|
||||||
self.assertEqual(SNAPSHOT["name"], sot.name)
|
self.assertEqual(SNAPSHOT["name"], sot.name)
|
||||||
|
self.assertTrue(sot.is_forced)
|
||||||
|
|
||||||
|
|
||||||
class TestSnapshotDetail(testtools.TestCase):
|
class TestSnapshotDetail(testtools.TestCase):
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
import datetime
|
||||||
|
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
@ -23,8 +24,8 @@ VOLUME = {
|
|||||||
"name": "my_volume",
|
"name": "my_volume",
|
||||||
"attachments": [],
|
"attachments": [],
|
||||||
"availability_zone": "nova",
|
"availability_zone": "nova",
|
||||||
"bootable": False,
|
"bootable": "false",
|
||||||
"created_at": "2014-02-21T19:52:04.949734",
|
"created_at": "2015-03-09T12:14:57.233772",
|
||||||
"description": "something",
|
"description": "something",
|
||||||
"volume_type": "some_type",
|
"volume_type": "some_type",
|
||||||
"snapshot_id": "93c2e2aa-7744-4fd6-a31a-80c4726b08d7",
|
"snapshot_id": "93c2e2aa-7744-4fd6-a31a-80c4726b08d7",
|
||||||
@ -45,7 +46,7 @@ DETAILS = {
|
|||||||
"consistencygroup_id": "123asf-asdf123",
|
"consistencygroup_id": "123asf-asdf123",
|
||||||
"os-volume-replication:driver_data": "ahasadfasdfasdfasdfsdf",
|
"os-volume-replication:driver_data": "ahasadfasdfasdfasdfsdf",
|
||||||
"snapshot_id": "93c2e2aa-7744-4fd6-a31a-80c4726b08d7",
|
"snapshot_id": "93c2e2aa-7744-4fd6-a31a-80c4726b08d7",
|
||||||
"encrypted": False,
|
"encrypted": "false",
|
||||||
}
|
}
|
||||||
|
|
||||||
VOLUME_DETAIL = copy.copy(VOLUME)
|
VOLUME_DETAIL = copy.copy(VOLUME)
|
||||||
@ -72,8 +73,10 @@ class TestVolume(testtools.TestCase):
|
|||||||
self.assertEqual(VOLUME["status"], sot.status)
|
self.assertEqual(VOLUME["status"], sot.status)
|
||||||
self.assertEqual(VOLUME["attachments"], sot.attachments)
|
self.assertEqual(VOLUME["attachments"], sot.attachments)
|
||||||
self.assertEqual(VOLUME["availability_zone"], sot.availability_zone)
|
self.assertEqual(VOLUME["availability_zone"], sot.availability_zone)
|
||||||
self.assertEqual(VOLUME["bootable"], sot.bootable)
|
self.assertFalse(sot.is_bootable)
|
||||||
self.assertEqual(VOLUME["created_at"], sot.created)
|
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["description"], sot.description)
|
||||||
self.assertEqual(VOLUME["volume_type"], sot.volume_type)
|
self.assertEqual(VOLUME["volume_type"], sot.volume_type)
|
||||||
self.assertEqual(VOLUME["snapshot_id"], sot.snapshot_id)
|
self.assertEqual(VOLUME["snapshot_id"], sot.snapshot_id)
|
||||||
@ -108,4 +111,4 @@ class TestVolumeDetail(testtools.TestCase):
|
|||||||
sot.consistency_group_id)
|
sot.consistency_group_id)
|
||||||
self.assertEqual(VOLUME_DETAIL["os-volume-replication:driver_data"],
|
self.assertEqual(VOLUME_DETAIL["os-volume-replication:driver_data"],
|
||||||
sot.replication_driver_data)
|
sot.replication_driver_data)
|
||||||
self.assertEqual(VOLUME_DETAIL["encrypted"], sot.encrypted)
|
self.assertFalse(sot.is_encrypted)
|
||||||
|
Loading…
Reference in New Issue
Block a user