Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnest an unnecessary ops-agent directory #484

Merged
merged 4 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
28 changes: 13 additions & 15 deletions integration_test/third_party_apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ func rejectDuplicates(apps []string) error {

// appsToTest reads which applications to test for the given agent+platform
// combination from the appropriate supported_applications.txt file.
func appsToTest(agentType, platform string) ([]string, error) {
func appsToTest(platform string) ([]string, error) {
contents, err := readFileFromScriptsDir(
path.Join("agent", agentType, osFolder(platform), "supported_applications.txt"))
path.Join("agent", osFolder(platform), "supported_applications.txt"))
if err != nil {
return nil, fmt.Errorf("could not read supported_applications.txt: %v", err)
}
Expand Down Expand Up @@ -168,24 +168,24 @@ func runScriptFromScriptsDir(ctx context.Context, logger *logging.DirectoryLogge

// Installs the agent according to the instructions in a script
// stored in the scripts directory.
func installUsingScript(ctx context.Context, logger *logging.DirectoryLogger, vm *gce.VM, agentType string) (bool, error) {
func installUsingScript(ctx context.Context, logger *logging.DirectoryLogger, vm *gce.VM) (bool, error) {
environmentVariables := make(map[string]string)
suffix := os.Getenv("REPO_SUFFIX")
if suffix != "" {
environmentVariables["REPO_SUFFIX"] = suffix
}
if _, err := runScriptFromScriptsDir(ctx, logger, vm, path.Join("agent", agentType, osFolder(vm.Platform), "install"), environmentVariables); err != nil {
if _, err := runScriptFromScriptsDir(ctx, logger, vm, path.Join("agent", osFolder(vm.Platform), "install"), environmentVariables); err != nil {
return retryable, fmt.Errorf("error installing agent: %v", err)
}
return nonRetryable, nil
}

func installAgent(ctx context.Context, logger *logging.DirectoryLogger, vm *gce.VM, agentType string) (bool, error) {
func installAgent(ctx context.Context, logger *logging.DirectoryLogger, vm *gce.VM) (bool, error) {
defer time.Sleep(10 * time.Second)
if packagesInGCS == "" {
return installUsingScript(ctx, logger, vm, agentType)
return installUsingScript(ctx, logger, vm)
}
return nonRetryable, agents.InstallPackageFromGCS(ctx, logger, vm, agentType, packagesInGCS)
return nonRetryable, agents.InstallPackageFromGCS(ctx, logger, vm, agents.OpsAgentType, packagesInGCS)
}

// expectedEntries encodes a series of assertions about what data we expect to
Expand Down Expand Up @@ -273,7 +273,7 @@ func parseTestConfigFile() (testConfig, error) {
// and ensures that the agent uploads data from the app.
// Returns an error (nil on success), and a boolean indicating whether the error
// is retryable.
func runSingleTest(ctx context.Context, logger *logging.DirectoryLogger, vm *gce.VM, agentType, app string) (retry bool, err error) {
func runSingleTest(ctx context.Context, logger *logging.DirectoryLogger, vm *gce.VM, app string) (retry bool, err error) {
folder, err := distroFolder(vm.Platform)
if err != nil {
return nonRetryable, err
Expand All @@ -283,7 +283,7 @@ func runSingleTest(ctx context.Context, logger *logging.DirectoryLogger, vm *gce
return retryable, fmt.Errorf("error installing %s: %v", app, err)
}

if shouldRetry, err := installAgent(ctx, logger, vm, agentType); err != nil {
if shouldRetry, err := installAgent(ctx, logger, vm); err != nil {
return shouldRetry, fmt.Errorf("error installing agent: %v", err)
}

Expand Down Expand Up @@ -421,21 +421,19 @@ func determineTestsToSkip(tests []test, impactedApps map[string]bool, testConfig
func TestThirdPartyApps(t *testing.T) {
t.Cleanup(gce.CleanupKeysOrDie)

agentType := agents.OpsAgentType

testConfig, err := parseTestConfigFile()
if err != nil {
t.Fatal(err)
}
tests := []test{}
platforms := strings.Split(os.Getenv("PLATFORMS"), ",")
for _, platform := range platforms {
apps, err := appsToTest(agentType, platform)
apps, err := appsToTest(platform)
if err != nil {
t.Fatalf("Error when reading list of apps to test for agentType=%v, platform=%v. err=%v", agentType, platform, err)
t.Fatalf("Error when reading list of apps to test for platform=%v. err=%v", platform, err)
}
if len(apps) == 0 {
t.Fatalf("Found no applications when testing agentType=%v, platform=%v", agentType, platform)
t.Fatalf("Found no applications when testing platform=%v", platform)
}
for _, app := range apps {
tests = append(tests, test{platform, app, ""})
Expand Down Expand Up @@ -466,7 +464,7 @@ func TestThirdPartyApps(t *testing.T) {
logger.ToMainLog().Printf("VM is ready: %#v", vm)

var retryable bool
retryable, err = runSingleTest(ctx, logger, vm, agentType, tc.app)
retryable, err = runSingleTest(ctx, logger, vm, tc.app)
log.Printf("Attempt %v of %s test of %s finished with err=%v, retryable=%v", attempt, tc.platform, tc.app, err, retryable)
if err == nil {
return
Expand Down