From 357d4e89224808596a8f4ac5b5c0bd9ced17169f Mon Sep 17 00:00:00 2001 From: Srijeet Chatterjee Date: Tue, 21 Dec 2021 17:05:20 -0700 Subject: [PATCH] Null lat/long should be converted to 0 --- CHANGELOG.md | 1 + .../testing/api/v4/cachegroups_test.go | 28 +++++++++++++++++++ traffic_ops/testing/api/v4/tc-fixtures.json | 5 ++++ .../cachegroup/cachegroups.go | 13 +++++++++ 4 files changed, 47 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 664b19fdcc..f999b81c72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - [#5893](https://github.com/apache/trafficcontrol/issues/5893) - A self signed certificate is created when an HTTPS delivery service is created or an HTTP delivery service is updated to HTTPS. - [#6125](https://github.com/apache/trafficcontrol/issues/6125) - Fix `/cdns/{name}/federations?id=#` to search for CDN. - [#6255](https://github.com/apache/trafficcontrol/issues/6255) - Unreadable Prod Mode CDN Notifications in Traffic Portal +- [#6378](https://github.com/apache/trafficcontrol/issues/6378) - Cannot update or delete Cache Groups with null latitude and longitude. - Fixed broken `GET /cdns/routing` Traffic Ops API - [#6259](https://github.com/apache/trafficcontrol/issues/6259) - Traffic Portal No Longer Allows Spaces in Server Object "Router Port Name" - [#6392](https://github.com/apache/trafficcontrol/issues/6392) - Traffic Ops prevents assigning ORG servers to topology-based delivery services (as well as a number of other valid operations being prohibited by "last server assigned to DS" validations which don't apply to topology-based delivery services) diff --git a/traffic_ops/testing/api/v4/cachegroups_test.go b/traffic_ops/testing/api/v4/cachegroups_test.go index b2eb675bf6..e956d3b581 100644 --- a/traffic_ops/testing/api/v4/cachegroups_test.go +++ b/traffic_ops/testing/api/v4/cachegroups_test.go @@ -32,6 +32,7 @@ import ( func TestCacheGroups(t *testing.T) { WithObjs(t, []TCObj{Types, Parameters, CacheGroups, CDNs, Profiles, Statuses, Divisions, Regions, PhysLocations, Servers, Topologies}, func() { + ReadUpdateTestCacheGroupWithNullLatLong(t) GetTestCacheGroupsIMS(t) GetTestCacheGroupsByNameIMS(t) GetTestCacheGroupsByShortNameIMS(t) @@ -62,6 +63,33 @@ func TestCacheGroups(t *testing.T) { }) } +func ReadUpdateTestCacheGroupWithNullLatLong(t *testing.T) { + opts := client.NewRequestOptions() + opts.QueryParameters.Add("name", "nullLatLongCG") + resp, _, err := TOSession.GetCacheGroups(opts) + if err != nil { + t.Fatalf("expected no error GETting cachegroups, but got %v", err) + } + if len(resp.Response) != 1 { + t.Fatalf("expected just one cachegroup, but got %d", len(resp.Response)) + } + cg := resp.Response[0] + if cg.ID == nil { + t.Fatalf("got nil ID") + } + if cg.Latitude == nil || cg.Longitude == nil { + t.Fatalf("expected lat/long to be not nil") + } + if *cg.Latitude != 0 || *cg.Longitude != 0 { + t.Errorf("expected lat/long to be 0 and 0, but got %f and %f", *cg.Latitude, *cg.Longitude) + } + cg.FallbackToClosest = util.BoolPtr(false) + _, _, err = TOSession.UpdateCacheGroup(*cg.ID, cg, client.NewRequestOptions()) + if err != nil { + t.Errorf("expected no error updating a cachegroup with null lat/long, but got %v", err) + } +} + func UpdateCachegroupWithLocks(t *testing.T) { var cdnName string servers := make([]tc.ServerV40, 0) diff --git a/traffic_ops/testing/api/v4/tc-fixtures.json b/traffic_ops/testing/api/v4/tc-fixtures.json index bc3b173e9b..4ae1fd0756 100644 --- a/traffic_ops/testing/api/v4/tc-fixtures.json +++ b/traffic_ops/testing/api/v4/tc-fixtures.json @@ -249,6 +249,11 @@ "name": "cdn1-only", "shortName": "cdn1-only", "typeName": "EDGE_LOC" + }, + { + "name": "nullLatLongCG", + "shortName": "null-ll", + "typeName": "EDGE_LOC" } ], "cdns": [ diff --git a/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go b/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go index b6c794e692..262518ad26 100644 --- a/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go +++ b/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go @@ -279,6 +279,12 @@ func (cg TOCacheGroup) Validate() error { //to be added to the struct func (cg *TOCacheGroup) Create() (error, error, int) { + if cg.Latitude == nil { + cg.Latitude = util.FloatPtr(0.0) + } + if cg.Longitude == nil { + cg.Longitude = util.FloatPtr(0.0) + } if cg.LocalizationMethods == nil { cg.LocalizationMethods = &[]tc.LocalizationMethod{} } @@ -619,6 +625,13 @@ LEFT JOIN cachegroup AS cgs ON cachegroup.secondary_parent_cachegroup_id = cgs.i //The TOCacheGroup implementation of the Updater interface func (cg *TOCacheGroup) Update(h http.Header) (error, error, int) { + if cg.Latitude == nil { + cg.Latitude = util.FloatPtr(0.0) + } + if cg.Longitude == nil { + cg.Longitude = util.FloatPtr(0.0) + } + if cg.LocalizationMethods == nil { cg.LocalizationMethods = &[]tc.LocalizationMethod{} }