New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test/ctr.bats: fixes and improvements #4253
Conversation
Skipping CI for Draft Pull Request. |
Codecov Report
@@ Coverage Diff @@
## master #4253 +/- ##
=======================================
Coverage 38.59% 38.59%
=======================================
Files 111 111
Lines 8893 8893
=======================================
Hits 3432 3432
Misses 5077 5077
Partials 384 384 |
Fix issues like this one: > In ctr.bats line 69: > errorconfig=$(cat "$TESTDATA"/container_config.json | python -c 'import json,sys;obj=json.load(sys.stdin);obj["command"] = ["false"]; json.dump(obj, sys.stdout)') > ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Test cleanup (including stopping+removing all containers and pods, and stopping crio) is performed via teardown. Remove the cleanup from those test cases where it's not clearly part of the test itself. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Fixes warings like this one: > In ctr.bats line 195: > if test $(stat -f -c%T /sys/fs/cgroup) != cgroup2fs; then > ^----------------------------^ SC2046: Quote this to prevent word splitting. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Commit 5f49b2c added this test case. Obviously, `run crictl` do not output anything to stdout, and `run grep` do not fail if grep exits with non-zero exit code. So the test was not testing anything. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: kolyshkin, mrunalp The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This [partially] fixes the test case. It was broken from the very beginning, since it was supposed to run a privileged container and check that /sys/fs/cgroup is mounted rw. Commit d3a50d8 ("privileged: set mounts to rw") added test/testdata/container_config_privileged.json file, but it is not used by the test (or any other tests). It also checks for ro mount while it should check for rw (based on what I understood). Finally, it used incorrect pod config while creating a container (not sure if it makes any difference, just observing). The test case was later amended to not check ro/rw bits since it was failing on some configurations (see commit 78badc8). This commit fixes the config used for container (and adds `edit_json` function to which hopefully other tests will be eventually converted), fixes the check for rw mount, and fixes the pod config used to create container. While at it, remove the never used container_config_privileged.json. The issues that are not fixed (will be addressed separately) are: - non-working check via jq; - excessive use of `run`. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Commits a2ec1d4 and 247d465 added a few checks using jq in the following test cases: * ctr lifecycle * ctr execsync should not overwrite initial spec args * privileged ctr -- check for rw mounts Alas, those checks do not work (and never worked); jq always succeeds. This happened because 1. in `run cmd1 ... | cmd2` the part starting with the pipe character is not part of `run` statement; 2. `run` eats `cmd1 ...` output (into `$output` variable); so `cmd2` is provided with empty input. Now, 3. `jq` with empty input does not run any filters and thus succeeds (even with `-e`, see [1]). The fix is to add a separate check that the output is not empty. While at it, remove `run` where it's not needed from the other places in those three tests we fix. [1] jqlang/jq#1628 Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is brought to you by shellcheck -f diff ctr.bats | patch -p1 Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Not sure what is going on. I have amended and pushed this branch, but github is not picking it up here. |
d398e11
to
4ab4128
Compare
/retest |
/lgtm |
/retest |
single failure with e2e_features_fedora (which I've seen before):
There is an open issue (kubernetes/kubernetes#92147) and looks like the related fix (kubernetes/kubernetes#93427 is in our codebase but it's not enough). |
/retest |
/retest |
No logs for "failed" integration_crun, it seems it just went astray. /retest |
shfmt has recently added support for bats files formatting (see mvdan/sh#600), so let's use it. We have to use git HEAD for now since there was no release done with this feature yet. Unfortunately, shfmt introduces an alledged regression (see [1]) so we have to specify `-ln bash` explicitly in Makefile. This commit has brought to you by go get 'mvdan.cc/sh/v3@master' go mod vendor go mod tidy [1] cri-o#4253 Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
What type of PR is this?
/kind bug
What this PR does / why we need it:
run
use).shellcheck
.edit_json
helper to modify json using jq(the plan is to switch code using
sed
orpython
to this one).The test fixed are:
1. "annotations passed through".
Commit 5f49b2c added this test case.
Obviously,
run crictl
do not output anything to stdout,and
run grep
do not fail if grep exits with non-zero exit code.So the test was not testing anything.
2. "privileged ctr -- check for rw mounts".
It was broken from the very beginning, since it was supposed to run a
privileged container and check that /sys/fs/cgroup is mounted rw.
Commit d3a50d8 ("privileged: set mounts to rw") added
test/testdata/container_config_privileged.json file, but it is not
used by the test (or any other tests). It also checks for ro mount
while it should check for rw (based on what I understood). Finally,
it used incorrect pod config while creating a container (not sure
if it makes any difference, just observing).
The test case was later amended to not check ro/rw bits since it was
failing on some configurations (see commit 78badc8).
This commit fixes the config used for container (and adds
edit_json
function to which hopefully other tests will be eventually converted),
fixes the check for rw mount, and fixes the pod config used to create
container.
While at it, remove the never used container_config_privileged.json.
3. "ctr lifecycle", "ctr execsync should not overwrite initial spec args", "privileged ctr -- check for rw mounts".
Commits a2ec1d4 and 247d465 added a few checks using jq.
Alas, those checks do not work (and never worked); jq always succeeds.
This happened because
in
run cmd1 ... | cmd2
the part starting with the pipecharacter is not part of
run
statement;run
eatscmd1 ...
output (into$output
variable);so
cmd2
is provided with empty input.Now,
jq
with empty input does not run any filters and thus succeeds(even with
-e
, see [1]).The fix is to add a separate check that the output is not empty.
While at it, remove
run
where it's not needed from the other placesin those three tests we fix.
[1] jqlang/jq#1628
Please see individual commits for more details.
Which issue(s) this PR fixes:
Fixes: #3662
Special notes for your reviewer:
Please review commit-by-commit.
Does this PR introduce a user-facing change?