You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ra...@apache.org on 2020/10/19 15:49:40 UTC

[trafficcontrol] branch master updated: Only run Last-Server-In-Cache Group validation when Cache Group has changed (#5166)

This is an automated email from the ASF dual-hosted git repository.

rawlin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 7c7d453  Only run Last-Server-In-Cache Group validation when Cache Group has changed (#5166)
7c7d453 is described below

commit 7c7d4538c9c9e4ca013e7cbb1ecd6c6c851ea5fa
Author: Zach Hoffman <zr...@apache.org>
AuthorDate: Mon Oct 19 09:49:24 2020 -0600

    Only run Last-Server-In-Cache Group validation when Cache Group has changed (#5166)
    
    * Reference to CacheGroup name: EdgeCg -> MidCg
    
    * Only fail validation for a server being the last in its Topology-based
    CacheGroup if its CacheGroup has changed
---
 traffic_ops/testing/api/v3/servers_test.go       |  8 +++++++-
 traffic_ops/testing/api/v3/tc-fixtures.json      | 14 +++++++-------
 traffic_ops/traffic_ops_golang/server/servers.go |  8 +++++---
 3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/traffic_ops/testing/api/v3/servers_test.go b/traffic_ops/testing/api/v3/servers_test.go
index ffbea29..9aa01b7 100644
--- a/traffic_ops/testing/api/v3/servers_test.go
+++ b/traffic_ops/testing/api/v3/servers_test.go
@@ -82,10 +82,16 @@ func LastServerInTopologyCacheGroup(t *testing.T) {
 	if len(cgs) != expectedLength {
 		t.Fatalf("expected %d cachegroup with hostname %s, received %d cachegroups", expectedLength, moveToCacheGroup, len(cgs))
 	}
+
+	_, _, err = TOSession.UpdateServerByID(*server.ID, server)
+	if err != nil {
+		t.Fatalf("error updating server with hostname %s without moving it to a different cachegroup: %s", *server.HostName, err.Error())
+	}
+
 	*server.CachegroupID = *cgs[0].ID
 	_, _, err = TOSession.UpdateServerByID(*server.ID, server)
 	if err == nil {
-		t.Fatalf("expected an error moving server with id %d to a different cachegroup, received no error", *server.ID)
+		t.Fatalf("expected an error moving server with id %s to a different cachegroup, received no error", *server.HostName)
 	}
 	if reqInf.StatusCode < http.StatusBadRequest || reqInf.StatusCode >= http.StatusInternalServerError {
 		t.Fatalf("expected a 400-level error moving server with id %d to a different cachegroup, got status code %d: %s", *server.ID, reqInf.StatusCode, err.Error())
diff --git a/traffic_ops/testing/api/v3/tc-fixtures.json b/traffic_ops/testing/api/v3/tc-fixtures.json
index ecaea8d..e52c462 100644
--- a/traffic_ops/testing/api/v3/tc-fixtures.json
+++ b/traffic_ops/testing/api/v3/tc-fixtures.json
@@ -3599,7 +3599,7 @@
             "cachegroup": "topology-mid-cg-01",
             "cdnName": "cdn2",
             "domainName": "kabletown.net",
-            "hostName": "midInTopologyEdgeCg01",
+            "hostName": "midInTopologyMidCg01",
             "httpsPort": 443,
             "interfaces": [
                 {
@@ -3633,7 +3633,7 @@
             "cachegroup": "topology-mid-cg-02",
             "cdnName": "cdn2",
             "domainName": "kabletown.net",
-            "hostName": "midInTopologyEdgeCg02",
+            "hostName": "midInTopologyMidCg02",
             "httpsPort": 443,
             "interfaces": [
                 {
@@ -3667,7 +3667,7 @@
             "cachegroup": "topology-mid-cg-03",
             "cdnName": "cdn2",
             "domainName": "kabletown.net",
-            "hostName": "midInTopologyEdgeCg03",
+            "hostName": "midInTopologyMidCg03",
             "httpsPort": 443,
             "interfaces": [
                 {
@@ -3701,7 +3701,7 @@
             "cachegroup": "topology-mid-cg-04",
             "cdnName": "cdn2",
             "domainName": "kabletown.net",
-            "hostName": "midInTopologyEdgeCg04",
+            "hostName": "midInTopologyMidCg04",
             "httpsPort": 443,
             "interfaces": [
                 {
@@ -3735,7 +3735,7 @@
             "cachegroup": "topology-mid-cg-05",
             "cdnName": "cdn2",
             "domainName": "kabletown.net",
-            "hostName": "midInTopologyEdgeCg05",
+            "hostName": "midInTopologyMidCg05",
             "httpsPort": 443,
             "interfaces": [
                 {
@@ -3769,7 +3769,7 @@
             "cachegroup": "topology-mid-cg-06",
             "cdnName": "cdn2",
             "domainName": "kabletown.net",
-            "hostName": "midInTopologyEdgeCg06",
+            "hostName": "midInTopologyMidCg06",
             "httpsPort": 443,
             "interfaces": [
                 {
@@ -3803,7 +3803,7 @@
             "cachegroup": "topology-mid-cg-07",
             "cdnName": "cdn2",
             "domainName": "kabletown.net",
-            "hostName": "midInTopologyEdgeCg07",
+            "hostName": "midInTopologyMidCg07",
             "httpsPort": 443,
             "interfaces": [
                 {
diff --git a/traffic_ops/traffic_ops_golang/server/servers.go b/traffic_ops/traffic_ops_golang/server/servers.go
index 8e5df19..4edb5d6 100644
--- a/traffic_ops/traffic_ops_golang/server/servers.go
+++ b/traffic_ops/traffic_ops_golang/server/servers.go
@@ -1226,9 +1226,11 @@ func Update(w http.ResponseWriter, r *http.Request) {
 
 		cacheGroupIds := []int{*origSer[0].CachegroupID}
 		serverIds := []int{*origSer[0].ID}
-		if err := topology.CheckForEmptyCacheGroups(inf.Tx, cacheGroupIds, true, serverIds); err != nil {
-			api.HandleErr(w, r, tx, http.StatusBadRequest, errors.New("server is the last one in its cachegroup, which is used by a topology, so it cannot be moved to another cachegroup: "+err.Error()), nil)
-			return
+		if *origSer[0].CachegroupID != *newServer.CachegroupID {
+			if err = topology.CheckForEmptyCacheGroups(inf.Tx, cacheGroupIds, true, serverIds); err != nil {
+				api.HandleErr(w, r, tx, http.StatusBadRequest, errors.New("server is the last one in its cachegroup, which is used by a topology, so it cannot be moved to another cachegroup: "+err.Error()), nil)
+				return
+			}
 		}
 
 		server, err = newServer.ToServerV2()