Merge "Cells API calls return 501 when cells disabled"
This commit is contained in:
@@ -51,6 +51,8 @@ CONF.register_opts(osapi_opts)
|
||||
LOG = logging.getLogger(__name__)
|
||||
QUOTAS = quota.QUOTAS
|
||||
|
||||
CONF.import_opt('enable', 'nova.cells.opts', group='cells')
|
||||
|
||||
# NOTE(cyeoh): A common regexp for acceptable names (user supplied)
|
||||
# that we want all new extensions to conform to unless there is a very
|
||||
# good reason not to.
|
||||
@@ -581,3 +583,13 @@ def get_instance(compute_api, context, instance_id, want_objects=False,
|
||||
expected_attrs=expected_attrs)
|
||||
except exception.InstanceNotFound as e:
|
||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
|
||||
|
||||
def check_cells_enabled(function):
|
||||
@functools.wraps(function)
|
||||
def inner(*args, **kwargs):
|
||||
if not CONF.cells.enable:
|
||||
msg = _("Cells is not enabled.")
|
||||
raise webob.exc.HTTPNotImplemented(explanation=msg)
|
||||
return function(*args, **kwargs)
|
||||
return inner
|
||||
|
||||
@@ -200,6 +200,7 @@ class Controller(object):
|
||||
return dict(cells=items)
|
||||
|
||||
@wsgi.serializers(xml=CellsTemplate)
|
||||
@common.check_cells_enabled
|
||||
def index(self, req):
|
||||
"""Return all cells in brief."""
|
||||
ctxt = req.environ['nova.context']
|
||||
@@ -207,6 +208,7 @@ class Controller(object):
|
||||
return self._get_cells(ctxt, req)
|
||||
|
||||
@wsgi.serializers(xml=CellsTemplate)
|
||||
@common.check_cells_enabled
|
||||
def detail(self, req):
|
||||
"""Return all cells in detail."""
|
||||
ctxt = req.environ['nova.context']
|
||||
@@ -214,6 +216,7 @@ class Controller(object):
|
||||
return self._get_cells(ctxt, req, detail=True)
|
||||
|
||||
@wsgi.serializers(xml=CellTemplate)
|
||||
@common.check_cells_enabled
|
||||
def info(self, req):
|
||||
"""Return name and capabilities for this cell."""
|
||||
context = req.environ['nova.context']
|
||||
@@ -232,6 +235,7 @@ class Controller(object):
|
||||
return dict(cell=cell)
|
||||
|
||||
@wsgi.serializers(xml=CellTemplate)
|
||||
@common.check_cells_enabled
|
||||
def capacities(self, req, id=None):
|
||||
"""Return capacities for a given cell or all cells."""
|
||||
# TODO(kaushikc): return capacities as a part of cell info and
|
||||
@@ -251,6 +255,7 @@ class Controller(object):
|
||||
return dict(cell={"capacities": capacities})
|
||||
|
||||
@wsgi.serializers(xml=CellTemplate)
|
||||
@common.check_cells_enabled
|
||||
def show(self, req, id):
|
||||
"""Return data about the given cell name. 'id' is a cell name."""
|
||||
context = req.environ['nova.context']
|
||||
@@ -261,6 +266,7 @@ class Controller(object):
|
||||
raise exc.HTTPNotFound()
|
||||
return dict(cell=_scrub_cell(cell))
|
||||
|
||||
@common.check_cells_enabled
|
||||
def delete(self, req, id):
|
||||
"""Delete a child or parent cell entry. 'id' is a cell name."""
|
||||
context = req.environ['nova.context']
|
||||
@@ -337,6 +343,7 @@ class Controller(object):
|
||||
|
||||
@wsgi.serializers(xml=CellTemplate)
|
||||
@wsgi.deserializers(xml=CellDeserializer)
|
||||
@common.check_cells_enabled
|
||||
def create(self, req, body):
|
||||
"""Create a child cell entry."""
|
||||
context = req.environ['nova.context']
|
||||
@@ -360,6 +367,7 @@ class Controller(object):
|
||||
|
||||
@wsgi.serializers(xml=CellTemplate)
|
||||
@wsgi.deserializers(xml=CellDeserializer)
|
||||
@common.check_cells_enabled
|
||||
def update(self, req, id, body):
|
||||
"""Update a child cell entry. 'id' is the cell name to update."""
|
||||
context = req.environ['nova.context']
|
||||
@@ -391,6 +399,7 @@ class Controller(object):
|
||||
raise exc.HTTPForbidden(explanation=e.format_message())
|
||||
return dict(cell=_scrub_cell(cell))
|
||||
|
||||
@common.check_cells_enabled
|
||||
def sync_instances(self, req, body):
|
||||
"""Tell all cells to sync instance info."""
|
||||
context = req.environ['nova.context']
|
||||
|
||||
@@ -108,21 +108,24 @@ class CellsController(object):
|
||||
items = [_scrub_cell(item, detail=detail) for item in items]
|
||||
return dict(cells=items)
|
||||
|
||||
@extensions.expected_errors(())
|
||||
@extensions.expected_errors(501)
|
||||
@common.check_cells_enabled
|
||||
def index(self, req):
|
||||
"""Return all cells in brief."""
|
||||
ctxt = req.environ['nova.context']
|
||||
authorize(ctxt)
|
||||
return self._get_cells(ctxt, req)
|
||||
|
||||
@extensions.expected_errors(())
|
||||
@extensions.expected_errors(501)
|
||||
@common.check_cells_enabled
|
||||
def detail(self, req):
|
||||
"""Return all cells in detail."""
|
||||
ctxt = req.environ['nova.context']
|
||||
authorize(ctxt)
|
||||
return self._get_cells(ctxt, req, detail=True)
|
||||
|
||||
@extensions.expected_errors(())
|
||||
@extensions.expected_errors(501)
|
||||
@common.check_cells_enabled
|
||||
def info(self, req):
|
||||
"""Return name and capabilities for this cell."""
|
||||
context = req.environ['nova.context']
|
||||
@@ -140,7 +143,8 @@ class CellsController(object):
|
||||
'capabilities': cell_capabs}
|
||||
return dict(cell=cell)
|
||||
|
||||
@extensions.expected_errors(404)
|
||||
@extensions.expected_errors((404, 501))
|
||||
@common.check_cells_enabled
|
||||
def capacities(self, req, id=None):
|
||||
"""Return capacities for a given cell or all cells."""
|
||||
# TODO(kaushikc): return capacities as a part of cell info and
|
||||
@@ -155,7 +159,8 @@ class CellsController(object):
|
||||
|
||||
return dict(cell={"capacities": capacities})
|
||||
|
||||
@extensions.expected_errors(404)
|
||||
@extensions.expected_errors((404, 501))
|
||||
@common.check_cells_enabled
|
||||
def show(self, req, id):
|
||||
"""Return data about the given cell name. 'id' is a cell name."""
|
||||
context = req.environ['nova.context']
|
||||
@@ -166,7 +171,8 @@ class CellsController(object):
|
||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
return dict(cell=_scrub_cell(cell))
|
||||
|
||||
@extensions.expected_errors((403, 404))
|
||||
@extensions.expected_errors((403, 404, 501))
|
||||
@common.check_cells_enabled
|
||||
@wsgi.response(204)
|
||||
def delete(self, req, id):
|
||||
"""Delete a child or parent cell entry. 'id' is a cell name."""
|
||||
@@ -242,7 +248,8 @@ class CellsController(object):
|
||||
# Now set the transport URL
|
||||
cell['transport_url'] = str(transport_url)
|
||||
|
||||
@extensions.expected_errors((400, 403))
|
||||
@extensions.expected_errors((400, 403, 501))
|
||||
@common.check_cells_enabled
|
||||
@wsgi.response(201)
|
||||
def create(self, req, body):
|
||||
"""Create a child cell entry."""
|
||||
@@ -265,7 +272,8 @@ class CellsController(object):
|
||||
raise exc.HTTPForbidden(explanation=e.format_message())
|
||||
return dict(cell=_scrub_cell(cell))
|
||||
|
||||
@extensions.expected_errors((400, 403, 404))
|
||||
@extensions.expected_errors((400, 403, 404, 501))
|
||||
@common.check_cells_enabled
|
||||
def update(self, req, id, body):
|
||||
"""Update a child cell entry. 'id' is the cell name to update."""
|
||||
context = req.environ['nova.context']
|
||||
@@ -297,7 +305,8 @@ class CellsController(object):
|
||||
raise exc.HTTPForbidden(explanation=e.format_message())
|
||||
return dict(cell=_scrub_cell(cell))
|
||||
|
||||
@extensions.expected_errors(400)
|
||||
@extensions.expected_errors((400, 501))
|
||||
@common.check_cells_enabled
|
||||
@wsgi.response(204)
|
||||
def sync_instances(self, req, body):
|
||||
"""Tell all cells to sync instance info."""
|
||||
|
||||
@@ -95,6 +95,7 @@ class CellsTest(BaseCellsTest):
|
||||
self.ext_mgr = self.mox.CreateMock(extensions.ExtensionManager)
|
||||
self.controller = cells_ext.Controller(self.ext_mgr)
|
||||
self.context = context.get_admin_context()
|
||||
self.flags(enable=True, group='cells')
|
||||
|
||||
def _get_request(self, resource):
|
||||
return fakes.HTTPRequest.blank('/v2/fake/' + resource)
|
||||
@@ -454,6 +455,36 @@ class CellsTest(BaseCellsTest):
|
||||
self.assertRaises(exc.HTTPBadRequest,
|
||||
self.controller.sync_instances, req, body=body)
|
||||
|
||||
def test_cells_disabled(self):
|
||||
self.flags(enable=False, group='cells')
|
||||
|
||||
req = self._get_request("cells")
|
||||
self.assertRaises(exc.HTTPNotImplemented,
|
||||
self.controller.index, req)
|
||||
|
||||
req = self._get_request("cells/detail")
|
||||
self.assertRaises(exc.HTTPNotImplemented,
|
||||
self.controller.detail, req)
|
||||
|
||||
req = self._get_request("cells/cell1")
|
||||
self.assertRaises(exc.HTTPNotImplemented,
|
||||
self.controller.show, req)
|
||||
|
||||
self.assertRaises(exc.HTTPNotImplemented,
|
||||
self.controller.delete, req, 'cell999')
|
||||
|
||||
req = self._get_request("cells/cells")
|
||||
self.assertRaises(exc.HTTPNotImplemented,
|
||||
self.controller.create, req, {})
|
||||
|
||||
req = self._get_request("cells/capacities")
|
||||
self.assertRaises(exc.HTTPNotImplemented,
|
||||
self.controller.capacities, req)
|
||||
|
||||
req = self._get_request("cells/sync_instances")
|
||||
self.assertRaises(exc.HTTPNotImplemented,
|
||||
self.controller.sync_instances, req, {})
|
||||
|
||||
|
||||
class TestCellsXMLSerializer(BaseCellsTest):
|
||||
def test_multiple_cells(self):
|
||||
|
||||
@@ -90,6 +90,7 @@ class CellsTest(BaseCellsTest):
|
||||
super(CellsTest, self).setUp()
|
||||
self.controller = cells_ext.CellsController()
|
||||
self.context = context.get_admin_context()
|
||||
self.flags(enable=True, group='cells')
|
||||
|
||||
def _get_request(self, resource):
|
||||
return fakes.HTTPRequestV3.blank('/' + resource)
|
||||
@@ -444,3 +445,33 @@ class CellsTest(BaseCellsTest):
|
||||
body = {'foo': 'meow'}
|
||||
self.assertRaises(exc.HTTPBadRequest,
|
||||
self.controller.sync_instances, req, body=body)
|
||||
|
||||
def test_cells_disabled(self):
|
||||
self.flags(enable=False, group='cells')
|
||||
|
||||
req = self._get_request("cells")
|
||||
self.assertRaises(exc.HTTPNotImplemented,
|
||||
self.controller.index, req)
|
||||
|
||||
req = self._get_request("cells/detail")
|
||||
self.assertRaises(exc.HTTPNotImplemented,
|
||||
self.controller.detail, req)
|
||||
|
||||
req = self._get_request("cells/cell1")
|
||||
self.assertRaises(exc.HTTPNotImplemented,
|
||||
self.controller.show, req)
|
||||
|
||||
self.assertRaises(exc.HTTPNotImplemented,
|
||||
self.controller.delete, req, 'cell999')
|
||||
|
||||
req = self._get_request("cells/cells")
|
||||
self.assertRaises(exc.HTTPNotImplemented,
|
||||
self.controller.create, req, {})
|
||||
|
||||
req = self._get_request("cells/capacities")
|
||||
self.assertRaises(exc.HTTPNotImplemented,
|
||||
self.controller.capacities, req)
|
||||
|
||||
req = self._get_request("cells/sync_instances")
|
||||
self.assertRaises(exc.HTTPNotImplemented,
|
||||
self.controller.sync_instances, req, {})
|
||||
|
||||
Reference in New Issue
Block a user