本文整理汇总了Python中oslo_db.exception.DBError方法的典型用法代码示例。如果您正苦于以下问题:Python exception.DBError方法的具体用法?Python exception.DBError怎么用?Python exception.DBError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_db.exception
的用法示例。
在下文中一共展示了exception.DBError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _retry_on_exceptions
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBError [as 别名]
def _retry_on_exceptions(exc):
if not isinstance(exc, exception.DBError):
return False
inn_e = exc.inner_exception
if not isinstance(inn_e, sqlalchemy.exc.InternalError):
return False
return ((
pymysql and
isinstance(inn_e.orig, pymysql.err.InternalError) and
(inn_e.orig.args[0] == pymysql.constants.ER.TABLE_DEF_CHANGED)
) or (
# HACK(jd) Sometimes, PostgreSQL raises an error such as "current
# transaction is aborted, commands ignored until end of transaction
# block" on its own catalog, so we need to retry, but this is not
# caught by oslo.db as a deadlock. This is likely because when we use
# Base.metadata.create_all(), sqlalchemy itself gets an error it does
# not catch or something. So this is why this function exists. To
# paperover I guess.
psycopg2
and isinstance(inn_e.orig, psycopg2.InternalError)
# current transaction is aborted
and inn_e.orig.pgcode == '25P02'
))
示例2: _validate_create_member
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBError [as 别名]
def _validate_create_member(self, lock_session, member_dict):
"""Validate creating member on pool."""
try:
return self.repositories.member.create(lock_session, **member_dict)
except odb_exceptions.DBDuplicateEntry as de:
column_list = ['pool_id', 'ip_address', 'protocol_port']
constraint_list = ['uq_member_pool_id_address_protocol_port']
if ['id'] == de.columns:
raise exceptions.IDAlreadyExists()
if (set(column_list) == set(de.columns) or
set(constraint_list) == set(de.columns)):
raise exceptions.DuplicateMemberEntry(
ip_address=member_dict.get('ip_address'),
port=member_dict.get('protocol_port'))
except odb_exceptions.DBError:
# TODO(blogan): will have to do separate validation protocol
# before creation or update since the exception messages
# do not give any information as to what constraint failed
raise exceptions.InvalidOption(value='', option='')
示例3: _validate_create_l7policy
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBError [as 别名]
def _validate_create_l7policy(self, lock_session, l7policy_dict):
try:
# Set the default HTTP redirect code here so it's explicit
if ((l7policy_dict.get('redirect_url') or
l7policy_dict.get('redirect_prefix')) and
not l7policy_dict.get('redirect_http_code')):
l7policy_dict['redirect_http_code'] = 302
return self.repositories.l7policy.create(lock_session,
**l7policy_dict)
except odb_exceptions.DBDuplicateEntry:
raise exceptions.IDAlreadyExists()
except odb_exceptions.DBError:
# TODO(blogan): will have to do separate validation protocol
# before creation or update since the exception messages
# do not give any information as to what constraint failed
raise exceptions.InvalidOption(value='', option='')
示例4: check_marker
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBError [as 别名]
def check_marker(table, marker, session):
marker_query = select([table]).where(table.c.id == marker)
try:
marker_resultproxy = session.execute(marker_query)
marker = marker_resultproxy.fetchone()
if marker is None:
raise exceptions.MarkerNotFound(
'Marker %s could not be found' % marker)
except oslo_db_exception.DBError as e:
# Malformed UUIDs return StatementError wrapped in a
# DBError
if isinstance(e.inner_exception,
sqlalchemy_exc.StatementError):
raise exceptions.InvalidMarker()
else:
raise
return marker
示例5: update
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBError [as 别名]
def update(context, id, name, description, is_public=None):
"""Update share type by id."""
values = {}
if name:
values.update({'name': name})
if description == "":
values.update({'description': None})
elif description:
values.update({'description': description})
if is_public is not None:
values.update({'is_public': is_public})
try:
db.share_type_update(context, id, values)
except db_exception.DBError:
LOG.exception('DB error.')
raise exception.ShareTypeUpdateFailed(id=id)
示例6: check_upgrade
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBError [as 别名]
def check_upgrade(self, engine, data):
sg_table = utils.load_table(self.table_name, engine)
db_result = engine.execute(sg_table.select().where(
sg_table.c.id == self.share_group_id))
self.test_case.assertEqual(1, db_result.rowcount)
for sg in db_result:
self.test_case.assertTrue(hasattr(sg, self.new_attr_name))
# Check that we can write proper enum data to the new field
for value in (None, 'pool', 'host'):
# pylint: disable=no-value-for-parameter
engine.execute(sg_table.update().where(
sg_table.c.id == self.share_group_id,
).values({self.new_attr_name: value}))
# Check that we cannot write values that are not allowed by enum.
for value in ('', 'fake', 'pool1', 'host1', '1pool', '1host'):
# pylint: disable=no-value-for-parameter
self.test_case.assertRaises(
oslo_db_exc.DBError,
engine.execute,
sg_table.update().where(
sg_table.c.id == self.share_group_id
).values({self.new_attr_name: value})
)
示例7: test_report_state_disconnected_DBError
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBError [as 别名]
def test_report_state_disconnected_DBError(self):
service_ref = {'host': self.host,
'binary': self.binary,
'topic': self.topic,
'report_count': 0,
'id': 1}
with mock.patch.object(service, 'db') as mock_db:
mock_db.service_get_by_args.side_effect = exception.NotFound()
mock_db.service_create.return_value = service_ref
mock_db.service_get.side_effect = db_exc.DBError()
serv = service.Service(
self.host,
self.binary,
self.topic,
'karbor.tests.unit.test_service.FakeManager'
)
serv.start()
serv.report_state()
self.assertTrue(serv.model_disconnected)
self.assertFalse(mock_db.service_update.called)
示例8: _validate_create_l7rule
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBError [as 别名]
def _validate_create_l7rule(self, lock_session, l7rule_dict):
try:
return self.repositories.l7rule.create(lock_session, **l7rule_dict)
except odb_exceptions.DBDuplicateEntry:
raise exceptions.IDAlreadyExists()
except odb_exceptions.DBError:
# TODO(blogan): will have to do separate validation protocol
# before creation or update since the exception messages
# do not give any information as to what constraint failed
raise exceptions.InvalidOption(value='', option='')
示例9: test_update_pool_add_ns_record_without_priority
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBError [as 别名]
def test_update_pool_add_ns_record_without_priority(self):
pool = self.create_pool(fixture=0)
self.create_zone(pool_id=pool.id)
new_ns_record = objects.PoolNsRecord(hostname='ns-new.example.org.')
pool.ns_records.append(new_ns_record)
# PoolNsRecord without "priority" triggers a DB exception
with testtools.ExpectedException(db_exception.DBError):
self.central_service.update_pool(self.admin_context, pool)
示例10: helper_create_endpoint_group
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBError [as 别名]
def helper_create_endpoint_group(self, info):
"""Create endpoint group database entry and verify OK."""
group = info['endpoint_group']
try:
actual = self.plugin.create_endpoint_group(self.context, info)
except db_exc.DBError as e:
self.fail("Endpoint create in prep for test failed: %s" % e)
self._compare_groups(group, actual)
self.assertIn('id', actual)
return actual['id']
示例11: test_JSONEncodedDict_type_check
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBError [as 别名]
def test_JSONEncodedDict_type_check(self):
self.assertRaises(db_exc.DBError,
self.dbapi.create_cluster_template,
{'labels':
['this is not a dict']})
示例12: test_JSONEncodedList_type_check
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBError [as 别名]
def test_JSONEncodedList_type_check(self):
self.assertRaises(db_exc.DBError,
self.dbapi.create_nodegroup,
{'node_addresses':
{'this is not a list': 'test'}})
示例13: create
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBError [as 别名]
def create(context, name, extra_specs=None, is_public=True,
projects=None, description=None):
"""Creates share types."""
extra_specs = extra_specs or {}
projects = projects or []
try:
get_valid_required_extra_specs(extra_specs)
get_valid_optional_extra_specs(extra_specs)
except exception.InvalidExtraSpec as e:
raise exception.InvalidShareType(reason=six.text_type(e))
extra_specs = sanitize_extra_specs(extra_specs)
try:
type_ref = db.share_type_create(context,
dict(name=name,
description=description,
extra_specs=extra_specs,
is_public=is_public),
projects=projects)
except db_exception.DBError:
LOG.exception('DB error.')
raise exception.ShareTypeCreateFailed(name=name,
extra_specs=extra_specs)
return type_ref
示例14: share_type_create
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBError [as 别名]
def share_type_create(context, values, projects=None):
"""Create a new share type.
In order to pass in extra specs, the values dict should contain a
'extra_specs' key/value pair:
{'extra_specs' : {'k1': 'v1', 'k2': 'v2', ...}}
"""
values = ensure_model_dict_has_id(values)
projects = projects or []
session = get_session()
with session.begin():
try:
values['extra_specs'] = _metadata_refs(values.get('extra_specs'),
models.ShareTypeExtraSpecs)
share_type_ref = models.ShareTypes()
share_type_ref.update(values)
share_type_ref.save(session=session)
except db_exception.DBDuplicateEntry:
raise exception.ShareTypeExists(id=values['name'])
except Exception as e:
raise db_exception.DBError(e)
for project in set(projects):
access_ref = models.ShareTypeProjects()
access_ref.update({"share_type_id": share_type_ref.id,
"project_id": project})
access_ref.save(session=session)
return share_type_ref
示例15: test_subnet_create_subnet_db_error
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBError [as 别名]
def test_subnet_create_subnet_db_error(self):
fake_sn_id = 'fake_sn_id'
req = fakes.HTTPRequest.blank('/subnets', version="2.51")
context = req.environ['manila.context']
body = {
'share-network-subnet': self._setup_create_test_request_body()
}
mock_sn_get = self.mock_object(db_api, 'share_network_get')
mock__validate_subnet = self.mock_object(
self.controller, '_validate_subnet')
mock_db_subnet_create = self.mock_object(
db_api, 'share_network_subnet_create',
mock.Mock(side_effect=db_exception.DBError()))
expected_data = copy.deepcopy(body['share-network-subnet'])
expected_data['availability_zone_id'] = fake_az['id']
expected_data.pop('availability_zone')
self.assertRaises(exc.HTTPInternalServerError,
self.controller.create,
req,
fake_sn_id,
body)
mock_sn_get.assert_called_once_with(context, fake_sn_id)
self.mock_az_get.assert_called_once_with(context, fake_az['name'])
mock__validate_subnet.assert_called_once_with(
context, fake_sn_id, az=fake_az)
mock_db_subnet_create.assert_called_once_with(
context, expected_data
)