Skip to content

Commit f64785c

Browse files
pazoneleehinman
andauthored
[CI] BK Integration tests: Run non-sudo tests (#6045)
* Sudo test script refactoring * sudo param * Test non-sudo * Added apm to TF deployment * Test build non-sudo * removed apm * Fix Kibana config * Fix Kibana config * Fix Kibana config * Non-sudo test run * Non-sudo test run * Cleanup * Cleanup * stop reading system log files for OtelTest * Renamed sudo-integration-tests.sh to buildkite-integration-tests.sh --------- Co-authored-by: Lee E. Hinman <[email protected]>
1 parent 825a15d commit f64785c

File tree

6 files changed

+128
-73
lines changed

6 files changed

+128
-73
lines changed

.buildkite/bk.integration.pipeline.yml

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ steps:
3232
image: "docker.elastic.co/ci-agent-images/platform-ingest/buildkite-agent-beats-ci-with-hooks:0.5"
3333
useCustomGlobalHooks: true
3434

35-
- group: "Stateful(Sudo): Windows"
35+
- group: "Stateful: Windows"
3636
key: integration-tests-win
3737
depends_on:
3838
- integration-ess
39+
- package-it
3940
steps:
40-
- label: "Win2022:{{matrix}}"
41+
- label: "Win2022:sudo:{{matrix}}"
4142
command: |
4243
buildkite-agent artifact download build/distributions/** . --step 'package-it'
43-
.buildkite/scripts/integration-tests.ps1 {{matrix}}
44+
.buildkite/scripts/integration-tests.ps1 {{matrix}} true
4445
artifact_paths:
4546
- build/**
4647
agents:
@@ -53,15 +54,42 @@ steps:
5354
- fleet-privileged
5455
- upgrade
5556

56-
- group: "Stateful(Sudo): Ubuntu"
57+
- label: "Win2022:non-sudo:{{matrix}}"
58+
command: |
59+
buildkite-agent artifact download build/distributions/** . --step 'package-it'
60+
.buildkite/scripts/integration-tests.ps1 {{matrix}} false
61+
artifact_paths:
62+
- build/**
63+
agents:
64+
provider: "gcp"
65+
machineType: "n1-standard-8"
66+
image: "family/platform-ingest-elastic-agent-windows-2022"
67+
matrix:
68+
- default
69+
70+
- group: "Stateful:Ubuntu"
5771
key: integration-tests-ubuntu
5872
depends_on:
5973
- integration-ess
74+
- package-it
6075
steps:
61-
- label: "x86_64:Group: {{matrix}}"
76+
- label: "x86_64:non-sudo: {{matrix}}"
77+
command: |
78+
buildkite-agent artifact download build/distributions/** . --step 'package-it'
79+
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix}} false
80+
artifact_paths:
81+
- build/**
82+
agents:
83+
provider: "gcp"
84+
machineType: "n1-standard-8"
85+
image: "family/platform-ingest-elastic-agent-ubuntu-2404"
86+
matrix:
87+
- default
88+
89+
- label: "x86_64:sudo: {{matrix}}"
6290
command: |
6391
buildkite-agent artifact download build/distributions/** . --step 'package-it'
64-
.buildkite/scripts/steps/integration_tests_tf_sudo.sh {{matrix}}
92+
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix}} true
6593
artifact_paths:
6694
- build/**
6795
agents:
@@ -80,10 +108,10 @@ steps:
80108
- fleet-privileged
81109
- fleet-airgapped-privileged
82110

83-
- label: "arm:Group: {{matrix}}"
111+
- label: "arm:sudo: {{matrix}}"
84112
command: |
85113
buildkite-agent artifact download build/distributions/** . --step 'package-it'
86-
.buildkite/scripts/steps/integration_tests_tf_sudo.sh {{matrix}}
114+
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix}} true
87115
artifact_paths:
88116
- build/**
89117
agents:
@@ -102,16 +130,29 @@ steps:
102130
- fleet-privileged
103131
- fleet-airgapped-privileged
104132

105-
- group: "Stateful(Sudo): RHEL8"
133+
- label: "arm:non-sudo: {{matrix}}"
134+
command: |
135+
buildkite-agent artifact download build/distributions/** . --step 'package-it'
136+
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix}} false
137+
artifact_paths:
138+
- build/**
139+
agents:
140+
provider: "aws"
141+
imagePrefix: "platform-ingest-beats-ubuntu-2404-aarch64"
142+
instanceType: "m6g.xlarge"
143+
matrix:
144+
- default
145+
146+
- group: "Stateful(Sudo):RHEL8"
106147
key: integration-tests-rhel8
107148
depends_on:
108149
- package-it
109150
- integration-ess
110151
steps:
111-
- label: "x86_64:Group: rpm"
152+
- label: "x86_64:sudo:rpm"
112153
command: |
113154
buildkite-agent artifact download build/distributions/** . --step 'package-it'
114-
.buildkite/scripts/steps/integration_tests_tf_sudo.sh rpm
155+
.buildkite/scripts/steps/integration_tests_tf.sh rpm true
115156
artifact_paths:
116157
- build/**
117158
agents:

.buildkite/scripts/sudo-integration-tests.sh renamed to .buildkite/scripts/buildkite-integration-tests.sh

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,42 @@
11
#!/usr/bin/env bash
22

3-
# Fixes source asdf.sh, otherwise it relies on unexisting /root/.asdf directory
4-
export HOME=/opt/buildkite-agent
53

6-
# The script is used to run integration tests with sudo
7-
source /opt/buildkite-agent/hooks/pre-command
8-
source .buildkite/hooks/pre-command || echo "No pre-command hook found"
4+
GROUP_NAME=$1
5+
TEST_SUDO=$2
6+
7+
if [ -z "$GROUP_NAME" ]; then
8+
echo "Error: Specify the group name: sudo-integration-tests.sh [group_name]" >&2
9+
exit 1
10+
fi
11+
12+
if [ -z "$TEST_SUDO" ]; then
13+
echo "Error: Specify the test sudo: sudo-integration-tests.sh [group_name] [test_sudo]" >&2
14+
exit 1
15+
fi
16+
17+
if [ "$TEST_SUDO" == "true" ]; then
18+
echo "Re-initializing ASDF. The user is changed to root..."
19+
export HOME=/opt/buildkite-agent
20+
source /opt/buildkite-agent/hooks/pre-command
21+
source .buildkite/hooks/pre-command || echo "No pre-command hook found"
22+
fi
923

1024
# Make sure that all tools are installed
1125
asdf install
1226

13-
GROUP_NAME=$1
14-
1527
echo "~~~ Running integration tests as $USER"
1628
echo "~~~ Integration tests: ${GROUP_NAME}"
29+
1730
go install gotest.tools/gotestsum
1831
gotestsum --version
32+
1933
PACKAGE_VERSION="$(cat .package-version)"
2034
if [[ -n "$PACKAGE_VERSION" ]]; then
2135
PACKAGE_VERSION=${PACKAGE_VERSION}"-SNAPSHOT"
2236
fi
37+
2338
set +e
24-
TEST_BINARY_NAME="elastic-agent" AGENT_VERSION="${PACKAGE_VERSION}" SNAPSHOT=true gotestsum --no-color -f standard-quiet --junitfile "build/${GROUP_NAME}.integration.xml" --jsonfile "build/${GROUP_NAME}.integration.out.json" -- -tags integration -test.shuffle on -test.timeout 2h0m0s github.com/elastic/elastic-agent/testing/integration -v -args -integration.groups="${GROUP_NAME}" -integration.sudo=true
39+
TEST_BINARY_NAME="elastic-agent" AGENT_VERSION="${PACKAGE_VERSION}" SNAPSHOT=true gotestsum --no-color -f standard-quiet --junitfile "build/${GROUP_NAME}.integration.xml" --jsonfile "build/${GROUP_NAME}.integration.out.json" -- -tags integration -test.shuffle on -test.timeout 2h0m0s github.com/elastic/elastic-agent/testing/integration -v -args -integration.groups="${GROUP_NAME}" -integration.sudo="${TEST_SUDO}"
2540
TESTS_EXIT_STATUS=$?
2641
set -e
2742

.buildkite/scripts/integration-tests.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
param (
2-
[string]$GROUP_NAME
2+
[string]$GROUP_NAME,
3+
[string]$TEST_SUDO
34
)
45

56
echo "~~~ Preparing environment"
@@ -26,7 +27,7 @@ mage build:testBinaries
2627
try {
2728
Get-Ess-Stack -StackVersion $PACKAGE_VERSION
2829
Write-Output "~~~ Running integration test group: $GROUP_NAME as user: $env:USERNAME"
29-
gotestsum --no-color -f standard-quiet --junitfile "build/${GROUP_NAME}.integration.xml" --jsonfile "build/${GROUP_NAME}.integration.out.json" -- -tags=integration -shuffle=on -timeout=2h0m0s "github.com/elastic/elastic-agent/testing/integration" -v -args "-integration.groups=$GROUP_NAME" "-integration.sudo=true"
30+
gotestsum --no-color -f standard-quiet --junitfile "build/${GROUP_NAME}.integration.xml" --jsonfile "build/${GROUP_NAME}.integration.out.json" -- -tags=integration -shuffle=on -timeout=2h0m0s "github.com/elastic/elastic-agent/testing/integration" -v -args "-integration.groups=$GROUP_NAME" "-integration.sudo=$TEST_SUDO"
3031
} finally {
3132
ess_down
3233
# Generate HTML report if XML output exists

.buildkite/scripts/steps/integration_tests_tf.sh

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,57 @@
22
set -euo pipefail
33

44
source .buildkite/scripts/common2.sh
5+
56
source .buildkite/scripts/steps/ess.sh
67

8+
# Make sure that all tools are installed
9+
asdf install
10+
11+
GROUP_NAME=$1
12+
TEST_SUDO=$2
13+
if [ -z "$GROUP_NAME" ]; then
14+
echo "Error: Specify the group name: integration_tests_tf.sh [group_name]" >&2
15+
exit 1
16+
fi
17+
18+
if [ -z "$TEST_SUDO" ]; then
19+
echo "Error: Specify the test sudo: integration_tests_tf.sh [group_name] [test_sudo]" >&2
20+
exit 1
21+
fi
722

823
# Override the agent package version using a string with format <major>.<minor>.<patch>
924
# There is a time when the snapshot is not built yet, so we cannot use the latest version automatically
1025
# This file is managed by an automation (mage integration:UpdateAgentPackageVersion) that check if the snapshot is ready.
11-
OVERRIDE_AGENT_PACKAGE_VERSION="$(cat .package-version)"
12-
OVERRIDE_TEST_AGENT_VERSION=${OVERRIDE_AGENT_PACKAGE_VERSION}"-SNAPSHOT"
26+
OVERRIDE_STACK_VERSION="$(cat .package-version)"
27+
OVERRIDE_STACK_VERSION=${OVERRIDE_STACK_VERSION}"-SNAPSHOT"
1328

14-
echo "~~~ Bulding test binaries"
29+
echo "~~~ Building test binaries"
1530
mage build:testBinaries
1631

17-
ess_up $OVERRIDE_TEST_AGENT_VERSION || echo "Failed to start ESS stack" >&2
18-
trap 'ess_down' EXIT
32+
# If the step is retried, we start the stack again.
33+
# BUILDKITE_RETRY_COUNT == "0" for the first run
34+
# BUILDKITE_RETRY_COUNT > 0 for the retries
35+
if [[ "${BUILDKITE_RETRY_COUNT}" -gt 0 ]]; then
36+
echo "~~~ The steps is retried, starting the ESS stack again"
37+
trap 'ess_down' EXIT
38+
ess_up $OVERRIDE_STACK_VERSION || echo "Failed to start ESS stack" >&2
39+
else
40+
# For the first run, we start the stack in the start_ess.sh step and it sets the meta-data
41+
echo "~~~ Receiving ESS stack metadata"
42+
export ELASTICSEARCH_HOST=$(buildkite-agent meta-data get "es.host")
43+
export ELASTICSEARCH_USERNAME=$(buildkite-agent meta-data get "es.username")
44+
export ELASTICSEARCH_PASSWORD=$(buildkite-agent meta-data get "es.pwd")
45+
export KIBANA_HOST=$(buildkite-agent meta-data get "kibana.host")
46+
export KIBANA_USERNAME=$(buildkite-agent meta-data get "kibana.username")
47+
export KIBANA_PASSWORD=$(buildkite-agent meta-data get "kibana.pwd")
48+
fi
1949

50+
# Run integration tests
2051
echo "~~~ Running integration tests"
21-
AGENT_VERSION="8.16.0-SNAPSHOT" SNAPSHOT=true TEST_DEFINE_PREFIX=non_sudo_linux gotestsum --no-color -f standard-verbose --junitfile build/TEST-go-integration.xml --jsonfile build/TEST-go-integration.out.json -- -tags integration github.com/elastic/elastic-agent/testing/integration
52+
53+
if [ "$TEST_SUDO" == "true" ]; then
54+
sudo -E .buildkite/scripts/buildkite-integration-tests.sh $@
55+
else
56+
.buildkite/scripts/buildkite-integration-tests.sh $@
57+
fi
58+

.buildkite/scripts/steps/integration_tests_tf_sudo.sh

Lines changed: 0 additions & 46 deletions
This file was deleted.

test_infra/ess/deployment.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ resource "ec_deployment" "integration-testing" {
7070
kibana = {
7171
size = "1g"
7272
zone_count = 1
73+
config = {
74+
user_settings_json = jsonencode({
75+
"xpack.fleet.enableExperimental" = ["agentTamperProtectionEnabled"]
76+
"xpack.fleet.internal.registry.kibanaVersionCheckEnabled" = false
77+
"server.restrictInternalApis" = false
78+
})
79+
}
7380
}
7481

7582
integrations_server = {

0 commit comments

Comments
 (0)