summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorJosh Kearney <josh@jk0.org>2011-09-08 16:10:03 -0500
committerJosh Kearney <josh@jk0.org>2011-09-08 16:10:03 -0500
commitaec647b3b42c4cd56a9509c2d1ac25ff12b0664e (patch)
tree560d7c7d7f6f5853005dcd3e0a48b641a1714e4c /nova
parentbb3b61b61dc4b45fba4bdab7ead69af239eac40a (diff)
First pass at adding reboot_type to reboot codepath.
Diffstat (limited to 'nova')
-rw-r--r--nova/api/openstack/servers.py5
-rw-r--r--nova/compute/api.py5
-rw-r--r--nova/compute/manager.py4
-rw-r--r--nova/tests/api/openstack/test_servers.py2
-rw-r--r--nova/tests/test_compute.py15
-rw-r--r--nova/tests/test_virt_drivers.py3
-rw-r--r--nova/tests/test_vmwareapi.py3
-rw-r--r--nova/virt/driver.py3
-rw-r--r--nova/virt/fake.py2
-rw-r--r--nova/virt/hyperv.py2
-rw-r--r--nova/virt/vmwareapi_conn.py2
-rw-r--r--nova/virt/xenapi/vmops.py9
-rw-r--r--nova/virt/xenapi_conn.py4
13 files changed, 38 insertions, 21 deletions
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index d084ac360..f5447edc5 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -334,9 +334,8 @@ class Controller(object):
LOG.exception(msg)
raise exc.HTTPBadRequest(explanation=msg)
try:
- # TODO(gundlach): pass reboot_type, support soft reboot in
- # virt driver
- self.compute_api.reboot(req.environ['nova.context'], id)
+ self.compute_api.reboot(req.environ['nova.context'], id,
+ reboot_type)
except Exception, e:
LOG.exception(_("Error in reboot %s"), e)
raise exc.HTTPUnprocessableEntity()
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 4e2944bb7..b0ea044c5 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -1042,13 +1042,14 @@ class API(base.Base):
return recv_meta
@scheduler_api.reroute_compute("reboot")
- def reboot(self, context, instance_id):
+ def reboot(self, context, instance_id, reboot_type):
"""Reboot the given instance."""
self.update(context,
instance_id,
vm_state=vm_states.ACTIVE,
task_state=task_states.REBOOTING)
- self._cast_compute_message('reboot_instance', context, instance_id)
+ self._cast_compute_message('reboot_instance', context, instance_id,
+ reboot_type)
@scheduler_api.reroute_compute("rebuild")
def rebuild(self, context, instance_id, image_href, admin_password,
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 0477db745..0be12297f 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -579,7 +579,7 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
@checks_instance_lock
- def reboot_instance(self, context, instance_id):
+ def reboot_instance(self, context, instance_id, reboot_type="SOFT"):
"""Reboot an instance on this host."""
LOG.audit(_("Rebooting instance %s"), instance_id, context=context)
context = context.elevated()
@@ -601,7 +601,7 @@ class ComputeManager(manager.SchedulerDependentManager):
context=context)
network_info = self._get_instance_nw_info(context, instance_ref)
- self.driver.reboot(instance_ref, network_info)
+ self.driver.reboot(instance_ref, network_info, reboot_type)
current_power_state = self._get_power_state(context, instance_ref)
self._instance_update(context,
diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py
index 2ef687709..d063a60c2 100644
--- a/nova/tests/api/openstack/test_servers.py
+++ b/nova/tests/api/openstack/test_servers.py
@@ -3615,7 +3615,7 @@ class TestGetKernelRamdiskFromImage(test.TestCase):
self.assertRaises(exception.NotFound, self._get_k_r, image_meta)
def test_ami_no_ramdisk(self):
- """If an ami is missing a ramdisk, return kernel ID and None for
+ """If an ami is missing a ramdisk, return kernel ID and None for
ramdisk ID
"""
image_meta = {'id': 1, 'status': 'active', 'container_format': 'ami',
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index 65fdffbd6..4d463572b 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -300,11 +300,20 @@ class ComputeTestCase(test.TestCase):
self.compute.resume_instance(self.context, instance_id)
self.compute.terminate_instance(self.context, instance_id)
- def test_reboot(self):
- """Ensure instance can be rebooted"""
+ def test_soft_reboot(self):
+ """Ensure instance can be soft rebooted"""
instance_id = self._create_instance()
+ reboot_type = "SOFT"
self.compute.run_instance(self.context, instance_id)
- self.compute.reboot_instance(self.context, instance_id)
+ self.compute.reboot_instance(self.context, instance_id, reboot_type)
+ self.compute.terminate_instance(self.context, instance_id)
+
+ def test_hard_reboot(self):
+ """Ensure instance can be hard rebooted"""
+ instance_id = self._create_instance()
+ reboot_type = "HARD"
+ self.compute.run_instance(self.context, instance_id)
+ self.compute.reboot_instance(self.context, instance_id, reboot_type)
self.compute.terminate_instance(self.context, instance_id)
def test_set_admin_password(self):
diff --git a/nova/tests/test_virt_drivers.py b/nova/tests/test_virt_drivers.py
index 480247c91..440d3401b 100644
--- a/nova/tests/test_virt_drivers.py
+++ b/nova/tests/test_virt_drivers.py
@@ -103,8 +103,9 @@ class _VirtDriverTestCase(test.TestCase):
def test_reboot(self):
instance_ref = test_utils.get_test_instance()
network_info = test_utils.get_test_network_info()
+ reboot_type = "SOFT"
self.connection.spawn(self.ctxt, instance_ref, network_info)
- self.connection.reboot(instance_ref, network_info)
+ self.connection.reboot(instance_ref, network_info, reboot_type)
@catch_notimplementederror
def test_get_host_ip_addr(self):
diff --git a/nova/tests/test_vmwareapi.py b/nova/tests/test_vmwareapi.py
index 06daf46e8..e6da1690f 100644
--- a/nova/tests/test_vmwareapi.py
+++ b/nova/tests/test_vmwareapi.py
@@ -170,7 +170,8 @@ class VMWareAPIVMTestCase(test.TestCase):
self._create_vm()
info = self.conn.get_info(1)
self._check_vm_info(info, power_state.RUNNING)
- self.conn.reboot(self.instance, self.network_info)
+ reboot_type = "SOFT"
+ self.conn.reboot(self.instance, self.network_info, reboot_type)
info = self.conn.get_info(1)
self._check_vm_info(info, power_state.RUNNING)
diff --git a/nova/virt/driver.py b/nova/virt/driver.py
index d05b51bd9..301346c6b 100644
--- a/nova/virt/driver.py
+++ b/nova/virt/driver.py
@@ -165,12 +165,13 @@ class ComputeDriver(object):
# TODO(Vek): Need to pass context in for access to auth_token
raise NotImplementedError()
- def reboot(self, instance, network_info):
+ def reboot(self, instance, network_info, reboot_type):
"""Reboot the specified instance.
:param instance: Instance object as returned by DB layer.
:param network_info:
:py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
+ :param reboot_type: Either a HARD or SOFT reboot
"""
# TODO(Vek): Need to pass context in for access to auth_token
raise NotImplementedError()
diff --git a/nova/virt/fake.py b/nova/virt/fake.py
index d5e2bf31b..3596d8353 100644
--- a/nova/virt/fake.py
+++ b/nova/virt/fake.py
@@ -103,7 +103,7 @@ class FakeConnection(driver.ComputeDriver):
if not instance['name'] in self.instances:
raise exception.InstanceNotRunning()
- def reboot(self, instance, network_info):
+ def reboot(self, instance, network_info, reboot_type):
pass
def get_host_ip_addr(self):
diff --git a/nova/virt/hyperv.py b/nova/virt/hyperv.py
index 03a78db1f..76925b405 100644
--- a/nova/virt/hyperv.py
+++ b/nova/virt/hyperv.py
@@ -367,7 +367,7 @@ class HyperVConnection(driver.ComputeDriver):
wmi_obj.Properties_.Item(prop).Value
return newinst
- def reboot(self, instance, network_info):
+ def reboot(self, instance, network_info, reboot_type):
"""Reboot the specified instance."""
vm = self._lookup(instance.name)
if vm is None:
diff --git a/nova/virt/vmwareapi_conn.py b/nova/virt/vmwareapi_conn.py
index 243ee64f5..fa89a8f45 100644
--- a/nova/virt/vmwareapi_conn.py
+++ b/nova/virt/vmwareapi_conn.py
@@ -133,7 +133,7 @@ class VMWareESXConnection(driver.ComputeDriver):
"""Create snapshot from a running VM instance."""
self._vmops.snapshot(context, instance, name)
- def reboot(self, instance, network_info):
+ def reboot(self, instance, network_info, reboot_type):
"""Reboot VM instance."""
self._vmops.reboot(instance, network_info)
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index c5f105f40..b7d6a40b4 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -617,10 +617,15 @@ class VMOps(object):
str(new_disk_size))
LOG.debug(_("Resize instance %s complete") % (instance.name))
- def reboot(self, instance):
+ def reboot(self, instance, reboot_type):
"""Reboot VM instance."""
vm_ref = self._get_vm_opaque_ref(instance)
- task = self._session.call_xenapi('Async.VM.clean_reboot', vm_ref)
+
+ if reboot_type == "HARD":
+ task = self._session.call_xenapi('Async.VM.hard_reboot', vm_ref)
+ else:
+ task = self._session.call_xenapi('Async.VM.clean_reboot', vm_ref)
+
self._session.wait_for_task(task, instance.id)
def get_agent_version(self, instance, timeout=None):
diff --git a/nova/virt/xenapi_conn.py b/nova/virt/xenapi_conn.py
index 0d23e7689..f6dbc19f8 100644
--- a/nova/virt/xenapi_conn.py
+++ b/nova/virt/xenapi_conn.py
@@ -203,9 +203,9 @@ class XenAPIConnection(driver.ComputeDriver):
""" Create snapshot from a running VM instance """
self._vmops.snapshot(context, instance, image_id)
- def reboot(self, instance, network_info):
+ def reboot(self, instance, network_info, reboot_type):
"""Reboot VM instance"""
- self._vmops.reboot(instance)
+ self._vmops.reboot(instance, reboot_type)
def set_admin_password(self, instance, new_pass):
"""Set the root/admin password on the VM instance"""