Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Move artifacts gathering around #3154

Merged
merged 4 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
29 changes: 0 additions & 29 deletions test/e2e/openshift/openshift_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package openshift

import (
"fmt"
"os"
"os/signal"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -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() {
Expand Down
50 changes: 29 additions & 21 deletions test/e2e/openshift/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,39 +107,25 @@ func TestHost(host string, maxRetries int, retryDelay time.Duration) error {
}

// DumpNodes dumps information about nodes.
func DumpNodes() (string, error) {
func DumpNodes() string {
cmd := exec.Command("oc", "get", "nodes", "-o", "wide")
printCmd(cmd)
out, err := cmd.CombinedOutput()
if err != nil {
log.Printf("Error trying to list nodes: %s", string(out))
return "", err
log.Printf("Error trying to list nodes: %v", err)
}
return string(out), nil
return string(out)
}

// DumpPods dumps the pods from all namespaces.
func DumpPods() (string, error) {
func DumpPods() string {
cmd := exec.Command("oc", "get", "pods", "--all-namespaces", "-o", "wide")
printCmd(cmd)
out, err := cmd.CombinedOutput()
if err != nil {
log.Printf("Error trying to list pods from all namespaces: %s", string(out))
return "", err
}
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
log.Printf("Error trying to list pods from all namespaces: %v", err)
}
return string(out), nil
return string(out)
}

// FetchLogs returns logs for the provided kind/name in namespace.
Expand All @@ -153,6 +139,27 @@ func FetchLogs(kind, namespace, name string) string {
return string(out)
}

// FetchClusterInfo returns node and pod information about the cluster.
func FetchClusterInfo(logPath string) {
needsLog := map[string]string{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy for this to merge, but you don't think map[string]func() error would be a better foundation here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel strong either way, updated to your suggestion (which needs to be map[string]func() string).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apols, I meant map[string]func() (string, error) - in which case the changes to the other functions aren't needed and they're more reusable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack, updated

"node-info": DumpNodes(),
"pod-info": DumpPods(),
}

var errs []error
for base, log := range needsLog {
path := filepath.Join(logPath, base)
err := ioutil.WriteFile(path, []byte(log), 0644)
if err != nil {
errs = append(errs, err)
}
}

if err := kerrors.NewAggregate(errs); err != nil {
log.Printf("Cannot fetch node and pod info: %v", err)
}
}

// FetchOpenShiftLogs returns logs for all OpenShift components
// (control plane and infra).
func FetchOpenShiftLogs(distro, version, sshKeyPath, adminName, name, location, logPath string) {
Expand All @@ -174,7 +181,8 @@ 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))
log.Printf("Invalid OpenShift version %q - won't gather logs from the control plane", version)
return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed - return fmt.Errorf() here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
}

Expand Down
1 change: 1 addition & 0 deletions test/e2e/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ func teardown() {
version := eng.Config.OrchestratorVersion
distro := eng.Config.Distro
outil.FetchOpenShiftLogs(distro, version, sshKeyPath, adminName, cfg.Name, cfg.Location, logsPath)
outil.FetchClusterInfo(logsPath)
}
if err := cliProvisioner.FetchActivityLog(acct, logsPath); err != nil {
log.Printf("cannot fetch the activity log: %v", err)
Expand Down