mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-11 04:05:40 +03:00
nixos/tests: add qemu-vm-restrictnetwork test
This commit is contained in:
parent
e039cb9d97
commit
b25e0e8ebc
2 changed files with 37 additions and 0 deletions
36
nixos/tests/qemu-vm-restrictnetwork.nix
Normal file
36
nixos/tests/qemu-vm-restrictnetwork.nix
Normal file
|
@ -0,0 +1,36 @@
|
|||
import ./make-test-python.nix ({
|
||||
name = "qemu-vm-restrictnetwork";
|
||||
|
||||
nodes = {
|
||||
unrestricted = { config, pkgs, ... }: {
|
||||
virtualisation.restrictNetwork = false;
|
||||
};
|
||||
|
||||
restricted = { config, pkgs, ... }: {
|
||||
virtualisation.restrictNetwork = true;
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
import os
|
||||
|
||||
if os.fork() == 0:
|
||||
# Start some HTTP server on the qemu host to test guest isolation.
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
HTTPServer(("", 8000), BaseHTTPRequestHandler).serve_forever()
|
||||
|
||||
else:
|
||||
start_all()
|
||||
unrestricted.wait_for_unit("network-online.target")
|
||||
restricted.wait_for_unit("network-online.target")
|
||||
|
||||
# Guests should be able to reach each other on the same VLAN.
|
||||
unrestricted.succeed("ping -c1 restricted")
|
||||
restricted.succeed("ping -c1 unrestricted")
|
||||
|
||||
# Only the unrestricted guest should be able to reach host services.
|
||||
# 10.0.2.2 is the gateway mapping to the host's loopback interface.
|
||||
unrestricted.succeed("curl -s http://10.0.2.2:8000")
|
||||
restricted.fail("curl -s http://10.0.2.2:8000")
|
||||
'';
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue