From b8ab35e6c54fa6fcf9b9c10ea2327f0c7b4fa020 Mon Sep 17 00:00:00 2001 From: travisn Date: Wed, 17 Apr 2019 22:21:51 -0600 Subject: [PATCH] tests: collect the operator log prior to a pod restart Signed-off-by: travisn --- .../installer/cassandra_installer.go | 4 +-- tests/framework/installer/ceph_installer.go | 31 ++++++++++--------- .../installer/cockroachdb_installer.go | 4 +-- tests/framework/installer/edgefs_installer.go | 4 +-- tests/framework/installer/nfs_installer.go | 4 +-- tests/framework/utils/k8s_helper.go | 20 +++++++++--- 6 files changed, 39 insertions(+), 28 deletions(-) diff --git a/tests/framework/installer/cassandra_installer.go b/tests/framework/installer/cassandra_installer.go index 4670fbc1f..00e10021f 100644 --- a/tests/framework/installer/cassandra_installer.go +++ b/tests/framework/installer/cassandra_installer.go @@ -164,6 +164,6 @@ func (ci *CassandraInstaller) UninstallCassandra(systemNamespace string, namespa func (ci *CassandraInstaller) GatherAllCassandraLogs(systemNamespace, namespace, testName string) { logger.Infof("Gathering all logs from Cassandra Cluster %s", namespace) - ci.k8sHelper.GetRookLogs("rook-cassandra-operator", Env.HostType, systemNamespace, testName) - ci.k8sHelper.GetRookLogs("rook-cassandra", Env.HostType, namespace, testName) + ci.k8sHelper.GetLogs("rook-cassandra-operator", Env.HostType, systemNamespace, testName) + ci.k8sHelper.GetLogs("rook-cassandra", Env.HostType, namespace, testName) } diff --git a/tests/framework/installer/ceph_installer.go b/tests/framework/installer/ceph_installer.go index 6de0a855f..1624fb70f 100644 --- a/tests/framework/installer/ceph_installer.go +++ b/tests/framework/installer/ceph_installer.go @@ -309,7 +309,7 @@ func (h *CephInstaller) InstallRookOnK8sWithHostPathAndDevices(namespace, storeT } if !h.k8shelper.IsPodInExpectedState("rook-ceph-operator", onamespace, "Running") { logger.Error("rook-ceph-operator is not running") - h.k8shelper.GetRookLogs("rook-ceph-operator", Env.HostType, onamespace, "test-setup") + h.k8shelper.GetLogs("rook-ceph-operator", Env.HostType, onamespace, "test-setup") logger.Error("rook-ceph-operator is not Running, abort!") return false, err } @@ -486,20 +486,21 @@ func (h *CephInstaller) cleanupDir(node, dir string) error { func (h *CephInstaller) GatherAllRookLogs(namespace, systemNamespace string, testName string) { logger.Infof("Gathering all logs from Rook Cluster %s", namespace) - h.k8shelper.GetRookLogs("rook-ceph-operator", Env.HostType, systemNamespace, testName) - h.k8shelper.GetRookLogs("rook-ceph-agent", Env.HostType, systemNamespace, testName) - h.k8shelper.GetRookLogs("rook-discover", Env.HostType, systemNamespace, testName) - h.k8shelper.GetRookLogs("rook-ceph-mgr", Env.HostType, namespace, testName) - h.k8shelper.GetRookLogs("rook-ceph-mon", Env.HostType, namespace, testName) - h.k8shelper.GetRookLogs("rook-ceph-osd", Env.HostType, namespace, testName) - h.k8shelper.GetRookLogs("rook-ceph-osd-prepare", Env.HostType, namespace, testName) - h.k8shelper.GetRookLogs("rook-ceph-rgw", Env.HostType, namespace, testName) - h.k8shelper.GetRookLogs("rook-ceph-mds", Env.HostType, namespace, testName) - h.k8shelper.GetRookContainerLogs("rook-ceph-mgr", Env.HostType, namespace, testName, opspec.ConfigInitContainerName) - h.k8shelper.GetRookContainerLogs("rook-ceph-mon", Env.HostType, namespace, testName, opspec.ConfigInitContainerName) - h.k8shelper.GetRookContainerLogs("rook-ceph-osd", Env.HostType, namespace, testName, opspec.ConfigInitContainerName) - h.k8shelper.GetRookContainerLogs("rook-ceph-rgw", Env.HostType, namespace, testName, opspec.ConfigInitContainerName) - h.k8shelper.GetRookContainerLogs("rook-ceph-mds", Env.HostType, namespace, testName, opspec.ConfigInitContainerName) + h.k8shelper.GetPreviousLogs("rook-ceph-operator", Env.HostType, systemNamespace, testName) + h.k8shelper.GetLogs("rook-ceph-operator", Env.HostType, systemNamespace, testName) + h.k8shelper.GetLogs("rook-ceph-agent", Env.HostType, systemNamespace, testName) + h.k8shelper.GetLogs("rook-discover", Env.HostType, systemNamespace, testName) + h.k8shelper.GetLogs("rook-ceph-mgr", Env.HostType, namespace, testName) + h.k8shelper.GetLogs("rook-ceph-mon", Env.HostType, namespace, testName) + h.k8shelper.GetLogs("rook-ceph-osd", Env.HostType, namespace, testName) + h.k8shelper.GetLogs("rook-ceph-osd-prepare", Env.HostType, namespace, testName) + h.k8shelper.GetLogs("rook-ceph-rgw", Env.HostType, namespace, testName) + h.k8shelper.GetLogs("rook-ceph-mds", Env.HostType, namespace, testName) + h.k8shelper.GetContainerLogs("rook-ceph-mgr", Env.HostType, namespace, testName, opspec.ConfigInitContainerName) + h.k8shelper.GetContainerLogs("rook-ceph-mon", Env.HostType, namespace, testName, opspec.ConfigInitContainerName) + h.k8shelper.GetContainerLogs("rook-ceph-osd", Env.HostType, namespace, testName, opspec.ConfigInitContainerName) + h.k8shelper.GetContainerLogs("rook-ceph-rgw", Env.HostType, namespace, testName, opspec.ConfigInitContainerName) + h.k8shelper.GetContainerLogs("rook-ceph-mds", Env.HostType, namespace, testName, opspec.ConfigInitContainerName) } // NewCephInstaller creates new instance of CephInstaller diff --git a/tests/framework/installer/cockroachdb_installer.go b/tests/framework/installer/cockroachdb_installer.go index b7a77c432..f61c068e9 100644 --- a/tests/framework/installer/cockroachdb_installer.go +++ b/tests/framework/installer/cockroachdb_installer.go @@ -151,6 +151,6 @@ func (h *CockroachDBInstaller) UninstallCockroachDB(systemNamespace, namespace s func (h *CockroachDBInstaller) GatherAllCockroachDBLogs(systemNamespace, namespace, testName string) { logger.Infof("Gathering all logs from cockroachdb cluster %s", namespace) - h.k8shelper.GetRookLogs("rook-cockroachdb-operator", Env.HostType, systemNamespace, testName) - h.k8shelper.GetRookLogs("rook-cockroachdb", Env.HostType, namespace, testName) + h.k8shelper.GetLogs("rook-cockroachdb-operator", Env.HostType, systemNamespace, testName) + h.k8shelper.GetLogs("rook-cockroachdb", Env.HostType, namespace, testName) } diff --git a/tests/framework/installer/edgefs_installer.go b/tests/framework/installer/edgefs_installer.go index e3cee8baf..d57c2ccc6 100644 --- a/tests/framework/installer/edgefs_installer.go +++ b/tests/framework/installer/edgefs_installer.go @@ -153,6 +153,6 @@ func (h *EdgefsInstaller) UninstallEdgefs(systemNamespace, namespace string) { func (h *EdgefsInstaller) GatherAllEdgefsLogs(systemNamespace, namespace, testName string) { logger.Infof("Gathering all logs from edgefs cluster %s", namespace) - h.k8shelper.GetRookLogs("rook-edgefs-operator", Env.HostType, systemNamespace, testName) - h.k8shelper.GetRookLogs("rook-edgefs", Env.HostType, namespace, testName) + h.k8shelper.GetLogs("rook-edgefs-operator", Env.HostType, systemNamespace, testName) + h.k8shelper.GetLogs("rook-edgefs", Env.HostType, namespace, testName) } diff --git a/tests/framework/installer/nfs_installer.go b/tests/framework/installer/nfs_installer.go index 8c763d653..5542a18b8 100644 --- a/tests/framework/installer/nfs_installer.go +++ b/tests/framework/installer/nfs_installer.go @@ -199,8 +199,8 @@ func (h *NFSInstaller) UninstallNFSServer(systemNamespace, namespace string) { // GatherAllNFSServerLogs gathers all NFS Server logs func (h *NFSInstaller) GatherAllNFSServerLogs(systemNamespace, namespace, testName string) { logger.Infof("Gathering all logs from NFSServer %s", namespace) - h.k8shelper.GetRookLogs("rook-nfs-operator", Env.HostType, systemNamespace, testName) - h.k8shelper.GetRookLogs("rook-nfs", Env.HostType, namespace, testName) + h.k8shelper.GetLogs("rook-nfs-operator", Env.HostType, systemNamespace, testName) + h.k8shelper.GetLogs("rook-nfs", Env.HostType, namespace, testName) } // GetNFSServerClusterIP gets the nfs server cluster ip on which it serves diff --git a/tests/framework/utils/k8s_helper.go b/tests/framework/utils/k8s_helper.go index 19e32d9a5..8070ccd89 100644 --- a/tests/framework/utils/k8s_helper.go +++ b/tests/framework/utils/k8s_helper.go @@ -1419,13 +1419,23 @@ func (k8sh *K8sHelper) IsRookInstalled(namespace string) bool { return false } -// GetRookLogs captures logs from specified rook pod and writes it to specified file -func (k8sh *K8sHelper) GetRookLogs(podAppName string, hostType string, namespace string, testName string) { - k8sh.GetRookContainerLogs(podAppName, hostType, namespace, testName, "") +// GetPreviousLogs captures logs from the previous run of the container if it exists +func (k8sh *K8sHelper) GetPreviousLogs(podAppName string, hostType string, namespace string, testName string) { + k8sh.getContainerLogs(podAppName, hostType, namespace, testName, "", true) } -func (k8sh *K8sHelper) GetRookContainerLogs(podAppName, hostType, namespace, testName, containerName string) { - logOpts := &v1.PodLogOptions{} +// GetLogs captures logs from specified rook pod and writes it to specified file +func (k8sh *K8sHelper) GetLogs(podAppName string, hostType string, namespace string, testName string) { + k8sh.getContainerLogs(podAppName, hostType, namespace, testName, "", false) +} + +// GetLogs captures logs from a specific container in a pod +func (k8sh *K8sHelper) GetContainerLogs(podAppName, hostType, namespace, testName, containerName string) { + k8sh.getContainerLogs(podAppName, hostType, namespace, testName, containerName, false) +} + +func (k8sh *K8sHelper) getContainerLogs(podAppName, hostType, namespace, testName, containerName string, previousLog bool) { + logOpts := &v1.PodLogOptions{Previous: previousLog} if containerName != "" { logOpts.Container = containerName }