Skip to content

Commit 189e477

Browse files
author
Xi Yang
committed
Add support of setting snapshot state
This patch is going to add the functionality of setting snapshot state which OSC currently lacks. Closes-Bug:#1535239 Change-Id: I2afd6567416e75ba0c70b73351cf1eb5394b3373
1 parent 752705a commit 189e477

4 files changed

Lines changed: 47 additions & 4 deletions

File tree

doc/source/command-objects/snapshot.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
snapshot
33
========
44

5-
Block Storage v1
5+
Block Storage v1, v2
66

77
snapshot create
88
---------------
@@ -82,6 +82,7 @@ Set snapshot properties
8282
[--name <name>]
8383
[--description <description>]
8484
[--property <key=value> [...] ]
85+
[--state <state>]
8586
<snapshot>
8687
8788
.. _snapshot_restore-snapshot:
@@ -97,6 +98,14 @@ Set snapshot properties
9798

9899
Property to add or modify for this snapshot (repeat option to set multiple properties)
99100

101+
.. option:: --state <state>
102+
103+
New snapshot state.
104+
Valid values are "available", "error", "creating",
105+
"deleting", and "error_deleting".
106+
107+
*Volume version 2 only*
108+
100109
.. describe:: <snapshot>
101110

102111
Snapshot to modify (name or ID)

openstackclient/tests/volume/v2/test_snapshot.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ def test_snapshot_list_all_projects(self):
205205

206206

207207
class TestSnapshotSet(TestSnapshot):
208-
209208
def setUp(self):
210209
super(TestSnapshotSet, self).setUp()
211210

@@ -246,6 +245,23 @@ def test_snapshot_set(self):
246245
)
247246
self.assertIsNone(result)
248247

248+
def test_snapshot_set_state_to_error(self):
249+
arglist = [
250+
"--state", "error",
251+
volume_fakes.snapshot_id
252+
]
253+
verifylist = [
254+
("state", "error"),
255+
("snapshot", volume_fakes.snapshot_id)
256+
]
257+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
258+
259+
result = self.cmd.take_action(parsed_args)
260+
261+
self.snapshots_mock.reset_state.assert_called_with(
262+
volume_fakes.snapshot_id, "error")
263+
self.assertIsNone(result)
264+
249265

250266
class TestSnapshotShow(TestSnapshot):
251267

@@ -276,7 +292,6 @@ def test_snapshot_show(self):
276292

277293

278294
class TestSnapshotUnset(TestSnapshot):
279-
280295
def setUp(self):
281296
super(TestSnapshotUnset, self).setUp()
282297

@@ -298,6 +313,7 @@ def test_snapshot_unset(self):
298313
("snapshot", volume_fakes.snapshot_id),
299314
("property", ["foo"])
300315
]
316+
301317
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
302318

303319
result = self.cmd.take_action(parsed_args)

openstackclient/volume/v2/snapshot.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ def get_parser(self, prog_name):
180180
help='Property to add/change for this snapshot '
181181
'(repeat option to set multiple properties)',
182182
)
183+
parser.add_argument(
184+
'--state',
185+
metavar='<state>',
186+
choices=['available', 'error', 'creating', 'deleting',
187+
'error-deleting'],
188+
help='New snapshot state. Valid values are available, '
189+
'error, creating, deleting, and error-deleting.',
190+
)
183191
return parser
184192

185193
def take_action(self, parsed_args):
@@ -193,13 +201,17 @@ def take_action(self, parsed_args):
193201
if parsed_args.description:
194202
kwargs['description'] = parsed_args.description
195203

196-
if not kwargs and not parsed_args.property:
204+
if (not kwargs and not parsed_args.property and not
205+
parsed_args.state):
197206
self.app.log.error("No changes requested\n")
198207
return
199208

200209
if parsed_args.property:
201210
volume_client.volume_snapshots.set_metadata(snapshot.id,
202211
parsed_args.property)
212+
if parsed_args.state:
213+
volume_client.volume_snapshots.reset_state(snapshot.id,
214+
parsed_args.state)
203215
volume_client.volume_snapshots.update(snapshot.id, **kwargs)
204216

205217

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
Support a new ``--state`` option for ``snapshot set`` command that
5+
changes the state of a snapshot.
6+
[Bug `1535239 <https://bugs.launchpad.net/bugs/1535239>`_]

0 commit comments

Comments
 (0)