Skip to content

Commit 2b61d40

Browse files
authored
[tests] Fix packetbeat system tests on windows (elastic#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
1 parent 5d37bd4 commit 2b61d40

File tree

5 files changed

+44
-26
lines changed

5 files changed

+44
-26
lines changed

.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/scripts/gcp_auth.sh

-14
This file was deleted.

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,8 @@ steps:
207207

208208
- label: ":windows: x-pack/packetbeat: Win 2022 System Tests"
209209
key: "mandatory-win-2022-system-tests"
210-
skip: "skipping due to elastic/beats#38142"
211210
command: |
212-
source .buildkite/scripts/gcp_auth.sh
211+
.buildkite/scripts/gcp_auth.ps1
213212
Set-Location -Path x-pack/packetbeat
214213
mage systemTest
215214
retry:
@@ -322,9 +321,8 @@ steps:
322321

323322
- label: ":windows: x-pack/packetbeat: Win 10 System Tests"
324323
key: "extended-win-10-system-tests"
325-
skip: "skipping due to elastic/beats#38142"
326324
command: |
327-
source .buildkite/scripts/gcp_auth.sh
325+
.buildkite/scripts/gcp_auth.ps1
328326
Set-Location -Path x-pack/packetbeat
329327
mage systemTest
330328
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)