summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-05-18 16:49:06 +0000
committerGerrit Code Review <review@openstack.org>2016-05-18 16:49:07 +0000
commit7a0845ec1127b89073845f07425b17651b005c38 (patch)
tree8e8bf31672c6572c34359004b91280d5149dfdfc
parent78c20f6f38f26d18ad769c0660451237a856c60e (diff)
parent189e4774f88243669ee1b9089d6c39021094c83d (diff)
downloadpython-openstackclient-7a0845ec1127b89073845f07425b17651b005c38.tar.gz
Merge "Add support of setting snapshot state"
-rw-r--r--doc/source/command-objects/snapshot.rst11
-rw-r--r--openstackclient/tests/volume/v2/test_snapshot.py20
-rw-r--r--openstackclient/volume/v2/snapshot.py14
-rw-r--r--releasenotes/notes/bug-1535239-767e6cf1990eda01.yaml6
4 files changed, 47 insertions, 4 deletions
diff --git a/doc/source/command-objects/snapshot.rst b/doc/source/command-objects/snapshot.rst
index b4838684..90330118 100644
--- a/doc/source/command-objects/snapshot.rst
+++ b/doc/source/command-objects/snapshot.rst
@@ -2,7 +2,7 @@
snapshot
========
-Block Storage v1
+Block Storage v1, v2
snapshot create
---------------
@@ -82,6 +82,7 @@ Set snapshot properties
[--name <name>]
[--description <description>]
[--property <key=value> [...] ]
+ [--state <state>]
<snapshot>
.. _snapshot_restore-snapshot:
@@ -97,6 +98,14 @@ Set snapshot properties
Property to add or modify for this snapshot (repeat option to set multiple properties)
+.. option:: --state <state>
+
+ New snapshot state.
+ Valid values are "available", "error", "creating",
+ "deleting", and "error_deleting".
+
+ *Volume version 2 only*
+
.. describe:: <snapshot>
Snapshot to modify (name or ID)
diff --git a/openstackclient/tests/volume/v2/test_snapshot.py b/openstackclient/tests/volume/v2/test_snapshot.py
index 8c75dfb2..d2fa5e07 100644
--- a/openstackclient/tests/volume/v2/test_snapshot.py
+++ b/openstackclient/tests/volume/v2/test_snapshot.py
@@ -229,7 +229,6 @@ class TestSnapshotList(TestSnapshot):
class TestSnapshotSet(TestSnapshot):
-
def setUp(self):
super(TestSnapshotSet, self).setUp()
@@ -270,6 +269,23 @@ class TestSnapshotSet(TestSnapshot):
)
self.assertIsNone(result)
+ def test_snapshot_set_state_to_error(self):
+ arglist = [
+ "--state", "error",
+ volume_fakes.snapshot_id
+ ]
+ verifylist = [
+ ("state", "error"),
+ ("snapshot", volume_fakes.snapshot_id)
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ self.snapshots_mock.reset_state.assert_called_with(
+ volume_fakes.snapshot_id, "error")
+ self.assertIsNone(result)
+
class TestSnapshotShow(TestSnapshot):
@@ -300,7 +316,6 @@ class TestSnapshotShow(TestSnapshot):
class TestSnapshotUnset(TestSnapshot):
-
def setUp(self):
super(TestSnapshotUnset, self).setUp()
@@ -322,6 +337,7 @@ class TestSnapshotUnset(TestSnapshot):
("snapshot", volume_fakes.snapshot_id),
("property", ["foo"])
]
+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
diff --git a/openstackclient/volume/v2/snapshot.py b/openstackclient/volume/v2/snapshot.py
index f124a5e2..65cb9a75 100644
--- a/openstackclient/volume/v2/snapshot.py
+++ b/openstackclient/volume/v2/snapshot.py
@@ -179,6 +179,14 @@ class SetSnapshot(command.Command):
help='Property to add/change for this snapshot '
'(repeat option to set multiple properties)',
)
+ parser.add_argument(
+ '--state',
+ metavar='<state>',
+ choices=['available', 'error', 'creating', 'deleting',
+ 'error-deleting'],
+ help='New snapshot state. Valid values are available, '
+ 'error, creating, deleting, and error-deleting.',
+ )
return parser
def take_action(self, parsed_args):
@@ -192,13 +200,17 @@ class SetSnapshot(command.Command):
if parsed_args.description:
kwargs['description'] = parsed_args.description
- if not kwargs and not parsed_args.property:
+ if (not kwargs and not parsed_args.property and not
+ parsed_args.state):
self.app.log.error("No changes requested\n")
return
if parsed_args.property:
volume_client.volume_snapshots.set_metadata(snapshot.id,
parsed_args.property)
+ if parsed_args.state:
+ volume_client.volume_snapshots.reset_state(snapshot.id,
+ parsed_args.state)
volume_client.volume_snapshots.update(snapshot.id, **kwargs)
diff --git a/releasenotes/notes/bug-1535239-767e6cf1990eda01.yaml b/releasenotes/notes/bug-1535239-767e6cf1990eda01.yaml
new file mode 100644
index 00000000..36f8e687
--- /dev/null
+++ b/releasenotes/notes/bug-1535239-767e6cf1990eda01.yaml
@@ -0,0 +1,6 @@
+---
+fixes:
+ - |
+ Support a new ``--state`` option for ``snapshot set`` command that
+ changes the state of a snapshot.
+ [Bug `1535239 <https://bugs.launchpad.net/bugs/1535239>`_]