From commits-return-8330-archive-asf-public=cust-asf.ponee.io@trafficcontrol.apache.org Tue Sep 8 23:18:33 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mailroute1-lw-us.apache.org (mailroute1-lw-us.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with ESMTPS id 431DB18066B for ; Wed, 9 Sep 2020 01:18:33 +0200 (CEST) Received: from mail.apache.org (localhost [127.0.0.1]) by mailroute1-lw-us.apache.org (ASF Mail Server at mailroute1-lw-us.apache.org) with SMTP id 764A9121A31 for ; Tue, 8 Sep 2020 23:18:32 +0000 (UTC) Received: (qmail 6325 invoked by uid 500); 8 Sep 2020 23:18:32 -0000 Mailing-List: contact commits-help@trafficcontrol.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@trafficcontrol.apache.org Delivered-To: mailing list commits@trafficcontrol.apache.org Received: (qmail 6316 invoked by uid 99); 8 Sep 2020 23:18:32 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Sep 2020 23:18:32 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id B45BD8087C; Tue, 8 Sep 2020 23:18:31 +0000 (UTC) Date: Tue, 08 Sep 2020 23:18:31 +0000 To: "commits@trafficcontrol.apache.org" Subject: [trafficcontrol] branch master updated: Missing ProfileId during server creation returns Bad Request error (#5003) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <159960711108.17465.14199627369883145875@gitbox.apache.org> From: ocket8888@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: trafficcontrol X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 5c23a002e80289970be357881726cde775121b9c X-Git-Newrev: c051ae9679c9c8e83565e77a71acfb3f4d41d161 X-Git-Rev: c051ae9679c9c8e83565e77a71acfb3f4d41d161 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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(¶ms, 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 }