Merge "Clear alarm after last device image deletion"

This commit is contained in:
Zuul 2020-07-17 14:51:16 +00:00 committed by Gerrit Code Review
commit b70e6eeea9
3 changed files with 17 additions and 5 deletions

View File

@ -265,17 +265,19 @@ class DeviceImageController(rest.RestController):
device_image = objects.device_image.get_by_uuid(
pecan.request.context, deviceimage_uuid)
# Check if the image has been written to any of the devices
# Check if the image has been written or is being written to any of the devices
if pecan.request.dbapi.device_image_state_get_all(
image_id=device_image.id,
status=dconstants.DEVICE_IMAGE_UPDATE_COMPLETED):
status=[dconstants.DEVICE_IMAGE_UPDATE_COMPLETED,
dconstants.DEVICE_IMAGE_UPDATE_IN_PROGRESS]):
raise wsme.exc.ClientSideError(_(
"Delete failed: device image has already been written to devices"))
"Delete failed: device image is being written to or has "
"already been written to devices"))
pecan.request.dbapi.deviceimage_destroy(deviceimage_uuid)
filename = cutils.format_image_filename(device_image)
pecan.request.rpcapi.delete_bitstream_file(pecan.request.context,
filename)
pecan.request.dbapi.deviceimage_destroy(deviceimage_uuid)
@cutils.synchronized(LOCK_NAME)
@wsme_pecan.wsexpose(DeviceImage, types.uuid, wtypes.text, body=types.apidict)

View File

@ -11727,6 +11727,13 @@ class ConductorManager(service.PeriodicService):
os.remove(image_file_path)
except OSError:
LOG.exception("Failed to delete bitstream file %s" % image_file_path)
# If no device image is uploaded, clear the in-progress alarm.
images = self.dbapi.deviceimages_get_all()
if not images:
system_uuid = self.dbapi.isystem_get_one().uuid
entity_instance_id = "%s=%s" % (fm_constants.FM_ENTITY_TYPE_SYSTEM, system_uuid)
self.fm_api.clear_fault(fm_constants.FM_ALARM_ID_DEVICE_IMAGE_UPDATE_IN_PROGRESS,
entity_instance_id)
def apply_device_image(self, context, host_uuid):
"""Apply device image"""

View File

@ -8790,5 +8790,8 @@ class Connection(api.Connection):
if image_id:
query = query.filter_by(image_id=image_id)
if status:
query = query.filter_by(status=status)
if isinstance(status, list):
query = query.filter(models.DeviceImageState.status.in_(status))
else:
query = query.filter_by(status=status)
return query.all()