api.py (openstack-cyborg-6.0.0) | : | api.py (openstack-cyborg-7.0.0) | ||
---|---|---|---|---|
skipping to change at line 249 | skipping to change at line 249 | |||
msg = _("Cannot overwrite UUID for an existing AttachHandle.") | msg = _("Cannot overwrite UUID for an existing AttachHandle.") | |||
raise exception.InvalidParameterValue(err=msg) | raise exception.InvalidParameterValue(err=msg) | |||
return self._do_update_attach_handle(context, uuid, values) | return self._do_update_attach_handle(context, uuid, values) | |||
@oslo_db_api.retry_on_deadlock | @oslo_db_api.retry_on_deadlock | |||
def _do_update_attach_handle(self, context, uuid, values): | def _do_update_attach_handle(self, context, uuid, values): | |||
with _session_for_write(): | with _session_for_write(): | |||
query = model_query(context, models.AttachHandle) | query = model_query(context, models.AttachHandle) | |||
query = add_identity_filter(query, uuid) | query = add_identity_filter(query, uuid) | |||
try: | try: | |||
ref = query.with_lockmode('update').one() | ref = query.with_for_update().one() | |||
except NoResultFound: | except NoResultFound: | |||
raise exception.ResourceNotFound( | raise exception.ResourceNotFound( | |||
resource='AttachHandle', | resource='AttachHandle', | |||
msg='with uuid=%s' % uuid) | msg='with uuid=%s' % uuid) | |||
ref.update(values) | ref.update(values) | |||
return ref | return ref | |||
@oslo_db_api.retry_on_deadlock | @oslo_db_api.retry_on_deadlock | |||
def _do_allocate_attach_handle(self, context, deployable_id): | def _do_allocate_attach_handle(self, context, deployable_id): | |||
"""Atomically get a set of attach handles that match the query | """Atomically get a set of attach handles that match the query | |||
and mark one of those as in_use. | and mark one of those as in_use. | |||
""" | """ | |||
with _session_for_write() as session: | with _session_for_write() as session: | |||
query = model_query(context, models.AttachHandle). \ | query = model_query(context, models.AttachHandle). \ | |||
filter_by(deployable_id=deployable_id, | filter_by(deployable_id=deployable_id, | |||
in_use=False) | in_use=False) | |||
values = {"in_use": True} | values = {"in_use": True} | |||
ref = query.with_lockmode('update').first() | ref = query.with_for_update().first() | |||
if not ref: | if not ref: | |||
msg = 'Matching deployable_id {0}'.format(deployable_id) | msg = 'Matching deployable_id {0}'.format(deployable_id) | |||
raise exception.ResourceNotFound( | raise exception.ResourceNotFound( | |||
resource='AttachHandle', msg=msg) | resource='AttachHandle', msg=msg) | |||
ref.update(values) | ref.update(values) | |||
session.flush() | session.flush() | |||
return ref | return ref | |||
def attach_handle_allocate(self, context, deployable_id): | def attach_handle_allocate(self, context, deployable_id): | |||
"""Allocate an attach handle with given deployable. | """Allocate an attach handle with given deployable. | |||
skipping to change at line 371 | skipping to change at line 371 | |||
msg = _("Cannot overwrite UUID for an existing ControlpathID.") | msg = _("Cannot overwrite UUID for an existing ControlpathID.") | |||
raise exception.InvalidParameterValue(err=msg) | raise exception.InvalidParameterValue(err=msg) | |||
return self._do_update_control_path(context, uuid, values) | return self._do_update_control_path(context, uuid, values) | |||
@oslo_db_api.retry_on_deadlock | @oslo_db_api.retry_on_deadlock | |||
def _do_update_control_path(self, context, uuid, values): | def _do_update_control_path(self, context, uuid, values): | |||
with _session_for_write(): | with _session_for_write(): | |||
query = model_query(context, models.ControlpathID) | query = model_query(context, models.ControlpathID) | |||
query = add_identity_filter(query, uuid) | query = add_identity_filter(query, uuid) | |||
try: | try: | |||
ref = query.with_lockmode('update').one() | ref = query.with_for_update().one() | |||
except NoResultFound: | except NoResultFound: | |||
raise exception.ResourceNotFound( | raise exception.ResourceNotFound( | |||
resource='ControlpathID', | resource='ControlpathID', | |||
msg='with uuid=%s' % uuid) | msg='with uuid=%s' % uuid) | |||
ref.update(values) | ref.update(values) | |||
return ref | return ref | |||
@oslo_db_api.retry_on_deadlock | @oslo_db_api.retry_on_deadlock | |||
def control_path_delete(self, context, uuid): | def control_path_delete(self, context, uuid): | |||
with _session_for_write(): | with _session_for_write(): | |||
skipping to change at line 471 | skipping to change at line 471 | |||
except db_exc.DBDuplicateEntry as e: | except db_exc.DBDuplicateEntry as e: | |||
if 'name' in e.columns: | if 'name' in e.columns: | |||
raise exception.DuplicateDeviceName(name=values['name']) | raise exception.DuplicateDeviceName(name=values['name']) | |||
@oslo_db_api.retry_on_deadlock | @oslo_db_api.retry_on_deadlock | |||
def _do_update_device(self, context, uuid, values): | def _do_update_device(self, context, uuid, values): | |||
with _session_for_write(): | with _session_for_write(): | |||
query = model_query(context, models.Device) | query = model_query(context, models.Device) | |||
query = add_identity_filter(query, uuid) | query = add_identity_filter(query, uuid) | |||
try: | try: | |||
ref = query.with_lockmode('update').one() | ref = query.with_for_update().one() | |||
except NoResultFound: | except NoResultFound: | |||
raise exception.ResourceNotFound( | raise exception.ResourceNotFound( | |||
resource='Device', | resource='Device', | |||
msg='with uuid=%s' % uuid) | msg='with uuid=%s' % uuid) | |||
ref.update(values) | ref.update(values) | |||
return ref | return ref | |||
@oslo_db_api.retry_on_deadlock | @oslo_db_api.retry_on_deadlock | |||
def device_delete(self, context, uuid): | def device_delete(self, context, uuid): | |||
skipping to change at line 503 | skipping to change at line 503 | |||
values['uuid'] = uuidutils.generate_uuid() | values['uuid'] = uuidutils.generate_uuid() | |||
device_profile = models.DeviceProfile() | device_profile = models.DeviceProfile() | |||
device_profile.update(values) | device_profile.update(values) | |||
with _session_for_write() as session: | with _session_for_write() as session: | |||
try: | try: | |||
session.add(device_profile) | session.add(device_profile) | |||
session.flush() | session.flush() | |||
except db_exc.DBDuplicateEntry as e: | except db_exc.DBDuplicateEntry as e: | |||
if 'name' in e.columns: | # mysql duplicate key error changed as reference link below: | |||
# https://review.opendev.org/c/openstack/oslo.db/+/792124 | ||||
LOG.info('Duplicate columns are: ', e.columns) | ||||
columns = [column.split('0')[1] if 'uniq_' in column else | ||||
column for column in e.columns] | ||||
if 'name' in columns: | ||||
raise exception.DuplicateDeviceProfileName( | raise exception.DuplicateDeviceProfileName( | |||
name=values['name']) | name=values['name']) | |||
else: | else: | |||
raise exception.DeviceProfileAlreadyExists( | raise exception.DeviceProfileAlreadyExists( | |||
uuid=values['uuid']) | uuid=values['uuid']) | |||
return device_profile | return device_profile | |||
def device_profile_get_by_uuid(self, context, uuid): | def device_profile_get_by_uuid(self, context, uuid): | |||
query = model_query( | query = model_query( | |||
context, | context, | |||
skipping to change at line 583 | skipping to change at line 588 | |||
except db_exc.DBDuplicateEntry as e: | except db_exc.DBDuplicateEntry as e: | |||
if 'name' in e.columns: | if 'name' in e.columns: | |||
raise exception.DuplicateDeviceProfileName(name=values['name']) | raise exception.DuplicateDeviceProfileName(name=values['name']) | |||
@oslo_db_api.retry_on_deadlock | @oslo_db_api.retry_on_deadlock | |||
def _do_update_device_profile(self, context, uuid, values): | def _do_update_device_profile(self, context, uuid, values): | |||
with _session_for_write(): | with _session_for_write(): | |||
query = model_query(context, models.DeviceProfile) | query = model_query(context, models.DeviceProfile) | |||
query = add_identity_filter(query, uuid) | query = add_identity_filter(query, uuid) | |||
try: | try: | |||
ref = query.with_lockmode('update').one() | ref = query.with_for_update().one() | |||
except NoResultFound: | except NoResultFound: | |||
raise exception.ResourceNotFound( | raise exception.ResourceNotFound( | |||
resource='Device Profile', | resource='Device Profile', | |||
msg='with uuid=%s' % uuid) | msg='with uuid=%s' % uuid) | |||
ref.update(values) | ref.update(values) | |||
return ref | return ref | |||
@oslo_db_api.retry_on_deadlock | @oslo_db_api.retry_on_deadlock | |||
def device_profile_delete(self, context, uuid): | def device_profile_delete(self, context, uuid): | |||
skipping to change at line 664 | skipping to change at line 669 | |||
if 'name' in e.columns: | if 'name' in e.columns: | |||
raise exception.DuplicateDeployableName(name=values['name']) | raise exception.DuplicateDeployableName(name=values['name']) | |||
@oslo_db_api.retry_on_deadlock | @oslo_db_api.retry_on_deadlock | |||
def _do_update_deployable(self, context, uuid, values): | def _do_update_deployable(self, context, uuid, values): | |||
with _session_for_write(): | with _session_for_write(): | |||
query = model_query(context, models.Deployable) | query = model_query(context, models.Deployable) | |||
# query = add_identity_filter(query, uuid) | # query = add_identity_filter(query, uuid) | |||
query = query.filter_by(uuid=uuid) | query = query.filter_by(uuid=uuid) | |||
try: | try: | |||
ref = query.with_lockmode('update').one() | ref = query.with_for_update().one() | |||
except NoResultFound: | except NoResultFound: | |||
raise exception.ResourceNotFound( | raise exception.ResourceNotFound( | |||
resource='Deployable', | resource='Deployable', | |||
msg='with uuid=%s' % uuid) | msg='with uuid=%s' % uuid) | |||
ref.update(values) | ref.update(values) | |||
return ref | return ref | |||
@oslo_db_api.retry_on_deadlock | @oslo_db_api.retry_on_deadlock | |||
def deployable_delete(self, context, uuid): | def deployable_delete(self, context, uuid): | |||
skipping to change at line 764 | skipping to change at line 769 | |||
def attribute_get_by_deployable_id(self, context, deployable_id): | def attribute_get_by_deployable_id(self, context, deployable_id): | |||
query = model_query( | query = model_query( | |||
context, | context, | |||
models.Attribute).filter_by(deployable_id=deployable_id) | models.Attribute).filter_by(deployable_id=deployable_id) | |||
return query.all() | return query.all() | |||
def attribute_get_by_filter(self, context, filters): | def attribute_get_by_filter(self, context, filters): | |||
"""Return attributes that matches the filters | """Return attributes that matches the filters | |||
""" | """ | |||
query_prefix = model_query(context, models.Attribute) | query_prefix = model_query(context, models.Attribute) | |||
exact_match_filter_names = ['deployable_id', 'key'] | ||||
# Filter the query | # Filter the query | |||
query_prefix = self._exact_filter(models.Attribute, query_prefix, | query_prefix = self._exact_filter(models.Attribute, query_prefix, | |||
filters) | filters, exact_match_filter_names) | |||
if query_prefix is None: | if query_prefix is None: | |||
return [] | return [] | |||
return query_prefix.all() | return query_prefix.all() | |||
# def _exact_attribute_by_filter(self, query, filters): | # def _exact_attribute_by_filter(self, query, filters): | |||
# """Applies exact match filtering to a atrtribute query. | # """Applies exact match filtering to a atrtribute query. | |||
# Returns the updated query. | # Returns the updated query. | |||
# :param filters: The filters specified by a dict of kv pairs | # :param filters: The filters specified by a dict of kv pairs | |||
# """ | # """ | |||
skipping to change at line 797 | skipping to change at line 803 | |||
def attribute_update(self, context, uuid, key, value): | def attribute_update(self, context, uuid, key, value): | |||
return self._do_update_attribute(context, uuid, key, value) | return self._do_update_attribute(context, uuid, key, value) | |||
@oslo_db_api.retry_on_deadlock | @oslo_db_api.retry_on_deadlock | |||
def _do_update_attribute(self, context, uuid, key, value): | def _do_update_attribute(self, context, uuid, key, value): | |||
update_fields = {'key': key, 'value': value} | update_fields = {'key': key, 'value': value} | |||
with _session_for_write(): | with _session_for_write(): | |||
query = model_query(context, models.Attribute) | query = model_query(context, models.Attribute) | |||
query = add_identity_filter(query, uuid) | query = add_identity_filter(query, uuid) | |||
try: | try: | |||
ref = query.with_lockmode('update').one() | ref = query.with_for_update().one() | |||
except NoResultFound: | except NoResultFound: | |||
raise exception.ResourceNotFound( | raise exception.ResourceNotFound( | |||
resource='Attribute', | resource='Attribute', | |||
msg='with uuid=%s' % uuid) | msg='with uuid=%s' % uuid) | |||
ref.update(update_fields) | ref.update(update_fields) | |||
return ref | return ref | |||
def attribute_delete(self, context, uuid): | def attribute_delete(self, context, uuid): | |||
with _session_for_write(): | with _session_for_write(): | |||
skipping to change at line 864 | skipping to change at line 870 | |||
if 'uuid' in values and values['uuid'] != uuid: | if 'uuid' in values and values['uuid'] != uuid: | |||
msg = _("Cannot overwrite UUID for an existing ExtArq.") | msg = _("Cannot overwrite UUID for an existing ExtArq.") | |||
raise exception.InvalidParameterValue(err=msg) | raise exception.InvalidParameterValue(err=msg) | |||
return self._do_update_extarq(context, uuid, values, state_scope) | return self._do_update_extarq(context, uuid, values, state_scope) | |||
@oslo_db_api.retry_on_deadlock | @oslo_db_api.retry_on_deadlock | |||
def _do_update_extarq(self, context, uuid, values, state_scope=None): | def _do_update_extarq(self, context, uuid, values, state_scope=None): | |||
with _session_for_write(): | with _session_for_write(): | |||
query = model_query(context, models.ExtArq) | query = model_query(context, models.ExtArq) | |||
query = query_update = query.filter_by( | query = query_update = query.filter_by( | |||
uuid=uuid).with_lockmode('update') | uuid=uuid).with_for_update() | |||
if type(state_scope) is list: | if type(state_scope) is list: | |||
query_update = query_update.filter( | query_update = query_update.filter( | |||
models.ExtArq.state.in_(state_scope)) | models.ExtArq.state.in_(state_scope)) | |||
try: | try: | |||
query_update.update( | query_update.update( | |||
values, synchronize_session="fetch") | values, synchronize_session="fetch") | |||
except NoResultFound: | except NoResultFound: | |||
raise exception.ResourceNotFound( | raise exception.ResourceNotFound( | |||
resource='ExtArq', | resource='ExtArq', | |||
msg='with uuid=%s' % uuid) | msg='with uuid=%s' % uuid) | |||
skipping to change at line 952 | skipping to change at line 958 | |||
filter(models.Reservation.uuid.in_(reservation_ids)). \ | filter(models.Reservation.uuid.in_(reservation_ids)). \ | |||
all() | all() | |||
return {r.resource for r in reservations} | return {r.resource for r in reservations} | |||
def _quota_reservations(self, session, context, reservations): | def _quota_reservations(self, session, context, reservations): | |||
"""Return the relevant reservations.""" | """Return the relevant reservations.""" | |||
# Get the listed reservations | # Get the listed reservations | |||
return model_query(context, models.Reservation). \ | return model_query(context, models.Reservation). \ | |||
filter(models.Reservation.uuid.in_(reservations)). \ | filter(models.Reservation.uuid.in_(reservations)). \ | |||
with_lockmode('update'). \ | with_for_update(). \ | |||
all() | all() | |||
def quota_reserve(self, context, resources, deltas, expire, | def quota_reserve(self, context, resources, deltas, expire, | |||
until_refresh, max_age, project_id=None, | until_refresh, max_age, project_id=None, | |||
is_allocated_reserve=False): | is_allocated_reserve=False): | |||
"""Create reservation record in DB according to params""" | """Create reservation record in DB according to params""" | |||
with _session_for_write() as session: | with _session_for_write() as session: | |||
if project_id is None: | if project_id is None: | |||
project_id = context.project_id | project_id = context.project_id | |||
usages = self._get_quota_usages(context, project_id, | usages = self._get_quota_usages(context, project_id, | |||
End of changes. 12 change blocks. | ||||
11 lines changed or deleted | 17 lines changed or added |