Skip to content

Commit 9b1d4ee

Browse files
Yi Hedjach7
authored andcommitted
add test case for binary support
1 parent f8deb30 commit 9b1d4ee

4 files changed

Lines changed: 38 additions & 7 deletions

File tree

src/lib/greenboot.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ fn run_scripts(name: &str, path: &str, disabled_scripts: Option<&[String]>) -> S
130130
};
131131

132132
for entry in entries.flatten() {
133-
// Process script name
133+
// Process script/binary name
134134
let file_name = match entry.file_name().and_then(|n| n.to_str()) {
135135
Some(name) => name,
136136
None => continue,
137137
};
138138

139-
// Check if script should be skipped
139+
// Check if script/binary should be skipped
140140
if let Some(disabled) = disabled_scripts {
141141
if disabled.contains(&file_name.to_string()) {
142142
log::info!("Skipping disabled script: {}", file_name);
@@ -147,7 +147,7 @@ fn run_scripts(name: &str, path: &str, disabled_scripts: Option<&[String]>) -> S
147147

148148
log::info!("running {} check {}", name, entry.to_string_lossy());
149149

150-
// Sort between script and binary since they require different commands to execute properly.
150+
// Sort between scripts and binaries since they require different commands to execute properly.
151151
let output = if entry.extension().and_then(|ext| ext.to_str()) == Some("sh") {
152152
Command::new("bash").arg("-C").arg(&entry).output()
153153
} else {
@@ -233,8 +233,8 @@ mod test {
233233
setup_folder_structure(false)
234234
.context("Test setup failed")
235235
.unwrap();
236-
// Causes errors if these are no removed since they cause an excess amount
237-
// of failure.
236+
// Causes errors if these are not removed since they cause an excess amount
237+
// of failures.
238238
let required_path = format!("{}/check/required.d", GREENBOOT_INSTALL_PATHS[1]);
239239
let _ = std::fs::remove_file(format!("{}/01_failing_binary", required_path));
240240
let _ = std::fs::remove_file(format!("{}/02_failing_binary", required_path));

tests/greenboot-bootc-anaconda-iso.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ fi
150150
greenprint "Building greenboot packages"
151151
pushd .. && \
152152
make rpm
153-
cp rpmbuild/RPMS/x86_64/*.rpm tests/ && popd
153+
cp rpmbuild/RPMS/x86_64/*.rpm tests/
154+
cp testing_assets/passing_binary tests/
155+
cp testing_assets/failing_binary tests/ && popd
154156

155157
###########################################################
156158
##
@@ -169,6 +171,8 @@ RUN dnf install -y \
169171
systemctl enable greenboot-healthcheck.service greenboot-rollback.service greenboot-success.target
170172
RUN sed -i "s/GREENBOOT_MAX_BOOT_ATTEMPTS=3/GREENBOOT_MAX_BOOT_ATTEMPTS=5/g" /etc/greenboot/greenboot.conf
171173
RUN sed -i 's#DISABLED_HEALTHCHECKS=()#DISABLED_HEALTHCHECKS=("01_repository_dns_check.sh" "not_exit.sh")#g' /etc/greenboot/greenboot.conf
174+
COPY passing_binary /etc/greenboot/check/required.d/
175+
COPY failing_binary /etc/greenboot/check/wanted.d/
172176
# Clean up by removing the local RPMs if desired
173177
RUN rm -f /tmp/greenboot-*.rpm
174178
EOF

tests/greenboot-bootc-qcow2.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ fi
150150
greenprint "Building greenboot packages"
151151
pushd .. && \
152152
make rpm
153-
cp rpmbuild/RPMS/x86_64/*.rpm tests/ && popd
153+
cp rpmbuild/RPMS/x86_64/*.rpm tests/
154+
cp testing_assets/passing_binary tests/
155+
cp testing_assets/failing_binary tests/ && popd
154156

155157
###########################################################
156158
##
@@ -169,6 +171,8 @@ RUN dnf install -y \
169171
systemctl enable greenboot-healthcheck.service greenboot-rollback.service greenboot-success.target
170172
RUN sed -i "s/GREENBOOT_MAX_BOOT_ATTEMPTS=3/GREENBOOT_MAX_BOOT_ATTEMPTS=5/g" /etc/greenboot/greenboot.conf
171173
RUN sed -i 's#DISABLED_HEALTHCHECKS=()#DISABLED_HEALTHCHECKS=("01_repository_dns_check.sh" "not_exit.sh")#g' /etc/greenboot/greenboot.conf
174+
COPY passing_binary /etc/greenboot/check/required.d/
175+
COPY failing_binary /etc/greenboot/check/wanted.d/
172176
# Clean up by removing the local RPMs if desired
173177
RUN rm -f /tmp/greenboot-*.rpm
174178
EOF

tests/greenboot-bootc.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,29 @@
164164
set_fact:
165165
failed_counter: "{{ failed_counter | int + 1 }}"
166166

167+
# case: check binary file support
168+
- name: check binary file support
169+
block:
170+
- name: binary file check result should be found here
171+
shell: journalctl -b -0 -u greenboot -u greenboot-healthcheck
172+
become: yes
173+
register: result_binary
174+
175+
- assert:
176+
that:
177+
- "'required script /etc/greenboot/check/required.d/passing_binary success!' in result_binary.stdout"
178+
- "'wanted script /etc/greenboot/check/wanted.d/failing_binary failed!' in result_binary.stdout"
179+
fail_msg: "Binary file check log not found"
180+
success_msg: "Found binary file check log"
181+
182+
always:
183+
- set_fact:
184+
total_counter: "{{ total_counter | int + 1 }}"
185+
rescue:
186+
- name: failed count + 1
187+
set_fact:
188+
failed_counter: "{{ failed_counter | int + 1 }}"
189+
167190
# case: check boot times
168191
- name: check boot times
169192
block:

0 commit comments

Comments
 (0)