Add is_cell0 helper method
This simplifies the task of checking if a CellMapping object is for cell0 by adding a helper method. Change-Id: I7e71ccfa0e1e6224cc807a2f27cd476ae705da99
This commit is contained in:
		@@ -1506,8 +1506,7 @@ class CellV2Commands(object):
 | 
			
		||||
            cell_mappings = objects.CellMappingList.get_all(context)
 | 
			
		||||
 | 
			
		||||
        for cell_mapping in cell_mappings:
 | 
			
		||||
            # TODO(alaski): Factor this into helper method on CellMapping
 | 
			
		||||
            if cell_mapping.uuid == cell_mapping.CELL0_UUID:
 | 
			
		||||
            if cell_mapping.is_cell0():
 | 
			
		||||
                continue
 | 
			
		||||
            with context.target_cell(ctxt, cell_mapping):
 | 
			
		||||
                compute_nodes = objects.ComputeNodeList.get_all(ctxt)
 | 
			
		||||
 
 | 
			
		||||
@@ -104,6 +104,9 @@ class CellMapping(base.NovaTimestampObject, base.NovaObject):
 | 
			
		||||
    def destroy(self):
 | 
			
		||||
        self._destroy_in_db(self._context, self.uuid)
 | 
			
		||||
 | 
			
		||||
    def is_cell0(self):
 | 
			
		||||
        return self.obj_attr_is_set('uuid') and self.uuid == self.CELL0_UUID
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@base.NovaObjectRegistry.register
 | 
			
		||||
class CellMappingList(base.ObjectListBase, base.NovaObject):
 | 
			
		||||
 
 | 
			
		||||
@@ -96,6 +96,13 @@ class _TestCellMappingObject(object):
 | 
			
		||||
        mapping_obj.destroy()
 | 
			
		||||
        destroy_in_db.assert_called_once_with(self.context, uuid)
 | 
			
		||||
 | 
			
		||||
    def test_is_cell0(self):
 | 
			
		||||
        self.assertFalse(objects.CellMapping().is_cell0())
 | 
			
		||||
        self.assertFalse(objects.CellMapping(
 | 
			
		||||
            uuid=uuidutils.generate_uuid()).is_cell0())
 | 
			
		||||
        self.assertTrue(objects.CellMapping(
 | 
			
		||||
            uuid=objects.CellMapping.CELL0_UUID).is_cell0())
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestCellMappingObject(test_objects._LocalTest,
 | 
			
		||||
                            _TestCellMappingObject):
 | 
			
		||||
 
 | 
			
		||||
@@ -1321,10 +1321,12 @@ class CellV2CommandsTestCase(test.TestCase):
 | 
			
		||||
            objects.ComputeNodeList(objects=compute_nodes[1:]),
 | 
			
		||||
            objects.ComputeNodeList(objects=compute_nodes[:1]))
 | 
			
		||||
 | 
			
		||||
        cell_mapping0 = objects.CellMapping(
 | 
			
		||||
            uuid=objects.CellMapping.CELL0_UUID)
 | 
			
		||||
        cell_mapping1 = objects.CellMapping(uuid=uuidutils.generate_uuid())
 | 
			
		||||
        cell_mapping2 = objects.CellMapping(uuid=uuidutils.generate_uuid())
 | 
			
		||||
        mock_cell_mapping_get_all.return_value = objects.CellMappingList(
 | 
			
		||||
            objects=[cell_mapping1, cell_mapping2])
 | 
			
		||||
            objects=[cell_mapping0, cell_mapping1, cell_mapping2])
 | 
			
		||||
 | 
			
		||||
        self.commands.discover_hosts()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user