Skip to content

Commit

Permalink
Set error state on spawn error + integration test.
Browse files Browse the repository at this point in the history
This branch should at least be considered a partial fix for bug 698336.

(Update) Grammar fix.
(Update) PEP8 fix.
(Update) Merged with origin/master
(Update) Fixed test (oops!) thanks comstud!

Change-Id: I10d607fd40953e334670cc39040a9a00ff6919ac
  • Loading branch information
Brian Lamar committed Oct 4, 2011
1 parent 3837f09 commit 981f527
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
6 changes: 3 additions & 3 deletions nova/compute/api.py
Expand Up @@ -81,17 +81,17 @@ def generate_default_display_name(instance):

def _is_able_to_shutdown(instance, instance_id):
vm_state = instance["vm_state"]
task_state = instance["task_state"]

valid_shutdown_states = [
vm_states.ACTIVE,
vm_states.REBUILDING,
vm_states.BUILDING,
vm_states.ERROR,
]

if vm_state not in valid_shutdown_states:
LOG.warn(_("Instance %(instance_id)s is not in an 'active' state. It "
"is currently %(vm_state)s. Shutdown aborted.") % locals())
LOG.warn(_("Instance %(instance_id)s cannot be shutdown from "
"its current state: %(vm_state)s.") % locals())
return False

return True
Expand Down
11 changes: 6 additions & 5 deletions nova/compute/manager.py
Expand Up @@ -436,11 +436,12 @@ def _deallocate_network():
try:
self.driver.spawn(context, instance,
network_info, block_device_info)
except Exception as ex: # pylint: disable=W0702
msg = _("Instance '%(instance_id)s' failed to spawn. Is "
"virtualization enabled in the BIOS? Details: "
"%(ex)s") % locals()
LOG.exception(msg)
except Exception as error: # pylint: disable=W0702
LOG.exception(_("Instance '%(instance_id)s' failed to spawn. "
"Details: %(error)s") % locals())
self._instance_update(context,
instance_id,
vm_state=vm_states.ERROR)
_deallocate_network()
return

Expand Down
22 changes: 22 additions & 0 deletions nova/tests/integrated/test_servers.py
Expand Up @@ -18,6 +18,7 @@
import time
import unittest

import nova.virt.fake
from nova.log import logging
from nova.tests.integrated import integrated_helpers
from nova.tests.integrated.api import client
Expand Down Expand Up @@ -52,6 +53,27 @@ def test_get_servers(self):
for server in servers:
LOG.debug("server: %s" % server)

def test_create_server_with_error(self):
"""Create a server which will enter error state."""
self.flags(stub_network=True)

def throw_error(*_):
raise Exception()

self.stubs.Set(nova.virt.fake.FakeConnection, 'spawn', throw_error)

server = self._build_minimal_create_server_request()
created_server = self.api.post_server({"server": server})
created_server_id = created_server['id']

found_server = self.api.get_server(created_server_id)
self.assertEqual(created_server_id, found_server['id'])

found_server = self._wait_for_state_change(found_server, 'BUILD')

self.assertEqual('ERROR', found_server['status'])
self._delete_server(created_server_id)

def test_create_and_delete_server(self):
"""Creates and deletes a server."""
self.flags(stub_network=True)
Expand Down

0 comments on commit 981f527

Please sign in to comment.