You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2020/07/08 23:35:06 UTC

[GitHub] [trafficcontrol] srijeet0406 opened a new pull request #4869: Fixing /api/1.1/servers/{id} endpoint to not return empty response

srijeet0406 opened a new pull request #4869:
URL: https://github.com/apache/trafficcontrol/pull/4869


   <!--
   ************ STOP!! ************
   If this Pull Request is intended to fix a security vulnerability, DO NOT submit it! Instead, contact
   the Apache Software Foundation Security Team at security@trafficcontrol.apache.org and follow the
   guidelines at https://www.apache.org/security/ regarding vulnerability disclosure.
   -->
   ## What does this PR (Pull Request) do?
   <!-- Explain the changes you made here. If this fixes an Issue, identify it by
   replacing the text in the checkbox item with the Issue number e.g.
   
   - [x] This PR fixes #9001 OR is not related to any Issue
   
   ^ This will automatically close Issue number 9001 when the Pull Request is
   merged (The '#' is important).
   
   Be sure you check the box properly, see the "The following criteria are ALL
   met by this PR" section for details.
   -->
   
   - [x] This PR fixes #4867  <!-- You can check for an issue here: https://github.com/apache/trafficcontrol/issues -->
   
   
   ## Which Traffic Control components are affected by this PR?
   <!-- Please delete all components from this list that are NOT affected by this
   Pull Request. Also, feel free to add the name of a tool or script that is
   affected but not on the list.
   
   Additionally, if this Pull Request does NOT affect documentation, please
   explain why documentation is not required. -->
   
   - CDN in a Box
   - Traffic Control Client Go <!-- Please specify which; e.g. 'Python', 'Go', 'Java' -->
   - Traffic Ops
   
   ## What is the best way to verify this PR?
   <!-- Please include here ALL the steps necessary to test your Pull Request. If
   it includes tests (and most should), outline here the steps needed to run the
   tests. If not, lay out the manual testing procedure and please explain why
   tests are unnecessary for this Pull Request. -->
   Run the API v1 tests and make sure they all pass.
   
   ## If this is a bug fix, what versions of Traffic Control are affected?
   <!-- If this PR fixes a bug, please list here all of the affected versions - to
   the best of your knowledge. It's also pretty helpful to include a commit hash
   of where 'master' is at the time this PR is opened (if it affects master),
   because what 'master' means will change over time. For example, if this PR
   fixes a bug that's present in master (at commit hash '1df853c8'), in v4.0.0,
   and in the current 4.0.1 Release candidate (e.g. RC1), then this list would
   look like:
   
   - master (1df853c8)
   - 4.0.0
   - 4.0.1 (RC1)
   
   If you don't know what other versions might have this bug, AND don't know how
   to find the commit hash of 'master', then feel free to leave this section
   blank (or, preferably, delete it entirely).
    -->
   - master
   
   ## The following criteria are ALL met by this PR
   <!-- Check the boxes to signify that the associated statement is true. To
   "check a box", replace the space inside of the square brackets with an 'x'.
   e.g.
   
   - [ x] <- Wrong
   - [x ] <- Wrong
   - [] <- Wrong
   - [*] <- Wrong
   - [x] <- Correct!
   
   -->
   
   - [x] This PR includes tests
   - [x] I have explained why documentation is unnecessary
   - [x] This PR does not include an update to CHANGELOG.md 
   - [x] This PR includes any and all required license headers
   - [x] This PR does not include a database migration
   - [x] This PR **DOES NOT FIX A SERIOUS SECURITY VULNERABILITY** (see [the Apache Software Foundation's security guidelines](https://www.apache.org/security/) for details)
   
   
   ## Additional Information
   <!-- If you would like to include any additional information on the PR for
   potential reviewers please put it here.
   
   Some examples of this would be:
   
   - Before and after screenshots/gifs of the Traffic Portal if it is affected
   - Links to other dependent Pull Requests
   - References to relevant context (e.g. new/updates to dependent libraries,
   mailing list records, blueprints)
   
   Feel free to leave this section blank (or, preferably, delete it entirely).
   -->
   
   <!--
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you under the Apache License, Version 2.0 (the
   "License"); you may not use this file except in compliance
   with the License.  You may obtain a copy of the License at
   
       http://www.apache.org/licenses/LICENSE-2.0
   
   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.
   -->
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #4869: Fixing /api/1.1/servers/{id} endpoint to not return empty response

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #4869:
URL: https://github.com/apache/trafficcontrol/pull/4869#discussion_r451991577



##########
File path: traffic_ops/traffic_ops_golang/server/servers.go
##########
@@ -581,18 +581,28 @@ func ReadID(w http.ResponseWriter, r *http.Request) {
 		log.Warnf("Couldn't get config %v", e)
 	}
 	servers, _, userErr, sysErr, errCode, _ = getServers(r.Header, inf.Params, inf.Tx, inf.User, useIMS)
-
 	if len(servers) > 1 {
 		api.HandleDeprecatedErr(w, r, tx, http.StatusInternalServerError, nil, fmt.Errorf("ID '%d' matched more than one server (%d total)", inf.IntParams["id"], len(servers)), &alternative)
 		return
 	}
-
 	deprecationAlerts := api.CreateDeprecationAlerts(&alternative)
 
 	// No need to bother converting if there's no data
 	if len(servers) < 1 {
 		api.WriteAlertsObj(w, r, http.StatusOK, deprecationAlerts, servers)
+		return
 	}
+	legacyServers := make([]tc.ServerNullableV11, 0, 1)
+	for _, server := range servers {
+		legacyServer, err := server.ToServerV2()
+		if err != nil {
+			api.HandleErr(w, r, tx, http.StatusInternalServerError, nil, fmt.Errorf("failed to convert servers to legacy format: %v", err))
+			return
+		}
+		legacyServers = append(legacyServers, legacyServer.ServerNullableV11)
+	}
+	api.WriteResp(w, r, legacyServers)

Review comment:
       The response needs to include a deprecation notice

##########
File path: traffic_ops/traffic_ops_golang/server/servers.go
##########
@@ -581,18 +581,28 @@ func ReadID(w http.ResponseWriter, r *http.Request) {
 		log.Warnf("Couldn't get config %v", e)
 	}
 	servers, _, userErr, sysErr, errCode, _ = getServers(r.Header, inf.Params, inf.Tx, inf.User, useIMS)
-
 	if len(servers) > 1 {
 		api.HandleDeprecatedErr(w, r, tx, http.StatusInternalServerError, nil, fmt.Errorf("ID '%d' matched more than one server (%d total)", inf.IntParams["id"], len(servers)), &alternative)
 		return
 	}
-
 	deprecationAlerts := api.CreateDeprecationAlerts(&alternative)
 
 	// No need to bother converting if there's no data
 	if len(servers) < 1 {
 		api.WriteAlertsObj(w, r, http.StatusOK, deprecationAlerts, servers)
+		return
 	}
+	legacyServers := make([]tc.ServerNullableV11, 0, 1)
+	for _, server := range servers {
+		legacyServer, err := server.ToServerV2()
+		if err != nil {
+			api.HandleErr(w, r, tx, http.StatusInternalServerError, nil, fmt.Errorf("failed to convert servers to legacy format: %v", err))

Review comment:
       The internal server error needs to include a deprecation notice




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on pull request #4869: Fixing /api/1.1/servers/{id} endpoint to not return empty response

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on pull request #4869:
URL: https://github.com/apache/trafficcontrol/pull/4869#issuecomment-656208339


   @ocket8888 - is this related to #4820 in any way? can they be merged together or do they address different problems?


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on pull request #4869: Fixing /api/1.1/servers/{id} endpoint to not return empty response

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on pull request #4869:
URL: https://github.com/apache/trafficcontrol/pull/4869#issuecomment-656212534


   They're different problems


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on pull request #4869: Fixing /api/1.1/servers/{id} endpoint to not return empty response

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on pull request #4869:
URL: https://github.com/apache/trafficcontrol/pull/4869#issuecomment-656779569


   @ocket8888 - you want to merge this?


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 merged pull request #4869: Fixing /api/1.1/servers/{id} endpoint to not return empty response

Posted by GitBox <gi...@apache.org>.
ocket8888 merged pull request #4869:
URL: https://github.com/apache/trafficcontrol/pull/4869


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #4869: Fixing /api/1.1/servers/{id} endpoint to not return empty response

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #4869:
URL: https://github.com/apache/trafficcontrol/pull/4869#discussion_r451929026



##########
File path: traffic_ops/testing/api/v1/servers_test.go
##########
@@ -71,19 +70,18 @@ func UpdateTestServers(t *testing.T) {
 	var alert tc.Alerts
 	alert, _, err = TOSession.UpdateServerByID(remoteServer.ID, remoteServer)
 	if err != nil {
-		t.Errorf("cannot UPDATE Server by hostname: %v - %v", err, alert)
+		t.Fatalf("cannot UPDATE Server by ID: %v - %v", err, alert)
 	}
-
 	// Retrieve the server to check rack and interfaceName values were updated
 	resp, _, err = TOSession.GetServerByID(remoteServer.ID)
 	if err != nil {
-		t.Errorf("cannot GET Server by ID: %v - %v", remoteServer.HostName, err)
+		t.Fatalf("cannot GET Server by ID: %v - %v", remoteServer.ID, err)
 	}
 
 	respServer := resp[0]
 	if respServer.InterfaceName != updatedServerInterface || respServer.Rack != updatedServerRack {
-		t.Errorf("results do not match actual: %s, expected: %s", respServer.InterfaceName, updatedServerInterface)
-		t.Errorf("results do not match actual: %s, expected: %s", respServer.Rack, updatedServerRack)
+		t.Fatalf("results do not match actual: %s, expected: %s", respServer.InterfaceName, updatedServerInterface)
+		t.Fatalf("results do not match actual: %s, expected: %s", respServer.Rack, updatedServerRack)

Review comment:
       Why are these fatal now? The rest of the test doesn't panic if the comparison is untrue. In fact, by making the first of these fatal, you've ensured that no one will ever see the second one, meaning that you can get the cryptic failure message:
   ```
   results do not match actual: test, expected: test
   ```

##########
File path: traffic_ops/testing/api/v1/servers_test.go
##########
@@ -16,9 +16,8 @@ package v1
 */
 
 import (
-	"testing"
-
 	"github.com/apache/trafficcontrol/lib/go-tc"
+	"testing"

Review comment:
       Why'd you re-order these? Normal procedure is to put standard library dependencies first, then in-project dependencies, then 3rd party.

##########
File path: traffic_ops/testing/api/v1/servers_test.go
##########
@@ -71,19 +70,18 @@ func UpdateTestServers(t *testing.T) {
 	var alert tc.Alerts
 	alert, _, err = TOSession.UpdateServerByID(remoteServer.ID, remoteServer)
 	if err != nil {
-		t.Errorf("cannot UPDATE Server by hostname: %v - %v", err, alert)
+		t.Fatalf("cannot UPDATE Server by ID: %v - %v", err, alert)

Review comment:
       Good fix on the typo, but why is that fatal? The one below definitely should be.

##########
File path: traffic_ops/traffic_ops_golang/server/servers.go
##########
@@ -581,18 +581,28 @@ func ReadID(w http.ResponseWriter, r *http.Request) {
 		log.Warnf("Couldn't get config %v", e)
 	}
 	servers, _, userErr, sysErr, errCode, _ = getServers(r.Header, inf.Params, inf.Tx, inf.User, useIMS)
-
 	if len(servers) > 1 {
 		api.HandleDeprecatedErr(w, r, tx, http.StatusInternalServerError, nil, fmt.Errorf("ID '%d' matched more than one server (%d total)", inf.IntParams["id"], len(servers)), &alternative)
 		return
 	}
-
 	deprecationAlerts := api.CreateDeprecationAlerts(&alternative)
 
 	// No need to bother converting if there's no data
 	if len(servers) < 1 {
 		api.WriteAlertsObj(w, r, http.StatusOK, deprecationAlerts, servers)
+		return
 	}
+	legacyServers := make([]tc.ServerNullableV11, 0, 1)

Review comment:
       as long as you're allocating memory ahead of time, you may as well set the capacity to what we know it needs to be; instead of 1 it'd be much more efficient to go ahead and allocate room for `len(servers)`.

##########
File path: traffic_ops/testing/api/v1/servers_test.go
##########
@@ -118,7 +116,7 @@ func UpdateTestServers(t *testing.T) {
 	// Attempt Update - should fail
 	_, _, err = TOSession.UpdateServerByID(remoteServer.ID, remoteServer)
 	if err == nil {
-		t.Errorf("expected error when updating Server Type of a server assigned to DSes")
+		t.Fatalf("expected error when updating Server Type of a server assigned to DSes")

Review comment:
       This one doesn't really matter either way, because it's at the end. Just seems a bit unnecessary.




----------------------------------------------------------------
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:
users@infra.apache.org