Skip to content

Commit

Permalink
[mq] working branch - merge 82d7668 on top of main at 2bbefc8
Browse files Browse the repository at this point in the history
{"baseBranch":"main","baseCommit":"2bbefc8ae6539050f9fd47b365a552993af90a96","createdAt":"2023-12-18T15:36:55.834573Z","headSha":"82d7668f99338f78d8970408fa3f8b039f109270","id":"39417da2-2784-4411-94cb-de423dc49fcf","priority":"200","pullRequestNumber":"21505","queuedAt":"2023-12-18T16:10:22.763305Z","status":"STATUS_QUEUED"}
  • Loading branch information
dd-mergequeue[bot] authored Dec 18, 2023
2 parents f8a5552 + 82d7668 commit 671a767
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 56 deletions.
2 changes: 0 additions & 2 deletions test/new-e2e/tests/ndm/snmp/compose/snmpCompose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ services:
agent:
volumes:
- ${CONFIG_DIR}/snmp.yaml:/etc/datadog-agent/conf.d/snmp.d/snmp.yaml
container_name: dd-agent

Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,24 @@
package snmp

import (
"context"
"embed"
"errors"
"path"
"testing"
"time"

"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/infra"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client"
"github.com/DataDog/test-infra-definitions/components/datadog/agent"
"github.com/DataDog/test-infra-definitions/components/datadog/dockeragentparams"
"github.com/DataDog/test-infra-definitions/scenarios/aws"
"github.com/DataDog/test-infra-definitions/scenarios/aws/vm/ec2os"
"github.com/DataDog/test-infra-definitions/scenarios/aws/vm/ec2params"
"github.com/DataDog/test-infra-definitions/scenarios/aws/vm/ec2vm"
"github.com/stretchr/testify/assert"

"github.com/pulumi/pulumi/sdk/v3/go/auto"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

// TestEnv implements a test environment for NDM. Deprecated, should port to TestSuite
type TestEnv struct {
context context.Context
name string

InstanceIP string
StackOutput auto.UpResult
}

//go:embed compose/snmpCompose.yaml
var snmpCompose string

Expand All @@ -41,96 +35,79 @@ const (
composeDataPath = "compose/data"
)

// NewTestEnv creates a new test environment for NDM. Deprecated, should port to NDM
func NewTestEnv() (*TestEnv, error) {
snmpTestEnv := &TestEnv{
context: context.Background(),
name: "snmp-agent",
}

stackManager := infra.GetStackManager()

_, upResult, err := stackManager.GetStack(snmpTestEnv.context, snmpTestEnv.name, nil, func(ctx *pulumi.Context) error {
// snmpDockerStackDef defines a stack with a docker agent on an AmazonLinuxDockerOS VM
// with snmpsim installed and configured with snmp recordings
func snmpDockerStackDef() *e2e.StackDefinition[e2e.DockerEnv] {
return e2e.EnvFactoryStackDef(func(ctx *pulumi.Context) (*e2e.DockerEnv, error) {
// setup VM
vm, err := ec2vm.NewUnixEc2VM(ctx)
vm, err := ec2vm.NewUnixEc2VM(ctx, ec2params.WithOS(ec2os.AmazonLinuxDockerOS))
if err != nil {
return err
return nil, err
}

fakeintakeExporter, err := aws.NewEcsFakeintake(vm.GetAwsEnvironment())
if err != nil {
return err
return nil, err
}

filemanager := vm.GetFileManager()
// upload snmpsim data files
createDataDirCommand, dataPath, err := filemanager.TempDirectory("data")
if err != nil {
return err
return nil, err
}
dataFiles, err := loadDataFileNames()
if err != nil {
return err
return nil, err
}

fileCommands := []pulumi.Resource{}
for _, fileName := range dataFiles {
fileContent, err := dataFolder.ReadFile(path.Join(composeDataPath, fileName))
if err != nil {
return err
return nil, err
}
dontUseSudo := false
fileCommand, err := filemanager.CopyInlineFile(pulumi.String(fileContent), path.Join(dataPath, fileName), dontUseSudo,
pulumi.DependsOn([]pulumi.Resource{createDataDirCommand}))
if err != nil {
return err
return nil, err
}
fileCommands = append(fileCommands, fileCommand)
}

createConfigDirCommand, configPath, err := filemanager.TempDirectory("config")
if err != nil {
return err
return nil, err
}
// edit snmp config file
dontUseSudo := false
configCommand, err := filemanager.CopyInlineFile(pulumi.String(snmpConfig), path.Join(configPath, "snmp.yaml"), dontUseSudo,
pulumi.DependsOn([]pulumi.Resource{createConfigDirCommand}))
if err != nil {
return err
return nil, err
}

// install agent and snmpsim on docker
envVars := pulumi.StringMap{"DATA_DIR": pulumi.String(dataPath), "CONFIG_DIR": pulumi.String(configPath)}
composeDependencies := []pulumi.Resource{createDataDirCommand, configCommand}
composeDependencies = append(composeDependencies, fileCommands...)
_, err = agent.NewDaemon(
docker, err := agent.NewDaemon(
vm,
dockeragentparams.WithFakeintake(fakeintakeExporter),
dockeragentparams.WithExtraComposeManifest("snmpsim", snmpCompose),
dockeragentparams.WithEnvironmentVariables(envVars),
dockeragentparams.WithPulumiDependsOn(pulumi.DependsOn(composeDependencies)),
)
return err
}, false)
if err != nil {
return nil, err
}

snmpTestEnv.StackOutput = upResult

output, found := upResult.Outputs["instance-ip"]

if !found {
return nil, errors.New("unable to find host ip")
}
snmpTestEnv.InstanceIP = output.Value.(string)

return snmpTestEnv, nil
}

// Destroy delete the NDM stack. Deprecated, should port to NDM
func (testEnv *TestEnv) Destroy() error {
return infra.GetStackManager().DeleteStack(testEnv.context, testEnv.name, nil)
if err != nil {
return nil, err
}
return &e2e.DockerEnv{
Docker: client.NewDocker(docker),
VM: client.NewPulumiStackVM(vm),
Fakeintake: client.NewFakeintake(fakeintakeExporter),
}, nil
})
}

//go:embed compose/data
Expand All @@ -146,3 +123,23 @@ func loadDataFileNames() (out []string, err error) {
}
return out, nil
}

type snmpDockerSuite struct {
e2e.Suite[e2e.DockerEnv]
}

// TestSnmpSuite runs the snmp e2e suite
func TestSnmpSuite(t *testing.T) {
e2e.Run(t, &snmpDockerSuite{}, snmpDockerStackDef())
}

// TestSnmp tests that the snmpsim container is running and that the agent container
// is sending snmp metrics to the fakeintake
func (s *snmpDockerSuite) TestSnmp() {
fakeintake := s.Env().Fakeintake
s.EventuallyWithT(func(c *assert.CollectT) {
metrics, err := fakeintake.GetMetricNames()
assert.NoError(c, err)
assert.Contains(c, metrics, "snmp.sysUpTimeInstance", "metrics %v doesn't contain snmp.sysUpTimeInstance", metrics)
}, 5*time.Minute, 10*time.Second)
}

0 comments on commit 671a767

Please sign in to comment.