Skip to content

Commit 75795d5

Browse files
Add check for instructions in manual ccrs
1 parent def3a79 commit 75795d5

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

e2e_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ func TestPlatformCompliance(t *testing.T) {
146146
}
147147
afterRemediation = true
148148

149+
err = helpers.CheckRulesForInstructions(tc, c, platformBindingName)
150+
if err != nil {
151+
t.Fatalf("Failed to check rules for instructions: %s", err)
152+
}
153+
149154
finalResults, err := helpers.CreateResultMap(tc, c, platformBindingName)
150155
if err != nil {
151156
t.Fatalf("Failed to create result map: %s", err)
@@ -259,6 +264,11 @@ func TestNodeCompliance(t *testing.T) {
259264
}
260265
afterRemediation = true
261266

267+
err = helpers.CheckRulesForInstructions(tc, c, nodeBindingName)
268+
if err != nil {
269+
t.Fatalf("Failed to check rules for instructions: %s", err)
270+
}
271+
262272
finalResults, err := helpers.CreateResultMap(tc, c, nodeBindingName)
263273
if err != nil {
264274
t.Fatalf("Failed to create result map: %s", err)

helpers/utilities.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,59 @@ func CreateResultMap(_ *testConfig.TestConfig, c dynclient.Client, suiteName str
17621762
return resultMap, nil
17631763
}
17641764

1765+
// CheckRulesForInstructions checks that all compliance check results have instructions.
1766+
// Compliance check results in the exception list are skipped from the instruction check.
1767+
func CheckRulesForInstructions(tc *testConfig.TestConfig, c dynclient.Client, suiteName string) error {
1768+
exceptionList := map[string]bool{
1769+
rhcos-node-master-bios-disable-usb-boot: true,
1770+
rhcos-node-master-wireless-disable-in-bios: true,
1771+
rhcos-node-worker-bios-disable-usb-boot: true,
1772+
rhcos-node-worker-wireless-disable-in-bios: true
1773+
}
1774+
1775+
labelSelector, err := labels.Parse(cmpv1alpha1.SuiteLabel + "=" + suiteName)
1776+
if err != nil {
1777+
return fmt.Errorf("failed to parse label selector: %w", err)
1778+
}
1779+
1780+
resultList := &cmpv1alpha1.ComplianceCheckResultList{}
1781+
opts := &dynclient.ListOptions{
1782+
LabelSelector: labelSelector,
1783+
Namespace: tc.OperatorNamespace.Namespace,
1784+
}
1785+
err = c.List(goctx.TODO(), resultList, opts)
1786+
if err != nil {
1787+
return fmt.Errorf("failed to get compliance check results for suite %s: %w", suiteName, err)
1788+
}
1789+
1790+
if len(resultList.Items) == 0 {
1791+
log.Printf("No compliance check results found for suite %s", suiteName)
1792+
return nil
1793+
}
1794+
1795+
// Check each result for instructions
1796+
var missingInstructions []string
1797+
for i := range resultList.Items {
1798+
result := &resultList.Items[i]
1799+
1800+
if exceptionList[result.Name] {
1801+
continue
1802+
}
1803+
1804+
if result.Instructions == "" {
1805+
missingInstructions = append(missingInstructions, result.Name)
1806+
log.Printf("Compliance check result '%s' does not have instructions", result.Name)
1807+
}
1808+
}
1809+
1810+
if len(missingInstructions) > 0 {
1811+
return fmt.Errorf("found %d compliance check result(s) without instructions for suite %s: %v",
1812+
len(missingInstructions), suiteName, missingInstructions)
1813+
}
1814+
1815+
return nil
1816+
}
1817+
17651818
// SaveResultAsYAML saves YAML data about the scan results to a file in the configured log directory.
17661819
func SaveResultAsYAML(tc *testConfig.TestConfig, results map[string]string, filename string) error {
17671820
p := path.Join(tc.LogDir, filename)

0 commit comments

Comments
 (0)