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
Add systemd analyze test #74066
Add systemd analyze test #74066
Conversation
nixos/lib/test-driver/test-driver.py
Outdated
""" | ||
# Compute the source, target, and intermediate shared file names | ||
out_dir = os.environ.get("out", os.getcwd()) | ||
filename = re.sub(r".*/", "", source) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use pathlib
here to calculate basenames and assemble paths:
https://docs.python.org/3/library/pathlib.html#methods-and-properties
nixos/lib/test-driver/test-driver.py
Outdated
out_dir = os.environ.get("out", os.getcwd()) | ||
filename = re.sub(r".*/", "", source) | ||
int_shared_dir = "/tmp/xchg" | ||
shared_temp = tempfile.mkdtemp(dir=self.shared_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use tempfile.TemporaryDirectory
as a context manager, it also takes care of cleaning up afterwards.
nixos/lib/test-driver/test-driver.py
Outdated
shared_temp = tempfile.mkdtemp(dir=self.shared_dir) | ||
shared_temp_basename = re.sub(r".*/", "", shared_temp) | ||
shared_temp_in = "{}/{}".format(int_shared_dir, shared_temp_basename) | ||
src_out = "{}/{}".format(shared_temp, filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can join pathlib
paths by just /
in between them.
nixos/lib/test-driver/test-driver.py
Outdated
src_in = "{}/{}".format(shared_temp_in, filename) | ||
tgt = "{}/{}/".format(out_dir, target_dir) | ||
# Copy the file to the shared directory inside VM | ||
if not self.is_up(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current behaviour in the Machine
class is to start machines if you request things from them, so we should do here, too.
nixos/lib/test-driver/test-driver.py
Outdated
self.succeed("cp -r {} {}".format(shlex.quote(source), shlex.quote(src_in))) | ||
self.succeed("sync") | ||
# Copy the file from the shared directory outside VM | ||
ret = subprocess.run(["mkdir", "-p", tgt]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably can also be done with python stdlib instead of shelling out to mkdir
.
@@ -260,6 +260,7 @@ in | |||
syncthing-init = handleTest ./syncthing-init.nix {}; | |||
syncthing-relay = handleTest ./syncthing-relay.nix {}; | |||
systemd = handleTest ./systemd.nix {}; | |||
systemd-analyze = handleTest ./systemd-analyze.nix {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice if we could split this into a separate PR, but fine to keep it around for now until the test driver additions are done.
a1821bc
to
277eedf
Compare
Depends on/includes #74077 |
db34588
to
16ab350
Compare
machine.wait_for_unit("multi-user.target") | ||
|
||
with subtest("Prepare output dir"): | ||
machine.succeed("mkdir systemd-analyze") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can put the equivalent of doing a mkdir -p $(dirname $dst)
into thecopy_from_vm
function, so we don't have to repeat ourselves.
Also see nixos/tests/blivet.nix
, which would benefit from that too (if it wouldn't have been broken, see #33496).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a change in #74077 of course, I can just better explain it with the example here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in-VM directory for systemd-analyze
output that will later become the original source location for copy_from_vm
"systemd-analyze {} > {}/{} 2> {}/{}.err".format( | ||
" ".join(args), tgt_dir, name, tgt_dir, name | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be overly generic. We only call it with one argument.
What about just executing machine.succeed(…)
with a list of the "raw" commands:
machine.succeed(
"systemd-analyze blame > blame.txt",
"systemd-analyze critical-chain > critical-chain.txt",
"systemd-analyze dot > dependencies.dot",
"systemd-analyze plot > systemd-analyze.svg",
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overly generic
True, but cheap
list of the "raw" commands
The replacement list loses stderr of the dot
subcommand which does contain some data that could be in principle useful.
Also, I do want to have a subdirectory that I can copy as a whole.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't care that much. I think it might be more readable if written more explicitly, but your call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried. It becomes pretty Black-fragile. Agree on the point of more comments needed.
nixos/tests/systemd-analyze.nix
Outdated
run_systemd_analyze(["dot"], "dependencies.dot") | ||
run_systemd_analyze(["plot"], "systemd-analyze.svg") | ||
|
||
with subtest("Install the resulting data"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with subtest("Copy the resulting data into $out"):
|
||
with subtest("Install the resulting data"): | ||
machine.copy_from_vm("systemd-analyze", "") | ||
machine.copy_from_vm("systemd-analyze/systemd-analyze.svg", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some files seem to be missing here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No: I copy The Main Picture to the toplevel, and then the entire set of data as a subdirectory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, more comments and less abstractions would help understanding it ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Less asbtractions mean more Black pain. More comments added
> + "systemd-analyze {} > {}/{} 2> {}/{}.err".format(
+ " ".join(args), tgt_dir, name, tgt_dir, name
+ )
This seems to be overly generic. We only call it with one argument.
True, but cheap
What about just executing `machine.succeed(…)` with a list of the "raw" commands:
```
machine.succeed(
"systemd-analyze blame > blame.txt",
"systemd-analyze critical-chain > critical-chain.txt",
"systemd-analyze dot > dependencies.dot",
"systemd-analyze plot > systemd-analyze.svg",
)
Well, not exactly; stderr from `dot` subcommand is actually useful in some sense. And also I do want to put stuff into a subdirectory that I can later copy as a whole.
|
+ with subtest("Prepare output dir"):
+ machine.succeed("mkdir systemd-analyze")
I think we can put the equivalent of doing a `mkdir -p $(dirname $dst)` into the`copy_from_vm` function, so we don't have to repeat ourselves.
This is in-VM directory for `systemd-analyze` output that will later become the original source location for `copy_from_vm`
…Also see `nixos/tests/blivet.nix`, which would benefit from that too (if it wouldn't have been broken, see #33496).
|
+ with subtest("Install the resulting data"):
+ machine.copy_from_vm("systemd-analyze", "")
+ machine.copy_from_vm("systemd-analyze/systemd-analyze.svg", "")
Some files seem to be missing here.
No: I copy The Main Picture to the toplevel, and then the entire set of data as a subdirectory.
|
16ab350
to
743cf85
Compare
With #74077 merged, can this be rebased on top of master? |
743cf85
to
c82a440
Compare
OK, the hard part of rebase (building the kernel from |
Maybe I should re-mention @flokli |
Can you move the replies sent via E-Mail into the thread? GitHub doesn't properly attach these, and keeping the discussion in threads seems like a good thing to do. |
Both options provided by GitHub (threaded and single-stream) are annoying in different ways, of course (which is why mailing lists, which are actually suitable for discussion, allow switching the navigation mode), but oh well… got around to starting a Firefox instance. @flokli stuffed stuff into the threads |
c82a440
to
e365454
Compare
@GrahamcOfBorg test systemd-analyze |
Thanks! |
Thanks for the carefuk rereading of all that and for the explanations! |
Thanks for staying through till the end, and enduring my pickyness 😆 |
I have to recognise that all of the pickyness was clearly actionable. |
Motivation for this change
Trying to improve the NixOS test infrastructure; fixing the handling of shared dir in Python test driver, adding a
copy_from_vm
function, and adding a test exporting evereythingsystemd-analyze
has to say.Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nix-review --run "nix-review wip"
./result/bin/
)nix path-info -S
before and after)Notify maintainers
cc @flokli