Skip to content

Commit

Permalink
Introduce testing profiles
Browse files Browse the repository at this point in the history
Update the profiles

Update the external yaml

Finish the profile parser

Finish the env setup for testing

Create a data folder to contains yaml files

Fix comment

Apply the struct with latest profile change
  • Loading branch information
xueli181114 committed Mar 21, 2024
1 parent 1ba8c13 commit 2ad0ae1
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ docs/
/rosa-linux-arm64
/rosa-linux-arm64.sha256
/*policy.json
/tests/output
.envrc
.env
cover.out
37 changes: 37 additions & 0 deletions tests/ci/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package config

import (
"os"
"path"
"strings"

"github.com/openshift/rosa/tests/utils/common"
. "github.com/openshift/rosa/tests/utils/log"
)

var Test *TestConfig

// TestConfig contains platforms info for the rosacli testing
type TestConfig struct {
// Env is the OpenShift Cluster Management environment used to provision clusters.
ENV string `env:"OCM_LOGIN_ENV" default:""`
TestProfile string `env:"TEST_PROFILE" default:""`
OutputDir string `env:"OUTPUT_DIR" default:""`
YAMLProfilesDir string `env:"TEST_PROFILE_DIR" default:""`
RootDir string `env:"WORKSPACE" default:""`
}

func init() {
Test = new(TestConfig)
currentDir, _ := os.Getwd()
project := "rosa"

Test.TestProfile = common.ReadENVWithDefaultValue("TEST_PROFILE", "")
Test.RootDir = common.ReadENVWithDefaultValue("WORKSPACE", strings.SplitAfter(currentDir, project)[0])
Test.YAMLProfilesDir = common.ReadENVWithDefaultValue("TEST_PROFILE_DIR", path.Join(Test.RootDir, "tests", "ci", "data", "profiles"))
Test.OutputDir = common.ReadENVWithDefaultValue("SHARED_DIR", path.Join(Test.RootDir, "tests", "output", Test.TestProfile))
err := os.MkdirAll(Test.OutputDir, 0777)
if err != nil {
Logger.Errorf("Meet error %s when create output dirs", err.Error())
}
}
2 changes: 1 addition & 1 deletion tests/ci/data/profiles/external.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ profiles:
additional_sg_number: 3
account-role:
path: ""
permission_boundary: ""
permission_boundary: ""
2 changes: 0 additions & 2 deletions tests/ci/data/profiles/rosa-hcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ profiles:
oidc_config: "managed"
auditlog_forward: true
admin_enabled: false
managed_policies: true
disable_uwm: true
autoscaler_enabled: true
account-role:
Expand Down Expand Up @@ -139,7 +138,6 @@ profiles:
shared_vpc: false
auditlog_forward: true
admin_enabled: false
managed_policies: true
disable_uwm: true
network_type: other
external_auth_config: true
Expand Down
17 changes: 15 additions & 2 deletions tests/e2e/dummy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,28 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

. "github.com/openshift/rosa/tests/utils/log"
TC "github.com/openshift/rosa/tests/ci/config"
"github.com/openshift/rosa/tests/utils/log"
PH "github.com/openshift/rosa/tests/utils/profilehandler"
)

var _ = Describe("ROSA CLI Test", func() {
Describe("Dummy test", func() {
It("Dummy", func() {
str := "dummy string"
Expect(str).ToNot(BeEmpty())
Logger.Infof("This is a dummy test to check everything is fine by executing jobs. Please remove me once other tests are added")
log.Logger.Infof("This is a dummy test to check everything is fine by executing jobs. Please remove me once other tests are added")
})
})
Describe("Profile test", func() {
It("ProfileParserTest", func() {
profile := PH.LoadProfileYamlFileByENV()
log.Logger.Infof("Got configured profile: %v", *profile)
log.Logger.Infof("Got configured cluster profile: %v", *profile.ClusterConfig)
log.Logger.Infof("Got configured account role profile: %v", *profile.AccountRoleConfig)
})
It("TestENVSetup", func() {
log.Logger.Infof("Got dir of out: %v", TC.Test.OutputDir)
})
})
})
10 changes: 10 additions & 0 deletions tests/utils/common/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package common

import "os"

func ReadENVWithDefaultValue(envName string, fallback string) string {
if os.Getenv(envName) != "" {
return os.Getenv(envName)
}
return fallback
}
48 changes: 48 additions & 0 deletions tests/utils/profilehandler/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package profilehandler

type Profile struct {
Name string `yaml:"as,omitempty"`
Version string `yaml:"version,omitempty"`
ChannelGroup string `yaml:"channel_group,omitempty"`
Region string `yaml:"region,omitempty"`
ClusterConfig *ClusterConfig `yaml:"cluster,omitempty"`
AccountRoleConfig *AccountRoleConfig `yaml:"account-role,omitempty"`
}
type AccountRoleConfig struct {
Path string `yaml:"path,omitempty"`
PermissionBoundary string `yaml:"permission_boundary,omitempty"`
}
type ClusterConfig struct {
InstanceType string `yaml:"instance_type,omitempty" json:"instance_type,omitempty"`
Zones string `yaml:"zones,omitempty" json:"zones,omitempty"`
TagEnabled bool `yaml:"tag_enabled,omitempty" json:"tag_enabled,omitempty"`
LabelEnabled bool `yaml:"label_enabled,omitempty" json:"label_enabled,omitempty"`
EtcdEncryption bool `yaml:"etcd_encryption,omitempty" json:"etcd_encryption,omitempty"`
FIPS bool `yaml:"fips,omitempty" json:"fips,omitempty"`
STS bool `yaml:"sts,omitempty" json:"sts,omitempty"`
Autoscale bool `yaml:"autoscale,omitempty" json:"autoscale,omitempty"`
MultiAZ bool `yaml:"multi_az,omitempty" json:"multi_az,omitempty"`
BYOVPC bool `yaml:"byo_vpc,omitempty" json:"byo_vpc,omitempty"`
PrivateLink bool `yaml:"private_link,omitempty" json:"private_link,omitempty"`
Private bool `yaml:"private,omitempty" json:"private,omitempty"`
KMSKey bool `yaml:"kms_key,omitempty" json:"kms_key,omitempty"`
ETCDKMS bool `yaml:"etcd_kms,omitempty" json:"etcd_kms,omitempty"`
NetWorkingSet bool `yaml:"networking,omitempty" json:"networking,omitempty"`
ProxyEnabled bool `yaml:"proxy_enabled,omitempty" json:"proxy_enabled,omitempty"`
HCP bool `yaml:"hcp,omitempty" json:"hypershift,omitempty"`
OIDCConfig string `yaml:"oidc_config,omitempty" json:"oidc_config,omitempty"`
ProvisionShard string `yaml:"provision_shard,omitempty" json:"provision_shard,omitempty"`
Ec2MetadataHttpTokens string `yaml:"imdsv2,omitempty" json:"imdsv2,omitempty"`
AuditLogForward bool `yaml:"auditlog_forward,omitempty" json:"auditlog_forward,omitempty"`
AdminEnabled bool `yaml:"admin_enabled,omitempty" json:"admin_enabled,omitempty"`
ExpirationTime int `yaml:"expiration_time,omitempty" json:"expiration_time,omitempty"`
VolumeSize int `yaml:"volume_size,omitempty" json:"volume_size,omitempty"`
BillingAccount string `yaml:"billing_account,omitempty" json:"billing_account,omitempty"`
AutoscalerEnabled bool `yaml:"autoscaler_enabled,omitempty" json:"autoscaler_enabled,omitempty"`
DisableUserWorKloadMonitoring bool `yaml:"disable_uwm,omitempty" json:"disable_uwm,omitempty"`
SharedVPC bool `yaml:"shared_vpc,omitempty" json:"shared_vpc,omitempty"`
DisableSCPChecks bool `yaml:"disable_scp_checks,omitempty" json:"disable_scp_checks,omitempty"`
AdditionalSGNumber int `yaml:"additional_sg_number" json:"additional_sg_number,omitempty"`
WorkerPoolReplicas int `yaml:"replicas" json:"replicas,omitempty"`
ExternalAuthConfig bool `yaml:"external_auth_config" json:"external_auth_config,omitempty"`
}
51 changes: 51 additions & 0 deletions tests/utils/profilehandler/parse_yaml.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package profilehandler

import (
"log"
"os"
"path"

"gopkg.in/yaml.v3"
)

type profiles struct {
Profiles []*Profile `yaml:"profiles,omitempty"`
}

func ParseProfiles(profilesDir string) map[string]*Profile {
files, err := os.ReadDir(profilesDir)
if err != nil {
log.Fatal(err)
}

profileMap := make(map[string]*Profile)
for _, file := range files {
yfile, err := os.ReadFile(path.Join(profilesDir, file.Name()))
if err != nil {
log.Fatal(err)
}

p := new(profiles)
err = yaml.Unmarshal(yfile, &p)
if err != nil {
log.Fatal(err)
}

for _, theProfile := range p.Profiles {
profileMap[theProfile.Name] = theProfile
}

}

return profileMap
}

func GetProfile(profileName string, profilesDir string) *Profile {
profileMap := ParseProfiles(profilesDir)

if _, exist := profileMap[profileName]; !exist {
log.Fatalf("Can not find the profile %s in %s\n", profileName, profilesDir)
}

return profileMap[profileName]
}
46 changes: 46 additions & 0 deletions tests/utils/profilehandler/profile_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package profilehandler

import (
"fmt"
"os"

"github.com/openshift/rosa/tests/ci/config"
. "github.com/openshift/rosa/tests/utils/log"
)

func GetYAMLProfilesDir() string {
return config.Test.YAMLProfilesDir
}
func LoadProfileYamlFile(profileName string) *Profile {
p := GetProfile(profileName, GetYAMLProfilesDir())
Logger.Infof("Loaded cluster profile configuration from origional profile %s : %v", profileName, *p)
Logger.Infof("Loaded cluster profile configuration from origional cluster %s : %v", profileName, *p.ClusterConfig)
Logger.Infof("Loaded cluster profile configuration from origional account-roles %s : %v", profileName, *p.AccountRoleConfig)
return p
}

func LoadProfileYamlFileByENV() *Profile {
if config.Test.TestProfile == "" {
panic(fmt.Errorf("ENV Variable TEST_PROFILE is empty, please make sure you set the env value"))
}
profile := LoadProfileYamlFile(config.Test.TestProfile)

// Supporting global env setting to overrite profile settings
if os.Getenv("CHANNEL_GROUP") != "" {
Logger.Infof("Got global env settings for CHANNEL_GROUP, overwritten the profile setting with value %s", os.Getenv("CHANNEL_GROUP"))
profile.ChannelGroup = os.Getenv("CHANNEL_GROUP")
}
if os.Getenv("VERSION") != "" {
Logger.Infof("Got global env settings for VERSION, overwritten the profile setting with value %s", os.Getenv("VERSION"))
profile.Version = os.Getenv("VERSION")
}
if os.Getenv("REGION") != "" {
Logger.Infof("Got global env settings for REGION, overwritten the profile setting with value %s", os.Getenv("REGION"))
profile.Region = os.Getenv("REGION")
}
if os.Getenv("PROVISION_SHARD") != "" {
Logger.Infof("Got global env settings for PROVISION_SHARD, overwritten the profile setting with value %s", os.Getenv("PROVISION_SHARD"))
profile.ClusterConfig.ProvisionShard = os.Getenv("PROVISION_SHARD")
}
return profile
}

0 comments on commit 2ad0ae1

Please sign in to comment.