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
This commit is contained in:
parent
752705ae30
commit
189e4774f8
doc/source/command-objects
openstackclient
releasenotes/notes
@ -2,7 +2,7 @@
|
|||||||
snapshot
|
snapshot
|
||||||
========
|
========
|
||||||
|
|
||||||
Block Storage v1
|
Block Storage v1, v2
|
||||||
|
|
||||||
snapshot create
|
snapshot create
|
||||||
---------------
|
---------------
|
||||||
@ -82,6 +82,7 @@ Set snapshot properties
|
|||||||
[--name <name>]
|
[--name <name>]
|
||||||
[--description <description>]
|
[--description <description>]
|
||||||
[--property <key=value> [...] ]
|
[--property <key=value> [...] ]
|
||||||
|
[--state <state>]
|
||||||
<snapshot>
|
<snapshot>
|
||||||
|
|
||||||
.. _snapshot_restore-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)
|
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>
|
.. describe:: <snapshot>
|
||||||
|
|
||||||
Snapshot to modify (name or ID)
|
Snapshot to modify (name or ID)
|
||||||
|
@ -205,7 +205,6 @@ class TestSnapshotList(TestSnapshot):
|
|||||||
|
|
||||||
|
|
||||||
class TestSnapshotSet(TestSnapshot):
|
class TestSnapshotSet(TestSnapshot):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestSnapshotSet, self).setUp()
|
super(TestSnapshotSet, self).setUp()
|
||||||
|
|
||||||
@ -246,6 +245,23 @@ class TestSnapshotSet(TestSnapshot):
|
|||||||
)
|
)
|
||||||
self.assertIsNone(result)
|
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):
|
class TestSnapshotShow(TestSnapshot):
|
||||||
|
|
||||||
@ -276,7 +292,6 @@ class TestSnapshotShow(TestSnapshot):
|
|||||||
|
|
||||||
|
|
||||||
class TestSnapshotUnset(TestSnapshot):
|
class TestSnapshotUnset(TestSnapshot):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestSnapshotUnset, self).setUp()
|
super(TestSnapshotUnset, self).setUp()
|
||||||
|
|
||||||
@ -298,6 +313,7 @@ class TestSnapshotUnset(TestSnapshot):
|
|||||||
("snapshot", volume_fakes.snapshot_id),
|
("snapshot", volume_fakes.snapshot_id),
|
||||||
("property", ["foo"])
|
("property", ["foo"])
|
||||||
]
|
]
|
||||||
|
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
result = self.cmd.take_action(parsed_args)
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
@ -180,6 +180,14 @@ class SetSnapshot(command.Command):
|
|||||||
help='Property to add/change for this snapshot '
|
help='Property to add/change for this snapshot '
|
||||||
'(repeat option to set multiple properties)',
|
'(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
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
@ -193,13 +201,17 @@ class SetSnapshot(command.Command):
|
|||||||
if parsed_args.description:
|
if parsed_args.description:
|
||||||
kwargs['description'] = 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")
|
self.app.log.error("No changes requested\n")
|
||||||
return
|
return
|
||||||
|
|
||||||
if parsed_args.property:
|
if parsed_args.property:
|
||||||
volume_client.volume_snapshots.set_metadata(snapshot.id,
|
volume_client.volume_snapshots.set_metadata(snapshot.id,
|
||||||
parsed_args.property)
|
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)
|
volume_client.volume_snapshots.update(snapshot.id, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
6
releasenotes/notes/bug-1535239-767e6cf1990eda01.yaml
Normal file
6
releasenotes/notes/bug-1535239-767e6cf1990eda01.yaml
Normal file
@ -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>`_]
|
Loading…
x
Reference in New Issue
Block a user