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

cnf ran: update skipped talm test case #210

Merged
merged 1 commit into from
Sep 20, 2024
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
4 changes: 2 additions & 2 deletions tests/cnf/ran/internal/ranconfig/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bmcTimeout: "15s"
ocpUpgradeUpstreamUrl: "https://api.openshift.com/api/upgrades_info/v1/graph"
ptpOperatorNamespace: "openshift-ptp"
talmPreCachePolicies:
- "common-config-policy"
- "common-subscriptions-policy"
- "^common(-v4\\.\\d\\d)?-config-policy"
- "^common(-v4\\.\\d\\d)?-subscriptions-policy"
ztpSiteGenerateImage: "registry-proxy.engineering.redhat.com/rh-osbs/openshift4-ztp-site-generate"
...
53 changes: 40 additions & 13 deletions tests/cnf/ran/talm/tests/talm-precache.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tests
import (
"context"
"fmt"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -38,7 +39,10 @@ import (
var _ = Describe("TALM precache", Label(tsparams.LabelPreCacheTestCases), func() {
When("there is a single spoke", func() {
Context("precache operator", func() {
var suffixes []string
var (
policies []string
suffixes []string
)

BeforeEach(func() {
By("verifying TalmPrecachePolicies from config are available on hub")
Expand All @@ -48,7 +52,11 @@ var _ = Describe("TALM precache", Label(tsparams.LabelPreCacheTestCases), func()
Skip("could not find all policies in TalmPreCachePolicies in config on hub")
}

suffixes = copyPoliciesWithSubscription(preCachePolicies)
policies, suffixes = copyPoliciesWithSubscription(preCachePolicies)

for _, suffix := range suffixes {
policies = append(policies, tsparams.PolicyName+suffix)
}
})

AfterEach(func() {
Expand All @@ -60,11 +68,6 @@ var _ = Describe("TALM precache", Label(tsparams.LabelPreCacheTestCases), func()

// 48902 Tests image precaching - operators
It("tests for precache operator with multiple sources", reportxml.ID("48902"), func() {
var policies []string
for _, suffix := range suffixes {
policies = append(policies, tsparams.PolicyName+suffix)
}

By("creating CGU with created operator upgrade policy")
cguBuilder := getPrecacheCGU(policies, []string{RANConfig.Spoke1Name})
_, err := cguBuilder.Create()
Expand Down Expand Up @@ -607,16 +610,26 @@ func checkPrecachePodLog(client *clients.Settings) error {
}

// checkPoliciesExist returns the PolicyBuilder for all the provided policyNames, regardless of namespace, and whether
// all policyNames could be found on the hub.
// all policyNames could be found on the hub. It takes the policyNames as valid regular expressions and uses a match to
// determine if a policy exists.
func checkPoliciesExist(client *clients.Settings, policyNames []string) ([]*ocm.PolicyBuilder, bool) {
var policyRegexps []*regexp.Regexp

for _, policyName := range policyNames {
policyRegexp, err := regexp.Compile(policyName)
Expect(err).ToNot(HaveOccurred(), "Failed to compile policy name regex %s", policyName)

policyRegexps = append(policyRegexps, policyRegexp)
}

allPolicies, err := ocm.ListPoliciesInAllNamespaces(client)
Expect(err).ToNot(HaveOccurred(), "Failed to list policies in all namespaces")

var expectedPolicies []*ocm.PolicyBuilder

for _, policyName := range policyNames {
for _, policyRegexp := range policyRegexps {
for _, policy := range allPolicies {
if policy.Object.Name == policyName {
if policyRegexp.MatchString(policy.Object.Name) {
expectedPolicies = append(expectedPolicies, policy)

break
Expand All @@ -627,8 +640,14 @@ func checkPoliciesExist(client *clients.Settings, policyNames []string) ([]*ocm.
return expectedPolicies, len(expectedPolicies) == len(policyNames)
}

func copyPoliciesWithSubscription(policies []*ocm.PolicyBuilder) []string {
var suffixes []string
// copyPoliciesWithSubscription copies the policies that have a subscription and makes them NonCompliant. Policies
// without a subscription have their names returned first and then the second return is the suffixes for policies that
// were copied.
func copyPoliciesWithSubscription(policies []*ocm.PolicyBuilder) ([]string, []string) {
var (
originals []string
suffixes []string
)

for index, policy := range policies {
glog.V(tsparams.LogLevel).Infof(
Expand All @@ -638,6 +657,8 @@ func copyPoliciesWithSubscription(policies []*ocm.PolicyBuilder) []string {
configPolicy, err := ranhelper.UnmarshalRaw[configurationPolicyv1.ConfigurationPolicy](template.ObjectDefinition.Raw)
Expect(err).ToNot(HaveOccurred(), "Failed to unmarshal config policy")

hadSubscription := false

for _, objectTemplate := range configPolicy.Spec.ObjectTemplates {
untyped := &unstructured.Unstructured{}
err := untyped.UnmarshalJSON(objectTemplate.ObjectDefinition.Raw)
Expand All @@ -648,6 +669,8 @@ func copyPoliciesWithSubscription(policies []*ocm.PolicyBuilder) []string {
continue
}

hadSubscription = true

// if the current policy has a subscription then copy the policy and force it to be non-compliant
suffix := fmt.Sprintf("-with-subscription-%d", index)
suffixes = append(suffixes, suffix)
Expand Down Expand Up @@ -692,7 +715,11 @@ func copyPoliciesWithSubscription(policies []*ocm.PolicyBuilder) []string {

break
}

if !hadSubscription {
originals = append(originals, policy.Definition.Name)
}
}

return suffixes
return originals, suffixes
}
Loading