cloud/bmaas/bmdb: correctly handle installation report
Previously we ignored the result of an installation report.
The bmdb does now store the result and correctly triggers
a recovery flow of the installation fails.
Change-Id: Ie8445cf9178ba84c6362b61ef8fa47208ab690be
Reviewed-on: https://review.monogon.dev/c/monogon/+/1865
Reviewed-by: Serge Bazanski <serge@monogon.tech>
Tested-by: Jenkins CI
diff --git a/cloud/bmaas/bmdb/model/migrations/1687875953_add_installation_report.down.sql b/cloud/bmaas/bmdb/model/migrations/1687875953_add_installation_report.down.sql
new file mode 100644
index 0000000..6c2cb40
--- /dev/null
+++ b/cloud/bmaas/bmdb/model/migrations/1687875953_add_installation_report.down.sql
@@ -0,0 +1,5 @@
+ALTER TABLE machine_os_installation_report
+DROP COLUMN os_installation_result,
+DROP COLUMN os_installation_report_raw;
+
+DROP TYPE machine_os_installation_result;
diff --git a/cloud/bmaas/bmdb/model/migrations/1687875953_add_installation_report.up.sql b/cloud/bmaas/bmdb/model/migrations/1687875953_add_installation_report.up.sql
new file mode 100644
index 0000000..4f25589
--- /dev/null
+++ b/cloud/bmaas/bmdb/model/migrations/1687875953_add_installation_report.up.sql
@@ -0,0 +1,10 @@
+CREATE TYPE machine_os_installation_result AS ENUM (
+ 'Success',
+ 'Error'
+ );
+
+-- Add column for storing the serialized cloud.bmaas.server.api.OSInstallationReport
+-- also add a column to display if the installation was successful or not.
+ALTER TABLE machine_os_installation_report
+ ADD COLUMN os_installation_result machine_os_installation_result NOT NULL,
+ ADD COLUMN os_installation_report_raw BYTEA NOT NULL;
\ No newline at end of file
diff --git a/cloud/bmaas/bmdb/model/queries_tags.sql b/cloud/bmaas/bmdb/model/queries_tags.sql
index ddb6f19..58e2d96 100644
--- a/cloud/bmaas/bmdb/model/queries_tags.sql
+++ b/cloud/bmaas/bmdb/model/queries_tags.sql
@@ -45,11 +45,13 @@
-- name: MachineSetOSInstallationReport :exec
INSERT INTO machine_os_installation_report (
- machine_id, generation
+ machine_id, generation, os_installation_result, os_installation_report_raw
) VALUES (
- $1, $2
+ $1, $2, $3, $4
) ON CONFLICT (machine_id) DO UPDATE SET
- generation = $2
+ generation = $2,
+ os_installation_result = $3,
+ os_installation_report_raw = $4
;
diff --git a/cloud/bmaas/bmdb/model/queries_workflows.sql b/cloud/bmaas/bmdb/model/queries_workflows.sql
index 854c15d..8400d4e 100644
--- a/cloud/bmaas/bmdb/model/queries_workflows.sql
+++ b/cloud/bmaas/bmdb/model/queries_workflows.sql
@@ -45,7 +45,7 @@
INNER JOIN machine_agent_started ON machines.machine_id = machine_agent_started.machine_id
LEFT JOIN machine_agent_heartbeat ON machines.machine_id = machine_agent_heartbeat.machine_id
LEFT JOIN machine_os_installation_request ON machines.machine_id = machine_os_installation_request.machine_id
-LEFT JOIN machine_os_installation_report ON machines.machine_id = machine_os_installation_report.machine_id
+LEFT JOIN machine_os_installation_report ON machines.machine_id = machine_os_installation_report.machine_id AND machine_os_installation_report.os_installation_result = 'Success'
WHERE
-- Do not recover machines that have a fulfilled OS installation request.
(