This is an automated email from the ASF dual-hosted git repository.
rawlin pushed a commit to branch 4.0.x
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/4.0.x by this push:
new 9d1261f traffic_ops_ort: fix for syncds having too many header
rewrite false … (#4343) (#4362)
9d1261f is described below
commit 9d1261ffb2dd6335ef160a161c97e6d60197b1b5
Author: Rawlin Peters <[email protected]>
AuthorDate: Thu Jan 30 18:04:08 2020 -0700
traffic_ops_ort: fix for syncds having too many header rewrite false …
(#4343) (#4362)
* traffic_ops_ort: fix for syncds having too many header rewrite false
positives
* traffic_ops_ort.pl: allow all files with changes to run through the
diff_file_lines function
(cherry picked from commit 7ee3ffa98cb41f727f75fc1d909b71fc2c974340)
Co-authored-by: Brian Olsen <[email protected]>
---
CHANGELOG.md | 1 +
traffic_ops/ort/traffic_ops_ort.pl | 69 ++++++++++++++++++++++++--------------
2 files changed, 45 insertions(+), 25 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7b4cecd..d8dc807 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -96,6 +96,7 @@ The format is based on [Keep a
Changelog](http://keepachangelog.com/en/1.0.0/).
- Traffic Monitor health/stat time now includes full body download (like prior
TM <=2.1 version)
- Modified Traffic Router logging format to include an additional field for
DNS log entries, namely `rhi`. This defaults to '-' and is only used when EDNS0
client subnet extensions are enabled and a client subnet is present in the
request. When enabled and a subnet is present, the subnet appears in the `chi`
field and the resolver address is in the `rhi` field.
- Changed traffic_ops_ort.pl so that hdr_rw-<ds>.config files are compared
with strict ordering and line duplication when detecting configuration changes.
+- Fix to traffic_ops_ort.pl to strip specific comment lines before checking if
a file has changed. Also promoted a changed file message from DEBUG to ERROR
for report mode.
- Traffic Ops (golang), Traffic Monitor, Traffic Stats are now compiled using
Go version 1.11. Grove was already being compiled with this version which
improves performance for TLS when RSA certificates are used.
- Fixed issue #3497: TO API clients that don't specify the latest minor
version will overwrite/default any fields introduced in later versions
- Fixed permissions on DELETE
/api/$version/deliveryservice_server/{dsid}/{serverid} endpoint
diff --git a/traffic_ops/ort/traffic_ops_ort.pl
b/traffic_ops/ort/traffic_ops_ort.pl
index 4b1bd30..ac56b5c 100755
--- a/traffic_ops/ort/traffic_ops_ort.pl
+++ b/traffic_ops/ort/traffic_ops_ort.pl
@@ -246,8 +246,6 @@ else {
( my $my_profile_name, $cfg_file_tracker, my $my_cdn_name ) =
&get_cfg_file_list( $hostname_short, $traffic_ops_host, $script_mode );
-
-
if ( $script_mode == $REVALIDATE ) {
( $log_level >> $INFO ) && print "\nINFO: ======== Revalidating, no
package processing needed ========\n";
}
@@ -410,6 +408,7 @@ sub process_cfg_file {
}
my @db_file_lines = @{ &scrape_unencode_text($result) };
+ @db_file_lines = @{ &scrape_canned_comments(\@db_file_lines) };
my $file = $config_dir . "/" . $cfg_file;
@@ -419,26 +418,33 @@ sub process_cfg_file {
if ( -e $file ) {
return $CFG_FILE_NOT_PROCESSED if (
!&can_read_write_file($cfg_file) );
@disk_file_lines = @{ &open_file_get_contents($file) };
+ @disk_file_lines = @{
&scrape_canned_comments(\@disk_file_lines) };
}
# First, check if the file to be generated would be identical including
order
my $change_needed = ( join( '\0', @disk_file_lines ) ne join( '\0',
@db_file_lines ) );
- # if different, look deeper to see if we care about the diffs (e.g.
different order)
- if ( $change_needed && !( $cfg_file eq 'logs_xml.config' || $cfg_file
=~ m/\.cer$/ || $cfg_file =~ m/hdr\_rw\_(.*)\.config$/ ) ) {
- my @return = &diff_file_lines( $cfg_file,
\@db_file_lines, \@disk_file_lines );
- my @db_lines_missing = @{ shift(@return) };
- my @disk_lines_missing = @{ shift(@return) };
+ # if different, look deeper to see if we care about the diffs
+ if ( $change_needed ) {
+ # diff_file_lines has all the debug we want
+ my @return = &diff_file_lines( $cfg_file, \@db_file_lines,
\@disk_file_lines );
+ my $order_dependent = ( $cfg_file eq 'logs_xml.config' ||
$cfg_file =~ m/\.cer$/ || $cfg_file =~ m/hdr\_rw\_(.*)\.config$/ );
+
+ # if the files aren't order dependent then relax the criteria
+ if ( ! $order_dependent ) {
+ my @db_lines_missing = @{ shift(@return) };
+ my @disk_lines_missing = @{ shift(@return) };
- if ( scalar(@disk_lines_missing) == 0 &&
scalar(@db_lines_missing) == 0 ) {
- # all lines accounted for
- $change_needed = undef;
+ if ( scalar(@disk_lines_missing) == 0 &&
scalar(@db_lines_missing) == 0 ) {
+ # all lines accounted for
+ $change_needed = undef;
+ }
}
}
- if ($change_needed) {
+ if ( $change_needed ) {
$cfg_file_tracker->{$cfg_file}{'change_needed'}++;
- ( $log_level >> $DEBUG ) && print "DEBUG $file needs
updated.\n";
+ ( $log_level >> $ERROR ) && print "ERROR $file needs
updated.\n";
&backup_file( $cfg_file, \$result );
}
else {
@@ -1755,23 +1761,23 @@ sub check_script_mode {
my $script_mode = undef;
if ( $ARGV[0] eq "interactive" ) {
( $log_level >> $DEBUG ) && print "DEBUG Script running in
interactive mode.\n";
- $script_mode = 0;
+ $script_mode = $INTERACTIVE;
}
elsif ( $ARGV[0] eq "report" ) {
( $log_level >> $DEBUG ) && print "DEBUG Script running in
report mode.\n";
- $script_mode = 1;
+ $script_mode = $REPORT;
}
elsif ( $ARGV[0] eq "badass" ) {
( $log_level >> $DEBUG ) && print "DEBUG Script running in
badass mode.\n";
- $script_mode = 2;
+ $script_mode = $BADASS;
}
elsif ( $ARGV[0] eq "syncds" ) {
( $log_level >> $DEBUG ) && print "DEBUG Script running in
syncds mode.\n";
- $script_mode = 3;
+ $script_mode = $SYNCDS;
}
elsif ( $ARGV[0] eq "revalidate" ) {
( $log_level >> $DEBUG ) && print "DEBUG Script running in
revalidate mode.\n";
- $script_mode = 4;
+ $script_mode = $REVALIDATE;
}
else {
( $log_level >> $FATAL ) && print "FATAL You did not specify a
valid mode. Exiting.\n";
@@ -2652,6 +2658,23 @@ sub scrape_unencode_text {
return \@lines;
}
+sub scrape_canned_comments {
+ my $linesin = $_[0];
+
+ my @linesout;
+
+ foreach my $line (@$linesin) {
+ if ( $line =~ m/^\#/ ) {
+ if ( $line =~ m/DO NOT EDIT - Generated for / || $line
=~ m/$header_comment/ || $line =~ m/TRAFFIC OPS NOTE\:/ || $line =~
m/^##OVERRID.*##/ ) {
+ next;
+ }
+ }
+ push( @linesout, $line );
+ }
+
+ return \@linesout;
+}
+
sub can_read_write_file {
my $filename = shift;
@@ -2709,10 +2732,10 @@ sub open_file_get_contents {
$line =~ s/(^\s+|\s+$)//g;
chomp($line);
( $log_level >> $TRACE ) && print "TRACE Line from cfg file on
disk:\t$line.\n";
- if ( $line =~ m/^\#/ || $line =~ m/^$/ ) {
- if ( ( $line !~ m/DO NOT EDIT - Generated for / &&
$line !~ m/$header_comment/ ) && ( $line !~ m/TRAFFIC OPS NOTE\:/ ) && ( $line
!~ m/^##OVERRID.*##/ ) ) {
- next;
- }
+
+ # strip empty lines
+ if ( $line =~ m/^$/ ) {
+ next;
}
push( @disk_file_lines, $line );
}
@@ -2818,7 +2841,6 @@ sub diff_file_lines {
foreach my $line (@db_lines_missing) {
( $log_level >> $ERROR ) && print "ERROR Config file
$cfg_file line only on disk :\t$line\n";
}
-
}
if ( scalar(@disk_lines_missing) ) {
@@ -2827,11 +2849,9 @@ sub diff_file_lines {
foreach my $line (@disk_lines_missing) {
( $log_level >> $ERROR ) && print "ERROR Config file
$cfg_file line only in TrOps:\t$line\n";
}
-
}
return ( \@db_lines_missing, \@disk_lines_missing );
-
}
sub validate_filename {
@@ -2884,7 +2904,6 @@ sub backup_file {
close $fh;
}
return 0;
-
}
sub adv_preprocessing_remap {