Skip to content

Commit

Permalink
[e2e] Export logs for TestNetworkPolicy subtests (#5149)
Browse files Browse the repository at this point in the history
One subtest of TestNetworkPolicy restarts antrea-controller, which
causes its log missing when subtests running before it fail. To preserve
component logs, we export logs for every subtest if it fails.

Signed-off-by: Quan Tian <qtian@vmware.com>
  • Loading branch information
tnqn committed Jun 26, 2023
1 parent d77a1e0 commit 74b856f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/e2e/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@ func setupTestForFlowAggregator(tb testing.TB) (*TestData, bool, bool, error) {
return testData, v4Enabled, v6Enabled, nil
}

func exportLogsForSubtest(tb testing.TB, data *TestData) func() {
substrings := strings.Split(tb.Name(), "/")
subDir := substrings[len(substrings)-1]
return func() {
exportLogs(tb, data, subDir, true)
}
}

func exportLogs(tb testing.TB, data *TestData, logsSubDir string, writeNodeLogs bool) {
if tb.Skipped() {
return
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/networkpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,34 +52,43 @@ func TestNetworkPolicy(t *testing.T) {
defer teardownTest(t, data)

t.Run("testNetworkPolicyStats", func(t *testing.T) {
t.Cleanup(exportLogsForSubtest(t, data))
skipIfNotIPv4Cluster(t)
skipIfNetworkPolicyStatsDisabled(t)
testNetworkPolicyStats(t, data)
})
t.Run("testDifferentNamedPorts", func(t *testing.T) {
t.Cleanup(exportLogsForSubtest(t, data))
testDifferentNamedPorts(t, data)
})
t.Run("testDefaultDenyIngressPolicy", func(t *testing.T) {
t.Cleanup(exportLogsForSubtest(t, data))
testDefaultDenyIngressPolicy(t, data)
})
t.Run("testDefaultDenyEgressPolicy", func(t *testing.T) {
t.Cleanup(exportLogsForSubtest(t, data))
testDefaultDenyEgressPolicy(t, data)
})
t.Run("testEgressToServerInCIDRBlock", func(t *testing.T) {
t.Cleanup(exportLogsForSubtest(t, data))
skipIfNotIPv6Cluster(t)
testEgressToServerInCIDRBlock(t, data)
})
t.Run("testEgressToServerInCIDRBlockWithException", func(t *testing.T) {
t.Cleanup(exportLogsForSubtest(t, data))
skipIfNotIPv6Cluster(t)
testEgressToServerInCIDRBlockWithException(t, data)
})
t.Run("testNetworkPolicyResyncAfterRestart", func(t *testing.T) {
t.Cleanup(exportLogsForSubtest(t, data))
testNetworkPolicyResyncAfterRestart(t, data)
})
t.Run("testIngressPolicyWithoutPortNumber", func(t *testing.T) {
t.Cleanup(exportLogsForSubtest(t, data))
testIngressPolicyWithoutPortNumber(t, data)
})
t.Run("testIngressPolicyWithEndPort", func(t *testing.T) {
t.Cleanup(exportLogsForSubtest(t, data))
testIngressPolicyWithEndPort(t, data)
})
}
Expand Down

0 comments on commit 74b856f

Please sign in to comment.