Whyrun not supported for custom resources #4537

Open
christinedraper opened this Issue Feb 6, 2016 · 4 comments

Projects

None yet

6 participants

@christinedraper

If I create a custom resource using the new approach with the action defined in the resources directory, whyrun is not supported. E.g.

resources/hi:

action :create do
  file '/home/tomcat/hi'
end

Even if I create a provider with a whyrun_supported? method, this does not work. I have to go back to the old split into resources and providers to get whyrun support.

@lamont-granquist
Contributor

That's a bug you can do this though:

resource_name :hi

provides :hi

action :create do
  file '/tmp/hi'
end

action_class do
  def whyrun_supported?
    true
  end
end

Output without the hack looks like:

Compiling Cookbooks...
Converging 1 resources
Recipe: test::default
  * hi[foo] action create
    * Whyrun not supported for hi[foo], bypassing load.
     (Skipped: whyrun not supported by provider )
   (up to date)
[2016-02-08T09:25:33-08:00] WARN: In why-run mode, so NOT performing node save.

Output after my workaround:

Compiling Cookbooks...
Converging 1 resources
Recipe: test::default
  * hi[foo] action create
    * file[/tmp/hi] action create
      - Would create new file /tmp/hi

[2016-02-08T09:27:48-08:00] WARN: In why-run mode, so NOT performing node save.

Running handlers:
Running handlers complete
Chef Client finished, 2/2 resources would have been updated
@lamont-granquist lamont-granquist added this to the Accepted Minor milestone Feb 8, 2016
@christinedraper

Thanks for the workaround!

@kamaradclimber
Contributor

I have tried this workaround without sucess in addition to the new :before notification style.

With the same hi resource, the output of chef (in non-whyrun) is:

 [2016-02-12T08:10:09+00:00] INFO: hi[foo] running why-run create action to support before action
     * hi[foo] action create[2016-02-12T08:10:09+00:00] INFO: Processing hi[foo] action create (test::default line 48)

       * Whyrun not supported for hi[foo], bypassing load.
        (Skipped: whyrun not supported by provider )
      (up to date)
   * hi[foo] action create[2016-02-12T08:10:09+00:00] INFO: Processing hi[foo] action create (test::default line 48)

     * file[/tmp/hi] action create[2016-02-12T08:10:09+00:00] INFO: Processing file[/tmp/hi] action create (/tmp/kitchen/cache/cookbooks/test/resources/hi.rb line 6)
   [2016-02-12T08:10:09+00:00] INFO: file[/tmp/hi] created file /tmp/hi

       - create new file /tmp/hi
       - restore selinux security context

I think this is a use-case that would need to be supported by a fix for this issue.

@soymsk
soymsk commented Jul 21, 2016 edited

This workaround doesn't work with Chef client v12.5.1, but does in v12.9.41.
Thanks!

@kamaradclimber kamaradclimber added a commit to criteo-cookbooks/choregraphie that referenced this issue Sep 29, 2016
@kamaradclimber kamaradclimber Add an example of custom resource using workaround for why-run
If custom_resource is defined with an explicity support for why-run,
choregraphie works correctly.

See chef/chef#4537

Change-Id: Ibcdb11135f2d7477584f1707ffd174ca1b7c56e7
fc28ead
@kamaradclimber kamaradclimber added a commit to criteo-cookbooks/choregraphie that referenced this issue Oct 14, 2016
@kamaradclimber kamaradclimber Add an example of custom resource using workaround for why-run
If custom_resource is defined with an explicity support for why-run,
choregraphie works correctly.

See chef/chef#4537

Change-Id: Ibcdb11135f2d7477584f1707ffd174ca1b7c56e7
ccafd66
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment