Use the `base2` option instead of an explicit factor.
There are two places left where we pass an explicit unit. For these we need to
think harder about what to do there. Mark them with FIXME comments for now.
For numbers < 1000 the unit should be "B" (bytes), not simply empty.
This is technically an API break, but most places which use that (like,
memory or storage device sizes) don't usually deal with such small
numbers (except "0"), and cockpit-files already has a hack for this [1].
As cockpit-files, -podman, etc. bundle cockpit.js, this can be fixed at
the time when updating cockpit lib, so it's not a sudden runtime
breakage.
Again, `format_bytes_per_sec()` already gets this right.
[1] https://github.com/cockpit-project/cockpit-files/blob/8e078434f5/src/sidebar.jsx#L80
It's "kB", not "KB". `format_bytes_per_sec()` is already correct (just
the documentation was wrong).
Also add unit tests for a really small (5 B) number in decimal and
binary, and a corner case for "1023" in binary units.
Adjust the pixel tests which exposed "KB".
- Put a plain number into the data store instead of a pre-formatted
string. This makes it easier to determine if we have an actual value
(it's an integer), and also if the value is exactly zero.
- Format the number in the React component instead, and move to the
current API of `base2: true`. This fixes a deprecation log message.
- Stop repeating the `"error"` string comparison. Anything which isn't
`undefined` or a number counts as "error, don't show".
Move our list of static files out of test/static-code (which is shared
with other projects). Add testlib to that list.
This reduces the cost of running mypy on a warm cache from 20s to ~0.3s,
while expanding checking to every single Python file in the source tree.
A overall `test/static-code` run (minus `node_modules`) decreases from
~24s to ~4s. The majority of that time is now in the json validity
checking rule (since it runs a separate python invocation for each
file).
We no longer gate tests on this, so it's safe to drop.
We leave the todoPybridgeRHEL8 decorator in place, since we plan to
bring back a scenario that involves running the Python bridge on RHEL8,
but for now, we make it a non-op.
We `import cdp` and later set `cdp = cdp.CDP()`. That might confuse
people who think that they could call other things from the `cdp`
module.
Just do `from cdp import CDP` and then `cdp = CD()` to avoid the issue.
We no longer need to have `machine` in the path — we refer to everything
in bots with its fully-qualified name, the same way it's now done in the
bots repository itself.
After mypy (addressed in #20342) the slowest thing in test/static-code
is... JSON validation. This is caused by the fact that `json.tool`
doesn't support multiple filenames, so we have to invoke it separately
for every single JSON file (and we have many).
Replace that with a small script which runs in a single Python
invocation and improves the output by printing the name of the file
containing the failure (which `json.tool` doesn't do). This saves us a
sed invocation after the fact.
Implements some rough typing for cockpit.spawn, this is already useful
to lint `cockpit.spawn`'s options in our codebase and found instances
where we pass a boolean to `superuser`.
This was pretty much completely pain-free, with a minor exception: the
test overrides the `cockpit.language` attribute, which we would
otherwise probably declare as `const`.
Add a new simplified style for all of the units-based number formatting
APIs (bytes, bytes/sec, bits/sec). Keep loose versions of the old APIs
around in `cockpit.d.ts`, but mark them deprecated.
Make sure we test the new API variant from test-format.js.
Use our fancy new tagged templates to name our assertions in
test-format. In addition to being a lot easier (and shorter) to write,
it means we see `{"precision": 2}` instead of `[object Object]`.
Also, leave out the value that we're comparing it equal to. This value
is already displayed on assertion failures, and having it shown twice
only makes the output harder to read.
Add a small function called f() to qunit-tests.ts. It is intended to be
used as a tagged template string format function.
The default formatting for template strings passes each argument to
String(), which means that objects get formatted like:
[object Object]
This function formats them using JSON, so you can see the actual object
value.
It can be imported into any QUnit test and used like:
f`format_bytes_per_sec(${checks[i][0]}, ${checks[i][1]}, ${checks[i][2]})`
which produces output like:
ok 121 - format_bytes_per_sec: format_bytes_per_sec(25555678, "kB/s", {"precision":2})
This has a single user (in storaged) and is more general than it needs
to be to support that user. Hardcode it to SI-based units and move it
into storaged/utils.js, so we can keep the unit tests.
The unit tests themselves only test the 1024 case (which is the opposite
of what is actually used in practice) so adjust them for SI (mostly by
renaming variables and changing `1024`s to `1000`s).
`kdumpctl` moved from the kexec-tools to the kdump-utils package in
Fedora Rawhide, and the former does not require the latter. To make sure
we get the one we want, depend on the program path directly.
https://bugzilla.redhat.com/show_bug.cgi?id=2275385
- Generalize the nginx skip (it's also not installed on
centos-9-stream, we just never have started to test it there on our
CI)
- vdo and wireguard are not currently available in RHEL 10
- NM team devices are not supported, see
https://issues.redhat.com/browse/RHEL-33026
Completely wiping the currently running root partition is too
aggressive: During shutdown, recent versions of systemd-shutdown [1]
re-executes itself to free all open fds on the root fs (so that it can
be unmounted cleanly), which doesn't work if /usr/sbin/systemd-shutdown
is gone. This leads to reboot hanging at
```
[ OK ] Reached target reboot.target - System Reboot.
[!!!!!!] Failed to execute shutdown binary.
```
Instead, make the partition unbootable by cleaning /etc (i.e. allowed
SSH keys, boot targets, etc.) Even that is redundant, as post reboot the
test already checks that it booted from the encrypted partition. But
let's keep the belt and suspenders.
[1] https://github.com/systemd/systemd/blob/main/src/shutdown/shutdown.c
Python 3.13 removes the cgi module and recommends using EmailMessage for
parsing a multipart section. This is a bit trickier as it needs a full
message with original Content-Type header and boundary.
As this runs inside our testvm we can't rely on for example the
`multipart` module.
The test inserts messages in the journal, we do not clean up the journal
but other non-destructive tests circumvent showing old test messages
from a retry by starting the log since the start time of the test.
`iptables` has been a backwards compatibility shim for nftables for a
long time now, and finally does not work on CentOS/RHEL 10 any more.
The first case in TestConnection.testBasic takes the socket away on the
login page with a TCP reset reply. We can get the same effect by just
stopping the socket.
The second case silently drops the packets to cover the "reply timeout"
functionality of the shell. Replace `iptables` with the corresponding
`nft` commands. It would be nice to use firewalld for that, but that has
a default rule to always allow packets on established connections -- but
severing that is exactly the goal of this test.
CentOS 10's rpm scripts don't properly reload systemd any more after
uninstalling a package, so that `pmlogger.service` still exists in
systemd's brain afterwards (as loaded/inactive). The same is true for
stratisd.service and others, so this is not pcp specific.
Explicitly reload systemd to purge units which don't exist on disk any
more from systemd's brain. This fixes TestClient.testBeibootNoBridge on
CentOS 10, which checks the case that `pcp.service` does not exist.
Don't remove the /var/log/pcp/pmlogger directory itself, just its
content, like we do in all other tests. Latest pcp version fails to
start up if the directory isn't present. This is a regression [1], but
also there's no need to be that demanding.
[1] https://bugzilla.redhat.com/show_bug.cgi?id=2275408Fixes#20327
Rename qunit-tests.js to .ts and stop hanging our functions on the main
QUnit object (which isn't typesafe). We can just export them from our
module. Adjust the users accordingly.
Add explicit file extensions to the list of tests in files.js (removing
the hardcoded '.js' from build.js) and add our first .ts case.
This new case tests that `cockpit.assert()` works properly in the
positive and negative cases and also verifies that it can be used for
type narrowing (otherwise tsc would complain).