You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2022/09/07 19:36:31 UTC
[GitHub] [trafficcontrol] shamrickus opened a new pull request, #7065: Allow update time params on Servers when CDN is locked.
shamrickus opened a new pull request, #7065:
URL: https://github.com/apache/trafficcontrol/pull/7065
<!--
Thank you for contributing! Please be sure to read our contribution guidelines: https://github.com/apache/trafficcontrol/blob/master/CONTRIBUTING.md
If this closes or relates to an existing issue, please reference it using one of the following:
Closes: #ISSUE
Related: #ISSUE
If this PR fixes a security vulnerability, DO NOT submit! Instead, contact
the Apache Traffic Control Security Team at security@trafficcontrol.apache.org and follow the
guidelines at https://apache.org/security regarding vulnerability disclosure.
-->
This PR fixes #7047
<!-- **^ Add meaningful description above** --><hr/>
## Which Traffic Control components are affected by this PR?
<!-- Please delete all components from this list that are NOT affected by this PR.
Feel free to add the name of a tool or script that is affected but not on the list.
-->
- Traffic Ops
## What is the best way to verify this PR?
Run the tests and verify that they pass. Lock a CDN and then call the `servers/{id}/update` endpoint with either/both `config_apply_time` and `revalidate_apply_time` options successfully.
<!-- Please include here ALL the steps necessary to test your PR.
If your PR has tests (and most should), provide the steps needed to run the tests.
If not, please provide step-by-step instructions to test the PR manually and explain why your PR does not need tests. -->
<!-- Delete this section if the PR is not a bugfix, or if the bug is only in the master branch.
Examples:
- 5.1.2
- 5.1.3 (RC1)
-->
## PR submission checklist
- [x] This PR has tests <!-- If not, please delete this text and explain why this PR does not need tests. -->
- [x] This PR has documentation <!-- If not, please delete this text and explain why this PR does not need documentation. -->
- [x] This PR has a CHANGELOG.md entry <!-- A fix for a bug from an ATC release, an improvement, or a new feature should have a changelog entry. -->
- [x] This PR **DOES NOT FIX A SERIOUS SECURITY VULNERABILITY** (see [the Apache Software Foundation's security guidelines](https://apache.org/security) for details)
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficcontrol] srijeet0406 commented on a diff in pull request #7065: Allow update time params on Servers when CDN is locked.
Posted by GitBox <gi...@apache.org>.
srijeet0406 commented on code in PR #7065:
URL: https://github.com/apache/trafficcontrol/pull/7065#discussion_r969976940
##########
traffic_ops/traffic_ops_golang/server/update.go:
##########
@@ -296,9 +296,16 @@ func UpdateHandlerV4(w http.ResponseWriter, r *http.Request) {
api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, err)
return
}
- userErr, sysErr, statusCode := dbhelpers.CheckIfCurrentUserHasCdnLock(inf.Tx.Tx, string(cdnName), inf.User.UserName)
- if userErr != nil || sysErr != nil {
- api.HandleErr(w, r, inf.Tx.Tx, statusCode, userErr, sysErr)
+
+ _, hasConfigUpdatedBoolParam := inf.Params["updated"]
+ _, hasRevalUpdatedBoolParam := inf.Params["reval_updated"]
+ _, hasConfigApplyTimeParam := inf.Params["config_apply_time"]
+ _, hasRevalidateApplyTimeParam := inf.Params["revalidate_apply_time"]
+ // Allow `apply_time` changes when the CDN is locked, but not `updated`
+ canIgnoreLock := (hasConfigApplyTimeParam || hasRevalidateApplyTimeParam) && !hasConfigUpdatedBoolParam && !hasRevalUpdatedBoolParam
+ userDoesntHaveLockErr, sysErr, statusCode := dbhelpers.CheckIfCurrentUserHasCdnLock(inf.Tx.Tx, string(cdnName), inf.User.UserName)
Review Comment:
You just need to perform this check if `canIgnoreLock` is `false`. Else, you don't even need to run this query.
##########
CHANGELOG.md:
##########
@@ -5,21 +5,20 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
## [unreleased]
### Added
-- [#2101](https://github.com/apache/trafficcontrol/issues/2101) Added the ability to tell if a Delivery Service is the target of another steering DS.
-- [#6033](https://github.com/apache/trafficcontrol/issues/6033) Added ability to assign multiple server capabilities to a server.
-- [#7032](https://github.com/apache/trafficcontrol/issues/7032) Add t3c-apply flag to use local ATS version for config generation rather than Server package Parameter, to allow managing the ATS OS package via external tools. See 'man t3c-apply' and 'man t3c-generate' for details.
-
-- [Traffic Monitor] Added logging for `ipv4Availability` and `ipv6Availability` in TM.
-- [Traffic Ops] Added the `ASN` field in TO Server struct, which provides the ability to query servers by `ASN`.
+- *Traffic Monitor* Added logging for `ipv4Availability` and `ipv6Availability` in TM.
+- *Traffic Ops* Added the `ASN` field in TO Server struct, which provides the ability to query servers by `ASN`.
+- [#2101](https://github.com/apache/trafficcontrol/issues/2101) *Traffic Portal* Added the ability to tell if a Delivery Service is the target of another steering DS.
+- [#6033](https://github.com/apache/trafficcontrol/issues/6033) *Traffic Ops, Traffic Portal* Added ability to assign multiple server capabilities to a server.
+- [#7032](https://github.com/apache/trafficcontrol/issues/7032) *Cache Config* Add t3c-apply flag to use local ATS version for config generation rather than Server package Parameter, to allow managing the ATS OS package via external tools. See 'man t3c-apply' and 'man t3c-generate' for details.
### Changed
-- Traffic Portal now obscures sensitive text in Delivery Service "Raw Remap" fields, private SSL keys, "Header Rewrite" rules, and ILO interface passwords by default.
-- Traffic Router now uses Traffic Ops API 4.0 by default
+- *Traffic Portal* Obscures sensitive text in Delivery Service "Raw Remap" fields, private SSL keys, "Header Rewrite" rules, and ILO interface passwords by default.
+- *Traffic Router* Uses Traffic Ops API 4.0 by default
### Fixed
-- Traffic Stats: Reuse InfluxDB client handle to prevent potential connection leaks
-- [#7021](https://github.com/apache/trafficcontrol/issues/7021) Fixed cache config for Delivery Services with IP Origins
-
+- *Traffic Stats* Reuse InfluxDB client handle to prevent potential connection leaks.
+- [#7021](https://github.com/apache/trafficcontrol/issues/7021) *Cache Config* Fixed cache config for Delivery Services with IP Origins.
+- [#7047](https://github.com/apache/trafficcontrol/issues/7047) *Traffic Ops* allow `apply_time` query parameters on the `servers/{id-name}/update` when the CDN is locked..
Review Comment:
nit: extra `.` here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficcontrol] srijeet0406 commented on a diff in pull request #7065: Allow update time params on Servers when CDN is locked.
Posted by GitBox <gi...@apache.org>.
srijeet0406 commented on code in PR #7065:
URL: https://github.com/apache/trafficcontrol/pull/7065#discussion_r972184353
##########
traffic_ops/testing/api/v4/serverupdatestatus_test.go:
##########
@@ -29,6 +29,119 @@ import (
client "github.com/apache/trafficcontrol/traffic_ops/v4-client"
)
+func TestServerUpdateApplyTimeLocked(t *testing.T) {
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, ServiceCategories, Topologies, DeliveryServices}, func() {
+ opts := client.NewRequestOptions()
+ opts.QueryParameters.Set("hostName", "atlanta-edge-01")
+ resp, _, err := TOSession.GetServers(opts)
+ if err != nil {
+ t.Fatalf("cannot get server by hostname: %v", err)
+ }
+ if len(resp.Response) != 1 {
+ t.Fatalf("Expected a server named 'atlanta-edge-01' to exist")
+ }
+ testServer := resp.Response[0]
+
+ testVals := func(configApply, revalApply *time.Time) {
+ resp, _, err := TOSession.GetServers(opts)
+ if err != nil {
+ t.Errorf("cannot get Server by name '%s': %v - alerts: %+v", *testServer.HostName, err, resp.Alerts)
+ } else if len(resp.Response) != 1 {
+ t.Fatalf("GET Server expected 1, actual %v", len(resp.Response))
+ }
+
+ beforeServer := resp.Response[0]
+
+ // Ensure baseline
+ if beforeServer.UpdPending == nil {
+ t.Fatalf("Server '%s' had nil UpdPending before update status change", *testServer.HostName)
Review Comment:
nit, these errors should begin with a lowercase letter.
##########
traffic_ops/traffic_ops_golang/server/update.go:
##########
@@ -296,10 +296,19 @@ func UpdateHandlerV4(w http.ResponseWriter, r *http.Request) {
api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, err)
return
}
- userErr, sysErr, statusCode := dbhelpers.CheckIfCurrentUserHasCdnLock(inf.Tx.Tx, string(cdnName), inf.User.UserName)
- if userErr != nil || sysErr != nil {
- api.HandleErr(w, r, inf.Tx.Tx, statusCode, userErr, sysErr)
- return
+
+ _, hasConfigUpdatedBoolParam := inf.Params["updated"]
+ _, hasRevalUpdatedBoolParam := inf.Params["reval_updated"]
+ _, hasConfigApplyTimeParam := inf.Params["config_apply_time"]
+ _, hasRevalidateApplyTimeParam := inf.Params["revalidate_apply_time"]
+ // Allow `apply_time` changes when the CDN is locked, but not `updated`
+ canIgnoreLock := (hasConfigApplyTimeParam || hasRevalidateApplyTimeParam) && !hasConfigUpdatedBoolParam && !hasRevalUpdatedBoolParam
+ if !canIgnoreLock {
+ userDoesntHaveLockErr, sysErr, statusCode := dbhelpers.CheckIfCurrentUserHasCdnLock(inf.Tx.Tx, string(cdnName), inf.User.UserName)
+ if sysErr != nil || (userDoesntHaveLockErr != nil && !canIgnoreLock) {
Review Comment:
You don't need the `canIgnoreLock` check here again.
##########
traffic_ops/testing/api/v4/serverupdatestatus_test.go:
##########
@@ -29,6 +29,119 @@ import (
client "github.com/apache/trafficcontrol/traffic_ops/v4-client"
)
+func TestServerUpdateApplyTimeLocked(t *testing.T) {
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, ServiceCategories, Topologies, DeliveryServices}, func() {
+ opts := client.NewRequestOptions()
+ opts.QueryParameters.Set("hostName", "atlanta-edge-01")
+ resp, _, err := TOSession.GetServers(opts)
+ if err != nil {
+ t.Fatalf("cannot get server by hostname: %v", err)
+ }
+ if len(resp.Response) != 1 {
+ t.Fatalf("Expected a server named 'atlanta-edge-01' to exist")
+ }
+ testServer := resp.Response[0]
+
+ testVals := func(configApply, revalApply *time.Time) {
+ resp, _, err := TOSession.GetServers(opts)
+ if err != nil {
+ t.Errorf("cannot get Server by name '%s': %v - alerts: %+v", *testServer.HostName, err, resp.Alerts)
+ } else if len(resp.Response) != 1 {
+ t.Fatalf("GET Server expected 1, actual %v", len(resp.Response))
+ }
+
+ beforeServer := resp.Response[0]
+
+ // Ensure baseline
+ if beforeServer.UpdPending == nil {
+ t.Fatalf("Server '%s' had nil UpdPending before update status change", *testServer.HostName)
+ }
+ if beforeServer.RevalPending == nil {
+ t.Fatalf("Server '%s' had nil RevalPending before update status change", *testServer.HostName)
+ }
+ if beforeServer.ConfigUpdateTime == nil {
+ t.Fatalf("Server '%s' had nil ConfigUpdateTime before update status change", *testServer.HostName)
+ }
+ if beforeServer.ConfigApplyTime == nil {
+ t.Fatalf("Server '%s' had nil ConfigApplyTime before update status change", *testServer.HostName)
+ }
+ if beforeServer.RevalUpdateTime == nil {
+ t.Fatalf("Server '%s' had nil RevalUpdateTime before update status change", *testServer.HostName)
+ }
+ if beforeServer.RevalApplyTime == nil {
+ t.Fatalf("Server '%s' had nil RevalApplyTime before update status change", *testServer.HostName)
+ }
+
+ _, _, err = TOSession.CreateCDNLock(tc.CDNLock{CDN: *testServer.CDNName, Soft: util.BoolPtr(false)}, client.NewRequestOptions())
+ if err != nil {
+ t.Errorf("cannont acquire lock on the Server '%s' CDN '%s: %v", *testServer.HostName, *testServer.CDNName, err)
+ }
+
+ opsSession, _, err := client.LoginWithAgent(Config.TrafficOps.URL, Config.TrafficOps.Users.Operations,
+ Config.TrafficOps.UserPassword, true, "to-api-v4-locks-ops",
+ true, time.Second*time.Duration(Config.Default.Session.TimeoutInSecs))
+ if err != nil {
+ t.Errorf("cannot login as '%s' user: %v", Config.TrafficOps.Users.Operations, err)
Review Comment:
Should this be a `fatal` error? Because if we can't login using the `Operations` user, we can't possibly check the status update, right?
##########
traffic_ops/testing/api/v4/serverupdatestatus_test.go:
##########
@@ -29,6 +29,119 @@ import (
client "github.com/apache/trafficcontrol/traffic_ops/v4-client"
)
+func TestServerUpdateApplyTimeLocked(t *testing.T) {
+ WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, ServiceCategories, Topologies, DeliveryServices}, func() {
+ opts := client.NewRequestOptions()
+ opts.QueryParameters.Set("hostName", "atlanta-edge-01")
+ resp, _, err := TOSession.GetServers(opts)
+ if err != nil {
+ t.Fatalf("cannot get server by hostname: %v", err)
+ }
+ if len(resp.Response) != 1 {
+ t.Fatalf("Expected a server named 'atlanta-edge-01' to exist")
+ }
+ testServer := resp.Response[0]
+
+ testVals := func(configApply, revalApply *time.Time) {
+ resp, _, err := TOSession.GetServers(opts)
+ if err != nil {
+ t.Errorf("cannot get Server by name '%s': %v - alerts: %+v", *testServer.HostName, err, resp.Alerts)
+ } else if len(resp.Response) != 1 {
+ t.Fatalf("GET Server expected 1, actual %v", len(resp.Response))
+ }
+
+ beforeServer := resp.Response[0]
+
+ // Ensure baseline
+ if beforeServer.UpdPending == nil {
+ t.Fatalf("Server '%s' had nil UpdPending before update status change", *testServer.HostName)
+ }
+ if beforeServer.RevalPending == nil {
+ t.Fatalf("Server '%s' had nil RevalPending before update status change", *testServer.HostName)
+ }
+ if beforeServer.ConfigUpdateTime == nil {
+ t.Fatalf("Server '%s' had nil ConfigUpdateTime before update status change", *testServer.HostName)
+ }
+ if beforeServer.ConfigApplyTime == nil {
+ t.Fatalf("Server '%s' had nil ConfigApplyTime before update status change", *testServer.HostName)
+ }
+ if beforeServer.RevalUpdateTime == nil {
+ t.Fatalf("Server '%s' had nil RevalUpdateTime before update status change", *testServer.HostName)
+ }
+ if beforeServer.RevalApplyTime == nil {
+ t.Fatalf("Server '%s' had nil RevalApplyTime before update status change", *testServer.HostName)
+ }
+
+ _, _, err = TOSession.CreateCDNLock(tc.CDNLock{CDN: *testServer.CDNName, Soft: util.BoolPtr(false)}, client.NewRequestOptions())
+ if err != nil {
+ t.Errorf("cannont acquire lock on the Server '%s' CDN '%s: %v", *testServer.HostName, *testServer.CDNName, err)
+ }
+
+ opsSession, _, err := client.LoginWithAgent(Config.TrafficOps.URL, Config.TrafficOps.Users.Operations,
+ Config.TrafficOps.UserPassword, true, "to-api-v4-locks-ops",
+ true, time.Second*time.Duration(Config.Default.Session.TimeoutInSecs))
+ if err != nil {
+ t.Errorf("cannot login as '%s' user: %v", Config.TrafficOps.Users.Operations, err)
+ }
+
+ badQueryOpts := client.NewRequestOptions()
+ badQueryOpts.QueryParameters.Set("updated", "true")
+ if _, _, err := opsSession.SetUpdateServerStatusTimes(*testServer.HostName, configApply, revalApply, badQueryOpts); err == nil {
+ t.Fatalf("expected SetUpdateServerStatusTimes to not allow updates due to `updated` field")
+ }
+
+ badQueryOpts = client.NewRequestOptions()
+ badQueryOpts.QueryParameters.Set("reval_updated", "true")
+ if _, _, err := opsSession.SetUpdateServerStatusTimes(*testServer.HostName, configApply, revalApply, badQueryOpts); err == nil {
+ t.Fatalf("expected SetUpdateServerStatusTimes to not allow updates due to `reval_updated` field")
+ }
+
+ if alerts, _, err := opsSession.SetUpdateServerStatusTimes(*testServer.HostName, configApply, revalApply, client.RequestOptions{}); err != nil {
+ t.Fatalf("SetUpdateServerStatusTimes error. expected: nil, actual: %v - alerts: %+v", err, alerts.Alerts)
+ }
+
+ resp, _, err = opsSession.GetServers(opts)
+ if err != nil {
+ t.Errorf("cannot GET Server by name '%s': %v - alerts: %+v", *testServer.HostName, err, resp.Alerts)
Review Comment:
This should be `fatal`, to prevent a panic in the following section, if `err` is not `nil` and `resp` is `nil`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficcontrol] srijeet0406 merged pull request #7065: Allow update time params on Servers when CDN is locked.
Posted by GitBox <gi...@apache.org>.
srijeet0406 merged PR #7065:
URL: https://github.com/apache/trafficcontrol/pull/7065
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org