Skip to content

Flaky Test: TestInstallWithEndpointSecurityAndRemoveEndpointIntegration/* #3480

Open
@pchila

Description

Flaky Test

  • Test Name: TestInstallWithEndpointSecurityAndRemoveEndpointIntegration/ unprotected OR protected

  • Link:

    func TestInstallWithEndpointSecurityAndRemoveEndpointIntegration(t *testing.T) {
    info := define.Require(t, define.Requirements{
    Stack: &define.Stack{},
    Local: false, // requires Agent installation
    Isolate: false,
    Sudo: true, // requires Agent installation
    OS: []define.OS{
    {Type: define.Linux},
    },
    })
    for _, tc := range protectionTests {
    t.Run(tc.name, func(t *testing.T) {
    testInstallWithEndpointSecurityAndRemoveEndpointIntegration(t, info, tc.protected)
    })
    }
    }
    func testInstallWithEndpointSecurityAndRemoveEndpointIntegration(t *testing.T, info *define.Info, protected bool) {
    // Get path to agent executable.
    fixture, err := define.NewFixture(t, define.Version())
    require.NoError(t, err)
    t.Log("Enrolling the agent in Fleet")
    policyUUID := uuid.New().String()
    createPolicyReq := buildPolicyWithTamperProtection(
    kibana.AgentPolicy{
    Name: "test-policy-" + policyUUID,
    Namespace: "default",
    Description: "Test policy " + policyUUID,
    MonitoringEnabled: []kibana.MonitoringEnabledOption{
    kibana.MonitoringEnabledLogs,
    kibana.MonitoringEnabledMetrics,
    },
    },
    protected,
    )
    installOpts := atesting.InstallOpts{
    NonInteractive: true,
    Force: true,
    }
    ctx, cn := context.WithCancel(context.Background())
    defer cn()
    policy, err := tools.InstallAgentWithPolicy(t, ctx, installOpts, fixture, info.KibanaClient, createPolicyReq)
    require.NoError(t, err)
    t.Log("Installing Elastic Defend")
    pkgPolicyResp, err := installElasticDefendPackage(t, info, policy.ID)
    require.NoErrorf(t, err, "Policy Response was: %#v", pkgPolicyResp)
    t.Log("Polling for endpoint-security to become Healthy")
    ctx, cancel := context.WithTimeout(context.Background(), endpointHealthPollingTimeout)
    defer cancel()
    agentClient := fixture.Client()
    err = agentClient.Connect(ctx)
    require.NoError(t, err)
    require.Eventually(t,
    func() bool { return agentAndEndpointAreHealthy(t, ctx, agentClient) },
    endpointHealthPollingTimeout,
    time.Second,
    "Endpoint component or units are not healthy.",
    )
    t.Log("Verified endpoint component and units are healthy")
    t.Logf("Removing Elastic Defend: %v", fmt.Sprintf("/api/fleet/package_policies/%v", pkgPolicyResp.Item.ID))
    _, err = info.KibanaClient.DeleteFleetPackage(ctx, pkgPolicyResp.Item.ID)
    require.NoError(t, err)
    t.Log("Waiting for endpoint to stop")
    require.Eventually(t,
    func() bool { return agentIsHealthyNoEndpoint(t, ctx, agentClient) },
    endpointHealthPollingTimeout,
    time.Second,
    "Endpoint component or units are still present.",
    )
    t.Log("Verified endpoint component and units are removed")
    // Verify that the Endpoint directory was correctly removed.
    // Regression test for https://github.com/elastic/elastic-agent/issues/3077
    agentInstallPath := fixture.WorkDir()
    files, err := os.ReadDir(filepath.Clean(filepath.Join(agentInstallPath, "..")))
    require.NoError(t, err)
    t.Logf("Checking directories at install path %s", agentInstallPath)
    for _, f := range files {
    if !f.IsDir() {
    continue
    }
    t.Log("Found directory", f.Name())
    require.False(t, strings.Contains(f.Name(), "Endpoint"), "Endpoint directory was not removed")
    }
    }

  • Branch: main

  • Artifact Link:
    TestInstallWithEndpointSecurityAndRemoveEndpointIntegration-artifacts.zip

  • Notes: Additional details about the test. e.g. theory as to failure cause
    It seems that the agent enrolled in Fleet never comes online. This already happened in the past and we thought it would have been fixed by Uninstall does not stop a running watcher after upgrade #3371
    We are seeing new occurrences after the probable fix has been merged, hence this issue

Stack Trace

paste stack trace here

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions