Skip to content

Commit ece91fe

Browse files
[E2E Testing] mage targets to interact with VMs and cloud stack (#3887)
This commit adds a number of mage targets to improve developer experience when using the integration test framework. Those targets aim to easy how to login into VMs and run tests from there as well as how to access the Cloud Stacks. The targets added are: - integration:deployDebugTools - integration:deployEnvFile - integration:generateEnvFile - integration:listInstances - integration:printState - integration:ssh - integration:stacks --------- Co-authored-by: Pierre HILBERT <pierre.hilbert@elastic.co>
1 parent 08ac21a commit ece91fe

File tree

2 files changed

+430
-0
lines changed

2 files changed

+430
-0
lines changed

docs/test-framework-dev-guide.md

+80
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,60 @@ when running them manually, such as `ELASTICSEARCH_HOST`, `ELASTICSEARCH_USERNAM
134134

135135
### Debugging tests
136136

137+
#### Manually debugging tests on VMs
138+
Many of the integration tests will install the Elastic-Agent and/or
139+
require root to run, which makes it hard to just run them on our work
140+
machines, the best way to circumvent that is to debug the tests
141+
directly on a VM. `mage integration:DeployDebugTools` will show a menu
142+
to select a VM and then install the common debugging tools: Delve,
143+
Mage and Docker. It will also create the `~/elastic-agent` folder
144+
containing the Git repository (required to package from within the VM)
145+
and the last version of the code uploaded to the VM. This allows you
146+
to easily build/package the Elastic-Agent from within the VM as well
147+
as run any tests.
148+
149+
After deploying the debug tools, `mage integrationDeployEnvFile` will
150+
create a `env.sh` and copy it to a selected VM, sourcing it will allow
151+
you to any test against the Cloud Stack you selected.
152+
153+
Example of how to run a test from within the VM:
154+
```
155+
## Run a single test
156+
SNAPSHOT=true TEST_PLATFORMS="linux/amd64" mage integration:single TestLogIngestionFleetManaged
157+
## Let's suppose it has failed
158+
159+
## Install DebugTools
160+
mage -v integration:DeployDebugTools
161+
162+
## Generate and deploy env file
163+
mage -v integration:DeployEnvFile
164+
165+
## SSH into the VM
166+
$(mage integration:SSHVM)
167+
168+
## From inside the VM, the test needs root
169+
sudo su
170+
source ./env.sh
171+
cd elastic-agent
172+
## Any flags passed to the test binary go after the '--', they also need to
173+
## include the `test.` prefix if they're for `go test`
174+
TEST_DEFINE_PREFIX=gambiarra dlv test ./testing/integration/ --build-flags="-tags integration" -- -test.v -test.run TestLogIngestionFleetManaged
175+
```
176+
177+
**A Delve trick**
178+
If you didn't build the Elastic-Agent directly on the machine you're
179+
debugging, it is very likely the location of the source code is
180+
different, hence delve cannot show you the code it is running. To
181+
solve this, once on Delve shell, run:
182+
``
183+
config substitute-path /go/src/github.com/elastic/elastic-agent /home/ubuntu/elastic-agent`
184+
``
185+
where:
186+
- `/go/src/github.com/elastic/elastic-agent` is the path annotated in
187+
the binary you are debugging (the one Delve shows).
188+
- `/home/ubuntu/elastic-agent` is where Delve should read the source
189+
code form.
190+
137191
#### Auto diagnostics retrieval
138192
When an integration test fails the testing fixture will try its best to automatically collect the diagnostic
139193
information of the installed Elastic Agent. In the case that diagnostics is collected the test runner will
@@ -172,6 +226,32 @@ with `go test`. E.g.:
172226
TEST_DEFINE_PREFIX=gambiarra go test -v -tags integration -run TestProxyURL ./testing/integration/
173227
```
174228

229+
## Connecting to VMs and running tests
230+
### Connecting to VMs
231+
All VMs (including Windows) support connections via SSH, the framework
232+
generates and stores the necessary SSH keys to access the VMs, the
233+
easiest way to connect to them is using the SSH command returned by
234+
`mage integration:SSHVM`. It will list the VMs and ask to select
235+
one.
236+
237+
On a Unix shell you can run `$(mage integration:SSHVM)`, the menu is
238+
printed to stderr and the SSH command to stdout. After selecting the
239+
VM you will have shell connected to it.
240+
241+
### Credentials for cloud stack/projects
242+
All cloud deployments and projects can be listed with `mage
243+
integration:listStacks`, they can be used to manually connect to
244+
Kibana and Elasticsearch.
245+
246+
If you need to manually run tests against any deployments, `mage
247+
integration:GenerateEnvFile` will generate a file called `env.sh` that
248+
exports environment variables for Unix compatible shells, you can load
249+
them into your shell by running `source ./env.sh`.
250+
251+
To easily deploy the credentials to any VM, just run `mage
252+
integration:DeployEnvFile`. A menu will ask for the desired Stack and
253+
VM.
254+
175255
## Writing tests
176256

177257
Write integration and E2E tests by adding them to the `testing/integration`

0 commit comments

Comments
 (0)