Merge "Convert pause/unpause, sus/res to use instance obj"
This commit is contained in:
commit
fb95f93bbd
@ -52,7 +52,8 @@ class Admin_actions(extensions.ExtensionDescriptor):
|
||||
"""Permit Admins to pause the server"""
|
||||
ctxt = req.environ['nova.context']
|
||||
try:
|
||||
self.compute_api.pause(ctxt, id)
|
||||
server = self.compute_api.get(ctxt, id)
|
||||
self.compute_api.pause(ctxt, server)
|
||||
except Exception:
|
||||
readable = traceback.format_exc()
|
||||
LOG.exception(_("Compute.api::pause %s"), readable)
|
||||
@ -66,7 +67,8 @@ class Admin_actions(extensions.ExtensionDescriptor):
|
||||
"""Permit Admins to unpause the server"""
|
||||
ctxt = req.environ['nova.context']
|
||||
try:
|
||||
self.compute_api.unpause(ctxt, id)
|
||||
server = self.compute_api.get(ctxt, id)
|
||||
self.compute_api.unpause(ctxt, server)
|
||||
except Exception:
|
||||
readable = traceback.format_exc()
|
||||
LOG.exception(_("Compute.api::unpause %s"), readable)
|
||||
@ -80,7 +82,8 @@ class Admin_actions(extensions.ExtensionDescriptor):
|
||||
"""Permit admins to suspend the server"""
|
||||
context = req.environ['nova.context']
|
||||
try:
|
||||
self.compute_api.suspend(context, id)
|
||||
server = self.compute_api.get(context, id)
|
||||
self.compute_api.suspend(context, server)
|
||||
except Exception:
|
||||
readable = traceback.format_exc()
|
||||
LOG.exception(_("compute.api::suspend %s"), readable)
|
||||
@ -94,7 +97,8 @@ class Admin_actions(extensions.ExtensionDescriptor):
|
||||
"""Permit admins to resume the server from suspend"""
|
||||
context = req.environ['nova.context']
|
||||
try:
|
||||
self.compute_api.resume(context, id)
|
||||
server = self.compute_api.get(context, id)
|
||||
self.compute_api.resume(context, server)
|
||||
except Exception:
|
||||
readable = traceback.format_exc()
|
||||
LOG.exception(_("compute.api::resume %s"), readable)
|
||||
|
@ -1353,8 +1353,9 @@ class API(base.Base):
|
||||
self.network_api.add_network_to_project(context, project_id)
|
||||
|
||||
@scheduler_api.reroute_compute("pause")
|
||||
def pause(self, context, instance_id):
|
||||
def pause(self, context, instance):
|
||||
"""Pause the given instance."""
|
||||
instance_id = instance["id"]
|
||||
self.update(context,
|
||||
instance_id,
|
||||
vm_state=vm_states.ACTIVE,
|
||||
@ -1362,8 +1363,9 @@ class API(base.Base):
|
||||
self._cast_compute_message('pause_instance', context, instance_id)
|
||||
|
||||
@scheduler_api.reroute_compute("unpause")
|
||||
def unpause(self, context, instance_id):
|
||||
def unpause(self, context, instance):
|
||||
"""Unpause the given instance."""
|
||||
instance_id = instance["id"]
|
||||
self.update(context,
|
||||
instance_id,
|
||||
vm_state=vm_states.PAUSED,
|
||||
@ -1398,8 +1400,9 @@ class API(base.Base):
|
||||
return self.db.instance_get_actions(context, instance_id)
|
||||
|
||||
@scheduler_api.reroute_compute("suspend")
|
||||
def suspend(self, context, instance_id):
|
||||
def suspend(self, context, instance):
|
||||
"""Suspend the given instance."""
|
||||
instance_id = instance["id"]
|
||||
self.update(context,
|
||||
instance_id,
|
||||
vm_state=vm_states.ACTIVE,
|
||||
@ -1407,8 +1410,9 @@ class API(base.Base):
|
||||
self._cast_compute_message('suspend_instance', context, instance_id)
|
||||
|
||||
@scheduler_api.reroute_compute("resume")
|
||||
def resume(self, context, instance_id):
|
||||
def resume(self, context, instance):
|
||||
"""Resume the given instance."""
|
||||
instance_id = instance["id"]
|
||||
self.update(context,
|
||||
instance_id,
|
||||
vm_state=vm_states.SUSPENDED,
|
||||
|
@ -12,6 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import datetime
|
||||
import json
|
||||
import webob
|
||||
|
||||
@ -23,11 +24,32 @@ from nova.tests.api.openstack import fakes
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
|
||||
INSTANCE = {
|
||||
"id": 1,
|
||||
"name": "fake",
|
||||
"display_name": "test_server",
|
||||
"uuid": "abcd",
|
||||
"user_id": 'fake_user_id',
|
||||
"tenant_id": 'fake_tenant_id',
|
||||
"created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
|
||||
"updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
|
||||
"security_groups": [{"id": 1, "name": "test"}],
|
||||
"progress": 0,
|
||||
"image_ref": 'http://foo.com/123',
|
||||
"fixed_ips": [],
|
||||
"instance_type": {"flavorid": '124'},
|
||||
}
|
||||
|
||||
|
||||
def fake_compute_api(cls, req, id):
|
||||
return True
|
||||
|
||||
|
||||
def return_server_by_id(context, id, session=None):
|
||||
INSTANCE['id'] = id
|
||||
return INSTANCE
|
||||
|
||||
|
||||
class AdminActionsTest(test.TestCase):
|
||||
|
||||
_actions = ('pause', 'unpause', 'suspend', 'resume', 'migrate',
|
||||
@ -41,6 +63,7 @@ class AdminActionsTest(test.TestCase):
|
||||
self.flags(allow_admin_api=True)
|
||||
for _method in self._methods:
|
||||
self.stubs.Set(compute.API, _method, fake_compute_api)
|
||||
self.stubs.Set(compute.API, 'get', return_server_by_id)
|
||||
|
||||
def test_admin_api_enabled(self):
|
||||
app = fakes.wsgi_app()
|
||||
|
@ -1123,6 +1123,66 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
instance = db.instance_get(self.context, instance_id)
|
||||
self.assertEqual(instance['task_state'], task_states.DELETING)
|
||||
|
||||
def test_suspend(self):
|
||||
"""Ensure instance can be suspended"""
|
||||
instance_id = self._create_instance()
|
||||
self.compute.run_instance(self.context, instance_id)
|
||||
|
||||
inst_ref = db.instance_get(self.context, instance_id)
|
||||
self.assertEqual(inst_ref['task_state'], None)
|
||||
|
||||
self.compute_api.suspend(self.context, inst_ref)
|
||||
|
||||
inst_ref = db.instance_get(self.context, instance_id)
|
||||
self.assertEqual(inst_ref['task_state'], task_states.SUSPENDING)
|
||||
|
||||
db.instance_destroy(self.context, instance_id)
|
||||
|
||||
def test_resume(self):
|
||||
"""Ensure instance can be resumed"""
|
||||
instance_id = self._create_instance()
|
||||
self.compute.run_instance(self.context, instance_id)
|
||||
|
||||
inst_ref = db.instance_get(self.context, instance_id)
|
||||
self.assertEqual(inst_ref['task_state'], None)
|
||||
|
||||
self.compute_api.resume(self.context, inst_ref)
|
||||
|
||||
inst_ref = db.instance_get(self.context, instance_id)
|
||||
self.assertEqual(inst_ref['task_state'], task_states.RESUMING)
|
||||
|
||||
db.instance_destroy(self.context, instance_id)
|
||||
|
||||
def test_pause(self):
|
||||
"""Ensure instance can be paused"""
|
||||
instance_id = self._create_instance()
|
||||
self.compute.run_instance(self.context, instance_id)
|
||||
|
||||
inst_ref = db.instance_get(self.context, instance_id)
|
||||
self.assertEqual(inst_ref['task_state'], None)
|
||||
|
||||
self.compute_api.pause(self.context, inst_ref)
|
||||
|
||||
inst_ref = db.instance_get(self.context, instance_id)
|
||||
self.assertEqual(inst_ref['task_state'], task_states.PAUSING)
|
||||
|
||||
db.instance_destroy(self.context, instance_id)
|
||||
|
||||
def test_unpause(self):
|
||||
"""Ensure instance can be unpaused"""
|
||||
instance_id = self._create_instance()
|
||||
self.compute.run_instance(self.context, instance_id)
|
||||
|
||||
inst_ref = db.instance_get(self.context, instance_id)
|
||||
self.assertEqual(inst_ref['task_state'], None)
|
||||
|
||||
self.compute.pause_instance(self.context, instance_id)
|
||||
|
||||
self.compute_api.unpause(self.context, inst_ref)
|
||||
|
||||
inst_ref = db.instance_get(self.context, instance_id)
|
||||
self.assertEqual(inst_ref['task_state'], task_states.UNPAUSING)
|
||||
|
||||
db.instance_destroy(self.context, instance_id)
|
||||
|
||||
def test_rebuild(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user