mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Add UT test to openstack and two para in configFromEnv
This commit is contained in:
parent
47d7d1d5dd
commit
a97d166903
@ -188,6 +188,8 @@ func configFromEnv() (cfg Config, ok bool) {
|
||||
cfg.Global.Username = os.Getenv("OS_USERNAME")
|
||||
cfg.Global.Password = os.Getenv("OS_PASSWORD")
|
||||
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")
|
||||
if cfg.Global.TenantId == "" {
|
||||
@ -211,7 +213,7 @@ func configFromEnv() (cfg Config, ok bool) {
|
||||
cfg.Global.Username != "" &&
|
||||
cfg.Global.Password != "" &&
|
||||
(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.BlockStorage.BSVersion = "auto"
|
||||
@ -671,7 +673,7 @@ func (os *OpenStack) Routes() (cloudprovider.Routes, bool) {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@ -704,21 +706,21 @@ func (os *OpenStack) volumeService(forceVersion string) (volumeService, error) {
|
||||
if err != nil {
|
||||
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
|
||||
case "v2":
|
||||
sClient, err := os.NewBlockStorageV2()
|
||||
if err != nil {
|
||||
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
|
||||
case "v3":
|
||||
sClient, err := os.NewBlockStorageV3()
|
||||
if err != nil {
|
||||
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
|
||||
case "auto":
|
||||
// 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.
|
||||
// Return appropriate message when kubernetes can't initialize them.
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -162,7 +162,11 @@ func TestReadConfig(t *testing.T) {
|
||||
func TestToAuthOptions(t *testing.T) {
|
||||
cfg := Config{}
|
||||
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()
|
||||
|
||||
@ -172,6 +176,24 @@ func TestToAuthOptions(t *testing.T) {
|
||||
if 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) {
|
||||
@ -400,7 +422,7 @@ func TestNodeAddresses(t *testing.T) {
|
||||
func TestNewOpenStack(t *testing.T) {
|
||||
cfg, ok := configFromEnv()
|
||||
if !ok {
|
||||
t.Skipf("No config found in environment")
|
||||
t.Skip("No config found in environment")
|
||||
}
|
||||
|
||||
_, err := newOpenStack(cfg)
|
||||
@ -412,7 +434,7 @@ func TestNewOpenStack(t *testing.T) {
|
||||
func TestLoadBalancer(t *testing.T) {
|
||||
cfg, ok := configFromEnv()
|
||||
if !ok {
|
||||
t.Skipf("No config found in environment")
|
||||
t.Skip("No config found in environment")
|
||||
}
|
||||
|
||||
versions := []string{"v2", ""}
|
||||
@ -476,7 +498,7 @@ var diskPathRegexp = regexp.MustCompile("/dev/disk/(?:by-id|by-path)/")
|
||||
func TestVolumes(t *testing.T) {
|
||||
cfg, ok := configFromEnv()
|
||||
if !ok {
|
||||
t.Skipf("No config found in environment")
|
||||
t.Skip("No config found in environment")
|
||||
}
|
||||
|
||||
os, err := newOpenStack(cfg)
|
||||
|
Loading…
Reference in New Issue
Block a user