blueprints: always set metadata when attempting to apply

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-08-23 18:48:01 +02:00
parent e70fcd1a6f
commit ca2fce8be2

View file

@ -125,8 +125,6 @@ def check_blueprint_v1_file(blueprint: BlueprintFile):
) )
instance.save() instance.save()
if instance.last_applied_hash != blueprint.hash: if instance.last_applied_hash != blueprint.hash:
instance.metadata = asdict(blueprint.meta) if blueprint.meta else {}
instance.save()
apply_blueprint.delay(instance.pk.hex) apply_blueprint.delay(instance.pk.hex)
@ -160,7 +158,6 @@ def apply_blueprint(self: MonitoredTask, instance_pk: str):
instance.status = BlueprintInstanceStatus.SUCCESSFUL instance.status = BlueprintInstanceStatus.SUCCESSFUL
instance.last_applied_hash = file_hash instance.last_applied_hash = file_hash
instance.last_applied = now() instance.last_applied = now()
instance.save()
self.set_status(TaskResult(TaskResultStatus.SUCCESSFUL)) self.set_status(TaskResult(TaskResultStatus.SUCCESSFUL))
except ( except (
DatabaseError, DatabaseError,
@ -170,5 +167,7 @@ def apply_blueprint(self: MonitoredTask, instance_pk: str):
BlueprintRetrievalFailed, BlueprintRetrievalFailed,
) as exc: ) as exc:
instance.status = BlueprintInstanceStatus.ERROR instance.status = BlueprintInstanceStatus.ERROR
instance.save()
self.set_status(TaskResult(TaskResultStatus.ERROR).with_error(exc)) self.set_status(TaskResult(TaskResultStatus.ERROR).with_error(exc))
finally:
instance.metadata = asdict(importer.blueprint.metadata)
instance.save()