Merge "Deal with db_exc.DBDuplicate of conductor startup" into stable/pike
This commit is contained in:
commit
3eb73ea41b
|
@ -17,6 +17,7 @@
|
||||||
from oslo_db import exception as db_exc
|
from oslo_db import exception as db_exc
|
||||||
from oslo_db.sqlalchemy import session as db_session
|
from oslo_db.sqlalchemy import session as db_session
|
||||||
from oslo_db.sqlalchemy import utils as db_utils
|
from oslo_db.sqlalchemy import utils as db_utils
|
||||||
|
from oslo_log import log
|
||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
from oslo_utils import strutils
|
from oslo_utils import strutils
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
|
@ -38,6 +39,7 @@ profiler_sqlalchemy = importutils.try_import('osprofiler.sqlalchemy')
|
||||||
|
|
||||||
CONF = magnum.conf.CONF
|
CONF = magnum.conf.CONF
|
||||||
|
|
||||||
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
_FACADE = None
|
_FACADE = None
|
||||||
|
|
||||||
|
@ -533,7 +535,14 @@ class Connection(api.Connection):
|
||||||
try:
|
try:
|
||||||
magnum_service.save()
|
magnum_service.save()
|
||||||
except db_exc.DBDuplicateEntry:
|
except db_exc.DBDuplicateEntry:
|
||||||
raise exception.MagnumServiceAlreadyExists(id=magnum_service['id'])
|
host = values["host"]
|
||||||
|
binary = values["binary"]
|
||||||
|
LOG.warning("Magnum service with same host:%(host)s and"
|
||||||
|
" binary:%(binary)s had been saved into DB",
|
||||||
|
{'host': host, 'binary': binary})
|
||||||
|
query = model_query(models.MagnumService)
|
||||||
|
query = query.filter_by(host=host, binary=binary)
|
||||||
|
return query.one()
|
||||||
return magnum_service
|
return magnum_service
|
||||||
|
|
||||||
def get_magnum_service_list(self, disabled=None, limit=None,
|
def get_magnum_service_list(self, disabled=None, limit=None,
|
||||||
|
|
|
@ -24,9 +24,10 @@ class DbMagnumServiceTestCase(base.DbTestCase):
|
||||||
utils.create_test_magnum_service()
|
utils.create_test_magnum_service()
|
||||||
|
|
||||||
def test_create_magnum_service_failure_for_dup(self):
|
def test_create_magnum_service_failure_for_dup(self):
|
||||||
utils.create_test_magnum_service()
|
ms = utils.create_test_magnum_service()
|
||||||
self.assertRaises(exception.MagnumServiceAlreadyExists,
|
res = self.dbapi.get_magnum_service_by_host_and_binary(
|
||||||
utils.create_test_magnum_service)
|
ms['host'], ms['binary'])
|
||||||
|
self.assertEqual(ms.id, res.id)
|
||||||
|
|
||||||
def test_get_magnum_service_by_host_and_binary(self):
|
def test_get_magnum_service_by_host_and_binary(self):
|
||||||
ms = utils.create_test_magnum_service()
|
ms = utils.create_test_magnum_service()
|
||||||
|
|
Loading…
Reference in New Issue