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
```
This commit is contained in:
Kubernetes Submit Queue 2018-02-03 21:55:40 -08:00 committed by GitHub
commit d5ee83bda0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 12 deletions

View File

@ -188,6 +188,8 @@ func configFromEnv() (cfg Config, ok bool) {
cfg.Global.Username = os.Getenv("OS_USERNAME") cfg.Global.Username = os.Getenv("OS_USERNAME")
cfg.Global.Password = os.Getenv("OS_PASSWORD") cfg.Global.Password = os.Getenv("OS_PASSWORD")
cfg.Global.Region = os.Getenv("OS_REGION_NAME") cfg.Global.Region = os.Getenv("OS_REGION_NAME")
cfg.Global.UserId = os.Getenv("OS_USER_ID")
cfg.Global.TrustId = os.Getenv("OS_TRUST_ID")
cfg.Global.TenantId = os.Getenv("OS_TENANT_ID") cfg.Global.TenantId = os.Getenv("OS_TENANT_ID")
if cfg.Global.TenantId == "" { if cfg.Global.TenantId == "" {
@ -211,7 +213,7 @@ func configFromEnv() (cfg Config, ok bool) {
cfg.Global.Username != "" && cfg.Global.Username != "" &&
cfg.Global.Password != "" && cfg.Global.Password != "" &&
(cfg.Global.TenantId != "" || cfg.Global.TenantName != "" || (cfg.Global.TenantId != "" || cfg.Global.TenantName != "" ||
cfg.Global.DomainId != "" || cfg.Global.DomainName != "") cfg.Global.DomainId != "" || cfg.Global.DomainName != "" || cfg.Global.Region != "" || cfg.Global.UserId != "" || cfg.Global.TrustId != "")
cfg.Metadata.SearchOrder = fmt.Sprintf("%s,%s", configDriveID, metadataID) cfg.Metadata.SearchOrder = fmt.Sprintf("%s,%s", configDriveID, metadataID)
cfg.BlockStorage.BSVersion = "auto" cfg.BlockStorage.BSVersion = "auto"
@ -671,7 +673,7 @@ func (os *OpenStack) Routes() (cloudprovider.Routes, bool) {
} }
if !netExts["extraroute"] { if !netExts["extraroute"] {
glog.V(3).Infof("Neutron extraroute extension not found, required for Routes support") glog.V(3).Info("Neutron extraroute extension not found, required for Routes support")
return nil, false return nil, false
} }
@ -704,21 +706,21 @@ func (os *OpenStack) volumeService(forceVersion string) (volumeService, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
glog.V(3).Infof("Using Blockstorage API V1") glog.V(3).Info("Using Blockstorage API V1")
return &VolumesV1{sClient, os.bsOpts}, nil return &VolumesV1{sClient, os.bsOpts}, nil
case "v2": case "v2":
sClient, err := os.NewBlockStorageV2() sClient, err := os.NewBlockStorageV2()
if err != nil { if err != nil {
return nil, err return nil, err
} }
glog.V(3).Infof("Using Blockstorage API V2") glog.V(3).Info("Using Blockstorage API V2")
return &VolumesV2{sClient, os.bsOpts}, nil return &VolumesV2{sClient, os.bsOpts}, nil
case "v3": case "v3":
sClient, err := os.NewBlockStorageV3() sClient, err := os.NewBlockStorageV3()
if err != nil { if err != nil {
return nil, err return nil, err
} }
glog.V(3).Infof("Using Blockstorage API V3") glog.V(3).Info("Using Blockstorage API V3")
return &VolumesV3{sClient, os.bsOpts}, nil return &VolumesV3{sClient, os.bsOpts}, nil
case "auto": case "auto":
// Currently kubernetes support Cinder v1 / Cinder v2 / Cinder v3. // Currently kubernetes support Cinder v1 / Cinder v2 / Cinder v3.
@ -726,17 +728,17 @@ func (os *OpenStack) volumeService(forceVersion string) (volumeService, error) {
// If kubernetes can't initialize cinder v2 client, try to initialize cinder v1 client. // If kubernetes can't initialize cinder v2 client, try to initialize cinder v1 client.
// Return appropriate message when kubernetes can't initialize them. // Return appropriate message when kubernetes can't initialize them.
if sClient, err := os.NewBlockStorageV3(); err == nil { if sClient, err := os.NewBlockStorageV3(); err == nil {
glog.V(3).Infof("Using Blockstorage API V3") glog.V(3).Info("Using Blockstorage API V3")
return &VolumesV3{sClient, os.bsOpts}, nil return &VolumesV3{sClient, os.bsOpts}, nil
} }
if sClient, err := os.NewBlockStorageV2(); err == nil { if sClient, err := os.NewBlockStorageV2(); err == nil {
glog.V(3).Infof("Using Blockstorage API V2") glog.V(3).Info("Using Blockstorage API V2")
return &VolumesV2{sClient, os.bsOpts}, nil return &VolumesV2{sClient, os.bsOpts}, nil
} }
if sClient, err := os.NewBlockStorageV1(); err == nil { if sClient, err := os.NewBlockStorageV1(); err == nil {
glog.V(3).Infof("Using Blockstorage API V1") glog.V(3).Info("Using Blockstorage API V1")
return &VolumesV1{sClient, os.bsOpts}, nil return &VolumesV1{sClient, os.bsOpts}, nil
} }

View File

@ -162,7 +162,11 @@ func TestReadConfig(t *testing.T) {
func TestToAuthOptions(t *testing.T) { func TestToAuthOptions(t *testing.T) {
cfg := Config{} cfg := Config{}
cfg.Global.Username = "user" cfg.Global.Username = "user"
// etc. cfg.Global.Password = "pass"
cfg.Global.DomainId = "2a73b8f597c04551a0fdc8e95544be8a"
cfg.Global.DomainName = "local"
cfg.Global.AuthUrl = "http://auth.url"
cfg.Global.UserId = "user"
ao := cfg.toAuthOptions() ao := cfg.toAuthOptions()
@ -172,6 +176,24 @@ func TestToAuthOptions(t *testing.T) {
if ao.Username != cfg.Global.Username { if ao.Username != cfg.Global.Username {
t.Errorf("Username %s != %s", ao.Username, cfg.Global.Username) t.Errorf("Username %s != %s", ao.Username, cfg.Global.Username)
} }
if ao.Password != cfg.Global.Password {
t.Errorf("Password %s != %s", ao.Password, cfg.Global.Password)
}
if ao.DomainID != cfg.Global.DomainId {
t.Errorf("DomainID %s != %s", ao.DomainID, cfg.Global.DomainId)
}
if ao.IdentityEndpoint != cfg.Global.AuthUrl {
t.Errorf("IdentityEndpoint %s != %s", ao.IdentityEndpoint, cfg.Global.AuthUrl)
}
if ao.UserID != cfg.Global.UserId {
t.Errorf("UserID %s != %s", ao.UserID, cfg.Global.UserId)
}
if ao.DomainName != cfg.Global.DomainName {
t.Errorf("DomainName %s != %s", ao.DomainName, cfg.Global.DomainName)
}
if ao.TenantID != cfg.Global.TenantId {
t.Errorf("TenantID %s != %s", ao.TenantID, cfg.Global.TenantId)
}
} }
func TestCheckOpenStackOpts(t *testing.T) { func TestCheckOpenStackOpts(t *testing.T) {
@ -442,7 +464,7 @@ func TestNodeAddresses(t *testing.T) {
func TestNewOpenStack(t *testing.T) { func TestNewOpenStack(t *testing.T) {
cfg, ok := configFromEnv() cfg, ok := configFromEnv()
if !ok { if !ok {
t.Skipf("No config found in environment") t.Skip("No config found in environment")
} }
_, err := newOpenStack(cfg) _, err := newOpenStack(cfg)
@ -454,7 +476,7 @@ func TestNewOpenStack(t *testing.T) {
func TestLoadBalancer(t *testing.T) { func TestLoadBalancer(t *testing.T) {
cfg, ok := configFromEnv() cfg, ok := configFromEnv()
if !ok { if !ok {
t.Skipf("No config found in environment") t.Skip("No config found in environment")
} }
versions := []string{"v2", ""} versions := []string{"v2", ""}
@ -518,7 +540,7 @@ var diskPathRegexp = regexp.MustCompile("/dev/disk/(?:by-id|by-path)/")
func TestVolumes(t *testing.T) { func TestVolumes(t *testing.T) {
cfg, ok := configFromEnv() cfg, ok := configFromEnv()
if !ok { if !ok {
t.Skipf("No config found in environment") t.Skip("No config found in environment")
} }
os, err := newOpenStack(cfg) os, err := newOpenStack(cfg)