-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add must_gather tests #943
base: release-4.10
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
package pao_mustgather | ||
|
||
import ( | ||
"archive/tar" | ||
"compress/gzip" | ||
"context" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
testutils "github.com/openshift-kni/performance-addon-operators/functests/utils" | ||
testclient "github.com/openshift-kni/performance-addon-operators/functests/utils/client" | ||
"github.com/openshift-kni/performance-addon-operators/functests/utils/nodes" | ||
"github.com/openshift-kni/performance-addon-operators/functests/utils/profiles" | ||
machineconfigv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
|
||
. "github.com/onsi/ginkgo" | ||
"github.com/onsi/gomega" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
const destDir = "must-gather" | ||
|
||
var _ = Describe("[rfe_id: 50649] Performance Addon Operator Must Gather", func() { | ||
mgContentFolder := "" | ||
|
||
testutils.BeforeAll(func() { | ||
destDirContent, err := ioutil.ReadDir(destDir) | ||
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "unable to read contents from destDir:%s. error: %w", destDir, err) | ||
|
||
for _, content := range destDirContent { | ||
if !content.IsDir() { | ||
continue | ||
} | ||
mgContentFolder = filepath.Join(destDir, content.Name()) | ||
} | ||
}) | ||
|
||
Context("with a freshly executed must-gather command", func() { | ||
It("Verify Generic cluster resource definitions are captured", func() { | ||
|
||
var genericFiles = []string{ | ||
"version", | ||
"cluster-scoped-resources/config.openshift.io/featuregates/cluster.yaml", | ||
"namespaces/openshift-cluster-node-tuning-operator/tuned.openshift.io/tuneds/default.yaml", | ||
"namespaces/openshift-cluster-node-tuning-operator/tuned.openshift.io/tuneds/rendered.yaml", | ||
} | ||
|
||
By(fmt.Sprintf("Checking Folder: %q\n", mgContentFolder)) | ||
By("\tLooking for generic files") | ||
err := checkfilesExist(genericFiles, mgContentFolder) | ||
Expect(err).ToNot(gomega.HaveOccurred()) | ||
}) | ||
|
||
It("Verify PAO cluster resources are captured", func() { | ||
profile, _ := profiles.GetByNodeLabels(testutils.NodeSelectorLabels) | ||
if profile == nil { | ||
Skip("No Performance Profile found") | ||
} | ||
//replace peformance.yaml for profile.Name when data is generated in the node | ||
ClusterSpecificFiles := []string{ | ||
"cluster-scoped-resources/performance.openshift.io/performanceprofiles/performance.yaml", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...perhaps to construct the names here (and below)? |
||
"cluster-scoped-resources/machineconfiguration.openshift.io/kubeletconfigs/performance-performance.yaml", | ||
"namespaces/openshift-cluster-node-tuning-operator/tuned.openshift.io/tuneds/openshift-node-performance-performance.yaml", | ||
} | ||
|
||
By(fmt.Sprintf("Checking Folder: %q\n", mgContentFolder)) | ||
By("\tLooking for generic files") | ||
err := checkfilesExist(ClusterSpecificFiles, mgContentFolder) | ||
Expect(err).ToNot(gomega.HaveOccurred()) | ||
}) | ||
|
||
It("Verify hardware related information are captured", func() { | ||
nodeSpecificFiles := []string{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I'd move this down below closer to the function using this slice. Now it is unnecessarily far from the calling site. |
||
"proc/cpuinfo", | ||
"cpu_affinities.json", | ||
"dmesg", | ||
"irq_affinities.json", | ||
"lscpu", | ||
"machineinfo.json", | ||
"podresources.json", | ||
"proc_cmdline", | ||
"sysinfo.log", | ||
} | ||
|
||
var workerRTNodes []corev1.Node | ||
|
||
workerRTNodes, err := nodes.GetByLabels(testutils.NodeSelectorLabels) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
workerRTNodes, err = nodes.MatchingOptionalSelector(workerRTNodes) | ||
Expect(err).ToNot(HaveOccurred()) | ||
cnfWorkerNode := workerRTNodes[0].ObjectMeta.Name | ||
|
||
// find the path of sysinfo.tgz of the correct node | ||
snapShotName := "" | ||
err = filepath.Walk(mgContentFolder, | ||
func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if !info.IsDir() && info.Name() == "sysinfo.tgz" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this should probably be a constant (in a must-gather package?) |
||
if strings.Contains(path, cnfWorkerNode) { | ||
snapShotName = path | ||
} | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
|
||
snapShotPath := filepath.Dir(snapShotName) | ||
|
||
err = Untar(snapShotPath, snapShotName) | ||
Expect(err).ToNot(HaveOccurred(), "failed to read the %s: %v", snapShotName, err) | ||
|
||
err = checkfilesExist(nodeSpecificFiles, snapShotPath) | ||
Expect(err).ToNot(gomega.HaveOccurred()) | ||
}) | ||
|
||
It("Verify machineconfig resources are captured", func() { | ||
mcps := &machineconfigv1.MachineConfigPoolList{} | ||
err := testclient.Client.List(context.TODO(), mcps) | ||
Expect(err).ToNot(HaveOccurred()) | ||
mcpFiles := make([]string, len(mcps.Items)) | ||
for _, item := range mcps.Items { | ||
mcpFiles = append(mcpFiles, fmt.Sprintf("cluster-scoped-resources/machineconfiguration.openshift.io/machineconfigpools/%s.yaml", item.Name)) | ||
} | ||
err = checkfilesExist(mcpFiles, mgContentFolder) | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
}) | ||
}) | ||
|
||
func checkfilesExist(listOfFiles []string, path string) error { | ||
for _, f := range listOfFiles { | ||
file := filepath.Join(path, f) | ||
if _, err := os.Stat(file); errors.Is(err, os.ErrNotExist) { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func Untar(root string, snapshotName string) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we can/should reuse |
||
var err error | ||
r, err := os.Open(snapshotName) | ||
if err != nil { | ||
return err | ||
} | ||
defer r.Close() | ||
|
||
gzr, err := gzip.NewReader(r) | ||
if err != nil { | ||
return err | ||
} | ||
defer gzr.Close() | ||
|
||
tr := tar.NewReader(gzr) | ||
for { | ||
header, err := tr.Next() | ||
if err == io.EOF { | ||
return nil | ||
} | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
target := filepath.Join(root, header.Name) | ||
mode := os.FileMode(header.Mode) | ||
|
||
switch header.Typeflag { | ||
case tar.TypeDir: | ||
err = os.MkdirAll(target, mode) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
case tar.TypeReg: | ||
dst, err := os.OpenFile(target, os.O_CREATE|os.O_RDWR, mode) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = io.Copy(dst, tr) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
dst.Close() | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package pao_mustgather | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"testing" | ||
|
||
"github.com/onsi/ginkgo" | ||
. "github.com/onsi/ginkgo" | ||
"github.com/onsi/gomega" | ||
. "github.com/onsi/gomega" | ||
"github.com/openshift-kni/performance-addon-operators/functests/utils/junit" | ||
|
||
ginkgo_reporters "kubevirt.io/qe-tools/pkg/ginkgo-reporters" | ||
) | ||
|
||
var _ = BeforeSuite(func() { | ||
By("Looking for oc tool") | ||
ocExec, err := exec.LookPath("oc") | ||
if err != nil { | ||
fmt.Fprintf(ginkgo.GinkgoWriter, "Unable to find oc executable: %v\n", err) | ||
Skip(fmt.Sprintf("unable to find 'oc' executable %v\n", err)) | ||
} | ||
|
||
mgImage := "quay.io/openshift-kni/performance-addon-operator-must-gather" | ||
mgTag := "4.10-snapshot" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be constructed from PAO version, or, in general, NOT be hardcoded? |
||
|
||
mgImageParam := fmt.Sprintf("--image=%s:%s", mgImage, mgTag) | ||
mgDestDirParam := fmt.Sprintf("--dest-dir=%s", destDir) | ||
|
||
cmdline := []string{ | ||
ocExec, | ||
"adm", | ||
"must-gather", | ||
mgImageParam, | ||
mgDestDirParam, | ||
} | ||
ginkgo.By(fmt.Sprintf("running: %v\n", cmdline)) | ||
|
||
cmd := exec.Command(cmdline[0], cmdline[1:]...) | ||
cmd.Stderr = ginkgo.GinkgoWriter | ||
|
||
_, err = cmd.Output() | ||
gomega.Expect(err).ToNot(gomega.HaveOccurred()) | ||
}) | ||
|
||
var _ = AfterSuite(func() { | ||
os.RemoveAll(destDir) | ||
}) | ||
|
||
func TestPaoMustgatherTests(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
|
||
rr := []Reporter{} | ||
if ginkgo_reporters.Polarion.Run { | ||
rr = append(rr, &ginkgo_reporters.Polarion) | ||
} | ||
rr = append(rr, junit.NewJUnitReporter("must-gather")) | ||
RunSpecsWithDefaultAndCustomReporters(t, "PAO must-gather tests", rr) | ||
} |
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.
do we need this for anything else?
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.
this PR is a cherry-pick. We can continue in the original one: #943