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

Commit

Permalink
openshift: record etcd logs in test runs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Minter committed May 21, 2018
1 parent 36fac61 commit 466de05
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
9 changes: 7 additions & 2 deletions test/e2e/kubernetes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package kubernetes

import (
"encoding/json"
"fmt"
"log"
"net/url"
"os/exec"
"strings"

"github.com/Azure/acs-engine/test/e2e/kubernetes/util"
)
Expand Down Expand Up @@ -45,5 +46,9 @@ func GetConfig() (*Config, error) {
// GetServerName returns the server for the given config in an sshable format
func (c *Config) GetServerName() string {
s := c.Clusters[0].ClusterInfo.Server
return strings.Split(s, "://")[1]
u, err := url.Parse(s)
if err != nil {
panic(fmt.Sprintf("Error parsing kubeconfig server %q: %s\n", s, err))
}
return u.Hostname()
}
4 changes: 4 additions & 0 deletions test/e2e/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ func teardown() {
if err != nil {
log.Printf("cannot create directory for logs: %s", err)
}
err = cliProvisioner.FetchOpenShiftMachineLogs(cfg, eng, logsPath)
if err != nil {
log.Printf("cliProvisioner.FetchOpenShiftMachineLogs error: %s", err)
}
err = cliProvisioner.FetchOpenShiftInfraLogs(logsPath)
if err != nil {
log.Printf("cliProvisioner.FetchOpenShiftInfraLogs error: %s", err)
Expand Down
36 changes: 34 additions & 2 deletions test/e2e/runner/cli_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/Azure/acs-engine/test/e2e/config"
"github.com/Azure/acs-engine/test/e2e/dcos"
"github.com/Azure/acs-engine/test/e2e/engine"
"github.com/Azure/acs-engine/test/e2e/kubernetes"
"github.com/Azure/acs-engine/test/e2e/kubernetes/node"
"github.com/Azure/acs-engine/test/e2e/kubernetes/util"
"github.com/Azure/acs-engine/test/e2e/metrics"
Expand Down Expand Up @@ -295,7 +296,7 @@ type resource struct {
}

func (r resource) String() string {
return fmt.Sprintf("%s_%s", r.namespace, r.name)
return fmt.Sprintf("%s_%s_%s", r.namespace, r.kind, r.name)
}

// FetchOpenShiftInfraLogs returns logs for Openshift infra components.
Expand All @@ -319,7 +320,7 @@ func (cli *CLIProvisioner) FetchOpenShiftInfraLogs(logPath string) error {
var errs []error
for _, r := range infraResources {
log := outil.FetchLogs(r.kind, r.namespace, r.name)
path := filepath.Join(logPath, r.String())
path := filepath.Join(logPath, "infra-"+r.String())
err := ioutil.WriteFile(path, []byte(log), 0644)
if err != nil {
errs = append(errs, err)
Expand All @@ -328,3 +329,34 @@ func (cli *CLIProvisioner) FetchOpenShiftInfraLogs(logPath string) error {

return kerrors.NewAggregate(errs)
}

// FetchOpenShiftMachineLogs returns logs for Openshift machine components.
func (cli *CLIProvisioner) FetchOpenShiftMachineLogs(cfg *config.Config, eng *engine.Engine, logPath string) error {
sshKeyPath := cfg.GetSSHKeyPath()

kubeConfig, err := kubernetes.GetConfig()
if err != nil {
return err
}
master := fmt.Sprintf("%s@%s", eng.ClusterDefinition.Properties.LinuxProfile.AdminUsername, kubeConfig.GetServerName())

services := []string{"etcd.service"}

var errs []error
for _, service := range services {
cmd := exec.Command("ssh", "-i", sshKeyPath, "-o", "ConnectTimeout=10", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", master, "sudo journalctl -u etcd.service")
util.PrintCommand(cmd)
out, err := cmd.Output()
if err != nil {
errs = append(errs, err)
continue
}
path := filepath.Join(logPath, "machine-"+service)
err = ioutil.WriteFile(path, out, 0644)
if err != nil {
errs = append(errs, err)
}
}

return kerrors.NewAggregate(errs)
}

0 comments on commit 466de05

Please sign in to comment.