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

openshift: record etcd logs in test runs #2996

Merged
merged 1 commit into from
May 25, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
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
34 changes: 32 additions & 2 deletions test/e2e/runner/cli_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,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 +319,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 +328,33 @@ 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()

master := fmt.Sprintf("%s@%s.%s.cloudapp.azure.com",
eng.ClusterDefinition.Properties.LinuxProfile.AdminUsername,
cfg.Name,
cfg.Location)

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)
}