From 0d6dd79a639ddbe226c6935e204a5a0594133c2a Mon Sep 17 00:00:00 2001 From: Michalis Kargakis Date: Tue, 5 Jun 2018 22:07:52 +0200 Subject: [PATCH] Move artifacts gathering around (#3154) * Fetch cluster info for openshift unconditionally * Avoid panicking when openshift version is not provided * map filenames to log fns * propagate errors back to runner.go --- test/e2e/openshift/openshift_test.go | 29 ------------------ test/e2e/openshift/util/util.go | 44 ++++++++++++++++++---------- test/e2e/runner.go | 7 ++++- 3 files changed, 34 insertions(+), 46 deletions(-) diff --git a/test/e2e/openshift/openshift_test.go b/test/e2e/openshift/openshift_test.go index 556fa1a431..70789504fa 100644 --- a/test/e2e/openshift/openshift_test.go +++ b/test/e2e/openshift/openshift_test.go @@ -1,9 +1,7 @@ package openshift import ( - "fmt" "os" - "os/signal" "path/filepath" "strings" "time" @@ -46,33 +44,6 @@ var _ = BeforeSuite(func() { ClusterDefinition: csInput, ExpandedDefinition: csGenerated, } - signal.Notify(ch, os.Interrupt) -}) - -var _ = AfterEach(func() { - // Recommended way to optionally act on failures after - // tests finish - see https://github.com/onsi/ginkgo/issues/361 - failed = failed || CurrentGinkgoTestDescription().Failed -}) - -var _ = AfterSuite(func() { - select { - case <-ch: - // interrupt - interrupted = true - default: - } - - if !failed && !interrupted { - return - } - - nodeOut, _ := util.DumpNodes() - fmt.Println(nodeOut) - podOut, _ := util.DumpPods() - fmt.Println(podOut) - diagnosticsOut, _ := util.RunDiagnostics() - fmt.Println(diagnosticsOut) }) var _ = Describe("Azure Container Cluster using the OpenShift Orchestrator", func() { diff --git a/test/e2e/openshift/util/util.go b/test/e2e/openshift/util/util.go index b3f3950e32..2a7f89c3d8 100644 --- a/test/e2e/openshift/util/util.go +++ b/test/e2e/openshift/util/util.go @@ -131,18 +131,6 @@ func DumpPods() (string, error) { return string(out), nil } -// RunDiagnostics runs the openshift diagnostics command. -func RunDiagnostics() (string, error) { - cmd := exec.Command("oc", "adm", "diagnostics") - printCmd(cmd) - out, err := cmd.CombinedOutput() - if err != nil { - log.Printf("Error trying to run diagnostics: %s", string(out)) - return "", err - } - return string(out), nil -} - // FetchLogs returns logs for the provided kind/name in namespace. func FetchLogs(kind, namespace, name string) string { cmd := exec.Command("oc", "logs", fmt.Sprintf("%s/%s", kind, name), "-n", namespace) @@ -154,15 +142,39 @@ func FetchLogs(kind, namespace, name string) string { return string(out) } +// FetchClusterInfo returns node and pod information about the cluster. +func FetchClusterInfo(logPath string) error { + needsLog := map[string]func() (string, error){ + "node-info": DumpNodes, + "pod-info": DumpPods, + } + + var errs []error + for base, logFn := range needsLog { + logs, err := logFn() + if err != nil { + errs = append(errs, err) + continue + } + path := filepath.Join(logPath, base) + if err := ioutil.WriteFile(path, []byte(logs), 0644); err != nil { + errs = append(errs, err) + } + } + + return kerrors.NewAggregate(errs) +} + // FetchOpenShiftLogs returns logs for all OpenShift components // (control plane and infra). -func FetchOpenShiftLogs(distro, version, sshKeyPath, adminName, name, location, logPath string) { +func FetchOpenShiftLogs(distro, version, sshKeyPath, adminName, name, location, logPath string) error { if err := fetchControlPlaneLogs(distro, version, sshKeyPath, adminName, name, location, logPath); err != nil { - log.Printf("Cannot fetch logs for control plane components: %v", err) + return fmt.Errorf("cannot fetch logs for control plane components: %v", err) } if err := fetchInfraLogs(logPath); err != nil { - log.Printf("Cannot fetch logs for infra components: %v", err) + return fmt.Errorf("cannot fetch logs for infra components: %v", err) } + return nil } // fetchControlPlaneLogs returns logs for Openshift control plane components. @@ -175,7 +187,7 @@ func fetchControlPlaneLogs(distro, version, sshKeyPath, adminName, name, locatio case common.OpenShiftVersionUnstable: return fetchUnstableControlPlaneLogs(distro, sshKeyPath, sshAddress, name, logPath) default: - panic(fmt.Sprintf("BUG: invalid OpenShift version %s", version)) + return fmt.Errorf("invalid OpenShift version %q - won't gather logs from the control plane", version) } } diff --git a/test/e2e/runner.go b/test/e2e/runner.go index fa73545e14..60598cf490 100644 --- a/test/e2e/runner.go +++ b/test/e2e/runner.go @@ -202,7 +202,12 @@ func teardown() { adminName := eng.ClusterDefinition.Properties.LinuxProfile.AdminUsername version := eng.Config.OrchestratorVersion distro := eng.Config.Distro - outil.FetchOpenShiftLogs(distro, version, sshKeyPath, adminName, cfg.Name, cfg.Location, logsPath) + if err := outil.FetchOpenShiftLogs(distro, version, sshKeyPath, adminName, cfg.Name, cfg.Location, logsPath); err != nil { + log.Printf("cannot get openshift logs: %v", err) + } + if err := outil.FetchClusterInfo(logsPath); err != nil { + log.Printf("cannot get pod and node info: %v", err) + } } if err := cliProvisioner.FetchActivityLog(acct, logsPath); err != nil { log.Printf("cannot fetch the activity log: %v", err)