Skip to content

Commit

Permalink
[tests] Fix packetbeat system tests on windows (elastic#42172)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
marc-gr authored Jan 30, 2025
1 parent 5d37bd4 commit 2b61d40
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 26 deletions.
20 changes: 20 additions & 0 deletions .buildkite/scripts/gcp_auth.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Write-Host "~~~ Authenticating GCP"
# Secrets must be redacted
# https://buildkite.com/docs/pipelines/managing-log-output#redacted-environment-variables

$privateCIGCSServiceAccount = "kv/ci-shared/platform-ingest/gcp-platform-ingest-ci-service-account"
$tempFileName = "google-cloud-credentials.json"
$secretFileLocation = Join-Path $env:TEMP $tempFileName

$serviceAccountJsonSecret = Retry-Command -ScriptBlock {
vault kv get -field=data -format=json $privateCIGCSServiceAccount | ConvertFrom-Json
if ( -not $? ) { throw "Error during vault kv get" }
}

New-Item -ItemType File -Path $secretFileLocation >$null
$serviceAccountJsonPlaintextSecret = $serviceAccountJsonSecret.plaintext | ConvertTo-Json
Set-Content -Path $secretFileLocation -Value $serviceAccountJsonPlaintextSecret
if ( -not $?) { throw "Error retrieving the required field from the secret" }

gcloud auth activate-service-account --key-file $secretFileLocation
Remove-Item -Path $secretFileLocation -Force
14 changes: 0 additions & 14 deletions .buildkite/scripts/gcp_auth.sh

This file was deleted.

6 changes: 2 additions & 4 deletions .buildkite/x-pack/pipeline.xpack.packetbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,8 @@ steps:

- label: ":windows: x-pack/packetbeat: Win 2022 System Tests"
key: "mandatory-win-2022-system-tests"
skip: "skipping due to elastic/beats#38142"
command: |
source .buildkite/scripts/gcp_auth.sh
.buildkite/scripts/gcp_auth.ps1
Set-Location -Path x-pack/packetbeat
mage systemTest
retry:
Expand Down Expand Up @@ -322,9 +321,8 @@ steps:

- label: ":windows: x-pack/packetbeat: Win 10 System Tests"
key: "extended-win-10-system-tests"
skip: "skipping due to elastic/beats#38142"
command: |
source .buildkite/scripts/gcp_auth.sh
.buildkite/scripts/gcp_auth.ps1
Set-Location -Path x-pack/packetbeat
mage systemTest
retry:
Expand Down
7 changes: 1 addition & 6 deletions x-pack/packetbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,7 @@ func TestPackages() error {
}

func SystemTest(ctx context.Context) error {
// Buildkite (CI) images have preinstalled npcap
if os.Getenv("CI") == "true" {
mg.SerialDeps(devtools.BuildSystemTestBinary)
} else {
mg.SerialDeps(xpacketbeat.GetNpcapInstaller, devtools.BuildSystemTestBinary)
}
mg.SerialDeps(xpacketbeat.GetNpcapInstaller, devtools.BuildSystemTestBinary)

args := devtools.DefaultGoTestIntegrationArgs()
args.Packages = []string{"./tests/system/..."}
Expand Down
23 changes: 21 additions & 2 deletions x-pack/packetbeat/tests/system/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

// Keep in sync with NpcapVersion in magefile.go.
const NpcapVersion = "1.79"
const NpcapVersion = "1.80"

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

ifcsLoop:
for _, ifc := range ifcs {
assert.Contains(t, stdout, ifc.Name)
if strings.Contains(stdout, ifc.Name) {
continue ifcsLoop
}
addrs, err := ifc.Addrs()
assert.NoError(t, err)
maddrs, err := ifc.MulticastAddrs()
assert.NoError(t, err)
addrs = append(addrs, maddrs...)
for _, addr := range addrs {
s := addr.String()
// remove the network mask suffix
if idx := strings.Index(s, "/"); idx > -1 {
s = s[:idx]
}
if strings.Contains(stdout, s) {
continue ifcsLoop
}
}
t.Errorf("interface %q not found", ifc.Name)
}
}

0 comments on commit 2b61d40

Please sign in to comment.