Thanks to https://github.com/NixOS/nixpkgs/pull/71684 being merged recently, we do now have a test driver implementation in Python that allows for writing the imperative part of NixOS integration tests in Python instead of Perl.
Thanks @flokli @edolstra @Lassulus @adisbladis @domenkozar @garbas @jonringer for the support and @blitz @jtraue @marijanp for helping me porting the remaining Perl tests to Python.
In order to finish this project, we are going to perform the following tasks over the next weeks/months:
dumpTTYContents
#72943forwardPort
#72943getWindowNames
#72835requireActiveUnit
#72835waitForWindow
waitUntilTTYMatches
emptyDiskImages
behaviour #73559 log
variable)cockroachdb
#73934 #80047docker-containers
broken: port #80049 (was renamed to oci-containers
in the meantime and fixed)docker-preloader
broken: #74143, port #80051docker-tools
broken: #75081, port #80048ec2
#79696hardened
#76708krb5/deprecated-config
#80130krb5/example-config
#80130kubernetes/*
openstack-image
#79696 partition
(test deleted in #87084)redmine
(fixed: #80061) #85747rsyslogd
#80096run-in-machine
#80099systemd-confinement
#80103taskserver
#93413virtualbox
#94858os-prober
https://github.com/NixOS/nixpkgs/issues/72828#issuecomment-605658186acme
ammonite
atd
#72833automysqlbackup
avahi
#72833babeld
#72833 #72834bcachefs
#72833beanstalkd
#72833bees
#74001bind
#72833bittorrent
blivet
(broken, see #33496)boot-stage1
#72833borgbackup
#72833buildbot
#78556caddy
#72935cadvisor
#72935cassandra
#72897ceph-multi-node
#73190ceph-single-node
#73190certmgr
#72935cfssl
#72935chromium
#79352cjdns
#72935clickhouse
#73131cloud-init
#72935codimd
#74036colord
#72935containers-bridge
#74218containers-ephemeral
#74196containers-extra_veth
#74761containers-hosts
#74196containers-imperative
#74218containers-ipv4
#74218containers-ipv6
#74218containers-macvlans
#74761containers-physical_interfaces
#74761containers-portforward
#74761containers-reloadable
#74196containers-restart_networking
#74761containers-tmpfs
#74196couchdb
#72935deluge
#73131dhparams
#75084dnscrypt-proxy
#72935docker-edge
docker-registry
#74033docker-tools-overlay
#75084docker
#72935documize
#72935dovecot
#74004ecryptfs
#75084emacs-daemon
env
#75084etcd-cluster
#74005etcd
#74005fancontrol
#73131ferm
#74513firefox
#72835firewall
#73131fish
#73131flannel
(broken #74941, PR #85252)flatpak-builder
flatpak
fluentd
#73131fontconfig-default-fonts
fsck
fwupd
gdk-pixbuf
gitlab
#73939gitolite
#74063gjs
glib-networking
glusterfs
#74003gnome-photos
gnome3-xorg
https://github.com/NixOS/nixpkgs/pull/73938gnome3
#74943gocd-agent
#74082gocd-server
#74082google-oslogin/default
#74002gotify-server
#74034grafana
#72904graphene
graphite
#76562 (python-twisted dependencies fail already in Perl)graylog
#74040hadoop/hdfs
hadoop/yarn
haka
#76707handbrake
#73131haproxy
#75459 #75695hibernate
#73131hitch/default
home-assistant
#74126hound
#73131hydra/default
i3wm
#74938icingaweb2
#73131iftop
ihatemoney
#78556incron
#73131influxdb
#74069initrd-network-ssh/default
#72904initrd-network
#75695installer
#78670ipv6
#74758jackett
#73131jellyfin
jenkins
#74074kerberos/heimdal
#73961kerberos/mit
#73961kernel-latest
kernel-lts
kernel-testing
kexec
#76560 (hangs forever already in Perl)keymap
#78556knot
#72834ldap
#74851leaps
#75695libgdata
libxmlb
lidarr
#75695lightdm
#73135limesurvey
(attempted in #75695, broke with python error on decoding incomplete utf-8 string), reattempt in #78555login
loki
#72904magnetico
mailcatcher
#75695matrix-synapse
#72835mediawiki
memcached
#74312metabase
#72857minidlna
#73131miniflux
#73131minio
#74070misc
#79064mongodb
#73933moodle
#72887morty
#72887mosquitto
#73827mpd
#73935mumble
#76410munin
#74935mutable-users
#75703mxisd
#75703mysql-backup
#73992mysql-replication
#73992mysql
#73992nat
#74754ndppd
a9a271792d59aa15b6cc4bc5dfafde9fd9529815neo4j
#73991nesting
#75703netdata
#74078networkingProxy
#78239networking
#75721nextcloud/basic
nextcloud/with-mysql-and-memcached
nextcloud/with-postgresql-and-redis
nexus
nfs
#73989nghttpx
#75703nginx-sso
#74072nginx
#74072nix-ssh-serve
#73994nixos-generate-config
novacomd
#75703nsd
#80065nzbget
#75703openarena
openldap
#74851opensmtpd
#72390openssh
orangefs
#75703osquery
#74073, broken: #74081osrm-backend
#75703ostree
overlayfs
#75703packagekit
pam-oath-login
#74898pam-u2f
#75180pantheon
#73140paperless
#75701pdns-recursor
#75701peerflix
#75701pgjwt
#72904pgmanage
#75701php-pcre
#75701plasma5
#73134plotinus
#80067postgis
#75701postgresql-wal-receiver
powerdns
#73059pppd
#73056printing
#79327prometheus-exporters
#72904prometheus
#74055proxy
#75462 #78555quagga
#75701quake3
rabbitmq
#74123radarr
#72887radicale
#74764redis
#72887riak
#74124roundcube
#72887 #73131rspamd
#75464rss2email
#72887rxe
#73568samba
#73080shiori
signal-desktop
#72887simple
slurm
#73179smokeping
#73057snapper
#72887solr
#80063sonarr
#75701strongswan-swanctl
#72887sudo
#74076switch-test
#75701syncthing-init
#74114syncthing-relay
#74114systemd-networkd-wireguard
#73699systemd-nspawn
#73990systemd-timesyncd
#75701systemd
#78241telegraf
#72887tiddlywiki
#74866timezone
#74858tinydns
#73059tor
trac
#72857transmission
trezord
#72857trickster
#72887udisks2
https://github.com/NixOS/nixpkgs/pull/72860upnp
#72887uwsgi
#74061vault
wireguard/default
wireguard/generated
wireguard/namespaces
#75695wordpress
#73993xautolock
#72887xdg-desktop-portal
xfce4-14
#73138xfce
#73138xmonad
#73137xmpp/ejabberd
#74254xmpp/prosody-mysql
#74031xmpp/prosody
#74031xrdp
#74854xss-lock
yabar
#72887yggdrasil
#73411zfs
#78670zookeeper
#72887beegfs
(broken & removed, see #73998)hocker-fetchdocker/default
#95517, PR: #96076ipfs
(broken, see #74000)mathics
#80055, PR: #95505mesos
#78557, PR: #95507Additional work that would be awesome:
some tests updated in https://github.com/NixOS/nixpkgs/pull/72810, which was merged.
Updated the checkboxes above.
cc @mmahut : jormungandr
metabase
trezord
cc @1000101: trickster
See https://github.com/NixOS/nixpkgs/pull/72835#issuecomment-549972297.
With getWindowNames
and waitForWindow
I will begin porting the tests mentioned there.
It would be nice if the driver had type annotations and was checked with mypy.
would also help with IDE experience, as it will warn you of type mismatches. At least pycharm will ;)
Did we get an equivalent in the python driver for perl's mustFail
?
Edit: it's fail
.
Why is it called differently?
Why is it called differently?
# nixos/lib/test-driver/Machine.pm
sub mustFail {
fail @_;
}
sub mustSucceed {
succeed @_;
}
They are synonyms of each other, so i dropped the mustXXX
counterparts.
Mypy support for the driver has been added here https://github.com/NixOS/nixpkgs/pull/73033
However the tests itself are not type checked yet. What makes this difficult is also the fact that dynamic variables are magically added when tests are run.
Packaged as a Python package and using Sphinx for docs in https://github.com/NixOS/nixpkgs/pull/73496.
Having a hard time with my gnome3-xorg port because it fails on waiting for the first call to a user unit
error: unit "[email protected]" is inactive and there are no pending jobs.
The new Python test functions made it easy for me to add some tests for consul
as well:
:+1:
I fixed magnetico in #72012.
It's not checked in the list, but ndppd
is already ported it seems.
networking
is not listed but it's not ported and is also a quite large test.
@rnhmjoj The size of the tests is rarely an issue once you have a set of search and replace regex's handy. You spend most of the time trying to figure out why tests do not work, mostly it seems because they didn't work to begin with, as is the case with networking
.
The size of the tests is rarely an issue once you have a set of search and replace regex's handy.
Ah, nice.
mostly it seems because they didn't work to begin with, as is the case with networking.
This is quite alarming. I've assumed people would regularly check the tests...
This is quite alarming. I've assumed people would regularly check the tests...
We should have automatic CI on them. Don't we have that already?
on PRs, we definitely don't. Ofborg is able to perform a test by doing @GrahamOfBorg test <test>
, but it's up to someone with ofborg permissions to call it, and know that the package change relates to that tests.
on PRs, we definitely don't. Ofborg is able to perform a test by doing
@GrahamOfBorg test <test>
, but it's up to someone with ofborg permissions to call it, and know that the package change relates to that tests.
When a package's derivation on a PR changes, then it would only transitively change the tests' derivations that it really affects, right? Couldn't ofborg automatically determine this and then rerun these tests? Or has this already been tried and there were problems that my naive assumption does not reflect?
It looks like the situation with networking.networkd.virtual
is known. See the commit message of a3a441cd870e29ec63b41b3fbedb9ccd9c81a69a.
When a package's derivation on a PR changes, then it would only transitively change the tests' derivations that it really affects, right? Couldn't ofborg automatically determine this and then rerun these tests? Or has this already been tried and there were problems that my naive assumption does not reflect?
Summoning @Ekleog who worked on that in the past.
See https://github.com/NixOS/nixpkgs/pull/44439 for the RFC, https://github.com/NixOS/ofborg/pull/410 for the ofborg associated PR.
could and does are two separate things. I don't have context on why the decisions were made, but I'm assuming it was a compromise in compute resources vs validity guarantees.
There may be some history in there as well, as nixos modules used to be a separate repo altogether
I'm assuming it was a compromise in compute resources vs validity guarantees.
Initial version was run on weakly managed and non-exclusive-use infrastructure without a way to filter by features… So an alive human was expected to stand behind each build (and there are still timeouts)
Note that a change that touches gtk can force a chromium rebuild if you ask for all tests, which will timeout after consuming a lot of build resources. So the proposed rules sometimes tries to build more than the current deployment finds acceptable.
There may be some history in there as well, as nixos modules used to be a separate repo altogether
I think Nixpkgs-NixOS re-merge is older than ofBorg
on PRs, we definitely don't.
But what about post-merge on Hydra? The way I understand it is that the perl networking tests were also broken for a while. Is there anything that runs tests post-merge?
If yes, how would one get notified by a failure there?
I'm not sure what makes people think the networking tests aren't executed. Most of them are, see nixos/release-combined.nix
:
(all nixos.tests.networking.scripted.loopback)
(all nixos.tests.networking.scripted.static)
(all nixos.tests.networking.scripted.dhcpSimple)
(all nixos.tests.networking.scripted.dhcpOneIf)
(all nixos.tests.networking.scripted.bond)
(all nixos.tests.networking.scripted.bridge)
(all nixos.tests.networking.scripted.macvlan)
(all nixos.tests.networking.scripted.sit)
(all nixos.tests.networking.scripted.vlan)
However some tests (e.g. virtual
and privacy
) are not listed there so they are not executed. Also we only test scripted networking, not networkd-based networking.
My comments were in response to:
We should have automatic CI on them. Don't we have that already?
It's very possible right now to have a PR which affects networking to be merged without the tests being ran.
From my point of view, running the networking tests before a release falls more into the category of CD (continuous delivery); as the CI part is done as the code already been merged, and now you have to git bisect to see which change broke the related test.
jormungandr
was removed in aa98348f880052547f4035c6ce1f5403e6a91d15
Out of curiosity, do you guys see any downside of not inlineing larger tests suits?
I think that placing the test code into a dedicated python file and then reading it into the test string can provide a better experience with regards to python specific content assist tools like auto-formatting, making the whole process of writing tests more pleasant over all.
Out of curiosity, do you guys see any downside of not inlineing larger tests suits?
That sounds dependent on whether you need variable expansion inside the test code. But maybe functions could still be defined and then called
Me and @tfc spoke about refactoring larger parts, and making the test driver more something like a library (which could also use other virtualization/isolation platforms except qemu).
Currently, we have some back and forth between who's rendering what, and how the testScript
is being passed etc, which is a bit spaghetti-esque.
I don't really want to touch that as long as the perl test driver is still around, but happy to tackle that afterwards.
That sounds dependent on whether you need variable expansion inside the test code. But maybe functions could still be defined and then called
Of course I don't want to generallize this, but in practice a lot of tests don't interpolate anything major, so might be worth considering.
Would it be possible to "forward" attributes as variables in Python, like it is done in derivations? Would it be a good idea? IMHO you would get the best of both worlds ^^
Would it be possible to "forward" attributes as variables in Python, like it is done in derivations? Would it be a good idea? IMHO you would get the best of both worlds ^^
From the top of my head, this should be possible:
testScript = ''
PYTHON_VAR=${nix_interpolation}
${lib.readFile ./testScript.py}
'';
and then use PYTHON_VAR
in your testScript.py
as if it were defined there.
I meant in an automated way, as in modifying the testing infrastructure so that all attributes in the returned attribute set passed to make-test-python.nix
are available as variable in the python script. But this could be a close enough temporary alternative
Would it be possible to "forward" attributes as variables in Python, like it is done in derivations? Would it be a good idea? IMHO you would get the best of both worlds ^^
My opinion: It's not so good because it makes things more implicit and less clear when variables appear out of thin air in the Python file.
It's a write-time optimisation at the cost of readability, and I consider readability more important.
I would rather recommend a stand-alone test to be a function that takes arguments (passing them in as a dict via a single parameter, e.g. env
. is also fine, because it creates lexical clarity).
@tfc @NinjaTrappeur
When a package's derivation on a PR changes, then it would only transitively change the tests' derivations that it really affects, right? Couldn't ofborg automatically determine this and then rerun these tests? Or has this already been tried and there were problems that my naive assumption does not reflect?
I haven't checked the full context of the discussion, but IÂ remember a friend (@symphorien, I think? I'm not 100% sure) tried to work on re-evaluating all tests to check which ones changed, and evaluation was way too long to be reasonably doable, hence my not trying this way and just adding manual passthru.tests
:)
Can anybody explain me what sendKeys
did before in perl?
It has no Python equivalent, there is only send_key()
.
It did:
sub sendKeys {
my ($self, @keys) = @_;
foreach my $key (@keys) {
$key = $charToKey{$key} if exists $charToKey{$key};
$self->sendMonitorCommand("sendkey $key");
}
}
sub sendChars {
my ($self, $chars) = @_;
$self->nest("sending keys ‘$chars’", sub {
$self->sendKeys(split //, $chars);
});
}
What does the split //
do here?
Is it used in any remaining tests? //
looks like an empty regular expression, splitting by empty separator should probably convert a string to the list of component characters, and it would make sense to then send each character as a key (to type a command, for example)
Is it used in any remaining tests?
I don't think so.
splitting by empty separator should probably convert a string to the list of component characters, and it would make sense to then send each character as a key (to type a command, for example)
I don't get it though: Wouldn't the foreach my $key (@keys)
by itself already do that?
Great progress so far, only 18 tests remaining without PR from the issue description (at the time of post, may checkmark them once new updates come in below):
gnome3-xorg
haka
hardened
hocker-fetchdocker/default
krb5/deprecated-config
krb5/example-config
mathics
mesos
misc
networking-proxy
nsd
os-prober
partition
plotinus
printing
systemd-confinement
systemd
taskserver
gnome3-xorg
has had a PR for a while https://github.com/NixOS/nixpkgs/pull/73938
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/steps-towards-even-more-pr-automation/5634/1
Somehow solr never showed up on this list... :thinking:
Somehow solr never showed up on this list... 🤔
I found some more missing items, refreshed the list and moved all undone items to the top
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/nixos-20-03-feature-freeze/5655/1
Drop Perl test driver
Maybe not drop, but deprecate it with a warning for 20.09 or something, because when you have a whole lot of Perl tests in CI, updating to 20.03 means rewriting all those tests...
@aszlig :+1: to this. If nixosTest was an internal API this would be fine. But it's public and I don't think it's reasonable to have such a change to hand off one release.
Maybe not drop, but deprecate it with a warning for 20.09 or something, because when you have a whole lot of Perl tests in CI, updating to 20.03 means rewriting all those tests...
@aszlig yes, totally makes sense.
For what it is worth, I think it would be best to keep the Perl driver around for 1 release, since it is a pretty coollibrary and I'm aware of a bunch of users of that library who would probably appreciate having a few months of transition time.
@grahamc sure, no reason to nuke it for 20.03, some tests are still in Perl.
However, we should show a warning in 20.03 every time it's used, so people are aware it's deprecated and will be removed for 20.09. Some of the planned refactorings are too big to do in both test drivers, so we should be able to break the perl variant during the next cycle.
I'm going to unpin this, since it's basically 80+% complete.
It seems there is no progress on this. What will happen with the remaining broken software?
I assume broken tests will be marked as broken (if they aren't already), and eventually removed.
I'm not sure if it makes sense to mechanically translate them to python - as we can't verify they still work
Currently working tests that are still in perl need to be changed to python, before we can remove the perl driver.
Here is my attempt at porting the os-prober test to python. https://github.com/symphorien/nixpkgs/tree/os-prober-python
When I run it, qemu simply hangs. Does anyone have an idea ?
It seems there is no progress on this. What will happen with the remaining broken software?
The broken tests are a thing that indeed needs to be discussed - what shall be done with them?
The non-broken tests will eventually be ported and are not forgotten (i am discussing this with colleagues currently), but the urgency dropped a bit after the 20.03 branch-off.
@tfc I thought of the same thing as @flokli as what to do with the broken tests. A test being broken and that can't be translated to the python driver isn't very useful. There's not many, and they will continue to exist in the git history, so we can just remove them if we have to. A final issue can be opened so people can be aware of this.
16 to go where most are broken :)
I'm going to take care of the VirtualBox test soonish, because we are using this internally and I'd want this to stay working. :)
I'm thinking it's a good idea to have the perl driver removed on unstable very soon.
agreed
Here is my attempt at porting the os-prober test to python. https://github.com/symphorien/nixpkgs/tree/os-prober-python
When I run it, qemu simply hangs. Does anyone have an idea ?
@symphorien I rebased your branch onto latest master, and got further until this:
machine: must succeed: nixos-rebuild boot >&2
machine # error: The option `virtualisation.qemu.consoles' defined in `/nix/var/nix/profiles/per-user/root/channels/nixos/nixos/modules/testing/test-instrumentation.nix' does not exist.
machine # (use '--show-trace' to show detailed location information)
machine # building Nix...
machine # error: The option `virtualisation.qemu.consoles' defined in `/nix/var/nix/profiles/per-user/root/channels/nixos/nixos/modules/testing/test-instrumentation.nix' does not exist.
The machine doesn't hang anymore, and the failure also exists like this in master.
Can you take another look, and maybe open a PR to carry the discussion over there?
Not in the coming days.
If someone has bandwidth, we could use some eyes on #94858 to remove quite a big piece of perl test code. :)
With all remaining tests ported over, I opened #96396 removing the (now unused) perl code.
Thanks a lot for everyone doing the porting! :-)
Soo proud that we did this :sparkles:
Most helpful comment
It would be nice if the driver had type annotations and was checked with mypy.