Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed phys_locations update API to remove error related to mismatching region name and ID #7762

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- [#7691](https://github.com/apache/trafficcontrol/pull/7691) *Traffic Ops* Fixed `/topologies` v5 APIs to respond with `RFC3339` timestamps.
- [#7413](https://github.com/apache/trafficcontrol/issues/7413) *Traffic Ops* Fixed `/service_category` v5 APIs to respond with `RFC3339` timestamps.
- [#7413](https://github.com/apache/trafficcontrol/issues/7706) *Traffic Ops* Fixed `/statuses` v5 APIs to respond with `RFC3339` timestamps.
- [#7743](https://github.com/apache/trafficcontrol/issues/7743) *Traffic Ops* Fixed `/server_server_capabilities` v5 APIs to respond with `RFC3339` timestamps.
- [#7762](https://github.com/apache/trafficcontrol/pull/7762) *Traffic Ops* Fixed `/phys_locations` update API to remove error related to mismatching region name and ID.
- [#7743](https://github.com/apache/trafficcontrol/issues/7743) *Traffic Ops* Fixed `/server_server_capabilities` v5 APIs to respond with `RFC3339` timestamps.
- [#7730](https://github.com/apache/trafficcontrol/pull/7730) *Traffic Monitor* Fixed the panic seen in TM when `plugin.system_stats.timestamp_ms` appears as float and not string.
- [#4393](https://github.com/apache/trafficcontrol/issues/4393) *Traffic Ops* Fixed the error code and alert structure when TO is queried for a delivery service with no ssl keys.
- [#7623](https://github.com/apache/trafficcontrol/pull/7623) *Traffic Ops* Removed TryIfModifiedSinceQuery from servicecategories.go and reused from ims.go
Expand Down
17 changes: 17 additions & 0 deletions traffic_ops/testing/api/v5/phys_locations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ func TestPhysLocations(t *testing.T) {
Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
validatePhysicalLocationUpdateCreateFields("HotAtlanta", map[string]interface{}{"City": "NewCity"})),
},
"OK when REGION ID doesn't match REGION NAME": {
EndpointID: GetPhysicalLocationID(t, "HotAtlanta"),
ClientSession: TOSession,
RequestBody: tc.PhysLocationV5{
Address: "1234 southern way",
City: "NewCity",
Name: "HotAtlanta",
Phone: "404-222-2222",
RegionID: GetRegionID(t, "region1")(),
RegionName: "notRegion1",
ShortName: "atlanta",
State: "GA",
Zip: "30301",
},
Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
validatePhysicalLocationUpdateCreateFields("HotAtlanta", map[string]interface{}{"City": "NewCity"})),
},
"PRECONDITION FAILED when updating with IMS & IUS Headers": {
EndpointID: GetPhysicalLocationID(t, "HotAtlanta"),
ClientSession: TOSession,
Expand Down
16 changes: 0 additions & 16 deletions traffic_ops/traffic_ops_golang/physlocation/phys_locations.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,22 +391,6 @@ func UpdatePhysLocation(w http.ResponseWriter, r *http.Request) {
return
}

// checks to see if the supplied region name and ID in the phys_location body correspond to each other.
if physLocation.RegionName != "" {
regionName, ok, err := dbhelpers.GetRegionNameFromID(tx, physLocation.RegionID)
if err != nil {
api.HandleErr(w, r, tx, http.StatusInternalServerError, fmt.Errorf("error fetching name from region ID: %w", err), nil)
return
} else if !ok {
api.HandleErr(w, r, tx, http.StatusNotFound, errors.New("no such region"), nil)
return
}
if regionName != physLocation.RegionName {
api.HandleErr(w, r, tx, http.StatusBadRequest, errors.New("region name and ID do not match"), nil)
return
}
}

requestedID := inf.Params["id"]

intRequestId, convErr := strconv.Atoi(requestedID)
Expand Down