summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nova/api/openstack/servers.py7
-rw-r--r--nova/compute/api.py7
-rw-r--r--nova/tests/test_compute.py16
3 files changed, 23 insertions, 7 deletions
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index 2a1424e46..125718114 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -145,7 +145,7 @@ class Controller(object):
def _get_server(self, context, instance_uuid):
"""Utility function for looking up an instance by uuid"""
try:
- return self.compute_api.get(context, instance_uuid)
+ return self.compute_api.routing_get(context, instance_uuid)
except exception.NotFound:
raise exc.HTTPNotFound()
@@ -769,6 +769,7 @@ class Controller(object):
def _action_rebuild(self, info, request, instance_id):
context = request.environ['nova.context']
+ instance = self._get_server(context, instance_id)
try:
image_href = info["rebuild"]["imageRef"]
@@ -794,7 +795,7 @@ class Controller(object):
password = utils.generate_password(FLAGS.password_length)
try:
- self.compute_api.rebuild(context, instance_id, image_href,
+ self.compute_api.rebuild(context, instance, image_href,
password, name=name, metadata=metadata,
files_to_inject=injected_files)
except exception.RebuildRequiresActiveInstance:
@@ -804,7 +805,7 @@ class Controller(object):
msg = _("Instance %s could not be found") % instance_id
raise exc.HTTPNotFound(explanation=msg)
- instance = self.compute_api.routing_get(context, instance_id)
+ instance = self._get_server(context, instance_id)
view = self._build_view(request, instance, is_detail=True)
view['server']['adminPass'] = password
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 92e492390..79b9cc290 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -1190,10 +1190,9 @@ class API(base.Base):
params={'reboot_type': reboot_type})
@scheduler_api.reroute_compute("rebuild")
- def rebuild(self, context, instance_id, image_href, admin_password,
+ def rebuild(self, context, instance, image_href, admin_password,
name=None, metadata=None, files_to_inject=None):
"""Rebuild the given instance with the provided metadata."""
- instance = self.db.instance_get(context, instance_id)
name = name or instance["display_name"]
if instance["vm_state"] != vm_states.ACTIVE:
@@ -1207,7 +1206,7 @@ class API(base.Base):
self._check_metadata_properties_quota(context, metadata)
self.update(context,
- instance_id,
+ instance["id"],
metadata=metadata,
display_name=name,
image_ref=image_href,
@@ -1222,7 +1221,7 @@ class API(base.Base):
self._cast_compute_message('rebuild_instance',
context,
- instance_id,
+ instance["id"],
params=rebuild_params)
@scheduler_api.reroute_compute("revert_resize")
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index 29269620c..021c75ed0 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -343,6 +343,22 @@ class ComputeTestCase(test.TestCase):
self.compute.resume_instance(self.context, instance_id)
self.compute.terminate_instance(self.context, instance_id)
+ def test_rebuild(self):
+ instance_id = self._create_instance()
+ self.compute.run_instance(self.context, instance_id)
+
+ instance = db.instance_get(self.context, instance_id)
+ self.assertEqual(instance['task_state'], None)
+
+ image_ref = instance["image_ref"]
+ password = "new_password"
+ self.compute_api.rebuild(self.context, instance, image_ref, password)
+
+ instance = db.instance_get(self.context, instance_id)
+ self.assertEqual(instance['task_state'], task_states.REBUILDING)
+
+ db.instance_destroy(self.context, instance_id)
+
def test_reboot_soft_api(self):
"""Ensure instance can be soft rebooted"""
instance_id = self._create_instance()