Don't allow deletion of associated node

Checks that node is associated with instance
added to method destroy_node() in db api.
Exception NodeAssociated raised in case associated node.

Change-Id: I52c7a0b3d33078b38460b5fd08e4cd2d4c7731ef
This commit is contained in:
Yuriy Zveryanskyy 2013-10-21 13:12:27 +03:00
parent 982b8ba204
commit 06c8d72494
5 changed files with 19 additions and 4 deletions

View File

@ -466,10 +466,7 @@ class NodesController(rest.RestController):
@wsme_pecan.wsexpose(None, unicode, status_code=204)
def delete(self, node_id):
"""Delete a node.
TODO(deva): don't allow deletion of an associated node.
"""
"""Delete a node."""
if self._from_chassis:
raise exception.OperationNotPermitted

View File

@ -274,6 +274,10 @@ class NodeLocked(InvalidState):
message = _("Node %(node)s is locked by another process.")
class NodeAssociated(InvalidState):
message = _("Node %(node)s is associated with instance %(instance)s.")
class PortNotFound(NotFound):
message = _("Port %(port)s could not be found.")

View File

@ -303,6 +303,9 @@ class Connection(api.Connection):
raise exception.NodeNotFound(node=node)
if node_ref['reservation'] is not None:
raise exception.NodeLocked(node=node)
if node_ref['instance_uuid'] is not None:
raise exception.NodeAssociated(node=node,
instance=node_ref['instance_uuid'])
# Get node ID, if an UUID was supplied. The ID is
# required for deleting all ports, attached to the node.

View File

@ -370,6 +370,12 @@ class TestDelete(base.FunctionalTest):
expect_errors=True)
self.assertEqual(response.status_int, 403)
def test_delete_associated(self):
ndict = dbutils.get_test_node(instance_uuid='fake-uuid-1234')
self.post_json('/nodes', ndict)
response = self.delete('/nodes/%s' % ndict['uuid'], expect_errors=True)
self.assertEqual(response.status_int, 409)
class TestPut(base.FunctionalTest):

View File

@ -155,6 +155,11 @@ class DbNodeTestCase(base.DbTestCase):
self.assertRaises(exception.NodeLocked,
self.dbapi.destroy_node, n['id'])
def test_destroy_associated_node(self):
n = self._create_test_node(instance_uuid='fake-uuid-1234')
self.assertRaises(exception.NodeAssociated,
self.dbapi.destroy_node, n['uuid'])
def test_ports_get_destroyed_after_destroying_a_node(self):
n = self._create_test_node()
node_id = n['id']