-
Notifications
You must be signed in to change notification settings - Fork 237
Export logs as wercker artifacts and delete e2e namespace on test failure #188
Conversation
67a194f
to
8672523
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple improvements/tweaks i've suggested. You could also do with a unit test or two if it's easy
test/e2e/framework/framework.go
Outdated
@@ -248,6 +250,8 @@ func (f *Framework) BeforeEach() { | |||
func (f *Framework) AfterEach() { | |||
RemoveCleanupAction(f.cleanupHandle) | |||
|
|||
printMySQLPodContainerLogs(f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a more accurate name. It's not printing, mysql pod container logs, it's retrieving, storing, dumping all container logs really...
test/e2e/framework/framework.go
Outdated
func printMySQLPodContainerLogs(f *Framework) { | ||
pods, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).List(metav1.ListOptions{}) | ||
if err != nil { | ||
Logf("Error retrieving pod list in namespace %s: %+v", f.Namespace.Name, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we bomb out here, return an error or something instead of logging and continuing
} | ||
|
||
// Operator Logs | ||
if opPod.Name != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably need else block to handle opPod.Name being empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@simonlord Good point. I have just logged a message here as there is no need for a fail.
test/e2e/framework/framework.go
Outdated
|
||
func printLogs(read io.ReadCloser, fileName string) error { | ||
defer read.Close() | ||
env := os.Getenv("WERCKER_REPORT_ARTIFACTS_DIR") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs a better name
test/e2e/framework/framework.go
Outdated
env := os.Getenv("WERCKER_REPORT_ARTIFACTS_DIR") | ||
dst := os.Stdout | ||
if env != "" { | ||
filepath := env + "/" + fileName + ".log" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to use os.Separator here instead of "/", maybe use a fmt.Sprintf too
test/e2e/framework/framework.go
Outdated
podLogs := f.ClientSet.CoreV1().Pods(f.Namespace.Name).GetLogs(podName, options) | ||
if podLogs != nil { | ||
Logf("Writing %s container logs to file for %s", options.Container, podName) | ||
read, _ := podLogs.Stream() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is _ in this case? If it's an error we can't ignore it...
test/e2e/framework/framework.go
Outdated
@@ -272,3 +276,64 @@ func (f *Framework) AfterEach() { | |||
} | |||
f.OperatorInstalled = false | |||
} | |||
|
|||
func printMySQLPodContainerLogs(f *Framework) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (f *Framework) outputLogs() error
test/e2e/framework/framework.go
Outdated
func printMySQLPodContainerLogs(f *Framework) { | ||
pods, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).List(metav1.ListOptions{}) | ||
if err != nil { | ||
Logf("Error retrieving pod list in namespace %s: %+v", f.Namespace.Name, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return errors.Wrap(err, "listing test Pods")
(otherwise pods.Items
will panic below if the above fails)
test/e2e/framework/framework.go
Outdated
filepath := env + "/" + fileName + ".log" | ||
file, err := os.OpenFile(filepath, os.O_WRONLY|os.O_CREATE, 0666) | ||
if err != nil { | ||
return fmt.Errorf("Error getting file for logs: %+v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return errors.Wrapf(err, "opening log file %q", filepath)
test/e2e/framework/framework.go
Outdated
} | ||
} | ||
|
||
func printLogs(read io.ReadCloser, fileName string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass in full file path and load os.Getenv("WERCKER_REPORT_ARTIFACTS_DIR")
on Framework
initialisation
test/e2e/framework/framework.go
Outdated
env := os.Getenv("WERCKER_REPORT_ARTIFACTS_DIR") | ||
dst := os.Stdout | ||
if env != "" { | ||
filepath := env + "/" + fileName + ".log" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs moving as per above but:
filePath := path.Join(env, fmt.Sprintf("%s.log", fileName))
test/e2e/framework/framework.go
Outdated
} | ||
_, err := io.Copy(dst, read) | ||
if err != nil { | ||
return fmt.Errorf("Error exporting logs: %+v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return errors.Wrapf(err, "writing logs to %q", filepath)
test/e2e/framework/framework.go
Outdated
@@ -248,6 +250,8 @@ func (f *Framework) BeforeEach() { | |||
func (f *Framework) AfterEach() { | |||
RemoveCleanupAction(f.cleanupHandle) | |||
|
|||
printMySQLPodContainerLogs(f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if err := f.outputLogs(); err != nil {
Logf("Failed to output container logs: %v", err)
}
aa8b20a
to
031fcaf
Compare
031fcaf
to
631c5bc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Closes #177
MySQL Agent, Server and Operator logs will be exported as wercker artifacts on a per pod basis. If tests are run locally they are printed to stdout. E2E test namespace deletion follows regardless of whether the test passes or fails.