|
| 1 | +// Unless explicitly stated otherwise all files in this repository are licensed |
| 2 | +// under the Apache License Version 2.0. |
| 3 | +// This product includes software developed at Datadog (https://www.datadoghq.com/). |
| 4 | +// Copyright 2016-present Datadog, Inc. |
| 5 | + |
| 6 | +package procmgr |
| 7 | + |
| 8 | +import ( |
| 9 | + "fmt" |
| 10 | + "path/filepath" |
| 11 | + "strings" |
| 12 | + "testing" |
| 13 | + "time" |
| 14 | + |
| 15 | + "github.com/stretchr/testify/assert" |
| 16 | + "github.com/stretchr/testify/require" |
| 17 | + |
| 18 | + "github.com/DataDog/datadog-agent/test/e2e-framework/components/datadog/agentparams" |
| 19 | + e2eos "github.com/DataDog/datadog-agent/test/e2e-framework/components/os" |
| 20 | + "github.com/DataDog/datadog-agent/test/e2e-framework/scenarios/aws/ec2" |
| 21 | + "github.com/DataDog/datadog-agent/test/e2e-framework/testing/e2e" |
| 22 | + "github.com/DataDog/datadog-agent/test/e2e-framework/testing/environments" |
| 23 | + awshost "github.com/DataDog/datadog-agent/test/e2e-framework/testing/provisioners/aws/host" |
| 24 | + paridentity "github.com/DataDog/datadog-agent/test/new-e2e/tests/privateactionrunner" |
| 25 | + windowsagent "github.com/DataDog/datadog-agent/test/new-e2e/tests/windows/common/agent" |
| 26 | +) |
| 27 | + |
| 28 | +const ( |
| 29 | + parProcessName = "datadog-agent-action" |
| 30 | + parLegacySCMServiceName = "datadog-agent-action" |
| 31 | + parProcmgrConfigFileName = "datadog-agent-action.yaml" |
| 32 | +) |
| 33 | + |
| 34 | +type parProcmgrWindowsSuite struct { |
| 35 | + e2e.BaseSuite[environments.Host] |
| 36 | +} |
| 37 | + |
| 38 | +func TestPARManagedByProcmgrWindows(t *testing.T) { |
| 39 | + t.Parallel() |
| 40 | + config := paridentity.GenerateTestPrivateActionRunnerConfig(t) |
| 41 | + e2e.Run(t, &parProcmgrWindowsSuite{}, e2e.WithProvisioner( |
| 42 | + awshost.ProvisionerNoFakeIntake( |
| 43 | + awshost.WithRunOptions( |
| 44 | + ec2.WithEC2InstanceOptions(ec2.WithOS(e2eos.WindowsServerDefault), ec2.WithInternetAccess()), |
| 45 | + ec2.WithAgentOptions(agentparams.WithAgentConfig(config)), |
| 46 | + ), |
| 47 | + ), |
| 48 | + )) |
| 49 | +} |
| 50 | + |
| 51 | +func (s *parProcmgrWindowsSuite) TestPARSupervisedByProcmgrAndLegacySCMStopped() { |
| 52 | + host := s.Env().RemoteHost |
| 53 | + installRoot, err := windowsagent.GetInstallPathFromRegistry(host) |
| 54 | + require.NoError(s.T(), err) |
| 55 | + |
| 56 | + parBin := filepath.Join(installRoot, "bin", "agent", "privateactionrunner.exe") |
| 57 | + exists, err := host.FileExists(parBin) |
| 58 | + require.NoError(s.T(), err) |
| 59 | + if !exists { |
| 60 | + s.T().Skip("privateactionrunner.exe not installed; skipping PAR procmgr test") |
| 61 | + } |
| 62 | + |
| 63 | + cfg := filepath.Join(installRoot, "processes.d", parProcmgrConfigFileName) |
| 64 | + exists, err = host.FileExists(cfg) |
| 65 | + require.NoError(s.T(), err) |
| 66 | + require.True(s.T(), exists, "fleet PAR processes.d config should exist at %s", cfg) |
| 67 | + |
| 68 | + cli := filepath.Join(installRoot, "bin", "agent", "dd-procmgr.exe") |
| 69 | + require.EventuallyWithT(s.T(), func(ct *assert.CollectT) { |
| 70 | + out, err := host.Execute(fmt.Sprintf(`& "%s" describe %s`, cli, parProcessName)) |
| 71 | + assert.NoError(ct, err) |
| 72 | + assert.Contains(ct, out, "State") |
| 73 | + assert.Contains(ct, out, "Running") |
| 74 | + }, 120*time.Second, 3*time.Second) |
| 75 | + |
| 76 | + out, err := host.Execute(fmt.Sprintf( |
| 77 | + `$s = Get-Service -Name '%s' -ErrorAction SilentlyContinue; if ($null -eq $s) { 'Absent' } else { $s.Status }`, |
| 78 | + parLegacySCMServiceName, |
| 79 | + )) |
| 80 | + require.NoError(s.T(), err) |
| 81 | + require.NotEqual(s.T(), "Running", strings.TrimSpace(out), |
| 82 | + "%s Windows service must not be Running when PAR is managed by dd-procmgr", parLegacySCMServiceName) |
| 83 | +} |
0 commit comments