Merge "Disable deleting a chassis that contains nodes"
This commit is contained in:
@@ -280,6 +280,11 @@ class NodeNotConfigured(IronicException):
|
||||
"is not fully configured.")
|
||||
|
||||
|
||||
class ChassisNotEmpty(IronicException):
|
||||
message = _("Cannot complete the requested action because chassis "
|
||||
"%(chassis)s contains nodes.")
|
||||
|
||||
|
||||
class IPMIFailure(IronicException):
|
||||
message = _("IPMI command failed: %(cmd)s.")
|
||||
|
||||
|
||||
@@ -395,8 +395,19 @@ class Connection(api.Connection):
|
||||
return ref
|
||||
|
||||
def destroy_chassis(self, chassis):
|
||||
def chassis_not_empty(session):
|
||||
"""Checks whether the chassis does not have nodes."""
|
||||
|
||||
query = model_query(models.Node, session=session)
|
||||
query = add_node_filter_by_chassis(query, chassis)
|
||||
|
||||
return query.count() != 0
|
||||
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
if chassis_not_empty(session):
|
||||
raise exception.ChassisNotEmpty(chassis=chassis)
|
||||
|
||||
query = model_query(models.Chassis, session=session)
|
||||
query = add_identity_filter(query, chassis)
|
||||
|
||||
|
||||
@@ -35,6 +35,10 @@ class DbChassisTestCase(base.DbTestCase):
|
||||
self.dbapi.create_chassis(ch)
|
||||
return ch
|
||||
|
||||
def _create_test_node(self, **kwargs):
|
||||
node = utils.get_test_node(**kwargs)
|
||||
return self.dbapi.create_node(node)
|
||||
|
||||
def test_get_chassis_list(self):
|
||||
uuids = []
|
||||
for i in xrange(1, 6):
|
||||
@@ -86,3 +90,10 @@ class DbChassisTestCase(base.DbTestCase):
|
||||
def test_destroy_chassis_that_does_not_exist(self):
|
||||
self.assertRaises(exception.ChassisNotFound,
|
||||
self.dbapi.destroy_chassis, 666)
|
||||
|
||||
def test_destroy_chassis_with_nodes(self):
|
||||
ch = self._create_test_chassis()
|
||||
self._create_test_node(chassis_id=ch['id'])
|
||||
|
||||
self.assertRaises(exception.ChassisNotEmpty,
|
||||
self.dbapi.destroy_chassis, ch['id'])
|
||||
|
||||
Reference in New Issue
Block a user