2020-01-22 21:55:17 +00:00
|
|
|
# End to End Tests
|
2018-03-09 22:15:12 +00:00
|
|
|
|
2020-08-20 03:22:35 +00:00
|
|
|
This package contains integration tests. Unlike tests alongside Nomad code,
|
|
|
|
these tests expect there to already be a functional Nomad cluster accessible
|
|
|
|
(either on localhost or via the `NOMAD_ADDR` env var).
|
2018-03-09 22:15:12 +00:00
|
|
|
|
2020-09-18 15:27:24 +00:00
|
|
|
See [`framework/doc.go`](framework/doc.go) for how to write tests.
|
2019-01-03 19:24:58 +00:00
|
|
|
|
2020-08-20 03:22:35 +00:00
|
|
|
The `NOMAD_E2E=1` environment variable must be set for these tests to run.
|
2019-01-03 19:24:58 +00:00
|
|
|
|
2020-01-22 21:55:17 +00:00
|
|
|
## Provisioning Test Infrastructure on AWS
|
|
|
|
|
2020-09-18 15:27:24 +00:00
|
|
|
The `terraform/` folder has provisioning code to spin up a Nomad cluster on
|
|
|
|
AWS. You'll need both Terraform and AWS credentials to setup AWS instances on
|
|
|
|
which e2e tests will run. See the
|
2021-03-08 13:50:13 +00:00
|
|
|
[README](https://github.com/hashicorp/nomad/blob/main/e2e/terraform/README.md)
|
2020-09-18 15:27:24 +00:00
|
|
|
for details. The number of servers and clients is configurable, as is the
|
|
|
|
specific build of Nomad to deploy and the configuration file for each client
|
|
|
|
and server.
|
2020-01-22 21:55:17 +00:00
|
|
|
|
2020-09-18 15:27:24 +00:00
|
|
|
## Provisioning Local Clusters
|
2020-01-22 21:55:17 +00:00
|
|
|
|
2020-09-18 15:27:24 +00:00
|
|
|
To run tests against a local cluster, you'll need to make sure the following
|
|
|
|
environment variables are set:
|
2020-01-22 21:55:17 +00:00
|
|
|
|
2020-09-18 15:27:24 +00:00
|
|
|
* `NOMAD_ADDR` should point to one of the Nomad servers
|
|
|
|
* `CONSUL_HTTP_ADDR` should point to one of the Consul servers
|
|
|
|
* `NOMAD_E2E=1`
|
2020-01-22 21:55:17 +00:00
|
|
|
|
2020-09-18 15:27:24 +00:00
|
|
|
_TODO: the scripts in `./bin` currently work only with Terraform, it would be
|
|
|
|
nice for us to have a way to deploy Nomad to Vagrant or local clusters._
|
2020-02-04 15:37:00 +00:00
|
|
|
|
2020-01-22 21:55:17 +00:00
|
|
|
## Running
|
|
|
|
|
|
|
|
After completing the provisioning step above, you can set the client
|
|
|
|
environment for `NOMAD_ADDR` and run the tests as shown below:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
# from the ./e2e/terraform directory, set your client environment
|
|
|
|
# if you haven't already
|
|
|
|
$(terraform output environment)
|
|
|
|
|
|
|
|
cd ..
|
2022-03-25 18:44:16 +00:00
|
|
|
go test -v ./...
|
2019-01-03 19:24:58 +00:00
|
|
|
```
|
2020-01-22 21:55:17 +00:00
|
|
|
|
2020-01-29 20:52:34 +00:00
|
|
|
If you want to run a specific suite, you can specify the `-suite` flag as
|
|
|
|
shown below. Only the suite with a matching `Framework.TestSuite.Component`
|
|
|
|
will be run, and all others will be skipped.
|
2020-02-04 15:37:00 +00:00
|
|
|
|
2020-01-29 20:52:34 +00:00
|
|
|
```sh
|
|
|
|
go test -v -suite=Consul .
|
|
|
|
```
|
|
|
|
|
2020-01-22 21:55:17 +00:00
|
|
|
If you want to run a specific test, you'll need to regex-escape some of the
|
|
|
|
test's name so that the test runner doesn't skip over framework struct method
|
|
|
|
names in the full name of the tests:
|
|
|
|
|
|
|
|
```sh
|
2020-01-29 20:52:34 +00:00
|
|
|
go test -v . -run 'TestE2E/Consul/\*consul\.ScriptChecksE2ETest/TestGroup'
|
2020-08-20 03:22:35 +00:00
|
|
|
^ ^ ^ ^
|
|
|
|
| | | |
|
2020-09-18 15:27:24 +00:00
|
|
|
Component | | Test func
|
2020-08-20 03:22:35 +00:00
|
|
|
| |
|
|
|
|
Go Package Struct
|
2020-01-29 20:52:34 +00:00
|
|
|
```
|
2020-02-04 15:37:00 +00:00
|
|
|
|
2022-03-25 18:44:16 +00:00
|
|
|
We're also in the process of migrating to "stdlib-style" tests that
|
|
|
|
use the standard go `testing` package without a notion of "suite". You
|
|
|
|
can run these with `-run` regexes the same way you would any other go
|
|
|
|
test:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
go test -v . -run TestExample/TestExample_Simple
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2020-02-04 15:37:00 +00:00
|
|
|
## I Want To...
|
|
|
|
|
|
|
|
### ...SSH Into One Of The Test Machines
|
|
|
|
|
|
|
|
You can use the Terraform output to find the IP address. The keys will
|
|
|
|
in the `./terraform/keys/` directory.
|
|
|
|
|
|
|
|
```sh
|
|
|
|
ssh -i keys/nomad-e2e-*.pem ubuntu@${EC2_IP_ADDR}
|
|
|
|
```
|
|
|
|
|
2020-08-20 03:22:35 +00:00
|
|
|
Run `terraform output` for IP addresses and details.
|
|
|
|
|
2020-02-04 15:37:00 +00:00
|
|
|
### ...Deploy a Cluster of Mixed Nomad Versions
|
|
|
|
|
2021-05-10 20:25:04 +00:00
|
|
|
The `variables.tf` file describes the `nomad_version`, and
|
|
|
|
`nomad_local_binary` variables that can be used for most circumstances. But if
|
2020-09-18 15:27:24 +00:00
|
|
|
you want to deploy mixed Nomad versions, you can provide a list of versions in
|
|
|
|
your `terraform.tfvars` file.
|
2020-02-04 15:37:00 +00:00
|
|
|
|
2020-09-18 15:27:24 +00:00
|
|
|
For example, if you want to provision 3 servers all using Nomad 0.12.1, and 2
|
|
|
|
Linux clients using 0.12.1 and 0.12.2, you can use the following variables:
|
2020-02-04 15:37:00 +00:00
|
|
|
|
2020-09-18 15:27:24 +00:00
|
|
|
```hcl
|
|
|
|
# will be used for servers
|
|
|
|
nomad_version = "0.12.1"
|
2020-02-04 15:37:00 +00:00
|
|
|
|
2020-09-18 15:27:24 +00:00
|
|
|
# will override the nomad_version for Linux clients
|
|
|
|
nomad_version_client_linux = [
|
|
|
|
"0.12.1",
|
|
|
|
"0.12.2"
|
2020-02-04 15:37:00 +00:00
|
|
|
]
|
|
|
|
```
|
|
|
|
|
2020-09-18 15:27:24 +00:00
|
|
|
### ...Deploy Custom Configuration Files
|
|
|
|
|
|
|
|
Set the `profile` field to `"custom"` and put the configuration files in
|
|
|
|
`./terraform/config/custom/` as described in the
|
2021-03-08 13:50:13 +00:00
|
|
|
[README](https://github.com/hashicorp/nomad/blob/main/e2e/terraform/README.md#Profiles).
|
2020-09-18 15:27:24 +00:00
|
|
|
|
2020-02-04 15:37:00 +00:00
|
|
|
### ...Deploy More Than 4 Linux Clients
|
|
|
|
|
2020-09-18 15:27:24 +00:00
|
|
|
Use the `"custom"` profile as described above.
|
|
|
|
|
|
|
|
### ...Change the Nomad Version After Provisioning
|
|
|
|
|
2021-05-10 20:25:04 +00:00
|
|
|
You can update the `nomad_version` variable, or simply rebuild the binary you
|
|
|
|
have at the `nomad_local_binary` path so that Terraform picks up the
|
|
|
|
changes. Then run `terraform plan`/`terraform apply` again. This will update
|
|
|
|
Nomad in place, making the minimum amount of changes necessary.
|