Skip to content

Commit c7d465a

Browse files
committed
volume: Migrate 'volume show' to SDK
Change-Id: Ibd9d7a62c2500a1f31aa2d3d13ac7e8bad4e6964 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent 5e5f12b commit c7d465a

File tree

6 files changed

+212
-109
lines changed

6 files changed

+212
-109
lines changed

openstackclient/tests/functional/volume/v2/test_volume.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def test_volume_set_and_unset(self):
171171
cmd_output["volume_image_metadata"],
172172
)
173173
self.assertEqual(
174-
'true',
174+
True,
175175
cmd_output["bootable"],
176176
)
177177

openstackclient/tests/functional/volume/v3/test_volume.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def test_volume_set_and_unset(self):
172172
cmd_output["volume_image_metadata"],
173173
)
174174
self.assertEqual(
175-
'true',
175+
True,
176176
cmd_output["bootable"],
177177
)
178178

openstackclient/tests/unit/volume/v2/test_volume.py

Lines changed: 95 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# under the License.
1313

1414
from unittest import mock
15+
import uuid
1516

1617
from openstack.block_storage.v2 import snapshot as _snapshot
1718
from openstack.block_storage.v2 import volume as _volume
@@ -1622,42 +1623,83 @@ def test_volume_set_with_only_retype_policy(self, mock_warning):
16221623
self.assertIsNone(result)
16231624

16241625

1625-
class TestVolumeShow(TestVolume):
1626+
class TestVolumeShow(volume_fakes.TestVolume):
16261627
def setUp(self):
16271628
super().setUp()
16281629

1629-
self._volume = volume_fakes.create_one_volume()
1630-
self.volumes_mock.get.return_value = self._volume
1631-
# Get the command object to test
1630+
self.volume = sdk_fakes.generate_fake_resource(_volume.Volume)
1631+
self.volume_sdk_client.find_volume.return_value = self.volume
1632+
1633+
self.columns = (
1634+
'attachments',
1635+
'availability_zone',
1636+
'bootable',
1637+
'consistencygroup_id',
1638+
'created_at',
1639+
'description',
1640+
'encrypted',
1641+
'id',
1642+
'multiattach',
1643+
'name',
1644+
'os-vol-host-attr:host',
1645+
'os-vol-mig-status-attr:migstat',
1646+
'os-vol-mig-status-attr:name_id',
1647+
'os-vol-tenant-attr:tenant_id',
1648+
'os-volume-replication:driver_data',
1649+
'os-volume-replication:extended_status',
1650+
'properties',
1651+
'replication_status',
1652+
'size',
1653+
'snapshot_id',
1654+
'source_volid',
1655+
'status',
1656+
'type',
1657+
'updated_at',
1658+
'user_id',
1659+
'volume_image_metadata',
1660+
)
1661+
self.data = (
1662+
self.volume.attachments,
1663+
self.volume.availability_zone,
1664+
self.volume.is_bootable,
1665+
self.volume.consistency_group_id,
1666+
self.volume.created_at,
1667+
self.volume.description,
1668+
self.volume.is_encrypted,
1669+
self.volume.id,
1670+
self.volume.is_multiattach,
1671+
self.volume.name,
1672+
self.volume.host,
1673+
self.volume.migration_status,
1674+
self.volume.migration_id,
1675+
self.volume.project_id,
1676+
self.volume.replication_driver_data,
1677+
self.volume.extended_replication_status,
1678+
format_columns.DictColumn(self.volume.metadata),
1679+
self.volume.replication_status,
1680+
self.volume.size,
1681+
self.volume.snapshot_id,
1682+
self.volume.source_volume_id,
1683+
self.volume.status,
1684+
self.volume.volume_type,
1685+
self.volume.updated_at,
1686+
self.volume.user_id,
1687+
self.volume.volume_image_metadata,
1688+
)
1689+
16321690
self.cmd = volume.ShowVolume(self.app, None)
16331691

16341692
def test_volume_show(self):
1635-
arglist = [self._volume.id]
1636-
verifylist = [("volume", self._volume.id)]
1693+
arglist = [self.volume.id]
1694+
verifylist = [("volume", self.volume.id)]
16371695
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
16381696

16391697
columns, data = self.cmd.take_action(parsed_args)
1640-
self.volumes_mock.get.assert_called_with(self._volume.id)
16411698

1642-
self.assertEqual(
1643-
tuple(sorted(self._volume.keys())),
1644-
columns,
1645-
)
1646-
self.assertTupleEqual(
1647-
(
1648-
self._volume.attachments,
1649-
self._volume.availability_zone,
1650-
self._volume.bootable,
1651-
self._volume.description,
1652-
self._volume.id,
1653-
self._volume.name,
1654-
format_columns.DictColumn(self._volume.metadata),
1655-
self._volume.size,
1656-
self._volume.snapshot_id,
1657-
self._volume.status,
1658-
self._volume.volume_type,
1659-
),
1660-
data,
1699+
self.assertEqual(self.columns, columns)
1700+
self.assertEqual(self.data, data)
1701+
self.volume_sdk_client.find_volume.assert_called_with(
1702+
self.volume.id, ignore_missing=False
16611703
)
16621704

16631705

@@ -1748,31 +1790,47 @@ def test_volume_unset_image_property_fail(self):
17481790
)
17491791

17501792

1751-
class TestColumns(TestVolume):
1793+
class TestColumns(volume_fakes.TestVolume):
17521794
def test_attachments_column_without_server_cache(self):
1753-
_volume = volume_fakes.create_one_volume()
1754-
server_id = _volume.attachments[0]['server_id']
1755-
device = _volume.attachments[0]['device']
1795+
vol = sdk_fakes.generate_fake_resource(
1796+
_volume.Volume,
1797+
attachments=[
1798+
{
1799+
'device': '/dev/' + uuid.uuid4().hex,
1800+
'server_id': uuid.uuid4().hex,
1801+
},
1802+
],
1803+
)
1804+
server_id = vol.attachments[0]['server_id']
1805+
device = vol.attachments[0]['device']
17561806

1757-
col = volume.AttachmentsColumn(_volume.attachments, {})
1807+
col = volume.AttachmentsColumn(vol.attachments, {})
17581808
self.assertEqual(
17591809
f'Attached to {server_id} on {device} ',
17601810
col.human_readable(),
17611811
)
1762-
self.assertEqual(_volume.attachments, col.machine_readable())
1812+
self.assertEqual(vol.attachments, col.machine_readable())
17631813

17641814
def test_attachments_column_with_server_cache(self):
1765-
_volume = volume_fakes.create_one_volume()
1815+
vol = sdk_fakes.generate_fake_resource(
1816+
_volume.Volume,
1817+
attachments=[
1818+
{
1819+
'device': '/dev/' + uuid.uuid4().hex,
1820+
'server_id': uuid.uuid4().hex,
1821+
},
1822+
],
1823+
)
17661824

1767-
server_id = _volume.attachments[0]['server_id']
1768-
device = _volume.attachments[0]['device']
1825+
server_id = vol.attachments[0]['server_id']
1826+
device = vol.attachments[0]['device']
17691827
fake_server = mock.Mock()
17701828
fake_server.name = 'fake-server-name'
17711829
server_cache = {server_id: fake_server}
17721830

1773-
col = volume.AttachmentsColumn(_volume.attachments, server_cache)
1831+
col = volume.AttachmentsColumn(vol.attachments, server_cache)
17741832
self.assertEqual(
17751833
'Attached to {} on {} '.format('fake-server-name', device),
17761834
col.human_readable(),
17771835
)
1778-
self.assertEqual(_volume.attachments, col.machine_readable())
1836+
self.assertEqual(vol.attachments, col.machine_readable())

openstackclient/tests/unit/volume/v3/test_volume.py

Lines changed: 104 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import copy
1515
from unittest import mock
16+
import uuid
1617

1718
from openstack.block_storage.v3 import backup as _backup
1819
from openstack.block_storage.v3 import block_storage_summary as _summary
@@ -2004,41 +2005,91 @@ class TestVolumeShow(volume_fakes.TestVolume):
20042005
def setUp(self):
20052006
super().setUp()
20062007

2007-
self.volumes_mock = self.volume_client.volumes
2008-
self.volumes_mock.reset_mock()
2008+
self.volume = sdk_fakes.generate_fake_resource(_volume.Volume)
2009+
self.volume_sdk_client.find_volume.return_value = self.volume
2010+
2011+
self.columns = (
2012+
'attachments',
2013+
'availability_zone',
2014+
'bootable',
2015+
'cluster_name',
2016+
'consistencygroup_id',
2017+
'consumes_quota',
2018+
'created_at',
2019+
'description',
2020+
'encrypted',
2021+
'encryption_key_id',
2022+
'group_id',
2023+
'id',
2024+
'multiattach',
2025+
'name',
2026+
'os-vol-host-attr:host',
2027+
'os-vol-mig-status-attr:migstat',
2028+
'os-vol-mig-status-attr:name_id',
2029+
'os-vol-tenant-attr:tenant_id',
2030+
'properties',
2031+
'provider_id',
2032+
'replication_status',
2033+
'service_uuid',
2034+
'shared_targets',
2035+
'size',
2036+
'snapshot_id',
2037+
'source_volid',
2038+
'status',
2039+
'type',
2040+
'updated_at',
2041+
'user_id',
2042+
'volume_image_metadata',
2043+
'volume_type_id',
2044+
)
2045+
self.data = (
2046+
self.volume.attachments,
2047+
self.volume.availability_zone,
2048+
self.volume.is_bootable,
2049+
self.volume.cluster_name,
2050+
self.volume.consistency_group_id,
2051+
self.volume.consumes_quota,
2052+
self.volume.created_at,
2053+
self.volume.description,
2054+
self.volume.is_encrypted,
2055+
self.volume.encryption_key_id,
2056+
self.volume.group_id,
2057+
self.volume.id,
2058+
self.volume.is_multiattach,
2059+
self.volume.name,
2060+
self.volume.host,
2061+
self.volume.migration_status,
2062+
self.volume.migration_id,
2063+
self.volume.project_id,
2064+
format_columns.DictColumn(self.volume.metadata),
2065+
self.volume.provider_id,
2066+
self.volume.replication_status,
2067+
self.volume.service_uuid,
2068+
self.volume.shared_targets,
2069+
self.volume.size,
2070+
self.volume.snapshot_id,
2071+
self.volume.source_volume_id,
2072+
self.volume.status,
2073+
self.volume.volume_type,
2074+
self.volume.updated_at,
2075+
self.volume.user_id,
2076+
self.volume.volume_image_metadata,
2077+
self.volume.volume_type_id,
2078+
)
20092079

2010-
self._volume = volume_fakes.create_one_volume()
2011-
self.volumes_mock.get.return_value = self._volume
2012-
# Get the command object to test
20132080
self.cmd = volume.ShowVolume(self.app, None)
20142081

20152082
def test_volume_show(self):
2016-
arglist = [self._volume.id]
2017-
verifylist = [("volume", self._volume.id)]
2083+
arglist = [self.volume.id]
2084+
verifylist = [("volume", self.volume.id)]
20182085
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
20192086

20202087
columns, data = self.cmd.take_action(parsed_args)
2021-
self.volumes_mock.get.assert_called_with(self._volume.id)
20222088

2023-
self.assertEqual(
2024-
tuple(sorted(self._volume.keys())),
2025-
columns,
2026-
)
2027-
self.assertTupleEqual(
2028-
(
2029-
self._volume.attachments,
2030-
self._volume.availability_zone,
2031-
self._volume.bootable,
2032-
self._volume.description,
2033-
self._volume.id,
2034-
self._volume.name,
2035-
format_columns.DictColumn(self._volume.metadata),
2036-
self._volume.size,
2037-
self._volume.snapshot_id,
2038-
self._volume.status,
2039-
self._volume.volume_type,
2040-
),
2041-
data,
2089+
self.assertEqual(self.columns, columns)
2090+
self.assertEqual(self.data, data)
2091+
self.volume_sdk_client.find_volume.assert_called_with(
2092+
self.volume.id, ignore_missing=False
20422093
)
20432094

20442095

@@ -2284,29 +2335,45 @@ def test_volume_revert_to_snapshot(self):
22842335

22852336
class TestColumns(volume_fakes.TestVolume):
22862337
def test_attachments_column_without_server_cache(self):
2287-
_volume = volume_fakes.create_one_volume()
2288-
server_id = _volume.attachments[0]['server_id']
2289-
device = _volume.attachments[0]['device']
2338+
vol = sdk_fakes.generate_fake_resource(
2339+
_volume.Volume,
2340+
attachments=[
2341+
{
2342+
'device': '/dev/' + uuid.uuid4().hex,
2343+
'server_id': uuid.uuid4().hex,
2344+
},
2345+
],
2346+
)
2347+
server_id = vol.attachments[0]['server_id']
2348+
device = vol.attachments[0]['device']
22902349

2291-
col = volume.AttachmentsColumn(_volume.attachments, {})
2350+
col = volume.AttachmentsColumn(vol.attachments, {})
22922351
self.assertEqual(
22932352
f'Attached to {server_id} on {device} ',
22942353
col.human_readable(),
22952354
)
2296-
self.assertEqual(_volume.attachments, col.machine_readable())
2355+
self.assertEqual(vol.attachments, col.machine_readable())
22972356

22982357
def test_attachments_column_with_server_cache(self):
2299-
_volume = volume_fakes.create_one_volume()
2358+
vol = sdk_fakes.generate_fake_resource(
2359+
_volume.Volume,
2360+
attachments=[
2361+
{
2362+
'device': '/dev/' + uuid.uuid4().hex,
2363+
'server_id': uuid.uuid4().hex,
2364+
},
2365+
],
2366+
)
23002367

2301-
server_id = _volume.attachments[0]['server_id']
2302-
device = _volume.attachments[0]['device']
2368+
server_id = vol.attachments[0]['server_id']
2369+
device = vol.attachments[0]['device']
23032370
fake_server = mock.Mock()
23042371
fake_server.name = 'fake-server-name'
23052372
server_cache = {server_id: fake_server}
23062373

2307-
col = volume.AttachmentsColumn(_volume.attachments, server_cache)
2374+
col = volume.AttachmentsColumn(vol.attachments, server_cache)
23082375
self.assertEqual(
23092376
'Attached to {} on {} '.format('fake-server-name', device),
23102377
col.human_readable(),
23112378
)
2312-
self.assertEqual(_volume.attachments, col.machine_readable())
2379+
self.assertEqual(vol.attachments, col.machine_readable())

0 commit comments

Comments
 (0)