[Nix-dev] using qemu virtual machine for testing software

Maarten Hoogendoorn maarten at moretea.nl
Fri Jul 29 08:42:51 CEST 2016


Am I correct to think that  you are trying to connect to the postgresql
instance in the VM from your host machine?
The documentation of forwardPort states: "Forward a TCP port on the host to
a TCP port on the guest.  Useful during interactive testing."
So it provides TCP forwarding in the direction host -> vm guest, it does
not expose a VM guests' port on the host.

AFAIK, the purpose of this vmtools machinery is to run tests inside the VM,
not to provide VM's that you can use in your other tests.
If you want access to debug your postgres db, you can either add assertions
/ psql cli commands to the test script, or you could see if it's possible
to (ab)use netcat to create a bash shell in your test vm machine.


2016-07-29 2:40 GMT+02:00 Tomasz Czyż <tomasz.czyz at gmail.com>:

> Hi,
>
> I'm trying to use same mechanism as nixos for testing with vm.
> I've created "run-vm.nix" and I can run vm with "nix-build run-vm.nix".
>
> I can't connect to forwarded port and I don't know how to connect/interact
> with the machine. Is there anyone who know how I could connect to this
> machine and would be willing to explain?
>
> run-vm.nix:
>
> {system?builtins.currentSystem}:
> let
>   pkgs = import <nixpkgs> {};
>   machine = {...}: {
>       services.postgresql = {
>           enable=true;
>           enableTCPIP = true;
>       };
>       # networking.firewall.enable=false; # I've tried with this
>    };
>   testing = import <nixpkgs/nixos/lib/testing.nix>{inherit system;};
>   test = testing.makeTest ({
>     machine = machine;
>     testScript=''
>       $machine->start;
>       $machine->waitForUnit("postgresql.service");
>       $machine->waitForOpenPort(5432);
>       $machine->forwardPort(9432, 5432);
>       # $machine->forwardPort(5432, 9432); # I've tried with this as well
>       # $machine->execute("sleep 9999999"); # I've tried with this as well
>       $machine->waitForShutdown;
>     '';
>   });
> in
>     test
>
>
>
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.science.uu.nl/pipermail/nix-dev/attachments/20160729/196703e0/attachment.html>


More information about the nix-dev mailing list