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 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
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
38 changes: 25 additions & 13 deletions test/e2e/openshift/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,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)
Expand All @@ -153,6 +141,29 @@ 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) {
Expand All @@ -174,7 +185,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
3 changes: 3 additions & 0 deletions test/e2e/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ func teardown() {
version := eng.Config.OrchestratorVersion
distro := eng.Config.Distro
outil.FetchOpenShiftLogs(distro, version, sshKeyPath, adminName, cfg.Name, cfg.Location, logsPath)
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)
Expand Down