nixos/test-driver: use attrname from nodes to refer to machines#181482
Closed
Sohalt wants to merge 2 commits intoNixOS:masterfrom
Closed
nixos/test-driver: use attrname from nodes to refer to machines#181482Sohalt wants to merge 2 commits intoNixOS:masterfrom
Sohalt wants to merge 2 commits intoNixOS:masterfrom
Conversation
This makes it possible to refer to machines by the attrname for the
config in the `nodes` attrset as opposed to the `system.name`, e.g.
makeTest = {
nodes = {
foo = { pkgs, ... }: {
...
};
bar = { pkgs, ... }: {
...
};
};
testScript = ''
foo.start()
bar.start()
...
'';
}
roberth
reviewed
Jul 15, 2022
| nodesList = (lib.attrNames nodes); | ||
| in nodesList ++ lib.optional (lib.length nodesList == 1 && !lib.elem "machine" nodesList) "machine"; | ||
|
|
||
| # TODO: This is an implementation error and needs fixing |
Member
There was a problem hiding this comment.
This comment was once added to acknowledge the problem that these names were too coupled.
When the nodes.<name> names correspond to python identifiers only, and to hostnames/system names only by their default value, we can get rid of this comment and invalidNodeNames.
We may still want to validate the attribute names to be valid identifiers, but as an alternative, we could use a dict of nodes in the test script. I don't have a much of an opinion about this choice.
roberth
reviewed
Sep 28, 2022
| vms = map (m: m.config.system.build.vm) (lib.attrValues nodes); | ||
|
|
||
| nodeHostNames = let | ||
| nodesList = map (c: c.config.system.name) (lib.attrValues nodes); |
Member
There was a problem hiding this comment.
This line has moved to nixos/lib/testing/driver.nix.
This was referenced Sep 28, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of changes
The NixOS test-driver sets up VMs as specified by the
nodesattrset passed tomakeTest. The VMs can then be interacted with from the pythontestScriptusing variables named aftersystem.nameof the VM. This breaks tests whensystem.namechanges (e.g. because you like to add a git SHA to the name).This change makes it possible to refer to machines by the attrname for the
config in the
nodesattrset as opposed to thesystem.name, e.g.I think this way is strictly better, because the attrnames in
nodesare guaranteed to be unique, they are usually defined right next to thetestScriptand they are completely independent from other parts of the module system (i.e. only the test-driver uses them).The code is not very clean and not backwards compatible. I just want to have a starting point for discussion.
Things done
sandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)nixos/doc/manual/md-to-db.shto update generated release notes