Skip to content

Commit aa7a3ce

Browse files
authored
Merge pull request #77 from arortiz-rh/red-green-ci-tests
Add test cases for red.d and green.d within CI
2 parents 91141b0 + 2d293e7 commit aa7a3ce

5 files changed

Lines changed: 154 additions & 2 deletions

File tree

tests/greenboot-bootc-anaconda-iso.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ greenprint "Building greenboot packages"
152152
pushd .. && \
153153
make rpm
154154
cp rpmbuild/RPMS/x86_64/*.rpm tests/
155+
cp testing_assets/passing_script.sh tests/
155156
cp testing_assets/passing_binary tests/
157+
cp testing_assets/failing_script.sh tests/
156158
cp testing_assets/failing_binary tests/ && popd
157159

158160
###########################################################
@@ -172,6 +174,17 @@ RUN dnf install -y \
172174
systemctl enable greenboot-healthcheck.service
173175
RUN sed -i "s/GREENBOOT_MAX_BOOT_ATTEMPTS=3/GREENBOOT_MAX_BOOT_ATTEMPTS=5/g" /etc/greenboot/greenboot.conf
174176
RUN sed -i 's#DISABLED_HEALTHCHECKS=()#DISABLED_HEALTHCHECKS=("01_repository_dns_check.sh" "not_exit.sh")#g' /etc/greenboot/greenboot.conf
177+
178+
COPY passing_script.sh /etc/greenboot/green.d
179+
COPY passing_binary /etc/greenboot/green.d/
180+
COPY failing_binary /etc/greenboot/green.d
181+
COPY failing_script.sh /etc/greenboot/green.d
182+
183+
COPY passing_script.sh /etc/greenboot/red.d
184+
COPY passing_binary /etc/greenboot/red.d/
185+
COPY failing_binary /etc/greenboot/red.d
186+
COPY failing_script.sh /etc/greenboot/red.d
187+
175188
COPY passing_binary /etc/greenboot/check/required.d/
176189
COPY failing_binary /etc/greenboot/check/wanted.d/
177190
# Clean up by removing the local RPMs if desired

tests/greenboot-bootc-qcow2.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ greenprint "Building greenboot packages"
152152
pushd .. && \
153153
make rpm
154154
cp rpmbuild/RPMS/x86_64/*.rpm tests/
155+
cp testing_assets/passing_script.sh tests/
155156
cp testing_assets/passing_binary tests/
157+
cp testing_assets/failing_script.sh tests/
156158
cp testing_assets/failing_binary tests/ && popd
157159

158160
###########################################################
@@ -172,6 +174,17 @@ RUN dnf install -y \
172174
systemctl enable greenboot-healthcheck.service
173175
RUN sed -i "s/GREENBOOT_MAX_BOOT_ATTEMPTS=3/GREENBOOT_MAX_BOOT_ATTEMPTS=5/g" /etc/greenboot/greenboot.conf
174176
RUN sed -i 's#DISABLED_HEALTHCHECKS=()#DISABLED_HEALTHCHECKS=("01_repository_dns_check.sh" "not_exit.sh")#g' /etc/greenboot/greenboot.conf
177+
178+
COPY passing_script.sh /etc/greenboot/green.d
179+
COPY passing_binary /etc/greenboot/green.d/
180+
COPY failing_binary /etc/greenboot/green.d
181+
COPY failing_script.sh /etc/greenboot/green.d
182+
183+
COPY passing_script.sh /etc/greenboot/red.d
184+
COPY passing_binary /etc/greenboot/red.d/
185+
COPY failing_binary /etc/greenboot/red.d
186+
COPY failing_script.sh /etc/greenboot/red.d
187+
175188
COPY passing_binary /etc/greenboot/check/required.d/
176189
COPY failing_binary /etc/greenboot/check/wanted.d/
177190
# Clean up by removing the local RPMs if desired

tests/greenboot-bootc.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,56 @@
187187
set_fact:
188188
failed_counter: "{{ failed_counter | int + 1 }}"
189189

190+
# case: check for red.d scripts and binaries running, both passing and failing
191+
- name: check red script execution after failed boot
192+
block:
193+
- name: red script execution logs should be found here after failed boot
194+
shell: journalctl -u greenboot-healthcheck.service
195+
become: yes
196+
register: result_red_scripts
197+
198+
- assert:
199+
that:
200+
- "'red script /etc/greenboot/red.d/passing_binary success!' in result_red_scripts.stdout"
201+
- "'red script /etc/greenboot/red.d/failing_binary failed!' in result_red_scripts.stdout"
202+
- "'red script /etc/greenboot/red.d/passing_script.sh success!' in result_red_scripts.stdout"
203+
- "'red script /etc/greenboot/red.d/failing_script.sh failed!' in result_red_scripts.stdout"
204+
fail_msg: "Red script execution logs not found"
205+
success_msg: "Found red script execution logs"
206+
207+
always:
208+
- set_fact:
209+
total_counter: "{{ total_counter | int + 1 }}"
210+
rescue:
211+
- name: failed count + 1
212+
set_fact:
213+
failed_counter: "{{ failed_counter | int + 1 }}"
214+
215+
# case: check for green.d scripts and binaries running, both passing and failing
216+
- name: check green script execution after successful boot
217+
block:
218+
- name: green script execution logs should be found here after successful boot
219+
shell: journalctl -b -0 -u greenboot -u greenboot-healthcheck
220+
become: yes
221+
register: result_green_scripts
222+
223+
- assert:
224+
that:
225+
- "'green script /etc/greenboot/green.d/passing_binary success!' in result_green_scripts.stdout"
226+
- "'green script /etc/greenboot/green.d/failing_binary failed!' in result_green_scripts.stdout"
227+
- "'green script /etc/greenboot/green.d/passing_script.sh success!' in result_green_scripts.stdout"
228+
- "'green script /etc/greenboot/green.d/failing_script.sh failed!' in result_green_scripts.stdout"
229+
fail_msg: "Green script and binary execution logs not found"
230+
success_msg: "Found green script and binary execution logs"
231+
232+
always:
233+
- set_fact:
234+
total_counter: "{{ total_counter | int + 1 }}"
235+
rescue:
236+
- name: failed count + 1
237+
set_fact:
238+
failed_counter: "{{ failed_counter | int + 1 }}"
239+
190240
# case: check boot times
191241
- name: check boot times
192242
block:

tests/greenboot-ostree.sh

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,38 @@ for _ in $(seq 0 30); do
404404
sleep 10
405405
done
406406

407-
greenprint "🛃 Copying binary check files to edge vm"
407+
greenprint "🛃 Copying binary and script files to edge vm"
408+
409+
# Create red.d and green.d directories if they don't exist
410+
ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" "${SSH_USER}@${GUEST_ADDRESS}" "sudo mkdir -p /etc/greenboot/red.d /etc/greenboot/green.d"
411+
412+
# Copy all files to temp directory first (all at once)
408413
scp "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" ../testing_assets/failing_binary "${SSH_USER}@${GUEST_ADDRESS}":/tmp/ && \
409-
ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" "${SSH_USER}@${GUEST_ADDRESS}" "sudo mv /tmp/failing_binary /etc/greenboot/check/wanted.d/"
410414
scp "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" ../testing_assets/passing_binary "${SSH_USER}@${GUEST_ADDRESS}":/tmp/ && \
415+
scp "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" ../testing_assets/failing_script.sh "${SSH_USER}@${GUEST_ADDRESS}":/tmp/ && \
416+
scp "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" ../testing_assets/passing_script.sh "${SSH_USER}@${GUEST_ADDRESS}":/tmp/
417+
418+
# Setup all directories using cp (copy) instead of mv (move) so files stay in /tmp/
419+
greenprint "🛃 Setting up red.d directory files"
420+
ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" "${SSH_USER}@${GUEST_ADDRESS}" "sudo cp /tmp/failing_binary /etc/greenboot/red.d/"
421+
ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" "${SSH_USER}@${GUEST_ADDRESS}" "sudo cp /tmp/passing_binary /etc/greenboot/red.d/"
422+
ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" "${SSH_USER}@${GUEST_ADDRESS}" "sudo cp /tmp/failing_script.sh /etc/greenboot/red.d/"
423+
ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" "${SSH_USER}@${GUEST_ADDRESS}" "sudo cp /tmp/passing_script.sh /etc/greenboot/red.d/"
424+
425+
greenprint "🛃 Setting up green.d directory files"
426+
ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" "${SSH_USER}@${GUEST_ADDRESS}" "sudo cp /tmp/failing_binary /etc/greenboot/green.d/"
427+
ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" "${SSH_USER}@${GUEST_ADDRESS}" "sudo cp /tmp/passing_binary /etc/greenboot/green.d/"
428+
ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" "${SSH_USER}@${GUEST_ADDRESS}" "sudo cp /tmp/failing_script.sh /etc/greenboot/green.d/"
429+
ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" "${SSH_USER}@${GUEST_ADDRESS}" "sudo cp /tmp/passing_script.sh /etc/greenboot/green.d/"
430+
431+
# Setup original check directories (keeping existing behavior)
432+
greenprint "🛃 Copying binary check files to edge vm"
433+
ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" "${SSH_USER}@${GUEST_ADDRESS}" "sudo mv /tmp/failing_binary /etc/greenboot/check/wanted.d/"
411434
ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" "${SSH_USER}@${GUEST_ADDRESS}" "sudo mv /tmp/passing_binary /etc/greenboot/check/required.d/"
412435

436+
# Clean up remaining temp files
437+
ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" "${SSH_USER}@${GUEST_ADDRESS}" "sudo rm -f /tmp/failing_script.sh /tmp/passing_script.sh"
438+
413439
# Add instance IP address into /etc/ansible/hosts
414440
tee "${TEMPDIR}"/inventory > /dev/null << EOF
415441
[ostree_guest]

tests/greenboot-ostree.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,56 @@
235235
set_fact:
236236
failed_counter: "{{ failed_counter | int + 1 }}"
237237

238+
# case: check for red.d scripts and binaries running, both passing and failing
239+
- name: check red script execution after failed boot
240+
block:
241+
- name: red script execution logs should be found here after failed boot
242+
shell: journalctl -u greenboot-healthcheck.service
243+
become: yes
244+
register: result_red_scripts
245+
246+
- assert:
247+
that:
248+
- "'red script /etc/greenboot/red.d/passing_binary success!' in result_red_scripts.stdout"
249+
- "'red script /etc/greenboot/red.d/failing_binary failed!' in result_red_scripts.stdout"
250+
- "'red script /etc/greenboot/red.d/passing_script.sh success!' in result_red_scripts.stdout"
251+
- "'red script /etc/greenboot/red.d/failing_script.sh failed!' in result_red_scripts.stdout"
252+
fail_msg: "Red script execution logs not found"
253+
success_msg: "Found red script execution logs"
254+
255+
always:
256+
- set_fact:
257+
total_counter: "{{ total_counter | int + 1 }}"
258+
rescue:
259+
- name: failed count + 1
260+
set_fact:
261+
failed_counter: "{{ failed_counter | int + 1 }}"
262+
263+
# case: check for green.d scripts and binaries running, both passing and failing
264+
- name: check green script execution after successful boot
265+
block:
266+
- name: green script execution logs should be found here after successful boot
267+
shell: journalctl -b -0 -u greenboot -u greenboot-healthcheck
268+
become: yes
269+
register: result_green_scripts
270+
271+
- assert:
272+
that:
273+
- "'green script /etc/greenboot/green.d/passing_binary success!' in result_green_scripts.stdout"
274+
- "'green script /etc/greenboot/green.d/failing_binary failed!' in result_green_scripts.stdout"
275+
- "'green script /etc/greenboot/green.d/passing_script.sh success!' in result_green_scripts.stdout"
276+
- "'green script /etc/greenboot/green.d/failing_script.sh failed!' in result_green_scripts.stdout"
277+
fail_msg: "Green script and binary execution logs not found"
278+
success_msg: "Found green script and binary execution logs"
279+
280+
always:
281+
- set_fact:
282+
total_counter: "{{ total_counter | int + 1 }}"
283+
rescue:
284+
- name: failed count + 1
285+
set_fact:
286+
failed_counter: "{{ failed_counter | int + 1 }}"
287+
238288
# case: check boot times
239289
- name: check boot times
240290
block:

0 commit comments

Comments
 (0)