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 2020/05/27 04:14:23 UTC

[GitHub] [trafficcontrol] rawlinp commented on a change in pull request #4718: Fix MaxRevalDurationDays validation for invalidation jobs

rawlinp commented on a change in pull request #4718:
URL: https://github.com/apache/trafficcontrol/pull/4718#discussion_r430735857



##########
File path: traffic_ops/testing/api/v3/jobs_test.go
##########
@@ -82,6 +83,28 @@ func CreateTestInvalidationJobs(t *testing.T) {
 	}
 }
 
+func CreateInvalidJob(t *testing.T) {
+	toDSes, _, err := TOSession.GetDeliveryServicesNullable()
+	if err != nil {
+		t.Fatalf("cannot GET Delivery Services: %v - %v", err, toDSes)
+	}
+	dsNameIDs := map[string]int64{}
+	for _, ds := range toDSes {
+		dsNameIDs[*ds.XMLID] = int64(*ds.ID)
+	}
+
+	job := testData.InvalidationJobs[0]
+	_, ok := dsNameIDs[(*job.DeliveryService).(string)]
+	if !ok {
+		t.Fatalf("can't create test data job: delivery service '%v' not found in Traffic Ops", job.DeliveryService)
+	}
+	tooHigh := interface{}(2161)
+	job.TTL = &tooHigh
+	if _, _, err := TOSession.CreateInvalidationJob(job); err == nil {
+		t.Error("creating invalid job (TTL higher than maxRevalDurationDays) - expected: error, actual: nil error")
+	}

Review comment:
       done in bae7ca548739e0d9fe501afba8b2c2559b7843f9

##########
File path: lib/go-tc/invalidationjobs.go
##########
@@ -349,12 +356,13 @@ func (job *UserInvalidationJobInput) Validate(tx *sql.Tx) error {
 
 	if job.TTL != nil {
 		row := tx.QueryRow(`SELECT value FROM parameter WHERE name='maxRevalDurationDays' AND config_file='regex_revalidate.config'`)
-		var max uint64
-		err := row.Scan(&max)
+		var maxDays uint64
+		err := row.Scan(&maxDays)
+		maxHours := maxDays * 24
 		if err == sql.ErrNoRows && MaxTTL < *(job.TTL) {
 			errs = append(errs, "ttl: cannot exceed "+strconv.FormatUint(MaxTTL, 10)+"!")
-		} else if err == nil && max < *(job.TTL) { //silently ignore other errors to
-			errs = append(errs, "ttl: cannot exceed "+strconv.FormatUint(max, 10)+"!")
+		} else if err == nil && maxHours < *(job.TTL) { //silently ignore other errors to
+			errs = append(errs, "ttl: cannot exceed "+strconv.FormatUint(maxHours, 10)+"!")

Review comment:
       done in bae7ca548739e0d9fe501afba8b2c2559b7843f9

##########
File path: lib/go-tc/invalidationjobs.go
##########
@@ -349,12 +356,13 @@ func (job *UserInvalidationJobInput) Validate(tx *sql.Tx) error {
 
 	if job.TTL != nil {
 		row := tx.QueryRow(`SELECT value FROM parameter WHERE name='maxRevalDurationDays' AND config_file='regex_revalidate.config'`)
-		var max uint64
-		err := row.Scan(&max)
+		var maxDays uint64
+		err := row.Scan(&maxDays)
+		maxHours := maxDays * 24
 		if err == sql.ErrNoRows && MaxTTL < *(job.TTL) {
 			errs = append(errs, "ttl: cannot exceed "+strconv.FormatUint(MaxTTL, 10)+"!")
-		} else if err == nil && max < *(job.TTL) { //silently ignore other errors to
-			errs = append(errs, "ttl: cannot exceed "+strconv.FormatUint(max, 10)+"!")
+		} else if err == nil && maxHours < *(job.TTL) { //silently ignore other errors to

Review comment:
       done in bae7ca548739e0d9fe501afba8b2c2559b7843f9

##########
File path: traffic_ops/testing/api/v3/jobs_test.go
##########
@@ -82,6 +83,28 @@ func CreateTestInvalidationJobs(t *testing.T) {
 	}
 }
 
+func CreateInvalidJob(t *testing.T) {
+	toDSes, _, err := TOSession.GetDeliveryServicesNullable()
+	if err != nil {
+		t.Fatalf("cannot GET Delivery Services: %v - %v", err, toDSes)
+	}
+	dsNameIDs := map[string]int64{}
+	for _, ds := range toDSes {
+		dsNameIDs[*ds.XMLID] = int64(*ds.ID)
+	}
+
+	job := testData.InvalidationJobs[0]
+	_, ok := dsNameIDs[(*job.DeliveryService).(string)]
+	if !ok {
+		t.Fatalf("can't create test data job: delivery service '%v' not found in Traffic Ops", job.DeliveryService)
+	}
+	tooHigh := interface{}(2161)

Review comment:
       done in bae7ca548739e0d9fe501afba8b2c2559b7843f9

##########
File path: traffic_ops/testing/api/v3/jobs_test.go
##########
@@ -82,6 +83,28 @@ func CreateTestInvalidationJobs(t *testing.T) {
 	}
 }
 
+func CreateInvalidJob(t *testing.T) {

Review comment:
       done in bae7ca548739e0d9fe501afba8b2c2559b7843f9

##########
File path: traffic_ops/testing/api/v3/jobs_test.go
##########
@@ -82,6 +85,47 @@ func CreateTestInvalidationJobs(t *testing.T) {
 	}
 }
 
+func CreateTestInvalidJob(t *testing.T) {
+	toDSes, _, err := TOSession.GetDeliveryServicesNullable()
+	if err != nil {
+		t.Fatalf("cannot GET Delivery Services: %v - %v", err, toDSes)
+	}
+	dsNameIDs := map[string]int64{}
+	for _, ds := range toDSes {
+		dsNameIDs[*ds.XMLID] = int64(*ds.ID)
+	}
+
+	job := testData.InvalidationJobs[0]
+	_, ok := dsNameIDs[(*job.DeliveryService).(string)]
+	if !ok {
+		t.Fatalf("can't create test data job: delivery service '%v' not found in Traffic Ops", job.DeliveryService)
+	}
+	maxRevalDays := 0
+	foundMaxRevalDays := false
+	for _, p := range testData.Parameters {
+		if p.Name == "maxRevalDurationDays" {
+			maxRevalDays, err = strconv.Atoi(p.Value)
+			if err != nil {
+				t.Fatalf("unable to parse maxRevalDurationDays value '%s' to int", p.Value)
+			}
+			foundMaxRevalDays = true
+			break

Review comment:
       unindented in 7509a9faeb20027557d9cc2332755dd47c8e8498 




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

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