Merge "Raise exception when poll returns error state"
This commit is contained in:
commit
2005e17bed
@ -77,6 +77,11 @@ class ConnectionRefused(Exception):
|
|||||||
return "ConnectionRefused: %s" % repr(self.response)
|
return "ConnectionRefused: %s" % repr(self.response)
|
||||||
|
|
||||||
|
|
||||||
|
class InstanceInErrorState(Exception):
|
||||||
|
"""Instance is in the error state."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ClientException(Exception):
|
class ClientException(Exception):
|
||||||
"""
|
"""
|
||||||
The base exception class for all exceptions this library raises.
|
The base exception class for all exceptions this library raises.
|
||||||
|
@ -369,7 +369,10 @@ class FakeHTTPClient(base_client.HTTPClient):
|
|||||||
if 'personality' in body['server']:
|
if 'personality' in body['server']:
|
||||||
for pfile in body['server']['personality']:
|
for pfile in body['server']['personality']:
|
||||||
fakes.assert_has_keys(pfile, required=['path', 'contents'])
|
fakes.assert_has_keys(pfile, required=['path', 'contents'])
|
||||||
return (202, {}, self.get_servers_1234()[2])
|
if body['server']['name'] == 'some-bad-server':
|
||||||
|
return (202, {}, self.get_servers_1235()[2])
|
||||||
|
else:
|
||||||
|
return (202, {}, self.get_servers_1234()[2])
|
||||||
|
|
||||||
def post_os_volumes_boot(self, body, **kw):
|
def post_os_volumes_boot(self, body, **kw):
|
||||||
assert set(body.keys()) <= set(['server', 'os:scheduler_hints'])
|
assert set(body.keys()) <= set(['server', 'os:scheduler_hints'])
|
||||||
@ -392,6 +395,13 @@ class FakeHTTPClient(base_client.HTTPClient):
|
|||||||
r = {'server': self.get_servers_detail()[2]['servers'][0]}
|
r = {'server': self.get_servers_detail()[2]['servers'][0]}
|
||||||
return (200, {}, r)
|
return (200, {}, r)
|
||||||
|
|
||||||
|
def get_servers_1235(self, **kw):
|
||||||
|
r = {'server': self.get_servers_detail()[2]['servers'][0]}
|
||||||
|
r['server']['id'] = 1235
|
||||||
|
r['server']['status'] = 'error'
|
||||||
|
r['server']['fault'] = {'message': 'something went wrong!'}
|
||||||
|
return (200, {}, r)
|
||||||
|
|
||||||
def get_servers_5678(self, **kw):
|
def get_servers_5678(self, **kw):
|
||||||
r = {'server': self.get_servers_detail()[2]['servers'][1]}
|
r = {'server': self.get_servers_detail()[2]['servers'][1]}
|
||||||
return (200, {}, r)
|
return (200, {}, r)
|
||||||
|
@ -581,6 +581,10 @@ class ShellTest(utils.TestCase):
|
|||||||
[mock.call(self.shell.cs.servers.get, 1234, 'building',
|
[mock.call(self.shell.cs.servers.get, 1234, 'building',
|
||||||
['active'])])
|
['active'])])
|
||||||
|
|
||||||
|
def test_boot_with_poll_to_check_VM_state_error(self):
|
||||||
|
self.assertRaises(exceptions.InstanceInErrorState, self.run_command,
|
||||||
|
'boot --flavor 1 --image 1 some-bad-server --poll')
|
||||||
|
|
||||||
def test_flavor_list(self):
|
def test_flavor_list(self):
|
||||||
self.run_command('flavor-list')
|
self.run_command('flavor-list')
|
||||||
self.assert_called_anytime('GET', '/flavors/detail')
|
self.assert_called_anytime('GET', '/flavors/detail')
|
||||||
|
@ -170,7 +170,10 @@ class FakeHTTPClient(fakes_v1_1.FakeHTTPClient):
|
|||||||
required=['name', 'image_ref', 'flavor_ref'],
|
required=['name', 'image_ref', 'flavor_ref'],
|
||||||
optional=['metadata', 'personality',
|
optional=['metadata', 'personality',
|
||||||
'os-scheduler-hints:scheduler_hints'])
|
'os-scheduler-hints:scheduler_hints'])
|
||||||
return (202, {}, self.get_servers_1234()[2])
|
if body['server']['name'] == 'some-bad-server':
|
||||||
|
return (202, {}, self.get_servers_1235()[2])
|
||||||
|
else:
|
||||||
|
return (202, {}, self.get_servers_1234()[2])
|
||||||
|
|
||||||
#
|
#
|
||||||
# Server Actions
|
# Server Actions
|
||||||
|
@ -480,3 +480,7 @@ class ShellTest(utils.TestCase):
|
|||||||
poll_method.assert_has_calls(
|
poll_method.assert_has_calls(
|
||||||
[mock.call(self.shell.cs.servers.get, 1234, 'building',
|
[mock.call(self.shell.cs.servers.get, 1234, 'building',
|
||||||
['active'])])
|
['active'])])
|
||||||
|
|
||||||
|
def test_boot_with_poll_to_check_VM_state_error(self):
|
||||||
|
self.assertRaises(exceptions.InstanceInErrorState, self.run_command,
|
||||||
|
'boot --flavor 1 --image 1 some-bad-server --poll')
|
||||||
|
@ -484,7 +484,7 @@ def _poll_for_status(poll_fn, obj_id, action, final_ok_states,
|
|||||||
elif status == "error":
|
elif status == "error":
|
||||||
if not silent:
|
if not silent:
|
||||||
print(_("\nError %s server") % action)
|
print(_("\nError %s server") % action)
|
||||||
break
|
raise exceptions.InstanceInErrorState(obj.fault['message'])
|
||||||
|
|
||||||
if not silent:
|
if not silent:
|
||||||
print_progress(progress)
|
print_progress(progress)
|
||||||
|
@ -339,7 +339,7 @@ def _poll_for_status(poll_fn, obj_id, action, final_ok_states,
|
|||||||
elif status == "error":
|
elif status == "error":
|
||||||
if not silent:
|
if not silent:
|
||||||
print("\nError %s server" % action)
|
print("\nError %s server" % action)
|
||||||
break
|
raise exceptions.InstanceInErrorState(obj.fault['message'])
|
||||||
|
|
||||||
if not silent:
|
if not silent:
|
||||||
print_progress(progress)
|
print_progress(progress)
|
||||||
|
Loading…
Reference in New Issue
Block a user