From 7571232c024cb66d5c68546e313b1a9a7ba2b2fc Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Thu, 13 Jun 2013 15:55:16 -0700 Subject: [PATCH] Implement reset-state (os-reset_status) action This change implements a reset-state method in the cinderclient which exposes the extension: os-reset_status from the Cinder API. Fix bug 1190731 Change-Id: I8f631f0f19ca16e0fdd1e3adcf923cc684292887 --- cinderclient/tests/v1/fakes.py | 4 +++- cinderclient/tests/v1/test_shell.py | 10 ++++++++++ cinderclient/tests/v2/fakes.py | 4 +++- cinderclient/tests/v2/test_shell.py | 10 ++++++++++ cinderclient/v1/shell.py | 12 ++++++++++++ cinderclient/v1/volumes.py | 8 ++++++++ cinderclient/v2/shell.py | 12 ++++++++++++ cinderclient/v2/volumes.py | 8 ++++++++ 8 files changed, 66 insertions(+), 2 deletions(-) diff --git a/cinderclient/tests/v1/fakes.py b/cinderclient/tests/v1/fakes.py index a71f50247..9910b1dab 100644 --- a/cinderclient/tests/v1/fakes.py +++ b/cinderclient/tests/v1/fakes.py @@ -234,8 +234,10 @@ class FakeHTTPClient(base_client.HTTPClient): assert body[action] is None elif action == 'os-roll_detaching': assert body[action] is None + elif action == 'os-reset_status': + assert 'status' in body[action] else: - raise AssertionError("Unexpected server action: %s" % action) + raise AssertionError("Unexpected action: %s" % action) return (resp, {}, _body) def post_volumes(self, **kw): diff --git a/cinderclient/tests/v1/test_shell.py b/cinderclient/tests/v1/test_shell.py index b3c7abfd0..f94b8ad8f 100644 --- a/cinderclient/tests/v1/test_shell.py +++ b/cinderclient/tests/v1/test_shell.py @@ -179,3 +179,13 @@ class ShellTest(utils.TestCase): self.run_command('metadata 1234 unset key1 key2') self.assert_called('DELETE', '/volumes/1234/metadata/key1') self.assert_called('DELETE', '/volumes/1234/metadata/key2', pos=-2) + + def test_reset_state(self): + self.run_command('reset-state 1234') + expected = {'os-reset_status': {'status': 'available'}} + self.assert_called('POST', '/volumes/1234/action', body=expected) + + def test_reset_state_with_flag(self): + self.run_command('reset-state --state error 1234') + expected = {'os-reset_status': {'status': 'error'}} + self.assert_called('POST', '/volumes/1234/action', body=expected) diff --git a/cinderclient/tests/v2/fakes.py b/cinderclient/tests/v2/fakes.py index 28cb20a8a..7482283c1 100644 --- a/cinderclient/tests/v2/fakes.py +++ b/cinderclient/tests/v2/fakes.py @@ -241,8 +241,10 @@ class FakeHTTPClient(base_client.HTTPClient): assert body[action] is None elif action == 'os-roll_detaching': assert body[action] is None + elif action == 'os-reset_status': + assert 'status' in body[action] else: - raise AssertionError("Unexpected server action: %s" % action) + raise AssertionError("Unexpected action: %s" % action) return (resp, {}, _body) def post_volumes(self, **kw): diff --git a/cinderclient/tests/v2/test_shell.py b/cinderclient/tests/v2/test_shell.py index 8f6e0742c..ce7842cf6 100644 --- a/cinderclient/tests/v2/test_shell.py +++ b/cinderclient/tests/v2/test_shell.py @@ -157,3 +157,13 @@ class ShellTest(utils.TestCase): self.run_command('metadata 1234 unset key1 key2') self.assert_called('DELETE', '/volumes/1234/metadata/key1') self.assert_called('DELETE', '/volumes/1234/metadata/key2', pos=-2) + + def test_reset_state(self): + self.run_command('reset-state 1234') + expected = {'os-reset_status': {'status': 'available'}} + self.assert_called('POST', '/volumes/1234/action', body=expected) + + def test_reset_state_with_flag(self): + self.run_command('reset-state --state error 1234') + expected = {'os-reset_status': {'status': 'error'}} + self.assert_called('POST', '/volumes/1234/action', body=expected) diff --git a/cinderclient/v1/shell.py b/cinderclient/v1/shell.py index 5c56f4a95..15a5fc1be 100644 --- a/cinderclient/v1/shell.py +++ b/cinderclient/v1/shell.py @@ -268,6 +268,18 @@ def do_force_delete(cs, args): volume.force_delete() +@utils.arg('volume', metavar='', help='ID of the volume to modify.') +@utils.arg('--state', metavar='', default='available', + help=('Indicate which state to assign the volume. Options include ' + 'available, error, creating, deleting, error_deleting. If no ' + 'state is provided, available will be used.')) +@utils.service_type('volume') +def do_reset_state(cs, args): + """Explicitly update the state of a volume.""" + volume = _find_volume(cs, args.volume) + volume.reset_state(args.state) + + @utils.arg('volume', metavar='', help='ID of the volume to rename.') @utils.arg('display_name', nargs='?', metavar='', help='New display-name for the volume.') diff --git a/cinderclient/v1/volumes.py b/cinderclient/v1/volumes.py index 9903f10fa..9ae5f478e 100644 --- a/cinderclient/v1/volumes.py +++ b/cinderclient/v1/volumes.py @@ -98,6 +98,10 @@ class Volume(base.Resource): """ self.manager.force_delete(self) + def reset_state(self, state): + """Update the volume with the provided state.""" + self.manager.reset_state(self, state) + class VolumeManager(base.ManagerWithFind): """ @@ -327,3 +331,7 @@ class VolumeManager(base.ManagerWithFind): def force_delete(self, volume): return self._action('os-force_delete', base.getid(volume)) + + def reset_state(self, volume, state): + """Update the provided volume with the provided state.""" + return self._action('os-reset_status', volume, {'status': state}) diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index 401681071..986b92511 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -278,6 +278,18 @@ def do_force_delete(cs, args): volume.force_delete() +@utils.arg('volume', metavar='', help='ID of the volume to modify.') +@utils.arg('--state', metavar='', default='available', + help=('Indicate which state to assign the volume. Options include ' + 'available, error, creating, deleting, error_deleting. If no ' + 'state is provided, available will be used.')) +@utils.service_type('volume') +def do_reset_state(cs, args): + """Explicitly update the state of a volume.""" + volume = _find_volume(cs, args.volume) + volume.reset_state(args.state) + + @utils.arg('volume', metavar='', help='ID of the volume to rename.') diff --git a/cinderclient/v2/volumes.py b/cinderclient/v2/volumes.py index a9b69ab1c..162183009 100644 --- a/cinderclient/v2/volumes.py +++ b/cinderclient/v2/volumes.py @@ -97,6 +97,10 @@ class Volume(base.Resource): """ self.manager.force_delete(self) + def reset_state(self, state): + """Update the volume with the provided state.""" + self.manager.reset_state(self, state) + class VolumeManager(base.ManagerWithFind): """Manage :class:`Volume` resources.""" @@ -307,3 +311,7 @@ class VolumeManager(base.ManagerWithFind): def force_delete(self, volume): return self._action('os-force_delete', base.getid(volume)) + + def reset_state(self, volume, state): + """Update the provided volume with the provided state.""" + return self._action('os-reset_status', volume, {'status': state})