From 79f63f95fe81a6642f43c4ad2cb75f657e11ca3c Mon Sep 17 00:00:00 2001 From: Dima Shulyak Date: Wed, 15 Jan 2014 14:44:19 +0200 Subject: [PATCH] Fix cross-import bug in cinder.db.sqlalchemy.api Cross import in cinder.sqlalchemy.db.api module breaks if lazy loading of db backend is removed In oslo.incubator db.api lazy loading was removed Check this change for details https://review.openstack.org/#/c/55985/ Change-Id: I6a75afd0b9b55097ef76ad24c53e84339b527196 --- cinder/db/api.py | 6 ------ cinder/db/sqlalchemy/api.py | 7 +++---- cinder/exception.py | 5 +++++ cinder/tests/test_db_api.py | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/cinder/db/api.py b/cinder/db/api.py index 81f2856c3..a59d5409c 100644 --- a/cinder/db/api.py +++ b/cinder/db/api.py @@ -43,7 +43,6 @@ these objects be simple dictionaries. from oslo.config import cfg -from cinder import exception from cinder.openstack.common.db import api as db_api @@ -77,11 +76,6 @@ _BACKEND_MAPPING = {'sqlalchemy': 'cinder.db.sqlalchemy.api'} IMPL = db_api.DBAPI(backend_mapping=_BACKEND_MAPPING) -class NoMoreTargets(exception.CinderException): - """No more available targets.""" - pass - - ################### diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 792514dbc..382e9a1ca 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -30,7 +30,6 @@ from sqlalchemy.sql.expression import literal_column from sqlalchemy.sql import func from cinder.common import sqlalchemyutils -from cinder import db from cinder.db.sqlalchemy import models from cinder import exception from cinder.openstack.common.db import exception as db_exc @@ -145,7 +144,7 @@ def require_volume_exists(f): """ def wrapper(context, volume_id, *args, **kwargs): - db.volume_get(context, volume_id) + volume_get(context, volume_id) return f(context, volume_id, *args, **kwargs) wrapper.__name__ = f.__name__ return wrapper @@ -159,7 +158,7 @@ def require_snapshot_exists(f): """ def wrapper(context, snapshot_id, *args, **kwargs): - db.api.snapshot_get(context, snapshot_id) + snapshot_get(context, snapshot_id) return f(context, snapshot_id, *args, **kwargs) wrapper.__name__ = f.__name__ return wrapper @@ -964,7 +963,7 @@ def volume_allocate_iscsi_target(context, volume_id, host): # NOTE(vish): if with_lockmode isn't supported, as in sqlite, # then this has concurrency issues if not iscsi_target_ref: - raise db.NoMoreTargets() + raise exception.NoMoreTargets() iscsi_target_ref.volume_id = volume_id session.add(iscsi_target_ref) diff --git a/cinder/exception.py b/cinder/exception.py index 68d564957..911531bb7 100644 --- a/cinder/exception.py +++ b/cinder/exception.py @@ -393,6 +393,11 @@ class NoValidHost(CinderException): message = _("No valid host was found. %(reason)s") +class NoMoreTargets(CinderException): + """No more available targets.""" + pass + + class WillNotSchedule(CinderException): message = _("Host %(host)s is not up or doesn't exist.") diff --git a/cinder/tests/test_db_api.py b/cinder/tests/test_db_api.py index 20c59c69d..a46e9ecc0 100644 --- a/cinder/tests/test_db_api.py +++ b/cinder/tests/test_db_api.py @@ -255,7 +255,7 @@ class DBAPIVolumeTestCase(BaseTest): self.assertEqual(volume.host, 'host1') def test_volume_allocate_iscsi_target_no_more_targets(self): - self.assertRaises(db.NoMoreTargets, + self.assertRaises(exception.NoMoreTargets, db.volume_allocate_iscsi_target, self.ctxt, 42, 'host1') -- 2.45.2