Skip to content

Commit

Permalink
fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
chouetz committed Nov 8, 2024
1 parent f8442ca commit 905edc4
Show file tree
Hide file tree
Showing 31 changed files with 118 additions and 125 deletions.
18 changes: 13 additions & 5 deletions test/new-e2e/examples/kind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"strings"
"testing"

corev1 "k8s.io/api/core/v1"

"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments"
awskubernetes "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments/aws/kubernetes"
Expand All @@ -20,6 +22,7 @@ import (
compkube "github.com/DataDog/test-infra-definitions/components/kubernetes"
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -29,19 +32,20 @@ type myKindSuite struct {

func TestMyKindSuite(t *testing.T) {
e2e.Run(t, &myKindSuite{}, e2e.WithProvisioner(
awskubernetes.Provisioner(
awskubernetes.KindProvisioner(
awskubernetes.WithoutFakeIntake(),
awskubernetes.WithWorkloadApp(func(e config.CommonEnvironment, kubeProvider *kubernetes.Provider) (*compkube.Workload, error) {
return nginx.K8sAppDefinition(e, kubeProvider, "nginx", nil)
awskubernetes.WithWorkloadApp(func(e config.Env, kubeProvider *kubernetes.Provider) (*compkube.Workload, error) {
return nginx.K8sAppDefinition(e, kubeProvider, "nginx", "", false, nil)
}),
awskubernetes.WithWorkloadApp(func(e config.CommonEnvironment, kubeProvider *kubernetes.Provider) (*compkube.Workload, error) {
awskubernetes.WithWorkloadApp(func(e config.Env, kubeProvider *kubernetes.Provider) (*compkube.Workload, error) {
return dogstatsd.K8sAppDefinition(e, kubeProvider, "dogstatsd", 8125, "/var/run/datadog/dsd.socket")
}),
)))
}

func (v *myKindSuite) TestClusterAgentInstalled() {
res, _ := v.Env().KubernetesCluster.Client().CoreV1().Pods("datadog").List(context.TODO(), v1.ListOptions{})
var clusterAgent corev1.Pod
containsClusterAgent := false
for _, pod := range res.Items {
if strings.Contains(pod.Name, "cluster-agent") {
Expand All @@ -50,5 +54,9 @@ func (v *myKindSuite) TestClusterAgentInstalled() {
}
}
assert.True(v.T(), containsClusterAgent, "Cluster Agent not found")
assert.Equal(v.T(), v.Env().Agent.InstallNameLinux, "dda")
stdout, stderr, err := v.Env().KubernetesCluster.KubernetesClient.
PodExec("datadog", clusterAgent.Name, "datadog-cluster-agent", []string{"ls"})
require.NoError(v.T(), err)
assert.Empty(v.T(), stderr)
assert.NotEmpty(v.T(), stdout)
}
2 changes: 1 addition & 1 deletion test/new-e2e/examples/vmenv_withami_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestVMSuiteEx2(t *testing.T) {
}

func (v *vmSuiteEx2) TestAmiMatch() {
ec2Metadata := client.NewEC2Metadata(v.Env().RemoteHost)
ec2Metadata := client.NewEC2Metadata(v.T(), v.Env().RemoteHost.Host, v.Env().RemoteHost.OSFamily)
amiID := ec2Metadata.Get("ami-id")
assert.Equal(v.T(), amiID, "ami-05fab674de2157a80")
}
30 changes: 0 additions & 30 deletions test/new-e2e/pkg/utils/e2e/client/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/DataDog/test-infra-definitions/components/docker"
"github.com/docker/cli/cli/connhelper"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/stdcopy"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -120,32 +119,3 @@ func (docker *Docker) ExecuteCommandStdoutStdErr(containerName string, commands

return stdout, stderr, err
}

// ListContainers returns a list of container names.
func (docker *Docker) ListContainers() ([]string, error) {
containersMap, err := docker.getContainerIDsByName()
if err != nil {
return nil, err
}
containerNames := make([]string, 0, len(containersMap))
for name := range containersMap {
containerNames = append(containerNames, name)
}
return containerNames, nil
}

func (docker *Docker) getContainerIDsByName() (map[string]string, error) {
containersMap := make(map[string]string)
containers, err := docker.client.ContainerList(context.Background(), container.ListOptions{All: true})
if err != nil {
return containersMap, err
}
for _, container := range containers {
for _, name := range container.Names {
// remove leading /
name = strings.TrimPrefix(name, "/")
containersMap[name] = container.ID
}
}
return containersMap, nil
}
18 changes: 12 additions & 6 deletions test/new-e2e/system-probe/system-probe-test-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,18 @@ func NewTestEnv(name, x86InstanceType, armInstanceType string, opts *EnvOpts) (*
config["ddinfra:aws/defaultSubnets"] = auto.ConfigValue{Value: az}
}

pulumiStack, upResult, err = stackManager.GetStackNoDeleteOnFailure(systemProbeTestEnv.context, systemProbeTestEnv.name, config, func(ctx *pulumi.Context) error {
if err := microvms.Run(ctx); err != nil {
return fmt.Errorf("setup micro-vms in remote instance: %w", err)
}
return nil
}, opts.FailOnMissing, nil)
pulumiStack, upResult, err = stackManager.GetStackNoDeleteOnFailure(
systemProbeTestEnv.context,
systemProbeTestEnv.name,
func(ctx *pulumi.Context) error {
if err := microvms.Run(ctx); err != nil {
return fmt.Errorf("setup micro-vms in remote instance: %w", err)
}
return nil
},
infra.WithFailOnMissing(opts.FailOnMissing),
infra.WithConfigMap(config),
)
if err != nil {
return handleScenarioFailure(err, func(possibleError handledError) {
// handle the following errors by trying in a different availability zone
Expand Down
4 changes: 2 additions & 2 deletions test/new-e2e/test-infra-definition/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ func TestVMSuite(t *testing.T) {

func (v *vmSuiteWithAMI) TestWithImageName() {
vm := v.Env().RemoteHost
metadata := client.NewEC2Metadata(vm)
metadata := client.NewEC2Metadata(v.T(), vm.Host, vm.OSFamily)
require.Equal(v.T(), requestedAmi, metadata.Get("ami-id"))
require.Equal(v.T(), "aarch64\n", vm.MustExecute("uname -m"))
require.Contains(v.T(), vm.MustExecute("grep PRETTY_NAME /etc/os-release"), "Amazon Linux")
}

func (v *vmSuiteWithInstanceType) TestWithInstanceType() {
vm := v.Env().RemoteHost
metadata := client.NewEC2Metadata(vm)
metadata := client.NewEC2Metadata(v.T(), vm.Host, vm.OSFamily)
require.Equal(v.T(), metadata.Get("instance-type"), instanceType)
}

Expand Down
6 changes: 4 additions & 2 deletions test/new-e2e/tests/agent-platform/common/test_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"github.com/DataDog/datadog-agent/test/new-e2e/pkg/components"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client/agentclient"
boundport "github.com/DataDog/datadog-agent/test/new-e2e/tests/agent-platform/common/bound-port"
Expand Down Expand Up @@ -191,10 +192,11 @@ func (c *TestClient) ExecuteWithRetry(cmd string) (string, error) {
}

// NewWindowsTestClient create a TestClient for Windows VM
func NewWindowsTestClient(t *testing.T, host *components.RemoteHost) *TestClient {
func NewWindowsTestClient(context e2e.Context, host *components.RemoteHost) *TestClient {
fileManager := filemanager.NewRemoteHost(host)
t := context.T()

agentClient, err := client.NewHostAgentClient(t, host, false)
agentClient, err := client.NewHostAgentClient(context, host.HostOutput, false)
require.NoError(t, err)

helper := helpers.NewWindowsHelper()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (is *installScriptSuite) testUninstall(client *common.TestClient, flavor st
func (is *installScriptSuite) AgentTest(flavor string) {
host := is.Env().RemoteHost
fileManager := filemanager.NewUnix(host)
agentClient, err := client.NewHostAgentClient(is.T(), host, false)
agentClient, err := client.NewHostAgentClient(is, host.HostOutput, false)
require.NoError(is.T(), err)

unixHelper := helpers.NewUnix()
Expand Down Expand Up @@ -146,7 +146,7 @@ func (is *installScriptSuite) AgentTest(flavor string) {
func (is *installScriptSuite) IotAgentTest() {
host := is.Env().RemoteHost
fileManager := filemanager.NewUnix(host)
agentClient, err := client.NewHostAgentClient(is.T(), host, false)
agentClient, err := client.NewHostAgentClient(is, host.HostOutput, false)
require.NoError(is.T(), err)

unixHelper := helpers.NewUnix()
Expand All @@ -167,7 +167,7 @@ func (is *installScriptSuite) IotAgentTest() {
func (is *installScriptSuite) DogstatsdAgentTest() {
host := is.Env().RemoteHost
fileManager := filemanager.NewUnix(host)
agentClient, err := client.NewHostAgentClient(is.T(), host, false)
agentClient, err := client.NewHostAgentClient(is, host.HostOutput, false)
require.NoError(is.T(), err)

unixHelper := helpers.NewUnixDogstatsd()
Expand Down
3 changes: 2 additions & 1 deletion test/new-e2e/tests/agent-platform/rpm/rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ func TestRpmScript(t *testing.T) {
}

func (is *rpmTestSuite) TestRpm() {
host := is.Env().RemoteHost
filemanager := filemanager.NewUnix(is.Env().RemoteHost)
unixHelper := helpers.NewUnix()
agentClient, err := client.NewHostAgentClient(is.T(), is.Env().RemoteHost, false)
agentClient, err := client.NewHostAgentClient(is, host.HostOutput, false)
require.NoError(is.T(), err)
VMclient := common.NewTestClient(is.Env().RemoteHost, agentClient, filemanager, unixHelper)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ func TestStepByStepScript(t *testing.T) {
}

func (is *stepByStepSuite) TestStepByStep() {
host := is.Env().RemoteHost
fileManager := filemanager.NewUnix(is.Env().RemoteHost)
unixHelper := helpers.NewUnix()
agentClient, err := client.NewHostAgentClient(is.T(), is.Env().RemoteHost, false)
agentClient, err := client.NewHostAgentClient(is, host.HostOutput, false)
require.NoError(is.T(), err)
VMclient := common.NewTestClient(is.Env().RemoteHost, agentClient, fileManager, unixHelper)

Expand Down
4 changes: 2 additions & 2 deletions test/new-e2e/tests/agent-platform/upgrade/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func TestUpgradeScript(t *testing.T) {

func (is *upgradeSuite) TestUpgrade() {
fileManager := filemanager.NewUnix(is.Env().RemoteHost)

agentClient, err := client.NewHostAgentClient(is.T(), is.Env().RemoteHost, false)
host := is.Env().RemoteHost
agentClient, err := client.NewHostAgentClient(is, host.HostOutput, false)
require.NoError(is.T(), err)

unixHelper := helpers.NewUnix()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type multiFakeIntakeEnv struct {

func (e *multiFakeIntakeEnv) Init(ctx e2e.Context) error {
if e.Agent != nil {
agent, err := client.NewHostAgentClient(ctx.T(), e.Host, true)
agent, err := client.NewHostAgentClient(ctx, e.Host.HostOutput, true)
if err != nil {
return err
}
Expand Down Expand Up @@ -95,7 +95,7 @@ func multiFakeIntakeAWS(agentOptions ...agentparams.Option) e2e.Provisioner {
}
host.Export(ctx, &env.Host.HostOutput)

agent, err := agent.NewHostAgent(awsEnv.CommonEnvironment, host, agentOptions...)
agent, err := agent.NewHostAgent(&awsEnv, host, agentOptions...)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (v *linuxHostnameSuite) TestAgentConfigHostnameFileOverride() {
func (v *linuxHostnameSuite) TestAgentConfigPreferImdsv2() {
v.UpdateEnv(awshost.ProvisionerNoFakeIntake(v.GetOs(), awshost.WithAgentOptions(agentparams.WithAgentConfig("ec2_prefer_imdsv2: true"))))
// e2e metadata provider already uses IMDSv2
metadata := client.NewEC2Metadata(v.Env().RemoteHost)
metadata := client.NewEC2Metadata(v.T(), v.Env().RemoteHost.Host, v.Env().RemoteHost.OSFamily)

hostname := v.Env().Agent.Client.Hostname()
resourceID := metadata.Get("instance-id")
Expand All @@ -48,7 +48,7 @@ func (v *linuxHostnameSuite) TestAgentConfigPreferImdsv2() {
func (v *linuxHostnameSuite) TestAgentHostnameDefaultsToResourceId() {
v.UpdateEnv(awshost.ProvisionerNoFakeIntake(v.GetOs(), awshost.WithAgentOptions(agentparams.WithAgentConfig(""))))

metadata := client.NewEC2Metadata(v.Env().RemoteHost)
metadata := client.NewEC2Metadata(v.T(), v.Env().RemoteHost.Host, v.Env().RemoteHost.OSFamily)
hostname := v.Env().Agent.Client.Hostname()

// Default configuration of hostname for EC2 instances is the resource-id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ec2_use_windows_prefix_detection: true`

v.UpdateEnv(awshost.ProvisionerNoFakeIntake(v.GetOs(), awshost.WithAgentOptions(agentparams.WithAgentConfig(config))))
// e2e metadata provider already uses IMDSv2
metadata := client.NewEC2Metadata(v.Env().RemoteHost)
metadata := client.NewEC2Metadata(v.T(), v.Env().RemoteHost.Host, v.Env().RemoteHost.OSFamily)

hostname := v.Env().Agent.Client.Hostname()
resourceID := metadata.Get("instance-id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestLinuxStatusSuite(t *testing.T) {
}

func (v *linuxStatusSuite) TestStatusHostname() {
metadata := client.NewEC2Metadata(v.Env().RemoteHost)
metadata := client.NewEC2Metadata(v.T(), v.Env().RemoteHost.Host, v.Env().RemoteHost.OSFamily)
resourceID := metadata.Get("instance-id")

status := v.Env().Agent.Client.Status()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestWindowsStatusSuite(t *testing.T) {
}

func (v *windowsStatusSuite) TestStatusHostname() {
metadata := client.NewEC2Metadata(v.Env().RemoteHost)
metadata := client.NewEC2Metadata(v.T(), v.Env().RemoteHost.Host, v.Env().RemoteHost.OSFamily)
resourceID := metadata.Get("instance-id")

status := v.Env().Agent.Client.Status()
Expand Down
2 changes: 1 addition & 1 deletion test/new-e2e/tests/apm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func waitRemotePort(v *VMFakeintakeSuite, port uint16) error {
v.Eventually(func() bool {
v.T().Logf("Waiting for remote:%v", port)
// TODO: Use the e2e context
c, err = v.Env().RemoteHost.DialRemotePort(port)
c, err = v.Env().RemoteHost.DialPort(port)
if err != nil {
v.T().Logf("Failed to dial remote:%v: %s\n", port, err)
return false
Expand Down
2 changes: 1 addition & 1 deletion test/new-e2e/tests/containers/ecs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (suite *ecsSuite) SetupSuite() {
"ddtestworkload:deploy": auto.ConfigValue{Value: "true"},
}

_, stackOutput, err := infra.GetStackManager().GetStackNoDeleteOnFailure(ctx, "ecs-cluster", stackConfig, ecs.Run, false, nil)
_, stackOutput, err := infra.GetStackManager().GetStackNoDeleteOnFailure(ctx, "ecs-cluster", ecs.Run, infra.WithConfigMap(stackConfig))
suite.Require().NoError(err)

fakeintake := &components.FakeIntake{}
Expand Down
2 changes: 1 addition & 1 deletion test/new-e2e/tests/containers/eks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (suite *eksSuite) SetupSuite() {
"dddogstatsd:deploy": auto.ConfigValue{Value: "true"},
}

_, stackOutput, err := infra.GetStackManager().GetStackNoDeleteOnFailure(ctx, "eks-cluster", stackConfig, eks.Run, false, nil)
_, stackOutput, err := infra.GetStackManager().GetStackNoDeleteOnFailure(ctx, "eks-cluster", eks.Run, infra.WithConfigMap(stackConfig))
if !suite.Assert().NoError(err) {
stackName, err := infra.GetStackManager().GetPulumiStackName("eks-cluster")
suite.Require().NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion test/new-e2e/tests/containers/kindvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (suite *kindSuite) SetupSuite() {
"dddogstatsd:deploy": auto.ConfigValue{Value: "true"},
}

_, stackOutput, err := infra.GetStackManager().GetStackNoDeleteOnFailure(ctx, "kind-cluster", stackConfig, kindvm.Run, false, nil)
_, stackOutput, err := infra.GetStackManager().GetStackNoDeleteOnFailure(ctx, "kind-cluster", kindvm.Run, infra.WithConfigMap(stackConfig))
if !suite.Assert().NoError(err) {
stackName, err := infra.GetStackManager().GetPulumiStackName("kind-cluster")
suite.Require().NoError(err)
Expand Down
4 changes: 2 additions & 2 deletions test/new-e2e/tests/cws/fargate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestECSFargate(t *testing.T) {

// Setup agent API key
apiKeyParam, err := ssm.NewParameter(ctx, awsEnv.Namer.ResourceName("agent-apikey"), &ssm.ParameterArgs{
Name: awsEnv.CommonNamer.DisplayName(1011, pulumi.String("agent-apikey")),
Name: awsEnv.CommonNamer().DisplayName(1011, pulumi.String("agent-apikey")),
Type: ssm.ParameterTypeSecureString,
Value: awsEnv.AgentAPIKey(),
}, awsEnv.WithProviders(configCommon.ProviderAWS, configCommon.ProviderAWSX))
Expand Down Expand Up @@ -217,7 +217,7 @@ func TestECSFargate(t *testing.T) {
TaskRole: &awsx.DefaultRoleWithPolicyArgs{
RoleArn: pulumi.StringPtr(awsEnv.ECSTaskRole()),
},
Family: awsEnv.CommonNamer.DisplayName(255, pulumi.String("cws-task")),
Family: awsEnv.CommonNamer().DisplayName(255, pulumi.String("cws-task")),
}, awsEnv.WithProviders(configCommon.ProviderAWS, configCommon.ProviderAWSX))
if err != nil {
return err
Expand Down
16 changes: 10 additions & 6 deletions test/new-e2e/tests/ndm/snmp/snmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments"
"github.com/stretchr/testify/assert"

"github.com/DataDog/test-infra-definitions/common/utils"
"github.com/DataDog/test-infra-definitions/components/datadog/agent"
"github.com/DataDog/test-infra-definitions/components/datadog/dockeragentparams"
"github.com/DataDog/test-infra-definitions/components/docker"
Expand Down Expand Up @@ -77,8 +78,7 @@ func snmpDockerProvisioner() e2e.Provisioner {
if err != nil {
return err
}
dontUseSudo := false
fileCommand, err := filemanager.CopyInlineFile(pulumi.String(fileContent), path.Join(dataPath, fileName), dontUseSudo,
fileCommand, err := filemanager.CopyInlineFile(pulumi.String(fileContent), path.Join(dataPath, fileName),
pulumi.DependsOn([]pulumi.Resource{createDataDirCommand}))
if err != nil {
return err
Expand All @@ -91,22 +91,26 @@ func snmpDockerProvisioner() e2e.Provisioner {
return err
}
// edit snmp config file
dontUseSudo := false
configCommand, err := filemanager.CopyInlineFile(pulumi.String(snmpConfig), path.Join(configPath, "snmp.yaml"), dontUseSudo,
configCommand, err := filemanager.CopyInlineFile(pulumi.String(snmpConfig), path.Join(configPath, "snmp.yaml"),
pulumi.DependsOn([]pulumi.Resource{createConfigDirCommand}))
if err != nil {
return err
}

dockerManager, _, err := docker.NewManager(*awsEnv.CommonEnvironment, host)
installEcrCredsHelperCmd, err := ec2.InstallECRCredentialsHelper(awsEnv, host)
if err != nil {
return err
}

dockerManager, err := docker.NewManager(&awsEnv, host, utils.PulumiDependsOn(installEcrCredsHelperCmd))
if err != nil {
return err
}

envVars := pulumi.StringMap{"DATA_DIR": pulumi.String(dataPath), "CONFIG_DIR": pulumi.String(configPath)}
composeDependencies := []pulumi.Resource{createDataDirCommand, configCommand}
composeDependencies = append(composeDependencies, fileCommands...)
dockerAgent, err := agent.NewDockerAgent(*awsEnv.CommonEnvironment, host, dockerManager,
dockerAgent, err := agent.NewDockerAgent(&awsEnv, host, dockerManager,
dockeragentparams.WithFakeintake(fakeIntake),
dockeragentparams.WithExtraComposeManifest("snmpsim", pulumi.String(snmpCompose)),
dockeragentparams.WithEnvironmentVariables(envVars),
Expand Down
Loading

0 comments on commit 905edc4

Please sign in to comment.