Skip to content

Commit e6d4457

Browse files
committed
fix: address CI test failures and improve error handling
Address review comments from mmartinv regarding CI test failures: 1. **Fix Copr package installation issue**: - CI tests were installing greenboot from official repos instead of Copr because version numbers were identical - Changed 'dnf install' to 'dnf reinstall || dnf install' to force installation of PR build from Copr even when version matches - This ensures tests run against the actual PR code changes 2. **Improve error handling in check_previous_rollback()**: - Verify stderr contains expected "No journal boot entry found" message before treating journalctl failure as "no previous boot" - Return proper error for unexpected journalctl failures - Check for both empty output and "-- No entries --" message 3. **Simplify first boot test**: - Use 'journalctl -b 1' to get first boot logs instead of complex boot ID lookup (simpler and more reliable per journalctl man page) - Remove unnecessary failed_when check - Separate combined assertion into two distinct checks for clarity Signed-off-by: Sarita Mahajan <sarmahaj@redhat.com>
1 parent 89c3968 commit e6d4457

5 files changed

Lines changed: 32 additions & 24 deletions

File tree

src/main.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,25 @@ fn check_previous_rollback() -> Result<bool> {
177177
.context("Failed to execute journalctl command to check rollback status")?;
178178

179179
if !output.status.success() {
180-
log::info!(
181-
"No previous boot journal available (expected on first boot or systems with non-persistent journal). Skipping rollback check."
180+
let stderr = String::from_utf8_lossy(&output.stderr);
181+
// Check if failure is due to missing previous boot (expected on first boot)
182+
if stderr.contains("No journal boot entry found for the specified boot") {
183+
log::info!(
184+
"No previous boot journal available (expected on first boot or systems with non-persistent journal). Skipping rollback check."
185+
);
186+
return Ok(false);
187+
}
188+
// For other failures, return an error
189+
bail!(
190+
"journalctl command failed with status: {}. stderr: {}",
191+
output.status,
192+
stderr.trim()
182193
);
183-
return Ok(false);
184194
}
185195

186196
let journal_output = String::from_utf8_lossy(&output.stdout);
187197

188-
if journal_output.trim().is_empty() {
198+
if journal_output.trim().is_empty() || journal_output.contains("-- No entries --") {
189199
log::debug!("No rollback service logs found in previous boot");
190200
return Ok(false);
191201
}

tests/greenboot-bootc-anaconda-iso.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ tee -a Containerfile >> /dev/null << EOF
229229
RUN (dnf install -y 'dnf5-command(copr)' || dnf install -y 'dnf-command(copr)') && \
230230
dnf copr enable -y packit/fedora-iot-greenboot-rs-${PR_NUMBER} ${COPR_CHROOT} && \
231231
dnf clean metadata && \
232-
dnf install -y greenboot greenboot-default-health-checks && \
232+
(dnf reinstall -y greenboot greenboot-default-health-checks || dnf install -y greenboot greenboot-default-health-checks) && \
233233
systemctl enable greenboot-healthcheck.service
234234
RUN sed -i "s/GREENBOOT_MAX_BOOT_ATTEMPTS=3/GREENBOOT_MAX_BOOT_ATTEMPTS=5/g" /etc/greenboot/greenboot.conf
235235
RUN sed -i 's#DISABLED_HEALTHCHECKS=()#DISABLED_HEALTHCHECKS=("01_repository_dns_check.sh" "not_exit.sh")#g' /etc/greenboot/greenboot.conf

tests/greenboot-bootc-qcow2.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ tee -a Containerfile >> /dev/null << EOF
229229
RUN (dnf install -y 'dnf5-command(copr)' || dnf install -y 'dnf-command(copr)') && \
230230
dnf copr enable -y packit/fedora-iot-greenboot-rs-${PR_NUMBER} ${COPR_CHROOT} && \
231231
dnf clean metadata && \
232-
dnf install -y greenboot greenboot-default-health-checks && \
232+
(dnf reinstall -y greenboot greenboot-default-health-checks || dnf install -y greenboot greenboot-default-health-checks) && \
233233
systemctl enable greenboot-healthcheck.service
234234
RUN sed -i "s/GREENBOOT_MAX_BOOT_ATTEMPTS=3/GREENBOOT_MAX_BOOT_ATTEMPTS=5/g" /etc/greenboot/greenboot.conf
235235
RUN sed -i 's#DISABLED_HEALTHCHECKS=()#DISABLED_HEALTHCHECKS=("01_repository_dns_check.sh" "not_exit.sh")#g' /etc/greenboot/greenboot.conf

tests/greenboot-bootc.yaml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,23 +167,22 @@
167167
# case: check proper first boot handling
168168
- name: check greenboot-healthcheck handles first boot correctly
169169
block:
170-
- name: get earliest boot ID
171-
shell: journalctl --list-boots --no-pager | awk '$2 ~ /^[0-9a-f]{32}$/{print $2; exit}'
172-
become: yes
173-
register: first_boot_id
174-
failed_when: first_boot_id.stdout | length == 0
175-
176170
- name: get greenboot-healthcheck log from first boot
177-
command: "journalctl -b {{ first_boot_id.stdout }} -u greenboot-healthcheck.service --no-pager"
171+
command: "journalctl -b 1 -u greenboot-healthcheck.service --no-pager"
178172
become: yes
179173
register: result_healthcheck_first_boot
180174

181175
- assert:
182176
that:
183177
- "'No previous boot journal available' in result_healthcheck_first_boot.stdout"
178+
fail_msg: "Expected first boot message not found"
179+
success_msg: "First boot correctly detected with appropriate message"
180+
181+
- assert:
182+
that:
184183
- "'FALLBACK BOOT DETECTED!' not in result_healthcheck_first_boot.stdout"
185-
fail_msg: "Expected first boot message not found or false rollback detection on first boot"
186-
success_msg: "First boot correctly detected with appropriate message and no false rollback detection"
184+
fail_msg: "False rollback detection on first boot"
185+
success_msg: "No false rollback detection on first boot"
187186

188187
always:
189188
- set_fact:

tests/greenboot-ostree.yaml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,22 @@
7474
# case: check proper first boot handling
7575
- name: check greenboot-healthcheck handles first boot correctly
7676
block:
77-
- name: get earliest boot ID
78-
shell: journalctl --list-boots --no-pager | awk '$2 ~ /^[0-9a-f]{32}$/{print $2; exit}'
79-
become: yes
80-
register: first_boot_id
81-
failed_when: first_boot_id.stdout | length == 0
82-
8377
- name: get greenboot-healthcheck log from first boot
84-
command: "journalctl -b {{ first_boot_id.stdout }} -u greenboot-healthcheck.service --no-pager"
78+
command: "journalctl -b 1 -u greenboot-healthcheck.service --no-pager"
8579
become: yes
8680
register: result_healthcheck_first_boot
8781

8882
- assert:
8983
that:
9084
- "'No previous boot journal available' in result_healthcheck_first_boot.stdout"
85+
fail_msg: "Expected first boot message not found"
86+
success_msg: "First boot correctly detected with appropriate message"
87+
88+
- assert:
89+
that:
9190
- "'FALLBACK BOOT DETECTED!' not in result_healthcheck_first_boot.stdout"
92-
fail_msg: "Expected first boot message not found or false rollback detection on first boot"
93-
success_msg: "First boot correctly detected with appropriate message and no false rollback detection"
91+
fail_msg: "False rollback detection on first boot"
92+
success_msg: "No false rollback detection on first boot"
9493

9594
always:
9695
- set_fact:

0 commit comments

Comments
 (0)