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 1dce038
Show file tree
Hide file tree
Showing 27 changed files with 4,168 additions and 2,804 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
15 changes: 8 additions & 7 deletions subsystem/agent_based_installer_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ import (
"github.com/openshift/assisted-service/cmd/agentbasedinstaller"
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/internal/network"
"github.com/openshift/assisted-service/subsystem/utils_test"
)

// Note: userBMClient is used because subsystems defaults to use "rhsso" as AUTH_TYPE.
// Note: utils_test.TestContext.UserBMClient is used because subsystems defaults to use "rhsso" as AUTH_TYPE.
// The ephermeral installer environment will use the "none" AUTH_TYPE at the start, and
// a pre-generated infra-env-id will be used when creating the infra-env.
// A new authentication scheme suited to the agent-based installer will be implemented
// in the future and userBMClient should be replaced at that time.
// in the future and utils_test.TestContext.UserBMClient should be replaced at that time.
var _ = Describe("RegisterClusterAndInfraEnv", func() {
ctx := context.Background()

It("good flow", func() {
modelCluster, registerClusterErr := agentbasedinstaller.RegisterCluster(ctx, log, userBMClient, pullSecret,
modelCluster, registerClusterErr := agentbasedinstaller.RegisterCluster(ctx, log, utils_test.TestContext.UserBMClient, pullSecret,
"../docs/hive-integration/crds/clusterDeployment.yaml",
"../docs/hive-integration/crds/agentClusterInstall.yaml",
"../docs/hive-integration/crds/clusterImageSet.yaml", "")
Expand All @@ -30,7 +31,7 @@ var _ = Describe("RegisterClusterAndInfraEnv", func() {
Expect(modelCluster.CPUArchitecture).To(Equal("x86_64"))
Expect(modelCluster.Name).To(Equal("test-cluster"))

modelInfraEnv, registerInfraEnvErr := agentbasedinstaller.RegisterInfraEnv(ctx, log, userBMClient, pullSecret,
modelInfraEnv, registerInfraEnvErr := agentbasedinstaller.RegisterInfraEnv(ctx, log, utils_test.TestContext.UserBMClient, pullSecret,
modelCluster, "../docs/hive-integration/crds/infraEnv.yaml",
"../docs/hive-integration/crds/nmstate.yaml", "full-iso", "")

Expand All @@ -41,7 +42,7 @@ var _ = Describe("RegisterClusterAndInfraEnv", func() {
})

It("InstallConfig override good flow", func() {
modelCluster, registerClusterErr := agentbasedinstaller.RegisterCluster(ctx, log, userBMClient, pullSecret,
modelCluster, registerClusterErr := agentbasedinstaller.RegisterCluster(ctx, log, utils_test.TestContext.UserBMClient, pullSecret,
"../docs/hive-integration/crds/clusterDeployment.yaml",
"../docs/hive-integration/crds/agentClusterInstall-with-installconfig-overrides.yaml",
"../docs/hive-integration/crds/clusterImageSet.yaml", "")
Expand All @@ -53,7 +54,7 @@ var _ = Describe("RegisterClusterAndInfraEnv", func() {
Expect(modelCluster.InstallConfigOverrides).To(Equal(`{"fips": true}`))
Expect(modelCluster.Name).To(Equal("test-cluster"))

modelInfraEnv, registerInfraEnvErr := agentbasedinstaller.RegisterInfraEnv(ctx, log, userBMClient, pullSecret,
modelInfraEnv, registerInfraEnvErr := agentbasedinstaller.RegisterInfraEnv(ctx, log, utils_test.TestContext.UserBMClient, pullSecret,
modelCluster, "../docs/hive-integration/crds/infraEnv.yaml",
"../docs/hive-integration/crds/nmstate.yaml", "full-iso", "")

Expand All @@ -64,7 +65,7 @@ var _ = Describe("RegisterClusterAndInfraEnv", func() {
})

It("missing one of the ZTP manifests", func() {
modelCluster, registerClusterErr := agentbasedinstaller.RegisterCluster(ctx, log, userBMClient, pullSecret,
modelCluster, registerClusterErr := agentbasedinstaller.RegisterCluster(ctx, log, utils_test.TestContext.UserBMClient, pullSecret,
"file-does-not-exist",
"../docs/hive-integration/crds/agentClusterInstall.yaml",
"../docs/hive-integration/crds/clusterImageSet.yaml", "")
Expand Down
59 changes: 30 additions & 29 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, utils_test.TestContext.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, utils_test.TestContext.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, utils_test.TestContext.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, utils_test.TestContext.UserBMClient, "test-cluster", pullSecret)
Expect(err).ToNot(HaveOccurred())
log.Infof("Register cluster %s", clusterID)
})
Expand All @@ -98,7 +99,7 @@ var _ = Describe("test AMS subscriptions", func() {
})

By("delete 'reserved' subscription", func() {
_, err = userBMClient.Installer.V2DeregisterCluster(ctx, &installer.V2DeregisterClusterParams{ClusterID: clusterID})
_, err = utils_test.TestContext.UserBMClient.Installer.V2DeregisterCluster(ctx, &installer.V2DeregisterClusterParams{ClusterID: clusterID})
Expect(err).To(HaveOccurred())
})
})
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, utils_test.TestContext.UserBMClient, "test-cluster", pullSecret)
Expect(err).ToNot(HaveOccurred())
log.Infof("Register cluster %s", clusterID)
})
Expand All @@ -131,7 +132,7 @@ var _ = Describe("test AMS subscriptions", func() {
By("delete subscription", func() {
// don't delete 'active' subscription
// we can't really check that because it is done in an external dependency (AMS) so we just check there are no errors in the flow
_, err = userBMClient.Installer.V2DeregisterCluster(ctx, &installer.V2DeregisterClusterParams{ClusterID: clusterID})
_, err = utils_test.TestContext.UserBMClient.Installer.V2DeregisterCluster(ctx, &installer.V2DeregisterClusterParams{ClusterID: clusterID})
Expect(err).ToNot(HaveOccurred())
})
})
Expand All @@ -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, utils_test.TestContext.UserBMClient, "test-cluster", pullSecret)
Expect(err).ToNot(HaveOccurred())
log.Infof("Register cluster %s", clusterID)
})
Expand All @@ -154,7 +155,7 @@ var _ = Describe("test AMS subscriptions", func() {
})

By("delete subscription", func() {
_, err = userBMClient.Installer.V2DeregisterCluster(ctx, &installer.V2DeregisterClusterParams{ClusterID: clusterID})
_, err = utils_test.TestContext.UserBMClient.Installer.V2DeregisterCluster(ctx, &installer.V2DeregisterClusterParams{ClusterID: clusterID})
Expect(err).To(HaveOccurred())
})

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

By("delete subscription", func() {
_, err = userBMClient.Installer.V2DeregisterCluster(ctx, &installer.V2DeregisterClusterParams{ClusterID: clusterID})
_, err = utils_test.TestContext.UserBMClient.Installer.V2DeregisterCluster(ctx, &installer.V2DeregisterClusterParams{ClusterID: clusterID})
Expect(err).To(HaveOccurred())
})
})
Expand All @@ -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, utils_test.TestContext.UserBMClient, "test-cluster", pullSecret)
Expect(err).ToNot(HaveOccurred())
log.Infof("Register cluster %s", clusterID)
})
Expand All @@ -187,7 +188,7 @@ var _ = Describe("test AMS subscriptions", func() {
})

By("delete subscription", func() {
_, err = userBMClient.Installer.V2DeregisterCluster(ctx, &installer.V2DeregisterClusterParams{ClusterID: clusterID})
_, err = utils_test.TestContext.UserBMClient.Installer.V2DeregisterCluster(ctx, &installer.V2DeregisterClusterParams{ClusterID: clusterID})
Expect(err).To(HaveOccurred())
})

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

By("delete subscription", func() {
_, err = userBMClient.Installer.V2DeregisterCluster(ctx, &installer.V2DeregisterClusterParams{ClusterID: clusterID})
_, err = utils_test.TestContext.UserBMClient.Installer.V2DeregisterCluster(ctx, &installer.V2DeregisterClusterParams{ClusterID: clusterID})
Expect(err).To(HaveOccurred())
})
})
Expand All @@ -211,14 +212,14 @@ 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, utils_test.TestContext.UserBMClient, "test-cluster", pullSecret)
Expect(err).ToNot(HaveOccurred())
log.Infof("Register cluster %s", clusterID)
})

By("update subscription's display name", func() {
newClusterName := "ams-cluster-new-name"
_, err = userBMClient.Installer.V2UpdateCluster(ctx, &installer.V2UpdateClusterParams{
_, err = utils_test.TestContext.UserBMClient.Installer.V2UpdateCluster(ctx, &installer.V2UpdateClusterParams{
ClusterID: clusterID,
ClusterUpdateParams: &models.V2ClusterUpdateParams{
Name: &newClusterName,
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, utils_test.TestContext.UserBMClient, "test-cluster", pullSecret)
Expect(err).ToNot(HaveOccurred())
log.Infof("Register cluster %s", clusterID)
})
Expand All @@ -247,7 +248,7 @@ var _ = Describe("test AMS subscriptions", func() {

By("update subscription's display name", func() {
newClusterName := "ams-cluster-new-name"
_, err = userBMClient.Installer.V2UpdateCluster(ctx, &installer.V2UpdateClusterParams{
_, err = utils_test.TestContext.UserBMClient.Installer.V2UpdateCluster(ctx, &installer.V2UpdateClusterParams{
ClusterID: clusterID,
ClusterUpdateParams: &models.V2ClusterUpdateParams{
Name: &newClusterName,
Expand All @@ -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, utils_test.TestContext.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)
completeInstallation(agentBMClient, clusterID)
waitForClusterState(ctx, clusterID, models.ClusterStatusFinalizing, utils_test.DefaultWaitForClusterStateTimeout, clusterFinalizingStateInfo)
completeInstallation(utils_test.TestContext.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, utils_test.TestContext.UserBMClient, "test-cluster", pullSecret)
Expect(err).ToNot(HaveOccurred())
log.Infof("Register cluster %s", clusterID)
})
Expand All @@ -323,12 +324,12 @@ var _ = Describe("test AMS subscriptions", func() {
By("update subscription with openshfit (external) cluster ID", func() {
infraEnvID := registerInfraEnv(&clusterID, models.ImageTypeMinimalIso).ID
registerHostsAndSetRoles(clusterID, *infraEnvID, minHosts, "test-cluster", "example.com")
reply, err = userBMClient.Installer.V2InstallCluster(context.Background(), &installer.V2InstallClusterParams{ClusterID: clusterID})
reply, err = utils_test.TestContext.UserBMClient.Installer.V2InstallCluster(context.Background(), &installer.V2InstallClusterParams{ClusterID: clusterID})
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
Loading

0 comments on commit 1dce038

Please sign in to comment.