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 2021/09/01 09:38:36 UTC

[GitHub] [trafficcontrol] dmohan001c opened a new pull request #6151: Add TO Client API for ServerServerCapability Automation

dmohan001c opened a new pull request #6151:
URL: https://github.com/apache/trafficcontrol/pull/6151


   ## What does this PR (Pull Request) do?
   
   - [x] This PR is not related to any Issue
   
   ## Which Traffic Control components are affected by this PR?
   
   - CDN in a Box
   - Traffic Control Client <!-- Please specify which; e.g. 'Python', 'Go', 'Java' -->
   - Traffic Ops
   - CI tests
   
   ## What is the best way to verify this PR?
   Execute all the Integration tests and make sure the tests passed.
   
   ## 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 OR I have explained why tests are unnecessary
   - [x] This PR includes documentation OR I have explained why documentation is unnecessary
   - [x] This PR includes an update to CHANGELOG.md OR such an update is not necessary
   - [x] This PR includes any and all required license headers
   - [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)


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #6151: Add TO Client API for ServerServerCapability Automation

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



##########
File path: traffic_ops/v4-client/server_server_capabilities.go
##########
@@ -39,7 +39,9 @@ func (to *Session) DeleteServerServerCapability(serverID int, serverCapability s
 	if opts.QueryParameters == nil {
 		opts.QueryParameters = url.Values{}
 	}
-	opts.QueryParameters.Set("serverId", strconv.Itoa(serverID))
+	if serverID != 0 {
+		opts.QueryParameters.Set("serverId", strconv.Itoa(serverID))
+	}

Review comment:
       This method doesn't work without specifying a server ID - why do 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.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #6151: Add TO Client API for ServerServerCapability Automation

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



##########
File path: traffic_ops/testing/api/v4/serverservercapability_test.go
##########
@@ -36,14 +37,17 @@ func TestServerServerCapabilities(t *testing.T) {
 		GetTestServerServerCapabilities(t)
 		GetDeliveryServiceServersWithCapabilities(t)
 		UpdateTestServerServerCapabilities(t)
+		GetTestPaginationSupportSsc(t)
+		DeleteTestServerServerCapabilityWithInvalidData(t)
 	})
 }
 
+/*
 func TestServerServerCapabilitiesForTopologies(t *testing.T) {
 	WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, DeliveryServices, ServerCapabilities, ServerServerCapabilitiesForTopologies, TopologyBasedDeliveryServiceRequiredCapabilities}, func() {
 		DeleteTestServerServerCapabilitiesForTopologiesValidation(t)
 	})
-}
+}*/

Review comment:
       Why are we removing this test?




-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #6151: Add TO Client API for ServerServerCapability Automation

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



##########
File path: traffic_ops/testing/api/v4/serverservercapability_test.go
##########
@@ -596,3 +597,99 @@ func GetDeliveryServiceServersWithCapabilities(t *testing.T) {
 		t.Errorf("Unexpected error removing server #%d from Delivery Service #%d: %v - alerts: %+v", midID, *ds.ID, err, alerts.Alerts)
 	}
 }
+
+func GetTestPaginationSupportSsc(t *testing.T) {
+	opts := client.NewRequestOptions()
+	opts.QueryParameters.Set("orderby", "id")
+	resp, _, err := TOSession.GetServerServerCapabilities(opts)
+	if err != nil {
+		t.Fatalf("cannot get server server capabilities: %v - alerts: %+v", err, resp.Alerts)
+	}
+	ServerServerCapabilities := resp.Response
+	if len(ServerServerCapabilities) < 3 {
+		t.Fatalf("Need at least 3 server server capabilities in Traffic Ops to test pagination support, found: %d", len(ServerServerCapabilities))
+	}
+
+	opts.QueryParameters.Set("orderby", "id")
+	opts.QueryParameters.Set("limit", "1")
+	serverServerCapWithLimit, _, err := TOSession.GetServerServerCapabilities(opts)
+	if err != nil {
+		t.Fatalf("cannot get server server capabilities by Order and Limit: %v - alerts: %+v", err, resp.Alerts)
+	}
+	if !reflect.DeepEqual(ServerServerCapabilities[:1], serverServerCapWithLimit.Response) {
+		t.Error("expected GET Server Server Capabilities with limit = 1 to return first result")
+	}
+
+	opts.QueryParameters.Set("orderby", "id")
+	opts.QueryParameters.Set("limit", "1")
+	opts.QueryParameters.Set("offset", "1")
+	serverServerCapWithOffset, _, err := TOSession.GetServerServerCapabilities(opts)
+	if err != nil {
+		t.Fatalf("cannot get server server capabilities by Order, Limit and Offset: %v - alerts: %+v", err, resp.Alerts)
+	}
+	if !reflect.DeepEqual(ServerServerCapabilities[1:2], serverServerCapWithOffset.Response) {
+		t.Error("expected GET server server capabilities with limit = 1, offset = 1 to return second result")
+	}
+
+	opts.QueryParameters.Set("orderby", "id")
+	opts.QueryParameters.Set("limit", "1")
+	opts.QueryParameters.Set("page", "2")
+	serverServerCapWithPage, _, err := TOSession.GetServerServerCapabilities(opts)
+	if err != nil {
+		t.Fatalf("cannot get server server capabilities by Order, Limit and Page: %v - alerts: %+v", err, resp.Alerts)
+	}
+	if !reflect.DeepEqual(ServerServerCapabilities[1:2], serverServerCapWithPage.Response) {
+		t.Error("expected GET Server Server Capabilities with limit = 1, page = 2 to return second result")
+	}
+
+	opts.QueryParameters = url.Values{}
+	opts.QueryParameters.Set("limit", "-2")
+	resp, _, err = TOSession.GetServerServerCapabilities(opts)
+	if err == nil {
+		t.Error("expected GET Server Server Capabilities to return an error when limit is not bigger than -1")
+	} else if !alertsHaveError(resp.Alerts.Alerts, "must be bigger than -1") {
+		t.Errorf("expected GET Server Server Capabilities to return an error for limit is not bigger than -1, actual error: %v - alerts: %+v", err, resp.Alerts)
+	}
+
+	opts.QueryParameters.Set("limit", "1")
+	opts.QueryParameters.Set("offset", "0")
+	resp, _, err = TOSession.GetServerServerCapabilities(opts)
+	if err == nil {
+		t.Error("expected GET Server Server Capabilities to return an error when offset is not a positive integer")
+	} else if !alertsHaveError(resp.Alerts.Alerts, "must be a positive integer") {
+		t.Errorf("expected GET Server Server Capabilities to return an error for offset is not a positive integer, actual error: %v - alerts: %+v", err, resp.Alerts)
+	}
+
+	opts.QueryParameters = url.Values{}
+	opts.QueryParameters.Set("limit", "1")
+	opts.QueryParameters.Set("page", "0")
+	resp, _, err = TOSession.GetServerServerCapabilities(opts)
+	if err == nil {
+		t.Error("expected GET Server Server Capabilities to return an error when page is not a positive integer")
+	} else if !alertsHaveError(resp.Alerts.Alerts, "must be a positive integer") {
+		t.Errorf("expected GET Server Server Capabilities to return an error for page is not a positive integer, actual error: %v - alerts: %+v", err, resp.Alerts)
+	}
+}
+
+func DeleteTestServerServerCapabilityWithInvalidData(t *testing.T) {
+	// Get Server server Capabilities to delete them
+	sscs, _, err := TOSession.GetServerServerCapabilities(client.RequestOptions{})
+	if err != nil {
+		t.Fatalf("cannot get server/Capability associations: %v - alerts: %+v", err, sscs.Alerts)
+	}
+	if len(sscs.Response) < 1 {
+		t.Fatalf("No Server Server Capability available to test invalid scenario")
+	}
+
+	//Delete Server Server Capability with Invalid Server Capability
+	alerts, _, err := TOSession.DeleteServerServerCapability(*sscs.Response[0].ServerID, "abcd", client.RequestOptions{})

Review comment:
       this line will segfault if the first response element has a null or undefined `serverId`




-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c closed pull request #6151: Add TO Client API for ServerServerCapability Automation

Posted by GitBox <gi...@apache.org>.
dmohan001c closed pull request #6151:
URL: https://github.com/apache/trafficcontrol/pull/6151


   


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] rawlinp commented on pull request #6151: Add TO Client API for ServerServerCapability Automation

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


   Looks like this PR had a bad merge because it's adding a bunch of already-existing code changes.


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c commented on pull request #6151: Add TO Client API for ServerServerCapability Automation

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


   > Looks like this PR had a bad merge because it's adding a bunch of already-existing code changes.
   
   Fixed.


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c commented on a change in pull request #6151: Add TO Client API for ServerServerCapability Automation

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



##########
File path: traffic_ops/testing/api/v4/serverservercapability_test.go
##########
@@ -596,3 +597,99 @@ func GetDeliveryServiceServersWithCapabilities(t *testing.T) {
 		t.Errorf("Unexpected error removing server #%d from Delivery Service #%d: %v - alerts: %+v", midID, *ds.ID, err, alerts.Alerts)
 	}
 }
+
+func GetTestPaginationSupportSsc(t *testing.T) {
+	opts := client.NewRequestOptions()
+	opts.QueryParameters.Set("orderby", "id")
+	resp, _, err := TOSession.GetServerServerCapabilities(opts)
+	if err != nil {
+		t.Fatalf("cannot get server server capabilities: %v - alerts: %+v", err, resp.Alerts)
+	}
+	ServerServerCapabilities := resp.Response
+	if len(ServerServerCapabilities) < 3 {
+		t.Fatalf("Need at least 3 server server capabilities in Traffic Ops to test pagination support, found: %d", len(ServerServerCapabilities))
+	}
+
+	opts.QueryParameters.Set("orderby", "id")
+	opts.QueryParameters.Set("limit", "1")
+	serverServerCapWithLimit, _, err := TOSession.GetServerServerCapabilities(opts)
+	if err != nil {
+		t.Fatalf("cannot get server server capabilities by Order and Limit: %v - alerts: %+v", err, resp.Alerts)
+	}
+	if !reflect.DeepEqual(ServerServerCapabilities[:1], serverServerCapWithLimit.Response) {
+		t.Error("expected GET Server Server Capabilities with limit = 1 to return first result")
+	}
+
+	opts.QueryParameters.Set("orderby", "id")
+	opts.QueryParameters.Set("limit", "1")
+	opts.QueryParameters.Set("offset", "1")
+	serverServerCapWithOffset, _, err := TOSession.GetServerServerCapabilities(opts)
+	if err != nil {
+		t.Fatalf("cannot get server server capabilities by Order, Limit and Offset: %v - alerts: %+v", err, resp.Alerts)
+	}
+	if !reflect.DeepEqual(ServerServerCapabilities[1:2], serverServerCapWithOffset.Response) {
+		t.Error("expected GET server server capabilities with limit = 1, offset = 1 to return second result")
+	}
+
+	opts.QueryParameters.Set("orderby", "id")
+	opts.QueryParameters.Set("limit", "1")
+	opts.QueryParameters.Set("page", "2")
+	serverServerCapWithPage, _, err := TOSession.GetServerServerCapabilities(opts)
+	if err != nil {
+		t.Fatalf("cannot get server server capabilities by Order, Limit and Page: %v - alerts: %+v", err, resp.Alerts)
+	}
+	if !reflect.DeepEqual(ServerServerCapabilities[1:2], serverServerCapWithPage.Response) {
+		t.Error("expected GET Server Server Capabilities with limit = 1, page = 2 to return second result")
+	}
+
+	opts.QueryParameters = url.Values{}
+	opts.QueryParameters.Set("limit", "-2")
+	resp, _, err = TOSession.GetServerServerCapabilities(opts)
+	if err == nil {
+		t.Error("expected GET Server Server Capabilities to return an error when limit is not bigger than -1")
+	} else if !alertsHaveError(resp.Alerts.Alerts, "must be bigger than -1") {
+		t.Errorf("expected GET Server Server Capabilities to return an error for limit is not bigger than -1, actual error: %v - alerts: %+v", err, resp.Alerts)
+	}
+
+	opts.QueryParameters.Set("limit", "1")
+	opts.QueryParameters.Set("offset", "0")
+	resp, _, err = TOSession.GetServerServerCapabilities(opts)
+	if err == nil {
+		t.Error("expected GET Server Server Capabilities to return an error when offset is not a positive integer")
+	} else if !alertsHaveError(resp.Alerts.Alerts, "must be a positive integer") {
+		t.Errorf("expected GET Server Server Capabilities to return an error for offset is not a positive integer, actual error: %v - alerts: %+v", err, resp.Alerts)
+	}
+
+	opts.QueryParameters = url.Values{}
+	opts.QueryParameters.Set("limit", "1")
+	opts.QueryParameters.Set("page", "0")
+	resp, _, err = TOSession.GetServerServerCapabilities(opts)
+	if err == nil {
+		t.Error("expected GET Server Server Capabilities to return an error when page is not a positive integer")
+	} else if !alertsHaveError(resp.Alerts.Alerts, "must be a positive integer") {
+		t.Errorf("expected GET Server Server Capabilities to return an error for page is not a positive integer, actual error: %v - alerts: %+v", err, resp.Alerts)
+	}
+}
+
+func DeleteTestServerServerCapabilityWithInvalidData(t *testing.T) {
+	// Get Server server Capabilities to delete them
+	sscs, _, err := TOSession.GetServerServerCapabilities(client.RequestOptions{})
+	if err != nil {
+		t.Fatalf("cannot get server/Capability associations: %v - alerts: %+v", err, sscs.Alerts)
+	}
+	if len(sscs.Response) < 1 {
+		t.Fatalf("No Server Server Capability available to test invalid scenario")
+	}
+
+	//Delete Server Server Capability with Invalid Server Capability
+	alerts, _, err := TOSession.DeleteServerServerCapability(*sscs.Response[0].ServerID, "abcd", client.RequestOptions{})

Review comment:
       Fixed.




-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #6151: Add TO Client API for ServerServerCapability Automation

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



##########
File path: traffic_ops/v4-client/server_server_capabilities.go
##########
@@ -39,7 +39,9 @@ func (to *Session) DeleteServerServerCapability(serverID int, serverCapability s
 	if opts.QueryParameters == nil {
 		opts.QueryParameters = url.Values{}
 	}
-	opts.QueryParameters.Set("serverId", strconv.Itoa(serverID))
+	if serverID != 0 {
+		opts.QueryParameters.Set("serverId", strconv.Itoa(serverID))
+	}

Review comment:
       This method doesn't work without specifying a server ID - why do 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.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c commented on a change in pull request #6151: Add TO Client API for ServerServerCapability Automation

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



##########
File path: traffic_ops/v4-client/server_server_capabilities.go
##########
@@ -39,7 +39,9 @@ func (to *Session) DeleteServerServerCapability(serverID int, serverCapability s
 	if opts.QueryParameters == nil {
 		opts.QueryParameters = url.Values{}
 	}
-	opts.QueryParameters.Set("serverId", strconv.Itoa(serverID))
+	if serverID != 0 {
+		opts.QueryParameters.Set("serverId", strconv.Itoa(serverID))
+	}

Review comment:
       reverted the client method changes.




-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c commented on a change in pull request #6151: Add TO Client API for ServerServerCapability Automation

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



##########
File path: traffic_ops/testing/api/v4/serverservercapability_test.go
##########
@@ -36,14 +37,17 @@ func TestServerServerCapabilities(t *testing.T) {
 		GetTestServerServerCapabilities(t)
 		GetDeliveryServiceServersWithCapabilities(t)
 		UpdateTestServerServerCapabilities(t)
+		GetTestPaginationSupportSsc(t)
+		DeleteTestServerServerCapabilityWithInvalidData(t)
 	})
 }
 
+/*
 func TestServerServerCapabilitiesForTopologies(t *testing.T) {
 	WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, DeliveryServices, ServerCapabilities, ServerServerCapabilitiesForTopologies, TopologyBasedDeliveryServiceRequiredCapabilities}, func() {
 		DeleteTestServerServerCapabilitiesForTopologiesValidation(t)
 	})
-}
+}*/

Review comment:
       it has been commented accidentally, I removed it.




-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 merged pull request #6151: Add TO Client API for ServerServerCapability Automation

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


   


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org