Skip to content

(PUP-3088) Fix zone provider debug call#4000

Merged
kylog merged 1 commit intopuppetlabs:3.xfrom
hunner:fix_zone
Jun 17, 2015
Merged

(PUP-3088) Fix zone provider debug call#4000
kylog merged 1 commit intopuppetlabs:3.xfrom
hunner:fix_zone

Conversation

@hunner
Copy link
Contributor

@hunner hunner commented Jun 3, 2015

The provider should directly call Puppet.debug and Puppet.err
because of the issue described in the PUP ticket.

@joshcooper
Copy link
Contributor

Can you update the commit message with the PUP ticket?

@joshcooper joshcooper added the PL label Jun 3, 2015
@hunner hunner changed the title (PE-10046) Fix zone provider debug call (PUP-3088) Fix zone provider debug call Jun 3, 2015
@puppetcla
Copy link

CLA signed by all contributors.

@hunner hunner changed the title (PUP-3088) Fix zone provider debug call (PUP-4691) Fix zone provider debug call Jun 3, 2015
@joshcooper
Copy link
Contributor

It looks like there are other calls to self.fail in the provider that will trigger the same bug.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The real root cause is that puppet assumes if the resource responds to path then it must respond to tags, file, etc. When that issue is fixed, then this change will cause us to lose context information about the resource that failed, e.g.

Error: /Stage[main]/Main/Zone[test_zone]: Ignoring ...

How about we fix the root cause instead, so we don't lose the context and ensure we work with custom providers that also have a path, e.g. registry_key. Something like?

diff --git a/lib/puppet/util/log.rb b/lib/puppet/util/log.rb
index 08a90b1..8909ab3 100644
--- a/lib/puppet/util/log.rb
+++ b/lib/puppet/util/log.rb
@@ -338,9 +338,9 @@ class Puppet::Util::Log
   def source=(source)
     if source.respond_to?(:path)
       @source = source.path
-      source.tags.each { |t| tag(t) }
-      self.file = source.file
-      self.line = source.line
+      source.tags.each { |t| tag(t) } if source.respond_to?(:tags)
+      self.file = source.file if source.respond_to?(:file)
+      self.line = source.line if source.respond_to?(:line)
     else
       @source = source.to_s
     end

cc'ing @hlindberg and @thallgren who were the last to work on logging messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we can't even be sure that the path/tags/file/line methods for providers are the RIGHT methods to call. A developer can make a custom provider with any one of those methods and end up getting unexpected calls, right? It seems like some sort of manifest source callback would be needed that can be referenced instead of the provider methods directly.

@hunner hunner changed the title (PUP-4691) Fix zone provider debug call (PUP-3088) Fix zone provider debug call Jun 5, 2015
@MikaelSmith
Copy link
Contributor

ping @joshcooper what's the state of this?

@MikaelSmith
Copy link
Contributor

I'll follow up on this while @joshcooper's out. @hunner any updates on Josh's comments?

@hunner
Copy link
Contributor Author

hunner commented Jun 15, 2015

@MikaelSmith Updating the PR now...

@MikaelSmith
Copy link
Contributor

I'm not sure I see the reason in the ticket why this uses the resource, instead of just falling through to to_s.

With the special handling you've added for provider we get
Warning: /File[/var/lib/puppet/rrd]: Fetching file owner.
Letting it fall through (like used to happen for most providers) produced
Warning: File[/var/lib/puppet/rrd](provider=posix): Fetching file owner.

I'd lean towards not changing the behavior for all providers.

@hunner
Copy link
Contributor Author

hunner commented Jun 16, 2015

Lost comments from Josh on hunner@afdbb23

@MikaelSmith I think you're referring to calling source.path vs. source.resource.path ? This is actually the problem that this commit fixes, as some providers provide .path property getters that override the provider's default path method such as https://github.com/puppetlabs/puppet/blob/3.8.1/lib/puppet/provider/zone/solaris.rb#L64

I can rename the default provider.path method to provider.resource_path or something, though this could have large ramifications than expected if anyone was otherwise depending on this behavior. What would you like?

@MikaelSmith
Copy link
Contributor

No, I mean that for most providers .path wasn't defined, and they would fall through to the else clause to print using to_s. You've changed the behavior on all providers to now use the printing we do for Types, which changes the output as I outlined in my comment.

@MikaelSmith
Copy link
Contributor

👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec test fails because these aren't invoked.

The util log library should use the type's path/file/tags when
available, but any other object's logging messages do not need this
kind of information.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would defined?(Puppet::Type) not be true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is from the is_resource? method of Puppet::Util::Logging at https://github.com/puppetlabs/puppet/blob/3.8.1/lib/puppet/util/logging.rb#L197-L199 , but this log util may not be used before require 'puppet/type' though the Puppet::Util::Logging one may, but I included it to be safe.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay; thanks for the context.

kylog pushed a commit that referenced this pull request Jun 17, 2015
(PUP-3088) Fix zone provider debug call
@kylog kylog merged commit 721d7b0 into puppetlabs:3.x Jun 17, 2015
@hunner hunner deleted the fix_zone branch June 17, 2015 00:12
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.

5 participants