Unverified Commit 29e6a1bb authored by Jörg Thalheim's avatar Jörg Thalheim Committed by GitHub
Browse files

cntr: 1.6.1 -> 2.0.0 (#473371)

parents feb58f85 6f40da31
Loading
Loading
Loading
Loading
+19 −17
Original line number Diff line number Diff line
@@ -31,15 +31,14 @@ let
        start_all()
        ${backend}.wait_for_unit("${backend}-nginx.service")
        ${backend}.wait_for_open_port(8181)
        # For some reason, the cntr command hangs when run without the &.
        # As such, we have to do some messy things to ensure we check the exitcode and output in a race-condition-safe manner
        ${backend}.execute(
            "(cntr attach -t ${backend} nginx sh -- -c 'curl localhost | grep Hello' > /tmp/result; echo $? > /tmp/exitcode; touch /tmp/done) &"
        )

        ${backend}.wait_for_file("/tmp/done")
        assert "0" == ${backend}.succeed("cat /tmp/exitcode").strip(), "non-zero exit code"
        assert "Hello" in ${backend}.succeed("cat /tmp/result"), "no greeting in output"
        # Test attach: uses host tools in container's network namespace
        # Curl localhost to verify we're in the container's network
        result = ${backend}.succeed("cntr attach -t ${backend} nginx curl -s localhost")
        assert "Hello" in result, f"no greeting in output: {result}"
        # Test exec: runs in container's native filesystem
        # Use nginx's own binary to verify exec works
        result = ${backend}.succeed("cntr exec -t ${backend} nginx -- nginx -v")
        assert "nginx" in result, f"expected nginx version: {result}"
      '';
    };

@@ -60,20 +59,23 @@ let
          privateNetwork = true;
          hostAddress = "172.16.0.1";
          localAddress = "172.16.0.2";
          config = { };
          config =
            { pkgs, ... }:
            {
              environment.systemPackages = [ pkgs.iputils ];
            };
        };
      };

    testScript = ''
      machine.start()
      machine.wait_for_unit("container@test.service")
      # I haven't observed the same hanging behaviour in this version as in the OCI version which necessetates this messy invocation, but it's probably better to be safe than sorry and use it here as well
      machine.execute(
          "(cntr attach test sh -- -c 'ping -c5 172.16.0.1'; echo $? > /tmp/exitcode; touch /tmp/done) &"
      )

      machine.wait_for_file("/tmp/done")
      assert "0" == machine.succeed("cat /tmp/exitcode").strip(), "non-zero exit code"
      # Test attach: container fs is mounted at /var/lib/cntr/
      # Writing to /var/lib/cntr/tmp/foo creates /tmp/foo in the container
      machine.succeed("cntr attach test touch /var/lib/cntr/tmp/cntr-attach-test")
      # Verify both that exec works and that the file from attach exists in container's /tmp
      machine.succeed("cntr exec test -- test -f /tmp/cntr-attach-test")
      machine.succeed("cntr exec test -- /run/current-system/sw/bin/ping -c1 172.16.0.1")
    '';
  };
in
+3 −3
Original line number Diff line number Diff line
@@ -7,16 +7,16 @@

rustPlatform.buildRustPackage rec {
  pname = "cntr";
  version = "1.6.1";
  version = "2.0.0";

  src = fetchFromGitHub {
    owner = "Mic92";
    repo = "cntr";
    rev = version;
    sha256 = "sha256-2tqPxbi8sKoEPq0/zQFsOrStEmQGlU8s81ohTfKeOmE=";
    sha256 = "sha256-4HBOUx9086nn3hRBLA4zuH0Dq+qDZHgo3DivmiEMh3w=";
  };

  cargoHash = "sha256-gWQ8seCuUSHuZUoNH9pnBTlzF9S0tHVLStnAiymLLbs=";
  cargoHash = "sha256-FBlKxQcQRkz5dYInot2WtZfUSAaX+7qlin+cLf3h8f4=";

  passthru.tests = nixosTests.cntr;