nixosTests.proxy: Port to python
This commit is contained in:
parent
4df1df986d
commit
ee2acd6c6c
@ -1,97 +1,90 @@
|
|||||||
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;
|
||||||
|
adminAddr = "bar@example.org";
|
||||||
|
extraModules = [ "proxy_balancer" "lbmethod_byrequests" ];
|
||||||
|
extraConfig = ''
|
||||||
|
ExtendedStatus on
|
||||||
|
'';
|
||||||
|
virtualHosts.localhost = {
|
||||||
|
extraConfig = ''
|
||||||
|
<Location /server-status>
|
||||||
|
Require all granted
|
||||||
|
SetHandler server-status
|
||||||
|
</Location>
|
||||||
|
|
||||||
{ services.httpd.enable = true;
|
<Proxy balancer://cluster>
|
||||||
services.httpd.adminAddr = "bar@example.org";
|
Require all granted
|
||||||
services.httpd.extraModules = [ "proxy_balancer" "lbmethod_byrequests" ];
|
BalancerMember http://${nodes.backend1.config.networking.hostName} retry=0
|
||||||
services.httpd.extraConfig = ''
|
BalancerMember http://${nodes.backend2.config.networking.hostName} retry=0
|
||||||
ExtendedStatus on
|
</Proxy>
|
||||||
|
|
||||||
|
ProxyStatus full
|
||||||
|
ProxyPass /server-status !
|
||||||
|
ProxyPass / balancer://cluster/
|
||||||
|
ProxyPassReverse / balancer://cluster/
|
||||||
|
|
||||||
|
# For testing; don't want to wait forever for dead backend servers.
|
||||||
|
ProxyTimeout 5
|
||||||
'';
|
'';
|
||||||
services.httpd.virtualHosts.localhost = {
|
|
||||||
extraConfig = ''
|
|
||||||
<Location /server-status>
|
|
||||||
Require all granted
|
|
||||||
SetHandler server-status
|
|
||||||
</Location>
|
|
||||||
|
|
||||||
<Proxy balancer://cluster>
|
|
||||||
Require all granted
|
|
||||||
BalancerMember http://${nodes.backend1.config.networking.hostName} retry=0
|
|
||||||
BalancerMember http://${nodes.backend2.config.networking.hostName} retry=0
|
|
||||||
</Proxy>
|
|
||||||
|
|
||||||
ProxyStatus full
|
|
||||||
ProxyPass /server-status !
|
|
||||||
ProxyPass / balancer://cluster/
|
|
||||||
ProxyPassReverse / balancer://cluster/
|
|
||||||
|
|
||||||
# For testing; don't want to wait forever for dead backend servers.
|
|
||||||
ProxyTimeout 5
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
networking.firewall.allowedTCPPorts = [ 80 ];
|
|
||||||
};
|
};
|
||||||
|
};
|
||||||
backend1 = backend;
|
networking.firewall.allowedTCPPorts = [ 80 ];
|
||||||
backend2 = backend;
|
|
||||||
|
|
||||||
client = { ... }: { };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
testScript =
|
backend1 = backend;
|
||||||
''
|
backend2 = backend;
|
||||||
startAll;
|
|
||||||
|
|
||||||
$proxy->waitForUnit("httpd");
|
client = { ... }: { };
|
||||||
$backend1->waitForUnit("httpd");
|
};
|
||||||
$backend2->waitForUnit("httpd");
|
|
||||||
$client->waitForUnit("network.target");
|
|
||||||
|
|
||||||
# With the back-ends up, the proxy should work.
|
testScript = ''
|
||||||
$client->succeed("curl --fail http://proxy/");
|
start_all()
|
||||||
|
|
||||||
$client->succeed("curl --fail http://proxy/server-status");
|
proxy.wait_for_unit("httpd")
|
||||||
|
backend1.wait_for_unit("httpd")
|
||||||
|
backend2.wait_for_unit("httpd")
|
||||||
|
client.wait_for_unit("network.target")
|
||||||
|
|
||||||
# Block the first back-end.
|
# With the back-ends up, the proxy should work.
|
||||||
$backend1->block;
|
client.succeed("curl --fail http://proxy/")
|
||||||
|
|
||||||
# The proxy should still work.
|
client.succeed("curl --fail http://proxy/server-status")
|
||||||
$client->succeed("curl --fail http://proxy/");
|
|
||||||
|
|
||||||
$client->succeed("curl --fail http://proxy/");
|
# Block the first back-end.
|
||||||
|
backend1.block()
|
||||||
|
|
||||||
# Block the second back-end.
|
# The proxy should still work.
|
||||||
$backend2->block;
|
client.succeed("curl --fail http://proxy/")
|
||||||
|
client.succeed("curl --fail http://proxy/")
|
||||||
|
|
||||||
# Now the proxy should fail as well.
|
# Block the second back-end.
|
||||||
$client->fail("curl --fail http://proxy/");
|
backend2.block()
|
||||||
|
|
||||||
# But if the second back-end comes back, the proxy should start
|
# Now the proxy should fail as well.
|
||||||
# working again.
|
client.fail("curl --fail http://proxy/")
|
||||||
$backend2->unblock;
|
|
||||||
$client->succeed("curl --fail http://proxy/");
|
# But if the second back-end comes back, the proxy should start
|
||||||
'';
|
# working again.
|
||||||
|
backend2.unblock()
|
||||||
|
client.succeed("curl --fail http://proxy/")
|
||||||
|
'';
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user