summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-08-03 17:14:06 +0000
committerGerrit Code Review <review@openstack.org>2014-08-03 17:14:06 +0000
commit88ee3b385c5df7d0d34cb99a16d0c05c65cfb967 (patch)
treec6c6ade0efdf43bac62727cfcb211e7a988d1048
parentd5c5bacb67a53086efcda4b8f5f675056ba8b2d8 (diff)
parentbf8fa0b606ca3c25808f526de0c06d1374dc7411 (diff)
downloadpython-cinderclient-88ee3b385c5df7d0d34cb99a16d0c05c65cfb967.tar.gz
Merge "Fix the return code of the command reset-state"
-rw-r--r--cinderclient/tests/v1/test_shell.py16
-rw-r--r--cinderclient/tests/v2/test_shell.py16
-rw-r--r--cinderclient/v1/shell.py14
-rw-r--r--cinderclient/v2/shell.py14
4 files changed, 42 insertions, 18 deletions
diff --git a/cinderclient/tests/v1/test_shell.py b/cinderclient/tests/v1/test_shell.py
index 8b7a6ea..96c600c 100644
--- a/cinderclient/tests/v1/test_shell.py
+++ b/cinderclient/tests/v1/test_shell.py
@@ -18,6 +18,7 @@
import fixtures
from cinderclient import client
+from cinderclient import exceptions
from cinderclient import shell
from cinderclient.v1 import shell as shell_v1
from cinderclient.tests.v1 import fakes
@@ -280,6 +281,21 @@ class ShellTest(utils.TestCase):
body=expected)
@httpretty.activate
+ def test_reset_state_two_with_one_nonexistent(self):
+ self.register_keystone_auth_fixture()
+ cmd = 'reset-state 1234 123456789'
+ self.assertRaises(exceptions.CommandError, self.run_command, cmd)
+ expected = {'os-reset_status': {'status': 'available'}}
+ self.assert_called_anytime('POST', '/volumes/1234/action',
+ body=expected)
+
+ @httpretty.activate
+ def test_reset_state_one_with_one_nonexistent(self):
+ self.register_keystone_auth_fixture()
+ cmd = 'reset-state 123456789'
+ self.assertRaises(exceptions.CommandError, self.run_command, cmd)
+
+ @httpretty.activate
def test_snapshot_reset_state(self):
self.register_keystone_auth_fixture()
diff --git a/cinderclient/tests/v2/test_shell.py b/cinderclient/tests/v2/test_shell.py
index f1c473c..fa0c1d2 100644
--- a/cinderclient/tests/v2/test_shell.py
+++ b/cinderclient/tests/v2/test_shell.py
@@ -17,6 +17,7 @@ import fixtures
import httpretty
from cinderclient import client
+from cinderclient import exceptions
from cinderclient import shell
from cinderclient.tests import utils
from cinderclient.tests.v2 import fakes
@@ -300,6 +301,21 @@ class ShellTest(utils.TestCase):
body=expected)
@httpretty.activate
+ def test_reset_state_two_with_one_nonexistent(self):
+ self.register_keystone_auth_fixture()
+ cmd = 'reset-state 1234 123456789'
+ self.assertRaises(exceptions.CommandError, self.run_command, cmd)
+ expected = {'os-reset_status': {'status': 'available'}}
+ self.assert_called_anytime('POST', '/volumes/1234/action',
+ body=expected)
+
+ @httpretty.activate
+ def test_reset_state_one_with_one_nonexistent(self):
+ self.register_keystone_auth_fixture()
+ cmd = 'reset-state 123456789'
+ self.assertRaises(exceptions.CommandError, self.run_command, cmd)
+
+ @httpretty.activate
def test_snapshot_reset_state(self):
self.register_keystone_auth_fixture()
self.run_command('snapshot-reset-state 1234')
diff --git a/cinderclient/v1/shell.py b/cinderclient/v1/shell.py
index fd7c55d..7ed30ac 100644
--- a/cinderclient/v1/shell.py
+++ b/cinderclient/v1/shell.py
@@ -338,22 +338,18 @@ def do_force_delete(cs, args):
@utils.service_type('volume')
def do_reset_state(cs, args):
"""Explicitly updates the volume state."""
- failure_count = 0
-
- single = (len(args.volume) == 1)
+ failure_flag = False
for volume in args.volume:
try:
utils.find_volume(cs, volume).reset_state(args.state)
except Exception as e:
- failure_count += 1
+ failure_flag = True
msg = "Reset state for volume %s failed: %s" % (volume, e)
- if not single:
- print(msg)
+ print(msg)
- if failure_count == len(args.volume):
- if not single:
- msg = "Unable to reset the state for any of the specified volumes."
+ if failure_flag:
+ msg = "Unable to reset the state for the specified volume(s)."
raise exceptions.CommandError(msg)
diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py
index a2735d8..ec6ee68 100644
--- a/cinderclient/v2/shell.py
+++ b/cinderclient/v2/shell.py
@@ -368,22 +368,18 @@ def do_force_delete(cs, args):
@utils.service_type('volumev2')
def do_reset_state(cs, args):
"""Explicitly updates the volume state."""
- failure_count = 0
-
- single = (len(args.volume) == 1)
+ failure_flag = False
for volume in args.volume:
try:
utils.find_volume(cs, volume).reset_state(args.state)
except Exception as e:
- failure_count += 1
+ failure_flag = True
msg = "Reset state for volume %s failed: %s" % (volume, e)
- if not single:
- print(msg)
+ print(msg)
- if failure_count == len(args.volume):
- if not single:
- msg = "Unable to reset the state for any of specified volumes."
+ if failure_flag:
+ msg = "Unable to reset the state for the specified volume(s)."
raise exceptions.CommandError(msg)