'Test that we raise an exception when attempting to delete a resource
class that is referenced in an inventory record.'

def test_destroy_fail_with_inventory(self):

    rc = objects.ResourceClass(self.ctx, name='CUSTOM_IRON_NFV')
    rc.create()
    rp = objects.ResourceProvider(self.ctx, name='my    rp', uuid=uuidsentinel.rp)
    rp.create()
    inv = objects.Inventory(resource_provider=rp, resource_class='CUSTOM_IRON_NFV', total=1)
    inv.obj_set_defaults()
    inv_list = objects.InventoryList(objects=[inv])
    rp.set_inventory(inv_list)
    self.assertRaises(exception.ResourceClassInUse, rc.destroy)
    rp.set_inventory(objects.InventoryList(objects=[]))
    rc.destroy()
    rc_list = objects.ResourceClassList.get_all(self.ctx)
    rc_ids = (r.id for r in rc_list)
    self.assertNotIn(rc.id, rc_ids)
