Skip to content

Commit 2ef420a

Browse files
committed
UPSTREAM: <carry>: migrate ocp-43975 to OTE
1 parent 637636f commit 2ef420a

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

tests-extension/.openshift-tests-extension/openshift_payload_olmv0.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,21 @@
345345
"exclude": "topology==\"External\""
346346
}
347347
},
348+
{
349+
"name": "[sig-operator][Jira:OLM] OLMv0 should PolarionID:43975-[OTP]olm operator serviceaccount should not rely on external networking for health check[Serial][Disruptive][Slow]",
350+
"labels": {
351+
"Extended": {},
352+
"NonHyperShiftHOST": {}
353+
},
354+
"resources": {
355+
"isolation": {}
356+
},
357+
"source": "openshift:payload:olmv0",
358+
"lifecycle": "blocking",
359+
"environmentSelector": {
360+
"exclude": "topology==\"External\""
361+
}
362+
},
348363
{
349364
"name": "[sig-operator][Jira:OLM] OLMv0 optional should PolarionID:68679-[OTP][Skipped:Disconnected]catalogsource with invalid name is created",
350365
"originalName": "[sig-operator][Jira:OLM] OLMv0 optional should PolarionID:68679-[Skipped:Disconnected]catalogsource with invalid name is created",

tests-extension/test/qe/specs/olmv0_common.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"os/exec"
77
"path/filepath"
8+
"regexp"
9+
"strconv"
810
"strings"
911
"time"
1012

@@ -1045,4 +1047,101 @@ var _ = g.Describe("[sig-operator][Jira:OLM] OLMv0 should", func() {
10451047
e2e.Logf("PrometheusRule validation passed: Alert rule is properly configured to monitor catalogsource_ready metric")
10461048
})
10471049

1050+
g.It("PolarionID:43975-[OTP]olm operator serviceaccount should not rely on external networking for health check[Disruptive][Slow]", g.Label("NonHyperShiftHOST"), func() {
1051+
g.By("1) get the cluster infrastructure")
1052+
infra, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("infrastructures", "cluster", "-o=jsonpath={.status.infrastructureTopology}").Output()
1053+
if err != nil {
1054+
e2e.Failf("Fail to get the cluster infra")
1055+
}
1056+
if infra != "SingleReplica" {
1057+
g.Skip("Not SNO cluster - skipping test ...")
1058+
}
1059+
1060+
originProfile := olmv0util.GetResource(oc, exutil.AsAdmin, exutil.WithoutNamespace, "apiserver", "cluster", "-o=jsonpath={.spec.audit.profile}")
1061+
o.Expect(originProfile).NotTo(o.BeEmpty())
1062+
if strings.Compare(originProfile, "Default") != 0 {
1063+
g.Skip("audit profile is not Default - skipping test ...")
1064+
}
1065+
1066+
g.By("2) get revision number")
1067+
revisionNumber1 := 0
1068+
reg := regexp.MustCompile(`at revision (\d+)`)
1069+
if reg == nil {
1070+
e2e.Failf("get revision number regexp err!")
1071+
}
1072+
output, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("kubeapiserver", "-o=jsonpath={..status.conditions[?(@.type==\"NodeInstallerProgressing\")]}").Output()
1073+
if err != nil {
1074+
e2e.Failf("Fail to get kubeapiserver")
1075+
}
1076+
result := reg.FindAllStringSubmatch(output, -1)
1077+
if result != nil {
1078+
revisionNumberStr1 := result[0][1]
1079+
revisionNumber1, _ = strconv.Atoi(revisionNumberStr1)
1080+
e2e.Logf("origin revision number is : %v", revisionNumber1)
1081+
} else {
1082+
e2e.Failf("Fail to get revision number")
1083+
}
1084+
1085+
g.By("3) Configuring the audit log policy to AllRequestBodies")
1086+
defer func() {
1087+
pathJSON := fmt.Sprintf("{\"spec\":{\"audit\":{\"profile\":\"%s\"}}}", originProfile)
1088+
e2e.Logf("recover to be %v", pathJSON)
1089+
exutil.PatchResource(oc, exutil.AsAdmin, exutil.WithoutNamespace, "apiserver", "cluster", "-p", pathJSON, "--type=merge")
1090+
output = olmv0util.GetResource(oc, exutil.AsAdmin, exutil.WithoutNamespace, "apiserver", "cluster", "-o=jsonpath={.spec.audit.profile}")
1091+
o.Expect(output).To(o.Equal("Default"))
1092+
}()
1093+
exutil.PatchResource(oc, exutil.AsAdmin, exutil.WithoutNamespace, "apiserver", "cluster", "-p", "{\"spec\":{\"audit\":{\"profile\":\"AllRequestBodies\"}}}", "--type=merge")
1094+
output = olmv0util.GetResource(oc, exutil.AsAdmin, exutil.WithoutNamespace, "apiserver", "cluster", "-o=jsonpath={.spec.audit.profile}")
1095+
o.Expect(output).To(o.Equal("AllRequestBodies"))
1096+
1097+
g.By("4) Wait for api rollout")
1098+
err = wait.PollUntilContextTimeout(context.TODO(), 30*time.Second, 600*time.Second, false, func(ctx context.Context) (bool, error) {
1099+
output, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("kubeapiserver", "-o=jsonpath={..status.conditions[?(@.type==\"NodeInstallerProgressing\")]}").Output()
1100+
e2e.Logf("kubeapiserver status output: %s", output)
1101+
if err != nil {
1102+
e2e.Logf("Fail to get kubeapiserver status, go next round")
1103+
return false, nil
1104+
}
1105+
if !strings.Contains(output, "AllNodesAtLatestRevision") {
1106+
e2e.Logf("the api is rolling, go next round")
1107+
return false, nil
1108+
}
1109+
result := reg.FindAllStringSubmatch(output, -1)
1110+
if result != nil {
1111+
revisionNumberStr2 := result[0][1]
1112+
revisionNumber2, _ := strconv.Atoi(revisionNumberStr2)
1113+
e2e.Logf("revision number is : %v", revisionNumber2)
1114+
if revisionNumber2 > revisionNumber1 {
1115+
return true, nil
1116+
}
1117+
e2e.Logf("revision number is not changed, go next round")
1118+
return false, nil
1119+
1120+
}
1121+
e2e.Logf("Fail to get revision number, go next round")
1122+
return false, nil
1123+
})
1124+
exutil.AssertWaitPollNoErr(err, "api not rollout")
1125+
1126+
// According to the case steps, wait for 5 minutes, then check the audit log doesn't contain olm-operator-serviceaccount.
1127+
g.By("Wait for 5 minutes, then check the audit log")
1128+
time.Sleep(5 * time.Minute)
1129+
1130+
g.By("check the audit log")
1131+
nodeName, err := exutil.GetFirstMasterNode(oc)
1132+
e2e.Logf("master node name: %s", nodeName)
1133+
o.Expect(err).NotTo(o.HaveOccurred())
1134+
auditlogPath := "43975.log"
1135+
defer func() {
1136+
_, _ = exec.Command("bash", "-c", "rm -fr "+auditlogPath).Output()
1137+
}()
1138+
outputPath, err := oc.AsAdmin().WithoutNamespace().Run("adm").Args("node-logs", nodeName, "--path=kube-apiserver/audit.log").OutputToFile(auditlogPath)
1139+
o.Expect(err).NotTo(o.HaveOccurred())
1140+
commandParserLog := "cat " + outputPath + " | grep -i health | grep -i subjectaccessreviews | grep -v Unhealth | jq -r '.user.username' | sort | uniq"
1141+
resultParserLog, err := exec.Command("bash", "-c", commandParserLog).Output()
1142+
o.Expect(err).NotTo(o.HaveOccurred())
1143+
e2e.Logf("Found usernames in audit log: %s", string(resultParserLog))
1144+
o.Expect(resultParserLog).NotTo(o.ContainSubstring("olm-operator-serviceaccount"))
1145+
})
1146+
10481147
})

0 commit comments

Comments
 (0)