Skip to content
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

Introduce a mechanism for gathering test artifacts during individual test failures #2442

Conversation

timflannagan
Copy link
Member

Update the testing e2e suite and add a mechanism for gathering test
artifacts during individual test failures. Currently, container logs are
gathered when deprovisioning upstream kind clusters, yet we lack
fine-grain ability to diagnose test failures further.

Note: test failures use the CurrentGinkgoTestDescription.Failed field
to determine failures. Testing artifacts are only gathered when the base
$ARTIFACTS_DIR environment variable has been specified.

Add a collect-ci-artifacts.sh bash script, responsible for gathering OLM
native resources for an individual testing namespace. This bash script
will be called when tearing down the generated testing namespace for
relevant e2e packages. Currently, the artifact gathering process is
restricted to only a single namespace - longer term, it might be
possible to instead migrate towards collecting resources that all share
a similar label selector, and utilizing that label selector to handle
multi-namespace testing scenarios.

Introduce another helper function in test/e2e/util_test.go that's
responsible for gathering test artifacts (i.e. calling this newly
introduced script) when the test case had failed, and in either case,
delete the namespace.

Signed-off-by: timflannagan [email protected]

Reviewer Checklist

  • Implementation matches the proposed design, or proposal is updated to match implementation
  • Sufficient unit test coverage
  • Sufficient end-to-end test coverage
  • Docs updated or added to /doc
  • Commit messages sensible and descriptive

}

// compiled test binary running e2e tests is run from the root ./bin directory
cmd := exec.Command("../test/e2e/collect-ci-artifacts.sh")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: likely need to stat this file vs. relying on a local file reference.

if currentTest.Failed {
log("collecting the %s namespace artifacts as the '%s' test case failed", ns.GetName(), currentTest.TestText)
if err := ctx.Ctx().DumpNamespaceArtifacts(ns.GetName()); err != nil {
log("failed to collect namespace artifacts: %v", err)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We avoid performing operations like Expect(err).ToBe(Nil()) here as we want the namespace to be deleted in any case, regardless of whether this method fails to gather artifacts.

echo "Storing the test artifact output in the ${TEST_ARTIFACTS_DIR} directory"
for command in "${commands[@]}"; do
echo "Collecting ${command} output..."
COMMAND_OUTPUT_FILE=${TEST_ARTIFACTS_DIR}/${command// /_}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This output file likely needs some work - here's an example of an e2e run locally:

$ make e2e-local ARTIFACTS_DIR=/tmp/artifacts
...
$ tree /tmp/artifacts/catalog-e2e-2jq84/
/tmp/artifacts/catalog-e2e-2jq84/
├── get_clusterserviceversions_-o_yaml
├── get_events_--sort-by_.lastTimestamp
├── get_installplans_-o_yaml
├── get_operatorgroups_-o_yaml
├── get_pods_-o_wide
└── get_subscriptions_-o_yaml

}
ctx.Logf("collecting logs in the %s artifacts directory", ctx.artifactsDir)

logDir := filepath.Join(ctx.artifactsDir, namespace)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to suggestions on how to best dump individual test failure artifacts. In the current implementation, this creates a directory named after whatever namespace was generated for that test. It wouldn't be immediately clear how to map this to an individual test failure, outside of looking at the overall CI logs that are produced during a run (as the namespace generated is logged).

for command in "${commands[@]}"; do
echo "Collecting ${command} output..."
COMMAND_OUTPUT_FILE=${TEST_ARTIFACTS_DIR}/${command// /_}
kubectl -n ${TEST_NAMESPACE} ${command} >> "${COMMAND_OUTPUT_FILE}"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this script would also neglect deleting any "empty" files here - any file that contains an empty List will still be created and housed in this directory:

apiVersion: v1
items: []
kind: List
metadata:
  resourceVersion: ""
  selfLink: ""

…st failures

Update the testing e2e suite and add a mechanism for gathering test
artifacts during individual test failures. Currently, container logs are
gathered when deprovisioning upstream kind clusters, yet we lack
fine-grain ability to diagnose test failures further.

Note: test failures use the `CurrentGinkgoTestDescription.Failed` field
to determine failures. Testing artifacts are only gathered when the base
$ARTIFACTS_DIR environment variable has been specified.

Add a collect-ci-artifacts.sh bash script, responsible for gathering OLM
native resources for an individual testing namespace. This bash script
will be called when tearing down the generated testing namespace for
relevant e2e packages. Currently, the artifact gathering process is
restricted to only a single namespace - longer term, it might be
possible to instead migrate towards collecting resources that all share
a similar label selector, and utilizing that label selector to handle
multi-namespace testing scenarios.

Introduce another helper function in test/e2e/util_test.go that's
responsible for gathering test artifacts (i.e. calling this newly
introduced script) when the test case had failed, and in either case,
delete the namespace.

Signed-off-by: timflannagan <[email protected]>
@timflannagan timflannagan force-pushed the test/collect-failed-test-artifacts branch from 29d4377 to 95ba037 Compare November 10, 2021 21:04
@kevinrizza
Copy link
Member

/approve

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 10, 2021
@timflannagan timflannagan changed the title Introduce mechanism for gathering test artifacts during individual test failures Introduce a mechanism for gathering test artifacts during individual test failures Nov 10, 2021
Copy link
Contributor

@anik120 anik120 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 11, 2021
@openshift-ci
Copy link

openshift-ci bot commented Nov 11, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: anik120, kevinrizza, timflannagan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 4cc28bb into operator-framework:master Nov 11, 2021
@timflannagan timflannagan deleted the test/collect-failed-test-artifacts branch November 11, 2021 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants