From 8a981243f39a3f5da8a0615df5e040cd3cd80ccd Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Thu, 25 Jun 2020 08:52:20 -0400 Subject: [PATCH] e2e: lifecycle hook tests for batch and service jobs --- e2e/e2e_test.go | 1 + e2e/lifecycle/inputs/batch.nomad | 118 +++++++++++++++++++++ e2e/lifecycle/inputs/service.nomad | 160 +++++++++++++++++++++++++++++ e2e/lifecycle/lifecycle.go | 109 ++++++++++++++++++++ 4 files changed, 388 insertions(+) create mode 100644 e2e/lifecycle/inputs/batch.nomad create mode 100644 e2e/lifecycle/inputs/service.nomad create mode 100644 e2e/lifecycle/lifecycle.go diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index 0b0f024cfbef..f8d4032d3a84 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -17,6 +17,7 @@ import ( _ "github.com/hashicorp/nomad/e2e/deployment" _ "github.com/hashicorp/nomad/e2e/example" _ "github.com/hashicorp/nomad/e2e/hostvolumes" + _ "github.com/hashicorp/nomad/e2e/lifecycle" _ "github.com/hashicorp/nomad/e2e/metrics" _ "github.com/hashicorp/nomad/e2e/nomad09upgrade" _ "github.com/hashicorp/nomad/e2e/nomadexec" diff --git a/e2e/lifecycle/inputs/batch.nomad b/e2e/lifecycle/inputs/batch.nomad new file mode 100644 index 000000000000..afb0334f5a07 --- /dev/null +++ b/e2e/lifecycle/inputs/batch.nomad @@ -0,0 +1,118 @@ +# lifecycle hook test job for batch jobs. touches, removes, and tests +# for the existence of files to assert the order of running tasks. +# all tasks should exit 0 and the alloc dir should contain the following +# files: ./init-ran, ./main-ran, ./cleanup-run + +job "batch-lifecycle" { + + datacenters = ["dc1"] + + type = "batch" + + group "test" { + + task "init" { + + lifecycle { + hook = "prestart" + } + + driver = "docker" + + config { + image = "busybox:1" + command = "/bin/sh" + args = ["local/prestart.sh"] + } + + template { + data = <