1
0
mirror of https://github.com/coreos/ignition.git synced 2026-02-06 09:47:17 +01:00
Commit Graph

251 Commits

Author SHA1 Message Date
yasminvalim
33caaa0d9b tests/filesystem: Wrap inner loop code to trigger defer
Wrap the inner loop code in an anonymous function to make sure that
defer calls are triggered for each iteration of the loop and join all
errors as needed.

Diff best viewed with whitespace changes hidden.

Fixes lint:
```
Error return value of `writer.Flush` is not checked (errcheck)
```
2025-08-07 12:37:43 +02:00
yasminvalim
848acd01ef tests/filesystem: Use named return value 2025-08-07 12:37:43 +02:00
yasminvalim
2c15a7331c tests/filesystem: Join cleanup errors
Fixes lints:
```
Error return value of `out.Close` is not checked (errcheck)
Error return value of `os.RemoveAll` is not checked (errcheck)
Error return value of `writer.Flush` is not checked (errcheck)
```

It's fine to take into account close errors here as those are unlikely
and in this case those are in tests, thus not a potential subtle change
in behavior.

We also setup the defer'ed close earlier, as soon as the file is opened.
2025-08-07 12:37:43 +02:00
yasminvalim
1ae3bc35d5 tests/blackbox_test: Log temp dir removal error
Fixes lint:
```
tests/blackbox_test.go:136:20: Error return value of `os.RemoveAll` is not checked (errcheck)
tests/blackbox_test.go:151:20: Error return value of `os.RemoveAll` is not checked (errcheck)
```
2025-08-07 12:37:43 +02:00
yasminvalim
a44ea471e1 tests/*: Use fmt.Fprintf for file writes
This avoids unnecessary memory allocations and resolves staticcheck
linter warnings.

Fixes lint:
```
QF1012: Use fmt.Fprintf(...) instead of Write([]byte(fmt.Sprintf(...))) (staticcheck)
```
2025-08-07 12:37:43 +02:00
yasminvalim
7f618b9f24 tests/stubs/*: Ignore file close errors
Fixes lint:
```
tests/stubs/groupdel-stub/main.go:55:23: Error return value of `groupFile.Close` is not checked (errcheck)
tests/stubs/groupdel-stub/main.go:78:25: Error return value of `gshadowFile.Close` is not checked (errcheck)
tests/stubs/useradd-stub/main.go:98:24: Error return value of `passwdFile.Close` is not checked (errcheck)
tests/stubs/useradd-stub/main.go:112:23: Error return value of `groupFile.Close` is not checked (errcheck)
tests/stubs/useradd-stub/main.go:126:24: Error return value of `shadowFile.Close` is not checked (errcheck)
tests/stubs/useradd-stub/main.go:140:25: Error return value of `gshadowFile.Close` is not checked (errcheck)
tests/stubs/userdel-stub/main.go:59:24: Error return value of `passwdFile.Close` is not checked (errcheck)
tests/stubs/userdel-stub/main.go:82:23: Error return value of `groupFile.Close` is not checked (errcheck)
tests/stubs/userdel-stub/main.go:105:24: Error return value of `shadowFile.Close` is not checked (errcheck)
tests/stubs/userdel-stub/main.go:128:25: Error return value of `gshadowFile.Close` is not checked (errcheck)
tests/stubs/usermod-stub/main.go:113:24: Error return value of `passwdFile.Close` is not checked (errcheck)
```
2025-08-07 12:37:02 +02:00
yasminvalim
14ff81419e tests: Use strings.ReplaceAll instead of strings.Replace
Addresses the staticcheck lint error  by replacing all instances of
strings.Replace(s, old, new, -1) with the more explicit
strings.ReplaceAll(s, old, new).

Fixes lint:
```
QF1004: could use strings.ReplaceAll instead (staticcheck)
```
2025-08-05 20:14:55 +02:00
yasminvalim
e78e5bec4e Remove embedded field "Node" from selector
Fixes lint:
```
QF1008: could remove embedded field "Node" from selector (staticcheck)
```
2025-08-05 20:14:55 +02:00
yasminvalim
6af0c4a3b1 *: Error message should start uncapitalized 2025-08-05 20:14:55 +02:00
Timothée Ravier
6b22612155 Revert "fix: Handle unchecked error returns across the codebase and other linter issues"
Too many changes in a single commit. Will be split to make it easier to
review.

This reverts commit de452c404c.
2025-08-04 17:08:18 +02:00
yasminvalim
de452c404c fix: Handle unchecked error returns across the codebase and other linter issues
The linter found staticcheck and errorcheck issues.  Deferred statements now  use join  to combine any new error with an existing one, preventing error information from being lost. Other minor error checks, like for printing text  and flushing data have also been addressed.
2025-07-28 19:12:25 -03:00
Timothée Ravier
d20dddf0a2 Merge pull request #2083 from travier/main-docs-cex
Misc whitespace and docs fixes
2025-05-30 16:33:32 +02:00
Tiago Bueno
93ff3d3d9d Fix TMT workflow to respect use_built_from_src
closes #2084

Signed-off-by: Tiago Bueno <tiago.bueno@gmail.com>
2025-05-22 11:31:00 -03:00
Timothée Ravier
08fc5955e6 tests/positive/files/file: Fix misc whitespace 2025-05-21 18:03:59 +02:00
Tiago Bueno
e4b62af541 Add initial tmt test and CI workflow
This commit introduces a new TMT tests and a GitHub Actions workflow to
run it.

TMT (Test Management Tool) is a tool for managing and executing tests
in a structured and efficient manner. It allows users to define test
plans, organize test cases, and execute them in a consistent manner. TMT is
particularly useful for testing software projects, as it provides a
framework for managing the entire testing process, from planning to
execution and reporting.

The workflow is set up to run on every push to the main branch and on
pull requests, providing continuous integration for the project.

The core test added is designed to verify the basic functionality of
the application using TMT, ensuring that it can successfully execute a
simple test case.

The smoke plan is defined in the `tests/tmt/plans/smoke.fmf` file and
is configure to run all tests with smoke tag.

The `tests/tmt/plans/main.fmf` file is the main plan that includes
common configurations and settings for the plans. Currently, it prepare
the test environment.

The workflow is defined in the `.github/workflows/tmt-tests.yml` file
and includes steps to set up the environment, install dependencies, and
run tests. It is allowed to execute on pull requests, pushes to the
main branch, and on demand. By default all tests are executed, but it
can be executed on demand with a TMT plan filter. As part of the
workflow, TMT will be executed inside a container.

JIRA: https://issues.redhat.com/browse/COS-2284

Signed-off-by: Tiago Bueno <tiago.bueno@gmail.com>
2025-05-16 19:31:50 -03:00
Steven Presti
9371a25f85 tests/../files: ensure customfilepermissions behave the same as before 3.6.0
Ensure bugfix does not effect existing versions of configs using 'mode'. This
means 3.5.0 - 3.2.0 should continue to lose bits on permissions.
2025-05-05 13:21:34 -04:00
Steven Presti
029ca4c41b tests/types: add configMax version to expand blackbox testing flexability
Add a field which can limit the max version of config generated from blackbox
testing. If left blank blackbox tests will act as they always have. The new
field simply limits the registration of tests to that version number. This
is for the odd case where we want to ensure functionality does not exist when
using older versions of configs.
2025-05-05 13:21:34 -04:00
Timothée Ravier
f3556808e4 tests/validator: Use ToFileMode to convert mode to FileMode 2025-05-01 11:50:42 -04:00
Timothée Ravier
c22df2e82b tests: Add blackbox tests for setuid/gid/sticky bit
Support for setuid/setgid/sticky bit got added in [1] but we did not add
tests and it's unclear when support for it broke.

[1]: https://github.com/coreos/ignition/pull/1325
See: https://github.com/coreos/ignition/issues/2042
2025-05-01 11:50:42 -04:00
Timothée Ravier
82480543f4 Revert "tests: Add blackbox tests for setuid/gid/sticky bit"
This reverts commit e6c9774858.
2025-04-23 17:23:21 +02:00
Timothée Ravier
b4cabdf73d Revert "tests/validator: Use ToFileMode to convert mode to FileMode"
This reverts commit 6dee4e5595.
2025-04-23 17:23:20 +02:00
Timothée Ravier
6dee4e5595 tests/validator: Use ToFileMode to convert mode to FileMode 2025-04-23 16:58:55 +02:00
Timothée Ravier
e6c9774858 tests: Add blackbox tests for setuid/gid/sticky bit
Support for setuid/setgid/sticky bit got added in [1] but we did not add
tests and it's unclear when support for it broke.

[1]: https://github.com/coreos/ignition/pull/1325
See: https://github.com/coreos/ignition/issues/2042
2025-04-23 16:58:55 +02:00
Madhu Pillai
1f51620654 tests: update for new experimental spec 2024-10-14 15:33:52 +02:00
Steven Presti
62786092a2 tests/*/luks: add blackbox tests for luks
Fixes #1554
2024-06-13 16:37:48 -04:00
Steven Presti
334361df19 blackbox_test: add support for luks tests
Until now, the blackbox tests would not correctly cleanup after
running a test with a luks device. Now Luks devices can be tested
using blackbox test framework.
2024-06-13 16:37:48 -04:00
Jonathan Lebon
bc737f04b4 tests/blackbox: allow skipping critical logging check
In the context of the test added in the previous patch, it's normal for
the first `sgdisk --zap-all` invocation to fail. Add a knob to allow the
harness to tolerate this and make use of it in the new test.
2023-10-25 13:07:27 -04:00
Jonathan Lebon
5717a50047 stages/disks: retry sgdisk --zap-all invocation
When `wipeTable` is enabled, we run `sgdisk --zap-all`. But if the table
was corrupted in the first place, `sgdisk` will exit with code 2 which
then breaks boot.

As a workaround, Ignition used to retry the invocation but the context
around it was lost in #544 and #1149 and the retry was removed and
the error-checking was added.

So this patch effectively re-applies 94c98bcb ("sgdisk: retry zap-all
operation on failure"), but now with a comment and a test to make sure
we don't regress again.

Closes: https://github.com/coreos/fedora-coreos-tracker/issues/1596
2023-10-25 13:07:27 -04:00
Benjamin Gilbert
38fe499cb9 tests: port to xfsprogs 5.19+
mkfs.xfs >= 5.19.0 refuses to create filesystems smaller than 300 MB
unless --unsupported is specified or some environment variables are set.
Apply workarounds for each affected test:

filesystem.create.multipledisks: Doesn't need XFS.  Switch to ext4.

filesystem.create.zfs.xfs: Must use XFS and must use an existing test
fixture that has a small partition.  Rather than reworking the fixture,
add --unsupported to storage.filesystems.options.

filesystem.create.xfs.wipe: The available default partitions are too
small.  Ideally we'd resize one, but I haven't researched whether there
are implications for other tests.  Just use --unsupported for now.

The use of --unsupported breaks the blackbox tests on xfsprogs < 5.19.
That doesn't affect CoreOS CI, but may affect anyone running them manually
on older systems.

Fixes https://github.com/coreos/ignition/issues/1583.
2023-03-25 03:24:26 -04:00
Benjamin Gilbert
af5ff516a6 tests: update for new experimental spec 2023-02-20 03:09:50 -05:00
Benjamin Gilbert
0e2b63c9d5 *: update to v3_5_experimental spec 2023-02-20 03:09:50 -05:00
Benjamin Gilbert
7814b85b5a Replace io/ioutil
It was deprecated in Go 1.16 and its functions moved elsewhere.
2022-08-09 19:04:31 -04:00
marmijo
a46c71c435 tests/positive: Add test for sorting systemd preset file 2022-06-03 14:35:58 -04:00
Sohan Kunkerkar
397aa6a210 internal/exec: delete enablement symlinks when disabling unit
For services where FCOS ships a symlink in /etc, if the user tries
to disable the service via Ignition, systemd ignores the disablement
directive in the preset. Avoid this behavior by deleting the enablement
symlinks when disabling a unit, but continue to record the disablement
in the preset file. This is a short-term solution until the upstream
systemd PR (systemd/systemd#15205) is merged and widely deployed.

Fixes https://github.com/coreos/fedora-coreos-tracker/issues/392
2022-05-06 11:12:18 -04:00
Sohan Kunkerkar
99b437eab2 tests: use umountPath as a thin wrapper around umountPartition 2021-11-23 16:18:29 -05:00
Sohan Kunkerkar
28cdee3945 tests: address gostatic-check warning
error strings should not be capitalized
2021-11-23 16:15:39 -05:00
Kai Lueke
39661ab4fc tests: Add base64 decoding test
The data URLs which are used are all in URL encoding, while users can
also use base64 encoded data URLs.
Add a test to make sure base64 decoding works as expected.
2021-11-17 12:49:51 +01:00
Benjamin Gilbert
93a734931d ci: give blackbox tests two hours to run
They're timing out at 30 minutes.
2021-11-16 15:20:02 -05:00
Benjamin Gilbert
3ccb59c97e tests/filesystem: fix umountPartition retry loop
This originally called umount(8), and on failure, checked to see if the
unmount had succeeded anyway.  A later refactor switched to umount(2) but
failed to update the error message, and also broke the retry loop so that
it no longer ignored a spurious error return if umount actually succeeded.

Reinstate the success return if the filesystem was umounted, regardless of
the umount(2) return value.  Also clarify our error message on failure and
include the error we got from the syscall.

Fixes: 634508423b ("tests/filesystems: fix error handling")
2021-11-16 11:13:14 -05:00
Andrey Sokolov
6784a11af1 stages/filesystems: use mkfs.fat instead of mkfs.vfat
Ignition should use mkfs.fat instead of mkfs.vfat because mkfs.vfat is
symlink to mkfs.fat and may be absent in some distributions.
Dosfstools always creates mkfs.fat, but mkfs.vfat is optional
(https://github.com/dosfstools/dosfstools/blob/master/src/Makefile.am)
2021-10-15 09:41:25 +03:00
Benjamin Gilbert
bf06784da5 tests: fix linter warning
cmd cannot be nil because it was checked earlier in the function.
2021-07-28 18:40:57 -04:00
Benjamin Gilbert
05537fb915 exec: fix permissions for mountpoints in home dirs
If Ignition creates a directory within a user's home directory as a result
of creating a mountpoint, fix its permissions once the user exists.

Co-authored-by: Stephen Lowrie <slowrie@redhat.com>
2021-07-26 15:23:00 -04:00
Benjamin Gilbert
3f5ae5e00c tests: drop os.ModeDir requirement in mode of output directories
validateDirectory() already checks that the inode is a directory, so
this is just noise.
2021-07-23 13:04:34 -04:00
Benjamin Gilbert
5517bad3db *: add general mechanism for persisting state between stages
Serialize a struct to a JSON file in /run at the end of each stage and load
it at the beginning of the next stage.  This is intended to be an internal
mechanism that can change incompatibly without warning.
2021-07-22 14:24:01 -04:00
Benjamin Gilbert
d2bc3a939b engine: don't hardcode neednet path
Traditionally we expose paths in /run as command-line options, which helps
with testing.
2021-07-22 12:18:09 -04:00
Jonathan Lebon
8f520621ee tree: update for stable v3.3.0 and new v3.4.0-experimental 2021-06-24 10:24:02 -04:00
Sohan Kunkerkar
63a6789958 Merge pull request #1179 from sohankunkerkar/wipe-fs
Add a way to erase a block device without creating a filesystem
2021-05-05 10:13:29 -04:00
Sohan Kunkerkar
4626200238 tests/*: verify deletion of block device w/o creating a FS 2021-05-05 09:18:31 -04:00
Sohan Kunkerkar
59c1b2ce37 *: allow erasing block device without creating a filesystem
Fixes: https://github.com/coreos/ignition/issues/1172
This commit tries to address the problem of erasing a block device
with Ignition without creating a filesystem on it.
Also, related to https://bugzilla.redhat.com/show_bug.cgi?id=1926221
2021-05-05 09:18:23 -04:00
Benjamin Gilbert
f79f2ab253 Merge pull request #1182 from jlebon/pr/ci-adapt
ci: adapt to new buildroot image
2021-03-25 19:32:45 -04:00