Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix should_content not correctly matching pdnsutil output #171

Closed
wants to merge 1 commit into from

Conversation

Longsight
Copy link

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

  • an extraneous \n after $ORIGIN . which causes \n\n to be added to the resultant zone after record sort;
  • rname values being included in a case-sensitive manner, when records are always returned as downcase, which means that uppercase characters in rname parameters cause zones to always be re-imported.

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.

This fixes two bugs when comparing zone contents to pdnsutil output, which triggers the continual re-import of managed zones:
- an extraneous `\n` after `$ORIGIN .` which causes `\n\n` to be added to the resultant zone;
- `rname` values being included in a case-sensitive manner, when records are always returned as downcase.
@Longsight
Copy link
Author

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

@Longsight
Copy link
Author

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 Longsight reopened this Apr 24, 2024
@Longsight
Copy link
Author

Longsight commented Apr 24, 2024

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
Copy link
Author

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

@Longsight Longsight closed this Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant