Skip to content

Commit

Permalink
ibmcloud: e2e test provisioner log level
Browse files Browse the repository at this point in the history
Fixes: confidential-containers#689

Signed-off-by: Qi Feng Huo <[email protected]>
  • Loading branch information
Qi Feng Huo authored and liudalibj committed Mar 10, 2023
1 parent dc71f34 commit cf3441c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/cluster-provisioner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
pv "github.com/confidential-containers/cloud-api-adaptor/test/provisioner"
)

// export DEBUG="true"
// export LOG_LEVEL="trace|debug"
// export CLOUD_PROVIDER="ibmcloud"
// export TEST_E2E_PROVISION_FILE="/root/provision_ibmcloud.properties"
// export TEST_E2E_PODVM_IMAGE="/root/e2e-test-image-amd64-20230308.qcow2
Expand Down
14 changes: 7 additions & 7 deletions test/provisioner/provision_ibmcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func NewIBMCloudProvisioner(properties map[string]string) (CloudProvisioner, err
// IBMCloudProvisioner

func (p *IBMCloudProvisioner) CreateCluster(ctx context.Context, cfg *envconf.Config) error {
log.Info("CreateCluster()")
log.Trace("CreateCluster()")

clusterInfo := containerv2.ClusterCreateRequest{
DisablePublicServiceEndpoint: true,
Expand Down Expand Up @@ -333,7 +333,7 @@ func (p *IBMCloudProvisioner) CreateCluster(ctx context.Context, cfg *envconf.Co
for i := 0; i <= waitMinutes; i++ {
ready, err := isClusterReady(IBMCloudProps.ClusterName)
if err != nil {
log.Infof("Err %s happened when retrieve cluster, try again...\n", err)
log.Warnf("Err %s happened when retrieve cluster, try again...\n", err)
continue
}
if ready {
Expand All @@ -353,12 +353,12 @@ func (p *IBMCloudProvisioner) CreateCluster(ctx context.Context, cfg *envconf.Co
}

func (p *IBMCloudProvisioner) CreateVPC(ctx context.Context, cfg *envconf.Config) error {
log.Info("CreateVPC()")
log.Trace("CreateVPC()")
return createVpcImpl()
}

func (p *IBMCloudProvisioner) DeleteCluster(ctx context.Context, cfg *envconf.Config) error {
log.Info("DeleteCluster()")
log.Trace("DeleteCluster()")

target := containerv2.ClusterTargetHeader{}
log.Infof("Deleting Cluster %s.\n", IBMCloudProps.ClusterName)
Expand All @@ -373,7 +373,7 @@ func (p *IBMCloudProvisioner) DeleteCluster(ctx context.Context, cfg *envconf.Co
for i := 0; i <= waitMinutes; i++ {
found, err := foundCluster(IBMCloudProps.ClusterName)
if err != nil {
log.Infof("Err %s happened when retrieve cluster, try again...\n", err)
log.Warnf("Err %s happened when retrieve cluster, try again...\n", err)
continue
}
if !found {
Expand All @@ -392,12 +392,12 @@ func (p *IBMCloudProvisioner) DeleteCluster(ctx context.Context, cfg *envconf.Co
}

func (p *IBMCloudProvisioner) DeleteVPC(ctx context.Context, cfg *envconf.Config) error {
log.Info("DeleteVPC()")
log.Trace("DeleteVPC()")
return deleteVpcImpl()
}

func (p *IBMCloudProvisioner) UploadPodvm(imagePath string, ctx context.Context, cfg *envconf.Config) error {
log.Info("UploadPodvm()")
log.Trace("UploadPodvm()")

filePath, err := filepath.Abs(imagePath)
if err != nil {
Expand Down
32 changes: 29 additions & 3 deletions test/provisioner/provision_ibmcloud_initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,32 @@ type IBMCloudProperties struct {

var IBMCloudProps = &IBMCloudProperties{}

func init() {
initLogger()
}

func initLogger() {
level := os.Getenv("LOG_LEVEL")
switch level {
case "trace":
log.SetLevel(log.TraceLevel)
case "debug":
log.SetLevel(log.DebugLevel)
case "info":
log.SetLevel(log.InfoLevel)
case "warn":
log.SetLevel(log.WarnLevel)
case "error":
log.SetLevel(log.ErrorLevel)
case "fatal":
log.SetLevel(log.FatalLevel)
case "panic":
log.SetLevel(log.PanicLevel)
default:
log.SetLevel(log.InfoLevel)
}
}

func initProperties(properties map[string]string) error {
IBMCloudProps = &IBMCloudProperties{
ApiKey: properties["APIKEY"],
Expand Down Expand Up @@ -112,7 +138,7 @@ func initProperties(properties map[string]string) error {
IBMCloudProps.IsSelfManaged = true
}

log.Infof("%+v", IBMCloudProps)
log.Debugf("%+v", IBMCloudProps)

if len(IBMCloudProps.ApiKey) <= 0 {
return errors.New("APIKEY was not set.")
Expand Down Expand Up @@ -165,7 +191,7 @@ func initProperties(properties map[string]string) error {
}

func initVpcV1() error {
log.Info("initVpcV1()")
log.Trace("initVpcV1()")

if IBMCloudProps.VPC != nil {
return nil
Expand All @@ -187,7 +213,7 @@ func initVpcV1() error {
}

func initClustersAPI() error {
log.Info("initClustersAPI()")
log.Trace("initClustersAPI()")

cfg := &bx.Config{
BluemixAPIKey: IBMCloudProps.ApiKey,
Expand Down

0 comments on commit cf3441c

Please sign in to comment.