Skip to content

Commit 90dbd76

Browse files
Enable E2E agent tests (#3595)
* Enable E2E agent container tests * replace deprecated testcontainers.GenericBindMountSource * enable agent install tests * Allow e2e tests to run in vagrant, fix e2e archive extraction
1 parent e0f0b00 commit 90dbd76

7 files changed

+263
-194
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ e2e-docker-stop: ## - Tear down testing Elasticsearch and Kibana instances
367367
@$(MAKE) int-docker-stop
368368

369369
.PHONY: test-e2e
370-
test-e2e: docker-cover-e2e-binaries e2e-certs build-docker ## - Setup and run the blackbox end to end test suite
370+
test-e2e: docker-cover-e2e-binaries build-e2e-agent-image e2e-certs build-docker ## - Setup and run the blackbox end to end test suite
371371
@mkdir -p build/e2e-cover
372372
@$(MAKE) e2e-docker-start
373373
@set -o pipefail; $(MAKE) test-e2e-set | tee build/test-e2e.out

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ pr: https://github.com/elastic/fleet-server/pull/2079
125125
issue: https://github.com/elastic/elastic-agent/issues/931
126126
```
127127
128+
### Vagrant
129+
130+
A Vagrantfile is provided to get an environment capable of developing and testing fleet-server.
131+
In order to provision the vagrant box run:
132+
133+
```shell
134+
vagrant plugin install vagrant-docker-compose
135+
vagrant up
136+
```
137+
128138
### Development build
129139
130140
To compile the fleet-server in development mode set the env var `DEV=true`.

Vagrantfile

+15-14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ Vagrant.configure("2") do |config|
77
vbox.cpus = 6
88
end
99

10+
# require plugin https://github.com/leighmcculloch/vagrant-docker-compose
11+
# vagrant plugin install vagrant-docker-compose
12+
config.vagrant.plugins = "vagrant-docker-compose"
13+
14+
# install docker and docker-compose
15+
config.vm.provision :docker
16+
config.vm.provision :docker_compose
17+
1018
config.vm.define "fleet-dev" do |nodeconfig|
1119
nodeconfig.vm.box = "ubuntu/jammy64"
1220

@@ -21,23 +29,15 @@ Vagrant.configure("2") do |config|
2129
# fleet-server needs the agent, so let's mount it all
2230
nodeconfig.vm.synced_folder "../", "/vagrant"
2331
nodeconfig.vm.provider "virtualbox" do |vb|
24-
# Display the VirtualBox GUI when booting the machine
2532
vb.gui = false
26-
vb.customize ["modifyvm", :id, "--vram", "128"]
27-
# Customize the amount of memory on the VM:
28-
vb.memory = "2048"
33+
vb.memory = 8192
34+
vb.cpus = 2
35+
vb.customize ["modifyvm", :id, "--ioapic", "on"]
2936
end
30-
$user_script = <<-SCRIPT
31-
GOPATH=$(go env GOPATH) # use Go's default
32-
mkdir -p $GOPATH/src/github.com/magefile
33-
cd $GOPATH/src/github.com/magefile
34-
git clone https://github.com/magefile/mage.git
35-
cd $GOPATH/src/github.com/magefile/mage
36-
go run bootstrap.go
37-
SCRIPT
38-
39-
nodeconfig.vm.provision "root-shell", type: "shell", inline: <<-SHELL
37+
38+
nodeconfig.vm.provision "shell", inline: <<-SHELL
4039
apt-get update
40+
apt-get upgrade -y
4141
apt-get install -y \
4242
build-essential \
4343
curl \
@@ -56,6 +56,7 @@ Vagrant.configure("2") do |config|
5656
tar -xf /tmp/mage.tar.gz
5757
mv mage /usr/local/bin
5858
SHELL
59+
nodeconfig.vm.provision "shell", reboot: true
5960
end
6061

6162
end

testing/e2e/agent_container_test.go

+41-30
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
// or more contributor license agreements. Licensed under the Elastic License;
33
// you may not use this file except in compliance with the Elastic License.
44

5-
// FIXME(ml): test suite is disabled by additional build flag.
6-
// we do not want to rely on agent builds in our pipeline.
7-
8-
//go:build e2e && ignore
5+
//go:build e2e
96

107
package e2e
118

@@ -15,10 +12,14 @@ import (
1512
"os"
1613
"os/exec"
1714
"path/filepath"
15+
"strings"
1816
"testing"
1917
"time"
2018

2119
"github.com/elastic/fleet-server/testing/e2e/scaffold"
20+
21+
"github.com/docker/docker/api/types/container"
22+
"github.com/docker/docker/api/types/mount"
2223
"github.com/stretchr/testify/suite"
2324
"github.com/testcontainers/testcontainers-go"
2425
)
@@ -115,11 +116,15 @@ func (suite *AgentContainerSuite) TestHTTP() {
115116
},
116117
ExposedPorts: []string{"8220/tcp"},
117118
Networks: []string{"integration_default"},
118-
Mounts: testcontainers.ContainerMounts{
119-
testcontainers.ContainerMount{
120-
Source: &testcontainers.GenericBindMountSource{suite.CoverPath},
119+
HostConfigModifier: func(cfg *container.HostConfig) {
120+
if cfg.Mounts == nil {
121+
cfg.Mounts = make([]mount.Mount, 0)
122+
}
123+
cfg.Mounts = append(cfg.Mounts, mount.Mount{
124+
Type: mount.TypeBind,
125+
Source: suite.CoverPath,
121126
Target: "/cover",
122-
},
127+
})
123128
},
124129
WaitingFor: containerWaitForHealthyStatus(),
125130
}
@@ -138,11 +143,6 @@ func (suite *AgentContainerSuite) TestHTTP() {
138143
}
139144

140145
func (suite *AgentContainerSuite) TestWithSecretFiles() {
141-
// Create a service token file in the temp test dir
142-
dir := suite.T().TempDir()
143-
err := os.WriteFile(filepath.Join(dir, "service-token"), []byte(suite.ServiceToken), 0644)
144-
suite.Require().NoError(err)
145-
146146
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
147147
defer cancel()
148148

@@ -180,17 +180,20 @@ func (suite *AgentContainerSuite) TestWithSecretFiles() {
180180
HostFilePath: filepath.Join(suite.CertPath, "passphrase"),
181181
ContainerFilePath: "/tmp/passphrase",
182182
FileMode: 0644,
183+
}, {
184+
Reader: strings.NewReader(suite.ServiceToken),
185+
ContainerFilePath: "/token/service-token",
186+
FileMode: 0644,
183187
}},
184-
Mounts: testcontainers.ContainerMounts{
185-
testcontainers.ContainerMount{
186-
Source: &testcontainers.GenericBindMountSource{dir},
187-
Target: "/token",
188-
ReadOnly: true,
189-
},
190-
testcontainers.ContainerMount{
191-
Source: &testcontainers.GenericBindMountSource{suite.CoverPath},
188+
HostConfigModifier: func(cfg *container.HostConfig) {
189+
if cfg.Mounts == nil {
190+
cfg.Mounts = make([]mount.Mount, 0)
191+
}
192+
cfg.Mounts = append(cfg.Mounts, mount.Mount{
193+
Type: mount.TypeBind,
194+
Source: suite.CoverPath,
192195
Target: "/cover",
193-
},
196+
})
194197
},
195198
WaitingFor: containerWaitForHealthyStatus().WithTLS(true, nil),
196199
}
@@ -252,11 +255,15 @@ func (suite *AgentContainerSuite) TestSleep10m() {
252255
ContainerFilePath: "/tmp/passphrase",
253256
FileMode: 0644,
254257
}},
255-
Mounts: testcontainers.ContainerMounts{
256-
testcontainers.ContainerMount{
257-
Source: &testcontainers.GenericBindMountSource{suite.CoverPath},
258+
HostConfigModifier: func(cfg *container.HostConfig) {
259+
if cfg.Mounts == nil {
260+
cfg.Mounts = make([]mount.Mount, 0)
261+
}
262+
cfg.Mounts = append(cfg.Mounts, mount.Mount{
263+
Type: mount.TypeBind,
264+
Source: suite.CoverPath,
258265
Target: "/cover",
259-
},
266+
})
260267
},
261268
WaitingFor: containerWaitForHealthyStatus().WithTLS(true, nil),
262269
}
@@ -323,11 +330,15 @@ func (suite *AgentContainerSuite) TestDockerAgent() {
323330
ContainerFilePath: "/tmp/passphrase",
324331
FileMode: 0644,
325332
}},
326-
Mounts: testcontainers.ContainerMounts{
327-
testcontainers.ContainerMount{
328-
Source: &testcontainers.GenericBindMountSource{suite.CoverPath},
333+
HostConfigModifier: func(cfg *container.HostConfig) {
334+
if cfg.Mounts == nil {
335+
cfg.Mounts = make([]mount.Mount, 0)
336+
}
337+
cfg.Mounts = append(cfg.Mounts, mount.Mount{
338+
Type: mount.TypeBind,
339+
Source: suite.CoverPath,
329340
Target: "/cover",
330-
},
341+
})
331342
},
332343
WaitingFor: containerWaitForHealthyStatus().WithTLS(true, nil),
333344
}

0 commit comments

Comments
 (0)