Adds reset-task-status mgmt api instance action
When reset-task-status is called the instance's task status is set to NONE. Partially implements: blueprint reset-task-status-mgmt-api Change-Id: I3150b53c3feb586d4bcfa8a2f5807ecd53c89e26
This commit is contained in:
parent
b4b4e8db41
commit
cd66821e86
@ -15,14 +15,12 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import webob.exc
|
||||
|
||||
from novaclient import exceptions as nova_exceptions
|
||||
|
||||
from reddwarf.common import exception
|
||||
from reddwarf.common import wsgi
|
||||
from reddwarf.common.auth import admin_context
|
||||
from reddwarf.common.remote import create_nova_client
|
||||
from reddwarf.instance import models as instance_models
|
||||
from reddwarf.extensions.mgmt.instances import models
|
||||
from reddwarf.extensions.mgmt.instances import views
|
||||
@ -91,7 +89,8 @@ class MgmtInstanceController(InstanceController):
|
||||
_actions = {
|
||||
'stop': self._action_stop,
|
||||
'reboot': self._action_reboot,
|
||||
'migrate': self._action_migrate
|
||||
'migrate': self._action_migrate,
|
||||
'reset-task-status': self._action_reset_task_status
|
||||
}
|
||||
selected_action = None
|
||||
for key in body:
|
||||
@ -124,6 +123,12 @@ class MgmtInstanceController(InstanceController):
|
||||
instance.migrate()
|
||||
return wsgi.Result(None, 202)
|
||||
|
||||
def _action_reset_task_status(self, context, instance, body):
|
||||
LOG.debug("Setting Task-Status to NONE on instance %s." %
|
||||
instance.id)
|
||||
instance.reset_task_status()
|
||||
return wsgi.Result(None, 202)
|
||||
|
||||
@admin_context
|
||||
def root(self, req, tenant_id, id):
|
||||
"""Return the date and time root was enabled on an instance,
|
||||
|
@ -487,6 +487,10 @@ class Instance(BuiltInstance):
|
||||
self.update_db(task_status=InstanceTasks.MIGRATING)
|
||||
task_api.API(self.context).migrate(self.id)
|
||||
|
||||
def reset_task_status(self):
|
||||
LOG.info("Settting task status to NONE on instance %s..." % self.id)
|
||||
self.update_db(task_status=InstanceTasks.NONE)
|
||||
|
||||
def _validate_can_perform_action(self):
|
||||
"""
|
||||
Raises exception if an instance action cannot currently be performed.
|
||||
|
@ -77,6 +77,11 @@ class TestAdminRequired(object):
|
||||
""" A regular user may not perform an instance reboot. """
|
||||
assert_raises(Unauthorized, self.dbaas.management.reboot, 0)
|
||||
|
||||
@test
|
||||
def test_mgmt_instance_reset_task_status(self):
|
||||
""" A regular user may not perform an instance task status reset. """
|
||||
assert_raises(Unauthorized, self.dbaas.management.reset_task_status, 0)
|
||||
|
||||
@test
|
||||
def test_storage_index(self):
|
||||
""" A regular user may not view the list of storage available. """
|
||||
|
132
reddwarf/tests/api/mgmt/instances_actions.py
Normal file
132
reddwarf/tests/api/mgmt/instances_actions.py
Normal file
@ -0,0 +1,132 @@
|
||||
# Copyright 2013 OpenStack LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mox
|
||||
from reddwarf.common.context import ReddwarfContext
|
||||
from reddwarf.instance.tasks import InstanceTasks
|
||||
from reddwarf.instance import models as imodels
|
||||
from reddwarf.instance.models import DBInstance
|
||||
from reddwarf.extensions.mgmt.instances.models import MgmtInstance
|
||||
|
||||
from novaclient.v1_1.servers import Server
|
||||
|
||||
from proboscis import test
|
||||
from proboscis import before_class
|
||||
from proboscis import after_class
|
||||
from proboscis.asserts import assert_equal
|
||||
from proboscis.asserts import assert_raises
|
||||
from reddwarf.common import exception
|
||||
from reddwarf.extensions.mgmt.instances.service import MgmtInstanceController
|
||||
|
||||
GROUP = "dbaas.api.mgmt.action.reset-task-status"
|
||||
|
||||
|
||||
class MgmtInstanceBase(object):
|
||||
|
||||
def setUp(self):
|
||||
self.mock = mox.Mox()
|
||||
self._create_instance()
|
||||
self.controller = MgmtInstanceController()
|
||||
|
||||
def tearDown(self):
|
||||
self.db_info.delete()
|
||||
|
||||
def _create_instance(self):
|
||||
self.context = ReddwarfContext(is_admin=True)
|
||||
self.tenant_id = 999
|
||||
self.db_info = DBInstance.create(
|
||||
name="instance",
|
||||
flavor_id=1,
|
||||
tenant_id=self.tenant_id,
|
||||
volume_size=None,
|
||||
task_status=InstanceTasks.NONE)
|
||||
self.server = self.mock.CreateMock(Server)
|
||||
self.instance = imodels.Instance(self.context,
|
||||
self.db_info,
|
||||
self.server,
|
||||
service_status="ACTIVE")
|
||||
|
||||
def _make_request(self, path='/', context=None, **kwargs):
|
||||
from webob import Request
|
||||
path = '/'
|
||||
print "path:", path
|
||||
return Request.blank(path=path, environ={'reddwarf.context': context},
|
||||
**kwargs)
|
||||
|
||||
def _reload_db_info(self):
|
||||
self.db_info = DBInstance.find_by(id=self.db_info.id, deleted=False)
|
||||
|
||||
|
||||
@test(groups=[GROUP])
|
||||
class RestartTaskStatusTests(MgmtInstanceBase):
|
||||
@before_class
|
||||
def setUp(self):
|
||||
super(RestartTaskStatusTests, self).setUp()
|
||||
|
||||
@after_class
|
||||
def tearDown(self):
|
||||
super(RestartTaskStatusTests, self).tearDown()
|
||||
|
||||
def _change_task_status_to(self, new_task_status):
|
||||
self.db_info.task_status = new_task_status
|
||||
self.db_info.save()
|
||||
|
||||
def _make_request(self, path='/', context=None, **kwargs):
|
||||
req = super(RestartTaskStatusTests, self)._make_request(path, context,
|
||||
**kwargs)
|
||||
req.method = 'POST'
|
||||
body = {'reset-task-status': {}}
|
||||
return req, body
|
||||
|
||||
def reset_task_status(self):
|
||||
self.mock.StubOutWithMock(MgmtInstance, 'load')
|
||||
MgmtInstance.load(context=self.context,
|
||||
id=self.db_info.id).AndReturn(self.instance)
|
||||
self.mock.ReplayAll()
|
||||
|
||||
req, body = self._make_request(context=self.context)
|
||||
self.controller = MgmtInstanceController()
|
||||
resp = self.controller.action(req, body, self.tenant_id,
|
||||
self.db_info.id)
|
||||
|
||||
self.mock.UnsetStubs()
|
||||
self.mock.VerifyAll()
|
||||
return resp
|
||||
|
||||
@test
|
||||
def mgmt_restart_task_requires_admin_account(self):
|
||||
context = ReddwarfContext(is_admin=False)
|
||||
req, body = self._make_request(context=context)
|
||||
self.controller = MgmtInstanceController()
|
||||
assert_raises(exception.Forbidden, self.controller.action,
|
||||
req, body, self.tenant_id, self.db_info.id)
|
||||
|
||||
@test
|
||||
def mgmt_restart_task_returns_json(self):
|
||||
resp = self.reset_task_status()
|
||||
out = resp.data("application/json")
|
||||
assert_equal(out, None)
|
||||
|
||||
@test
|
||||
def mgmt_restart_task_returns_xml(self):
|
||||
resp = self.reset_task_status()
|
||||
out = resp.data("application/xml")
|
||||
assert_equal(out, None)
|
||||
|
||||
@test
|
||||
def mgmt_restart_task_changes_status_to_none(self):
|
||||
self._change_task_status_to(InstanceTasks.BUILDING)
|
||||
self.reset_task_status()
|
||||
self._reload_db_info()
|
||||
assert_equal(self.db_info.task_status, InstanceTasks.NONE)
|
@ -123,6 +123,7 @@ if __name__=="__main__":
|
||||
from reddwarf.tests.api.mgmt import accounts
|
||||
from reddwarf.tests.api.mgmt import admin_required
|
||||
from reddwarf.tests.api.mgmt import instances
|
||||
from reddwarf.tests.api.mgmt import instances_actions
|
||||
from reddwarf.tests.api.mgmt import storage
|
||||
|
||||
proboscis.TestProgram().run_and_exit()
|
||||
|
Loading…
x
Reference in New Issue
Block a user