From b1672eee0cc014408bff056375436fb25d6235ab Mon Sep 17 00:00:00 2001 From: Richard Marko Date: Wed, 24 Feb 2021 14:10:22 +0100 Subject: [PATCH 1/2] nixosTests.cntr: init --- nixos/tests/all-tests.nix | 1 + nixos/tests/cntr.nix | 63 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 nixos/tests/cntr.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 62188ddf9e8d..aa7c291ba654 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -64,6 +64,7 @@ in cjdns = handleTest ./cjdns.nix {}; clickhouse = handleTest ./clickhouse.nix {}; cloud-init = handleTest ./cloud-init.nix {}; + cntr = handleTest ./cntr.nix {}; cockroachdb = handleTestOn ["x86_64-linux"] ./cockroachdb.nix {}; consul = handleTest ./consul.nix {}; containers-bridge = handleTest ./containers-bridge.nix {}; diff --git a/nixos/tests/cntr.nix b/nixos/tests/cntr.nix new file mode 100644 index 000000000000..8cffd97459d0 --- /dev/null +++ b/nixos/tests/cntr.nix @@ -0,0 +1,63 @@ +# Test for cntr tool +{ system ? builtins.currentSystem, config ? { } +, pkgs ? import ../.. { inherit system config; }, lib ? pkgs.lib }: + +let + inherit (import ../lib/testing-python.nix { inherit system pkgs; }) makeTest; + + mkOCITest = backend: + makeTest { + name = "cntr-${backend}"; + + meta = { maintainers = with lib.maintainers; [ srk mic92 ]; }; + + nodes = { + ${backend} = { pkgs, ... }: { + environment.systemPackages = [ pkgs.cntr ]; + virtualisation.oci-containers = { + inherit backend; + containers.nginx = { + image = "nginx-container"; + imageFile = pkgs.dockerTools.examples.nginx; + ports = [ "8181:80" ]; + }; + }; + }; + }; + + testScript = '' + start_all() + ${backend}.wait_for_unit("${backend}-nginx.service") + result = ${backend}.wait_until_succeeds( + "cntr attach -t ${backend} nginx sh -- -c 'curl localhost | grep Hello'" + ) + assert "Hello" in result + ''; + }; + + mkContainersTest = makeTest { + name = "cntr-containers"; + + meta = with pkgs.lib.maintainers; { maintainers = [ sorki mic92 ]; }; + + machine = { lib, ... }: { + environment.systemPackages = [ pkgs.cntr ]; + containers.test = { + autoStart = true; + privateNetwork = true; + hostAddress = "172.16.0.1"; + localAddress = "172.16.0.2"; + config = { }; + }; + }; + + testScript = '' + machine.start() + machine.wait_for_unit("container@test.service") + machine.succeed("cntr attach test sh -- -c 'ping -c5 172.16.0.1'") + ''; + }; +in { + nixos-container = mkContainersTest; +} // (lib.foldl' (attrs: backend: attrs // { ${backend} = mkOCITest backend; }) + { } [ "docker" "podman" ]) From c520a26b7e8a1754697658dc29fd247a9758d719 Mon Sep 17 00:00:00 2001 From: Richard Marko Date: Thu, 4 Mar 2021 11:49:53 +0100 Subject: [PATCH 2/2] cntr: add passthru.tests --- pkgs/applications/virtualization/cntr/default.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/applications/virtualization/cntr/default.nix b/pkgs/applications/virtualization/cntr/default.nix index 9b57be87e443..ebe1644e96b9 100644 --- a/pkgs/applications/virtualization/cntr/default.nix +++ b/pkgs/applications/virtualization/cntr/default.nix @@ -1,4 +1,4 @@ -{ lib, rustPlatform, fetchFromGitHub }: +{ lib, rustPlatform, fetchFromGitHub, nixosTests }: rustPlatform.buildRustPackage rec { pname = "cntr"; @@ -13,6 +13,10 @@ rustPlatform.buildRustPackage rec { cargoSha256 = "sha256-o8o/ixjYdnezQZEp78brjmR2lvQbiwCJr4Y97tHiYbk="; + passthru.tests = { + nixos = nixosTests.cntr; + }; + meta = with lib; { description = "A container debugging tool based on FUSE"; homepage = "https://github.com/Mic92/cntr";