Merge "Fix the return code of the command reset-state"

This commit is contained in:
Jenkins
2014-08-03 17:14:06 +00:00
committed by Gerrit Code Review
4 changed files with 42 additions and 18 deletions

View File

@@ -18,6 +18,7 @@
import fixtures import fixtures
from cinderclient import client from cinderclient import client
from cinderclient import exceptions
from cinderclient import shell from cinderclient import shell
from cinderclient.v1 import shell as shell_v1 from cinderclient.v1 import shell as shell_v1
from cinderclient.tests.v1 import fakes from cinderclient.tests.v1 import fakes
@@ -279,6 +280,21 @@ class ShellTest(utils.TestCase):
self.assert_called_anytime('POST', '/volumes/5678/action', self.assert_called_anytime('POST', '/volumes/5678/action',
body=expected) 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 @httpretty.activate
def test_snapshot_reset_state(self): def test_snapshot_reset_state(self):

View File

@@ -17,6 +17,7 @@ import fixtures
import httpretty import httpretty
from cinderclient import client from cinderclient import client
from cinderclient import exceptions
from cinderclient import shell from cinderclient import shell
from cinderclient.tests import utils from cinderclient.tests import utils
from cinderclient.tests.v2 import fakes from cinderclient.tests.v2 import fakes
@@ -299,6 +300,21 @@ class ShellTest(utils.TestCase):
self.assert_called_anytime('POST', '/volumes/5678/action', self.assert_called_anytime('POST', '/volumes/5678/action',
body=expected) 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 @httpretty.activate
def test_snapshot_reset_state(self): def test_snapshot_reset_state(self):
self.register_keystone_auth_fixture() self.register_keystone_auth_fixture()

View File

@@ -338,22 +338,18 @@ def do_force_delete(cs, args):
@utils.service_type('volume') @utils.service_type('volume')
def do_reset_state(cs, args): def do_reset_state(cs, args):
"""Explicitly updates the volume state.""" """Explicitly updates the volume state."""
failure_count = 0 failure_flag = False
single = (len(args.volume) == 1)
for volume in args.volume: for volume in args.volume:
try: try:
utils.find_volume(cs, volume).reset_state(args.state) utils.find_volume(cs, volume).reset_state(args.state)
except Exception as e: except Exception as e:
failure_count += 1 failure_flag = True
msg = "Reset state for volume %s failed: %s" % (volume, e) msg = "Reset state for volume %s failed: %s" % (volume, e)
if not single: print(msg)
print(msg)
if failure_count == len(args.volume): if failure_flag:
if not single: msg = "Unable to reset the state for the specified volume(s)."
msg = "Unable to reset the state for any of the specified volumes."
raise exceptions.CommandError(msg) raise exceptions.CommandError(msg)

View File

@@ -368,22 +368,18 @@ def do_force_delete(cs, args):
@utils.service_type('volumev2') @utils.service_type('volumev2')
def do_reset_state(cs, args): def do_reset_state(cs, args):
"""Explicitly updates the volume state.""" """Explicitly updates the volume state."""
failure_count = 0 failure_flag = False
single = (len(args.volume) == 1)
for volume in args.volume: for volume in args.volume:
try: try:
utils.find_volume(cs, volume).reset_state(args.state) utils.find_volume(cs, volume).reset_state(args.state)
except Exception as e: except Exception as e:
failure_count += 1 failure_flag = True
msg = "Reset state for volume %s failed: %s" % (volume, e) msg = "Reset state for volume %s failed: %s" % (volume, e)
if not single: print(msg)
print(msg)
if failure_count == len(args.volume): if failure_flag:
if not single: msg = "Unable to reset the state for the specified volume(s)."
msg = "Unable to reset the state for any of specified volumes."
raise exceptions.CommandError(msg) raise exceptions.CommandError(msg)