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

Commit

Permalink
Move artifacts gathering around (#3154)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
0xmichalis authored and acs-bot committed Jun 5, 2018
1 parent 9304fe3 commit 0d6dd79
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 46 deletions.
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
44 changes: 28 additions & 16 deletions test/e2e/openshift/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand All @@ -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)
}
}

Expand Down
7 changes: 6 additions & 1 deletion test/e2e/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0d6dd79

Please sign in to comment.