Skip to content

Commit 754e63e

Browse files
committed
OCM-9780 | test: automated id:65900,id:76481 install with use-local-credentials will work
1 parent d63bd9c commit 754e63e

File tree

7 files changed

+163
-20
lines changed

7 files changed

+163
-20
lines changed

tests/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ For the test cases, we need `$ make install` to make the rosa command line insta
128128
> * **PROVISION_SHARD** if it is set, a provision shard will be specified for cluster provision
129129
> * **NAME_PREFIX** if it is set, all resources will be generated based with the name prefix to identify the created cluster created by you. Otherwise _`rosacli-ci`_ will be used. For local testing, we should have it be set with your alias
130130
> * **CLUSTER_TIMEOUT** if it is set, the process will exit if cluster cannot be ready in setting time. Unit is minute
131+
> * **USE_LOCAL_CREDENTIALS** if it is set to `true`, then when the cluster is provisioned the `--use-local-credentials` flag will be enabled
131132
132133
### Running a local CI test simulation
133134

tests/ci/config/config.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,17 @@ type GlobalENVVariables struct {
6161
OCM_LOGIN_ENV string `env:"OCM_LOGIN_ENV" default:""`
6262
}
6363
type ClusterENVVariables struct {
64-
ComputeMachineType string `env:"COMPUTE_MACHINE_TYPE" default:""`
65-
BYOVPC string `env:"BYOVPC" default:""`
66-
Private string `env:"PRIVATE" default:""`
67-
Autoscale string `env:"AUTOSCALE" default:""`
68-
ProxyEnabled string `env:"PROXY_ENABLED" default:""`
69-
FipsEnabled string `env:"FIPS_ENABLED" default:""`
70-
VolumeSize string `env:"VOLUME_SIZE" default:""`
71-
Replicas string `env:"REPLICAS" default:""`
72-
MultiAZ string `env:"MULTI_AZ" default:""`
73-
AllowRegistries string `env:"ALLOW_REGISTRIES" default:""`
64+
ComputeMachineType string `env:"COMPUTE_MACHINE_TYPE" default:""`
65+
BYOVPC string `env:"BYOVPC" default:""`
66+
Private string `env:"PRIVATE" default:""`
67+
Autoscale string `env:"AUTOSCALE" default:""`
68+
ProxyEnabled string `env:"PROXY_ENABLED" default:""`
69+
FipsEnabled string `env:"FIPS_ENABLED" default:""`
70+
VolumeSize string `env:"VOLUME_SIZE" default:""`
71+
Replicas string `env:"REPLICAS" default:""`
72+
MultiAZ string `env:"MULTI_AZ" default:""`
73+
AllowRegistries string `env:"ALLOW_REGISTRIES" default:""`
74+
UseLocalCredentials bool `env:"USE_LOCAL_CREDENTIALS" default:"false"`
7475
}
7576

7677
func init() {
@@ -120,6 +121,7 @@ func init() {
120121
panic(fmt.Errorf("env variable CLUSTER_TIMEOUT must be set to an integer"))
121122
}
122123
waitSetupClusterReady, _ := strconv.ParseBool(helper.ReadENVWithDefaultValue("WAIT_SETUP_CLUSTER_READY", "true"))
124+
useLocalCredentials, _ := strconv.ParseBool(helper.ReadENVWithDefaultValue("USE_LOCAL_CREDENTIALS", "false"))
123125
Test.GlobalENV = &GlobalENVVariables{
124126
ChannelGroup: os.Getenv("CHANNEL_GROUP"),
125127
Version: os.Getenv("VERSION"),
@@ -134,16 +136,17 @@ func init() {
134136
WaitSetupClusterReady: waitSetupClusterReady,
135137
}
136138
Test.ClusterENV = &ClusterENVVariables{
137-
ComputeMachineType: os.Getenv("COMPUTE_MACHINE_TYPE"),
138-
BYOVPC: os.Getenv("BYOVPC"),
139-
Private: os.Getenv("PRIVATE"),
140-
Autoscale: os.Getenv("AUTOSCALE"),
141-
ProxyEnabled: os.Getenv("PROXY_ENABLED"),
142-
FipsEnabled: os.Getenv("FIPS_ENABLED"),
143-
VolumeSize: os.Getenv("VOLUME_SIZE"),
144-
Replicas: os.Getenv("REPLICAS"),
145-
MultiAZ: os.Getenv("MULTI_AZ"),
146-
AllowRegistries: os.Getenv("ALLOW_REGISTRIES"),
139+
ComputeMachineType: os.Getenv("COMPUTE_MACHINE_TYPE"),
140+
BYOVPC: os.Getenv("BYOVPC"),
141+
Private: os.Getenv("PRIVATE"),
142+
Autoscale: os.Getenv("AUTOSCALE"),
143+
ProxyEnabled: os.Getenv("PROXY_ENABLED"),
144+
FipsEnabled: os.Getenv("FIPS_ENABLED"),
145+
VolumeSize: os.Getenv("VOLUME_SIZE"),
146+
Replicas: os.Getenv("REPLICAS"),
147+
MultiAZ: os.Getenv("MULTI_AZ"),
148+
AllowRegistries: os.Getenv("ALLOW_REGISTRIES"),
149+
UseLocalCredentials: useLocalCredentials,
147150
}
148151

149152
}

tests/e2e/test_rosacli_cluster.go

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,18 @@ var _ = Describe("Classic cluster creation validation",
15541554
Expect(err).NotTo(BeNil())
15551555
Expect(errorOutput.String()).To(ContainSubstring("etcd encryption cannot be disabled on clusters with FIPS mode"))
15561556
})
1557+
It("validate use-local-credentials won't work with sts - [id:76481]",
1558+
labels.Medium, labels.Runtime.Day1Negative,
1559+
func() {
1560+
clusterName := "ocp-76481"
1561+
1562+
By("Create cluster with use-local-credentials flag but with sts")
1563+
errorOutput, err := clusterService.CreateDryRun(
1564+
clusterName, "--use-local-credentials", "--sts", "--mode=auto", "-y",
1565+
)
1566+
Expect(err).NotTo(BeNil())
1567+
Expect(errorOutput.String()).To(ContainSubstring("Local credentials are not supported for STS clusters"))
1568+
})
15571569
})
15581570

15591571
var _ = Describe("Create cluster with invalid options will",
@@ -4226,3 +4238,112 @@ var _ = Describe("Sts cluster with BYO oidc flow creation supplemental testing",
42264238
Expect(err).To(BeNil(), "It met error or timeout when waiting cluster to installing status")
42274239
})
42284240
})
4241+
var _ = Describe("Non-STS cluster with local credentials",
4242+
labels.Feature.Cluster,
4243+
func() {
4244+
defer GinkgoRecover()
4245+
4246+
var (
4247+
rosaClient *rosacli.Client
4248+
clusterService rosacli.ClusterService
4249+
4250+
customProfile *handler.Profile
4251+
clusterID string
4252+
ocmResourceService rosacli.OCMResourceService
4253+
testingClusterName string
4254+
clusterHandler handler.ClusterHandler
4255+
)
4256+
BeforeEach(func() {
4257+
var err error
4258+
4259+
By("Init the client")
4260+
rosaClient = rosacli.NewClient()
4261+
clusterService = rosaClient.Cluster
4262+
ocmResourceService = rosaClient.OCMResource
4263+
4264+
By("Get AWS account id")
4265+
rosaClient.Runner.JsonFormat()
4266+
rosaClient.Runner.UnsetFormat()
4267+
4268+
By("Prepare custom profile")
4269+
customProfile = &handler.Profile{
4270+
ClusterConfig: &handler.ClusterConfig{
4271+
HCP: false,
4272+
MultiAZ: false,
4273+
STS: false,
4274+
OIDCConfig: "",
4275+
NetworkingSet: false,
4276+
BYOVPC: false,
4277+
UseLocalCredentials: true,
4278+
},
4279+
AccountRoleConfig: &handler.AccountRoleConfig{
4280+
Path: "/aa/bb/",
4281+
PermissionBoundary: "",
4282+
},
4283+
Version: "latest",
4284+
ChannelGroup: "candidate",
4285+
Region: "us-east-2",
4286+
}
4287+
customProfile.NamePrefix = constants.DefaultNamePrefix
4288+
clusterHandler, err = handler.NewTempClusterHandler(rosaClient, customProfile)
4289+
Expect(err).ToNot(HaveOccurred())
4290+
})
4291+
4292+
AfterEach(func() {
4293+
defer func() {
4294+
By("Clean resources")
4295+
clusterHandler.Destroy()
4296+
}()
4297+
4298+
By("Delete cluster")
4299+
rosaClient.Runner.UnsetArgs()
4300+
_, err := clusterService.DeleteCluster(clusterID, "-y")
4301+
Expect(err).To(BeNil())
4302+
4303+
rosaClient.Runner.UnsetArgs()
4304+
err = clusterService.WaitClusterDeleted(clusterID, 3, 30)
4305+
Expect(err).To(BeNil())
4306+
4307+
By("Delete operator-roles")
4308+
_, err = ocmResourceService.DeleteOperatorRoles(
4309+
"-c", clusterID,
4310+
"--mode", "auto",
4311+
"-y",
4312+
)
4313+
Expect(err).To(BeNil())
4314+
})
4315+
4316+
It("Creating cluster with non-sts use-local-credentials should succeed - [id:65900]",
4317+
labels.Medium, labels.Runtime.Day1Supplemental,
4318+
func() {
4319+
By("Create classic cluster in auto mode")
4320+
testingClusterName = helper.GenerateRandomName("c65900", 2)
4321+
testOperatorRolePrefix := helper.GenerateRandomName("opp65900", 2)
4322+
flags, err := clusterHandler.GenerateClusterCreateFlags()
4323+
Expect(err).ToNot(HaveOccurred())
4324+
4325+
command := "rosa create cluster --cluster-name " + testingClusterName + " " + strings.Join(flags, " ")
4326+
rosalCommand := config.GenerateCommand(command)
4327+
rosalCommand.ReplaceFlagValue(map[string]string{
4328+
"--operator-roles-prefix": testOperatorRolePrefix,
4329+
})
4330+
4331+
rosalCommand.AddFlags("--mode", "auto")
4332+
_, err = rosaClient.Runner.RunCMD(strings.Split(rosalCommand.GetFullCommand(), " "))
4333+
Expect(err).To(BeNil())
4334+
4335+
By("Wait for the cluster to be installing")
4336+
clusterListout, err := clusterService.List()
4337+
Expect(err).To(BeNil())
4338+
clusterList, err := clusterService.ReflectClusterList(clusterListout)
4339+
Expect(err).To(BeNil())
4340+
clusterID = clusterList.ClusterByName(testingClusterName).ID
4341+
err = clusterService.WaitClusterStatus(clusterID, "installing", 3, 20)
4342+
Expect(err).To(BeNil())
4343+
4344+
By("Check the properties of the cluster")
4345+
jsonData, err := clusterService.GetJSONClusterDescription(clusterID)
4346+
Expect(err).ToNot(HaveOccurred())
4347+
Expect(jsonData.DigBool("properties", "use_local_credentials")).To(BeTrue())
4348+
})
4349+
})

tests/e2e/test_rosacli_cluster_post.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,14 @@ var _ = Describe("Healthy check",
587587
Expect(jsonData.DigBool("multi_arch_enabled")).To(BeFalse())
588588
}
589589
})
590+
It("with use-local-credentials will work - [id:65900]", labels.Runtime.Day1Post, labels.High,
591+
func() {
592+
By("Check that the 'use_local_credentials' property matches the profile")
593+
jsonData, err := clusterService.GetJSONClusterDescription(clusterID)
594+
Expect(err).ToNot(HaveOccurred())
595+
Expect(jsonData.DigBool("properties", "use_local_credentials")).
596+
To(Equal(profile.ClusterConfig.UseLocalCredentials))
597+
})
590598

591599
It("with policy path will work - [id:75525]", labels.Runtime.Day1Post, labels.High,
592600
func() {

tests/utils/handler/cluster_handler.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ func (ch *clusterHandler) GenerateClusterCreateFlags() ([]string, error) {
217217
"--domain-prefix", helper.TrimNameByLength(clusterName, ocm.MaxClusterDomainPrefixLength),
218218
)
219219
}
220+
if ch.profile.ClusterConfig.UseLocalCredentials {
221+
flags = append(flags,
222+
"--use-local-credentials",
223+
)
224+
}
220225
if ch.profile.ClusterConfig.STS {
221226
var accRoles *rosacli.AccountRolesUnit
222227
var oidcConfigID string

tests/utils/handler/interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type ClusterConfig struct {
6262
BlockedRegistries bool `yaml:"blocked_registries" json:"blocked_registries,omitempty"`
6363
ManualCreationMode bool `yaml:"manual_creation_mode" json:"manual_creation_mode,omitempty"`
6464
FedRAMP bool `yaml:"fedramp" json:"fedramp,omitempty"`
65+
UseLocalCredentials bool `yaml:"use_local_credentials,omitempty" json:"use_local_credentials,omitempty"`
6566
}
6667

6768
// Resources will record the resources prepared

tests/utils/handler/profile.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ func LoadProfileYamlFileByENV() *Profile {
135135
config.Test.ClusterENV.ComputeMachineType)
136136
profile.ClusterConfig.InstanceType = config.Test.ClusterENV.ComputeMachineType
137137
}
138+
if config.Test.ClusterENV.UseLocalCredentials {
139+
log.Logger.Info("Got global env setting for USE_LOCAL_CREDENTIALS, overwritten the profile setting to true")
140+
profile.ClusterConfig.UseLocalCredentials = true
141+
}
138142
if config.Test.ClusterENV.BYOVPC != "" {
139143
log.Logger.Infof("Got global env settings for BYOVPC, overwritten the profile setting with value %s",
140144
config.Test.ClusterENV.BYOVPC)

0 commit comments

Comments
 (0)