Skip to content

Commit

Permalink
MGMT-19258: Identify and copy shared code
Browse files Browse the repository at this point in the history
MGMT-19258: Copied context sensitive funcs into a context

MGMT-19258: Ensure that all context sensitive code is in test context
  • Loading branch information
paul-maidment committed Jan 1, 2025
1 parent 6c35570 commit 8930f91
Show file tree
Hide file tree
Showing 23 changed files with 3,570 additions and 2,185 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,10 @@ deploy-dev-infra: create-hub-cluster
########

test:
$(MAKE) _run_subsystem_test AUTH_TYPE=rhsso ENABLE_ORG_TENANCY=true ENABLE_ORG_BASED_FEATURE_GATES=true
$(MAKE) _run_subsystem_test AUTH_TYPE=rhsso ENABLE_ORG_TENANCY=true ENABLE_ORG_BASED_FEATURE_GATES=true TEST="$(or $(TEST),'github.com/openshift/assisted-service/subsystem')"

test-kube-api:
$(MAKE) _run_subsystem_test AUTH_TYPE=local FOCUS="$(or ${FOCUS},kube-api)"
$(MAKE) _run_subsystem_test AUTH_TYPE=local TEST="$(or $(TEST),'github.com/openshift/assisted-service/subsystem/kubeapi')"

# Alias for test
subsystem-test: test
Expand Down Expand Up @@ -490,7 +490,7 @@ _run_subsystem_test:
TEST_TOKEN_UNALLOWED="$(shell cat $(BUILD_FOLDER)/auth-tokenUnallowedString)" \
TEST_TOKEN_EDITOR="$(shell cat $(BUILD_FOLDER)/auth-tokenClusterEditor)" \
RELEASE_SOURCES='$(or ${RELEASE_SOURCES},${DEFAULT_RELEASE_SOURCES})' \
$(MAKE) _test TEST_SCENARIO=subsystem TIMEOUT=120m TEST="$(or $(TEST),./subsystem/...)"
$(MAKE) _test TEST_SCENARIO=subsystem TIMEOUT=120m

enable-kube-api-for-subsystem: $(BUILD_FOLDER)
$(MAKE) deploy-service-requirements AUTH_TYPE=local ENABLE_KUBE_API=true ALLOW_CONVERGED_FLOW=true ISO_IMAGE_TYPE=minimal-iso
Expand Down
39 changes: 20 additions & 19 deletions subsystem/ams_subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/openshift/assisted-service/models"
"github.com/openshift/assisted-service/pkg/auth"
"github.com/openshift/assisted-service/pkg/ocm"
"github.com/openshift/assisted-service/subsystem/utils_test"
"k8s.io/apimachinery/pkg/util/wait"
)

Expand Down Expand Up @@ -43,10 +44,10 @@ var _ = Describe("test AMS subscriptions", func() {

It("happy flow", func() {

clusterID, err := registerCluster(ctx, userBMClient, "test-cluster", pullSecret)
clusterID, err := utils_test.TestContext.RegisterCluster(ctx, userBMClient, "test-cluster", pullSecret)
Expect(err).ToNot(HaveOccurred())
log.Infof("Register cluster %s", clusterID)
cc := getCommonCluster(ctx, clusterID)
cc := utils_test.TestContext.GetCommonCluster(ctx, clusterID)
Expect(cc.AmsSubscriptionID).To(Equal(FakeSubscriptionID))
})

Expand All @@ -59,7 +60,7 @@ var _ = Describe("test AMS subscriptions", func() {
})

By("register cluster", func() {
_, err := registerCluster(ctx, userBMClient, "test-cluster", pullSecret)
_, err := utils_test.TestContext.RegisterCluster(ctx, userBMClient, "test-cluster", pullSecret)
Expect(err).To(HaveOccurred())
})

Expand All @@ -69,7 +70,7 @@ var _ = Describe("test AMS subscriptions", func() {
})

By("register cluster", func() {
_, err := registerCluster(ctx, userBMClient, "test-cluster", pullSecret)
_, err := utils_test.TestContext.RegisterCluster(ctx, userBMClient, "test-cluster", pullSecret)
Expect(err).To(HaveOccurred())
})
})
Expand All @@ -84,7 +85,7 @@ var _ = Describe("test AMS subscriptions", func() {
var err error

By("create subscription (in 'reserved' status)", func() {
clusterID, err = registerCluster(ctx, userBMClient, "test-cluster", pullSecret)
clusterID, err = utils_test.TestContext.RegisterCluster(ctx, userBMClient, "test-cluster", pullSecret)
Expect(err).ToNot(HaveOccurred())
log.Infof("Register cluster %s", clusterID)
})
Expand All @@ -110,7 +111,7 @@ var _ = Describe("test AMS subscriptions", func() {
var err error

By("create subscription", func() {
clusterID, err = registerCluster(ctx, userBMClient, "test-cluster", pullSecret)
clusterID, err = utils_test.TestContext.RegisterCluster(ctx, userBMClient, "test-cluster", pullSecret)
Expect(err).ToNot(HaveOccurred())
log.Infof("Register cluster %s", clusterID)
})
Expand Down Expand Up @@ -143,7 +144,7 @@ var _ = Describe("test AMS subscriptions", func() {
var err error

By("create subscription", func() {
clusterID, err = registerCluster(ctx, userBMClient, "test-cluster", pullSecret)
clusterID, err = utils_test.TestContext.RegisterCluster(ctx, userBMClient, "test-cluster", pullSecret)
Expect(err).ToNot(HaveOccurred())
log.Infof("Register cluster %s", clusterID)
})
Expand Down Expand Up @@ -176,7 +177,7 @@ var _ = Describe("test AMS subscriptions", func() {
var err error

By("create subscription", func() {
clusterID, err = registerCluster(ctx, userBMClient, "test-cluster", pullSecret)
clusterID, err = utils_test.TestContext.RegisterCluster(ctx, userBMClient, "test-cluster", pullSecret)
Expect(err).ToNot(HaveOccurred())
log.Infof("Register cluster %s", clusterID)
})
Expand Down Expand Up @@ -211,7 +212,7 @@ var _ = Describe("test AMS subscriptions", func() {
var err error

By("create subscription", func() {
clusterID, err = registerCluster(ctx, userBMClient, "test-cluster", pullSecret)
clusterID, err = utils_test.TestContext.RegisterCluster(ctx, userBMClient, "test-cluster", pullSecret)
Expect(err).ToNot(HaveOccurred())
log.Infof("Register cluster %s", clusterID)
})
Expand All @@ -235,7 +236,7 @@ var _ = Describe("test AMS subscriptions", func() {
var err error

By("create subscription", func() {
clusterID, err = registerCluster(ctx, userBMClient, "test-cluster", pullSecret)
clusterID, err = utils_test.TestContext.RegisterCluster(ctx, userBMClient, "test-cluster", pullSecret)
Expect(err).ToNot(HaveOccurred())
log.Infof("Register cluster %s", clusterID)
})
Expand Down Expand Up @@ -263,7 +264,7 @@ var _ = Describe("test AMS subscriptions", func() {
waitForConsoleUrlUpdateInAMS := func(clusterID strfmt.UUID) {

waitFunc := func(ctx context.Context) (bool, error) {
c := getCommonCluster(ctx, clusterID)
c := utils_test.TestContext.GetCommonCluster(ctx, clusterID)
return c.IsAmsSubscriptionConsoleUrlSet, nil
}
err := wait.PollUntilContextTimeout(ctx, pollDefaultInterval, pollDefaultTimeout, false, waitFunc)
Expand All @@ -276,7 +277,7 @@ var _ = Describe("test AMS subscriptions", func() {
var err error

By("create subscription", func() {
clusterID, err = registerCluster(ctx, userBMClient, "test-cluster", pullSecret)
clusterID, err = utils_test.TestContext.RegisterCluster(ctx, userBMClient, "test-cluster", pullSecret)
Expect(err).ToNot(HaveOccurred())
log.Infof("Register cluster %s", clusterID)
})
Expand All @@ -288,17 +289,17 @@ var _ = Describe("test AMS subscriptions", func() {
})

By("update subscription with console url", func() {
c := getCluster(clusterID)
c := utils_test.TestContext.GetCluster(clusterID)
for _, host := range c.Hosts {
updateProgress(*host.ID, host.InfraEnvID, models.HostStageDone)
utils_test.TestContext.UpdateProgress(*host.ID, host.InfraEnvID, models.HostStageDone)
}
waitForClusterState(ctx, clusterID, models.ClusterStatusFinalizing, defaultWaitForClusterStateTimeout, clusterFinalizingStateInfo)
waitForClusterState(ctx, clusterID, models.ClusterStatusFinalizing, utils_test.DefaultWaitForClusterStateTimeout, clusterFinalizingStateInfo)
completeInstallation(agentBMClient, clusterID)
waitForConsoleUrlUpdateInAMS(clusterID)
})

By("update subscription with status 'Active'", func() {
waitForClusterState(ctx, clusterID, models.ClusterStatusInstalled, defaultWaitForClusterStateTimeout, clusterInstallingStateInfo)
waitForClusterState(ctx, clusterID, models.ClusterStatusInstalled, utils_test.DefaultWaitForClusterStateTimeout, clusterInstallingStateInfo)
})
})

Expand All @@ -310,7 +311,7 @@ var _ = Describe("test AMS subscriptions", func() {
var err error

By("create subscription", func() {
clusterID, err = registerCluster(ctx, userBMClient, "test-cluster", pullSecret)
clusterID, err = utils_test.TestContext.RegisterCluster(ctx, userBMClient, "test-cluster", pullSecret)
Expect(err).ToNot(HaveOccurred())
log.Infof("Register cluster %s", clusterID)
})
Expand All @@ -327,8 +328,8 @@ var _ = Describe("test AMS subscriptions", func() {
Expect(err).NotTo(HaveOccurred())
c := reply.GetPayload()
Expect(*c.Status).Should(Equal(models.ClusterStatusPreparingForInstallation))
generateEssentialPrepareForInstallationSteps(ctx, c.Hosts...)
waitForLastInstallationCompletionStatus(clusterID, models.LastInstallationPreparationStatusFailed)
utils_test.TestContext.GenerateEssentialPrepareForInstallationSteps(ctx, c.Hosts...)
utils_test.TestContext.WaitForLastInstallationCompletionStatus(clusterID, models.LastInstallationPreparationStatusFailed)
})
})
})
Expand Down
17 changes: 9 additions & 8 deletions subsystem/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/models"
"github.com/openshift/assisted-service/pkg/auth"
"github.com/openshift/assisted-service/subsystem/utils_test"
)

const psTemplate = "{\"auths\":{\"cloud.openshift.com\":{\"auth\":\"%s\",\"email\":\"[email protected]\"}}}"
Expand Down Expand Up @@ -113,11 +114,11 @@ var _ = Describe("test authorization", func() {
Skip("auth is disabled")
}

userClusterID, err = registerCluster(ctx, userBMClient, "user-cluster", fmt.Sprintf(psTemplate, FakePS))
userClusterID, err = utils_test.TestContext.RegisterCluster(ctx, userBMClient, "user-cluster", fmt.Sprintf(psTemplate, FakePS))
Expect(err).ShouldNot(HaveOccurred())
userClusterID2, err = registerCluster(ctx, user2BMClient, "user2-cluster", fmt.Sprintf(psTemplate, FakePS2))
userClusterID2, err = utils_test.TestContext.RegisterCluster(ctx, user2BMClient, "user2-cluster", fmt.Sprintf(psTemplate, FakePS2))
Expect(err).ShouldNot(HaveOccurred())
userClusterID3, err = registerCluster(ctx, editclusterUserBMClient, "user3-cluster", fmt.Sprintf(psTemplate, FakePS3))
userClusterID3, err = utils_test.TestContext.RegisterCluster(ctx, editclusterUserBMClient, "user3-cluster", fmt.Sprintf(psTemplate, FakePS3))
Expect(err).ShouldNot(HaveOccurred())
})

Expand Down Expand Up @@ -171,7 +172,7 @@ var _ = Describe("test authorization", func() {

It("can update day2 cluster", func() {
// Install day1 cluster
clusterId, err := registerCluster(ctx, userBMClient, "test-cluster", pullSecret)
clusterId, err := utils_test.TestContext.RegisterCluster(ctx, userBMClient, "test-cluster", pullSecret)
Expect(err).ToNot(HaveOccurred())
infraEnvID := registerInfraEnv(&clusterId, models.ImageTypeMinimalIso).ID
registerHostsAndSetRoles(clusterId, *infraEnvID, minHosts, "test-cluster", "example.com")
Expand Down Expand Up @@ -234,7 +235,7 @@ var _ = Describe("test authorization", func() {
Name: swag.String("test-infra-env-2"),
OpenshiftVersion: openshiftVersion,
PullSecret: swag.String(fmt.Sprintf(psTemplate, FakePS2)),
SSHAuthorizedKey: swag.String(sshPublicKey),
SSHAuthorizedKey: swag.String(utils_test.SshPublicKey),
ImageType: models.ImageTypeMinimalIso,
ClusterID: &userClusterID2,
},
Expand Down Expand Up @@ -293,7 +294,7 @@ var _ = Describe("test authorization", func() {
Name: swag.String("test-infra-env-agent-2"),
OpenshiftVersion: openshiftVersion,
PullSecret: swag.String(fmt.Sprintf(psTemplate, FakePS2)),
SSHAuthorizedKey: swag.String(sshPublicKey),
SSHAuthorizedKey: swag.String(utils_test.SshPublicKey),
ImageType: models.ImageTypeMinimalIso,
ClusterID: &userClusterID2,
},
Expand Down Expand Up @@ -457,7 +458,7 @@ var _ = Describe("Make sure that sensitive files are accessible only by owners o

BeforeEach(func() {
ctx = context.Background()
cID, err := registerCluster(ctx, userBMClient, "test-cluster", pullSecret)
cID, err := utils_test.TestContext.RegisterCluster(ctx, userBMClient, "test-cluster", pullSecret)
Expect(err).ToNot(HaveOccurred())
Expect(err).ToNot(HaveOccurred())
clusterID = cID
Expand Down Expand Up @@ -527,7 +528,7 @@ var _ = Describe("Cluster credentials should be accessed only by cluster owner",

BeforeEach(func() {
ctx = context.Background()
cID, err := registerCluster(ctx, userBMClient, "test-cluster", pullSecret)
cID, err := utils_test.TestContext.RegisterCluster(ctx, userBMClient, "test-cluster", pullSecret)
Expect(err).ToNot(HaveOccurred())
clusterID = cID
infraEnvID = registerInfraEnv(&clusterID, models.ImageTypeMinimalIso).ID
Expand Down
Loading

0 comments on commit 8930f91

Please sign in to comment.