Skip to content

Commit 7a0845e

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add support of setting snapshot state"
2 parents 78c20f6 + 189e477 commit 7a0845e

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
@@ -229,7 +229,6 @@ def test_snapshot_list_all_projects(self):
229229

230230

231231
class TestSnapshotSet(TestSnapshot):
232-
233232
def setUp(self):
234233
super(TestSnapshotSet, self).setUp()
235234

@@ -270,6 +269,23 @@ def test_snapshot_set(self):
270269
)
271270
self.assertIsNone(result)
272271

272+
def test_snapshot_set_state_to_error(self):
273+
arglist = [
274+
"--state", "error",
275+
volume_fakes.snapshot_id
276+
]
277+
verifylist = [
278+
("state", "error"),
279+
("snapshot", volume_fakes.snapshot_id)
280+
]
281+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
282+
283+
result = self.cmd.take_action(parsed_args)
284+
285+
self.snapshots_mock.reset_state.assert_called_with(
286+
volume_fakes.snapshot_id, "error")
287+
self.assertIsNone(result)
288+
273289

274290
class TestSnapshotShow(TestSnapshot):
275291

@@ -300,7 +316,6 @@ def test_snapshot_show(self):
300316

301317

302318
class TestSnapshotUnset(TestSnapshot):
303-
304319
def setUp(self):
305320
super(TestSnapshotUnset, self).setUp()
306321

@@ -322,6 +337,7 @@ def test_snapshot_unset(self):
322337
("snapshot", volume_fakes.snapshot_id),
323338
("property", ["foo"])
324339
]
340+
325341
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
326342

327343
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
@@ -179,6 +179,14 @@ def get_parser(self, prog_name):
179179
help='Property to add/change for this snapshot '
180180
'(repeat option to set multiple properties)',
181181
)
182+
parser.add_argument(
183+
'--state',
184+
metavar='<state>',
185+
choices=['available', 'error', 'creating', 'deleting',
186+
'error-deleting'],
187+
help='New snapshot state. Valid values are available, '
188+
'error, creating, deleting, and error-deleting.',
189+
)
182190
return parser
183191

184192
def take_action(self, parsed_args):
@@ -192,13 +200,17 @@ def take_action(self, parsed_args):
192200
if parsed_args.description:
193201
kwargs['description'] = parsed_args.description
194202

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

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

204216

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)