def process_deployment(self, base):
"""
Check for deployments, download them, verify checksum and trigger
RAUC install operation.
"""
if self.action_id is not None:
self.logger.info('Deployment is already in progress')
return
# retrieve action id and resource parameter from URL
deployment = base['_links']['deploymentBase']['href']
match = re.search('/deploymentBase/(.+)\?c=(.+)$', deployment)
action_id, resource = match.groups()
self.logger.info('Deployment found for this target')
# fetch deployment information
deploy_info = await self.ddi.deploymentBase[action_id](resource)
try:
chunk = deploy_info['deployment']['chunks'][0]
except IndexError:
# send negative feedback to HawkBit
status_execution = DeploymentStatusExecution.closed
status_result = DeploymentStatusResult.failure
msg = 'Deployment without chunks found. Ignoring'
await self.ddi.deploymentBase[action_id].feedback(
status_execution, status_result, [msg])
raise APIError(msg)
try:
artifact = chunk['artifacts'][0]
except IndexError:
# send negative feedback to HawkBit
status_execution = DeploymentStatusExecution.closed
status_result = DeploymentStatusResult.failure
msg = 'Deployment without artifacts found. Ignoring'
await self.ddi.deploymentBase[action_id].feedback(
status_execution, status_result, [msg])
raise APIError(msg)
# download artifact, check md5 and report feedback
download_url = artifact['_links']['download-http']['href']
md5_hash = artifact['hashes']['md5']
self.logger.info('Starting bundle download')
await self.download_artifact(action_id, download_url, md5_hash)
# download successful, start install
self.logger.info('Starting installation')
try:
self.action_id = action_id
# do not interrupt install call
await asyncio.shield(self.install())
except GLib.Error as e:
# send negative feedback to HawkBit
status_execution = DeploymentStatusExecution.closed
status_result = DeploymentStatusResult.failure
await self.ddi.deploymentBase[action_id].feedback(
status_execution, status_result, [str(e)])
raise APIError(str(e))
评论列表
文章目录