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 2022/04/12 00:58:30 UTC
[trafficcontrol] branch master updated: Refactor DeliveryServiceServers and DeliveryServiceRequiredCapabilities tests (#6728)
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 eb276f3b13 Refactor DeliveryServiceServers and DeliveryServiceRequiredCapabilities tests (#6728)
eb276f3b13 is described below
commit eb276f3b13caef04ef34f49407fba5802ff1fc98
Author: Eric Holguin <14...@users.noreply.github.com>
AuthorDate: Mon Apr 11 18:58:25 2022 -0600
Refactor DeliveryServiceServers and DeliveryServiceRequiredCapabilities tests (#6728)
* Initial refactor
* addd server assignment prereq
* initial refactor
* add server prereq
* with obj prereq moved to dsrc
* DeliveryServiceServers refactor
* DSRC refactor
* Added needed prereqs
* remove prereq
* Remove conflicting dependencies
* fix dep issue and remove unneeded check
* fix dependency order
* fix dependency order and flaky test
---
.../deliveryservices_required_capabilities_test.go | 673 ++++--------
.../testing/api/v3/deliveryservices_test.go | 2 +-
.../testing/api/v3/deliveryserviceservers_test.go | 930 ++++++-----------
.../testing/api/v3/serverservercapability_test.go | 10 +-
traffic_ops/testing/api/v3/tc-fixtures.json | 65 ++
traffic_ops/testing/api/v3/topologies_test.go | 3 +-
traffic_ops/testing/api/v3/withobjs_test.go | 6 +-
.../deliveryservices_required_capabilities_test.go | 880 ++++------------
.../testing/api/v4/deliveryservices_test.go | 15 +-
.../testing/api/v4/deliveryserviceservers_test.go | 1103 +++++++-------------
.../testing/api/v4/serverservercapability_test.go | 10 +-
traffic_ops/testing/api/v4/tc-fixtures.json | 69 +-
traffic_ops/testing/api/v4/topologies_test.go | 2 +-
traffic_ops/testing/api/v4/withobjs_test.go | 6 +-
14 files changed, 1271 insertions(+), 2503 deletions(-)
diff --git a/traffic_ops/testing/api/v3/deliveryservices_required_capabilities_test.go b/traffic_ops/testing/api/v3/deliveryservices_required_capabilities_test.go
index 6b094619bf..b521a3140d 100644
--- a/traffic_ops/testing/api/v3/deliveryservices_required_capabilities_test.go
+++ b/traffic_ops/testing/api/v3/deliveryservices_required_capabilities_test.go
@@ -16,524 +16,231 @@ package v3
*/
import (
- "fmt"
+ "encoding/json"
"net/http"
"net/url"
"strconv"
- "strings"
"testing"
"time"
"github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
- "github.com/apache/trafficcontrol/lib/go-util"
+ "github.com/apache/trafficcontrol/traffic_ops/testing/api/assert"
+ "github.com/apache/trafficcontrol/traffic_ops/testing/api/utils"
+ "github.com/apache/trafficcontrol/traffic_ops/toclientlib"
)
func TestDeliveryServicesRequiredCapabilities(t *testing.T) {
- WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, ServerCapabilities, Topologies, DeliveryServices, DeliveryServicesRequiredCapabilities}, func() {
- GetTestDeliveryServicesRequiredCapabilitiesIMS(t)
- InvalidDeliveryServicesRequiredCapabilityAddition(t)
- GetTestDeliveryServicesRequiredCapabilities(t)
- currentTime := time.Now().UTC().Add(-5 * time.Second)
- time := currentTime.Format(time.RFC1123)
- var header http.Header
- header = make(map[string][]string)
- header.Set(rfc.IfModifiedSince, time)
- GetTestDeliveryServicesRequiredCapabilitiesIMSAfterChange(t, header)
- })
-}
-
-func TestTopologyBasedDeliveryServicesRequiredCapabilities(t *testing.T) {
- WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, ServerCapabilities, ServerServerCapabilitiesForTopologies, Topologies, DeliveryServices, TopologyBasedDeliveryServiceRequiredCapabilities}, func() {
- GetTestDeliveryServicesRequiredCapabilities(t)
- OriginAssignTopologyBasedDeliveryServiceWithRequiredCapabilities(t)
- })
-}
-
-func OriginAssignTopologyBasedDeliveryServiceWithRequiredCapabilities(t *testing.T) {
- resp, _, err := TOSession.GetDeliveryServiceByXMLIDNullableWithHdr("ds-top-req-cap2", nil)
- if err != nil {
- t.Errorf("getting delivery service by xml ID: %v", err.Error())
- }
- if len(resp) != 1 {
- t.Fatalf("expected to get only one delivery service in the response, but got %d", len(resp))
- }
- if resp[0].ID == nil {
- t.Fatalf("no ID in the resulting delivery service")
- }
- dsID := *resp[0].ID
- params := url.Values{}
- _, _, err = TOSession.AssignServersToDeliveryService([]string{"denver-mso-org-01"}, "ds-top-req-cap2")
- if err != nil {
- t.Errorf("assigning ORG server to ds-top delivery service: %v", err.Error())
- }
- params.Add("dsId", strconv.Itoa(dsID))
- params.Add("type", tc.OriginTypeName)
- responseServers, _, err := TOSession.GetServersWithHdr(¶ms, nil)
- if err != nil {
- t.Fatalf("getting servers for ds-top-req-cap2 delivery service: %v", err.Error())
- }
- if len(responseServers.Response) != 1 {
- t.Fatalf("expected just one ORG server in the response, but got %d", len(responseServers.Response))
- }
- if responseServers.Response[0].HostName == nil {
- t.Fatal("expected a valid host name for the resulting ORG server, but got nothing")
- }
- if *responseServers.Response[0].HostName != "denver-mso-org-01" {
- t.Errorf("expected host name of the resulting ORG server to be %v, but got %v", "denver-mso-org-01", *responseServers.Response[0].HostName)
- }
-}
-
-func GetTestDeliveryServicesRequiredCapabilitiesIMSAfterChange(t *testing.T, header http.Header) {
- data := testData.DeliveryServicesRequiredCapabilities
- ds1 := helperGetDeliveryServiceID(t, data[0].XMLID)
-
- testCases := []struct {
- description string
- capability tc.DeliveryServicesRequiredCapability
- }{
- {
- description: "get all deliveryservices required capabilities",
- },
- {
- description: fmt.Sprintf("get all deliveryservices required capabilities by deliveryServiceID: %d", *ds1),
- capability: tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: ds1,
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, ServerCapabilities, Topologies, ServiceCategories, DeliveryServices, DeliveryServiceServerAssignments, ServerServerCapabilities, DeliveryServicesRequiredCapabilities}, func() {
+
+ currentTime := time.Now().UTC().Add(-15 * time.Second)
+ currentTimeRFC := currentTime.Format(time.RFC1123)
+ tomorrow := currentTime.AddDate(0, 0, 1).Format(time.RFC1123)
+
+ methodTests := utils.V3TestCase{
+ "GET": {
+ "NOT MODIFIED when NO CHANGES made": {
+ ClientSession: TOSession, RequestHeaders: http.Header{rfc.IfModifiedSince: {tomorrow}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusNotModified)),
+ },
+ "OK when VALID request": {
+ ClientSession: TOSession, Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ "OK when VALID DELIVERYSERVICEID parameter": {
+ ClientSession: TOSession,
+ RequestParams: url.Values{"deliveryServiceId": {"ds1"}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseLengthGreaterOrEqual(1),
+ validateDSRCExpectedFields(map[string]interface{}{"DeliveryServiceId": "ds1"})),
+ },
+ "OK when VALID XMLID parameter": {
+ ClientSession: TOSession, RequestParams: url.Values{"xmlID": {"ds2"}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseLengthGreaterOrEqual(1),
+ validateDSRCExpectedFields(map[string]interface{}{"XMLID": "ds2"})),
+ },
+ "OK when VALID REQUIREDCAPABILITY parameter": {
+ ClientSession: TOSession, RequestParams: url.Values{"requiredCapability": {"bar"}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseLengthGreaterOrEqual(1),
+ validateDSRCExpectedFields(map[string]interface{}{"RequiredCapability": "bar"})),
+ },
+ },
+ "POST": {
+ "BAD REQUEST when REASSIGNING REQUIRED CAPABILITY to DELIVERY SERVICE": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "deliveryServiceID": GetDeliveryServiceId(t, "ds1")(),
+ "requiredCapability": "foo",
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ "BAD REQUEST when SERVERS DONT have CAPABILITY": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "deliveryServiceID": GetDeliveryServiceId(t, "test-ds-server-assignments")(),
+ "requiredCapability": "disk",
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ "BAD REQUEST when DELIVERY SERVICE HAS TOPOLOGY where SERVERS DONT have CAPABILITY": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "deliveryServiceID": GetDeliveryServiceId(t, "ds-top-req-cap")(),
+ "requiredCapability": "bar",
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ "BAD REQUEST when DELIVERY SERVICE ID EMPTY": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "requiredCapability": "bar",
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ "BAD REQUEST when REQUIRED CAPABILITY EMPTY": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "deliveryServiceID": GetDeliveryServiceId(t, "ds1")(),
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ "NOT FOUND when NON-EXISTENT REQUIRED CAPABILITY": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "deliveryServiceID": GetDeliveryServiceId(t, "ds1")(),
+ "requiredCapability": "bogus",
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusNotFound)),
+ },
+ "NOT FOUND when NON-EXISTENT DELIVERY SERVICE ID": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "deliveryServiceID": -1,
+ "requiredCapability": "foo",
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusNotFound)),
+ },
+ "BAD REQUEST when INVALID DELIVERY SERVICE TYPE": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "deliveryServiceID": GetDeliveryServiceId(t, "anymap-ds")(),
+ "requiredCapability": "foo",
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ },
+ "DELETE": {
+ "OK when VALID request": {
+ EndpointId: GetDeliveryServiceId(t, "ds-top-req-cap"), ClientSession: TOSession,
+ RequestBody: map[string]interface{}{"requiredCapability": "ram"},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ "NOT FOUND when NON-EXISTENT DELIVERYSERVICEID parameter": {
+ EndpointId: func() int { return -1 }, ClientSession: TOSession,
+ RequestBody: map[string]interface{}{"requiredCapability": "foo"},
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusNotFound)),
+ },
+ "NOT FOUND when NON-EXISTENT REQUIREDCAPABILITY parameter": {
+ EndpointId: GetDeliveryServiceId(t, "ds1"), ClientSession: TOSession,
+ RequestBody: map[string]interface{}{"requiredCapability": "bogus"},
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusNotFound)),
+ },
+ },
+ "GET AFTER CHANGES": {
+ "OK when CHANGES made": {
+ ClientSession: TOSession, RequestHeaders: http.Header{rfc.IfModifiedSince: {currentTimeRFC}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
},
- },
- {
- description: fmt.Sprintf("get all deliveryservices required capabilities by xmlID: %s", *data[0].XMLID),
- capability: tc.DeliveryServicesRequiredCapability{
- XMLID: data[0].XMLID,
- },
- },
- {
- description: fmt.Sprintf("get all deliveryservices required capabilities by requiredCapability: %s", *data[0].RequiredCapability),
- capability: tc.DeliveryServicesRequiredCapability{
- RequiredCapability: data[0].RequiredCapability,
- },
- },
- }
+ }
- for _, tc := range testCases {
- t.Run(tc.description, func(t *testing.T) {
- _, reqInf, err := TOSession.GetDeliveryServicesRequiredCapabilitiesWithHdr(tc.capability.DeliveryServiceID, tc.capability.XMLID, tc.capability.RequiredCapability, header)
- if err != nil {
- t.Fatalf("Expected no error, but got %v", err.Error())
- }
- if reqInf.StatusCode != http.StatusOK {
- t.Fatalf("Expected 200 status code, got %v", reqInf.StatusCode)
- }
- })
- }
- currentTime := time.Now().UTC()
- currentTime = currentTime.Add(1 * time.Second)
- timeStr := currentTime.Format(time.RFC1123)
- header.Set(rfc.IfModifiedSince, timeStr)
- for _, tc := range testCases {
- t.Run(tc.description, func(t *testing.T) {
- _, reqInf, err := TOSession.GetDeliveryServicesRequiredCapabilitiesWithHdr(tc.capability.DeliveryServiceID, tc.capability.XMLID, tc.capability.RequiredCapability, header)
- if err != nil {
- t.Fatalf("Expected no error, but got %v", err.Error())
- }
- if reqInf.StatusCode != http.StatusNotModified {
- t.Fatalf("Expected 304 status code, got %v", reqInf.StatusCode)
- }
- })
- }
-}
+ for method, testCases := range methodTests {
+ t.Run(method, func(t *testing.T) {
+ for name, testCase := range testCases {
+ dsrc := tc.DeliveryServicesRequiredCapability{}
-func GetTestDeliveryServicesRequiredCapabilities(t *testing.T) {
- data := testData.DeliveryServicesRequiredCapabilities
- ds1 := helperGetDeliveryServiceID(t, data[0].XMLID)
+ var deliveryServiceId *int
+ var xmlId *string
+ var capability *string
- testCases := []struct {
- description string
- capability tc.DeliveryServicesRequiredCapability
- expectFunc func(tc.DeliveryServicesRequiredCapability, []tc.DeliveryServicesRequiredCapability)
- }{
- {
- description: "get all deliveryservices required capabilities",
- expectFunc: func(expect tc.DeliveryServicesRequiredCapability, actual []tc.DeliveryServicesRequiredCapability) {
- if len(actual) != len(testData.DeliveryServicesRequiredCapabilities) {
- t.Errorf("expected length: %d, actual: %d", len(testData.DeliveryServicesRequiredCapabilities), len(actual))
- }
- },
- },
- {
- description: fmt.Sprintf("get all deliveryservices required capabilities by deliveryServiceID: %d", *ds1),
- capability: tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: ds1,
- },
- expectFunc: func(dsRequiredCapability tc.DeliveryServicesRequiredCapability, dsReqCaps []tc.DeliveryServicesRequiredCapability) {
- for _, dsrc := range dsReqCaps {
- if *dsrc.DeliveryServiceID != *dsRequiredCapability.DeliveryServiceID {
- t.Errorf("expected: all delivery service IDs to equal %d, actual: found %d", *dsRequiredCapability.DeliveryServiceID, *dsrc.DeliveryServiceID)
+ if val, ok := testCase.RequestParams["deliveryServiceId"]; ok {
+ if _, err := strconv.Atoi(val[0]); err != nil {
+ dsId := GetDeliveryServiceId(t, val[0])()
+ deliveryServiceId = &dsId
+ }
}
- }
- },
- },
- {
- description: fmt.Sprintf("get all deliveryservices required capabilities by xmlID: %s", *data[0].XMLID),
- capability: tc.DeliveryServicesRequiredCapability{
- XMLID: data[0].XMLID,
- },
- expectFunc: func(dsRequiredCapability tc.DeliveryServicesRequiredCapability, dsReqCaps []tc.DeliveryServicesRequiredCapability) {
- for _, dsrc := range dsReqCaps {
- if *dsrc.XMLID != *dsRequiredCapability.XMLID {
- t.Errorf("expected: all delivery service XMLIDs to equal %s, actual: found %s", *dsRequiredCapability.XMLID, *dsrc.XMLID)
+ if val, ok := testCase.RequestParams["xmlID"]; ok {
+ xmlId = &val[0]
}
- }
- },
- },
- {
- description: fmt.Sprintf("get all deliveryservices required capabilities by requiredCapability: %s", *data[0].RequiredCapability),
- capability: tc.DeliveryServicesRequiredCapability{
- RequiredCapability: data[0].RequiredCapability,
- },
- expectFunc: func(dsRequiredCapability tc.DeliveryServicesRequiredCapability, dsReqCaps []tc.DeliveryServicesRequiredCapability) {
- for _, dsrc := range dsReqCaps {
- if *dsrc.RequiredCapability != *dsRequiredCapability.RequiredCapability {
- t.Errorf("expected: all delivery service required capabilities to equal %s, actual: found %s", *dsRequiredCapability.RequiredCapability, *dsrc.RequiredCapability)
+ if val, ok := testCase.RequestParams["requiredCapability"]; ok {
+ capability = &val[0]
}
- }
- },
- },
- }
- for _, tc := range testCases {
- t.Run(tc.description, func(t *testing.T) {
- capabilities, _, err := TOSession.GetDeliveryServicesRequiredCapabilitiesWithHdr(tc.capability.DeliveryServiceID, tc.capability.XMLID, tc.capability.RequiredCapability, nil)
- if err != nil {
- t.Fatalf("%s; got err= %v; expected err= nil", tc.description, err)
- }
- tc.expectFunc(tc.capability, capabilities)
- })
- }
-}
-
-func GetTestDeliveryServicesRequiredCapabilitiesIMS(t *testing.T) {
- var header http.Header
- header = make(map[string][]string)
- futureTime := time.Now().AddDate(0, 0, 1)
- time := futureTime.Format(time.RFC1123)
- header.Set(rfc.IfModifiedSince, time)
- data := testData.DeliveryServicesRequiredCapabilities
- ds1 := helperGetDeliveryServiceID(t, data[0].XMLID)
+ if testCase.RequestBody != nil {
+ dat, err := json.Marshal(testCase.RequestBody)
+ assert.NoError(t, err, "Error occurred when marshalling request body: %v", err)
+ err = json.Unmarshal(dat, &dsrc)
+ assert.NoError(t, err, "Error occurred when unmarshalling request body: %v", err)
+ }
- testCases := []struct {
- description string
- capability tc.DeliveryServicesRequiredCapability
- }{
- {
- description: "get all deliveryservices required capabilities",
- },
- {
- description: fmt.Sprintf("get all deliveryservices required capabilities by deliveryServiceID: %d", *ds1),
- capability: tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: ds1,
- },
- },
- {
- description: fmt.Sprintf("get all deliveryservices required capabilities by xmlID: %s", *data[0].XMLID),
- capability: tc.DeliveryServicesRequiredCapability{
- XMLID: data[0].XMLID,
- },
- },
- {
- description: fmt.Sprintf("get all deliveryservices required capabilities by requiredCapability: %s", *data[0].RequiredCapability),
- capability: tc.DeliveryServicesRequiredCapability{
- RequiredCapability: data[0].RequiredCapability,
- },
- },
- }
+ switch method {
+ case "GET", "GET AFTER CHANGES":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.GetDeliveryServicesRequiredCapabilitiesWithHdr(deliveryServiceId, xmlId, capability, testCase.RequestHeaders)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, resp, tc.Alerts{}, err)
+ }
+ })
+ case "POST":
+ t.Run(name, func(t *testing.T) {
+ alerts, reqInf, err := testCase.ClientSession.CreateDeliveryServicesRequiredCapability(dsrc)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, nil, alerts, err)
+ }
+ })
+ case "DELETE":
+ t.Run(name, func(t *testing.T) {
+ alerts, reqInf, err := testCase.ClientSession.DeleteDeliveryServicesRequiredCapability(testCase.EndpointId(), testCase.RequestBody["requiredCapability"].(string))
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, nil, alerts, err)
+ }
+ })
+ }
+ }
+ })
+ }
+ })
- for _, tc := range testCases {
- t.Run(tc.description, func(t *testing.T) {
- _, reqInf, err := TOSession.GetDeliveryServicesRequiredCapabilitiesWithHdr(tc.capability.DeliveryServiceID, tc.capability.XMLID, tc.capability.RequiredCapability, header)
- if err != nil {
- t.Fatalf("Expected no error, but got %v", err.Error())
- }
- if reqInf.StatusCode != http.StatusNotModified {
- t.Fatalf("Expected 304 status code, got %v", reqInf.StatusCode)
- }
- })
- }
}
-func CreateTestTopologyBasedDeliveryServicesRequiredCapabilities(t *testing.T) {
- for _, td := range testData.TopologyBasedDeliveryServicesRequiredCapabilities {
-
- c := tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: helperGetDeliveryServiceID(t, td.XMLID),
- RequiredCapability: td.RequiredCapability,
- }
-
- _, _, err := TOSession.CreateDeliveryServicesRequiredCapability(c)
- if err != nil {
- t.Fatalf("cannot create delivery service required capability: %v", err)
+func validateDSRCExpectedFields(expectedResp map[string]interface{}) utils.CkReqFunc {
+ return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, _ tc.Alerts, _ error) {
+ dsrcResp := resp.([]tc.DeliveryServicesRequiredCapability)
+ for field, expected := range expectedResp {
+ for _, dsrc := range dsrcResp {
+ switch field {
+ case "DeliveryServiceID":
+ assert.Equal(t, expected, *dsrc.DeliveryServiceID, "Expected deliveryServiceId to be %v, but got %v", expected, dsrc.DeliveryServiceID)
+ case "XMLID":
+ assert.Equal(t, expected, *dsrc.XMLID, "Expected xmlID to be %v, but got %v", expected, dsrc.XMLID)
+ case "RequiredCapability":
+ assert.Equal(t, expected, *dsrc.RequiredCapability, "Expected requiredCapability to be %v, but got %v", expected, dsrc.RequiredCapability)
+ }
+ }
}
}
-
- invalid := tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: helperGetDeliveryServiceID(t, util.StrPtr("ds-top-req-cap")),
- RequiredCapability: util.StrPtr("asdf"),
- }
- _, reqInf, err := TOSession.CreateDeliveryServicesRequiredCapability(invalid)
- if err == nil {
- t.Fatal("when adding delivery service required capability to a delivery service with a topology that " +
- "doesn't have cachegroups with at least one server with the required capabilities - expected: error, actual: nil")
- }
- if reqInf.StatusCode != http.StatusBadRequest {
- t.Fatalf("when adding delivery service required capability to a delivery service with a topology that "+
- "doesn't have cachegroups with at least one server with the required capabilities - expected status code: "+
- "%d, actual: %d", http.StatusBadRequest, reqInf.StatusCode)
- }
}
func CreateTestDeliveryServicesRequiredCapabilities(t *testing.T) {
- data := testData.DeliveryServicesRequiredCapabilities
- if len(data) == 0 {
- t.Fatal("there must be at least one test ds required capability defined")
- }
- ds1 := helperGetDeliveryServiceID(t, data[0].XMLID)
- amDS := helperGetDeliveryServiceID(t, util.StrPtr("anymap-ds"))
- testCases := []struct {
- description string
- capability tc.DeliveryServicesRequiredCapability
- }{
- {
- description: fmt.Sprintf("re-assign a deliveryservice to a required capability; deliveryServiceID: %d, requiredCapability: %s", *ds1, *data[0].RequiredCapability),
- capability: tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: ds1,
- RequiredCapability: data[0].RequiredCapability,
- },
- },
- {
- description: fmt.Sprintf("assign a deliveryservice to a required capability with no delivery service id; deliveryServiceID: 0, requiredCapability: %s", *data[0].RequiredCapability),
- capability: tc.DeliveryServicesRequiredCapability{
- RequiredCapability: data[0].RequiredCapability,
- },
- },
- {
- description: fmt.Sprintf("assign a deliveryservice to a required capability with no requiredCapability; deliveryServiceID: %d, requiredCapability: 0", *ds1),
- capability: tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: ds1,
- },
- },
- {
- description: fmt.Sprintf("assign a deliveryservice to a required capability with an invalid required capability; deliveryServiceID: %d, requiredCapability: bogus", *ds1),
- capability: tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: ds1,
- RequiredCapability: util.StrPtr("bogus"),
- },
- },
- {
- description: fmt.Sprintf("assign a deliveryservice to a required capability with an invalid delivery service id; deliveryServiceID: -1, requiredCapability: %s", *data[0].RequiredCapability),
- capability: tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: util.IntPtr(-1),
- RequiredCapability: data[0].RequiredCapability,
- },
- },
- {
- description: "assign a deliveryservice to a required capability with an invalid deliveryservice type",
- capability: tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: amDS,
- RequiredCapability: data[0].RequiredCapability,
- },
- },
- }
-
// Assign all required capability to delivery services listed in `tc-fixtures.json`.
- for _, td := range testData.DeliveryServicesRequiredCapabilities {
- var dsID int
- if td.DeliveryServiceID != nil {
- dsID = *td.DeliveryServiceID
+ for _, dsrc := range testData.DeliveryServicesRequiredCapabilities {
+ dsId := GetDeliveryServiceId(t, *dsrc.XMLID)()
+ dsrc = tc.DeliveryServicesRequiredCapability{
+ DeliveryServiceID: &dsId,
+ RequiredCapability: dsrc.RequiredCapability,
}
-
- var capability string
- if td.RequiredCapability != nil {
- capability = *td.RequiredCapability
- }
-
- t.Run(fmt.Sprintf("assign a deliveryservice to a required capability; deliveryServiceID: %d, requiredCapability: %s", dsID, capability), func(t *testing.T) {
- cap := tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: helperGetDeliveryServiceID(t, td.XMLID),
- RequiredCapability: td.RequiredCapability,
- }
-
- _, _, err := TOSession.CreateDeliveryServicesRequiredCapability(cap)
- if err != nil {
- t.Fatalf(err.Error())
- }
- })
- }
-
- for _, tc := range testCases {
- t.Run(tc.description, func(t *testing.T) {
- _, _, err := TOSession.CreateDeliveryServicesRequiredCapability(tc.capability)
- if err == nil {
- t.Fatalf("%s; expected err", tc.description)
- }
- })
+ resp, _, err := TOSession.CreateDeliveryServicesRequiredCapability(dsrc)
+ assert.NoError(t, err, "Unexpected error creating a Delivery Service/Required Capability relationship: %v - alerts: %+v", err, resp.Alerts)
}
}
-func InvalidDeliveryServicesRequiredCapabilityAddition(t *testing.T) {
- // Tests that a capability cannot be made required if the DS's services do not have it assigned
-
- // Get Delivery Capability for a DS
- capabilities, _, err := TOSession.GetDeliveryServicesRequiredCapabilitiesWithHdr(nil, util.StrPtr("ds1"), nil, nil)
- if err != nil {
- t.Fatalf("cannot GET delivery service required capabilities: %v", err)
- }
- if len(capabilities) == 0 {
- t.Fatal("delivery service ds1 needs at least one capability required")
- }
-
- // First assign current capabilities to edge server so we can assign it to the DS
- // TODO: DON'T hard-code hostnames!
- params := url.Values{}
- params.Add("hostName", "atlanta-edge-01")
- resp, _, err := TOSession.GetServersWithHdr(¶ms, nil)
- if err != nil {
- t.Fatalf("cannot GET Server by hostname: %v", err)
- }
- servers := resp.Response
- if len(servers) < 1 {
- t.Fatal("need at least one server to test invalid ds required capability assignment")
- }
-
- if servers[0].ID == nil {
- t.Fatal("server 'atlanta-edge-01' had nil ID")
- }
-
- dsID := capabilities[0].DeliveryServiceID
- sID := *servers[0].ID
- serverCaps := []tc.ServerServerCapability{}
-
- for _, cap := range capabilities {
- sCap := tc.ServerServerCapability{
- ServerID: &sID,
- ServerCapability: cap.RequiredCapability,
- }
- _, _, err := TOSession.CreateServerServerCapability(sCap)
- if err != nil {
- t.Errorf("could not POST the server capability %v to server %v: %v", *cap.RequiredCapability, sID, err)
- }
- serverCaps = append(serverCaps, sCap)
- }
-
- // Assign server to ds
- _, _, err = TOSession.CreateDeliveryServiceServers(*dsID, []int{sID}, false)
- if err != nil {
- t.Fatalf("cannot CREATE server delivery service assignement: %v", err)
- }
-
- // Create new bogus server capability
- _, _, err = TOSession.CreateServerCapability(tc.ServerCapability{
- Name: "newcap",
- })
- if err != nil {
- t.Fatalf("cannot CREATE newcap server capability: %v", err)
- }
-
- // Attempt to assign to DS should fail
- _, _, err = TOSession.CreateDeliveryServicesRequiredCapability(tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: dsID,
- RequiredCapability: util.StrPtr("newcap"),
- })
- if err == nil {
- t.Fatal("expected error requiring a capability that is not associated on the delivery service's servers")
- }
-
- // Disassociate server from DS
- setInactive(t, *dsID)
- _, _, err = TOSession.DeleteDeliveryServiceServer(*dsID, sID)
- if err != nil {
- t.Fatalf("could not DELETE the server %v from ds %v: %v", sID, *dsID, err)
- }
-
- // Remove server capabilities from server
- for _, ssc := range serverCaps {
- _, _, err := TOSession.DeleteServerServerCapability(*ssc.ServerID, *ssc.ServerCapability)
- if err != nil {
- t.Errorf("could not DELETE the server capability %v from server %v: %v", *ssc.ServerCapability, *ssc.Server, err)
- }
- }
-
- // Delete server capability
- _, _, err = TOSession.DeleteServerCapability("newcap")
- if err != nil {
- t.Fatalf("cannot DELETE newcap server capability: %v", err)
- }
-
-}
-
func DeleteTestDeliveryServicesRequiredCapabilities(t *testing.T) {
// Get Required Capabilities to delete them
- capabilities, _, err := TOSession.GetDeliveryServicesRequiredCapabilitiesWithHdr(nil, nil, nil, nil)
- if err != nil {
- t.Fatalf(err.Error())
- }
- if len(capabilities) < 1 {
- t.Fatal("no delivery services returned")
- }
-
- type testCase struct {
- description string
- capability tc.DeliveryServicesRequiredCapability
- err string
- }
-
- testCases := []testCase{
- testCase{
- description: fmt.Sprintf("delete a deliveryservices required capability with an invalid delivery service id; deliveryServiceID: -1, requiredCapability: %s", *capabilities[0].RequiredCapability),
- capability: tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: util.IntPtr(-1),
- RequiredCapability: capabilities[0].RequiredCapability,
- },
- err: "no deliveryservice.RequiredCapability with that key found",
- },
- testCase{
- description: fmt.Sprintf("delete a deliveryservices required capability with an invalid required capability; deliveryServiceID: %d, requiredCapability: bogus", *capabilities[0].DeliveryServiceID),
- capability: tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: capabilities[0].DeliveryServiceID,
- RequiredCapability: util.StrPtr("bogus"),
- },
- err: "no deliveryservice.RequiredCapability with that key found",
- },
- }
-
- for _, c := range capabilities {
- t := testCase{
- description: fmt.Sprintf("delete a deliveryservices required capability; deliveryServiceID: %d, requiredCapability: %s", *c.DeliveryServiceID, *c.RequiredCapability),
- capability: c,
- }
- testCases = append(testCases, t)
- }
-
- for _, c := range testCases {
- t.Run(c.description, func(t *testing.T) {
- _, _, err := TOSession.DeleteDeliveryServicesRequiredCapability(*c.capability.DeliveryServiceID, *c.capability.RequiredCapability)
- if err != nil && !strings.Contains(err.Error(), c.err) {
- t.Fatalf("%s; got err= %s; expected err= %s", c.description, err, c.err)
- }
- })
- }
-}
+ dsrcs, _, err := TOSession.GetDeliveryServicesRequiredCapabilitiesWithHdr(nil, nil, nil, nil)
+ assert.NoError(t, err, "Error getting Delivery Service/Required Capability relationships: %v - resp: %+v", err, dsrcs)
-func helperGetDeliveryServiceID(t *testing.T, xmlID *string) *int {
- t.Helper()
- if xmlID == nil {
- t.Fatal("xml id must not be nil")
- }
- ds, _, err := TOSession.GetDeliveryServiceByXMLIDNullableWithHdr(*xmlID, nil)
- if err != nil {
- t.Fatal(err)
- }
- if len(ds) < 1 {
- t.Fatalf("cannot GET deliveyservice by xml id: %v. Response did not include record.", *xmlID)
+ for _, dsrc := range dsrcs {
+ alerts, _, err := TOSession.DeleteDeliveryServicesRequiredCapability(*dsrc.DeliveryServiceID, *dsrc.RequiredCapability)
+ assert.NoError(t, err, "Error deleting a relationship between a Delivery Service and a Capability: %v - alerts: %+v", err, alerts.Alerts)
}
- return ds[0].ID
}
diff --git a/traffic_ops/testing/api/v3/deliveryservices_test.go b/traffic_ops/testing/api/v3/deliveryservices_test.go
index 58b679de45..7e9a6e5b85 100644
--- a/traffic_ops/testing/api/v3/deliveryservices_test.go
+++ b/traffic_ops/testing/api/v3/deliveryservices_test.go
@@ -31,7 +31,7 @@ import (
)
func TestDeliveryServices(t *testing.T) {
- WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, ServerCapabilities, DeliveryServices, DeliveryServicesRequiredCapabilities, DeliveryServiceServerAssignments}, func() {
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, ServerCapabilities, DeliveryServices, ServerServerCapabilities, DeliveryServicesRequiredCapabilities, DeliveryServiceServerAssignments}, func() {
tomorrow := time.Now().AddDate(0, 0, 1).Format(time.RFC1123)
currentTime := time.Now().UTC().Add(-15 * time.Second)
diff --git a/traffic_ops/testing/api/v3/deliveryserviceservers_test.go b/traffic_ops/testing/api/v3/deliveryserviceservers_test.go
index 3902350401..0e03f69839 100644
--- a/traffic_ops/testing/api/v3/deliveryserviceservers_test.go
+++ b/traffic_ops/testing/api/v3/deliveryserviceservers_test.go
@@ -16,633 +16,387 @@ package v3
*/
import (
- "errors"
+ "encoding/json"
"net/http"
"net/url"
"strconv"
- "strings"
"testing"
"time"
"github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
- "github.com/apache/trafficcontrol/lib/go-util"
"github.com/apache/trafficcontrol/traffic_ops/testing/api/assert"
+ "github.com/apache/trafficcontrol/traffic_ops/testing/api/utils"
)
func TestDeliveryServiceServers(t *testing.T) {
- WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, DeliveryServices}, func() {
- DeleteTestDeliveryServiceServers(t)
- AssignServersToTopologyBasedDeliveryService(t)
- AssignOriginsToTopologyBasedDeliveryServices(t)
- TryToRemoveLastServerInDeliveryService(t)
- AssignServersToNonTopologyBasedDeliveryServiceThatUsesMidTier(t)
- GetTestDSSIMS(t)
- })
-}
-
-func TestDeliveryServiceServersWithRequiredCapabilities(t *testing.T) {
- WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, ServerCapabilities, Topologies, DeliveryServices, DeliveryServicesRequiredCapabilities, ServerServerCapabilities}, func() {
- CreateTestDeliveryServiceServersWithRequiredCapabilities(t)
- CreateTestMSODSServerWithReqCap(t)
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, ServiceCategories, ServerCapabilities, DeliveryServices, ServerServerCapabilities, DeliveryServicesRequiredCapabilities, DeliveryServiceServerAssignments}, func() {
+
+ tomorrow := time.Now().UTC().AddDate(0, 0, 1).Format(time.RFC1123)
+
+ dssTests := utils.V3TestCase{
+ "GET": {
+ "NOT MODIFIED when NO CHANGES made": {
+ ClientSession: TOSession, RequestHeaders: http.Header{rfc.IfModifiedSince: {tomorrow}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusNotModified)),
+ },
+ "OK when VALID request": {
+ ClientSession: TOSession, Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ },
+ "POST": {
+ "OK when VALID request": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "dsId": GetDeliveryServiceId(t, "ds3")(),
+ "replace": true,
+ "servers": []int{getServerID(t, "atlanta-edge-01")(), getServerID(t, "atlanta-edge-03")()},
+ },
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ "OK when ASSIGNING ORG SERVER IN CACHEGROUP of TOPOLOGY DS": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "dsId": GetDeliveryServiceId(t, "ds-top")(),
+ "replace": true,
+ "servers": []int{getServerID(t, "denver-mso-org-01")()},
+ },
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ "BAD REQUEST when ASSIGNING ORG SERVER NOT IN CACHEGROUP of TOPOLOGY DS": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "dsId": GetDeliveryServiceId(t, "ds-top-req-cap")(),
+ "replace": true,
+ "servers": []int{getServerID(t, "denver-mso-org-01")()},
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ "BAD REQUEST when ASSIGNING SERVERS to a TOPOLOGY DS": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "dsId": GetDeliveryServiceId(t, "ds-top")(),
+ "servers": []int{getServerID(t, "atlanta-edge-01")(), getServerID(t, "atlanta-edge-03")()},
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ "CONFLICT when REMOVING ONLY EDGE SERVER ASSIGNMENT": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "dsId": GetDeliveryServiceId(t, "test-ds-server-assignments")(),
+ "replace": true,
+ "servers": []int{},
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusConflict)),
+ },
+ "CONFLICT when REPLACING EDGE SERVER ASSIGNMENT with EDGE SERVER in BAD STATE": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "dsId": GetDeliveryServiceId(t, "test-ds-server-assignments")(),
+ "replace": true,
+ "servers": []int{getServerID(t, "admin-down-server")()},
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusConflict)),
+ },
+ "OK when MAKING ASSIGNMENTS when DELIVERY SERVICE AND SERVER HAVE MATCHING CAPABILITIES": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "dsId": GetDeliveryServiceId(t, "ds2")(),
+ "replace": true,
+ "servers": []int{getServerID(t, "atlanta-org-2")()},
+ },
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ "OK when ASSIGNING a ORIGIN server to a DS with REQUIRED CAPABILITY": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "dsId": GetDeliveryServiceId(t, "msods1")(),
+ "replace": true,
+ "servers": []int{getServerID(t, "denver-mso-org-01")()},
+ },
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ },
+ "SERVER DELETE": {
+ "CONFLICT when DELETING SERVER when its the ONLY EDGE SERVER ASSIGNED": {
+ EndpointId: getServerID(t, "test-ds-server-assignments"), ClientSession: TOSession,
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusConflict)),
+ },
+ },
+ "SERVER STATUS PUT": {
+ "BAD REQUEST when UPDATING SERVER STATUS when ONLY EDGE SERVER ASSIGNED": {
+ EndpointId: getServerID(t, "test-ds-server-assignments"), ClientSession: TOSession,
+ RequestBody: map[string]interface{}{
+ "status": "ADMIN_DOWN",
+ "offlineReason": "admin down",
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusConflict)),
+ },
+ },
+ }
+ for method, testCases := range dssTests {
+ t.Run(method, func(t *testing.T) {
+ for name, testCase := range testCases {
+ var dsID int
+ var replace bool
+ var serverIDs []int
+ status := tc.ServerPutStatus{}
+
+ if testCase.RequestBody != nil {
+ if val, ok := testCase.RequestBody["dsId"]; ok {
+ dsID = val.(int)
+ }
+ if val, ok := testCase.RequestBody["replace"]; ok {
+ replace = val.(bool)
+ }
+ if val, ok := testCase.RequestBody["servers"]; ok {
+ serverIDs = val.([]int)
+ }
+ if _, ok := testCase.RequestBody["offlineReason"]; ok {
+ dat, err := json.Marshal(testCase.RequestBody)
+ assert.NoError(t, err, "Error occurred when marshalling request body: %v", err)
+ err = json.Unmarshal(dat, &status)
+ assert.NoError(t, err, "Error occurred when unmarshalling request body: %v", err)
+ }
+ }
+
+ switch method {
+ case "GET":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.GetDeliveryServiceServersWithHdr(testCase.RequestHeaders)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, resp.Response, resp.Alerts, err)
+ }
+ })
+ case "POST":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.CreateDeliveryServiceServers(dsID, serverIDs, replace)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, resp, tc.Alerts{}, err)
+ }
+ })
+ case "SERVER DELETE":
+ t.Run(name, func(t *testing.T) {
+ alerts, reqInf, err := testCase.ClientSession.DeleteServerByID(testCase.EndpointId())
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, nil, alerts, err)
+ }
+ })
+ case "SERVER STATUS PUT":
+ t.Run(name, func(t *testing.T) {
+ _, reqInf, err := testCase.ClientSession.UpdateServerStatus(testCase.EndpointId(), status)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, nil, tc.Alerts{}, err)
+ }
+ })
+ }
+ }
+ })
+ }
})
}
-const dssaTestingXMLID = "test-ds-server-assignments"
-
-func TryToRemoveLastServerInDeliveryService(t *testing.T) {
- dses, _, err := TOSession.GetDeliveryServiceByXMLIDNullableWithHdr(dssaTestingXMLID, nil)
- if err != nil {
- t.Fatalf("Unexpected error trying to get Delivery service with XMLID '%s': %v", dssaTestingXMLID, err)
- }
- if len(dses) != 1 {
- t.Fatalf("Expected exactly one Delivery service with XMLID '%s', got: %d", dssaTestingXMLID, len(dses))
- }
- ds := dses[0]
- if ds.ID == nil {
- t.Fatalf("Delivery Service '%s' has no ID", dssaTestingXMLID)
- }
-
- statuses, _, err := TOSession.GetStatusesWithHdr(nil)
- if err != nil {
- t.Fatalf("Could not fetch Statuses: %v", err)
- }
- if len(statuses) < 1 {
- t.Fatal("Need at least one Status")
- }
-
- var badStatusID int
- found := false
- for _, status := range statuses {
- if status.Name != tc.CacheStatusOnline.String() && status.Name != tc.CacheStatusReported.String() {
- badStatusID = status.ID
- found = true
- break
+func TestDeliveryServiceXMLIDServers(t *testing.T) {
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, ServiceCategories, DeliveryServices, DeliveryServiceServerAssignments}, func() {
+ dsXMLIDServersTests := utils.V3TestCase{
+ "POST": {
+ "BAD REQUEST when ASSIGNING SERVERS to a TOPOLOGY DS": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "xmlID": "ds-top",
+ "serverNames": []string{"atlanta-edge-01", "atlanta-edge-03"},
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ "BAD REQUEST when ASSIGNING ORG SERVER NOT IN CACHEGROUP of TOPOLOGY DS": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "xmlID": "ds-top-req-cap",
+ "serverNames": []string{"denver-mso-org-01"},
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ },
+ }
+ for method, testCases := range dsXMLIDServersTests {
+ t.Run(method, func(t *testing.T) {
+ for name, testCase := range testCases {
+ var xmlID string
+ var servers []string
+
+ if testCase.RequestBody != nil {
+ if val, ok := testCase.RequestBody["xmlID"]; ok {
+ xmlID = val.(string)
+ }
+ if val, ok := testCase.RequestBody["serverNames"]; ok {
+ servers = val.([]string)
+ }
+ }
+
+ switch method {
+ case "POST":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.AssignServersToDeliveryService(servers, xmlID)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, nil, resp, err)
+ }
+ })
+ }
+ }
+ })
}
- }
- if !found {
- t.Fatalf("Need at least one status with a name other than '%s' or '%s'", tc.CacheStatusOnline, tc.CacheStatusReported)
- }
-
- // TODO: this isn't sufficient to define a single server, so there might be
- // a better way to do this.
- params := url.Values{}
- params.Set("hostName", dssaTestingXMLID)
- params.Set("domainName", dssaTestingXMLID)
- servers, _, err := TOSession.GetServersWithHdr(¶ms, nil)
- if err != nil {
- t.Fatalf("Unexpected error fetching server '%s.%s': %v", dssaTestingXMLID, dssaTestingXMLID, err)
- }
- if len(servers.Response) != 1 {
- t.Fatalf("Expected exactly one server with FQDN '%s.%s', got: %d", dssaTestingXMLID, dssaTestingXMLID, len(servers.Response))
- }
- server := servers.Response[0]
- if server.ID == nil {
- t.Fatal("Server had null/undefined ID after creation")
- }
-
- _, _, err = TOSession.CreateDeliveryServiceServers(*ds.ID, []int{*server.ID}, true)
- if err != nil {
- t.Fatalf("Failed to assign server to Delivery Service: %v", err)
- }
-
- _, _, err = TOSession.CreateDeliveryServiceServers(*ds.ID, []int{}, true)
- if err == nil {
- t.Error("Didn't get expected error trying to remove the only server assigned to a Delivery Service")
- } else {
- t.Logf("Got expected error trying to remove the only server assigned to a Delivery Service: %v", err)
- }
-
- _, _, err = TOSession.DeleteDeliveryServiceServer(*ds.ID, *server.ID)
- if err == nil {
- t.Error("Didn't get expected error trying to remove the only server assigned to a Delivery Service")
- } else {
- t.Logf("Got expected error trying to remove the only server assigned to a Delivery Service: %v", err)
- }
-
- alerts, _, err := TOSession.DeleteServerByID(*server.ID)
- t.Logf("Alerts from deleting server: %s", strings.Join(alerts.ToStrings(), ", "))
- if err == nil {
- t.Error("Didn't get expected error trying to delete the only server assigned to a Delivery Service")
- } else {
- t.Logf("Got expected error trying to delete the only server assigned to a Delivery Service: %v", err)
- }
-
- alerts, _, err = TOSession.AssignDeliveryServiceIDsToServerID(*server.ID, []int{}, true)
- t.Logf("Alerts from removing Delivery Service from server: %s", strings.Join(alerts.ToStrings(), ", "))
- if err == nil {
- t.Error("Didn't get expected error trying to remove a Delivery Service from the only server to which it is assigned")
- } else {
- t.Logf("Got expected error trying to remove a Delivery Service from the only server to which it is assigned: %v", err)
- }
-
- server.StatusID = &badStatusID
- putRequest := tc.ServerPutStatus{
- Status: util.JSONNameOrIDStr{ID: &badStatusID},
- OfflineReason: util.StrPtr("test"),
- }
- alertsPtr, _, err := TOSession.UpdateServerStatus(*server.ID, putRequest)
- if alertsPtr != nil {
- t.Logf("Alerts from updating server status: %s", strings.Join(alertsPtr.ToStrings(), ", "))
- }
- if err == nil {
- t.Error("Didn't get expected error trying to put server into a bad state when it's the only one assigned to a Delivery Service")
- } else {
- t.Logf("Got expected error trying to put server into a bad state when it's the only one assigned to a Delivery Service: %v", err)
- }
-
- alerts, _, err = TOSession.UpdateServerByIDWithHdr(*server.ID, server, nil)
- t.Logf("Alerts from updating server status: %s", strings.Join(alerts.ToStrings(), ", "))
- if err == nil {
- t.Error("Didn't get expected error trying to put server into a bad state when it's the only one assigned to a Delivery Service")
- } else {
- t.Logf("Got expected error trying to put server into a bad state when it's the only one assigned to a Delivery Service: %v", err)
- }
-
- server.HostName = util.StrPtr(dssaTestingXMLID + "-quest")
- server.ID = nil
- if len(server.Interfaces) == 0 {
- t.Fatal("no interfaces in this server, quitting")
- }
- interfaces := make([]tc.ServerInterfaceInfo, 0)
- ipAddresses := make([]tc.ServerIPAddress, 0)
- gateway := "1.2.3.4"
- ipAddresses = append(ipAddresses, tc.ServerIPAddress{
- Address: "1.1.1.1",
- Gateway: &gateway,
- ServiceAddress: true,
- })
- interfaces = append(interfaces, tc.ServerInterfaceInfo{
- IPAddresses: ipAddresses,
- MaxBandwidth: server.Interfaces[0].MaxBandwidth,
- Monitor: false,
- MTU: server.Interfaces[0].MTU,
- Name: server.Interfaces[0].Name,
})
- server.Interfaces = interfaces
- alerts, _, err = TOSession.CreateServerWithHdr(server, nil)
- if err != nil {
- t.Fatalf("Failed to create server: %v - alerts: %s", err, strings.Join(alerts.ToStrings(), ", "))
- }
- params.Set("hostName", *server.HostName)
- servers, _, err = TOSession.GetServersWithHdr(¶ms, nil)
- if err != nil {
- t.Fatalf("Could not fetch server after creation: %v", err)
- }
- if len(servers.Response) != 1 {
- t.Fatalf("Expected exactly 1 server with hostname '%s'; got: %d", *server.HostName, len(servers.Response))
- }
- server = servers.Response[0]
- if server.ID == nil {
- t.Fatal("Server had null/undefined ID after creation")
- }
-
- _, _, err = TOSession.CreateDeliveryServiceServers(*ds.ID, []int{*server.ID}, true)
- if err == nil {
- t.Error("Didn't get expected error trying to replace the last server assigned to a Delivery Service with a server in a bad state")
- } else {
- t.Logf("Got expected error trying to replace the last server assigned to a Delivery Service with a server in a bad state: %v", err)
- }
-
- // Cleanup
- setInactive(t, *ds.ID)
- alerts, _, err = TOSession.DeleteServerByID(*server.ID)
- t.Logf("Alerts from deleting a server: %s", strings.Join(alerts.ToStrings(), ", "))
- if err != nil {
- t.Errorf("Failed to delete server: %v", err)
- }
}
-func AssignServersToTopologyBasedDeliveryService(t *testing.T) {
- params := url.Values{}
- params.Set("xmlId", "ds-top")
- ds, _, err := TOSession.GetDeliveryServicesV30WithHdr(nil, params)
- if err != nil {
- t.Fatalf("cannot GET delivery service 'ds-top': %s", err.Error())
- }
- if len(ds) != 1 {
- t.Fatalf("expected one delivery service: 'ds-top', actual: %v", len(ds))
- }
- if ds[0].Topology == nil {
- t.Fatal("expected delivery service: 'ds-top' to have a non-nil Topology, actual: nil")
- }
- serversResp, _, err := TOSession.GetServersWithHdr(nil, nil)
- servers := []tc.ServerV30{}
- for _, s := range serversResp.Response {
- if s.CDNID != nil && *s.CDNID == *ds[0].CDNID && s.Type == tc.CacheTypeEdge.String() {
- servers = append(servers, s)
+func TestDeliveryServicesIDServers(t *testing.T) {
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, ServiceCategories, DeliveryServices, DeliveryServiceServerAssignments}, func() {
+ dsIDServersTests := utils.V3TestCase{
+ "GET": {
+ "OK when VALID request": {
+ EndpointId: GetDeliveryServiceId(t, "test-ds-server-assignments"), ClientSession: TOSession,
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
+ utils.ResponseHasLength(1)),
+ },
+ },
}
- }
- if len(servers) < 1 {
- t.Fatalf("expected: at least one EDGE in cdn %s, actual: %v", *ds[0].CDNName, servers)
- }
- serverNames := []string{}
- for _, s := range servers {
- if s.CDNID != nil && *s.CDNID == *ds[0].CDNID && s.Type == tc.CacheTypeEdge.String() {
- serverNames = append(serverNames, *s.HostName)
- } else {
- t.Fatalf("expected only EDGE servers in cdn '%s', actual: %v", *ds[0].CDNName, servers)
+ for method, testCases := range dsIDServersTests {
+ t.Run(method, func(t *testing.T) {
+ for name, testCase := range testCases {
+ switch method {
+ case "GET":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.GetServersByDeliveryService(testCase.EndpointId())
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, resp.Response, resp.Alerts, err)
+ }
+ })
+ }
+ }
+ })
}
- }
- _, reqInf, err := TOSession.AssignServersToDeliveryService(serverNames, "ds-top")
- if err == nil {
- t.Fatal("assigning servers to topology-based delivery service - expected: error, actual: nil error")
- }
- if reqInf.StatusCode < http.StatusBadRequest || reqInf.StatusCode >= http.StatusInternalServerError {
- t.Fatalf("assigning servers to topology-based delivery service - expected: 400-level status code, actual: %d", reqInf.StatusCode)
- }
-
- _, reqInf, err = TOSession.CreateDeliveryServiceServers(*ds[0].ID, []int{*servers[0].ID}, false)
- if err == nil {
- t.Fatal("creating deliveryserviceserver assignment for topology-based delivery service - expected: error, actual: nil error")
- }
- if reqInf.StatusCode < http.StatusBadRequest || reqInf.StatusCode >= http.StatusInternalServerError {
- t.Fatalf("creating deliveryserviceserver assignment for topology-based delivery service - expected: 400-level status code, actual: %d", reqInf.StatusCode)
- }
-}
-
-func AssignOriginsToTopologyBasedDeliveryServices(t *testing.T) {
- // attempt to assign ORG server to a topology-based DS while the ORG server's cachegroup doesn't belong to the topology
- params := url.Values{}
- params.Add("hostName", "denver-mso-org-01")
- resp, _, err := TOSession.GetServersWithHdr(¶ms, nil)
- if err != nil {
- t.Fatalf("unable to GET server: %v", err)
- }
- if len(resp.Response) != 1 {
- t.Fatalf("GET server expected length: 1, actual: %d", len(resp.Response))
- }
- orgServer := resp.Response[0]
- _, reqInf, err := TOSession.AssignServersToDeliveryService([]string{*orgServer.HostName}, "ds-top-req-cap")
- if err == nil {
- t.Fatal("assigning ORG server to topology-based delivery service while the ORG server's cachegroup does not belong to the topology - expected: error, actual: nil error")
- }
- if reqInf.StatusCode < http.StatusBadRequest || reqInf.StatusCode >= http.StatusInternalServerError {
- t.Fatalf("assigning ORG server to topology-based delivery service while the ORG server's cachegroup does not belong to the topology - expected: 400-level status code, actual: %d", reqInf.StatusCode)
- }
- params = url.Values{}
- params.Set("xmlId", "ds-top-req-cap")
- ds, _, err := TOSession.GetDeliveryServicesV30WithHdr(nil, params)
- if err != nil {
- t.Fatalf("cannot GET delivery service 'ds-top-req-cap': %s", err.Error())
- }
- if len(ds) != 1 {
- t.Fatalf("expected one delivery service: 'ds-top-req-cap', actual: %v", len(ds))
- }
- if ds[0].Topology == nil {
- t.Fatal("expected delivery service: 'ds-top-req-cap' to have a non-nil Topology, actual: nil")
- }
- _, reqInf, err = TOSession.CreateDeliveryServiceServers(*ds[0].ID, []int{*orgServer.ID}, false)
- if err == nil {
- t.Fatal("creating deliveryserviceserver assignment for ORG server to topology-based delivery service while the ORG server's cachegroup does not belong to the topology - expected: error, actual: nil error")
- }
- if reqInf.StatusCode < http.StatusBadRequest || reqInf.StatusCode >= http.StatusInternalServerError {
- t.Fatalf("creating deliveryserviceserver assignment for ORG server to topology-based delivery service while the ORG server's cachegroup does not belong to the topology - expected: 400-level status code, actual: %d", reqInf.StatusCode)
- }
-
- // attempt to assign ORG server to a topology-based DS while the ORG server's cachegroup belongs to the topology
- _, reqInf, err = TOSession.AssignServersToDeliveryService([]string{*orgServer.HostName}, "ds-top")
- if err != nil {
- t.Fatalf("assigning ORG server to topology-based delivery service while the ORG server's cachegroup belongs to the topology - expected: no error, actual: %v", err)
- }
- if reqInf.StatusCode < http.StatusOK || reqInf.StatusCode >= http.StatusMultipleChoices {
- t.Fatalf("assigning ORG server to topology-based delivery service while the ORG server's cachegroup belongs to the topology - expected: 200-level status code, actual: %d", reqInf.StatusCode)
- }
- params = url.Values{}
- params.Set("xmlId", "ds-top")
- ds, _, err = TOSession.GetDeliveryServicesV30WithHdr(nil, params)
- if err != nil {
- t.Fatalf("cannot GET delivery service 'ds-top': %s", err.Error())
- }
- if len(ds) != 1 {
- t.Fatalf("expected one delivery service: 'ds-top', actual: %v", len(ds))
- }
- if ds[0].Topology == nil {
- t.Fatal("expected delivery service: 'ds-top' to have a non-nil Topology, actual: nil")
- }
- _, reqInf, err = TOSession.CreateDeliveryServiceServers(*ds[0].ID, []int{*orgServer.ID}, true)
- if err != nil {
- t.Fatalf("creating deliveryserviceserver assignment for ORG server to topology-based delivery service while the ORG server's cachegroup belongs to the topology - expected: no error, actual: %v", err)
- }
- if reqInf.StatusCode < http.StatusOK || reqInf.StatusCode >= http.StatusMultipleChoices {
- t.Fatalf("creating deliveryserviceserver assignment for ORG server to topology-based delivery service while the ORG server's cachegroup belongs to the topology - expected: 200-level status code, actual: %d", reqInf.StatusCode)
- }
+ })
}
-func AssignServersToNonTopologyBasedDeliveryServiceThatUsesMidTier(t *testing.T) {
- params := url.Values{}
- params.Set("xmlId", "ds1")
- dsWithMid, _, err := TOSession.GetDeliveryServicesV30WithHdr(nil, params)
- if err != nil {
- t.Fatalf("cannot GET delivery service 'ds1': %s", err.Error())
- }
- if len(dsWithMid) != 1 {
- t.Fatalf("expected one delivery service: 'ds1', actual: %v", len(dsWithMid))
- }
- if dsWithMid[0].Topology != nil {
- t.Fatal("expected delivery service: 'ds1' to have a nil Topology, actual: non-nil")
- }
- serversResp, _, err := TOSession.GetServersWithHdr(nil, nil)
- if err != nil {
- t.Fatalf("unable to fetch all servers: %v", err)
- }
- serversIds := []int{}
- for _, s := range serversResp.Response {
- if s.CDNID != nil && *s.CDNID == *dsWithMid[0].CDNID && s.Type == tc.CacheTypeEdge.String() {
- serversIds = append(serversIds, *s.ID)
+func TestServersIDDeliveryServices(t *testing.T) {
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, ServiceCategories, DeliveryServices, DeliveryServiceServerAssignments}, func() {
+ serversIDDSTests := utils.V3TestCase{
+ "POST": {
+ "BAD REQUEST when REMOVING ONLY EDGE SERVER ASSIGNMENT": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "server": getServerID(t, "test-ds-server-assignments")(),
+ "dsIds": []int{GetDeliveryServiceId(t, "test-ds-server-assignments")()},
+ "replace": true,
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusConflict)),
+ },
+ },
}
- }
- if len(serversIds) < 1 {
- t.Fatalf("expected: at least one EDGE in cdn %s, actual: 0", *dsWithMid[0].CDNName)
- }
-
- _, _, err = TOSession.CreateDeliveryServiceServers(*dsWithMid[0].ID, serversIds, true)
- if err != nil {
- t.Fatalf("unable to create delivery service server associations: %v", err)
- }
-
- params = url.Values{"dsId": []string{strconv.Itoa(*dsWithMid[0].ID)}}
- dsServersResp, _, err := TOSession.GetServersWithHdr(¶ms, nil)
- if err != nil {
- t.Fatalf("unable to fetch delivery service servers: %v", err)
- }
- dsServerIds := []int{}
- for _, dss := range dsServersResp.Response {
- dsServerIds = append(dsServerIds, *dss.ID)
- }
- if len(dsServerIds) <= len(serversIds) {
- t.Fatalf("delivery service servers (%d) expected to exceed directly assigned servers (%d) to account for implicitly assigned mid servers", len(dsServerIds), len(serversIds))
- }
-
- for _, dss := range dsServersResp.Response {
- if dss.CDNID != nil && *dss.CDNID != *dsWithMid[0].CDNID {
- t.Fatalf("a server for another cdn was returned for this delivery service")
+ for method, testCases := range serversIDDSTests {
+ t.Run(method, func(t *testing.T) {
+ for name, testCase := range testCases {
+
+ var server int
+ var replace bool
+
+ if testCase.RequestBody != nil {
+ if val, ok := testCase.RequestBody["server"]; ok {
+ server = val.(int)
+ }
+ if val, ok := testCase.RequestBody["replace"]; ok {
+ replace = val.(bool)
+ }
+ }
+
+ switch method {
+ case "POST":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.AssignDeliveryServiceIDsToServerID(server, []int{}, replace)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, nil, resp, err)
+ }
+ })
+ }
+ }
+ })
}
- }
-}
-
-func GetTestDSSIMS(t *testing.T) {
- const noLimit = 999999
- _, reqInf, err := TOSession.GetDeliveryServiceServersWithLimitsWithHdr(noLimit, nil, nil, nil)
- if err != nil {
- t.Errorf("deliveryserviceservers expected: no error, actual: %v", err)
- } else if reqInf.StatusCode != http.StatusOK {
- t.Errorf("expected deliveryserviceservers response code %v, actual %v", http.StatusOK, reqInf.StatusCode)
- }
-
- reqHdr := http.Header{}
- reqHdr.Set(rfc.IfModifiedSince, time.Now().UTC().Add(2*time.Second).Format(time.RFC1123))
-
- _, reqInf, err = TOSession.GetDeliveryServiceServersWithLimitsWithHdr(noLimit, nil, nil, reqHdr)
- if err != nil {
- t.Errorf("deliveryserviceservers IMS request expected: no error, actual: %v", err)
- } else if reqInf.StatusCode != http.StatusNotModified {
- t.Errorf("expected deliveryserviceservers IMS response code %v, actual %v", http.StatusNotModified, reqInf.StatusCode)
- }
+ })
}
-func CreateTestDeliveryServiceServersWithRequiredCapabilities(t *testing.T) {
- sscs := testData.ServerServerCapabilities
-
- testCases := []struct {
- ds string
- serverName string
- ssc tc.ServerServerCapability
- description string
- err error
- capability tc.DeliveryServicesRequiredCapability
- }{
- {
- serverName: "atlanta-edge-01",
- description: "missing requirements for server -> DS assignment",
- err: errors.New("cannot be assigned to this delivery service"),
- ssc: sscs[0],
- capability: tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: helperGetDeliveryServiceID(t, util.StrPtr("ds-test-minor-versions")),
- RequiredCapability: sscs[1].ServerCapability,
- },
- },
- {
- serverName: "atlanta-mid-01",
- description: "successful server -> DS assignment",
- err: nil,
- ssc: sscs[1],
- capability: tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: helperGetDeliveryServiceID(t, util.StrPtr("ds3")),
- RequiredCapability: sscs[1].ServerCapability,
+func TestDeliveryServicesDSIDServerID(t *testing.T) {
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, ServiceCategories, DeliveryServices, DeliveryServiceServerAssignments}, func() {
+ dssDSIDServerIDTests := utils.V3TestCase{
+ "DELETE": {
+ "OK when VALID REQUEST": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "server": getServerID(t, "denver-mso-org-01")(),
+ "dsId": GetDeliveryServiceId(t, "ds-top")(),
+ },
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ "BAD REQUEST when REMOVING ONLY EDGE SERVER ASSIGNMENT": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "server": getServerID(t, "test-ds-server-assignments")(),
+ "dsId": GetDeliveryServiceId(t, "test-ds-server-assignments")(),
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusConflict)),
+ },
},
- },
- }
-
- for _, ctc := range testCases {
- t.Run(ctc.description, func(t *testing.T) {
- params := url.Values{}
- params.Add("hostName", ctc.serverName)
- resp, _, err := TOSession.GetServersWithHdr(¶ms, nil)
- if err != nil {
- t.Fatalf("cannot GET Server by hostname: %v", err)
- }
- servers := resp.Response
- server := servers[0]
- if server.ID == nil {
- t.Fatalf("server %s had nil ID", ctc.serverName)
- }
-
- _, _, err = TOSession.CreateDeliveryServicesRequiredCapability(ctc.capability)
- if err != nil {
- t.Fatalf("*POST delivery service required capability: %v", err)
- }
-
- ctc.ssc.ServerID = server.ID
- _, _, err = TOSession.CreateServerServerCapability(ctc.ssc)
- if err != nil {
- t.Fatalf("could not POST the server capability %v to server %v: %v", *ctc.ssc.ServerCapability, *ctc.ssc.Server, err)
- }
-
- _, _, got := TOSession.CreateDeliveryServiceServers(*ctc.capability.DeliveryServiceID, []int{*server.ID}, true)
- if (ctc.err == nil && got != nil) || (ctc.err != nil && !strings.Contains(got.Error(), ctc.err.Error())) {
- t.Fatalf("expected ctc.err to contain %v, got %v", ctc.err, got)
- }
-
- _, _, err = TOSession.DeleteDeliveryServicesRequiredCapability(*ctc.capability.DeliveryServiceID, *ctc.capability.RequiredCapability)
- if err != nil {
- t.Fatalf("*DELETE delivery service required capability: %v", err)
- }
- })
- }
-}
-
-func CreateTestMSODSServerWithReqCap(t *testing.T) {
- dsReqCap, _, err := TOSession.GetDeliveryServicesRequiredCapabilitiesWithHdr(nil, util.StrPtr("msods1"), nil, nil)
- if err != nil {
- t.Fatalf("GET delivery service required capabilites: %v", err)
- }
-
- if len(dsReqCap) == 0 {
- t.Fatal("no delivery service required capabilites found for ds msods1")
- }
-
- // Associate origin server to msods1 even though it does not have req cap
- // TODO: DON'T hard-code server hostnames!
- params := url.Values{}
- params.Add("hostName", "denver-mso-org-01")
- resp, _, err := TOSession.GetServersWithHdr(¶ms, nil)
- if err != nil {
- t.Fatalf("GET server denver-mso-org-01: %v", err)
- }
- servers := resp.Response
- if len(servers) != 1 {
- t.Fatal("expected 1 server with hostname denver-mso-org-01")
- }
-
- s := servers[0]
- if s.ID == nil {
- t.Fatal("server 'denver-mso-org-01' had nil ID")
- }
-
- // Make sure server has no caps to ensure test correctness
- sccs, _, err := TOSession.GetServerServerCapabilitiesWithHdr(s.ID, nil, nil, nil)
- if err != nil {
- t.Fatalf("GET server server capabilities for denver-mso-org-01: %v", err)
- }
- if len(sccs) != 0 {
- t.Fatal("expected 0 server server capabilities for server denver-mso-org-01")
- }
-
- // Is origin included in eligible servers even though it doesnt have required capability
- eServers, _, err := TOSession.GetDeliveryServicesEligibleWithHdr(*dsReqCap[0].DeliveryServiceID, nil)
- if err != nil {
- t.Fatalf("GET delivery service msods1 eligible servers: %v", err)
- }
- found := false
- for _, es := range eServers {
- if es.HostName != nil && *es.HostName == "denver-mso-org-01" {
- found = true
- break
}
- }
- if !found {
- t.Fatal("expected to find origin server denver-mso-org-01 to be in eligible server return even though it is missing a required capability")
- }
-
- if _, _, err = TOSession.CreateDeliveryServiceServers(*dsReqCap[0].DeliveryServiceID, []int{*s.ID}, true); err != nil {
- t.Fatalf("POST delivery service origin servers without capabilities: %v", err)
- }
-
- // Create new bogus server capability
- if _, _, err = TOSession.CreateServerCapability(tc.ServerCapability{Name: "newfun"}); err != nil {
- t.Fatalf("cannot CREATE newfun server capability: %v", err)
- }
-
- // Attempt to assign to DS should not fail
- if _, _, err = TOSession.CreateDeliveryServicesRequiredCapability(tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: dsReqCap[0].DeliveryServiceID,
- RequiredCapability: util.StrPtr("newfun"),
- }); err != nil {
- t.Fatalf("POST required capability newfun to ds msods1: %v", err)
- }
-
- // Remove required capablity
- if _, _, err = TOSession.DeleteDeliveryServicesRequiredCapability(*dsReqCap[0].DeliveryServiceID, "newfun"); err != nil {
- t.Fatalf("DELETE delivery service required capability: %v", err)
- }
+ for method, testCases := range dssDSIDServerIDTests {
+ t.Run(method, func(t *testing.T) {
+ for name, testCase := range testCases {
+ var dsID int
+ var serverId int
+
+ if testCase.RequestBody != nil {
+ if val, ok := testCase.RequestBody["server"]; ok {
+ serverId = val.(int)
+ }
+ if val, ok := testCase.RequestBody["dsId"]; ok {
+ dsID = val.(int)
+ }
+ }
+
+ switch method {
+ case "DELETE":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.DeleteDeliveryServiceServer(dsID, serverId)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, nil, resp, err)
+ }
+ })
+ }
+ }
+ })
+ }
+ })
+}
- // Delete server capability
- if _, _, err = TOSession.DeleteServerCapability("newfun"); err != nil {
- t.Fatalf("DELETE newfun server capability: %v", err)
+func getServerID(t *testing.T, hostName string) func() int {
+ return func() int {
+ params := url.Values{}
+ params.Add("hostName", hostName)
+ serversResp, _, err := TOSession.GetServersWithHdr(¶ms, nil)
+ assert.NoError(t, err, "Get Servers Request failed with error:", err)
+ assert.Equal(t, 1, len(serversResp.Response), "Expected response object length 1, but got %d", len(serversResp.Response))
+ assert.NotNil(t, serversResp.Response[0].ID, "Expected id to not be nil")
+ return *serversResp.Response[0].ID
}
}
func DeleteTestDeliveryServiceServers(t *testing.T) {
- ds, server := getServerAndDSofSameCDN(t)
- if server.ID == nil {
- t.Fatalf("Got a server with a nil ID: %+v", server)
- }
- if ds.ID == nil {
- t.Fatalf("Got a delivery service with a nil ID %+v", ds)
- }
- if ds.Active == nil {
- t.Fatalf("Got a Delivery Service with nil 'Active': %+v", ds)
- }
-
- _, _, err := TOSession.CreateDeliveryServiceServers(*ds.ID, []int{*server.ID}, true)
- if err != nil {
- t.Errorf("POST delivery service servers: %v", err)
- }
-
dsServers, _, err := TOSession.GetDeliveryServiceServersWithHdr(nil)
- if err != nil {
- t.Errorf("GET delivery service servers: %v", err)
- }
+ assert.NoError(t, err, "Unexpected error retrieving server-to-Delivery-Service assignments: %v - alerts: %+v", err, dsServers.Alerts)
- found := false
for _, dss := range dsServers.Response {
- if dss.DeliveryService != nil && *dss.DeliveryService == *ds.ID && dss.Server != nil && *dss.Server == *server.ID {
- found = true
- break
- }
- }
- if !found {
- t.Error("POST delivery service servers returned success, but ds-server not in GET")
+ // Retrieve Delivery Service in order to update its active field to false
+ params := url.Values{"id": {strconv.Itoa(*dss.DeliveryService)}}
+ getDS, _, err := TOSession.GetDeliveryServicesV30WithHdr(nil, params)
+ assert.NoError(t, err, "Error retrieving Delivery Service: %v - resp: %+v", err, getDS)
+ assert.Equal(t, 1, len(getDS), "Expected 1 Delivery Service.")
+ // Update active to false in order to remove the server assignment
+ active := false
+ getDS[0].Active = &active
+ updResp, _, err := TOSession.UpdateDeliveryServiceV30WithHdr(*dss.DeliveryService, getDS[0], nil)
+ assert.NoError(t, err, "Error updating Delivery Service: %v - resp: %+v", err, updResp)
+ assert.Equal(t, false, *updResp.Active, "Expected Delivery Service to be Inactive.")
+
+ alerts, _, err := TOSession.DeleteDeliveryServiceServer(*dss.DeliveryService, *dss.Server)
+ assert.NoError(t, err, "Unexpected error removing server-to-Delivery-Service assignments: %v - alerts: %+v", err, alerts.Alerts)
}
-
- if *ds.Active {
- *ds.Active = false
- _, _, err = TOSession.UpdateDeliveryServiceV30WithHdr(*ds.ID, ds, nil)
- if err != nil {
- t.Errorf("Setting Delivery Service #%d to inactive", *ds.ID)
- }
- }
-
- if _, _, err := TOSession.DeleteDeliveryServiceServer(*ds.ID, *server.ID); err != nil {
- t.Errorf("DELETE delivery service server: %v", err)
- }
-
dsServers, _, err = TOSession.GetDeliveryServiceServersWithHdr(nil)
- if err != nil {
- t.Errorf("GET delivery service servers: %v", err)
- }
-
- found = false
- for _, dss := range dsServers.Response {
- if dss.DeliveryService != nil && *dss.DeliveryService == *ds.ID && dss.Server != nil && *dss.Server == *server.ID {
- found = true
- break
- }
- }
- if found {
- t.Error("DELETE delivery service servers returned success, but still in GET")
- }
-}
-
-func getServerAndDSofSameCDN(t *testing.T) (tc.DeliveryServiceNullableV30, tc.ServerV30) {
- dses, _, err := TOSession.GetDeliveryServicesV30WithHdr(nil, nil)
- if err != nil {
- t.Fatalf("cannot GET DeliveryServices: %v", err)
- }
- if len(dses) < 1 {
- t.Fatal("GET DeliveryServices returned no dses, must have at least 1 to test ds-servers")
- }
-
- resp, _, err := TOSession.GetServersWithHdr(nil, nil)
- if err != nil {
- t.Fatalf("cannot GET Servers: %v", err)
- }
- servers := resp.Response
- if len(servers) < 1 {
- t.Fatal("GET Servers returned no dses, must have at least 1 to test ds-servers")
- }
-
- for _, ds := range dses {
- for _, s := range servers {
- if ds.CDNName != nil && s.CDNName != nil && *ds.CDNName == *s.CDNName {
- return ds, s
- }
- }
- }
- t.Fatal("expected at least one delivery service and server in the same CDN")
-
- return tc.DeliveryServiceNullableV30{}, tc.ServerV30{}
+ assert.NoError(t, err, "Unexpected error retrieving server-to-Delivery-Service assignments: %v - alerts: %+v", err, dsServers.Alerts)
+ assert.Equal(t, dsServers.Size, 0, "Expected all Delivery Service Server assignments to be deleted.")
}
func CreateTestDeliveryServiceServerAssignments(t *testing.T) {
diff --git a/traffic_ops/testing/api/v3/serverservercapability_test.go b/traffic_ops/testing/api/v3/serverservercapability_test.go
index f971f0d55d..b2b70484e8 100644
--- a/traffic_ops/testing/api/v3/serverservercapability_test.go
+++ b/traffic_ops/testing/api/v3/serverservercapability_test.go
@@ -29,16 +29,11 @@ import (
)
func TestServerServerCapabilities(t *testing.T) {
- WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, DeliveryServices, ServerCapabilities, DeliveryServicesRequiredCapabilities, ServerServerCapabilities}, func() {
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, DeliveryServices, ServerCapabilities, ServerServerCapabilities, DeliveryServicesRequiredCapabilities}, func() {
SortTestServerServerCapabilities(t)
GetTestServerServerCapabilitiesIMS(t)
GetTestServerServerCapabilities(t)
GetDeliveryServiceServersWithCapabilities(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)
})
}
@@ -278,9 +273,6 @@ func DeleteTestServerServerCapabilities(t *testing.T) {
})
assignedServers[*ssc.ServerID] = true
}
- if len(dsServers) == 0 {
- t.Fatalf("test requires at least one server with a capability that is required by at least one delivery service")
- }
// Delete should fail as their delivery services now require the capabilities
for _, ssc := range sscs {
diff --git a/traffic_ops/testing/api/v3/tc-fixtures.json b/traffic_ops/testing/api/v3/tc-fixtures.json
index 1c47bcf774..39c20b95ae 100644
--- a/traffic_ops/testing/api/v3/tc-fixtures.json
+++ b/traffic_ops/testing/api/v3/tc-fixtures.json
@@ -1566,12 +1566,28 @@
{
"xmlID": "msods1",
"RequiredCapability": "bar"
+ },
+ {
+ "xmlID": "ds-top-req-cap",
+ "RequiredCapability": "ram"
+ },
+ {
+ "xmlID": "ds-top-req-cap",
+ "RequiredCapability": "disk"
+ },
+ {
+ "xmlID": "ds-top-req-cap2",
+ "RequiredCapability": "ram"
}
],
"deliveryServiceServerAssignments": [
{
"xmlId": "ds-top",
"serverNames": ["denver-mso-org-01"]
+ },
+ {
+ "xmlId": "test-ds-server-assignments",
+ "serverNames": ["test-ds-server-assignments"]
}
],
"topologyBasedDeliveryServicesRequiredCapabilities": [
@@ -4630,6 +4646,55 @@
"updPending": false,
"xmppId": "atlanta-mid-02\\\\@ocdn.kabletown.net",
"xmppPasswd": "X"
+ },
+ {
+ "cachegroup": "cachegroup1",
+ "cdnName": "cdn1",
+ "domainName": "ga.atlanta.kabletown.net",
+ "guid": null,
+ "hostName": "admin-down-server",
+ "httpsPort": 443,
+ "iloIpAddress": "",
+ "iloIpGateway": "",
+ "iloIpNetmask": "",
+ "iloPassword": "",
+ "iloUsername": "",
+ "interfaces": [
+ {
+ "ipAddresses": [
+ {
+ "address": "127.0.0.22/30",
+ "gateway": "127.0.0.22",
+ "serviceAddress": true
+ },
+ {
+ "address": "2345:1234:13:8::1/64",
+ "gateway": "2345:1234:13:8::1",
+ "serviceAddress": false
+ }
+ ],
+ "maxBandwidth": null,
+ "monitor": true,
+ "mtu": 9000,
+ "name": "bond0",
+ "routerHostName": "router1",
+ "routerPort": "9000"
+ }
+ ],
+ "mgmtIpAddress": "",
+ "mgmtIpGateway": "",
+ "mgmtIpNetmask": "",
+ "offlineReason": null,
+ "physLocation": "Denver",
+ "profile": "EDGE1",
+ "rack": "RR 119.02",
+ "revalPending": false,
+ "status": "ADMIN_DOWN",
+ "tcpPort": 80,
+ "type": "EDGE",
+ "updPending": false,
+ "xmppId": "atlanta-edge-01\\\\@ocdn.kabletown.net",
+ "xmppPasswd": "X"
}
],
"serverCapabilities": [
diff --git a/traffic_ops/testing/api/v3/topologies_test.go b/traffic_ops/testing/api/v3/topologies_test.go
index d0da4c578a..da5b5ed66d 100644
--- a/traffic_ops/testing/api/v3/topologies_test.go
+++ b/traffic_ops/testing/api/v3/topologies_test.go
@@ -36,7 +36,7 @@ type topologyTestCase struct {
}
func TestTopologies(t *testing.T) {
- WithObjs(t, []TCObj{Types, CacheGroups, CDNs, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, Servers, ServerCapabilities, ServerServerCapabilitiesForTopologies, Topologies, Tenants, DeliveryServices, TopologyBasedDeliveryServiceRequiredCapabilities}, func() {
+ WithObjs(t, []TCObj{Types, CacheGroups, CDNs, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, Servers, ServerCapabilities, ServerServerCapabilitiesForTopologies, Topologies, Tenants, DeliveryServices, DeliveryServicesRequiredCapabilities}, func() {
GetTestTopologies(t)
UpdateTestTopologies(t)
ValidationTestTopologies(t)
@@ -58,7 +58,6 @@ func CreateTestTopologies(t *testing.T) {
if !reflect.DeepEqual(topology, postResponse.Response) {
t.Fatalf("Topology in response should be the same as the one POSTed. expected: %v\nactual: %v", topology, postResponse.Response)
}
- t.Log("Response: ", postResponse)
}
}
diff --git a/traffic_ops/testing/api/v3/withobjs_test.go b/traffic_ops/testing/api/v3/withobjs_test.go
index 905d5872b8..f13f2d51f5 100644
--- a/traffic_ops/testing/api/v3/withobjs_test.go
+++ b/traffic_ops/testing/api/v3/withobjs_test.go
@@ -76,7 +76,6 @@ const (
Tenants
ServerCheckExtensions
Topologies
- TopologyBasedDeliveryServiceRequiredCapabilities
Types
Users
)
@@ -122,7 +121,6 @@ var withFuncs = map[TCObj]TCObjFuncs{
Tenants: {CreateTestTenants, DeleteTestTenants},
ServerCheckExtensions: {CreateTestServerCheckExtensions, DeleteTestServerCheckExtensions},
Topologies: {CreateTestTopologies, DeleteTestTopologies},
- TopologyBasedDeliveryServiceRequiredCapabilities: {CreateTestTopologyBasedDeliveryServicesRequiredCapabilities, DeleteTestDeliveryServicesRequiredCapabilities},
- Types: {CreateTestTypes, DeleteTestTypes},
- Users: {CreateTestUsers, ForceDeleteTestUsers},
+ Types: {CreateTestTypes, DeleteTestTypes},
+ Users: {CreateTestUsers, ForceDeleteTestUsers},
}
diff --git a/traffic_ops/testing/api/v4/deliveryservices_required_capabilities_test.go b/traffic_ops/testing/api/v4/deliveryservices_required_capabilities_test.go
index 1e304ef4b8..fa10faa669 100644
--- a/traffic_ops/testing/api/v4/deliveryservices_required_capabilities_test.go
+++ b/traffic_ops/testing/api/v4/deliveryservices_required_capabilities_test.go
@@ -16,702 +16,270 @@ package v4
*/
import (
- "fmt"
+ "encoding/json"
"net/http"
"net/url"
- "reflect"
"strconv"
- "strings"
"testing"
"time"
"github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
- "github.com/apache/trafficcontrol/lib/go-util"
+ "github.com/apache/trafficcontrol/traffic_ops/testing/api/assert"
+ "github.com/apache/trafficcontrol/traffic_ops/testing/api/utils"
+ "github.com/apache/trafficcontrol/traffic_ops/toclientlib"
client "github.com/apache/trafficcontrol/traffic_ops/v4-client"
)
func TestDeliveryServicesRequiredCapabilities(t *testing.T) {
- WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, ServerCapabilities, Topologies, ServiceCategories, DeliveryServices, DeliveryServicesRequiredCapabilities}, func() {
- GetTestDeliveryServicesRequiredCapabilitiesIMS(t)
- InvalidDeliveryServicesRequiredCapabilityAddition(t)
- GetTestDeliveryServicesRequiredCapabilities(t)
- currentTime := time.Now().UTC().Add(-5 * time.Second)
- time := currentTime.Format(time.RFC1123)
- var header http.Header
- header = make(map[string][]string)
- header.Set(rfc.IfModifiedSince, time)
- GetTestDeliveryServicesRequiredCapabilitiesIMSAfterChange(t, header)
- GetTestPaginationSupportDsrc(t)
- })
-}
-
-func TestTopologyBasedDeliveryServicesRequiredCapabilities(t *testing.T) {
- WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, ServerCapabilities, ServerServerCapabilitiesForTopologies, Topologies, ServiceCategories, DeliveryServices, TopologyBasedDeliveryServiceRequiredCapabilities}, func() {
- GetTestDeliveryServicesRequiredCapabilities(t)
- OriginAssignTopologyBasedDeliveryServiceWithRequiredCapabilities(t)
- })
-}
-
-func OriginAssignTopologyBasedDeliveryServiceWithRequiredCapabilities(t *testing.T) {
- opts := client.NewRequestOptions()
- opts.QueryParameters.Set("xmlId", "ds-top-req-cap2")
- resp, _, err := TOSession.GetDeliveryServices(opts)
- if err != nil {
- t.Errorf("getting Delivery Service 'ds-top-req-cap2': %v - alerts: %+v", err, resp.Alerts)
- }
- if len(resp.Response) != 1 {
- t.Fatalf("expected to get only one Delivery Service with XMLID 'ds-top-req-cap2', but got %d", len(resp.Response))
- }
- if resp.Response[0].ID == nil {
- t.Fatal("no ID in the resulting delivery service")
- }
- dsID := *resp.Response[0].ID
- opts.QueryParameters = url.Values{}
- alerts, _, err := TOSession.AssignServersToDeliveryService([]string{"denver-mso-org-01"}, "ds-top-req-cap2", client.RequestOptions{})
- if err != nil {
- t.Errorf("assigning server 'denver-mso-org-01' to Delivery Service 'ds-top-req-cap2': %v - alerts: %+v", err, alerts)
- }
- opts.QueryParameters.Set("dsId", strconv.Itoa(dsID))
- opts.QueryParameters.Set("type", tc.OriginTypeName)
- responseServers, _, err := TOSession.GetServers(opts)
- if err != nil {
- t.Fatalf("getting servers for the 'ds-top-req-cap2' Delivery Service: %v - alerts: %+v", err, responseServers.Alerts)
- }
- if len(responseServers.Response) != 1 {
- t.Fatalf("expected just one ORG server in the response, but got %d", len(responseServers.Response))
- }
- if responseServers.Response[0].HostName == nil {
- t.Fatal("expected a valid host name for the resulting ORG server, but got nothing")
- }
- if *responseServers.Response[0].HostName != "denver-mso-org-01" {
- t.Errorf("expected host name of the resulting ORG server to be %v, but got %v", "denver-mso-org-01", *responseServers.Response[0].HostName)
- }
-}
-
-func GetTestDeliveryServicesRequiredCapabilitiesIMSAfterChange(t *testing.T, header http.Header) {
- data := testData.DeliveryServicesRequiredCapabilities
- if len(data) < 1 {
- t.Fatal("Need at least one Delivery Service Required Capability to test IMS updates to Delivery Service Required Capabilities")
- }
- if data[0].XMLID == nil {
- t.Fatal("Found a Delivery Service Required Capability in the testing data with null or undefined XMLID")
- }
- if data[0].RequiredCapability == nil {
- t.Fatal("Found a Delivery Service Required Capability in the testing data with null or undefined Required Capability")
- }
- xmlid := *data[0].XMLID
- cap := *data[0].RequiredCapability
- ds1 := helperGetDeliveryServiceID(t, &xmlid)
- if ds1 == nil {
- t.Fatalf("Failed to get ID for Delivery Service '%s'", xmlid)
- }
-
- testCases := []struct {
- description string
- params url.Values
- }{
- {
- description: "get all deliveryservices required capabilities",
- },
- {
- description: fmt.Sprintf("get all deliveryservices required capabilities by deliveryServiceID: %d", *ds1),
- params: url.Values{
- "deliveryServiceID": {strconv.Itoa(*ds1)},
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, ServerCapabilities, Topologies, ServiceCategories, DeliveryServices, DeliveryServiceServerAssignments, ServerServerCapabilities, DeliveryServicesRequiredCapabilities}, func() {
+
+ currentTime := time.Now().UTC().Add(-15 * time.Second)
+ currentTimeRFC := currentTime.Format(time.RFC1123)
+ tomorrow := currentTime.AddDate(0, 0, 1).Format(time.RFC1123)
+
+ methodTests := utils.V4TestCase{
+ "GET": {
+ "NOT MODIFIED when NO CHANGES made": {
+ ClientSession: TOSession, RequestOpts: client.RequestOptions{Header: http.Header{rfc.IfModifiedSince: {tomorrow}}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusNotModified)),
+ },
+ "OK when VALID request": {
+ ClientSession: TOSession, Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ "OK when VALID DELIVERYSERVICEID parameter": {
+ ClientSession: TOSession,
+ RequestOpts: client.RequestOptions{QueryParameters: url.Values{"deliveryServiceId": {"ds1"}}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseLengthGreaterOrEqual(1),
+ validateDSRCExpectedFields(map[string]interface{}{"DeliveryServiceId": "ds1"})),
+ },
+ "OK when VALID XMLID parameter": {
+ ClientSession: TOSession, RequestOpts: client.RequestOptions{QueryParameters: url.Values{"xmlID": {"ds2"}}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseLengthGreaterOrEqual(1),
+ validateDSRCExpectedFields(map[string]interface{}{"XMLID": "ds2"})),
+ },
+ "OK when VALID REQUIREDCAPABILITY parameter": {
+ ClientSession: TOSession, RequestOpts: client.RequestOptions{QueryParameters: url.Values{"requiredCapability": {"bar"}}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseLengthGreaterOrEqual(1),
+ validateDSRCExpectedFields(map[string]interface{}{"RequiredCapability": "bar"})),
+ },
+ "FIRST RESULT when LIMIT=1": {
+ ClientSession: TOSession,
+ RequestOpts: client.RequestOptions{QueryParameters: url.Values{"orderby": {"requiredCapability"}, "limit": {"1"}}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), validateDSRCPagination("limit")),
+ },
+ "SECOND RESULT when LIMIT=1 OFFSET=1": {
+ ClientSession: TOSession,
+ RequestOpts: client.RequestOptions{QueryParameters: url.Values{"orderby": {"requiredCapability"}, "limit": {"1"}, "offset": {"1"}}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), validateDSRCPagination("offset")),
+ },
+ "SECOND RESULT when LIMIT=1 PAGE=2": {
+ ClientSession: TOSession,
+ RequestOpts: client.RequestOptions{QueryParameters: url.Values{"orderby": {"requiredCapability"}, "limit": {"1"}, "page": {"2"}}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), validateDSRCPagination("page")),
+ },
+ "BAD REQUEST when INVALID LIMIT parameter": {
+ ClientSession: TOSession, RequestOpts: client.RequestOptions{QueryParameters: url.Values{"limit": {"-2"}}},
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ "BAD REQUEST when INVALID OFFSET parameter": {
+ ClientSession: TOSession, RequestOpts: client.RequestOptions{QueryParameters: url.Values{"limit": {"1"}, "offset": {"0"}}},
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ "BAD REQUEST when INVALID PAGE parameter": {
+ ClientSession: TOSession, RequestOpts: client.RequestOptions{QueryParameters: url.Values{"limit": {"1"}, "page": {"0"}}},
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
},
- },
- {
- description: fmt.Sprintf("get all deliveryservices required capabilities by xmlID: %s", xmlid),
- params: url.Values{
- "xmlID": {xmlid},
+ "POST": {
+ "BAD REQUEST when REASSIGNING REQUIRED CAPABILITY to DELIVERY SERVICE": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "deliveryServiceID": GetDeliveryServiceId(t, "ds1")(),
+ "requiredCapability": "foo",
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ "BAD REQUEST when SERVERS DONT have CAPABILITY": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "deliveryServiceID": GetDeliveryServiceId(t, "test-ds-server-assignments")(),
+ "requiredCapability": "disk",
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ "BAD REQUEST when DELIVERY SERVICE HAS TOPOLOGY where SERVERS DONT have CAPABILITY": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "deliveryServiceID": GetDeliveryServiceId(t, "ds-top-req-cap")(),
+ "requiredCapability": "bar",
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ "BAD REQUEST when DELIVERY SERVICE ID EMPTY": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "requiredCapability": "bar",
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ "BAD REQUEST when REQUIRED CAPABILITY EMPTY": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "deliveryServiceID": GetDeliveryServiceId(t, "ds1")(),
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ "NOT FOUND when NON-EXISTENT REQUIRED CAPABILITY": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "deliveryServiceID": GetDeliveryServiceId(t, "ds1")(),
+ "requiredCapability": "bogus",
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusNotFound)),
+ },
+ "NOT FOUND when NON-EXISTENT DELIVERY SERVICE ID": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "deliveryServiceID": -1,
+ "requiredCapability": "foo",
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusNotFound)),
+ },
+ "BAD REQUEST when INVALID DELIVERY SERVICE TYPE": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "deliveryServiceID": GetDeliveryServiceId(t, "anymap-ds")(),
+ "requiredCapability": "foo",
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
},
- },
- {
- description: fmt.Sprintf("get all deliveryservices required capabilities by requiredCapability: %s", cap),
- params: url.Values{
- "requiredCapability": {cap},
+ "DELETE": {
+ "OK when VALID request": {
+ EndpointId: GetDeliveryServiceId(t, "ds-top-req-cap"), ClientSession: TOSession,
+ RequestBody: map[string]interface{}{"requiredCapability": "ram"},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ "NOT FOUND when NON-EXISTENT DELIVERYSERVICEID parameter": {
+ EndpointId: func() int { return -1 }, ClientSession: TOSession,
+ RequestBody: map[string]interface{}{"requiredCapability": "foo"},
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusNotFound)),
+ },
+ "NOT FOUND when NON-EXISTENT REQUIREDCAPABILITY parameter": {
+ EndpointId: GetDeliveryServiceId(t, "ds1"), ClientSession: TOSession,
+ RequestBody: map[string]interface{}{"requiredCapability": "bogus"},
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusNotFound)),
+ },
},
- },
- }
-
- opts := client.NewRequestOptions()
- opts.Header = header
- for _, tc := range testCases {
- t.Run(tc.description, func(t *testing.T) {
- opts.QueryParameters = tc.params
- resp, reqInf, err := TOSession.GetDeliveryServicesRequiredCapabilities(opts)
- if err != nil {
- t.Errorf("Expected no error, but got %v - alerts: %+v", err, resp.Alerts)
- }
- if reqInf.StatusCode != http.StatusOK {
- t.Errorf("Expected 200 status code, got %v", reqInf.StatusCode)
- }
- })
- }
-
- currentTime := time.Now().UTC()
- currentTime = currentTime.Add(1 * time.Second)
- timeStr := currentTime.Format(time.RFC1123)
-
- opts.Header.Set(rfc.IfModifiedSince, timeStr)
- for _, tc := range testCases {
- t.Run(tc.description, func(t *testing.T) {
- opts.QueryParameters = tc.params
- resp, reqInf, err := TOSession.GetDeliveryServicesRequiredCapabilities(opts)
- if err != nil {
- t.Fatalf("Expected no error, but got %v - alerts: %+v", err, resp.Alerts)
- }
- if reqInf.StatusCode != http.StatusNotModified {
- t.Fatalf("Expected 304 status code, got %v", reqInf.StatusCode)
- }
- })
- }
-}
+ "GET AFTER CHANGES": {
+ "OK when CHANGES made": {
+ ClientSession: TOSession, RequestOpts: client.RequestOptions{Header: http.Header{rfc.IfModifiedSince: {currentTimeRFC}}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ },
+ }
-func GetTestDeliveryServicesRequiredCapabilities(t *testing.T) {
- data := testData.DeliveryServicesRequiredCapabilities
- if len(data) < 1 {
- t.Fatal("Need at least one Delivery Service Required Capability to test IMS updates to Delivery Service Required Capabilities")
- }
- if data[0].XMLID == nil {
- t.Fatal("Found a Delivery Service Required Capability in the testing data with null or undefined XMLID")
- }
- if data[0].RequiredCapability == nil {
- t.Fatal("Found a Delivery Service Required Capability in the testing data with null or undefined Required Capability")
- }
- ds1 := helperGetDeliveryServiceID(t, data[0].XMLID)
- if ds1 == nil {
- t.Fatalf("Failed to get ID for Delivery Service '%s'", *data[0].XMLID)
- }
+ for method, testCases := range methodTests {
+ t.Run(method, func(t *testing.T) {
+ for name, testCase := range testCases {
+ dsrc := tc.DeliveryServicesRequiredCapability{}
- testCases := []struct {
- description string
- capability tc.DeliveryServicesRequiredCapability
- expectFunc func(tc.DeliveryServicesRequiredCapability, []tc.DeliveryServicesRequiredCapability)
- }{
- {
- description: "get all deliveryservices required capabilities",
- expectFunc: func(expect tc.DeliveryServicesRequiredCapability, actual []tc.DeliveryServicesRequiredCapability) {
- if len(actual) != len(testData.DeliveryServicesRequiredCapabilities) {
- t.Errorf("expected length: %d, actual: %d", len(testData.DeliveryServicesRequiredCapabilities), len(actual))
- }
- },
- },
- {
- description: fmt.Sprintf("get all deliveryservices required capabilities by deliveryServiceID: %d", *ds1),
- capability: tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: ds1,
- },
- expectFunc: func(dsRequiredCapability tc.DeliveryServicesRequiredCapability, dsReqCaps []tc.DeliveryServicesRequiredCapability) {
- for _, dsrc := range dsReqCaps {
- if dsrc.DeliveryServiceID == nil {
- t.Error("Traffic Ops returned a representation for a Delivery Service/Required Capability relationship with null or undefined Delivery Service ID")
- continue
- }
- if *dsrc.DeliveryServiceID != *dsRequiredCapability.DeliveryServiceID {
- t.Errorf("expected: all delivery service IDs to equal %d, actual: found %d", *dsRequiredCapability.DeliveryServiceID, *dsrc.DeliveryServiceID)
- }
- }
- },
- },
- {
- description: fmt.Sprintf("get all deliveryservices required capabilities by xmlID: %s", *data[0].XMLID),
- capability: tc.DeliveryServicesRequiredCapability{
- XMLID: data[0].XMLID,
- },
- expectFunc: func(dsRequiredCapability tc.DeliveryServicesRequiredCapability, dsReqCaps []tc.DeliveryServicesRequiredCapability) {
- for _, dsrc := range dsReqCaps {
- if dsrc.XMLID == nil {
- t.Error("Traffic Ops returned a representation for a Delivery Service/Required Capability relationship with null or undefined XMLID")
- continue
- }
- if *dsrc.XMLID != *dsRequiredCapability.XMLID {
- t.Errorf("expected: all delivery service XMLIDs to equal %s, actual: found %s", *dsRequiredCapability.XMLID, *dsrc.XMLID)
+ if val, ok := testCase.RequestOpts.QueryParameters["deliveryServiceId"]; ok {
+ if _, err := strconv.Atoi(val[0]); err != nil {
+ testCase.RequestOpts.QueryParameters.Set("deliveryServiceId", strconv.Itoa(GetDeliveryServiceId(t, val[0])()))
+ }
}
- }
- },
- },
- {
- description: fmt.Sprintf("get all deliveryservices required capabilities by requiredCapability: %s", *data[0].RequiredCapability),
- capability: tc.DeliveryServicesRequiredCapability{
- RequiredCapability: data[0].RequiredCapability,
- },
- expectFunc: func(dsRequiredCapability tc.DeliveryServicesRequiredCapability, dsReqCaps []tc.DeliveryServicesRequiredCapability) {
- for _, dsrc := range dsReqCaps {
- if dsrc.RequiredCapability == nil {
- t.Error("Traffic Ops returned a representation for a Delivery Service/Required Capability relationship with null or undefined required Capability")
- continue
+
+ if testCase.RequestBody != nil {
+ dat, err := json.Marshal(testCase.RequestBody)
+ assert.NoError(t, err, "Error occurred when marshalling request body: %v", err)
+ err = json.Unmarshal(dat, &dsrc)
+ assert.NoError(t, err, "Error occurred when unmarshalling request body: %v", err)
}
- if *dsrc.RequiredCapability != *dsRequiredCapability.RequiredCapability {
- t.Errorf("expected: all delivery service required capabilities to equal %s, actual: found %s", *dsRequiredCapability.RequiredCapability, *dsrc.RequiredCapability)
+
+ switch method {
+ case "GET", "GET AFTER CHANGES":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.GetDeliveryServicesRequiredCapabilities(testCase.RequestOpts)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, resp.Response, resp.Alerts, err)
+ }
+ })
+ case "POST":
+ t.Run(name, func(t *testing.T) {
+ alerts, reqInf, err := testCase.ClientSession.CreateDeliveryServicesRequiredCapability(dsrc, testCase.RequestOpts)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, nil, alerts, err)
+ }
+ })
+ case "DELETE":
+ t.Run(name, func(t *testing.T) {
+ alerts, reqInf, err := testCase.ClientSession.DeleteDeliveryServicesRequiredCapability(testCase.EndpointId(), testCase.RequestBody["requiredCapability"].(string), testCase.RequestOpts)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, nil, alerts, err)
+ }
+ })
}
}
- },
- },
- }
+ })
+ }
+ })
- for _, tc := range testCases {
- t.Run(tc.description, func(t *testing.T) {
- opts := client.NewRequestOptions()
- if tc.capability.XMLID != nil {
- opts.QueryParameters.Set("xmlID", *tc.capability.XMLID)
- }
- if tc.capability.RequiredCapability != nil {
- opts.QueryParameters.Set("requiredCapability", *tc.capability.RequiredCapability)
- }
- if tc.capability.DeliveryServiceID != nil {
- opts.QueryParameters.Set("deliveryServiceID", strconv.Itoa(*tc.capability.DeliveryServiceID))
- }
- capabilities, _, err := TOSession.GetDeliveryServicesRequiredCapabilities(opts)
- if err != nil {
- t.Errorf("Unexpected error requesting Delivery Service Required Capabilities: %v - alerts: %+v", err, capabilities.Alerts)
- }
- tc.expectFunc(tc.capability, capabilities.Response)
- })
- }
}
-func GetTestDeliveryServicesRequiredCapabilitiesIMS(t *testing.T) {
- data := testData.DeliveryServicesRequiredCapabilities
- if len(data) < 1 {
- t.Fatal("Need at least one Delivery Service Required Capability to test IMS updates to Delivery Service Required Capabilities")
- }
- if data[0].XMLID == nil {
- t.Fatal("Found a Delivery Service Required Capability in the testing data with null or undefined XMLID")
- }
- if data[0].RequiredCapability == nil {
- t.Fatal("Found a Delivery Service Required Capability in the testing data with null or undefined Required Capability")
- }
- xmlid := *data[0].XMLID
- cap := *data[0].RequiredCapability
- ds1 := helperGetDeliveryServiceID(t, &xmlid)
- if ds1 == nil {
- t.Fatalf("Failed to get ID for Delivery Service '%s'", xmlid)
- }
-
- futureTime := time.Now().AddDate(0, 0, 1)
- time := futureTime.Format(time.RFC1123)
-
- opts := client.NewRequestOptions()
- opts.Header.Set(rfc.IfModifiedSince, time)
-
- testCases := []struct {
- description string
- params url.Values
- }{
- {
- description: "get all deliveryservices required capabilities",
- },
- {
- description: fmt.Sprintf("get all deliveryservices required capabilities by deliveryServiceID: %d", *ds1),
- params: url.Values{
- "deliveryServiceID": {strconv.Itoa(*ds1)},
- },
- },
- {
- description: fmt.Sprintf("get all deliveryservices required capabilities by xmlID: %s", xmlid),
- params: url.Values{
- "xmlID": {xmlid},
- },
- },
- {
- description: fmt.Sprintf("get all deliveryservices required capabilities by requiredCapability: %s", cap),
- params: url.Values{
- "requiredCapability": {cap},
- },
- },
- }
-
- for _, tc := range testCases {
- opts.QueryParameters = tc.params
- t.Run(tc.description, func(t *testing.T) {
- resp, reqInf, err := TOSession.GetDeliveryServicesRequiredCapabilities(opts)
- if err != nil {
- t.Fatalf("Expected no error, but got %v - alerts: %+v", err, resp.Alerts)
- }
- if reqInf.StatusCode != http.StatusNotModified {
- t.Fatalf("Expected 304 status code, got %v", reqInf.StatusCode)
+func validateDSRCExpectedFields(expectedResp map[string]interface{}) utils.CkReqFunc {
+ return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, _ tc.Alerts, _ error) {
+ dsrcResp := resp.([]tc.DeliveryServicesRequiredCapability)
+ for field, expected := range expectedResp {
+ for _, dsrc := range dsrcResp {
+ switch field {
+ case "DeliveryServiceID":
+ assert.Equal(t, expected, *dsrc.DeliveryServiceID, "Expected deliveryServiceId to be %v, but got %v", expected, dsrc.DeliveryServiceID)
+ case "XMLID":
+ assert.Equal(t, expected, *dsrc.XMLID, "Expected xmlID to be %v, but got %v", expected, dsrc.XMLID)
+ case "RequiredCapability":
+ assert.Equal(t, expected, *dsrc.RequiredCapability, "Expected requiredCapability to be %v, but got %v", expected, dsrc.RequiredCapability)
+ }
}
- })
+ }
}
}
-func CreateTestTopologyBasedDeliveryServicesRequiredCapabilities(t *testing.T) {
- for _, td := range testData.TopologyBasedDeliveryServicesRequiredCapabilities {
-
- c := tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: helperGetDeliveryServiceID(t, td.XMLID),
- RequiredCapability: td.RequiredCapability,
+func validateDSRCPagination(paginationParam string) utils.CkReqFunc {
+ return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, _ tc.Alerts, _ error) {
+ paginationResp := resp.([]tc.DeliveryServicesRequiredCapability)
+
+ opts := client.NewRequestOptions()
+ opts.QueryParameters.Set("orderby", "requiredCapability")
+ respBase, _, err := TOSession.GetDeliveryServicesRequiredCapabilities(opts)
+ assert.RequireNoError(t, err, "Cannot get Delivery Services Required Capabilities: %v - alerts: %+v", err, respBase.Alerts)
+
+ dsrc := respBase.Response
+ assert.RequireGreaterOrEqual(t, len(dsrc), 3, "Need at least 3 Delivery Services Required Capabilities in Traffic Ops to test pagination support, found: %d", len(dsrc))
+ switch paginationParam {
+ case "limit:":
+ assert.Exactly(t, dsrc[:1], paginationResp, "Expected GET deliveryservices_required_capabilities with limit = 1 to return first result")
+ case "offset":
+ assert.Exactly(t, dsrc[1:2], paginationResp, "Expected GET deliveryservices_required_capabilities with limit = 1, offset = 1 to return second result")
+ case "page":
+ assert.Exactly(t, dsrc[1:2], paginationResp, "Expected GET deliveryservices_required_capabilities with limit = 1, page = 2 to return second result")
}
-
- alerts, _, err := TOSession.CreateDeliveryServicesRequiredCapability(c, client.RequestOptions{})
- if err != nil {
- t.Fatalf("cannot create delivery service required capability: %v - %+v", err, alerts.Alerts)
- }
- }
-
- invalid := tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: helperGetDeliveryServiceID(t, util.StrPtr("ds-top-req-cap")),
- RequiredCapability: util.StrPtr("asdf"),
- }
- _, reqInf, err := TOSession.CreateDeliveryServicesRequiredCapability(invalid, client.RequestOptions{})
- if err == nil {
- t.Fatal("when adding delivery service required capability to a delivery service with a topology that " +
- "doesn't have cachegroups with at least one server with the required capabilities - expected: error, actual: nil")
- }
- if reqInf.StatusCode != http.StatusBadRequest {
- t.Fatalf("when adding delivery service required capability to a delivery service with a topology that "+
- "doesn't have cachegroups with at least one server with the required capabilities - expected status code: "+
- "%d, actual: %d", http.StatusBadRequest, reqInf.StatusCode)
}
}
func CreateTestDeliveryServicesRequiredCapabilities(t *testing.T) {
- data := testData.DeliveryServicesRequiredCapabilities
- if len(data) == 0 {
- t.Fatal("there must be at least one test ds required capability defined")
- }
- ds1 := helperGetDeliveryServiceID(t, data[0].XMLID)
- amDS := helperGetDeliveryServiceID(t, util.StrPtr("anymap-ds"))
- testCases := []struct {
- description string
- capability tc.DeliveryServicesRequiredCapability
- }{
- {
- description: fmt.Sprintf("re-assign a deliveryservice to a required capability; deliveryServiceID: %d, requiredCapability: %s", *ds1, *data[0].RequiredCapability),
- capability: tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: ds1,
- RequiredCapability: data[0].RequiredCapability,
- },
- },
- {
- description: fmt.Sprintf("assign a deliveryservice to a required capability with no delivery service id; deliveryServiceID: 0, requiredCapability: %s", *data[0].RequiredCapability),
- capability: tc.DeliveryServicesRequiredCapability{
- RequiredCapability: data[0].RequiredCapability,
- },
- },
- {
- description: fmt.Sprintf("assign a deliveryservice to a required capability with no requiredCapability; deliveryServiceID: %d, requiredCapability: 0", *ds1),
- capability: tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: ds1,
- },
- },
- {
- description: fmt.Sprintf("assign a deliveryservice to a required capability with an invalid required capability; deliveryServiceID: %d, requiredCapability: bogus", *ds1),
- capability: tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: ds1,
- RequiredCapability: util.StrPtr("bogus"),
- },
- },
- {
- description: fmt.Sprintf("assign a deliveryservice to a required capability with an invalid delivery service id; deliveryServiceID: -1, requiredCapability: %s", *data[0].RequiredCapability),
- capability: tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: util.IntPtr(-1),
- RequiredCapability: data[0].RequiredCapability,
- },
- },
- {
- description: "assign a deliveryservice to a required capability with an invalid deliveryservice type",
- capability: tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: amDS,
- RequiredCapability: data[0].RequiredCapability,
- },
- },
- }
-
// Assign all required capability to delivery services listed in `tc-fixtures.json`.
- for _, td := range testData.DeliveryServicesRequiredCapabilities {
- var dsID int
- if td.DeliveryServiceID != nil {
- dsID = *td.DeliveryServiceID
- }
-
- var capability string
- if td.RequiredCapability != nil {
- capability = *td.RequiredCapability
- }
-
- t.Run(fmt.Sprintf("assign a deliveryservice to a required capability; deliveryServiceID: %d, requiredCapability: %s", dsID, capability), func(t *testing.T) {
- cap := tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: helperGetDeliveryServiceID(t, td.XMLID),
- RequiredCapability: td.RequiredCapability,
- }
-
- resp, _, err := TOSession.CreateDeliveryServicesRequiredCapability(cap, client.RequestOptions{})
- if err != nil {
- t.Fatalf("Unexpected error creating a Delivery Service/Required Capability relationship: %v - alerts: %+v", err, resp.Alerts)
- }
- })
- }
-
- for _, tc := range testCases {
- t.Run(tc.description, func(t *testing.T) {
- _, _, err := TOSession.CreateDeliveryServicesRequiredCapability(tc.capability, client.RequestOptions{})
- if err == nil {
- t.Fatalf("%s; expected err", tc.description)
- }
- })
- }
-}
-
-func InvalidDeliveryServicesRequiredCapabilityAddition(t *testing.T) {
- // Tests that a capability cannot be made required if the DS's services do not have it assigned
-
- // Get Delivery Capability for a DS
- opts := client.NewRequestOptions()
- opts.QueryParameters.Set("xmlID", "ds1")
- capabilities, _, err := TOSession.GetDeliveryServicesRequiredCapabilities(opts)
- if err != nil {
- t.Fatalf("cannot get Delivery Service Required Capabilities: %v - alerts: %+v", err, capabilities.Alerts)
- }
- if len(capabilities.Response) == 0 {
- t.Fatal("delivery service ds1 needs at least one capability required")
- }
- dsID := capabilities.Response[0].DeliveryServiceID
- if dsID == nil {
- t.Fatal("Traffic Ops returned a representation for a Delivery Service/Required Capability relationship with null or undefined Delivery Service ID")
- }
-
- // First assign current capabilities to edge server so we can assign it to the DS
- // TODO: DON'T hard-code hostnames!
- opts.QueryParameters = url.Values{}
- opts.QueryParameters.Set("hostName", "atlanta-edge-01")
- resp, _, err := TOSession.GetServers(opts)
- if err != nil {
- t.Fatalf("cannot get Server by Host Name 'atlanta-edge-01': %v - alerts: %+v", err, resp.Alerts)
- }
- servers := resp.Response
- if len(servers) < 1 {
- t.Fatal("need at least one server to test invalid ds required capability assignment")
- }
-
- if servers[0].ID == nil {
- t.Fatal("server 'atlanta-edge-01' had nil ID")
- }
-
- sID := *servers[0].ID
- serverCaps := []tc.ServerServerCapability{}
-
- for _, cap := range capabilities.Response {
- if cap.RequiredCapability == nil {
- t.Errorf("Traffic Ops returned a representation for a Delivery Service/Required Capability relationship with null or undefined required Capability")
- continue
- }
- sCap := tc.ServerServerCapability{
- ServerID: &sID,
- ServerCapability: cap.RequiredCapability,
- }
- resp, _, err := TOSession.CreateServerServerCapability(sCap, client.RequestOptions{})
- if err != nil {
- t.Errorf("could not associate Capability %s with server #%d: %v - alerts: %+v", *cap.RequiredCapability, sID, err, resp.Alerts)
- }
- serverCaps = append(serverCaps, sCap)
- }
-
- // Assign server to ds
- alerts, _, err := TOSession.CreateDeliveryServiceServers(*dsID, []int{sID}, false, client.RequestOptions{})
- if err != nil {
- t.Fatalf("Unexpected error assigning server #%d to Delivery Service #%d: %v - alerts: %+v", sID, *dsID, err, alerts.Alerts)
- }
-
- // Create new bogus server capability
- scResp, _, err := TOSession.CreateServerCapability(tc.ServerCapability{
- Name: "newcap",
- }, client.RequestOptions{})
- if err != nil {
- t.Fatalf("cannot create 'newcap' Server Capability: %v - alerts: %+v", err, scResp.Alerts)
- }
-
- // Attempt to assign to DS should fail
- _, _, err = TOSession.CreateDeliveryServicesRequiredCapability(tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: dsID,
- RequiredCapability: util.StrPtr("newcap"),
- }, client.RequestOptions{})
- if err == nil {
- t.Error("expected error requiring a capability that is not associated on the delivery service's servers")
- }
-
- // Disassociate server from DS
- setInactive(t, *dsID)
- deleteResp, _, err := TOSession.DeleteDeliveryServiceServer(*dsID, sID, client.RequestOptions{})
- if err != nil {
- t.Fatalf("could not remove server #%d from Delivery Service #%d: %v - alerts: %+v", sID, *dsID, err, deleteResp.Alerts)
- }
-
- // Remove server capabilities from server
- for _, ssc := range serverCaps {
- resp, _, err := TOSession.DeleteServerServerCapability(*ssc.ServerID, *ssc.ServerCapability, client.RequestOptions{})
- if err != nil {
- t.Errorf("could not remove Capability '%s' from server #%d: %v - alerts: %+v", *ssc.ServerCapability, *ssc.ServerID, err, resp.Alerts)
+ for _, dsrc := range testData.DeliveryServicesRequiredCapabilities {
+ dsId := GetDeliveryServiceId(t, *dsrc.XMLID)()
+ dsrc = tc.DeliveryServicesRequiredCapability{
+ DeliveryServiceID: &dsId,
+ RequiredCapability: dsrc.RequiredCapability,
}
+ resp, _, err := TOSession.CreateDeliveryServicesRequiredCapability(dsrc, client.RequestOptions{})
+ assert.NoError(t, err, "Unexpected error creating a Delivery Service/Required Capability relationship: %v - alerts: %+v", err, resp.Alerts)
}
-
- // Delete server capability
- deleteAlerts, _, err := TOSession.DeleteServerCapability("newcap", client.RequestOptions{})
- if err != nil {
- t.Fatalf("cannot delete 'newcap' Server Capability: %v - alerts: %+v", err, deleteAlerts.Alerts)
- }
-
}
func DeleteTestDeliveryServicesRequiredCapabilities(t *testing.T) {
// Get Required Capabilities to delete them
- capabilities, _, err := TOSession.GetDeliveryServicesRequiredCapabilities(client.RequestOptions{})
- if err != nil {
- t.Fatalf("Unexpected error getting Delivery Service/Required Capability relationships: %v - alerts: %+v", err, capabilities.Alerts)
- }
- if len(capabilities.Response) < 1 {
- t.Fatal("no Delivery Service/Required Capability relationships returned")
- }
- cap := capabilities.Response[0]
- if cap.DeliveryServiceID == nil || cap.RequiredCapability == nil {
- t.Fatal("Traffic Ops returned a representation of a Delivery Service/Required Capability relationship with null or undefined required Capability and/or Delivery Service ID")
- }
-
- type testCase struct {
- description string
- dsID int
- capability string
- err string
- }
-
- testCases := []testCase{
- {
- description: fmt.Sprintf("delete a deliveryservices required capability with an invalid delivery service id; deliveryServiceID: -1, requiredCapability: %s", *cap.RequiredCapability),
- dsID: -1,
- capability: *cap.RequiredCapability,
- err: "no deliveryservice.RequiredCapability with that key found",
- },
- {
- description: fmt.Sprintf("delete a deliveryservices required capability with an invalid required capability; deliveryServiceID: %d, requiredCapability: bogus", *cap.DeliveryServiceID),
- dsID: *cap.DeliveryServiceID,
- capability: "bogus",
- err: "no deliveryservice.RequiredCapability with that key found",
- },
- }
-
- for _, c := range capabilities.Response {
- if c.DeliveryServiceID == nil || c.RequiredCapability == nil {
- t.Error("Traffic Ops returned a representation of a Delivery Service/Required Capability relationship with null or undefined required Capability and/or Delivery Service ID")
- continue
- }
- t := testCase{
- description: fmt.Sprintf("delete a deliveryservices required capability; deliveryServiceID: %d, requiredCapability: %s", *c.DeliveryServiceID, *c.RequiredCapability),
- capability: *c.RequiredCapability,
- dsID: *c.DeliveryServiceID,
- }
- testCases = append(testCases, t)
- }
-
- for _, c := range testCases {
- t.Run(c.description, func(t *testing.T) {
- alerts, _, err := TOSession.DeleteDeliveryServicesRequiredCapability(c.dsID, c.capability, client.RequestOptions{})
- if err != nil {
- if c.err != "" {
- found := false
- for _, alert := range alerts.Alerts {
- if alert.Level == tc.ErrorLevel.String() && strings.Contains(alert.Text, c.err) {
- found = true
- continue
- }
- }
- if !found {
- t.Errorf("Expected to find an error-level alert containing the text '%s', but it was not found - alerts: %+v", c.err, alerts.Alerts)
- }
- } else {
- t.Errorf("Unexpected error deleting a relationship between a Delivery Service and a Capability it requires: %v - alerts: %+v", err, alerts.Alerts)
- }
- } else if c.err != "" {
- t.Errorf("Expected deletion to fail with reason '%s' but it succeeded", c.err)
- }
- })
- }
-}
-
-func helperGetDeliveryServiceID(t *testing.T, xmlID *string) *int {
- t.Helper()
- if xmlID == nil {
- t.Error("xml id must not be nil")
- return nil
- }
- opts := client.NewRequestOptions()
- opts.QueryParameters.Set("xmlId", *xmlID)
- ds, _, err := TOSession.GetDeliveryServices(opts)
- if err != nil {
- t.Errorf("Unexpected error getting Delivery Services filtered by XMLID '%s': %v - alerts: %+v", *xmlID, err, ds.Alerts)
- return nil
- }
- if len(ds.Response) != 1 {
- t.Errorf("Expected exactly one Delivery Service to have XMLID '%s', found: %d", *xmlID, len(ds.Response))
- return nil
- }
- return ds.Response[0].ID
-}
-
-func GetTestPaginationSupportDsrc(t *testing.T) {
- opts := client.NewRequestOptions()
- opts.QueryParameters.Set("orderby", "requiredCapability")
- resp, _, err := TOSession.GetDeliveryServicesRequiredCapabilities(opts)
- if err != nil {
- t.Fatalf("cannot Get DeliveryServicesRequiredCapabilities: %v - alerts: %+v", err, resp.Alerts)
- }
- dsrc := resp.Response
- if len(dsrc) < 3 {
- t.Fatalf("Need at least 3 DeliveryServicesRequiredCapabilities in Traffic Ops to test pagination support, found: %d", len(dsrc))
- }
- opts.QueryParameters.Set("limit", "1")
- dsrcWithLimit, _, err := TOSession.GetDeliveryServicesRequiredCapabilities(opts)
- if err != nil {
- t.Fatalf("cannot Get DeliveryServicesRequiredCapabilities with Limit: %v - alerts: %+v", err, dsrcWithLimit.Alerts)
- }
- if !reflect.DeepEqual(dsrc[:1], dsrcWithLimit.Response) {
- t.Error("expected GET DeliveryServicesRequiredCapabilities with limit = 1 to return first result")
- }
-
- opts.QueryParameters.Set("offset", "1")
- dsrcWithOffset, _, err := TOSession.GetDeliveryServicesRequiredCapabilities(opts)
- if err != nil {
- t.Fatalf("cannot Get DeliveryServicesRequiredCapabilities with Limit and Offset: %v - alerts: %+v", err, dsrcWithOffset.Alerts)
- }
- if !reflect.DeepEqual(dsrc[1:2], dsrcWithOffset.Response) {
- t.Error("expected GET DeliveryServicesRequiredCapabilities with limit = 1, offset = 1 to return second result")
- }
-
- opts.QueryParameters.Del("offset")
- opts.QueryParameters.Set("page", "2")
- dsrcWithPage, _, err := TOSession.GetDeliveryServicesRequiredCapabilities(opts)
- if err != nil {
- t.Fatalf("cannot Get DeliveryServicesRequiredCapabilities with Limit and Page: %v - alerts: %+v", err, dsrcWithPage.Alerts)
- }
- if !reflect.DeepEqual(dsrc[1:2], dsrcWithPage.Response) {
- t.Error("expected GET DeliveryServicesRequiredCapabilities with limit = 1, page = 2 to return second result")
- }
-
- opts.QueryParameters = url.Values{}
- opts.QueryParameters.Set("limit", "-2")
- resp, _, err = TOSession.GetDeliveryServicesRequiredCapabilities(opts)
- if err == nil {
- t.Error("expected GET DeliveryServicesRequiredCapabilities 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 DeliveryServicesRequiredCapabilities 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.GetDeliveryServicesRequiredCapabilities(opts)
- if err == nil {
- t.Error("expected GET DeliveryServicesRequiredCapabilities 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 DeliveryServicesRequiredCapabilities to return an error for offset is not a positive integer, actual error: %v - alerts: %+v", err, resp.Alerts)
- }
+ dsrcs, _, err := TOSession.GetDeliveryServicesRequiredCapabilities(client.RequestOptions{})
+ assert.NoError(t, err, "Error getting Delivery Service/Required Capability relationships: %v - alerts: %+v", err, dsrcs.Alerts)
- opts.QueryParameters = url.Values{}
- opts.QueryParameters.Set("limit", "1")
- opts.QueryParameters.Set("page", "0")
- resp, _, err = TOSession.GetDeliveryServicesRequiredCapabilities(opts)
- if err == nil {
- t.Error("expected GET DeliveryServicesRequiredCapabilities 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 DeliveryServicesRequiredCapabilities to return an error for page is not a positive integer, actual error: %v - alerts: %+v", err, resp.Alerts)
+ for _, dsrc := range dsrcs.Response {
+ alerts, _, err := TOSession.DeleteDeliveryServicesRequiredCapability(*dsrc.DeliveryServiceID, *dsrc.RequiredCapability, client.RequestOptions{})
+ assert.NoError(t, err, "Error deleting a relationship between a Delivery Service and a Capability: %v - alerts: %+v", err, alerts.Alerts)
}
}
diff --git a/traffic_ops/testing/api/v4/deliveryservices_test.go b/traffic_ops/testing/api/v4/deliveryservices_test.go
index 69475d2c57..5bff71199f 100644
--- a/traffic_ops/testing/api/v4/deliveryservices_test.go
+++ b/traffic_ops/testing/api/v4/deliveryservices_test.go
@@ -32,7 +32,7 @@ import (
)
func TestDeliveryServices(t *testing.T) {
- WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, ServerCapabilities, ServiceCategories, DeliveryServices, DeliveryServicesRequiredCapabilities, DeliveryServiceServerAssignments}, func() {
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, ServerCapabilities, ServiceCategories, DeliveryServices, ServerServerCapabilities, DeliveryServicesRequiredCapabilities, DeliveryServiceServerAssignments}, func() {
currentTime := time.Now().UTC().Add(-15 * time.Second)
currentTimeRFC := currentTime.Format(time.RFC1123)
@@ -240,14 +240,14 @@ func TestDeliveryServices(t *testing.T) {
Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
},
"OK when VALID request": {
- EndpointId: GetDeliveryServiceId(t, "ds1"), ClientSession: TOSession,
+ EndpointId: GetDeliveryServiceId(t, "ds2"), ClientSession: TOSession,
RequestBody: generateDeliveryService(t, map[string]interface{}{
"maxRequestHeaderBytes": 131080,
"longDesc": "something different",
"maxDNSAnswers": 164598,
"maxOriginConnections": 100,
"active": false,
- "displayName": "newds1displayname",
+ "displayName": "newds2displayname",
"dscp": 41,
"geoLimit": 1,
"initialDispersion": 2,
@@ -258,13 +258,15 @@ func TestDeliveryServices(t *testing.T) {
"multiSiteOrigin": true,
"orgServerFqdn": "http://origin.example.net",
"protocol": 2,
+ "routingName": "ccr-ds2",
"qStringIgnore": 0,
"regionalGeoBlocking": true,
+ "xmlId": "ds2",
}),
Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
validateDSExpectedFields(map[string]interface{}{"MaxRequestHeaderSize": 131080,
"LongDesc": "something different", "MaxDNSAnswers": 164598, "MaxOriginConnections": 100,
- "Active": false, "DisplayName": "newds1displayname", "DSCP": 41, "GeoLimit": 1,
+ "Active": false, "DisplayName": "newds2displayname", "DSCP": 41, "GeoLimit": 1,
"InitialDispersion": 2, "IPV6RoutingEnabled": false, "LogsEnabled": false, "MissLat": 42.881944,
"MissLong": -88.627778, "MultiSiteOrigin": true, "OrgServerFQDN": "http://origin.example.net",
"Protocol": 2, "QStringIgnore": 0, "RegionalGeoBlocking": true,
@@ -381,12 +383,13 @@ func TestDeliveryServices(t *testing.T) {
Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
},
"OK when DS with NO TOPOLOGY updates LEGACY HEADER REWRITE FIELDS": {
- EndpointId: GetDeliveryServiceId(t, "ds1"), ClientSession: TOSession,
+ EndpointId: GetDeliveryServiceId(t, "ds2"), ClientSession: TOSession,
RequestBody: generateDeliveryService(t, map[string]interface{}{
"profileId": GetProfileId(t, "ATS_EDGE_TIER_CACHE"),
"edgeHeaderRewrite": "foo",
"midHeaderRewrite": "bar",
- "xmlId": "ds1",
+ "routingName": "ccr-ds2",
+ "xmlId": "ds2",
}),
Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
},
diff --git a/traffic_ops/testing/api/v4/deliveryserviceservers_test.go b/traffic_ops/testing/api/v4/deliveryserviceservers_test.go
index b1a86be32f..ffcf87799b 100644
--- a/traffic_ops/testing/api/v4/deliveryserviceservers_test.go
+++ b/traffic_ops/testing/api/v4/deliveryserviceservers_test.go
@@ -16,782 +16,423 @@ package v4
*/
import (
- "errors"
+ "encoding/json"
"net/http"
"net/url"
"strconv"
- "strings"
"testing"
"time"
"github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
- "github.com/apache/trafficcontrol/lib/go-util"
"github.com/apache/trafficcontrol/traffic_ops/testing/api/assert"
+ "github.com/apache/trafficcontrol/traffic_ops/testing/api/utils"
client "github.com/apache/trafficcontrol/traffic_ops/v4-client"
)
func TestDeliveryServiceServers(t *testing.T) {
- WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, ServiceCategories, DeliveryServices}, func() {
- DeleteTestDeliveryServiceServers(t)
- AssignServersToTopologyBasedDeliveryService(t)
- AssignOriginsToTopologyBasedDeliveryServices(t)
- TryToRemoveLastServerInDeliveryService(t)
- AssignServersToNonTopologyBasedDeliveryServiceThatUsesMidTier(t)
- GetTestDSSIMS(t)
- GetTestDSServerByCDN(t)
- })
-}
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, ServiceCategories, ServerCapabilities, DeliveryServices, DeliveryServiceServerAssignments, ServerServerCapabilities, DeliveryServicesRequiredCapabilities}, func() {
+
+ tomorrow := time.Now().UTC().AddDate(0, 0, 1).Format(time.RFC1123)
+
+ dssTests := utils.V4TestCase{
+ "GET": {
+ "NOT MODIFIED when NO CHANGES made": {
+ ClientSession: TOSession, RequestOpts: client.RequestOptions{Header: http.Header{rfc.IfModifiedSince: {tomorrow}}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusNotModified)),
+ },
+ "OK when VALID request": {
+ ClientSession: TOSession, Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ "OK when VALID CDN parameter": {
+ ClientSession: TOSession, RequestOpts: client.RequestOptions{QueryParameters: url.Values{"cdn": {"cdn1"}}},
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseLengthGreaterOrEqual(1)),
+ },
+ },
+ "POST": {
+ "OK when VALID request": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "dsId": GetDeliveryServiceId(t, "ds3")(),
+ "replace": true,
+ "servers": []int{getServerID(t, "atlanta-edge-01")(), getServerID(t, "atlanta-edge-03")()},
+ },
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ "OK when ASSIGNING ORG SERVER IN CACHEGROUP of TOPOLOGY DS": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "dsId": GetDeliveryServiceId(t, "ds-top")(),
+ "replace": true,
+ "servers": []int{getServerID(t, "denver-mso-org-01")()},
+ },
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ "BAD REQUEST when ASSIGNING ORG SERVER NOT IN CACHEGROUP of TOPOLOGY DS": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "dsId": GetDeliveryServiceId(t, "ds-top-req-cap")(),
+ "replace": true,
+ "servers": []int{getServerID(t, "denver-mso-org-01")()},
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ "BAD REQUEST when ASSIGNING SERVERS to a TOPOLOGY DS": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "dsId": GetDeliveryServiceId(t, "ds-top")(),
+ "servers": []int{getServerID(t, "atlanta-edge-01")(), getServerID(t, "atlanta-edge-03")()},
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ "CONFLICT when REMOVING ONLY EDGE SERVER ASSIGNMENT": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "dsId": GetDeliveryServiceId(t, "test-ds-server-assignments")(),
+ "replace": true,
+ "servers": []int{getServerID(t, "test-mso-org-01")()},
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusConflict)),
+ },
+ "CONFLICT when REMOVING ONLY ORIGIN SERVER ASSIGNMENT": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "dsId": GetDeliveryServiceId(t, "test-ds-server-assignments")(),
+ "replace": true,
+ "servers": []int{getServerID(t, "test-ds-server-assignments")()},
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusConflict)),
+ },
+ "CONFLICT when REPLACING EDGE SERVER ASSIGNMENT with EDGE SERVER in BAD STATE": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "dsId": GetDeliveryServiceId(t, "test-ds-server-assignments")(),
+ "replace": true,
+ "servers": []int{getServerID(t, "admin-down-server")()},
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusConflict)),
+ },
+ "OK when MAKING ASSIGNMENTS when DELIVERY SERVICE AND SERVER HAVE MATCHING CAPABILITIES": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "dsId": GetDeliveryServiceId(t, "ds2")(),
+ "replace": true,
+ "servers": []int{getServerID(t, "atlanta-org-2")()},
+ },
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ "OK when ASSIGNING a ORIGIN server to a DS with REQUIRED CAPABILITY": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "dsId": GetDeliveryServiceId(t, "msods1")(),
+ "replace": true,
+ "servers": []int{getServerID(t, "denver-mso-org-01")()},
+ },
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ },
+ "SERVER DELETE": {
+ "CONFLICT when DELETING SERVER when its the ONLY EDGE SERVER ASSIGNED": {
+ EndpointId: getServerID(t, "test-ds-server-assignments"), ClientSession: TOSession,
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusConflict)),
+ },
+ "CONFLICT when DELETING SERVER when its the ONLY ORIGIN SERVER ASSIGNED": {
+ EndpointId: getServerID(t, "test-mso-org-01"), ClientSession: TOSession,
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusConflict)),
+ },
+ },
+ "SERVER STATUS PUT": {
+ "BAD REQUEST when UPDATING SERVER STATUS when ONLY EDGE SERVER ASSIGNED": {
+ EndpointId: getServerID(t, "test-ds-server-assignments"), ClientSession: TOSession,
+ RequestBody: map[string]interface{}{
+ "status": "ADMIN_DOWN",
+ "offlineReason": "admin down",
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusConflict)),
+ },
+ "BAD REQUEST when UPDATING SERVER STATUS when ONLY ORIGIN SERVER ASSIGNED": {
+ EndpointId: getServerID(t, "test-mso-org-01"), ClientSession: TOSession,
+ RequestBody: map[string]interface{}{
+ "status": "ADMIN_DOWN",
+ "offlineReason": "admin down",
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusConflict)),
+ },
+ },
+ }
+ for method, testCases := range dssTests {
+ t.Run(method, func(t *testing.T) {
+ for name, testCase := range testCases {
+ var dsID int
+ var replace bool
+ var serverIDs []int
+ status := tc.ServerPutStatus{}
+
+ if testCase.RequestBody != nil {
+ if val, ok := testCase.RequestBody["dsId"]; ok {
+ dsID = val.(int)
+ }
+ if val, ok := testCase.RequestBody["replace"]; ok {
+ replace = val.(bool)
+ }
+ if val, ok := testCase.RequestBody["servers"]; ok {
+ serverIDs = val.([]int)
+ }
+ if _, ok := testCase.RequestBody["offlineReason"]; ok {
+ dat, err := json.Marshal(testCase.RequestBody)
+ assert.NoError(t, err, "Error occurred when marshalling request body: %v", err)
+ err = json.Unmarshal(dat, &status)
+ assert.NoError(t, err, "Error occurred when unmarshalling request body: %v", err)
+ }
+ }
-func TestDeliveryServiceServersWithRequiredCapabilities(t *testing.T) {
- WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, ServerCapabilities, Topologies, ServiceCategories, DeliveryServices, DeliveryServicesRequiredCapabilities, ServerServerCapabilities}, func() {
- CreateTestDeliveryServiceServersWithRequiredCapabilities(t)
- CreateTestMSODSServerWithReqCap(t)
+ switch method {
+ case "GET":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.GetDeliveryServiceServers(testCase.RequestOpts)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, resp.Response, resp.Alerts, err)
+ }
+ })
+ case "POST":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.CreateDeliveryServiceServers(dsID, serverIDs, replace, testCase.RequestOpts)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, resp.Response, resp.Alerts, err)
+ }
+ })
+ case "SERVER DELETE":
+ t.Run(name, func(t *testing.T) {
+ alerts, reqInf, err := testCase.ClientSession.DeleteServer(testCase.EndpointId(), testCase.RequestOpts)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, nil, alerts, err)
+ }
+ })
+ case "SERVER STATUS PUT":
+ t.Run(name, func(t *testing.T) {
+ alerts, reqInf, err := testCase.ClientSession.UpdateServerStatus(testCase.EndpointId(), status, testCase.RequestOpts)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, nil, alerts, err)
+ }
+ })
+ }
+ }
+ })
+ }
})
}
-const dssaTestingXMLID = "test-ds-server-assignments"
-
-func TryToRemoveLastServerInDeliveryService(t *testing.T) {
- opts := client.NewRequestOptions()
- opts.QueryParameters.Set("xmlId", dssaTestingXMLID)
- dses, _, err := TOSession.GetDeliveryServices(opts)
- if err != nil {
- t.Fatalf("Unexpected error trying to get Delivery service with XMLID '%s': %v - alerts: %+v", dssaTestingXMLID, err, dses.Alerts)
- }
- if len(dses.Response) != 1 {
- t.Fatalf("Expected exactly one Delivery service with XMLID '%s', got: %d", dssaTestingXMLID, len(dses.Response))
- }
- ds := dses.Response[0]
- if ds.ID == nil {
- t.Fatalf("Delivery Service '%s' has no ID", dssaTestingXMLID)
- }
-
- statuses, _, err := TOSession.GetStatuses(client.RequestOptions{})
- if err != nil {
- t.Fatalf("Could not fetch Statuses: %v - alerts: %+v", err, statuses.Alerts)
- }
- if len(statuses.Response) < 1 {
- t.Fatal("Need at least one Status")
- }
-
- var badStatusID int
- found := false
- for _, status := range statuses.Response {
- if status.Name != tc.CacheStatusOnline.String() && status.Name != tc.CacheStatusReported.String() {
- badStatusID = status.ID
- found = true
- break
+func TestDeliveryServiceXMLIDServers(t *testing.T) {
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, ServiceCategories, DeliveryServices, DeliveryServiceServerAssignments}, func() {
+ dsXMLIDServersTests := utils.V4TestCase{
+ "POST": {
+ "BAD REQUEST when ASSIGNING SERVERS to a TOPOLOGY DS": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "xmlID": "ds-top",
+ "serverNames": []string{"atlanta-edge-01", "atlanta-edge-03"},
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ "BAD REQUEST when ASSIGNING ORG SERVER NOT IN CACHEGROUP of TOPOLOGY DS": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "xmlID": "ds-top-req-cap",
+ "serverNames": []string{"denver-mso-org-01"},
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ "OK when ASSIGNING ORG SERVER IN CACHEGROUP of TOPOLOGY DS": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "xmlID": "ds-top",
+ "serverNames": []string{"test-mso-org-01"},
+ },
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ },
}
- }
- if !found {
- t.Fatalf("Need at least one status with a name other than '%s' or '%s'", tc.CacheStatusOnline, tc.CacheStatusReported)
- }
-
- server := getServer(dssaTestingXMLID, t)
- orgServer := getServer("test-mso-org-01", t)
-
- resp, _, err := TOSession.CreateDeliveryServiceServers(*ds.ID, []int{*server.ID, *orgServer.ID}, true, client.RequestOptions{})
- if err != nil {
- t.Fatalf("Failed to assign servers to Delivery Service: %v - alerts: %+v", err, resp.Alerts)
- }
-
- _, _, err = TOSession.CreateDeliveryServiceServers(*ds.ID, []int{*orgServer.ID}, true, client.RequestOptions{})
- if err == nil {
- t.Error("Didn't get expected error trying to remove the only EDGE server assigned to a Delivery Service")
- }
-
- _, _, err = TOSession.CreateDeliveryServiceServers(*ds.ID, []int{*server.ID}, true, client.RequestOptions{})
- if err == nil {
- t.Error("Didn't get expected error trying to remove the only ORG server assigned to an MSO-enabled Delivery Service")
- }
-
- _, _, err = TOSession.DeleteDeliveryServiceServer(*ds.ID, *server.ID, client.RequestOptions{})
- if err == nil {
- t.Error("Didn't get expected error trying to remove the only EDGE server assigned to a Delivery Service")
- }
-
- _, _, err = TOSession.DeleteDeliveryServiceServer(*ds.ID, *orgServer.ID, client.RequestOptions{})
- if err == nil {
- t.Error("Didn't get expected error trying to remove the only ORG server assigned to an MSO-enabled Delivery Service")
- }
-
- alerts, _, err := TOSession.DeleteServer(*server.ID, client.RequestOptions{})
- if err == nil {
- t.Error("Didn't get expected error trying to delete the only EDGE server assigned to a Delivery Service")
- } else {
- t.Logf("Got expected error trying to delete the only EDGE server assigned to a Delivery Service: %v - alerts: %+v", err, alerts.Alerts)
- }
-
- alerts, _, err = TOSession.DeleteServer(*orgServer.ID, client.RequestOptions{})
- if err == nil {
- t.Error("Didn't get expected error trying to delete the only ORG server assigned to an MSO-enabled Delivery Service")
- } else {
- t.Logf("Got expected error trying to delete the only ORG server assigned to an MSO-enabled Delivery Service: %v - alerts: %+v", err, alerts.Alerts)
- }
-
- alerts, _, err = TOSession.AssignDeliveryServiceIDsToServerID(*server.ID, []int{}, true, client.RequestOptions{})
- if err == nil {
- t.Error("Didn't get expected error trying to remove a Delivery Service from the only EDGE server to which it is assigned")
- } else {
- t.Logf("Got expected error trying to remove a Delivery Service from the only EDGE server to which it is assigned: %v - alerts: %+v", err, alerts.Alerts)
- }
-
- alerts, _, err = TOSession.AssignDeliveryServiceIDsToServerID(*orgServer.ID, []int{}, true, client.RequestOptions{})
- if err == nil {
- t.Error("Didn't get expected error trying to remove a Delivery Service from the only EDGE server to which it is assigned")
- } else {
- t.Logf("Got expected error trying to remove a Delivery Service from the only EDGE server to which it is assigned: %v - alerts: %+v", err, alerts.Alerts)
- }
-
- server.StatusID = &badStatusID
- orgServer.StatusID = &badStatusID
- putRequest := tc.ServerPutStatus{
- Status: util.JSONNameOrIDStr{ID: &badStatusID},
- OfflineReason: util.StrPtr("test"),
- }
- alerts, _, err = TOSession.UpdateServerStatus(*server.ID, putRequest, client.RequestOptions{})
- if err == nil {
- t.Error("Didn't get expected error trying to put server into a bad state when it's the only EDGE assigned to a Delivery Service")
- } else {
- t.Logf("Got expected error trying to put server into a bad state when it's the only EDGE assigned to a Delivery Service: %v - alerts: %+v", err, alerts.Alerts)
- }
- alerts, _, err = TOSession.UpdateServerStatus(*orgServer.ID, putRequest, client.RequestOptions{})
- if err == nil {
- t.Error("Didn't get expected error trying to put server into a bad state when it's the only ORG assigned to an MSO Delivery Service")
- } else {
- t.Logf("Got expected error trying to put server into a bad state when it's the only ORG assigned to an MSO Delivery Service: %v - alerts: %+v", err, alerts.Alerts)
- }
-
- alerts, _, err = TOSession.UpdateServer(*server.ID, server, client.RequestOptions{})
- if err == nil {
- t.Error("Didn't get expected error trying to put server into a bad state when it's the only EDGE assigned to a Delivery Service")
- } else {
- t.Logf("Got expected error trying to put server into a bad state when it's the only EDGE assigned to a Delivery Service: %v - alerts: %+v", err, alerts.Alerts)
- }
- alerts, _, err = TOSession.UpdateServer(*orgServer.ID, orgServer, client.RequestOptions{})
- if err == nil {
- t.Error("Didn't get expected error trying to put server into a bad state when it's the only ORG assigned to an MSO Delivery Service")
- } else {
- t.Logf("Got expected error trying to put server into a bad state when it's the only ORG assigned to an MSO Delivery Service: %v - alerts: %+v", err, alerts.Alerts)
- }
+ for method, testCases := range dsXMLIDServersTests {
+ t.Run(method, func(t *testing.T) {
+ for name, testCase := range testCases {
+ var xmlID string
+ var servers []string
+
+ if testCase.RequestBody != nil {
+ if val, ok := testCase.RequestBody["xmlID"]; ok {
+ xmlID = val.(string)
+ }
+ if val, ok := testCase.RequestBody["serverNames"]; ok {
+ servers = val.([]string)
+ }
+ }
- server.HostName = util.StrPtr(dssaTestingXMLID + "-quest")
- server.ID = nil
- interfaces := server.Interfaces
- for interfaceIndex, i := range interfaces {
- ipAddresses := i.IPAddresses
- for index, ip := range ipAddresses {
- if ip.ServiceAddress {
- str := "100.100.100."
- ip.Address = str + strconv.Itoa(index)
- }
- ipAddresses[index] = ip
+ switch method {
+ case "POST":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.AssignServersToDeliveryService(servers, xmlID, testCase.RequestOpts)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, nil, resp, err)
+ }
+ })
+ }
+ }
+ })
}
- interfaces[interfaceIndex].IPAddresses = ipAddresses
- }
- server.Interfaces = interfaces
- alerts, _, err = TOSession.CreateServer(server, client.RequestOptions{})
- if err != nil {
- t.Fatalf("Failed to create server: %v - alerts: %+v", err, alerts.Alerts)
- }
- server = getServer(*server.HostName, t)
-
- _, _, err = TOSession.CreateDeliveryServiceServers(*ds.ID, []int{*server.ID}, true, client.RequestOptions{})
- if err == nil {
- t.Error("Didn't get expected error trying to replace the last EDGE server assigned to a Delivery Service with a server in a bad state")
- }
-
- // Cleanup
- setInactive(t, *ds.ID)
- alerts, _, err = TOSession.DeleteServer(*server.ID, client.RequestOptions{})
- if err != nil {
- t.Errorf("Failed to delete server: %v - alerts: %+v", err, alerts.Alerts)
- }
-}
-
-func getServer(hostname string, t *testing.T) tc.ServerV4 {
- opts := client.NewRequestOptions()
- opts.QueryParameters = url.Values{}
- opts.QueryParameters.Set("hostName", hostname)
- servers, _, err := TOSession.GetServers(opts)
- if err != nil {
- t.Fatalf("Unexpected error fetching server '%s': %v - alerts: %+v", hostname, err, servers.Alerts)
- }
- if len(servers.Response) != 1 {
- t.Fatalf("Expected exactly one server with FQDN '%s', got: %d", hostname, len(servers.Response))
- }
- server := servers.Response[0]
- if server.ID == nil {
- t.Fatal("Server had null/undefined ID after creation")
- }
- return server
-}
-
-func GetTestDSSIMS(t *testing.T) {
- const noLimit = 999999
-
- limit := noLimit
- opts := client.NewRequestOptions()
- opts.QueryParameters.Set("limit", strconv.Itoa(limit))
- _, reqInf, err := TOSession.GetDeliveryServiceServers(opts)
- if err != nil {
- t.Errorf("deliveryserviceservers expected: no error, actual: %v", err)
- } else if reqInf.StatusCode != http.StatusOK {
- t.Errorf("expected deliveryserviceservers response code %v, actual %v", http.StatusOK, reqInf.StatusCode)
- }
-
- opts.Header.Set(rfc.IfModifiedSince, time.Now().UTC().Add(2*time.Second).Format(time.RFC1123))
- _, reqInf, err = TOSession.GetDeliveryServiceServers(opts)
- if err != nil {
- t.Errorf("deliveryserviceservers IMS request expected: no error, actual: %v", err)
- } else if reqInf.StatusCode != http.StatusNotModified {
- t.Errorf("expected deliveryserviceservers IMS response code %v, actual %v", http.StatusNotModified, reqInf.StatusCode)
- }
+ })
}
-func AssignServersToTopologyBasedDeliveryService(t *testing.T) {
- opts := client.NewRequestOptions()
- opts.QueryParameters.Set("xmlId", "ds-top")
- ds, _, err := TOSession.GetDeliveryServices(opts)
- if err != nil {
- t.Fatalf("cannot get Delivery Service 'ds-top': %v - alerts: %+v", err, ds.Alerts)
- }
- if len(ds.Response) != 1 {
- t.Fatalf("expected one delivery service: 'ds-top', actual: %v", len(ds.Response))
- }
- d := ds.Response[0]
- if d.Topology == nil || d.ID == nil || d.CDNID == nil || d.CDNName == nil {
- t.Fatal("Traffic Ops returned a representation of a Delivery Service that had null or undefined Topology and/or CDN ID and/or CDN Name and/or ID")
- }
- serversResp, _, err := TOSession.GetServers(client.RequestOptions{})
- servers := []tc.ServerV4{}
- for _, s := range serversResp.Response {
- if s.CDNID != nil && *s.CDNID == *d.CDNID && s.Type == tc.CacheTypeEdge.String() {
- servers = append(servers, s)
+func TestDeliveryServicesIDServers(t *testing.T) {
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, ServiceCategories, DeliveryServices, DeliveryServiceServerAssignments}, func() {
+ dsIDServersTests := utils.V4TestCase{
+ "GET": {
+ "OK when VALID request": {
+ EndpointId: GetDeliveryServiceId(t, "test-ds-server-assignments"), ClientSession: TOSession,
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
+ utils.ResponseHasLength(2)),
+ },
+ },
}
- }
- if len(servers) < 1 {
- t.Fatalf("expected: at least one EDGE in cdn %s, actual: %v", *d.CDNName, servers)
- }
- if servers[0].ID == nil {
- t.Fatal("Traffic ops returned a representation of a Server that had a null or undefined ID")
- }
- serverNames := []string{}
- for _, s := range servers {
- if s.CDNID != nil && s.HostName != nil && *s.CDNID == *d.CDNID && s.Type == tc.CacheTypeEdge.String() {
- serverNames = append(serverNames, *s.HostName)
- } else {
- t.Fatalf("expected only EDGE servers in cdn '%s', actual: %v", *d.CDNName, servers)
+ for method, testCases := range dsIDServersTests {
+ t.Run(method, func(t *testing.T) {
+ for name, testCase := range testCases {
+ switch method {
+ case "GET":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.GetServersByDeliveryService(testCase.EndpointId(), testCase.RequestOpts)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, resp.Response, resp.Alerts, err)
+ }
+ })
+ }
+ }
+ })
}
- }
- _, reqInf, err := TOSession.AssignServersToDeliveryService(serverNames, "ds-top", client.RequestOptions{})
- if err == nil {
- t.Fatal("assigning servers to topology-based delivery service - expected: error, actual: nil error")
- }
- if reqInf.StatusCode < http.StatusBadRequest || reqInf.StatusCode >= http.StatusInternalServerError {
- t.Fatalf("assigning servers to topology-based delivery service - expected: 400-level status code, actual: %d", reqInf.StatusCode)
- }
-
- _, reqInf, err = TOSession.CreateDeliveryServiceServers(*d.ID, []int{*servers[0].ID}, false, client.RequestOptions{})
- if err == nil {
- t.Fatal("creating deliveryserviceserver assignment for topology-based delivery service - expected: error, actual: nil error")
- }
- if reqInf.StatusCode < http.StatusBadRequest || reqInf.StatusCode >= http.StatusInternalServerError {
- t.Fatalf("creating deliveryserviceserver assignment for topology-based delivery service - expected: 400-level status code, actual: %d", reqInf.StatusCode)
- }
-}
-
-func AssignOriginsToTopologyBasedDeliveryServices(t *testing.T) {
- // attempt to assign ORG server to a topology-based DS while the ORG server's cachegroup doesn't belong to the topology
- opts := client.NewRequestOptions()
- opts.QueryParameters.Add("hostName", "denver-mso-org-01")
- resp, _, err := TOSession.GetServers(opts)
- if err != nil {
- t.Fatalf("unable to get server 'denver-mso-org-01': %v - alerts: %+v", err, resp.Alerts)
- }
- if len(resp.Response) != 1 {
- t.Fatalf("Expected exactly one server to exist with Host Name 'denver-mso-org-01': %d", len(resp.Response))
- }
- orgServer := resp.Response[0]
- _, reqInf, err := TOSession.AssignServersToDeliveryService([]string{*orgServer.HostName}, "ds-top-req-cap", client.RequestOptions{})
- if err == nil {
- t.Fatal("assigning ORG server to topology-based delivery service while the ORG server's cachegroup does not belong to the topology - expected: error, actual: nil error")
- }
- if reqInf.StatusCode < http.StatusBadRequest || reqInf.StatusCode >= http.StatusInternalServerError {
- t.Fatalf("assigning ORG server to topology-based delivery service while the ORG server's cachegroup does not belong to the topology - expected: 400-level status code, actual: %d", reqInf.StatusCode)
- }
- opts.QueryParameters.Del("hostName")
- opts.QueryParameters.Set("xmlId", "ds-top-req-cap")
- ds, _, err := TOSession.GetDeliveryServices(opts)
- if err != nil {
- t.Fatalf("cannot get Delivery Service 'ds-top-req-cap': %v - alerts: %+v", err, ds.Alerts)
- }
- if len(ds.Response) != 1 {
- t.Fatalf("expected one delivery service: 'ds-top-req-cap', actual: %v", len(ds.Response))
- }
- d := ds.Response[0]
- if d.Topology == nil || d.ID == nil {
- t.Fatal("Traffic Ops returned a representation of a Delivery Service that had null or undefined Topology and/or ID")
- }
- _, reqInf, err = TOSession.CreateDeliveryServiceServers(*d.ID, []int{*orgServer.ID}, false, client.RequestOptions{})
- if err == nil {
- t.Fatal("creating deliveryserviceserver assignment for ORG server to topology-based delivery service while the ORG server's cachegroup does not belong to the topology - expected: error, actual: nil error")
- }
- if reqInf.StatusCode < http.StatusBadRequest || reqInf.StatusCode >= http.StatusInternalServerError {
- t.Fatalf("creating deliveryserviceserver assignment for ORG server to topology-based delivery service while the ORG server's cachegroup does not belong to the topology - expected: 400-level status code, actual: %d", reqInf.StatusCode)
- }
-
- // attempt to assign ORG server to a topology-based DS while the ORG server's cachegroup belongs to the topology
- assignResp, reqInf, err := TOSession.AssignServersToDeliveryService([]string{*orgServer.HostName}, "ds-top", client.RequestOptions{})
- if err != nil {
- t.Fatalf("assigning Origin server '%s' to Topology-based Delivery Service 'ds-top' while the ORG server's Cache Group belongs to the Topology - expected: no error, actual: %v - alerts: %+v", *orgServer.HostName, err, assignResp.Alerts)
- }
- if reqInf.StatusCode < http.StatusOK || reqInf.StatusCode >= http.StatusMultipleChoices {
- t.Fatalf("assigning ORG server to topology-based delivery service while the ORG server's cachegroup belongs to the topology - expected: 200-level status code, actual: %d", reqInf.StatusCode)
- }
- opts.QueryParameters.Set("xmlId", "ds-top")
- ds, _, err = TOSession.GetDeliveryServices(opts)
- if err != nil {
- t.Fatalf("cannot get Delivery Service 'ds-top': %v - alerts: %+v", err, ds.Alerts)
- }
- if len(ds.Response) != 1 {
- t.Fatalf("expected one delivery service: 'ds-top', actual: %v", len(ds.Response))
- }
- d = ds.Response[0]
- if d.Topology == nil || d.ID == nil {
- t.Fatal("Traffic Ops returned a representation of a Delivery Service that had null or undefined Topology and/or ID")
- }
- alerts, reqInf, err := TOSession.CreateDeliveryServiceServers(*d.ID, []int{*orgServer.ID}, true, client.RequestOptions{})
- if err != nil {
- t.Fatalf("assigning Origin server #%d to Topology-based Delivery Service #%d while the server's Cache Group belongs to the Topology - expected: no error, actual: %v - alerts: %+v", *orgServer.ID, *d.ID, err, alerts.Alerts)
- }
- if reqInf.StatusCode < http.StatusOK || reqInf.StatusCode >= http.StatusMultipleChoices {
- t.Fatalf("creating deliveryserviceserver assignment for ORG server to topology-based delivery service while the ORG server's cachegroup belongs to the topology - expected: 200-level status code, actual: %d", reqInf.StatusCode)
- }
+ })
}
-func AssignServersToNonTopologyBasedDeliveryServiceThatUsesMidTier(t *testing.T) {
- opts := client.NewRequestOptions()
- opts.QueryParameters.Set("xmlId", "ds1")
- resp, _, err := TOSession.GetDeliveryServices(opts)
- if err != nil {
- t.Fatalf("cannot get Delivery Service 'ds1': %v - alerts: %+v", err, resp.Alerts)
- }
- if len(resp.Response) != 1 {
- t.Fatalf("expected one delivery service: 'ds1', actual: %d", len(resp.Response))
- }
- dsWithMid := resp.Response[0]
- if dsWithMid.Topology != nil {
- t.Fatal("expected delivery service: 'ds1' to have a nil Topology, actual: non-nil")
- }
- if dsWithMid.CDNID == nil || dsWithMid.CDNName == nil || dsWithMid.ID == nil {
- t.Fatal("Traffic Ops returned a representation of a Delivery Service that had null or undefined CDN ID and/or CDN Name and/or ID")
- }
- serversResp, _, err := TOSession.GetServers(client.RequestOptions{})
- if err != nil {
- t.Fatalf("unable to fetch all servers: %v - alerts: %+v", err, serversResp.Alerts)
- }
- serversIds := []int{}
- for _, s := range serversResp.Response {
- if s.CDNID != nil && *s.CDNID == *dsWithMid.CDNID && s.Type == tc.CacheTypeEdge.String() {
- serversIds = append(serversIds, *s.ID)
+func TestServersIDDeliveryServices(t *testing.T) {
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, ServiceCategories, DeliveryServices, DeliveryServiceServerAssignments}, func() {
+ serversIDDSTests := utils.V4TestCase{
+ "POST": {
+ "BAD REQUEST when REMOVING ONLY EDGE SERVER ASSIGNMENT": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "server": getServerID(t, "test-mso-org-01")(),
+ "dsIds": []int{GetDeliveryServiceId(t, "test-ds-server-assignments")()},
+ "replace": true,
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusConflict)),
+ },
+ "BAD REQUEST when REMOVING ONLY ORIGIN SERVER ASSIGNMENT": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "server": getServerID(t, "test-ds-server-assignments")(),
+ "dsIds": []int{GetDeliveryServiceId(t, "test-ds-server-assignments")()},
+ "replace": true,
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusConflict)),
+ },
+ },
}
- }
- if len(serversIds) < 1 {
- t.Fatalf("expected: at least one EDGE in cdn %s, actual: 0", *dsWithMid.CDNName)
- }
-
- assignResp, _, err := TOSession.CreateDeliveryServiceServers(*dsWithMid.ID, serversIds, true, client.RequestOptions{})
- if err != nil {
- t.Fatalf("Unexpected error assigning servers %v to Delivery Service #%d: %v - alerts: %+v", serversIds, *dsWithMid.ID, err, assignResp.Alerts)
- }
-
- opts.QueryParameters = url.Values{"dsId": []string{strconv.Itoa(*dsWithMid.ID)}}
- dsServersResp, _, err := TOSession.GetServers(opts)
- if err != nil {
- t.Fatalf("unable to fetch Delivery Service #%d servers: %v - alerts: %+v", *dsWithMid.ID, err, dsServersResp.Alerts)
- }
- dsServerIds := []int{}
- for _, dss := range dsServersResp.Response {
- dsServerIds = append(dsServerIds, *dss.ID)
- }
- if len(dsServerIds) <= len(serversIds) {
- t.Fatalf("delivery service servers (%d) expected to exceed directly assigned servers (%d) to account for implicitly assigned mid servers", len(dsServerIds), len(serversIds))
- }
+ for method, testCases := range serversIDDSTests {
+ t.Run(method, func(t *testing.T) {
+ for name, testCase := range testCases {
+
+ var server int
+ var replace bool
+
+ if testCase.RequestBody != nil {
+ if val, ok := testCase.RequestBody["server"]; ok {
+ server = val.(int)
+ }
+ if val, ok := testCase.RequestBody["replace"]; ok {
+ replace = val.(bool)
+ }
+ }
- for _, dss := range dsServersResp.Response {
- if dss.CDNID != nil && *dss.CDNID != *dsWithMid.CDNID {
- t.Fatalf("a server for another cdn was returned for this delivery service")
+ switch method {
+ case "POST":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.AssignDeliveryServiceIDsToServerID(server, []int{}, replace, testCase.RequestOpts)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, nil, resp, err)
+ }
+ })
+ }
+ }
+ })
}
- }
+ })
}
-func CreateTestDeliveryServiceServersWithRequiredCapabilities(t *testing.T) {
- sscs := testData.ServerServerCapabilities
-
- testCases := []struct {
- ds string
- serverName string
- ssc tc.ServerServerCapability
- description string
- err error
- capability tc.DeliveryServicesRequiredCapability
- }{
- {
- serverName: "atlanta-edge-01",
- description: "missing requirements for server -> DS assignment",
- err: errors.New("cannot be assigned to this delivery service"),
- ssc: sscs[0],
- capability: tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: helperGetDeliveryServiceID(t, util.StrPtr("ds-test-minor-versions")),
- RequiredCapability: sscs[1].ServerCapability,
+func TestDeliveryServicesDSIDServerID(t *testing.T) {
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, ServiceCategories, DeliveryServices, DeliveryServiceServerAssignments}, func() {
+ dssDSIDServerIDTests := utils.V4TestCase{
+ "DELETE": {
+ "OK when VALID REQUEST": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "server": getServerID(t, "denver-mso-org-01")(),
+ "dsId": GetDeliveryServiceId(t, "ds-top")(),
+ },
+ Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ },
+ "BAD REQUEST when REMOVING ONLY EDGE SERVER ASSIGNMENT": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "server": getServerID(t, "test-ds-server-assignments")(),
+ "dsId": GetDeliveryServiceId(t, "test-ds-server-assignments")(),
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusConflict)),
+ },
+ "BAD REQUEST when REMOVING ONLY ORIGIN SERVER ASSIGNMENT": {
+ ClientSession: TOSession, RequestBody: map[string]interface{}{
+ "server": getServerID(t, "test-mso-org-01")(),
+ "dsId": GetDeliveryServiceId(t, "test-ds-server-assignments")(),
+ },
+ Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusConflict)),
+ },
},
- },
- {
- serverName: "atlanta-mid-01",
- description: "successful server -> DS assignment",
- err: nil,
- ssc: sscs[1],
- capability: tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: helperGetDeliveryServiceID(t, util.StrPtr("ds3")),
- RequiredCapability: sscs[1].ServerCapability,
- },
- },
- }
-
- for _, ctc := range testCases {
- if ctc.capability.DeliveryServiceID == nil || ctc.capability.RequiredCapability == nil {
- t.Errorf("Bad hard-coded test case '%s' - MUST include non-nil DeliveryServiceID and RequiredCapability", ctc.description)
- continue
}
- t.Run(ctc.description, func(t *testing.T) {
- opts := client.NewRequestOptions()
- opts.QueryParameters.Set("hostName", ctc.serverName)
- resp, _, err := TOSession.GetServers(opts)
- if err != nil {
- t.Fatalf("cannot get Server '%s' by hostname: %v - alerts: %+v", ctc.serverName, err, resp.Alerts)
- }
- servers := resp.Response
- if len(servers) < 1 {
- t.Fatalf("Expected at least one server to exist with Host Name '%s', found none", ctc.serverName)
- }
- server := servers[0]
- if server.ID == nil {
- t.Fatalf("server %s had nil ID", ctc.serverName)
- }
-
- alerts, _, err := TOSession.CreateDeliveryServicesRequiredCapability(ctc.capability, client.RequestOptions{})
- if err != nil {
- t.Fatalf("Unexpected error creating a relationship between a Delivery Service and a Capability it requires: %v - alerts: %+v", err, alerts.Alerts)
- }
-
- ctc.ssc.ServerID = server.ID
- sscResp, _, err := TOSession.CreateServerServerCapability(ctc.ssc, client.RequestOptions{})
- if err != nil {
- t.Fatalf("could not associate Capability '%s' to server #%d: %v - alerts: %+v", *ctc.ssc.ServerCapability, *ctc.ssc.ServerID, err, sscResp.Alerts)
- }
+ for method, testCases := range dssDSIDServerIDTests {
+ t.Run(method, func(t *testing.T) {
+ for name, testCase := range testCases {
+ var dsID int
+ var serverId int
+
+ if testCase.RequestBody != nil {
+ if val, ok := testCase.RequestBody["server"]; ok {
+ serverId = val.(int)
+ }
+ if val, ok := testCase.RequestBody["dsId"]; ok {
+ dsID = val.(int)
+ }
+ }
- assignResp, _, got := TOSession.CreateDeliveryServiceServers(*ctc.capability.DeliveryServiceID, []int{*server.ID}, true, client.RequestOptions{})
- if ctc.err == nil && got != nil {
- t.Fatalf("Unexpected error creating server-to-Delivery-Service assignments: %v - alerts: %+v", err, assignResp.Alerts)
- } else if ctc.err != nil {
- found := false
- for _, alert := range assignResp.Alerts.Alerts {
- if alert.Level == tc.ErrorLevel.String() && strings.Contains(alert.Text, ctc.err.Error()) {
- found = true
+ switch method {
+ case "DELETE":
+ t.Run(name, func(t *testing.T) {
+ resp, reqInf, err := testCase.ClientSession.DeleteDeliveryServiceServer(dsID, serverId, testCase.RequestOpts)
+ for _, check := range testCase.Expectations {
+ check(t, reqInf, nil, resp, err)
+ }
+ })
}
}
- if !found {
- t.Fatalf("Expected to find an error-level alert relating to '%v', but it wasn't found. Actual alerts: %v", ctc.err, assignResp.Alerts.Alerts)
- }
- }
-
- alerts, _, err = TOSession.DeleteDeliveryServicesRequiredCapability(*ctc.capability.DeliveryServiceID, *ctc.capability.RequiredCapability, client.RequestOptions{})
- if err != nil {
- t.Fatalf("Unexpected error deleting a relationship between a Delivery Service and a Capability it requires: %v - alerts: %+v", err, alerts.Alerts)
- }
- })
- }
-}
-
-func GetTestDSServerByCDN(t *testing.T) {
- opts := client.NewRequestOptions()
- cdns, _, err := TOSession.GetCDNs(opts)
- if err != nil {
- t.Fatalf("unexpected error getting CDNs: %v", err)
- } else if len(cdns.Response) < 2 {
- t.Fatalf("expected at least 2 CDNs but got %d instead", len(cdns.Response))
- }
- dses, _, err := TOSession.GetDeliveryServices(opts)
- if err != nil {
- t.Fatalf("unexpected error getting delivery services: %v", err)
- }
- cdnNonTopologyDSMap := make(map[int][]int)
- dsMap := make(map[int]tc.DeliveryServiceV4)
- for _, ds := range dses.Response {
- dsMap[*ds.ID] = ds
- if ds.Topology != nil && *ds.Topology != "" {
- continue
+ })
}
- cdnNonTopologyDSMap[*ds.CDNID] = append(cdnNonTopologyDSMap[*ds.CDNID], *ds.ID)
- }
- servers, _, err := TOSession.GetServers(opts)
- if err != nil {
- t.Fatalf("unexpected error getting servers: %v", err)
- }
- serverMap := make(map[int]tc.ServerV4)
- cdnEdgeMap := make(map[int][]int)
- for _, server := range servers.Response {
- serverMap[*server.ID] = server
- if !strings.HasPrefix(server.Type, tc.EdgeTypePrefix) {
- continue
- }
- cdnEdgeMap[*server.CDNID] = append(cdnEdgeMap[*server.CDNID], *server.ID)
- }
- emptyCDN := tc.CDN{}
- cdn1 := tc.CDN{}
- cdn2 := tc.CDN{}
- for i, cdn := range cdns.Response {
- if len(cdnNonTopologyDSMap[cdn.ID]) > 0 && len(cdnEdgeMap[cdn.ID]) > 0 {
- if cdn1 == emptyCDN {
- cdn1 = cdns.Response[i]
- } else {
- cdn2 = cdns.Response[i]
- break
- }
- }
- }
- if cdn1 == emptyCDN || cdn2 == emptyCDN {
- t.Fatalf("expected at least 2 CDNs with at least 1 non-topology-based deliveryservice and 1 edge each")
- }
- _, _, err = TOSession.CreateDeliveryServiceServers(cdnNonTopologyDSMap[cdn1.ID][0], []int{cdnEdgeMap[cdn1.ID][0]}, true, client.RequestOptions{})
- if err != nil {
- t.Fatalf("unexpected error creating delivery service servers: %v", err)
- }
- _, _, err = TOSession.CreateDeliveryServiceServers(cdnNonTopologyDSMap[cdn2.ID][0], []int{cdnEdgeMap[cdn2.ID][0]}, true, client.RequestOptions{})
- if err != nil {
- t.Fatalf("unexpected error creating delivery service servers: %v", err)
- }
-
- opts.QueryParameters.Set("cdn", cdn1.Name)
- opts.QueryParameters.Set("limit", "999999999")
- dss, _, err := TOSession.GetDeliveryServiceServers(opts)
- if err != nil {
- t.Fatalf("unexpected error getting delivery service servers by cdn: %v", err)
- } else if len(dss.Response) < 1 {
- t.Fatalf("getting delivery service servers - expected: at least 1, actual: %d", len(dss.Response))
- }
- for _, d := range dss.Response {
- if *dsMap[*d.DeliveryService].CDNID != cdn1.ID {
- t.Errorf("getting delivery service servers by cdn (%s) - found entry that did not match the given cdn (server hostname = %s, server CDN name = %s, delivery service xmlId = %s, delivery service CDN name = %s", cdn1.Name, *serverMap[*d.Server].HostName, *serverMap[*d.Server].CDNName, *dsMap[*d.DeliveryService].XMLID, *dsMap[*d.DeliveryService].CDNName)
- }
- }
- opts.QueryParameters.Set("cdn", cdn2.Name)
- dss, _, err = TOSession.GetDeliveryServiceServers(opts)
- if err != nil {
- t.Fatalf("unexpected error getting delivery service servers by cdn: %v", err)
- } else if len(dss.Response) < 1 {
- t.Fatalf("getting delivery service servers - expected: at least 1, actual: %d", len(dss.Response))
- }
- for _, d := range dss.Response {
- if *dsMap[*d.DeliveryService].CDNID != cdn2.ID {
- t.Errorf("getting delivery service servers by cdn (%s) - found entry that did not match the given cdn", cdn2.Name)
- t.Errorf("getting delivery service servers by cdn (%s) - found entry that did not match the given cdn (server hostname = %s, server CDN name = %s, delivery service xmlId = %s, delivery service CDN name = %s", cdn2.Name, *serverMap[*d.Server].HostName, *serverMap[*d.Server].CDNName, *dsMap[*d.DeliveryService].XMLID, *dsMap[*d.DeliveryService].CDNName)
- }
- }
-}
-
-func CreateTestMSODSServerWithReqCap(t *testing.T) {
- opts := client.NewRequestOptions()
- opts.QueryParameters.Set("xmlID", "msods1")
- dsReqCap, _, err := TOSession.GetDeliveryServicesRequiredCapabilities(opts)
- if err != nil {
- t.Fatalf("Unexpected error retrieving relationships between Delivery Services and Capabilities they require: %v - alerts: %+v", err, dsReqCap.Alerts)
- }
-
- if len(dsReqCap.Response) == 0 {
- t.Fatal("no delivery service required capabilites found for ds msods1")
- }
- dsrc := dsReqCap.Response[0]
- if dsrc.DeliveryServiceID == nil {
- t.Fatal("Traffic Ops returned a representation of a Delivery Service/Required Capability relationship with null or undefined Delivery Service ID")
- }
-
- // Associate origin server to msods1 even though it does not have req cap
- // TODO: DON'T hard-code server hostnames!
- opts.QueryParameters = url.Values{}
- opts.QueryParameters.Set("hostName", "denver-mso-org-01")
- resp, _, err := TOSession.GetServers(opts)
- if err != nil {
- t.Fatalf("getting server denver-mso-org-01: %v - alerts: %+v", err, resp.Alerts)
- }
- servers := resp.Response
- if len(servers) != 1 {
- t.Fatal("expected 1 server with hostname denver-mso-org-01")
- }
-
- s := servers[0]
- if s.ID == nil {
- t.Fatal("server 'denver-mso-org-01' had nil ID")
- }
-
- // Make sure server has no caps to ensure test correctness
- sccsOpts := client.NewRequestOptions()
- sccsOpts.QueryParameters.Set("serverId", strconv.Itoa(*s.ID))
- sccs, _, err := TOSession.GetServerServerCapabilities(sccsOpts)
- if err != nil {
- t.Fatalf("Unexpected error getting Capabilities for server #%d ('denver-mso-org-01'): %v - alerts: %+v", *s.ID, err, sccs.Alerts)
- }
- if len(sccs.Response) != 0 {
- t.Fatal("expected 0 server server capabilities for server denver-mso-org-01")
- }
-
- // Is origin included in eligible servers even though it doesnt have required capability
- eServers, _, err := TOSession.GetDeliveryServicesEligible(*dsrc.DeliveryServiceID, client.RequestOptions{})
- if err != nil {
- t.Fatalf("get delivery service msods1 eligible servers: %v - alerts: %+v", err, eServers.Alerts)
- }
- found := false
- for _, es := range eServers.Response {
- if es.HostName != nil && *es.HostName == "denver-mso-org-01" {
- found = true
- break
- }
- }
- if !found {
- t.Fatal("expected to find origin server denver-mso-org-01 to be in eligible server return even though it is missing a required capability")
- }
-
- if createResp, _, err := TOSession.CreateDeliveryServiceServers(*dsrc.DeliveryServiceID, []int{*s.ID}, true, client.RequestOptions{}); err != nil {
- t.Fatalf("Unexpected error creating server-to-Delivery-Service assignments: %v - alerts: %+v", err, createResp.Alerts)
- }
-
- // Create new bogus server capability
- if alerts, _, err := TOSession.CreateServerCapability(tc.ServerCapability{Name: "newfun"}, client.RequestOptions{}); err != nil {
- t.Fatalf("cannot create 'newfun' Server Capability: %v - alerts: %+v", err, alerts.Alerts)
- }
-
- // Attempt to assign to DS should not fail
- if alerts, _, err := TOSession.CreateDeliveryServicesRequiredCapability(tc.DeliveryServicesRequiredCapability{
- DeliveryServiceID: dsrc.DeliveryServiceID,
- RequiredCapability: util.StrPtr("newfun"),
- }, client.RequestOptions{}); err != nil {
- t.Fatalf("Unexpected error adding Capability 'newfun' as requirement to Delivery Service 'msods1' (#%d): %v - alerts: %+v", *dsrc.DeliveryServiceID, err, alerts.Alerts)
- }
-
- // Remove required capablity
- if alerts, _, err := TOSession.DeleteDeliveryServicesRequiredCapability(*dsrc.DeliveryServiceID, "newfun", client.RequestOptions{}); err != nil {
- t.Fatalf("Unexpected error removing Capability 'newfun' as requirement from Delivery Service 'msods1' (#%d): %v - alerts: %+v", *dsrc.DeliveryServiceID, err, alerts.Alerts)
- }
-
- // Delete server capability
- if alerts, _, err := TOSession.DeleteServerCapability("newfun", client.RequestOptions{}); err != nil {
- t.Fatalf("Unexpected error deleteing the 'newfun' Server Capability: %v - alerts: %+v", err, alerts.Alerts)
- }
+ })
}
func DeleteTestDeliveryServiceServers(t *testing.T) {
- ds, server := getServerAndDSofSameCDN(t)
- if server.ID == nil {
- t.Fatalf("Got a server with a nil ID: %+v", server)
- }
- if ds.ID == nil {
- t.Fatalf("Got a delivery service with a nil ID %+v", ds)
- }
- if ds.Active == nil {
- t.Fatalf("Got a Delivery Service with nil 'Active': %+v", ds)
- }
-
- resp, _, err := TOSession.CreateDeliveryServiceServers(*ds.ID, []int{*server.ID}, true, client.RequestOptions{})
- if err != nil {
- t.Fatalf("Unexpected error creating server-to-Delivery-Service assignments: %v - alerts: %+v", err, resp.Alerts)
- }
-
dsServers, _, err := TOSession.GetDeliveryServiceServers(client.RequestOptions{})
- if err != nil {
- t.Fatalf("Unexpected error retrieving server-to-Delivery-Service assignments: %v - alerts: %+v", err, dsServers.Alerts)
- }
+ assert.NoError(t, err, "Unexpected error retrieving server-to-Delivery-Service assignments: %v - alerts: %+v", err, dsServers.Alerts)
- found := false
for _, dss := range dsServers.Response {
- if dss.DeliveryService != nil && *dss.DeliveryService == *ds.ID && dss.Server != nil && *dss.Server == *server.ID {
- found = true
- break
- }
- }
- if !found {
- t.Error("POST delivery service servers returned success, but ds-server not in GET")
+ // Retrieve Delivery Service in order to update its active field to false
+ opts := client.NewRequestOptions()
+ opts.QueryParameters.Set("id", strconv.Itoa(*dss.DeliveryService))
+ getDS, _, err := TOSession.GetDeliveryServices(opts)
+ assert.NoError(t, err, "Error retrieving Delivery Service: %v - alerts: %+v", err, getDS.Alerts)
+ assert.Equal(t, 1, len(getDS.Response), "Expected 1 Delivery Service.")
+ // Update active to false in order to remove the server assignment
+ active := false
+ getDS.Response[0].Active = &active
+ updResp, _, err := TOSession.UpdateDeliveryService(*dss.DeliveryService, getDS.Response[0], client.RequestOptions{})
+ assert.NoError(t, err, "Error updating Delivery Service: %v - alerts: %+v", err, updResp.Alerts)
+ assert.Equal(t, false, *updResp.Response[0].Active, "Expected Delivery Service to be Inactive.")
+
+ alerts, _, err := TOSession.DeleteDeliveryServiceServer(*dss.DeliveryService, *dss.Server, client.RequestOptions{})
+ assert.NoError(t, err, "Unexpected error removing server-to-Delivery-Service assignments: %v - alerts: %+v", err, alerts.Alerts)
}
-
- serversByDS, _, err := TOSession.GetServersByDeliveryService(*ds.ID, client.RequestOptions{})
- if err != nil {
- t.Errorf("unexpected error getting servers by delivery service: %v", err)
- }
- if len(serversByDS.Response) != 1 {
- t.Errorf("getting servers by delivery service - expected: 1 server, actual: %d servers", len(serversByDS.Response))
- }
- if *serversByDS.Response[0].ID != *server.ID {
- t.Errorf("getting servers by delivery service - expected: server ID %d, actual: %d", *server.ID, *serversByDS.Response[0].ID)
- }
-
- if *ds.Active {
- *ds.Active = false
- _, _, err = TOSession.UpdateDeliveryService(*ds.ID, ds, client.RequestOptions{})
- if err != nil {
- t.Errorf("Setting Delivery Service #%d to inactive", *ds.ID)
- }
- }
-
- if alerts, _, err := TOSession.DeleteDeliveryServiceServer(*ds.ID, *server.ID, client.RequestOptions{}); err != nil {
- t.Errorf("Unexpected error removing server-to-Delivery-Service assignments: %v - alerts: %+v", err, alerts.Alerts)
- }
-
dsServers, _, err = TOSession.GetDeliveryServiceServers(client.RequestOptions{})
- if err != nil {
- t.Fatalf("Unexpected error retrieving server-to-Delivery-Service assignments: %v - alerts: %+v", err, dsServers.Alerts)
- }
-
- found = false
- for _, dss := range dsServers.Response {
- if dss.DeliveryService != nil && *dss.DeliveryService == *ds.ID && dss.Server != nil && *dss.Server == *server.ID {
- found = true
- break
- }
- }
- if found {
- t.Error("DELETE delivery service servers returned success, but still in GET")
- }
-}
-
-func getServerAndDSofSameCDN(t *testing.T) (tc.DeliveryServiceV4, tc.ServerV4) {
- dses, _, err := TOSession.GetDeliveryServices(client.RequestOptions{})
- if err != nil {
- t.Fatalf("cannot GET DeliveryServices: %v", err)
- }
- if len(dses.Response) < 1 {
- t.Fatal("GET DeliveryServices returned no dses, must have at least 1 to test ds-servers")
- }
-
- resp, _, err := TOSession.GetServers(client.RequestOptions{})
- if err != nil {
- t.Fatalf("cannot get Servers: %v - alerts: %+v", err, resp.Alerts)
- }
- servers := resp.Response
- if len(servers) < 1 {
- t.Fatal("GET Servers returned no dses, must have at least 1 to test ds-servers")
- }
-
- for _, ds := range dses.Response {
- for _, s := range servers {
- if ds.CDNName != nil && s.CDNName != nil && *ds.CDNName == *s.CDNName {
- return ds, s
- }
- }
- }
- t.Fatal("expected at least one delivery service and server in the same CDN")
-
- return tc.DeliveryServiceV4{}, tc.ServerV4{}
+ assert.NoError(t, err, "Unexpected error retrieving server-to-Delivery-Service assignments: %v - alerts: %+v", err, dsServers.Alerts)
+ assert.Equal(t, dsServers.Size, 0, "Expected all Delivery Service Server assignments to be deleted.")
}
func CreateTestDeliveryServiceServerAssignments(t *testing.T) {
diff --git a/traffic_ops/testing/api/v4/serverservercapability_test.go b/traffic_ops/testing/api/v4/serverservercapability_test.go
index aa92bb13ed..09f90a189a 100644
--- a/traffic_ops/testing/api/v4/serverservercapability_test.go
+++ b/traffic_ops/testing/api/v4/serverservercapability_test.go
@@ -31,7 +31,7 @@ import (
)
func TestServerServerCapabilities(t *testing.T) {
- WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, ServiceCategories, DeliveryServices, ServerCapabilities, DeliveryServicesRequiredCapabilities, ServerServerCapabilities}, func() {
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, ServiceCategories, DeliveryServices, ServerCapabilities, ServerServerCapabilities, DeliveryServicesRequiredCapabilities}, func() {
SortTestServerServerCapabilities(t)
GetTestServerServerCapabilitiesIMS(t)
GetTestServerServerCapabilities(t)
@@ -39,11 +39,6 @@ func TestServerServerCapabilities(t *testing.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, ServiceCategories, DeliveryServices, ServerCapabilities, ServerServerCapabilitiesForTopologies, TopologyBasedDeliveryServiceRequiredCapabilities}, func() {
DeleteTestServerServerCapabilitiesForTopologiesValidation(t)
})
}
@@ -386,9 +381,6 @@ func DeleteTestServerServerCapabilities(t *testing.T) {
})
assignedServers[*ssc.ServerID] = true
}
- if len(dsServers) == 0 {
- t.Fatalf("test requires at least one server with a capability that is required by at least one delivery service")
- }
// Delete should fail as their delivery services now require the capabilities
for _, ssc := range sscs.Response {
diff --git a/traffic_ops/testing/api/v4/tc-fixtures.json b/traffic_ops/testing/api/v4/tc-fixtures.json
index d686a8c4de..4278eaaa02 100644
--- a/traffic_ops/testing/api/v4/tc-fixtures.json
+++ b/traffic_ops/testing/api/v4/tc-fixtures.json
@@ -1791,15 +1791,7 @@
{
"xmlID": "msods1",
"RequiredCapability": "bar"
- }
- ],
- "deliveryServiceServerAssignments": [
- {
- "xmlId": "ds-top",
- "serverNames": ["denver-mso-org-01"]
- }
- ],
- "topologyBasedDeliveryServicesRequiredCapabilities": [
+ },
{
"xmlID": "ds-top-req-cap",
"RequiredCapability": "ram"
@@ -1813,6 +1805,16 @@
"RequiredCapability": "ram"
}
],
+ "deliveryServiceServerAssignments": [
+ {
+ "xmlId": "ds-top",
+ "serverNames": ["denver-mso-org-01"]
+ },
+ {
+ "xmlId": "test-ds-server-assignments",
+ "serverNames": ["test-ds-server-assignments", "test-mso-org-01"]
+ }
+ ],
"divisions": [
{
"name": "division1"
@@ -5311,6 +5313,55 @@
"type": "EDGE",
"xmppId": "config-update-time\\\\@ocdn.kabletown.net",
"xmppPasswd": "X"
+ },
+ {
+ "cachegroup": "cachegroup1",
+ "cdnName": "cdn1",
+ "domainName": "ga.atlanta.kabletown.net",
+ "guid": null,
+ "hostName": "admin-down-server",
+ "httpsPort": 443,
+ "iloIpAddress": "",
+ "iloIpGateway": "",
+ "iloIpNetmask": "",
+ "iloPassword": "",
+ "iloUsername": "",
+ "interfaces": [
+ {
+ "ipAddresses": [
+ {
+ "address": "127.0.0.22/30",
+ "gateway": "127.0.0.22",
+ "serviceAddress": true
+ },
+ {
+ "address": "2345:1234:13:8::1/64",
+ "gateway": "2345:1234:13:8::1",
+ "serviceAddress": false
+ }
+ ],
+ "maxBandwidth": null,
+ "monitor": true,
+ "mtu": 9000,
+ "name": "bond0",
+ "routerHostName": "router1",
+ "routerPort": "9000"
+ }
+ ],
+ "mgmtIpAddress": "",
+ "mgmtIpGateway": "",
+ "mgmtIpNetmask": "",
+ "offlineReason": null,
+ "physLocation": "Denver",
+ "profile": "EDGE1",
+ "rack": "RR 119.02",
+ "revalPending": false,
+ "status": "ADMIN_DOWN",
+ "tcpPort": 80,
+ "type": "EDGE",
+ "updPending": false,
+ "xmppId": "atlanta-edge-01\\\\@ocdn.kabletown.net",
+ "xmppPasswd": "X"
}
],
"serverCapabilities": [
diff --git a/traffic_ops/testing/api/v4/topologies_test.go b/traffic_ops/testing/api/v4/topologies_test.go
index c9fa5a8dbf..b8a5b94b26 100644
--- a/traffic_ops/testing/api/v4/topologies_test.go
+++ b/traffic_ops/testing/api/v4/topologies_test.go
@@ -42,7 +42,7 @@ type topologyTestCase struct {
}
func TestTopologies(t *testing.T) {
- WithObjs(t, []TCObj{Types, CacheGroups, CDNs, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, Servers, ServerCapabilities, ServerServerCapabilitiesForTopologies, Topologies, Tenants, ServiceCategories, DeliveryServices, TopologyBasedDeliveryServiceRequiredCapabilities}, func() {
+ WithObjs(t, []TCObj{Types, CacheGroups, CDNs, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, Servers, ServerCapabilities, ServerServerCapabilitiesForTopologies, Topologies, Tenants, ServiceCategories, DeliveryServices, DeliveryServicesRequiredCapabilities}, func() {
GetTestTopologies(t)
currentTime := time.Now().UTC().Add(-5 * time.Second)
rfcTime := currentTime.Format(time.RFC1123)
diff --git a/traffic_ops/testing/api/v4/withobjs_test.go b/traffic_ops/testing/api/v4/withobjs_test.go
index 0d4a65e8fa..a13e0b6a25 100644
--- a/traffic_ops/testing/api/v4/withobjs_test.go
+++ b/traffic_ops/testing/api/v4/withobjs_test.go
@@ -77,7 +77,6 @@ const (
Tenants
ServerCheckExtensions
Topologies
- TopologyBasedDeliveryServiceRequiredCapabilities
Types
Users
)
@@ -124,7 +123,6 @@ var withFuncs = map[TCObj]TCObjFuncs{
Tenants: {CreateTestTenants, DeleteTestTenants},
ServerCheckExtensions: {CreateTestServerCheckExtensions, DeleteTestServerCheckExtensions},
Topologies: {CreateTestTopologies, DeleteTestTopologies},
- TopologyBasedDeliveryServiceRequiredCapabilities: {CreateTestTopologyBasedDeliveryServicesRequiredCapabilities, DeleteTestDeliveryServicesRequiredCapabilities},
- Types: {CreateTestTypes, DeleteTestTypes},
- Users: {CreateTestUsers, ForceDeleteTestUsers},
+ Types: {CreateTestTypes, DeleteTestTypes},
+ Users: {CreateTestUsers, ForceDeleteTestUsers},
}