srijeet0406 commented on a change in pull request #4881:
URL: https://github.com/apache/trafficcontrol/pull/4881#discussion_r458219401



##########
File path: traffic_ops/testing/api/v2/servers_test.go
##########
@@ -130,6 +136,33 @@ func UpdateTestServers(t *testing.T) {
                t.Errorf("results do not match actual: %s, expected: %s", 
respServer.Rack, updatedServerRack)
        }
 
+       //Check change in hostname with no change to xmppid
+       if originalHostname == respServer.HostName && originalXMPIDD == 
respServer.XMPPID {
+               t.Errorf("HostName didn't change. Expected: #{updatedHostName}, 
actual: #{originalHostname}")
+       }
+
+       //Check to verify XMPPID never gets updated
+       changeXMPPID := true
+       if changeXMPPID {

Review comment:
       Won't this always be true?

##########
File path: traffic_ops/traffic_ops_golang/server/servers.go
##########
@@ -984,6 +984,11 @@ func Update(w http.ResponseWriter, r *http.Request) {
        }
        defer inf.Close()
 
+       //Get original xmppid
+       origSer, _, _, _, _, _ := getServers(r.Header, inf.Params, inf.Tx, 
inf.User, false)

Review comment:
       We should check for the errors here, and only dereference the `origSer` 
variable in the case when there was no error

##########
File path: traffic_ops/traffic_ops_golang/server/servers.go
##########
@@ -1055,52 +1065,56 @@ func Update(w http.ResponseWriter, r *http.Request) {
                return
        }
 
-       rows, err := inf.Tx.NamedQuery(updateQuery, server)
-       if err != nil {
-               userErr, sysErr, errCode = api.ParseDBError(err)
-               api.HandleErr(w, r, tx, errCode, userErr, sysErr)
-               return
-       }
-       defer rows.Close()
+       if changeXMPPID {
+               api.WriteRespAlertObj(w, r, tc.ErrorLevel, fmt.Sprintf("server 
cannot be updated due to requested XMPPID change. XMPIDD is immutable"), nil)

Review comment:
       You should return here, after `api.WriteRespAlertObj` because of two 
reasons:
   1.) That way, you dont have to use the `else` block
   2.) If you dont return, the `error.log` will complain about response being 
written twice

##########
File path: traffic_ops/testing/api/v3/servers_test.go
##########
@@ -321,6 +332,33 @@ func UpdateTestServers(t *testing.T) {
                t.Fatalf("Cannot test server type change update; server '%s' 
had nil type ID", hostName)
        }
 
+       //Check change in hostname with no change to xmppid
+       if originalHostname == *respServer.HostName && originalXMPIDD == 
*respServer.XMPPID {
+               t.Errorf("HostName didn't change. Expected: #{updatedHostName}, 
actual: #{originalHostname}")
+       }
+
+       //Check to verify XMPPID never gets updated
+       changeXMPPID := true

Review comment:
       Same comment here




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to