python-openstackclient 8.0.0__py3-none-any.whl → 8.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. openstackclient/api/compute_v2.py +2 -2
  2. openstackclient/api/volume_v2.py +60 -0
  3. openstackclient/api/volume_v3.py +60 -0
  4. openstackclient/compute/client.py +5 -0
  5. openstackclient/compute/v2/console.py +7 -0
  6. openstackclient/compute/v2/console_connection.py +48 -0
  7. openstackclient/compute/v2/flavor.py +14 -1
  8. openstackclient/compute/v2/keypair.py +10 -3
  9. openstackclient/compute/v2/server.py +76 -13
  10. openstackclient/compute/v2/server_event.py +1 -1
  11. openstackclient/identity/common.py +85 -11
  12. openstackclient/identity/v3/application_credential.py +88 -87
  13. openstackclient/identity/v3/domain.py +67 -49
  14. openstackclient/identity/v3/group.py +113 -68
  15. openstackclient/identity/v3/project.py +42 -20
  16. openstackclient/identity/v3/role.py +7 -2
  17. openstackclient/identity/v3/user.py +38 -5
  18. openstackclient/image/client.py +5 -0
  19. openstackclient/image/v1/image.py +16 -1
  20. openstackclient/image/v2/cache.py +10 -6
  21. openstackclient/image/v2/image.py +59 -12
  22. openstackclient/image/v2/metadef_objects.py +8 -2
  23. openstackclient/image/v2/metadef_properties.py +9 -2
  24. openstackclient/network/client.py +0 -6
  25. openstackclient/network/v2/floating_ip.py +58 -29
  26. openstackclient/network/v2/network_qos_rule.py +3 -11
  27. openstackclient/network/v2/port.py +16 -0
  28. openstackclient/network/v2/router.py +1 -1
  29. openstackclient/network/v2/security_group.py +49 -7
  30. openstackclient/network/v2/security_group_rule.py +18 -1
  31. openstackclient/shell.py +1 -1
  32. openstackclient/tests/functional/base.py +5 -1
  33. openstackclient/tests/functional/compute/v2/test_keypair.py +41 -5
  34. openstackclient/tests/functional/identity/v3/test_access_rule.py +1 -1
  35. openstackclient/tests/functional/identity/v3/test_application_credential.py +7 -7
  36. openstackclient/tests/functional/image/v2/test_image.py +36 -14
  37. openstackclient/tests/functional/volume/v2/test_volume.py +1 -1
  38. openstackclient/tests/functional/volume/v3/test_volume.py +2 -2
  39. openstackclient/tests/unit/api/test_volume_v2.py +124 -0
  40. openstackclient/tests/unit/api/test_volume_v3.py +124 -0
  41. openstackclient/tests/unit/compute/v2/fakes.py +81 -305
  42. openstackclient/tests/unit/compute/v2/test_console.py +18 -1
  43. openstackclient/tests/unit/compute/v2/test_console_connection.py +72 -0
  44. openstackclient/tests/unit/compute/v2/test_flavor.py +160 -175
  45. openstackclient/tests/unit/compute/v2/test_keypair.py +12 -5
  46. openstackclient/tests/unit/compute/v2/test_server.py +211 -97
  47. openstackclient/tests/unit/compute/v2/test_server_backup.py +32 -71
  48. openstackclient/tests/unit/compute/v2/test_server_event.py +2 -2
  49. openstackclient/tests/unit/compute/v2/test_server_image.py +33 -72
  50. openstackclient/tests/unit/compute/v2/test_server_migration.py +4 -4
  51. openstackclient/tests/unit/identity/v3/test_application_credential.py +93 -65
  52. openstackclient/tests/unit/identity/v3/test_domain.py +117 -107
  53. openstackclient/tests/unit/identity/v3/test_group.py +353 -202
  54. openstackclient/tests/unit/identity/v3/test_project.py +46 -53
  55. openstackclient/tests/unit/identity/v3/test_role.py +2 -8
  56. openstackclient/tests/unit/identity/v3/test_user.py +86 -6
  57. openstackclient/tests/unit/image/v1/test_image.py +55 -9
  58. openstackclient/tests/unit/image/v2/test_image.py +128 -58
  59. openstackclient/tests/unit/image/v2/test_metadef_objects.py +22 -0
  60. openstackclient/tests/unit/image/v2/test_metadef_properties.py +24 -10
  61. openstackclient/tests/unit/network/v2/fakes.py +406 -485
  62. openstackclient/tests/unit/network/v2/test_floating_ip_network.py +13 -19
  63. openstackclient/tests/unit/network/v2/test_l3_conntrack_helper.py +2 -2
  64. openstackclient/tests/unit/network/v2/test_ndp_proxy.py +3 -5
  65. openstackclient/tests/unit/network/v2/test_network.py +4 -4
  66. openstackclient/tests/unit/network/v2/test_network_agent.py +15 -29
  67. openstackclient/tests/unit/network/v2/test_network_qos_policy.py +16 -19
  68. openstackclient/tests/unit/network/v2/test_network_qos_rule.py +79 -152
  69. openstackclient/tests/unit/network/v2/test_network_qos_rule_type.py +4 -6
  70. openstackclient/tests/unit/network/v2/test_network_rbac.py +2 -2
  71. openstackclient/tests/unit/network/v2/test_port.py +57 -17
  72. openstackclient/tests/unit/network/v2/test_router.py +73 -57
  73. openstackclient/tests/unit/network/v2/test_security_group_network.py +31 -27
  74. openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py +1 -3
  75. openstackclient/tests/unit/network/v2/test_security_group_rule_network.py +82 -39
  76. openstackclient/tests/unit/volume/v2/fakes.py +1 -2
  77. openstackclient/tests/unit/volume/v2/test_service.py +57 -91
  78. openstackclient/tests/unit/volume/v2/test_volume.py +466 -410
  79. openstackclient/tests/unit/volume/v2/test_volume_backup.py +141 -148
  80. openstackclient/tests/unit/volume/v2/test_volume_snapshot.py +293 -283
  81. openstackclient/tests/unit/volume/v3/test_block_storage_log_level.py +61 -71
  82. openstackclient/tests/unit/volume/v3/test_service.py +221 -141
  83. openstackclient/tests/unit/volume/v3/test_volume.py +569 -534
  84. openstackclient/tests/unit/volume/v3/test_volume_attachment.py +1 -1
  85. openstackclient/tests/unit/volume/v3/test_volume_backup.py +198 -203
  86. openstackclient/tests/unit/volume/v3/test_volume_snapshot.py +682 -47
  87. openstackclient/volume/v2/service.py +41 -38
  88. openstackclient/volume/v2/volume.py +140 -88
  89. openstackclient/volume/v2/volume_backup.py +9 -3
  90. openstackclient/volume/v2/volume_snapshot.py +121 -84
  91. openstackclient/volume/v3/block_storage_log_level.py +22 -28
  92. openstackclient/volume/v3/service.py +105 -14
  93. openstackclient/volume/v3/volume.py +287 -99
  94. openstackclient/volume/v3/volume_backup.py +24 -19
  95. openstackclient/volume/v3/volume_group.py +1 -1
  96. openstackclient/volume/v3/volume_snapshot.py +485 -10
  97. {python_openstackclient-8.0.0.dist-info → python_openstackclient-8.2.0.dist-info}/AUTHORS +13 -0
  98. python_openstackclient-8.2.0.dist-info/METADATA +264 -0
  99. {python_openstackclient-8.0.0.dist-info → python_openstackclient-8.2.0.dist-info}/RECORD +104 -98
  100. {python_openstackclient-8.0.0.dist-info → python_openstackclient-8.2.0.dist-info}/entry_points.txt +7 -6
  101. python_openstackclient-8.2.0.dist-info/pbr.json +1 -0
  102. python_openstackclient-8.0.0.dist-info/METADATA +0 -166
  103. python_openstackclient-8.0.0.dist-info/pbr.json +0 -1
  104. {python_openstackclient-8.0.0.dist-info → python_openstackclient-8.2.0.dist-info}/LICENSE +0 -0
  105. {python_openstackclient-8.0.0.dist-info → python_openstackclient-8.2.0.dist-info}/WHEEL +0 -0
  106. {python_openstackclient-8.0.0.dist-info → python_openstackclient-8.2.0.dist-info}/top_level.txt +0 -0
@@ -13,9 +13,12 @@
13
13
 
14
14
  from unittest import mock
15
15
 
16
+ from openstack.block_storage.v2 import snapshot as _snapshot
17
+ from openstack.block_storage.v3 import volume as _volume
18
+ from openstack import exceptions as sdk_exceptions
19
+ from openstack.test import fakes as sdk_fakes
16
20
  from osc_lib.cli import format_columns
17
21
  from osc_lib import exceptions
18
- from osc_lib import utils
19
22
 
20
23
  from openstackclient.tests.unit.identity.v3 import fakes as project_fakes
21
24
  from openstackclient.tests.unit import utils as test_utils
@@ -23,19 +26,7 @@ from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
23
26
  from openstackclient.volume.v2 import volume_snapshot
24
27
 
25
28
 
26
- class TestVolumeSnapshot(volume_fakes.TestVolume):
27
- def setUp(self):
28
- super().setUp()
29
-
30
- self.snapshots_mock = self.volume_client.volume_snapshots
31
- self.snapshots_mock.reset_mock()
32
- self.volumes_mock = self.volume_client.volumes
33
- self.volumes_mock.reset_mock()
34
- self.project_mock = self.identity_client.projects
35
- self.project_mock.reset_mock()
36
-
37
-
38
- class TestVolumeSnapshotCreate(TestVolumeSnapshot):
29
+ class TestVolumeSnapshotCreate(volume_fakes.TestVolume):
39
30
  columns = (
40
31
  'created_at',
41
32
  'description',
@@ -50,69 +41,71 @@ class TestVolumeSnapshotCreate(TestVolumeSnapshot):
50
41
  def setUp(self):
51
42
  super().setUp()
52
43
 
53
- self.volume = volume_fakes.create_one_volume()
54
- self.new_snapshot = volume_fakes.create_one_snapshot(
55
- attrs={'volume_id': self.volume.id}
44
+ self.volume = sdk_fakes.generate_fake_resource(_volume.Volume)
45
+ self.volume_sdk_client.find_volume.return_value = self.volume
46
+ self.snapshot = sdk_fakes.generate_fake_resource(
47
+ _snapshot.Snapshot, volume_id=self.volume.id
56
48
  )
49
+ self.volume_sdk_client.create_snapshot.return_value = self.snapshot
50
+ self.volume_sdk_client.manage_snapshot.return_value = self.snapshot
57
51
 
58
52
  self.data = (
59
- self.new_snapshot.created_at,
60
- self.new_snapshot.description,
61
- self.new_snapshot.id,
62
- self.new_snapshot.name,
63
- format_columns.DictColumn(self.new_snapshot.metadata),
64
- self.new_snapshot.size,
65
- self.new_snapshot.status,
66
- self.new_snapshot.volume_id,
67
- )
68
-
69
- self.volumes_mock.get.return_value = self.volume
70
- self.snapshots_mock.create.return_value = self.new_snapshot
71
- self.snapshots_mock.manage.return_value = self.new_snapshot
72
- # Get the command object to test
53
+ self.snapshot.created_at,
54
+ self.snapshot.description,
55
+ self.snapshot.id,
56
+ self.snapshot.name,
57
+ format_columns.DictColumn(self.snapshot.metadata),
58
+ self.snapshot.size,
59
+ self.snapshot.status,
60
+ self.snapshot.volume_id,
61
+ )
62
+
73
63
  self.cmd = volume_snapshot.CreateVolumeSnapshot(self.app, None)
74
64
 
75
65
  def test_snapshot_create(self):
76
66
  arglist = [
77
67
  "--volume",
78
- self.new_snapshot.volume_id,
68
+ self.snapshot.volume_id,
79
69
  "--description",
80
- self.new_snapshot.description,
70
+ self.snapshot.description,
81
71
  "--force",
82
72
  '--property',
83
73
  'Alpha=a',
84
74
  '--property',
85
75
  'Beta=b',
86
- self.new_snapshot.name,
76
+ self.snapshot.name,
87
77
  ]
88
78
  verifylist = [
89
- ("volume", self.new_snapshot.volume_id),
90
- ("description", self.new_snapshot.description),
79
+ ("volume", self.snapshot.volume_id),
80
+ ("description", self.snapshot.description),
91
81
  ("force", True),
92
- ('property', {'Alpha': 'a', 'Beta': 'b'}),
93
- ("snapshot_name", self.new_snapshot.name),
82
+ ('properties', {'Alpha': 'a', 'Beta': 'b'}),
83
+ ("snapshot_name", self.snapshot.name),
94
84
  ]
95
85
  parsed_args = self.check_parser(self.cmd, arglist, verifylist)
96
86
 
97
87
  columns, data = self.cmd.take_action(parsed_args)
98
88
 
99
- self.snapshots_mock.create.assert_called_with(
100
- self.new_snapshot.volume_id,
89
+ self.assertEqual(self.columns, columns)
90
+ self.assertEqual(self.data, data)
91
+ self.volume_sdk_client.find_volume.assert_called_once_with(
92
+ self.snapshot.volume_id, ignore_missing=False
93
+ )
94
+ self.volume_sdk_client.create_snapshot.assert_called_with(
95
+ volume_id=self.snapshot.volume_id,
101
96
  force=True,
102
- name=self.new_snapshot.name,
103
- description=self.new_snapshot.description,
97
+ name=self.snapshot.name,
98
+ description=self.snapshot.description,
104
99
  metadata={'Alpha': 'a', 'Beta': 'b'},
105
100
  )
106
- self.assertEqual(self.columns, columns)
107
- self.assertEqual(self.data, data)
108
101
 
109
102
  def test_snapshot_create_without_name(self):
110
103
  arglist = [
111
104
  "--volume",
112
- self.new_snapshot.volume_id,
105
+ self.snapshot.volume_id,
113
106
  ]
114
107
  verifylist = [
115
- ("volume", self.new_snapshot.volume_id),
108
+ ("volume", self.snapshot.volume_id),
116
109
  ]
117
110
  self.assertRaises(
118
111
  test_utils.ParserException,
@@ -125,29 +118,31 @@ class TestVolumeSnapshotCreate(TestVolumeSnapshot):
125
118
  def test_snapshot_create_without_volume(self):
126
119
  arglist = [
127
120
  "--description",
128
- self.new_snapshot.description,
121
+ self.snapshot.description,
129
122
  "--force",
130
- self.new_snapshot.name,
123
+ self.snapshot.name,
131
124
  ]
132
125
  verifylist = [
133
- ("description", self.new_snapshot.description),
126
+ ("description", self.snapshot.description),
134
127
  ("force", True),
135
- ("snapshot_name", self.new_snapshot.name),
128
+ ("snapshot_name", self.snapshot.name),
136
129
  ]
137
130
  parsed_args = self.check_parser(self.cmd, arglist, verifylist)
138
131
 
139
132
  columns, data = self.cmd.take_action(parsed_args)
140
133
 
141
- self.volumes_mock.get.assert_called_once_with(self.new_snapshot.name)
142
- self.snapshots_mock.create.assert_called_once_with(
143
- self.new_snapshot.volume_id,
134
+ self.assertEqual(self.columns, columns)
135
+ self.assertEqual(self.data, data)
136
+ self.volume_sdk_client.find_volume.assert_called_once_with(
137
+ self.snapshot.name, ignore_missing=False
138
+ )
139
+ self.volume_sdk_client.create_snapshot.assert_called_once_with(
140
+ volume_id=self.snapshot.volume_id,
144
141
  force=True,
145
- name=self.new_snapshot.name,
146
- description=self.new_snapshot.description,
142
+ name=self.snapshot.name,
143
+ description=self.snapshot.description,
147
144
  metadata=None,
148
145
  )
149
- self.assertEqual(self.columns, columns)
150
- self.assertEqual(self.data, data)
151
146
 
152
147
  def test_snapshot_create_with_remote_source(self):
153
148
  arglist = [
@@ -156,8 +151,8 @@ class TestVolumeSnapshotCreate(TestVolumeSnapshot):
156
151
  '--remote-source',
157
152
  'source-id=test_source_id',
158
153
  '--volume',
159
- self.new_snapshot.volume_id,
160
- self.new_snapshot.name,
154
+ self.snapshot.volume_id,
155
+ self.snapshot.name,
161
156
  ]
162
157
  ref_dict = {
163
158
  'source-name': 'test_source_name',
@@ -165,35 +160,38 @@ class TestVolumeSnapshotCreate(TestVolumeSnapshot):
165
160
  }
166
161
  verifylist = [
167
162
  ('remote_source', ref_dict),
168
- ('volume', self.new_snapshot.volume_id),
169
- ("snapshot_name", self.new_snapshot.name),
163
+ ('volume', self.snapshot.volume_id),
164
+ ("snapshot_name", self.snapshot.name),
170
165
  ]
171
166
  parsed_args = self.check_parser(self.cmd, arglist, verifylist)
172
167
 
173
168
  columns, data = self.cmd.take_action(parsed_args)
174
169
 
175
- self.snapshots_mock.manage.assert_called_with(
176
- volume_id=self.new_snapshot.volume_id,
170
+ self.assertEqual(self.columns, columns)
171
+ self.assertEqual(self.data, data)
172
+ self.volume_sdk_client.find_volume.assert_called_once_with(
173
+ self.snapshot.volume_id, ignore_missing=False
174
+ )
175
+ self.volume_sdk_client.manage_snapshot.assert_called_with(
176
+ volume_id=self.snapshot.volume_id,
177
177
  ref=ref_dict,
178
- name=self.new_snapshot.name,
178
+ name=self.snapshot.name,
179
179
  description=None,
180
180
  metadata=None,
181
181
  )
182
- self.snapshots_mock.create.assert_not_called()
183
- self.assertEqual(self.columns, columns)
184
- self.assertEqual(self.data, data)
182
+ self.volume_sdk_client.create_snapshot.assert_not_called()
185
183
 
186
184
 
187
- class TestVolumeSnapshotDelete(TestVolumeSnapshot):
188
- snapshots = volume_fakes.create_snapshots(count=2)
189
-
185
+ class TestVolumeSnapshotDelete(volume_fakes.TestVolume):
190
186
  def setUp(self):
191
187
  super().setUp()
192
188
 
193
- self.snapshots_mock.get = volume_fakes.get_snapshots(self.snapshots)
194
- self.snapshots_mock.delete.return_value = None
189
+ self.snapshots = list(
190
+ sdk_fakes.generate_fake_resources(_snapshot.Snapshot)
191
+ )
192
+ self.volume_sdk_client.find_snapshot.side_effect = self.snapshots
193
+ self.volume_sdk_client.delete_snapshot.return_value = None
195
194
 
196
- # Get the command object to mock
197
195
  self.cmd = volume_snapshot.DeleteVolumeSnapshot(self.app, None)
198
196
 
199
197
  def test_snapshot_delete(self):
@@ -202,11 +200,14 @@ class TestVolumeSnapshotDelete(TestVolumeSnapshot):
202
200
  parsed_args = self.check_parser(self.cmd, arglist, verifylist)
203
201
 
204
202
  result = self.cmd.take_action(parsed_args)
203
+ self.assertIsNone(result)
205
204
 
206
- self.snapshots_mock.delete.assert_called_with(
207
- self.snapshots[0].id, False
205
+ self.volume_sdk_client.find_snapshot.assert_called_once_with(
206
+ self.snapshots[0].id, ignore_missing=False
207
+ )
208
+ self.volume_sdk_client.delete_snapshot.assert_called_once_with(
209
+ self.snapshots[0].id, force=False
208
210
  )
209
- self.assertIsNone(result)
210
211
 
211
212
  def test_snapshot_delete_with_force(self):
212
213
  arglist = ['--force', self.snapshots[0].id]
@@ -214,11 +215,14 @@ class TestVolumeSnapshotDelete(TestVolumeSnapshot):
214
215
  parsed_args = self.check_parser(self.cmd, arglist, verifylist)
215
216
 
216
217
  result = self.cmd.take_action(parsed_args)
218
+ self.assertIsNone(result)
217
219
 
218
- self.snapshots_mock.delete.assert_called_with(
219
- self.snapshots[0].id, True
220
+ self.volume_sdk_client.find_snapshot.assert_called_once_with(
221
+ self.snapshots[0].id, ignore_missing=False
222
+ )
223
+ self.volume_sdk_client.delete_snapshot.assert_called_once_with(
224
+ self.snapshots[0].id, force=True
220
225
  )
221
- self.assertIsNone(result)
222
226
 
223
227
  def test_delete_multiple_snapshots(self):
224
228
  arglist = []
@@ -227,17 +231,24 @@ class TestVolumeSnapshotDelete(TestVolumeSnapshot):
227
231
  verifylist = [
228
232
  ('snapshots', arglist),
229
233
  ]
230
-
231
234
  parsed_args = self.check_parser(self.cmd, arglist, verifylist)
232
- result = self.cmd.take_action(parsed_args)
233
235
 
234
- calls = []
235
- for s in self.snapshots:
236
- calls.append(mock.call(s.id, False))
237
- self.snapshots_mock.delete.assert_has_calls(calls)
236
+ result = self.cmd.take_action(parsed_args)
238
237
  self.assertIsNone(result)
239
238
 
239
+ self.volume_sdk_client.find_snapshot.assert_has_calls(
240
+ [mock.call(x.id, ignore_missing=False) for x in self.snapshots]
241
+ )
242
+ self.volume_sdk_client.delete_snapshot.assert_has_calls(
243
+ [mock.call(x.id, force=False) for x in self.snapshots]
244
+ )
245
+
240
246
  def test_delete_multiple_snapshots_with_exception(self):
247
+ self.volume_sdk_client.find_snapshot.side_effect = [
248
+ self.snapshots[0],
249
+ sdk_exceptions.NotFoundException(),
250
+ ]
251
+
241
252
  arglist = [
242
253
  self.snapshots[0].id,
243
254
  'unexist_snapshot',
@@ -248,73 +259,77 @@ class TestVolumeSnapshotDelete(TestVolumeSnapshot):
248
259
 
249
260
  parsed_args = self.check_parser(self.cmd, arglist, verifylist)
250
261
 
251
- find_mock_result = [self.snapshots[0], exceptions.CommandError]
252
- with mock.patch.object(
253
- utils, 'find_resource', side_effect=find_mock_result
254
- ) as find_mock:
255
- try:
256
- self.cmd.take_action(parsed_args)
257
- self.fail('CommandError should be raised.')
258
- except exceptions.CommandError as e:
259
- self.assertEqual('1 of 2 snapshots failed to delete.', str(e))
260
-
261
- find_mock.assert_any_call(
262
- self.snapshots_mock, self.snapshots[0].id
263
- )
264
- find_mock.assert_any_call(self.snapshots_mock, 'unexist_snapshot')
262
+ exc = self.assertRaises(
263
+ exceptions.CommandError,
264
+ self.cmd.take_action,
265
+ parsed_args,
266
+ )
267
+ self.assertEqual('1 of 2 snapshots failed to delete.', str(exc))
265
268
 
266
- self.assertEqual(2, find_mock.call_count)
267
- self.snapshots_mock.delete.assert_called_once_with(
268
- self.snapshots[0].id, False
269
- )
269
+ self.volume_sdk_client.find_snapshot.assert_has_calls(
270
+ [
271
+ mock.call(self.snapshots[0].id, ignore_missing=False),
272
+ mock.call('unexist_snapshot', ignore_missing=False),
273
+ ]
274
+ )
275
+ self.volume_sdk_client.delete_snapshot.assert_has_calls(
276
+ [
277
+ mock.call(self.snapshots[0].id, force=False),
278
+ ]
279
+ )
270
280
 
271
281
 
272
- class TestVolumeSnapshotList(TestVolumeSnapshot):
273
- volume = volume_fakes.create_one_volume()
274
- project = project_fakes.FakeProject.create_one_project()
275
- snapshots = volume_fakes.create_snapshots(
276
- attrs={'volume_id': volume.name}, count=3
277
- )
282
+ class TestVolumeSnapshotList(volume_fakes.TestVolume):
283
+ def setUp(self):
284
+ super().setUp()
278
285
 
279
- columns = ["ID", "Name", "Description", "Status", "Size"]
280
- columns_long = columns + ["Created At", "Volume", "Properties"]
281
-
282
- data = []
283
- for s in snapshots:
284
- data.append(
285
- (
286
- s.id,
287
- s.name,
288
- s.description,
289
- s.status,
290
- s.size,
286
+ self.volume = sdk_fakes.generate_fake_resource(_volume.Volume)
287
+ self.snapshots = list(
288
+ sdk_fakes.generate_fake_resources(
289
+ _snapshot.Snapshot, attrs={'volume_id': self.volume.name}
291
290
  )
292
291
  )
293
- data_long = []
294
- for s in snapshots:
295
- data_long.append(
296
- (
297
- s.id,
298
- s.name,
299
- s.description,
300
- s.status,
301
- s.size,
302
- s.created_at,
303
- volume_snapshot.VolumeIdColumn(
304
- s.volume_id, volume_cache={volume.id: volume}
305
- ),
306
- format_columns.DictColumn(s.metadata),
307
- )
292
+ self.project = project_fakes.FakeProject.create_one_project()
293
+ self.volume_sdk_client.volumes.return_value = [self.volume]
294
+ self.volume_sdk_client.find_volume.return_value = self.volume
295
+ self.volume_sdk_client.snapshots.return_value = self.snapshots
296
+ self.project_mock = self.identity_client.projects
297
+ self.project_mock.get.return_value = self.project
298
+
299
+ self.columns = ("ID", "Name", "Description", "Status", "Size")
300
+ self.columns_long = self.columns + (
301
+ "Created At",
302
+ "Volume",
303
+ "Properties",
308
304
  )
309
305
 
310
- def setUp(self):
311
- super().setUp()
306
+ self.data = []
307
+ self.data_long = []
308
+ for s in self.snapshots:
309
+ self.data.append(
310
+ (
311
+ s.id,
312
+ s.name,
313
+ s.description,
314
+ s.status,
315
+ s.size,
316
+ )
317
+ )
318
+ self.data_long.append(
319
+ (
320
+ s.id,
321
+ s.name,
322
+ s.description,
323
+ s.status,
324
+ s.size,
325
+ s.created_at,
326
+ volume_snapshot.VolumeIdColumn(
327
+ s.volume_id, volume_cache={self.volume.id: self.volume}
328
+ ),
329
+ format_columns.DictColumn(s.metadata),
330
+ )
331
+ )
312
332
 
313
- self.volumes_mock.list.return_value = [self.volume]
314
- self.volumes_mock.get.return_value = self.volume
315
- self.project_mock.get.return_value = self.project
316
- self.snapshots_mock.list.return_value = self.snapshots
317
- # Get the command to test
318
333
  self.cmd = volume_snapshot.ListVolumeSnapshot(self.app, None)
319
334
 
320
335
  def test_snapshot_list_without_options(self):
@@ -324,16 +339,14 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
324
339
 
325
340
  columns, data = self.cmd.take_action(parsed_args)
326
341
 
327
- self.snapshots_mock.list.assert_called_once_with(
342
+ self.volume_sdk_client.snapshots.assert_called_once_with(
328
343
  limit=None,
329
344
  marker=None,
330
- search_opts={
331
- 'all_tenants': False,
332
- 'name': None,
333
- 'status': None,
334
- 'project_id': None,
335
- 'volume_id': None,
336
- },
345
+ all_projects=False,
346
+ name=None,
347
+ status=None,
348
+ project_id=None,
349
+ volume_id=None,
337
350
  )
338
351
  self.assertEqual(self.columns, columns)
339
352
  self.assertEqual(self.data, list(data))
@@ -359,16 +372,14 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
359
372
 
360
373
  columns, data = self.cmd.take_action(parsed_args)
361
374
 
362
- self.snapshots_mock.list.assert_called_once_with(
375
+ self.volume_sdk_client.snapshots.assert_called_once_with(
363
376
  limit=2,
364
377
  marker=self.snapshots[0].id,
365
- search_opts={
366
- 'all_tenants': True,
367
- 'project_id': self.project.id,
368
- 'name': None,
369
- 'status': None,
370
- 'volume_id': None,
371
- },
378
+ all_projects=True,
379
+ project_id=self.project.id,
380
+ name=None,
381
+ status=None,
382
+ volume_id=None,
372
383
  )
373
384
  self.assertEqual(self.columns_long, columns)
374
385
  self.assertEqual(self.data_long, list(data))
@@ -382,16 +393,14 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
382
393
 
383
394
  columns, data = self.cmd.take_action(parsed_args)
384
395
 
385
- self.snapshots_mock.list.assert_called_once_with(
396
+ self.volume_sdk_client.snapshots.assert_called_once_with(
386
397
  limit=None,
387
398
  marker=None,
388
- search_opts={
389
- 'all_tenants': True,
390
- 'name': None,
391
- 'status': None,
392
- 'project_id': None,
393
- 'volume_id': None,
394
- },
399
+ all_projects=True,
400
+ name=None,
401
+ status=None,
402
+ project_id=None,
403
+ volume_id=None,
395
404
  )
396
405
  self.assertEqual(self.columns, columns)
397
406
  self.assertEqual(self.data, list(data))
@@ -410,16 +419,14 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
410
419
 
411
420
  columns, data = self.cmd.take_action(parsed_args)
412
421
 
413
- self.snapshots_mock.list.assert_called_once_with(
422
+ self.volume_sdk_client.snapshots.assert_called_once_with(
414
423
  limit=None,
415
424
  marker=None,
416
- search_opts={
417
- 'all_tenants': False,
418
- 'name': self.snapshots[0].name,
419
- 'status': None,
420
- 'project_id': None,
421
- 'volume_id': None,
422
- },
425
+ all_projects=False,
426
+ name=self.snapshots[0].name,
427
+ status=None,
428
+ project_id=None,
429
+ volume_id=None,
423
430
  )
424
431
  self.assertEqual(self.columns, columns)
425
432
  self.assertEqual(self.data, list(data))
@@ -427,27 +434,25 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
427
434
  def test_snapshot_list_status_option(self):
428
435
  arglist = [
429
436
  '--status',
430
- self.snapshots[0].status,
437
+ 'available',
431
438
  ]
432
439
  verifylist = [
433
440
  ('all_projects', False),
434
441
  ('long', False),
435
- ('status', self.snapshots[0].status),
442
+ ('status', 'available'),
436
443
  ]
437
444
  parsed_args = self.check_parser(self.cmd, arglist, verifylist)
438
445
 
439
446
  columns, data = self.cmd.take_action(parsed_args)
440
447
 
441
- self.snapshots_mock.list.assert_called_once_with(
448
+ self.volume_sdk_client.snapshots.assert_called_once_with(
442
449
  limit=None,
443
450
  marker=None,
444
- search_opts={
445
- 'all_tenants': False,
446
- 'name': None,
447
- 'status': self.snapshots[0].status,
448
- 'project_id': None,
449
- 'volume_id': None,
450
- },
451
+ all_projects=False,
452
+ name=None,
453
+ status='available',
454
+ project_id=None,
455
+ volume_id=None,
451
456
  )
452
457
  self.assertEqual(self.columns, columns)
453
458
  self.assertEqual(self.data, list(data))
@@ -466,16 +471,14 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
466
471
 
467
472
  columns, data = self.cmd.take_action(parsed_args)
468
473
 
469
- self.snapshots_mock.list.assert_called_once_with(
474
+ self.volume_sdk_client.snapshots.assert_called_once_with(
470
475
  limit=None,
471
476
  marker=None,
472
- search_opts={
473
- 'all_tenants': False,
474
- 'name': None,
475
- 'status': None,
476
- 'project_id': None,
477
- 'volume_id': self.volume.id,
478
- },
477
+ all_projects=False,
478
+ name=None,
479
+ status=None,
480
+ project_id=None,
481
+ volume_id=self.volume.id,
479
482
  )
480
483
  self.assertEqual(self.columns, columns)
481
484
  self.assertEqual(self.data, list(data))
@@ -497,16 +500,18 @@ class TestVolumeSnapshotList(TestVolumeSnapshot):
497
500
  )
498
501
 
499
502
 
500
- class TestVolumeSnapshotSet(TestVolumeSnapshot):
501
- snapshot = volume_fakes.create_one_snapshot()
502
-
503
+ class TestVolumeSnapshotSet(volume_fakes.TestVolume):
503
504
  def setUp(self):
504
505
  super().setUp()
505
506
 
506
- self.snapshots_mock.get.return_value = self.snapshot
507
- self.snapshots_mock.set_metadata.return_value = None
508
- self.snapshots_mock.update.return_value = None
509
- # Get the command object to mock
507
+ self.snapshot = sdk_fakes.generate_fake_resource(
508
+ _snapshot.Snapshot, metadata={'foo': 'bar'}
509
+ )
510
+ self.volume_sdk_client.find_snapshot.return_value = self.snapshot
511
+ self.volume_sdk_client.delete_snapshot_metadata.return_value = None
512
+ self.volume_sdk_client.set_snapshot_metadata.return_value = None
513
+ self.volume_sdk_client.update_snapshot.return_value = None
514
+
510
515
  self.cmd = volume_snapshot.SetVolumeSnapshot(self.app, None)
511
516
 
512
517
  def test_snapshot_set_no_option(self):
@@ -519,11 +524,14 @@ class TestVolumeSnapshotSet(TestVolumeSnapshot):
519
524
  parsed_args = self.check_parser(self.cmd, arglist, verifylist)
520
525
 
521
526
  result = self.cmd.take_action(parsed_args)
522
- self.snapshots_mock.get.assert_called_once_with(parsed_args.snapshot)
523
- self.assertNotCalled(self.snapshots_mock.reset_state)
524
- self.assertNotCalled(self.snapshots_mock.update)
525
- self.assertNotCalled(self.snapshots_mock.set_metadata)
527
+
526
528
  self.assertIsNone(result)
529
+ self.volume_sdk_client.find_snapshot.assert_called_once_with(
530
+ parsed_args.snapshot, ignore_missing=False
531
+ )
532
+ self.volume_sdk_client.reset_snapshot_status.assert_not_called()
533
+ self.volume_sdk_client.update_snapshot.assert_not_called()
534
+ self.volume_sdk_client.set_snapshot_metadata.assert_not_called()
527
535
 
528
536
  def test_snapshot_set_name_and_property(self):
529
537
  arglist = [
@@ -535,26 +543,22 @@ class TestVolumeSnapshotSet(TestVolumeSnapshot):
535
543
  "foo=foo",
536
544
  self.snapshot.id,
537
545
  ]
538
- new_property = {"x": "y", "foo": "foo"}
539
546
  verifylist = [
540
547
  ("name", "new_snapshot"),
541
- ("property", new_property),
548
+ ("properties", {"x": "y", "foo": "foo"}),
542
549
  ("snapshot", self.snapshot.id),
543
550
  ]
544
551
  parsed_args = self.check_parser(self.cmd, arglist, verifylist)
545
552
 
546
553
  result = self.cmd.take_action(parsed_args)
547
554
 
548
- kwargs = {
549
- "name": "new_snapshot",
550
- }
551
- self.snapshots_mock.update.assert_called_with(
552
- self.snapshot.id, **kwargs
555
+ self.assertIsNone(result)
556
+ self.volume_sdk_client.update_snapshot.assert_called_with(
557
+ self.snapshot.id, name="new_snapshot"
553
558
  )
554
- self.snapshots_mock.set_metadata.assert_called_with(
555
- self.snapshot.id, new_property
559
+ self.volume_sdk_client.set_snapshot_metadata.assert_called_with(
560
+ self.snapshot.id, x="y", foo="foo"
556
561
  )
557
- self.assertIsNone(result)
558
562
 
559
563
  def test_snapshot_set_with_no_property(self):
560
564
  arglist = [
@@ -568,14 +572,17 @@ class TestVolumeSnapshotSet(TestVolumeSnapshot):
568
572
  parsed_args = self.check_parser(self.cmd, arglist, verifylist)
569
573
 
570
574
  result = self.cmd.take_action(parsed_args)
571
- self.snapshots_mock.get.assert_called_once_with(parsed_args.snapshot)
572
- self.assertNotCalled(self.snapshots_mock.reset_state)
573
- self.assertNotCalled(self.snapshots_mock.update)
574
- self.assertNotCalled(self.snapshots_mock.set_metadata)
575
- self.snapshots_mock.delete_metadata.assert_called_with(
576
- self.snapshot.id, ["foo"]
577
- )
575
+
578
576
  self.assertIsNone(result)
577
+ self.volume_sdk_client.find_snapshot.assert_called_once_with(
578
+ parsed_args.snapshot, ignore_missing=False
579
+ )
580
+ self.volume_sdk_client.reset_snapshot_status.assert_not_called()
581
+ self.volume_sdk_client.update_snapshot.assert_not_called()
582
+ self.volume_sdk_client.set_snapshot_metadata.assert_not_called()
583
+ self.volume_sdk_client.delete_snapshot_metadata.assert_called_with(
584
+ self.snapshot.id, keys=["foo"]
585
+ )
579
586
 
580
587
  def test_snapshot_set_with_no_property_and_property(self):
581
588
  arglist = [
@@ -586,22 +593,26 @@ class TestVolumeSnapshotSet(TestVolumeSnapshot):
586
593
  ]
587
594
  verifylist = [
588
595
  ("no_property", True),
589
- ("property", {"foo_1": "bar_1"}),
596
+ ("properties", {"foo_1": "bar_1"}),
590
597
  ("snapshot", self.snapshot.id),
591
598
  ]
592
599
  parsed_args = self.check_parser(self.cmd, arglist, verifylist)
593
600
 
594
601
  result = self.cmd.take_action(parsed_args)
595
- self.snapshots_mock.get.assert_called_once_with(parsed_args.snapshot)
596
- self.assertNotCalled(self.snapshots_mock.reset_state)
597
- self.assertNotCalled(self.snapshots_mock.update)
598
- self.snapshots_mock.delete_metadata.assert_called_with(
599
- self.snapshot.id, ["foo"]
602
+
603
+ self.assertIsNone(result)
604
+ self.volume_sdk_client.find_snapshot.assert_called_once_with(
605
+ parsed_args.snapshot, ignore_missing=False
600
606
  )
601
- self.snapshots_mock.set_metadata.assert_called_once_with(
602
- self.snapshot.id, {"foo_1": "bar_1"}
607
+ self.volume_sdk_client.reset_snapshot_status.assert_not_called()
608
+ self.volume_sdk_client.update_snapshot.assert_not_called()
609
+ self.volume_sdk_client.delete_snapshot_metadata.assert_called_with(
610
+ self.snapshot.id, keys=["foo"]
611
+ )
612
+ self.volume_sdk_client.set_snapshot_metadata.assert_called_once_with(
613
+ self.snapshot.id,
614
+ foo_1="bar_1",
603
615
  )
604
- self.assertIsNone(result)
605
616
 
606
617
  def test_snapshot_set_state_to_error(self):
607
618
  arglist = ["--state", "error", self.snapshot.id]
@@ -610,30 +621,32 @@ class TestVolumeSnapshotSet(TestVolumeSnapshot):
610
621
 
611
622
  result = self.cmd.take_action(parsed_args)
612
623
 
613
- self.snapshots_mock.reset_state.assert_called_with(
624
+ self.assertIsNone(result)
625
+ self.volume_sdk_client.reset_snapshot_status.assert_called_with(
614
626
  self.snapshot.id, "error"
615
627
  )
616
- self.assertIsNone(result)
617
628
 
618
629
  def test_volume_set_state_failed(self):
619
- self.snapshots_mock.reset_state.side_effect = exceptions.CommandError()
630
+ self.volume_sdk_client.reset_snapshot_status.side_effect = (
631
+ exceptions.CommandError()
632
+ )
620
633
  arglist = ['--state', 'error', self.snapshot.id]
621
634
  verifylist = [('state', 'error'), ('snapshot', self.snapshot.id)]
622
635
 
623
636
  parsed_args = self.check_parser(self.cmd, arglist, verifylist)
624
- try:
625
- self.cmd.take_action(parsed_args)
626
- self.fail('CommandError should be raised.')
627
- except exceptions.CommandError as e:
628
- self.assertEqual(
629
- 'One or more of the set operations failed', str(e)
630
- )
631
- self.snapshots_mock.reset_state.assert_called_once_with(
637
+
638
+ exc = self.assertRaises(
639
+ exceptions.CommandError, self.cmd.take_action, parsed_args
640
+ )
641
+ self.assertEqual('One or more of the set operations failed', str(exc))
642
+ self.volume_sdk_client.reset_snapshot_status.assert_called_once_with(
632
643
  self.snapshot.id, 'error'
633
644
  )
634
645
 
635
646
  def test_volume_set_name_and_state_failed(self):
636
- self.snapshots_mock.reset_state.side_effect = exceptions.CommandError()
647
+ self.volume_sdk_client.reset_snapshot_status.side_effect = (
648
+ exceptions.CommandError()
649
+ )
637
650
  arglist = [
638
651
  '--state',
639
652
  'error',
@@ -646,43 +659,39 @@ class TestVolumeSnapshotSet(TestVolumeSnapshot):
646
659
  ("name", "new_snapshot"),
647
660
  ('snapshot', self.snapshot.id),
648
661
  ]
649
-
650
662
  parsed_args = self.check_parser(self.cmd, arglist, verifylist)
651
- try:
652
- self.cmd.take_action(parsed_args)
653
- self.fail('CommandError should be raised.')
654
- except exceptions.CommandError as e:
655
- self.assertEqual(
656
- 'One or more of the set operations failed', str(e)
657
- )
658
- kwargs = {
659
- "name": "new_snapshot",
660
- }
661
- self.snapshots_mock.update.assert_called_once_with(
662
- self.snapshot.id, **kwargs
663
+
664
+ exc = self.assertRaises(
665
+ exceptions.CommandError,
666
+ self.cmd.take_action,
667
+ parsed_args,
668
+ )
669
+
670
+ self.assertEqual('One or more of the set operations failed', str(exc))
671
+ self.volume_sdk_client.update_snapshot.assert_called_once_with(
672
+ self.snapshot.id, name="new_snapshot"
663
673
  )
664
- self.snapshots_mock.reset_state.assert_called_once_with(
674
+ self.volume_sdk_client.reset_snapshot_status.assert_called_once_with(
665
675
  self.snapshot.id, 'error'
666
676
  )
667
677
 
668
678
 
669
- class TestVolumeSnapshotShow(TestVolumeSnapshot):
670
- columns = (
671
- 'created_at',
672
- 'description',
673
- 'id',
674
- 'name',
675
- 'properties',
676
- 'size',
677
- 'status',
678
- 'volume_id',
679
- )
680
-
679
+ class TestVolumeSnapshotShow(volume_fakes.TestVolume):
681
680
  def setUp(self):
682
681
  super().setUp()
683
682
 
684
- self.snapshot = volume_fakes.create_one_snapshot()
685
-
683
+ self.snapshot = sdk_fakes.generate_fake_resource(_snapshot.Snapshot)
684
+
685
+ self.columns = (
686
+ 'created_at',
687
+ 'description',
688
+ 'id',
689
+ 'name',
690
+ 'properties',
691
+ 'size',
692
+ 'status',
693
+ 'volume_id',
694
+ )
686
695
  self.data = (
687
696
  self.snapshot.created_at,
688
697
  self.snapshot.description,
@@ -694,8 +703,8 @@ class TestVolumeSnapshotShow(TestVolumeSnapshot):
694
703
  self.snapshot.volume_id,
695
704
  )
696
705
 
697
- self.snapshots_mock.get.return_value = self.snapshot
698
- # Get the command object to test
706
+ self.volume_sdk_client.find_snapshot.return_value = self.snapshot
707
+
699
708
  self.cmd = volume_snapshot.ShowVolumeSnapshot(self.app, None)
700
709
 
701
710
  def test_snapshot_show(self):
@@ -704,21 +713,22 @@ class TestVolumeSnapshotShow(TestVolumeSnapshot):
704
713
  parsed_args = self.check_parser(self.cmd, arglist, verifylist)
705
714
 
706
715
  columns, data = self.cmd.take_action(parsed_args)
707
- self.snapshots_mock.get.assert_called_with(self.snapshot.id)
716
+ self.volume_sdk_client.find_snapshot.assert_called_with(
717
+ self.snapshot.id, ignore_missing=False
718
+ )
708
719
 
709
720
  self.assertEqual(self.columns, columns)
710
721
  self.assertCountEqual(self.data, data)
711
722
 
712
723
 
713
- class TestVolumeSnapshotUnset(TestVolumeSnapshot):
714
- snapshot = volume_fakes.create_one_snapshot()
715
-
724
+ class TestVolumeSnapshotUnset(volume_fakes.TestVolume):
716
725
  def setUp(self):
717
726
  super().setUp()
718
727
 
719
- self.snapshots_mock.get.return_value = self.snapshot
720
- self.snapshots_mock.delete_metadata.return_value = None
721
- # Get the command object to mock
728
+ self.snapshot = sdk_fakes.generate_fake_resource(_snapshot.Snapshot)
729
+ self.volume_sdk_client.find_snapshot.return_value = self.snapshot
730
+ self.volume_sdk_client.delete_snapshot_metadata.return_value = None
731
+
722
732
  self.cmd = volume_snapshot.UnsetVolumeSnapshot(self.app, None)
723
733
 
724
734
  def test_snapshot_unset(self):
@@ -728,7 +738,7 @@ class TestVolumeSnapshotUnset(TestVolumeSnapshot):
728
738
  self.snapshot.id,
729
739
  ]
730
740
  verifylist = [
731
- ("property", ["foo"]),
741
+ ("properties", ["foo"]),
732
742
  ("snapshot", self.snapshot.id),
733
743
  ]
734
744
 
@@ -736,7 +746,7 @@ class TestVolumeSnapshotUnset(TestVolumeSnapshot):
736
746
 
737
747
  result = self.cmd.take_action(parsed_args)
738
748
 
739
- self.snapshots_mock.delete_metadata.assert_called_with(
740
- self.snapshot.id, ["foo"]
741
- )
742
749
  self.assertIsNone(result)
750
+ self.volume_sdk_client.delete_snapshot_metadata.assert_called_with(
751
+ self.snapshot.id, keys=["foo"]
752
+ )