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

Cannot update or delete Cache Groups with null latitude and longitude #6442

Merged
merged 1 commit into from
Jan 3, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions traffic_ops/testing/api/v4/cachegroups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions traffic_ops/testing/api/v4/tc-fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@
"name": "cdn1-only",
"shortName": "cdn1-only",
"typeName": "EDGE_LOC"
},
{
"name": "nullLatLongCG",
"shortName": "null-ll",
"typeName": "EDGE_LOC"
}
],
"cdns": [
Expand Down
13 changes: 13 additions & 0 deletions traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
Expand Down Expand Up @@ -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{}
}
Expand Down