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

Whyrun not supported for custom resources #4537

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

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

This comment has been minimized.

Show comment
Hide comment
@lamont-granquist

lamont-granquist Feb 8, 2016

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
Contributor

lamont-granquist commented Feb 8, 2016

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
@christinedraper

This comment has been minimized.

Show comment
Hide comment
@christinedraper

christinedraper Feb 8, 2016

Thanks for the workaround!

Thanks for the workaround!

@kamaradclimber

This comment has been minimized.

Show comment
Hide comment
@kamaradclimber

kamaradclimber Feb 12, 2016

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.

Contributor

kamaradclimber commented Feb 12, 2016

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

This comment has been minimized.

Show comment
Hide comment
@soymsk

soymsk Jul 21, 2016

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

soymsk commented Jul 21, 2016

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

kamaradclimber added a commit to criteo-cookbooks/choregraphie that referenced this issue Sep 29, 2016

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

kamaradclimber added a commit to criteo-cookbooks/choregraphie that referenced this issue Oct 14, 2016

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

@jmauro jmauro referenced this issue May 29, 2017

Merged

Recursor systemd #61

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment