nixosTests.proxy: Port to python

This commit is contained in:
Jacek Galowicz 2020-01-26 13:04:36 +01:00
parent 4df1df986d
commit ee2acd6c6c

View File

@ -1,35 +1,30 @@
import ./make-test.nix ({ pkgs, ...} : import ./make-test-python.nix ({ pkgs, ...} :
let let
backend = { pkgs, ... }: {
backend = services.httpd = {
{ pkgs, ... }: enable = true;
adminAddr = "foo@example.org";
{ services.httpd.enable = true; virtualHosts.localhost.documentRoot = "${pkgs.valgrind.doc}/share/doc/valgrind/html";
services.httpd.adminAddr = "foo@example.org"; };
services.httpd.virtualHosts.localhost.documentRoot = "${pkgs.valgrind.doc}/share/doc/valgrind/html";
networking.firewall.allowedTCPPorts = [ 80 ]; networking.firewall.allowedTCPPorts = [ 80 ];
}; };
in {
in
{
name = "proxy"; name = "proxy";
meta = with pkgs.stdenv.lib.maintainers; { meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ eelco ]; maintainers = [ eelco ];
}; };
nodes = nodes = {
{ proxy = proxy = { nodes, ... }: {
{ nodes, ... }: services.httpd = {
enable = true;
{ services.httpd.enable = true; adminAddr = "bar@example.org";
services.httpd.adminAddr = "bar@example.org"; extraModules = [ "proxy_balancer" "lbmethod_byrequests" ];
services.httpd.extraModules = [ "proxy_balancer" "lbmethod_byrequests" ]; extraConfig = ''
services.httpd.extraConfig = ''
ExtendedStatus on ExtendedStatus on
''; '';
services.httpd.virtualHosts.localhost = { virtualHosts.localhost = {
extraConfig = '' extraConfig = ''
<Location /server-status> <Location /server-status>
Require all granted Require all granted
@ -51,7 +46,7 @@ in
ProxyTimeout 5 ProxyTimeout 5
''; '';
}; };
};
networking.firewall.allowedTCPPorts = [ 80 ]; networking.firewall.allowedTCPPorts = [ 80 ];
}; };
@ -61,37 +56,35 @@ in
client = { ... }: { }; client = { ... }: { };
}; };
testScript = testScript = ''
'' start_all()
startAll;
$proxy->waitForUnit("httpd"); proxy.wait_for_unit("httpd")
$backend1->waitForUnit("httpd"); backend1.wait_for_unit("httpd")
$backend2->waitForUnit("httpd"); backend2.wait_for_unit("httpd")
$client->waitForUnit("network.target"); client.wait_for_unit("network.target")
# With the back-ends up, the proxy should work. # With the back-ends up, the proxy should work.
$client->succeed("curl --fail http://proxy/"); client.succeed("curl --fail http://proxy/")
$client->succeed("curl --fail http://proxy/server-status"); client.succeed("curl --fail http://proxy/server-status")
# Block the first back-end. # Block the first back-end.
$backend1->block; backend1.block()
# The proxy should still work. # The proxy should still work.
$client->succeed("curl --fail http://proxy/"); client.succeed("curl --fail http://proxy/")
client.succeed("curl --fail http://proxy/")
$client->succeed("curl --fail http://proxy/");
# Block the second back-end. # Block the second back-end.
$backend2->block; backend2.block()
# Now the proxy should fail as well. # Now the proxy should fail as well.
$client->fail("curl --fail http://proxy/"); client.fail("curl --fail http://proxy/")
# But if the second back-end comes back, the proxy should start # But if the second back-end comes back, the proxy should start
# working again. # working again.
$backend2->unblock; backend2.unblock()
$client->succeed("curl --fail http://proxy/"); client.succeed("curl --fail http://proxy/")
''; '';
}) })