Skip to content

Commit

Permalink
MGMT-19258: Split KubeAPI and non KubeAPI subsystem tests
Browse files Browse the repository at this point in the history
We are dealing with an issue where some tests have not been executed since they were created, this is because they lack the [kube-api] tag in the test name.
It's not ideal to need to specify this tag in each test as it is easily missed and the consequences of this are not good.

I have decided to solve this by placing the KubeAPI and non KubeAPI tests into different packages

`github.com/openshift/assisted-service/subsystem` for non KubeAPI tests
'github.com/openshift/assisted-service/subsystem/kubeapi' for KubeAPI tests

Now every test within the respective package will be executed, irrespective of how it has been tagged.

In order to get to this point, some refactoring of common code between tests was required. The common code has been placed in a package called `utils_test`
Some of the existing utils code has been moved here also in order to support sharing of this code.

This is quite a big change in terms of volume, but the principles are simple. functions, consts and vars between tests have been moved to the new namespace and exported.
References to `package private` members that have been moved to the new namespace have been updated to point to the correct place.

Some tests were found to be failing after they started to run, not unexpected.
As these are non trivial to fix and somewhat unrelated to this fix for how we run the tests, these tests have been disabled by marking them with `PDescribe` for now.
These tests will be dealt with in MGMT-19596
  • Loading branch information
paul-maidment committed Dec 31, 2024
1 parent 6cdfd59 commit 49cde10
Show file tree
Hide file tree
Showing 30 changed files with 3,259 additions and 2,941 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 TEST="$(TEST)"

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
4 changes: 2 additions & 2 deletions hack/add_wiremock_stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/kelseyhightower/envconfig"
"github.com/openshift/assisted-service/models"
"github.com/openshift/assisted-service/pkg/auth"
"github.com/openshift/assisted-service/subsystem"
"github.com/openshift/assisted-service/subsystem/utils_test"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -39,7 +39,7 @@ func main() {
log.Fatal("Fail to parse release sources, ", err)
}

wiremock := &subsystem.WireMock{
wiremock := &utils_test.WireMock{
OCMHost: Options.OCMBaseURL,
ReleaseSources: releaseSources,
}
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.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.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.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.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.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.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.UserBMClient, pullSecret,
"file-does-not-exist",
"../docs/hive-integration/crds/agentClusterInstall.yaml",
"../docs/hive-integration/crds/clusterImageSet.yaml", "")
Expand Down
Loading

0 comments on commit 49cde10

Please sign in to comment.