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)
|
||||
|
||||
|
||||
class InstanceInErrorState(Exception):
|
||||
"""Instance is in the error state."""
|
||||
pass
|
||||
|
||||
|
||||
class ClientException(Exception):
|
||||
"""
|
||||
The base exception class for all exceptions this library raises.
|
||||
|
@ -369,7 +369,10 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
if 'personality' in body['server']:
|
||||
for pfile in body['server']['personality']:
|
||||
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):
|
||||
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]}
|
||||
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):
|
||||
r = {'server': self.get_servers_detail()[2]['servers'][1]}
|
||||
return (200, {}, r)
|
||||
|
@ -581,6 +581,10 @@ class ShellTest(utils.TestCase):
|
||||
[mock.call(self.shell.cs.servers.get, 1234, 'building',
|
||||
['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):
|
||||
self.run_command('flavor-list')
|
||||
self.assert_called_anytime('GET', '/flavors/detail')
|
||||
|
@ -170,7 +170,10 @@ class FakeHTTPClient(fakes_v1_1.FakeHTTPClient):
|
||||
required=['name', 'image_ref', 'flavor_ref'],
|
||||
optional=['metadata', 'personality',
|
||||
'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
|
||||
|
@ -480,3 +480,7 @@ class ShellTest(utils.TestCase):
|
||||
poll_method.assert_has_calls(
|
||||
[mock.call(self.shell.cs.servers.get, 1234, 'building',
|
||||
['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":
|
||||
if not silent:
|
||||
print(_("\nError %s server") % action)
|
||||
break
|
||||
raise exceptions.InstanceInErrorState(obj.fault['message'])
|
||||
|
||||
if not silent:
|
||||
print_progress(progress)
|
||||
|
@ -339,7 +339,7 @@ def _poll_for_status(poll_fn, obj_id, action, final_ok_states,
|
||||
elif status == "error":
|
||||
if not silent:
|
||||
print("\nError %s server" % action)
|
||||
break
|
||||
raise exceptions.InstanceInErrorState(obj.fault['message'])
|
||||
|
||||
if not silent:
|
||||
print_progress(progress)
|
||||
|
Loading…
Reference in New Issue
Block a user