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

e2e: Don't rely on order of inconsistent results #790

Merged
merged 1 commit into from
Feb 7, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).
- Implemented a multi-step release process to prevent unintentional changes
from making their way into the release
([bug](https://github.com/openshift/compliance-operator/issues/783)).
- The TestInconsistentResult e2e test was relying on a certain order of results.
This bug was fixed and the test now passes with any order of results.

### Deprecations

Expand Down
41 changes: 24 additions & 17 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2454,37 +2454,44 @@ func TestE2E(t *testing.T) {
}

var expectedInconsistentSource string
var shouldHaveMostCommonState bool

if len(workerNodes) >= 3 {
// The annotations should list the node that had a different result
expectedInconsistentSource = workerNodes[0].Name + ":" + string(compv1alpha1.CheckResultPass)
inconsistentSources := rootLoginCheck.Annotations[compv1alpha1.ComplianceCheckResultInconsistentSourceAnnotation]
if inconsistentSources != expectedInconsistentSource {
return fmt.Errorf("expected that node %s would report %s, instead it reports %s", workerNodes[0].Name, expectedInconsistentSource, inconsistentSources)
}

// Since all the other nodes consistently fail, there should also be a common result
shouldHaveMostCommonState = true
mostCommonState := rootLoginCheck.Annotations[compv1alpha1.ComplianceCheckResultMostCommonAnnotation]
if mostCommonState != string(compv1alpha1.CheckResultFail) {
return fmt.Errorf("expected that there would be a common FAIL state, instead got %s", mostCommonState)
}
} else if len(workerNodes) == 2 {
// example: ip-10-0-184-135.us-west-1.compute.internal:PASS,ip-10-0-226-48.us-west-1.compute.internal:FAIL
expectedInconsistentSource = workerNodes[0].Name + ":" + string(compv1alpha1.CheckResultPass) + "," + workerNodes[1].Name + string(compv1alpha1.CheckResultFail)
var expectedInconsistentSource [2]string
expectedInconsistentSource[0] = workerNodes[0].Name + ":" + string(compv1alpha1.CheckResultPass) + "," + workerNodes[1].Name + string(compv1alpha1.CheckResultFail)
expectedInconsistentSource[1] = workerNodes[1].Name + ":" + string(compv1alpha1.CheckResultFail) + "," + workerNodes[0].Name + string(compv1alpha1.CheckResultPass)

inconsistentSources := rootLoginCheck.Annotations[compv1alpha1.ComplianceCheckResultInconsistentSourceAnnotation]
if inconsistentSources != expectedInconsistentSource[0] && inconsistentSources != expectedInconsistentSource[1] {
return fmt.Errorf(
"expected that node %s would report %s or %s, instead it reports %s",
workerNodes[0].Name,
expectedInconsistentSource[0], expectedInconsistentSource[1],
inconsistentSources)
}

// If there are only two worker nodes, we won't be able to find the common status, so both
// nodes would be listed as inconsistent -- we can't figure out which of the two results is
// consistent and which is not
shouldHaveMostCommonState = false
// consistent and which is not. Therefore this branch skips the check for
// compv1alpha1.ComplianceCheckResultMostCommonAnnotation
} else {
E2ELog(t, "Only one worker node? Shortcutting the test")
return nil
}

inconsistentSources := rootLoginCheck.Annotations[compv1alpha1.ComplianceCheckResultInconsistentSourceAnnotation]
if inconsistentSources != expectedInconsistentSource {
return fmt.Errorf("expected that node %s would report %s, instead it reports %s", workerNodes[0].Name, expectedInconsistentSource, inconsistentSources)
}

if shouldHaveMostCommonState {
mostCommonState := rootLoginCheck.Annotations[compv1alpha1.ComplianceCheckResultMostCommonAnnotation]
if mostCommonState != string(compv1alpha1.CheckResultFail) {
return fmt.Errorf("expected that there would be a common FAIL state, instead got %s", mostCommonState)
}
}

// Since all states were either pass or fail, we still create the remediation
workerRemediations := []string{
fmt.Sprintf("%s-no-direct-root-logins", workerScanName),
Expand Down