From 2a6737061d2b86dd6718154efae923282c32fe4f Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Thu, 21 Feb 2019 18:16:17 +0800 Subject: [PATCH 1/2] fix: find empty endpoints due to invalid duplicate service --- pkg/mcclient/token2.go | 2 +- pkg/mcclient/token3.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/mcclient/token2.go b/pkg/mcclient/token2.go index f64d045014..81645b4396 100644 --- a/pkg/mcclient/token2.go +++ b/pkg/mcclient/token2.go @@ -191,7 +191,7 @@ func (catalog KeystoneServiceCatalogV2) getRegions() []string { func (catalog KeystoneServiceCatalogV2) getServiceEndpoint(service, region, zone string) (KeystoneEndpointV2, error) { var selected KeystoneEndpointV2 for i := 0; i < len(catalog); i++ { - if service == catalog[i].Type { + if service == catalog[i].Type && len(catalog[i].Endpoints) > 0 { if len(region) == 0 { if len(catalog[i].Endpoints) >= 1 { selected = catalog[i].Endpoints[0] diff --git a/pkg/mcclient/token3.go b/pkg/mcclient/token3.go index 38e962b119..3f943397e2 100644 --- a/pkg/mcclient/token3.go +++ b/pkg/mcclient/token3.go @@ -270,7 +270,7 @@ func (catalog KeystoneServiceCatalogV3) GetServiceURLs(service, region, zone, en endpointType = "internalURL" } for i := 0; i < len(catalog); i++ { - if service == catalog[i].Type { + if service == catalog[i].Type && len(catalog[i].Endpoints) > 0 { var selected []string regeps := make(map[string][]string) regionzone := "" From c624341b19f20918a3c0ba7ec2c4aad2b18bb506 Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Thu, 21 Feb 2019 18:48:50 +0800 Subject: [PATCH 2/2] minor fix --- pkg/mcclient/token2.go | 19 ++++++++++++------- pkg/mcclient/token3.go | 5 ++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/pkg/mcclient/token2.go b/pkg/mcclient/token2.go index 81645b4396..d5188353ad 100644 --- a/pkg/mcclient/token2.go +++ b/pkg/mcclient/token2.go @@ -190,14 +190,15 @@ func (catalog KeystoneServiceCatalogV2) getRegions() []string { func (catalog KeystoneServiceCatalogV2) getServiceEndpoint(service, region, zone string) (KeystoneEndpointV2, error) { var selected KeystoneEndpointV2 + var findService bool for i := 0; i < len(catalog); i++ { - if service == catalog[i].Type && len(catalog[i].Endpoints) > 0 { + if service == catalog[i].Type { + findService = true + if len(catalog[i].Endpoints) == 0 { + continue + } if len(region) == 0 { - if len(catalog[i].Endpoints) >= 1 { - selected = catalog[i].Endpoints[0] - } else { - return selected, fmt.Errorf("No default region") - } + selected = catalog[i].Endpoints[0] } else { regionEps := make([]KeystoneEndpointV2, 0) zoneEps := make([]KeystoneEndpointV2, 0) @@ -222,7 +223,11 @@ func (catalog KeystoneServiceCatalogV2) getServiceEndpoint(service, region, zone return selected, nil } } - return selected, fmt.Errorf("No such service %s", service) + if findService { + return selected, fmt.Errorf("No default region") + } else { + return selected, fmt.Errorf("No such service %s", service) + } } func (catalog KeystoneServiceCatalogV2) GetServiceURL(service, region, zone, endpointType string) (string, error) { diff --git a/pkg/mcclient/token3.go b/pkg/mcclient/token3.go index 3f943397e2..db5ef59b50 100644 --- a/pkg/mcclient/token3.go +++ b/pkg/mcclient/token3.go @@ -270,7 +270,10 @@ func (catalog KeystoneServiceCatalogV3) GetServiceURLs(service, region, zone, en endpointType = "internalURL" } for i := 0; i < len(catalog); i++ { - if service == catalog[i].Type && len(catalog[i].Endpoints) > 0 { + if service == catalog[i].Type { + if len(catalog[i].Endpoints) == 0 { + continue + } var selected []string regeps := make(map[string][]string) regionzone := ""