volume: Migrate 'snapshot show', 'snapshot list' to SDK
Change-Id: I40de24012363f496e46c3dddc31a3e2563ccf443 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
@@ -26,18 +26,6 @@ from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
|
||||
from openstackclient.volume.v2 import volume_snapshot
|
||||
|
||||
|
||||
class TestVolumeSnapshot(volume_fakes.TestVolume):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.snapshots_mock = self.volume_client.volume_snapshots
|
||||
self.snapshots_mock.reset_mock()
|
||||
self.volumes_mock = self.volume_client.volumes
|
||||
self.volumes_mock.reset_mock()
|
||||
self.project_mock = self.identity_client.projects
|
||||
self.project_mock.reset_mock()
|
||||
|
||||
|
||||
class TestVolumeSnapshotCreate(volume_fakes.TestVolume):
|
||||
columns = (
|
||||
'created_at',
|
||||
@@ -291,52 +279,57 @@ class TestVolumeSnapshotDelete(volume_fakes.TestVolume):
|
||||
)
|
||||
|
||||
|
||||
class TestVolumeSnapshotList(TestVolumeSnapshot):
|
||||
volume = volume_fakes.create_one_volume()
|
||||
project = project_fakes.FakeProject.create_one_project()
|
||||
snapshots = volume_fakes.create_snapshots(
|
||||
attrs={'volume_id': volume.name}, count=3
|
||||
)
|
||||
|
||||
columns = ["ID", "Name", "Description", "Status", "Size"]
|
||||
columns_long = columns + ["Created At", "Volume", "Properties"]
|
||||
|
||||
data = []
|
||||
for s in snapshots:
|
||||
data.append(
|
||||
(
|
||||
s.id,
|
||||
s.name,
|
||||
s.description,
|
||||
s.status,
|
||||
s.size,
|
||||
)
|
||||
)
|
||||
data_long = []
|
||||
for s in snapshots:
|
||||
data_long.append(
|
||||
(
|
||||
s.id,
|
||||
s.name,
|
||||
s.description,
|
||||
s.status,
|
||||
s.size,
|
||||
s.created_at,
|
||||
volume_snapshot.VolumeIdColumn(
|
||||
s.volume_id, volume_cache={volume.id: volume}
|
||||
),
|
||||
format_columns.DictColumn(s.metadata),
|
||||
)
|
||||
)
|
||||
|
||||
class TestVolumeSnapshotList(volume_fakes.TestVolume):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.volumes_mock.list.return_value = [self.volume]
|
||||
self.volumes_mock.get.return_value = self.volume
|
||||
self.volume = sdk_fakes.generate_fake_resource(_volume.Volume)
|
||||
self.snapshots = list(
|
||||
sdk_fakes.generate_fake_resources(
|
||||
_snapshot.Snapshot, attrs={'volume_id': self.volume.name}
|
||||
)
|
||||
)
|
||||
self.project = project_fakes.FakeProject.create_one_project()
|
||||
self.volume_sdk_client.volumes.return_value = [self.volume]
|
||||
self.volume_sdk_client.find_volume.return_value = self.volume
|
||||
self.volume_sdk_client.snapshots.return_value = self.snapshots
|
||||
self.project_mock = self.identity_client.projects
|
||||
self.project_mock.get.return_value = self.project
|
||||
self.snapshots_mock.list.return_value = self.snapshots
|
||||
# Get the command to test
|
||||
|
||||
self.columns = ("ID", "Name", "Description", "Status", "Size")
|
||||
self.columns_long = self.columns + (
|
||||
"Created At",
|
||||
"Volume",
|
||||
"Properties",
|
||||
)
|
||||
|
||||
self.data = []
|
||||
self.data_long = []
|
||||
for s in self.snapshots:
|
||||
self.data.append(
|
||||
(
|
||||
s.id,
|
||||
s.name,
|
||||
s.description,
|
||||
s.status,
|
||||
s.size,
|
||||
)
|
||||
)
|
||||
self.data_long.append(
|
||||
(
|
||||
s.id,
|
||||
s.name,
|
||||
s.description,
|
||||
s.status,
|
||||
s.size,
|
||||
s.created_at,
|
||||
volume_snapshot.VolumeIdColumn(
|
||||
s.volume_id, volume_cache={self.volume.id: self.volume}
|
||||
),
|
||||
format_columns.DictColumn(s.metadata),
|
||||
)
|
||||
)
|
||||
|
||||
self.cmd = volume_snapshot.ListVolumeSnapshot(self.app, None)
|
||||
|
||||
def test_snapshot_list_without_options(self):
|
||||
@@ -346,16 +339,14 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.snapshots_mock.list.assert_called_once_with(
|
||||
self.volume_sdk_client.snapshots.assert_called_once_with(
|
||||
limit=None,
|
||||
marker=None,
|
||||
search_opts={
|
||||
'all_tenants': False,
|
||||
'name': None,
|
||||
'status': None,
|
||||
'project_id': None,
|
||||
'volume_id': None,
|
||||
},
|
||||
all_projects=False,
|
||||
name=None,
|
||||
status=None,
|
||||
project_id=None,
|
||||
volume_id=None,
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
@@ -381,16 +372,14 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.snapshots_mock.list.assert_called_once_with(
|
||||
self.volume_sdk_client.snapshots.assert_called_once_with(
|
||||
limit=2,
|
||||
marker=self.snapshots[0].id,
|
||||
search_opts={
|
||||
'all_tenants': True,
|
||||
'project_id': self.project.id,
|
||||
'name': None,
|
||||
'status': None,
|
||||
'volume_id': None,
|
||||
},
|
||||
all_projects=True,
|
||||
project_id=self.project.id,
|
||||
name=None,
|
||||
status=None,
|
||||
volume_id=None,
|
||||
)
|
||||
self.assertEqual(self.columns_long, columns)
|
||||
self.assertEqual(self.data_long, list(data))
|
||||
@@ -404,16 +393,14 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.snapshots_mock.list.assert_called_once_with(
|
||||
self.volume_sdk_client.snapshots.assert_called_once_with(
|
||||
limit=None,
|
||||
marker=None,
|
||||
search_opts={
|
||||
'all_tenants': True,
|
||||
'name': None,
|
||||
'status': None,
|
||||
'project_id': None,
|
||||
'volume_id': None,
|
||||
},
|
||||
all_projects=True,
|
||||
name=None,
|
||||
status=None,
|
||||
project_id=None,
|
||||
volume_id=None,
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
@@ -432,16 +419,14 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.snapshots_mock.list.assert_called_once_with(
|
||||
self.volume_sdk_client.snapshots.assert_called_once_with(
|
||||
limit=None,
|
||||
marker=None,
|
||||
search_opts={
|
||||
'all_tenants': False,
|
||||
'name': self.snapshots[0].name,
|
||||
'status': None,
|
||||
'project_id': None,
|
||||
'volume_id': None,
|
||||
},
|
||||
all_projects=False,
|
||||
name=self.snapshots[0].name,
|
||||
status=None,
|
||||
project_id=None,
|
||||
volume_id=None,
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
@@ -449,27 +434,25 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
|
||||
def test_snapshot_list_status_option(self):
|
||||
arglist = [
|
||||
'--status',
|
||||
self.snapshots[0].status,
|
||||
'available',
|
||||
]
|
||||
verifylist = [
|
||||
('all_projects', False),
|
||||
('long', False),
|
||||
('status', self.snapshots[0].status),
|
||||
('status', 'available'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.snapshots_mock.list.assert_called_once_with(
|
||||
self.volume_sdk_client.snapshots.assert_called_once_with(
|
||||
limit=None,
|
||||
marker=None,
|
||||
search_opts={
|
||||
'all_tenants': False,
|
||||
'name': None,
|
||||
'status': self.snapshots[0].status,
|
||||
'project_id': None,
|
||||
'volume_id': None,
|
||||
},
|
||||
all_projects=False,
|
||||
name=None,
|
||||
status='available',
|
||||
project_id=None,
|
||||
volume_id=None,
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
@@ -488,16 +471,14 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.snapshots_mock.list.assert_called_once_with(
|
||||
self.volume_sdk_client.snapshots.assert_called_once_with(
|
||||
limit=None,
|
||||
marker=None,
|
||||
search_opts={
|
||||
'all_tenants': False,
|
||||
'name': None,
|
||||
'status': None,
|
||||
'project_id': None,
|
||||
'volume_id': self.volume.id,
|
||||
},
|
||||
all_projects=False,
|
||||
name=None,
|
||||
status=None,
|
||||
project_id=None,
|
||||
volume_id=self.volume.id,
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
@@ -695,23 +676,22 @@ class TestVolumeSnapshotSet(volume_fakes.TestVolume):
|
||||
)
|
||||
|
||||
|
||||
class TestVolumeSnapshotShow(TestVolumeSnapshot):
|
||||
columns = (
|
||||
'created_at',
|
||||
'description',
|
||||
'id',
|
||||
'name',
|
||||
'properties',
|
||||
'size',
|
||||
'status',
|
||||
'volume_id',
|
||||
)
|
||||
|
||||
class TestVolumeSnapshotShow(volume_fakes.TestVolume):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.snapshot = volume_fakes.create_one_snapshot()
|
||||
self.snapshot = sdk_fakes.generate_fake_resource(_snapshot.Snapshot)
|
||||
|
||||
self.columns = (
|
||||
'created_at',
|
||||
'description',
|
||||
'id',
|
||||
'name',
|
||||
'properties',
|
||||
'size',
|
||||
'status',
|
||||
'volume_id',
|
||||
)
|
||||
self.data = (
|
||||
self.snapshot.created_at,
|
||||
self.snapshot.description,
|
||||
@@ -723,8 +703,8 @@ class TestVolumeSnapshotShow(TestVolumeSnapshot):
|
||||
self.snapshot.volume_id,
|
||||
)
|
||||
|
||||
self.snapshots_mock.get.return_value = self.snapshot
|
||||
# Get the command object to test
|
||||
self.volume_sdk_client.find_snapshot.return_value = self.snapshot
|
||||
|
||||
self.cmd = volume_snapshot.ShowVolumeSnapshot(self.app, None)
|
||||
|
||||
def test_snapshot_show(self):
|
||||
@@ -733,7 +713,9 @@ class TestVolumeSnapshotShow(TestVolumeSnapshot):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.snapshots_mock.get.assert_called_with(self.snapshot.id)
|
||||
self.volume_sdk_client.find_snapshot.assert_called_with(
|
||||
self.snapshot.id, ignore_missing=False
|
||||
)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertCountEqual(self.data, data)
|
||||
|
@@ -22,37 +22,11 @@ from osc_lib import exceptions
|
||||
|
||||
from openstackclient.tests.unit.identity.v3 import fakes as project_fakes
|
||||
from openstackclient.tests.unit import utils as test_utils
|
||||
from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
|
||||
from openstackclient.tests.unit.volume.v3 import fakes as volume_fakes_v3
|
||||
from openstackclient.tests.unit.volume.v3 import fakes as volume_fakes
|
||||
from openstackclient.volume.v3 import volume_snapshot
|
||||
|
||||
|
||||
class TestVolumeSnapshot(volume_fakes_v3.TestVolume):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.snapshots_mock = self.volume_client.volume_snapshots
|
||||
self.snapshots_mock.reset_mock()
|
||||
self.volumes_mock = self.volume_client.volumes
|
||||
self.volumes_mock.reset_mock()
|
||||
self.project_mock = self.identity_client.projects
|
||||
self.project_mock.reset_mock()
|
||||
|
||||
self.volume_sdk_client.unmanage_snapshot.return_value = None
|
||||
|
||||
|
||||
class TestVolumeSnapshotCreate(volume_fakes_v3.TestVolume):
|
||||
columns = (
|
||||
'created_at',
|
||||
'description',
|
||||
'id',
|
||||
'name',
|
||||
'properties',
|
||||
'size',
|
||||
'status',
|
||||
'volume_id',
|
||||
)
|
||||
|
||||
class TestVolumeSnapshotCreate(volume_fakes.TestVolume):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
@@ -64,6 +38,16 @@ class TestVolumeSnapshotCreate(volume_fakes_v3.TestVolume):
|
||||
self.volume_sdk_client.create_snapshot.return_value = self.snapshot
|
||||
self.volume_sdk_client.manage_snapshot.return_value = self.snapshot
|
||||
|
||||
self.columns = (
|
||||
'created_at',
|
||||
'description',
|
||||
'id',
|
||||
'name',
|
||||
'properties',
|
||||
'size',
|
||||
'status',
|
||||
'volume_id',
|
||||
)
|
||||
self.data = (
|
||||
self.snapshot.created_at,
|
||||
self.snapshot.description,
|
||||
@@ -197,7 +181,7 @@ class TestVolumeSnapshotCreate(volume_fakes_v3.TestVolume):
|
||||
self.volume_sdk_client.create_snapshot.assert_not_called()
|
||||
|
||||
|
||||
class TestVolumeSnapshotDelete(volume_fakes_v3.TestVolume):
|
||||
class TestVolumeSnapshotDelete(volume_fakes.TestVolume):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
@@ -338,52 +322,57 @@ class TestVolumeSnapshotDelete(volume_fakes_v3.TestVolume):
|
||||
)
|
||||
|
||||
|
||||
class TestVolumeSnapshotList(TestVolumeSnapshot):
|
||||
volume = volume_fakes.create_one_volume()
|
||||
project = project_fakes.FakeProject.create_one_project()
|
||||
snapshots = volume_fakes.create_snapshots(
|
||||
attrs={'volume_id': volume.name}, count=3
|
||||
)
|
||||
|
||||
columns = ["ID", "Name", "Description", "Status", "Size"]
|
||||
columns_long = columns + ["Created At", "Volume", "Properties"]
|
||||
|
||||
data = []
|
||||
for s in snapshots:
|
||||
data.append(
|
||||
(
|
||||
s.id,
|
||||
s.name,
|
||||
s.description,
|
||||
s.status,
|
||||
s.size,
|
||||
)
|
||||
)
|
||||
data_long = []
|
||||
for s in snapshots:
|
||||
data_long.append(
|
||||
(
|
||||
s.id,
|
||||
s.name,
|
||||
s.description,
|
||||
s.status,
|
||||
s.size,
|
||||
s.created_at,
|
||||
volume_snapshot.VolumeIdColumn(
|
||||
s.volume_id, volume_cache={volume.id: volume}
|
||||
),
|
||||
format_columns.DictColumn(s.metadata),
|
||||
)
|
||||
)
|
||||
|
||||
class TestVolumeSnapshotList(volume_fakes.TestVolume):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.volumes_mock.list.return_value = [self.volume]
|
||||
self.volumes_mock.get.return_value = self.volume
|
||||
self.volume = sdk_fakes.generate_fake_resource(_volume.Volume)
|
||||
self.snapshots = list(
|
||||
sdk_fakes.generate_fake_resources(
|
||||
_snapshot.Snapshot, attrs={'volume_id': self.volume.name}
|
||||
)
|
||||
)
|
||||
self.project = project_fakes.FakeProject.create_one_project()
|
||||
self.volume_sdk_client.volumes.return_value = [self.volume]
|
||||
self.volume_sdk_client.find_volume.return_value = self.volume
|
||||
self.volume_sdk_client.snapshots.return_value = self.snapshots
|
||||
self.project_mock = self.identity_client.projects
|
||||
self.project_mock.get.return_value = self.project
|
||||
self.snapshots_mock.list.return_value = self.snapshots
|
||||
# Get the command to test
|
||||
|
||||
self.columns = ("ID", "Name", "Description", "Status", "Size")
|
||||
self.columns_long = self.columns + (
|
||||
"Created At",
|
||||
"Volume",
|
||||
"Properties",
|
||||
)
|
||||
|
||||
self.data = []
|
||||
self.data_long = []
|
||||
for s in self.snapshots:
|
||||
self.data.append(
|
||||
(
|
||||
s.id,
|
||||
s.name,
|
||||
s.description,
|
||||
s.status,
|
||||
s.size,
|
||||
)
|
||||
)
|
||||
self.data_long.append(
|
||||
(
|
||||
s.id,
|
||||
s.name,
|
||||
s.description,
|
||||
s.status,
|
||||
s.size,
|
||||
s.created_at,
|
||||
volume_snapshot.VolumeIdColumn(
|
||||
s.volume_id, volume_cache={self.volume.id: self.volume}
|
||||
),
|
||||
format_columns.DictColumn(s.metadata),
|
||||
)
|
||||
)
|
||||
|
||||
self.cmd = volume_snapshot.ListVolumeSnapshot(self.app, None)
|
||||
|
||||
def test_snapshot_list_without_options(self):
|
||||
@@ -393,16 +382,14 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.snapshots_mock.list.assert_called_once_with(
|
||||
self.volume_sdk_client.snapshots.assert_called_once_with(
|
||||
limit=None,
|
||||
marker=None,
|
||||
search_opts={
|
||||
'all_tenants': False,
|
||||
'name': None,
|
||||
'status': None,
|
||||
'project_id': None,
|
||||
'volume_id': None,
|
||||
},
|
||||
all_projects=False,
|
||||
name=None,
|
||||
status=None,
|
||||
project_id=None,
|
||||
volume_id=None,
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
@@ -428,16 +415,14 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.snapshots_mock.list.assert_called_once_with(
|
||||
self.volume_sdk_client.snapshots.assert_called_once_with(
|
||||
limit=2,
|
||||
marker=self.snapshots[0].id,
|
||||
search_opts={
|
||||
'all_tenants': True,
|
||||
'project_id': self.project.id,
|
||||
'name': None,
|
||||
'status': None,
|
||||
'volume_id': None,
|
||||
},
|
||||
all_projects=True,
|
||||
project_id=self.project.id,
|
||||
name=None,
|
||||
status=None,
|
||||
volume_id=None,
|
||||
)
|
||||
self.assertEqual(self.columns_long, columns)
|
||||
self.assertEqual(self.data_long, list(data))
|
||||
@@ -451,16 +436,14 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.snapshots_mock.list.assert_called_once_with(
|
||||
self.volume_sdk_client.snapshots.assert_called_once_with(
|
||||
limit=None,
|
||||
marker=None,
|
||||
search_opts={
|
||||
'all_tenants': True,
|
||||
'name': None,
|
||||
'status': None,
|
||||
'project_id': None,
|
||||
'volume_id': None,
|
||||
},
|
||||
all_projects=True,
|
||||
name=None,
|
||||
status=None,
|
||||
project_id=None,
|
||||
volume_id=None,
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
@@ -479,16 +462,14 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.snapshots_mock.list.assert_called_once_with(
|
||||
self.volume_sdk_client.snapshots.assert_called_once_with(
|
||||
limit=None,
|
||||
marker=None,
|
||||
search_opts={
|
||||
'all_tenants': False,
|
||||
'name': self.snapshots[0].name,
|
||||
'status': None,
|
||||
'project_id': None,
|
||||
'volume_id': None,
|
||||
},
|
||||
all_projects=False,
|
||||
name=self.snapshots[0].name,
|
||||
status=None,
|
||||
project_id=None,
|
||||
volume_id=None,
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
@@ -496,27 +477,25 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
|
||||
def test_snapshot_list_status_option(self):
|
||||
arglist = [
|
||||
'--status',
|
||||
self.snapshots[0].status,
|
||||
'available',
|
||||
]
|
||||
verifylist = [
|
||||
('all_projects', False),
|
||||
('long', False),
|
||||
('status', self.snapshots[0].status),
|
||||
('status', 'available'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.snapshots_mock.list.assert_called_once_with(
|
||||
self.volume_sdk_client.snapshots.assert_called_once_with(
|
||||
limit=None,
|
||||
marker=None,
|
||||
search_opts={
|
||||
'all_tenants': False,
|
||||
'name': None,
|
||||
'status': self.snapshots[0].status,
|
||||
'project_id': None,
|
||||
'volume_id': None,
|
||||
},
|
||||
all_projects=False,
|
||||
name=None,
|
||||
status='available',
|
||||
project_id=None,
|
||||
volume_id=None,
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
@@ -535,16 +514,14 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.snapshots_mock.list.assert_called_once_with(
|
||||
self.volume_sdk_client.snapshots.assert_called_once_with(
|
||||
limit=None,
|
||||
marker=None,
|
||||
search_opts={
|
||||
'all_tenants': False,
|
||||
'name': None,
|
||||
'status': None,
|
||||
'project_id': None,
|
||||
'volume_id': self.volume.id,
|
||||
},
|
||||
all_projects=False,
|
||||
name=None,
|
||||
status=None,
|
||||
project_id=None,
|
||||
volume_id=self.volume.id,
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
@@ -566,7 +543,7 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
|
||||
)
|
||||
|
||||
|
||||
class TestVolumeSnapshotSet(volume_fakes_v3.TestVolume):
|
||||
class TestVolumeSnapshotSet(volume_fakes.TestVolume):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
@@ -743,23 +720,22 @@ class TestVolumeSnapshotSet(volume_fakes_v3.TestVolume):
|
||||
)
|
||||
|
||||
|
||||
class TestVolumeSnapshotShow(TestVolumeSnapshot):
|
||||
columns = (
|
||||
'created_at',
|
||||
'description',
|
||||
'id',
|
||||
'name',
|
||||
'properties',
|
||||
'size',
|
||||
'status',
|
||||
'volume_id',
|
||||
)
|
||||
|
||||
class TestVolumeSnapshotShow(volume_fakes.TestVolume):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.snapshot = volume_fakes.create_one_snapshot()
|
||||
self.snapshot = sdk_fakes.generate_fake_resource(_snapshot.Snapshot)
|
||||
|
||||
self.columns = (
|
||||
'created_at',
|
||||
'description',
|
||||
'id',
|
||||
'name',
|
||||
'properties',
|
||||
'size',
|
||||
'status',
|
||||
'volume_id',
|
||||
)
|
||||
self.data = (
|
||||
self.snapshot.created_at,
|
||||
self.snapshot.description,
|
||||
@@ -771,8 +747,8 @@ class TestVolumeSnapshotShow(TestVolumeSnapshot):
|
||||
self.snapshot.volume_id,
|
||||
)
|
||||
|
||||
self.snapshots_mock.get.return_value = self.snapshot
|
||||
# Get the command object to test
|
||||
self.volume_sdk_client.find_snapshot.return_value = self.snapshot
|
||||
|
||||
self.cmd = volume_snapshot.ShowVolumeSnapshot(self.app, None)
|
||||
|
||||
def test_snapshot_show(self):
|
||||
@@ -781,13 +757,15 @@ class TestVolumeSnapshotShow(TestVolumeSnapshot):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.snapshots_mock.get.assert_called_with(self.snapshot.id)
|
||||
self.volume_sdk_client.find_snapshot.assert_called_with(
|
||||
self.snapshot.id, ignore_missing=False
|
||||
)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertCountEqual(self.data, data)
|
||||
|
||||
|
||||
class TestVolumeSnapshotUnset(volume_fakes_v3.TestVolume):
|
||||
class TestVolumeSnapshotUnset(volume_fakes.TestVolume):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
|
@@ -14,7 +14,6 @@
|
||||
|
||||
"""Volume v2 snapshot action implementations"""
|
||||
|
||||
import copy
|
||||
import functools
|
||||
import logging
|
||||
import typing as ty
|
||||
@@ -297,31 +296,39 @@ class ListVolumeSnapshot(command.Lister):
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
volume_client = self.app.client_manager.volume
|
||||
volume_client = self.app.client_manager.sdk_connection.volume
|
||||
identity_client = self.app.client_manager.identity
|
||||
|
||||
columns: tuple[str, ...] = (
|
||||
'id',
|
||||
'name',
|
||||
'description',
|
||||
'status',
|
||||
'size',
|
||||
)
|
||||
column_headers: tuple[str, ...] = (
|
||||
'ID',
|
||||
'Name',
|
||||
'Description',
|
||||
'Status',
|
||||
'Size',
|
||||
)
|
||||
if parsed_args.long:
|
||||
columns = [
|
||||
'ID',
|
||||
'Name',
|
||||
'Description',
|
||||
'Status',
|
||||
'Size',
|
||||
columns += (
|
||||
'created_at',
|
||||
'volume_id',
|
||||
'metadata',
|
||||
)
|
||||
column_headers += (
|
||||
'Created At',
|
||||
'Volume ID',
|
||||
'Metadata',
|
||||
]
|
||||
column_headers = copy.deepcopy(columns)
|
||||
column_headers[6] = 'Volume'
|
||||
column_headers[7] = 'Properties'
|
||||
else:
|
||||
columns = ['ID', 'Name', 'Description', 'Status', 'Size']
|
||||
column_headers = copy.deepcopy(columns)
|
||||
'Volume',
|
||||
'Properties',
|
||||
)
|
||||
|
||||
# Cache the volume list
|
||||
volume_cache = {}
|
||||
try:
|
||||
for s in volume_client.volumes.list():
|
||||
for s in volume_client.volumes():
|
||||
volume_cache[s.id] = s
|
||||
except Exception: # noqa: S110
|
||||
# Just forget it if there's any trouble
|
||||
@@ -332,8 +339,8 @@ class ListVolumeSnapshot(command.Lister):
|
||||
|
||||
volume_id = None
|
||||
if parsed_args.volume:
|
||||
volume_id = utils.find_resource(
|
||||
volume_client.volumes, parsed_args.volume
|
||||
volume_id = volume_client.find_volume(
|
||||
parsed_args.volume, ignore_missing=False
|
||||
).id
|
||||
|
||||
project_id = None
|
||||
@@ -349,18 +356,14 @@ class ListVolumeSnapshot(command.Lister):
|
||||
True if parsed_args.project else parsed_args.all_projects
|
||||
)
|
||||
|
||||
search_opts = {
|
||||
'all_tenants': all_projects,
|
||||
'project_id': project_id,
|
||||
'name': parsed_args.name,
|
||||
'status': parsed_args.status,
|
||||
'volume_id': volume_id,
|
||||
}
|
||||
|
||||
data = volume_client.volume_snapshots.list(
|
||||
search_opts=search_opts,
|
||||
data = volume_client.snapshots(
|
||||
marker=parsed_args.marker,
|
||||
limit=parsed_args.limit,
|
||||
all_projects=all_projects,
|
||||
project_id=project_id,
|
||||
name=parsed_args.name,
|
||||
status=parsed_args.status,
|
||||
volume_id=volume_id,
|
||||
)
|
||||
return (
|
||||
column_headers,
|
||||
@@ -369,8 +372,8 @@ class ListVolumeSnapshot(command.Lister):
|
||||
s,
|
||||
columns,
|
||||
formatters={
|
||||
'Metadata': format_columns.DictColumn,
|
||||
'Volume ID': _VolumeIdColumn,
|
||||
'metadata': format_columns.DictColumn,
|
||||
'volume_id': _VolumeIdColumn,
|
||||
},
|
||||
)
|
||||
for s in data
|
||||
@@ -506,18 +509,14 @@ class ShowVolumeSnapshot(command.ShowOne):
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
volume_client = self.app.client_manager.volume
|
||||
snapshot = utils.find_resource(
|
||||
volume_client.volume_snapshots, parsed_args.snapshot
|
||||
volume_client = self.app.client_manager.sdk_connection.volume
|
||||
|
||||
snapshot = volume_client.find_snapshot(
|
||||
parsed_args.snapshot, ignore_missing=False
|
||||
)
|
||||
snapshot._info.update(
|
||||
{
|
||||
'properties': format_columns.DictColumn(
|
||||
snapshot._info.pop('metadata')
|
||||
)
|
||||
}
|
||||
)
|
||||
return zip(*sorted(snapshot._info.items()))
|
||||
|
||||
data = _format_snapshot(snapshot)
|
||||
return zip(*sorted(data.items()))
|
||||
|
||||
|
||||
class UnsetVolumeSnapshot(command.Command):
|
||||
|
@@ -14,7 +14,6 @@
|
||||
|
||||
"""Volume v3 snapshot action implementations"""
|
||||
|
||||
import copy
|
||||
import functools
|
||||
import logging
|
||||
import typing as ty
|
||||
@@ -315,31 +314,39 @@ class ListVolumeSnapshot(command.Lister):
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
volume_client = self.app.client_manager.volume
|
||||
volume_client = self.app.client_manager.sdk_connection.volume
|
||||
identity_client = self.app.client_manager.identity
|
||||
|
||||
columns: tuple[str, ...] = (
|
||||
'id',
|
||||
'name',
|
||||
'description',
|
||||
'status',
|
||||
'size',
|
||||
)
|
||||
column_headers: tuple[str, ...] = (
|
||||
'ID',
|
||||
'Name',
|
||||
'Description',
|
||||
'Status',
|
||||
'Size',
|
||||
)
|
||||
if parsed_args.long:
|
||||
columns = [
|
||||
'ID',
|
||||
'Name',
|
||||
'Description',
|
||||
'Status',
|
||||
'Size',
|
||||
columns += (
|
||||
'created_at',
|
||||
'volume_id',
|
||||
'metadata',
|
||||
)
|
||||
column_headers += (
|
||||
'Created At',
|
||||
'Volume ID',
|
||||
'Metadata',
|
||||
]
|
||||
column_headers = copy.deepcopy(columns)
|
||||
column_headers[6] = 'Volume'
|
||||
column_headers[7] = 'Properties'
|
||||
else:
|
||||
columns = ['ID', 'Name', 'Description', 'Status', 'Size']
|
||||
column_headers = copy.deepcopy(columns)
|
||||
'Volume',
|
||||
'Properties',
|
||||
)
|
||||
|
||||
# Cache the volume list
|
||||
volume_cache = {}
|
||||
try:
|
||||
for s in volume_client.volumes.list():
|
||||
for s in volume_client.volumes():
|
||||
volume_cache[s.id] = s
|
||||
except Exception: # noqa: S110
|
||||
# Just forget it if there's any trouble
|
||||
@@ -350,8 +357,8 @@ class ListVolumeSnapshot(command.Lister):
|
||||
|
||||
volume_id = None
|
||||
if parsed_args.volume:
|
||||
volume_id = utils.find_resource(
|
||||
volume_client.volumes, parsed_args.volume
|
||||
volume_id = volume_client.find_volume(
|
||||
parsed_args.volume, ignore_missing=False
|
||||
).id
|
||||
|
||||
project_id = None
|
||||
@@ -367,18 +374,14 @@ class ListVolumeSnapshot(command.Lister):
|
||||
True if parsed_args.project else parsed_args.all_projects
|
||||
)
|
||||
|
||||
search_opts = {
|
||||
'all_tenants': all_projects,
|
||||
'project_id': project_id,
|
||||
'name': parsed_args.name,
|
||||
'status': parsed_args.status,
|
||||
'volume_id': volume_id,
|
||||
}
|
||||
|
||||
data = volume_client.volume_snapshots.list(
|
||||
search_opts=search_opts,
|
||||
data = volume_client.snapshots(
|
||||
marker=parsed_args.marker,
|
||||
limit=parsed_args.limit,
|
||||
all_projects=all_projects,
|
||||
project_id=project_id,
|
||||
name=parsed_args.name,
|
||||
status=parsed_args.status,
|
||||
volume_id=volume_id,
|
||||
)
|
||||
return (
|
||||
column_headers,
|
||||
@@ -387,8 +390,8 @@ class ListVolumeSnapshot(command.Lister):
|
||||
s,
|
||||
columns,
|
||||
formatters={
|
||||
'Metadata': format_columns.DictColumn,
|
||||
'Volume ID': _VolumeIdColumn,
|
||||
'metadata': format_columns.DictColumn,
|
||||
'volume_id': _VolumeIdColumn,
|
||||
},
|
||||
)
|
||||
for s in data
|
||||
@@ -524,18 +527,14 @@ class ShowVolumeSnapshot(command.ShowOne):
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
volume_client = self.app.client_manager.volume
|
||||
snapshot = utils.find_resource(
|
||||
volume_client.volume_snapshots, parsed_args.snapshot
|
||||
volume_client = self.app.client_manager.sdk_connection.volume
|
||||
|
||||
snapshot = volume_client.find_snapshot(
|
||||
parsed_args.snapshot, ignore_missing=False
|
||||
)
|
||||
snapshot._info.update(
|
||||
{
|
||||
'properties': format_columns.DictColumn(
|
||||
snapshot._info.pop('metadata')
|
||||
)
|
||||
}
|
||||
)
|
||||
return zip(*sorted(snapshot._info.items()))
|
||||
|
||||
data = _format_snapshot(snapshot)
|
||||
return zip(*sorted(data.items()))
|
||||
|
||||
|
||||
class UnsetVolumeSnapshot(command.Command):
|
||||
|
Reference in New Issue
Block a user