Skip to content

Commit

Permalink
Merge pull request #621 from ystia/bugfix/GH-550-check-loc-type
Browse files Browse the repository at this point in the history
Check for location type mismatch
  • Loading branch information
adidanes committed Mar 30, 2020
2 parents 90bd63e + be1c4fc commit f702398
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
### BUG FIXES

* CLI yorc locations list doesn't return HostsPool information ([GH-615](https://github.com/ystia/yorc/issues/615))
* Check for location type mismatch ([GH-550](https://github.com/ystia/yorc/issues/550))

## 4.0.0-M10 (March 10, 2020)

Expand Down
11 changes: 9 additions & 2 deletions locations/location_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ func (mgr *locationManager) GetLocationProperties(locationName, locationType str
if locationType == adapter.AdaptedLocationType {
return mgr.hpAdapter.GetLocationConfiguration(locationName)
}

// get location configuration from the kv store
var props config.DynamicMap
kvp, _, err := mgr.cc.KV().Get(path.Join(consulutil.LocationsPrefix, locationName), nil)
if err != nil {
Expand All @@ -186,10 +188,15 @@ func (mgr *locationManager) GetLocationProperties(locationName, locationType str

var lConfig LocationConfiguration
err = json.Unmarshal(kvp.Value, &lConfig)
props = lConfig.Properties
if err != nil {
return props, errors.Wrapf(err, "failed to unmarshal configuration for location %s", locationName)
}
// got configuration for the requested location
props = lConfig.Properties
// check if no mismatch between the type defined in the configuration and the given location type
if locationType != lConfig.Type {
return props, errors.Errorf("The location %q has %s type defined and not the requested %s type", locationName, lConfig.Type, locationType)
}

return props, err
}
Expand All @@ -198,7 +205,7 @@ func (mgr *locationManager) GetLocationProperties(locationName, locationType str
// on which the node template in argument is or will be created.
// The corresponding location name should be provided in the node template metadata.
// If no location name is provided in the node template metadata, the configuration
// of the first location of the expected type in returned
// of the first location having the requested location type is returned
func (mgr *locationManager) GetLocationPropertiesForNode(ctx context.Context, deploymentID, nodeName, locationType string) (config.DynamicMap, error) {

// Get the location name in node template metadata
Expand Down

0 comments on commit f702398

Please sign in to comment.