trafficcontrol-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ocket8...@apache.org
Subject [trafficcontrol] branch master updated: Missing ProfileId during server creation returns Bad Request error (#5003)
Date Tue, 08 Sep 2020 23:18:31 GMT
This is an automated email from the ASF dual-hosted git repository.

ocket8888 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 c051ae9  Missing ProfileId during server creation returns Bad Request error (#5003)
c051ae9 is described below

commit c051ae9679c9c8e83565e77a71acfb3f4d41d161
Author: rimashah25 <22248619+rimashah25@users.noreply.github.com>
AuthorDate: Tue Sep 8 17:18:19 2020 -0600

    Missing ProfileId during server creation returns Bad Request error (#5003)
    
    * Returning BadRequest error during server creation,
    
    * Removed fmt statements
    
    * Added a v3/api test case for missing profile ID and update changelog
    
    * Added a new line to make it a text file
    
    * Updated API test case.
    
    * Updated API test case-1
    
    * Updated based on review feedback
    
    * removed string contains check
    
    * Updated based on PR review-1
---
 CHANGELOG.md                                     |  1 +
 traffic_ops/testing/api/v3/servers_test.go       | 38 +++++++++++++++++++++++-
 traffic_ops/testing/api/v3/tc-fixtures.json      |  4 +--
 traffic_ops/traffic_ops_golang/server/servers.go |  7 ++---
 traffic_ops/v3-client/server.go                  |  3 ++
 5 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 744e76c..e3fb81e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -43,6 +43,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 - Added Traffic Monitor: Support astats CSV output. Includes http_polling_format configuration
option to specify the Accept header sent to stats endpoints. Adds CSV parsing ability (~100%
faster than JSON) to the astats plugin
 
 ### Fixed
+- Fixed #4979 - Returns a Bad Request error during server creation with missing profileId
[Related github issue](https://github.com/apache/trafficcontrol/issues/4979)
 - Fixed #3400 - Allow "0" as a TTL value for Static DNS entries
 - Fixed #4743 - Validate absolute DNS name requirement on Static DNS entry for CNAME type
[Related github issue](https://github.com/apache/trafficcontrol/issues/4743)
 - Fixed #4848 - `GET /api/x/cdns/capacity` gives back 500, with the message `capacity was
zero`
diff --git a/traffic_ops/testing/api/v3/servers_test.go b/traffic_ops/testing/api/v3/servers_test.go
index 324e743..fb1efc2 100644
--- a/traffic_ops/testing/api/v3/servers_test.go
+++ b/traffic_ops/testing/api/v3/servers_test.go
@@ -41,6 +41,7 @@ func TestServers(t *testing.T) {
 		GetTestServers(t)
 		GetTestServersIMSAfterChange(t, header)
 		GetTestServersQueryParameters(t)
+		CreateTestServerWithoutProfileId(t)
 		UniqueIPProfileTestServers(t)
 		UpdateTestServerStatus(t)
 	})
@@ -241,13 +242,47 @@ func CreateTestServers(t *testing.T) {
 			continue
 		}
 		resp, _, err := TOSession.CreateServer(server)
-		t.Log("Response: ", server.HostName, " ", resp)
+		t.Log("Response: ", *server.HostName, " ", resp)
 		if err != nil {
 			t.Errorf("could not CREATE servers: %v", err)
 		}
 	}
 }
 
+func CreateTestServerWithoutProfileId(t *testing.T) {
+	params := url.Values{}
+	servers := testData.Servers[19]
+	params.Set("hostName", *servers.HostName)
+
+	resp, _, err := TOSession.GetServersWithHdr(&params, nil)
+	if err != nil {
+		t.Fatalf("cannot GET Server by name '%s': %v - %v", *servers.HostName, err, resp.Alerts)
+	}
+
+	server := resp.Response[0]
+	originalProfile := *server.Profile
+	delResp, _, err := TOSession.DeleteServerByID(*server.ID)
+	if err != nil {
+		t.Fatalf("cannot DELETE Server by ID %d: %v - %v", *server.ID, err, delResp)
+	}
+
+	*server.Profile = ""
+	server.ProfileID = nil
+	response, reqInfo, errs := TOSession.CreateServer(server)
+	t.Log("Response: ", *server.HostName, " ", response)
+	if reqInfo.StatusCode != 400 {
+		t.Fatalf("Expected status code: %v but got: %v", "400", reqInfo.StatusCode)
+	}
+
+	//Reverting it back for further tests
+	*server.Profile = originalProfile
+	response, _, errs = TOSession.CreateServer(server)
+	t.Log("Response: ", *server.HostName, " ", response)
+	if errs != nil {
+		t.Fatalf("could not CREATE servers: %v", errs)
+	}
+}
+
 func GetTestServers(t *testing.T) {
 	params := url.Values{}
 	for _, server := range testData.Servers {
@@ -261,6 +296,7 @@ func GetTestServers(t *testing.T) {
 			t.Errorf("cannot GET Server by name '%s': %v - %v", *server.HostName, err, resp.Alerts)
 		} else if resp.Summary.Count != 1 {
 			t.Errorf("incorrect server count, expected: 1, actual: %d", resp.Summary.Count)
+
 		}
 	}
 }
diff --git a/traffic_ops/testing/api/v3/tc-fixtures.json b/traffic_ops/testing/api/v3/tc-fixtures.json
index 132497f..ce5b78c 100644
--- a/traffic_ops/testing/api/v3/tc-fixtures.json
+++ b/traffic_ops/testing/api/v3/tc-fixtures.json
@@ -2755,8 +2755,8 @@
             "description": "a topology",
             "nodes": [
                 {
-                  "cachegroup": "parentCachegroup",
-                  "parents": []
+                    "cachegroup": "parentCachegroup",
+                    "parents": []
                 },
                 {
                     "cachegroup": "secondaryCachegroup",
diff --git a/traffic_ops/traffic_ops_golang/server/servers.go b/traffic_ops/traffic_ops_golang/server/servers.go
index b33dd06..6df40ba 100644
--- a/traffic_ops/traffic_ops_golang/server/servers.go
+++ b/traffic_ops/traffic_ops_golang/server/servers.go
@@ -582,9 +582,9 @@ func validateV3(s *tc.ServerNullable, tx *sql.Tx) (string, error) {
 	if !serviceAddrV6Found && !serviceAddrV4Found {
 		errs = append(errs, errors.New("a server must have at least one service address"))
 	}
-
-	errs = append(errs, validateCommon(&s.CommonServerProperties, tx)...)
-
+	if errs = append(errs, validateCommon(&s.CommonServerProperties, tx)...); errs != nil
{
+		return serviceInterface, util.JoinErrs(errs)
+	}
 	query := `
 SELECT s.ID, ip.address FROM server s 
 JOIN profile p on p.Id = s.Profile
@@ -1445,7 +1445,6 @@ func createV3(inf *api.APIInfo, w http.ResponseWriter, r *http.Request)
{
 
 	str := uuid.New().String()
 	server.XMPPID = &str
-
 	_, err := validateV3(&server, tx)
 	if err != nil {
 		api.HandleErr(w, r, tx, http.StatusBadRequest, err, nil)
diff --git a/traffic_ops/v3-client/server.go b/traffic_ops/v3-client/server.go
index dc71b1b..993642b 100644
--- a/traffic_ops/v3-client/server.go
+++ b/traffic_ops/v3-client/server.go
@@ -116,6 +116,9 @@ func (to *Session) CreateServer(server tc.ServerNullable) (tc.Alerts,
ReqInf, er
 
 	resp, remoteAddr, err := to.request(http.MethodPost, API_SERVERS, reqBody, nil)
 	reqInf.RemoteAddr = remoteAddr
+	if resp != nil {
+		reqInf.StatusCode = resp.StatusCode
+	}
 	if err != nil {
 		return alerts, reqInf, err
 	}


Mime
View raw message