From 37df529e7a058846eb989038b6d5198a32d7f107 Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Mon, 26 Jun 2023 09:51:18 -0500 Subject: [PATCH] e2e: refactor pids isolation tests (#17717) This PR refactors some old PID isolation tests to make use of the e2e/v3 packages. Should be quite a bit easier to read. Adds 'alloc exec' capability to the jobs3 package. --- e2e/isolation/doc.go | 3 + e2e/isolation/input/alloc_exec.hcl | 41 +++ e2e/isolation/input/alloc_exec.nomad | 28 -- ...oc_exec_java.nomad => alloc_exec_java.hcl} | 40 ++- e2e/isolation/input/{exec.nomad => exec.hcl} | 23 +- .../input/{exec_host.nomad => exec_host.hcl} | 23 +- e2e/isolation/input/{java.nomad => java.hcl} | 38 ++- .../input/{java_host.nomad => java_host.hcl} | 38 ++- .../input/{raw_exec.nomad => raw_exec.hcl} | 23 +- e2e/isolation/pids.go | 304 ------------------ e2e/isolation/pids_test.go | 118 +++++++ e2e/v3/jobs3/allocexec3.go | 70 ++++ 12 files changed, 379 insertions(+), 370 deletions(-) create mode 100644 e2e/isolation/doc.go create mode 100644 e2e/isolation/input/alloc_exec.hcl delete mode 100644 e2e/isolation/input/alloc_exec.nomad rename e2e/isolation/input/{alloc_exec_java.nomad => alloc_exec_java.hcl} (57%) rename e2e/isolation/input/{exec.nomad => exec.hcl} (66%) rename e2e/isolation/input/{exec_host.nomad => exec_host.hcl} (69%) rename e2e/isolation/input/{java.nomad => java.hcl} (62%) rename e2e/isolation/input/{java_host.nomad => java_host.hcl} (63%) rename e2e/isolation/input/{raw_exec.nomad => raw_exec.hcl} (68%) delete mode 100644 e2e/isolation/pids.go create mode 100644 e2e/isolation/pids_test.go create mode 100644 e2e/v3/jobs3/allocexec3.go diff --git a/e2e/isolation/doc.go b/e2e/isolation/doc.go new file mode 100644 index 000000000..d423392a9 --- /dev/null +++ b/e2e/isolation/doc.go @@ -0,0 +1,3 @@ +// Package isolation provides tests around various kinds of isolation, such as +// artifact downloading, PID namespacing, and chroot task environments. +package isolation diff --git a/e2e/isolation/input/alloc_exec.hcl b/e2e/isolation/input/alloc_exec.hcl new file mode 100644 index 000000000..c0986d290 --- /dev/null +++ b/e2e/isolation/input/alloc_exec.hcl @@ -0,0 +1,41 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +job "alloc_exec" { + + constraint { + attribute = "${attr.kernel.name}" + value = "linux" + } + + group "group" { + + update { + min_healthy_time = "2s" + } + + reschedule { + attempts = 0 + unlimited = false + } + + restart { + attempts = 0 + mode = "fail" + } + + task "sleep" { + driver = "exec" + + config { + command = "sleep" + args = ["infinity"] + } + + resources { + cpu = 10 + memory = 16 + } + } + } +} diff --git a/e2e/isolation/input/alloc_exec.nomad b/e2e/isolation/input/alloc_exec.nomad deleted file mode 100644 index e6ea63b63..000000000 --- a/e2e/isolation/input/alloc_exec.nomad +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - -job "alloc_exec" { - datacenters = ["dc1"] - type = "service" - - constraint { - attribute = "${attr.kernel.name}" - value = "linux" - } - - group "main" { - task "main" { - driver = "exec" - - config { - command = "/bin/sleep" - args = ["30s"] - } - - resources { - cpu = 100 - memory = 64 - } - } - } -} diff --git a/e2e/isolation/input/alloc_exec_java.nomad b/e2e/isolation/input/alloc_exec_java.hcl similarity index 57% rename from e2e/isolation/input/alloc_exec_java.nomad rename to e2e/isolation/input/alloc_exec_java.hcl index 12f89c79d..46092540a 100644 --- a/e2e/isolation/input/alloc_exec_java.nomad +++ b/e2e/isolation/input/alloc_exec_java.hcl @@ -1,11 +1,28 @@ # Copyright (c) HashiCorp, Inc. # SPDX-License-Identifier: MPL-2.0 -job "java_sleep" { - datacenters = ["dc1"] - type = "batch" +job "java_exec" { - group "java" { + constraint { + attribute = "${attr.kernel.name}" + value = "linux" + } + + group "group" { + + update { + min_healthy_time = "2s" + } + + reschedule { + attempts = 0 + unlimited = false + } + + restart { + attempts = 0 + mode = "fail" + } task "build" { lifecycle { @@ -24,19 +41,30 @@ job "java_sleep" { data = <