Skip to content

Commit d025490

Browse files
committed
volume: Add v3-specific consistency group snapshot module
Change-Id: I756766b28414a42a0ef4f5084a5ee350f8bb6fd2 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent 0ce4928 commit d025490

3 files changed

Lines changed: 583 additions & 4 deletions

File tree

Lines changed: 354 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,354 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3+
# not use this file except in compliance with the License. You may obtain
4+
# a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
# License for the specific language governing permissions and limitations
12+
# under the License.
13+
14+
from unittest.mock import call
15+
16+
from openstackclient.tests.unit.volume.v3 import fakes as volume_fakes
17+
from openstackclient.volume.v3 import consistency_group_snapshot
18+
19+
20+
class TestConsistencyGroupSnapshot(volume_fakes.TestVolume):
21+
def setUp(self):
22+
super().setUp()
23+
24+
# Get a shortcut to the TransferManager Mock
25+
self.cgsnapshots_mock = self.volume_client.cgsnapshots
26+
self.cgsnapshots_mock.reset_mock()
27+
self.consistencygroups_mock = self.volume_client.consistencygroups
28+
self.consistencygroups_mock.reset_mock()
29+
30+
31+
class TestConsistencyGroupSnapshotCreate(TestConsistencyGroupSnapshot):
32+
_consistency_group_snapshot = (
33+
volume_fakes.create_one_consistency_group_snapshot()
34+
)
35+
consistency_group = volume_fakes.create_one_consistency_group()
36+
37+
columns = (
38+
'consistencygroup_id',
39+
'created_at',
40+
'description',
41+
'id',
42+
'name',
43+
'status',
44+
)
45+
data = (
46+
_consistency_group_snapshot.consistencygroup_id,
47+
_consistency_group_snapshot.created_at,
48+
_consistency_group_snapshot.description,
49+
_consistency_group_snapshot.id,
50+
_consistency_group_snapshot.name,
51+
_consistency_group_snapshot.status,
52+
)
53+
54+
def setUp(self):
55+
super().setUp()
56+
self.cgsnapshots_mock.create.return_value = (
57+
self._consistency_group_snapshot
58+
)
59+
self.consistencygroups_mock.get.return_value = self.consistency_group
60+
61+
# Get the command object to test
62+
self.cmd = consistency_group_snapshot.CreateConsistencyGroupSnapshot(
63+
self.app, None
64+
)
65+
66+
def test_consistency_group_snapshot_create(self):
67+
arglist = [
68+
'--consistency-group',
69+
self.consistency_group.id,
70+
'--description',
71+
self._consistency_group_snapshot.description,
72+
self._consistency_group_snapshot.name,
73+
]
74+
verifylist = [
75+
('consistency_group', self.consistency_group.id),
76+
('description', self._consistency_group_snapshot.description),
77+
('snapshot_name', self._consistency_group_snapshot.name),
78+
]
79+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
80+
81+
columns, data = self.cmd.take_action(parsed_args)
82+
83+
self.consistencygroups_mock.get.assert_called_once_with(
84+
self.consistency_group.id
85+
)
86+
self.cgsnapshots_mock.create.assert_called_once_with(
87+
self.consistency_group.id,
88+
name=self._consistency_group_snapshot.name,
89+
description=self._consistency_group_snapshot.description,
90+
)
91+
92+
self.assertEqual(self.columns, columns)
93+
self.assertEqual(self.data, data)
94+
95+
def test_consistency_group_snapshot_create_no_consistency_group(self):
96+
arglist = [
97+
'--description',
98+
self._consistency_group_snapshot.description,
99+
self._consistency_group_snapshot.name,
100+
]
101+
verifylist = [
102+
('description', self._consistency_group_snapshot.description),
103+
('snapshot_name', self._consistency_group_snapshot.name),
104+
]
105+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
106+
107+
columns, data = self.cmd.take_action(parsed_args)
108+
109+
self.consistencygroups_mock.get.assert_called_once_with(
110+
self._consistency_group_snapshot.name
111+
)
112+
self.cgsnapshots_mock.create.assert_called_once_with(
113+
self.consistency_group.id,
114+
name=self._consistency_group_snapshot.name,
115+
description=self._consistency_group_snapshot.description,
116+
)
117+
118+
self.assertEqual(self.columns, columns)
119+
self.assertEqual(self.data, data)
120+
121+
122+
class TestConsistencyGroupSnapshotDelete(TestConsistencyGroupSnapshot):
123+
consistency_group_snapshots = (
124+
volume_fakes.create_consistency_group_snapshots(count=2)
125+
)
126+
127+
def setUp(self):
128+
super().setUp()
129+
130+
self.cgsnapshots_mock.get = (
131+
volume_fakes.get_consistency_group_snapshots(
132+
self.consistency_group_snapshots
133+
)
134+
)
135+
self.cgsnapshots_mock.delete.return_value = None
136+
137+
# Get the command object to mock
138+
self.cmd = consistency_group_snapshot.DeleteConsistencyGroupSnapshot(
139+
self.app, None
140+
)
141+
142+
def test_consistency_group_snapshot_delete(self):
143+
arglist = [self.consistency_group_snapshots[0].id]
144+
verifylist = [
145+
(
146+
"consistency_group_snapshot",
147+
[self.consistency_group_snapshots[0].id],
148+
)
149+
]
150+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
151+
152+
result = self.cmd.take_action(parsed_args)
153+
154+
self.cgsnapshots_mock.delete.assert_called_once_with(
155+
self.consistency_group_snapshots[0].id
156+
)
157+
self.assertIsNone(result)
158+
159+
def test_multiple_consistency_group_snapshots_delete(self):
160+
arglist = []
161+
for c in self.consistency_group_snapshots:
162+
arglist.append(c.id)
163+
verifylist = [
164+
('consistency_group_snapshot', arglist),
165+
]
166+
167+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
168+
result = self.cmd.take_action(parsed_args)
169+
170+
calls = []
171+
for c in self.consistency_group_snapshots:
172+
calls.append(call(c.id))
173+
self.cgsnapshots_mock.delete.assert_has_calls(calls)
174+
self.assertIsNone(result)
175+
176+
177+
class TestConsistencyGroupSnapshotList(TestConsistencyGroupSnapshot):
178+
consistency_group_snapshots = (
179+
volume_fakes.create_consistency_group_snapshots(count=2)
180+
)
181+
consistency_group = volume_fakes.create_one_consistency_group()
182+
183+
columns = [
184+
'ID',
185+
'Status',
186+
'Name',
187+
]
188+
columns_long = [
189+
'ID',
190+
'Status',
191+
'ConsistencyGroup ID',
192+
'Name',
193+
'Description',
194+
'Created At',
195+
]
196+
data = []
197+
for c in consistency_group_snapshots:
198+
data.append(
199+
(
200+
c.id,
201+
c.status,
202+
c.name,
203+
)
204+
)
205+
data_long = []
206+
for c in consistency_group_snapshots:
207+
data_long.append(
208+
(
209+
c.id,
210+
c.status,
211+
c.consistencygroup_id,
212+
c.name,
213+
c.description,
214+
c.created_at,
215+
)
216+
)
217+
218+
def setUp(self):
219+
super().setUp()
220+
221+
self.cgsnapshots_mock.list.return_value = (
222+
self.consistency_group_snapshots
223+
)
224+
self.consistencygroups_mock.get.return_value = self.consistency_group
225+
# Get the command to test
226+
self.cmd = consistency_group_snapshot.ListConsistencyGroupSnapshot(
227+
self.app, None
228+
)
229+
230+
def test_consistency_group_snapshot_list_without_options(self):
231+
arglist = []
232+
verifylist = [
233+
("all_projects", False),
234+
("long", False),
235+
("status", None),
236+
("consistency_group", None),
237+
]
238+
239+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
240+
columns, data = self.cmd.take_action(parsed_args)
241+
242+
search_opts = {
243+
'all_tenants': False,
244+
'status': None,
245+
'consistencygroup_id': None,
246+
}
247+
self.cgsnapshots_mock.list.assert_called_once_with(
248+
detailed=True, search_opts=search_opts
249+
)
250+
self.assertEqual(self.columns, columns)
251+
self.assertEqual(self.data, list(data))
252+
253+
def test_consistency_group_snapshot_list_with_long(self):
254+
arglist = [
255+
"--long",
256+
]
257+
verifylist = [
258+
("all_projects", False),
259+
("long", True),
260+
("status", None),
261+
("consistency_group", None),
262+
]
263+
264+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
265+
columns, data = self.cmd.take_action(parsed_args)
266+
267+
search_opts = {
268+
'all_tenants': False,
269+
'status': None,
270+
'consistencygroup_id': None,
271+
}
272+
self.cgsnapshots_mock.list.assert_called_once_with(
273+
detailed=True, search_opts=search_opts
274+
)
275+
self.assertEqual(self.columns_long, columns)
276+
self.assertEqual(self.data_long, list(data))
277+
278+
def test_consistency_group_snapshot_list_with_options(self):
279+
arglist = [
280+
"--all-project",
281+
"--status",
282+
self.consistency_group_snapshots[0].status,
283+
"--consistency-group",
284+
self.consistency_group.id,
285+
]
286+
verifylist = [
287+
("all_projects", True),
288+
("long", False),
289+
("status", self.consistency_group_snapshots[0].status),
290+
("consistency_group", self.consistency_group.id),
291+
]
292+
293+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
294+
columns, data = self.cmd.take_action(parsed_args)
295+
296+
search_opts = {
297+
'all_tenants': True,
298+
'status': self.consistency_group_snapshots[0].status,
299+
'consistencygroup_id': self.consistency_group.id,
300+
}
301+
self.consistencygroups_mock.get.assert_called_once_with(
302+
self.consistency_group.id
303+
)
304+
self.cgsnapshots_mock.list.assert_called_once_with(
305+
detailed=True, search_opts=search_opts
306+
)
307+
self.assertEqual(self.columns, columns)
308+
self.assertEqual(self.data, list(data))
309+
310+
311+
class TestConsistencyGroupSnapshotShow(TestConsistencyGroupSnapshot):
312+
_consistency_group_snapshot = (
313+
volume_fakes.create_one_consistency_group_snapshot()
314+
)
315+
316+
columns = (
317+
'consistencygroup_id',
318+
'created_at',
319+
'description',
320+
'id',
321+
'name',
322+
'status',
323+
)
324+
data = (
325+
_consistency_group_snapshot.consistencygroup_id,
326+
_consistency_group_snapshot.created_at,
327+
_consistency_group_snapshot.description,
328+
_consistency_group_snapshot.id,
329+
_consistency_group_snapshot.name,
330+
_consistency_group_snapshot.status,
331+
)
332+
333+
def setUp(self):
334+
super().setUp()
335+
336+
self.cgsnapshots_mock.get.return_value = (
337+
self._consistency_group_snapshot
338+
)
339+
self.cmd = consistency_group_snapshot.ShowConsistencyGroupSnapshot(
340+
self.app, None
341+
)
342+
343+
def test_consistency_group_snapshot_show(self):
344+
arglist = [self._consistency_group_snapshot.id]
345+
verifylist = [
346+
("consistency_group_snapshot", self._consistency_group_snapshot.id)
347+
]
348+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
349+
columns, data = self.cmd.take_action(parsed_args)
350+
self.cgsnapshots_mock.get.assert_called_once_with(
351+
self._consistency_group_snapshot.id
352+
)
353+
self.assertEqual(self.columns, columns)
354+
self.assertEqual(self.data, data)

0 commit comments

Comments
 (0)