sensson / puppet-powerdns

A Puppet module to install and configure the PowerDNS 4.x authorative server and recursor
12 stars 46 forks source link

Fix should_content not correctly matching pdnsutil output #171

Closed Longsight closed 6 months ago

Longsight commented 6 months ago

This fixes two bugs when comparing zone contents to pdnsutil output, which triggers the continual re-import of managed zones:

Changing the relevant lines in should_content ensures that affected zones are only re-imported when records actually differ.

No test changes are included as powerdns_zone contents do not currently have any tests running against them.

Longsight commented 6 months ago

Okay now I can't trigger the bug with the old code, so something else has changed.

Longsight commented 6 months ago

Reopening this because a) the \n change, while apparently not actually fixing anything in terms of re-importing, is still technically correct, and b) the case sensitivity change definitely does fix a re-import issue.

Longsight commented 6 months ago

With no changes to zone, but uppercase record resources present:

existing code:

root@dns01:~# puppet agent --test --pidfile /var/run/puppetlabs/collector.pid --agent_catalog_run_lockfile /opt/puppetlabs/puppet/cache/state/collector.lock --tags powerdns_zone_private,powerdns_zone,powerdns_record,profile::powerdns::reversezone --skip_tags null
Info: Using environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Notice: /File[/opt/puppetlabs/puppet/cache/lib/puppet/type/powerdns_zone.rb]/content: 
--- /opt/puppetlabs/puppet/cache/lib/puppet/type/powerdns_zone.rb       2024-04-24 15:58:25.547955583 +0100
+++ /tmp/puppet-file20240424-2804593-rclwmr     2024-04-24 16:02:21.498453862 +0100
@@ -136,7 +136,7 @@
       if r[:rname] == '.'
         content.push([r[:target_zone], r[:rttl], r[:rclass], r[:rtype], r[:rcontent]].join("\t"))
       else
-        content.push([(r[:rname] + '.' + r[:target_zone]).downcase, r[:rttl], r[:rclass], r[:rtype], r[:rcontent]].join("\t"))
+        content.push([r[:rname] + '.' + r[:target_zone], r[:rttl], r[:rclass], r[:rtype], r[:rcontent]].join("\t"))
       end
       # rubocop:enable Style/StringConcatenation
     end

Notice: /File[/opt/puppetlabs/puppet/cache/lib/puppet/type/powerdns_zone.rb]/content: content changed '{sha256}cf1f49d965abd0dcd8b4da359c0185aed98c42bcfd6e90dd547e034c93ac0f1b' to '{sha256}73c4de974051989bec1a9846106675128a2d148224b68d4ed08c616ea4250fac'
Info: Loading facts
Notice: Requesting catalog from puppet:8140
Info: Applying configuration version '1713970968'
Notice: /Stage[main]/Profile::Powerdns::Domains/Powerdns_zone_private[example.com]/content: content changed {md5}f9053db25088ee6897bacd0dafcac5d7 to {md5}66f8af72b6e0feab8b886255b48ea3da

#   Zone should not have been re-imported, but was

Info: Class[Profile::Powerdns::Domains]: Unscheduling all events on Class[Profile::Powerdns::Domains]
Notice: Applied catalog in 71.31 seconds

changed code:

root@dns01:~# puppet agent --test --pidfile /var/run/puppetlabs/collector.pid --agent_catalog_run_lockfile /opt/puppetlabs/puppet/cache/state/collector.lock --tags powerdns_zone_private,powerdns_zone,powerdns_record,profile::powerdns::reversezone --skip_tags null
Info: Using environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Notice: /File[/opt/puppetlabs/puppet/cache/lib/puppet/type/powerdns_zone.rb]/content: 
--- /opt/puppetlabs/puppet/cache/lib/puppet/type/powerdns_zone.rb       2024-04-24 15:57:06.635119987 +0100
+++ /tmp/puppet-file20240424-2803416-c0j3tp     2024-04-24 15:58:25.471954777 +0100
@@ -136,7 +136,7 @@
       if r[:rname] == '.'
         content.push([r[:target_zone], r[:rttl], r[:rclass], r[:rtype], r[:rcontent]].join("\t"))
       else
-        content.push([r[:rname] + '.' + r[:target_zone], r[:rttl], r[:rclass], r[:rtype], r[:rcontent]].join("\t"))
+        content.push([(r[:rname] + '.' + r[:target_zone]).downcase, r[:rttl], r[:rclass], r[:rtype], r[:rcontent]].join("\t"))
       end
       # rubocop:enable Style/StringConcatenation
     end

Notice: /File[/opt/puppetlabs/puppet/cache/lib/puppet/type/powerdns_zone.rb]/content: content changed '{sha256}73c4de974051989bec1a9846106675128a2d148224b68d4ed08c616ea4250fac' to '{sha256}cf1f49d965abd0dcd8b4da359c0185aed98c42bcfd6e90dd547e034c93ac0f1b'
Info: Loading facts
Notice: Requesting catalog from puppet:8140
Info: Applying configuration version '1713970714'

#   No changes

Notice: Applied catalog in 65.91 seconds
Longsight commented 6 months ago

You know the more I think about this, the more I don't like this solution anyway. I'm gonna close it for now.