Skip to content
This repository was archived by the owner on Mar 22, 2018. It is now read-only.

Commit 15a2dac

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request #59039 from jianglingxia/jlx-01301854
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Add UT test to openstack and two para in configFromEnv **What this PR does / why we need it**: configFromEnv fun miss some para that the type define and add ut to TestToAuthOptions fun **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: /assign @dims **Release note**: ```release-note NONE ```
2 parents 7b7891a + 226f543 commit 15a2dac

2 files changed

Lines changed: 36 additions & 12 deletions

File tree

pkg/cloudprovider/providers/openstack/openstack.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ func configFromEnv() (cfg Config, ok bool) {
188188
cfg.Global.Username = os.Getenv("OS_USERNAME")
189189
cfg.Global.Password = os.Getenv("OS_PASSWORD")
190190
cfg.Global.Region = os.Getenv("OS_REGION_NAME")
191+
cfg.Global.UserId = os.Getenv("OS_USER_ID")
192+
cfg.Global.TrustId = os.Getenv("OS_TRUST_ID")
191193

192194
cfg.Global.TenantId = os.Getenv("OS_TENANT_ID")
193195
if cfg.Global.TenantId == "" {
@@ -211,7 +213,7 @@ func configFromEnv() (cfg Config, ok bool) {
211213
cfg.Global.Username != "" &&
212214
cfg.Global.Password != "" &&
213215
(cfg.Global.TenantId != "" || cfg.Global.TenantName != "" ||
214-
cfg.Global.DomainId != "" || cfg.Global.DomainName != "")
216+
cfg.Global.DomainId != "" || cfg.Global.DomainName != "" || cfg.Global.Region != "" || cfg.Global.UserId != "" || cfg.Global.TrustId != "")
215217

216218
cfg.Metadata.SearchOrder = fmt.Sprintf("%s,%s", configDriveID, metadataID)
217219
cfg.BlockStorage.BSVersion = "auto"
@@ -671,7 +673,7 @@ func (os *OpenStack) Routes() (cloudprovider.Routes, bool) {
671673
}
672674

673675
if !netExts["extraroute"] {
674-
glog.V(3).Infof("Neutron extraroute extension not found, required for Routes support")
676+
glog.V(3).Info("Neutron extraroute extension not found, required for Routes support")
675677
return nil, false
676678
}
677679

@@ -704,39 +706,39 @@ func (os *OpenStack) volumeService(forceVersion string) (volumeService, error) {
704706
if err != nil {
705707
return nil, err
706708
}
707-
glog.V(3).Infof("Using Blockstorage API V1")
709+
glog.V(3).Info("Using Blockstorage API V1")
708710
return &VolumesV1{sClient, os.bsOpts}, nil
709711
case "v2":
710712
sClient, err := os.NewBlockStorageV2()
711713
if err != nil {
712714
return nil, err
713715
}
714-
glog.V(3).Infof("Using Blockstorage API V2")
716+
glog.V(3).Info("Using Blockstorage API V2")
715717
return &VolumesV2{sClient, os.bsOpts}, nil
716718
case "v3":
717719
sClient, err := os.NewBlockStorageV3()
718720
if err != nil {
719721
return nil, err
720722
}
721-
glog.V(3).Infof("Using Blockstorage API V3")
723+
glog.V(3).Info("Using Blockstorage API V3")
722724
return &VolumesV3{sClient, os.bsOpts}, nil
723725
case "auto":
724726
// Currently kubernetes support Cinder v1 / Cinder v2 / Cinder v3.
725727
// Choose Cinder v3 firstly, if kubernetes can't initialize cinder v3 client, try to initialize cinder v2 client.
726728
// If kubernetes can't initialize cinder v2 client, try to initialize cinder v1 client.
727729
// Return appropriate message when kubernetes can't initialize them.
728730
if sClient, err := os.NewBlockStorageV3(); err == nil {
729-
glog.V(3).Infof("Using Blockstorage API V3")
731+
glog.V(3).Info("Using Blockstorage API V3")
730732
return &VolumesV3{sClient, os.bsOpts}, nil
731733
}
732734

733735
if sClient, err := os.NewBlockStorageV2(); err == nil {
734-
glog.V(3).Infof("Using Blockstorage API V2")
736+
glog.V(3).Info("Using Blockstorage API V2")
735737
return &VolumesV2{sClient, os.bsOpts}, nil
736738
}
737739

738740
if sClient, err := os.NewBlockStorageV1(); err == nil {
739-
glog.V(3).Infof("Using Blockstorage API V1")
741+
glog.V(3).Info("Using Blockstorage API V1")
740742
return &VolumesV1{sClient, os.bsOpts}, nil
741743
}
742744

pkg/cloudprovider/providers/openstack/openstack_test.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ func TestReadConfig(t *testing.T) {
162162
func TestToAuthOptions(t *testing.T) {
163163
cfg := Config{}
164164
cfg.Global.Username = "user"
165-
// etc.
165+
cfg.Global.Password = "pass"
166+
cfg.Global.DomainId = "2a73b8f597c04551a0fdc8e95544be8a"
167+
cfg.Global.DomainName = "local"
168+
cfg.Global.AuthUrl = "http://auth.url"
169+
cfg.Global.UserId = "user"
166170

167171
ao := cfg.toAuthOptions()
168172

@@ -172,6 +176,24 @@ func TestToAuthOptions(t *testing.T) {
172176
if ao.Username != cfg.Global.Username {
173177
t.Errorf("Username %s != %s", ao.Username, cfg.Global.Username)
174178
}
179+
if ao.Password != cfg.Global.Password {
180+
t.Errorf("Password %s != %s", ao.Password, cfg.Global.Password)
181+
}
182+
if ao.DomainID != cfg.Global.DomainId {
183+
t.Errorf("DomainID %s != %s", ao.DomainID, cfg.Global.DomainId)
184+
}
185+
if ao.IdentityEndpoint != cfg.Global.AuthUrl {
186+
t.Errorf("IdentityEndpoint %s != %s", ao.IdentityEndpoint, cfg.Global.AuthUrl)
187+
}
188+
if ao.UserID != cfg.Global.UserId {
189+
t.Errorf("UserID %s != %s", ao.UserID, cfg.Global.UserId)
190+
}
191+
if ao.DomainName != cfg.Global.DomainName {
192+
t.Errorf("DomainName %s != %s", ao.DomainName, cfg.Global.DomainName)
193+
}
194+
if ao.TenantID != cfg.Global.TenantId {
195+
t.Errorf("TenantID %s != %s", ao.TenantID, cfg.Global.TenantId)
196+
}
175197
}
176198

177199
func TestCheckOpenStackOpts(t *testing.T) {
@@ -442,7 +464,7 @@ func TestNodeAddresses(t *testing.T) {
442464
func TestNewOpenStack(t *testing.T) {
443465
cfg, ok := configFromEnv()
444466
if !ok {
445-
t.Skipf("No config found in environment")
467+
t.Skip("No config found in environment")
446468
}
447469

448470
_, err := newOpenStack(cfg)
@@ -454,7 +476,7 @@ func TestNewOpenStack(t *testing.T) {
454476
func TestLoadBalancer(t *testing.T) {
455477
cfg, ok := configFromEnv()
456478
if !ok {
457-
t.Skipf("No config found in environment")
479+
t.Skip("No config found in environment")
458480
}
459481

460482
versions := []string{"v2", ""}
@@ -518,7 +540,7 @@ var diskPathRegexp = regexp.MustCompile("/dev/disk/(?:by-id|by-path)/")
518540
func TestVolumes(t *testing.T) {
519541
cfg, ok := configFromEnv()
520542
if !ok {
521-
t.Skipf("No config found in environment")
543+
t.Skip("No config found in environment")
522544
}
523545

524546
os, err := newOpenStack(cfg)

0 commit comments

Comments
 (0)