Skip to content

Commit a719fe8

Browse files
[8.16](backport #42172) [tests] Fix packetbeat system tests on windows (#42602)
* [tests] Fix packetbeat system tests on windows (#42172) * Fix packetbeat system tests on windows * Add retry if needed in pre command hook * Add hook path * Undo retry changes * Remove retry in hook * Undo version change * Fix test * Do not skip npcap installation for system tests * Revert "Do not skip npcap installation for system tests" This reverts commit 90a8265. * Enable npcap installation on CI * use dot sourcing for ps * source in pre-command * test win10 image * fix image name * Revert "fix image name" This reverts commit 587a00e. * Revert "test win10 image" This reverts commit 95b7dea. * test win10 image * Revert "test win10 image" This reverts commit 7ae9b46. * Move out of hook * update gcp auth script * call script instead of dot sourcing (cherry picked from commit 2b61d40) # Conflicts: # .buildkite/x-pack/pipeline.xpack.packetbeat.yml * Update pipeline.xpack.packetbeat.yml * remove unused pre-command code --------- Co-authored-by: Marc Guasch <marc-gr@users.noreply.github.com> Co-authored-by: Marc Guasch <marc.guasch@elastic.co>
1 parent a49efe2 commit a719fe8

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

.buildkite/hooks/pre-command

-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ if [[ "${BUILDKITE_LABEL:-}" == *"Pipeline upload"* || "${BUILDKITE_LABEL:-}" ==
1313
fi
1414
fi
1515

16-
if [[ "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-packetbeat" && "$BUILDKITE_STEP_KEY" == *"system-tests"* ]]; then
17-
PRIVATE_CI_GCS_CREDENTIALS_SECRET=$(retry -t 5 -- vault kv get -field plaintext -format=json ${PRIVATE_CI_GCS_CREDENTIALS_PATH})
18-
export PRIVATE_CI_GCS_CREDENTIALS_SECRET
19-
fi
20-
2116
CPU_ARCH=$(uname -m)
2217
PLATFORM_TYPE=$(uname)
2318

.buildkite/scripts/gcp_auth.ps1

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Write-Host "~~~ Authenticating GCP"
2+
# Secrets must be redacted
3+
# https://buildkite.com/docs/pipelines/managing-log-output#redacted-environment-variables
4+
5+
$privateCIGCSServiceAccount = "kv/ci-shared/platform-ingest/gcp-platform-ingest-ci-service-account"
6+
$tempFileName = "google-cloud-credentials.json"
7+
$secretFileLocation = Join-Path $env:TEMP $tempFileName
8+
9+
$serviceAccountJsonSecret = Retry-Command -ScriptBlock {
10+
vault kv get -field=data -format=json $privateCIGCSServiceAccount | ConvertFrom-Json
11+
if ( -not $? ) { throw "Error during vault kv get" }
12+
}
13+
14+
New-Item -ItemType File -Path $secretFileLocation >$null
15+
$serviceAccountJsonPlaintextSecret = $serviceAccountJsonSecret.plaintext | ConvertTo-Json
16+
Set-Content -Path $secretFileLocation -Value $serviceAccountJsonPlaintextSecret
17+
if ( -not $?) { throw "Error retrieving the required field from the secret" }
18+
19+
gcloud auth activate-service-account --key-file $secretFileLocation
20+
Remove-Item -Path $secretFileLocation -Force

.buildkite/x-pack/pipeline.xpack.packetbeat.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ steps:
177177

178178
- label: ":windows: x-pack/packetbeat: Win 2022 System Tests"
179179
key: "mandatory-win-2022-system-tests"
180-
skip: "skipping due to elastic/beats#38142"
181180
command: |
181+
.buildkite/scripts/gcp_auth.ps1
182182
Set-Location -Path x-pack/packetbeat
183183
mage systemTest
184184
retry:
@@ -267,8 +267,8 @@ steps:
267267

268268
- label: ":windows: x-pack/packetbeat: Win 10 System Tests"
269269
key: "extended-win-10-system-tests"
270-
skip: "skipping due to elastic/beats#38142"
271270
command: |
271+
.buildkite/scripts/gcp_auth.ps1
272272
Set-Location -Path x-pack/packetbeat
273273
mage systemTest
274274
retry:

x-pack/packetbeat/magefile.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,7 @@ func TestPackages() error {
137137
}
138138

139139
func SystemTest(ctx context.Context) error {
140-
// Buildkite (CI) images have preinstalled npcap
141-
if os.Getenv("CI") == "true" {
142-
mg.SerialDeps(devtools.BuildSystemTestBinary)
143-
} else {
144-
mg.SerialDeps(xpacketbeat.GetNpcapInstaller, devtools.BuildSystemTestBinary)
145-
}
140+
mg.SerialDeps(xpacketbeat.GetNpcapInstaller, devtools.BuildSystemTestBinary)
146141

147142
args := devtools.DefaultGoTestIntegrationArgs()
148143
args.Packages = []string{"./tests/system/..."}

x-pack/packetbeat/tests/system/app_test.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
)
2525

2626
// Keep in sync with NpcapVersion in magefile.go.
27-
const NpcapVersion = "1.79"
27+
const NpcapVersion = "1.80"
2828

2929
func TestWindowsNpcapInstaller(t *testing.T) {
3030
if runtime.GOOS != "windows" {
@@ -65,7 +65,26 @@ func TestDevices(t *testing.T) {
6565
}
6666
t.Log("Expect interfaces:\n", expected)
6767

68+
ifcsLoop:
6869
for _, ifc := range ifcs {
69-
assert.Contains(t, stdout, ifc.Name)
70+
if strings.Contains(stdout, ifc.Name) {
71+
continue ifcsLoop
72+
}
73+
addrs, err := ifc.Addrs()
74+
assert.NoError(t, err)
75+
maddrs, err := ifc.MulticastAddrs()
76+
assert.NoError(t, err)
77+
addrs = append(addrs, maddrs...)
78+
for _, addr := range addrs {
79+
s := addr.String()
80+
// remove the network mask suffix
81+
if idx := strings.Index(s, "/"); idx > -1 {
82+
s = s[:idx]
83+
}
84+
if strings.Contains(stdout, s) {
85+
continue ifcsLoop
86+
}
87+
}
88+
t.Errorf("interface %q not found", ifc.Name)
7089
}
7190
}

0 commit comments

Comments
 (0)