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

package ignore_failure doesn't work with notification #5685

Closed
jsirex opened this issue Dec 26, 2016 · 3 comments
Closed

package ignore_failure doesn't work with notification #5685

jsirex opened this issue Dec 26, 2016 · 3 comments

Comments

@jsirex
Copy link

jsirex commented Dec 26, 2016

Looks like notify doesn't work with ignore_failure. I'm not sure is it feature or bug:

remote_file 'oracle-java8-jdk-deb' do
  path pkg_path
  source node['e3s']['java']['url']
  checksum node['e3s']['java']['checksum']
  mode '0644'

  notifies :install, 'package[oracle-java8-jdk]', :immediately
end

package 'oracle-java8-jdk' do
  source pkg_path
  ignore_failure true # We need to install dependencies

  if pkg_path.end_with?('.deb')
    provider Chef::Provider::Package::Dpkg
  elsif pkg_path.end_with?('.rpm')
    provider Chef::Provider::Package::Rpm
  end

  notifies :run, 'execute[fix-dependencies-for-oracle-java8-jdk]', :immediately
end

execute 'fix-dependencies-for-oracle-java8-jdk' do
  command 'apt-get -yf install'
  action :nothing
end

Result:

Errors were encountered while processing:
            oracle-java8-jdk
           ---- End output of dpkg -i /tmp/kitchen/cache/oracle-java8-jdk_8u111_amd64.deb ----
           Ran dpkg -i /tmp/kitchen/cache/oracle-java8-jdk_8u111_amd64.deb returned 1
           
           Resource Declaration:
           ---------------------
           # In /tmp/kitchen/cache/cookbooks/e3s-java/recipes/install.rb
           
            15: package 'oracle-java8-jdk' do
            16:   source pkg_path
            17:   ignore_failure true # We need to install dependencies
            18: 
            19:   if pkg_path.end_with?('.deb')
            20:     provider Chef::Provider::Package::Dpkg
            21:   elsif pkg_path.end_with?('.rpm')
            22:     provider Chef::Provider::Package::Rpm
            23:   end
            24: 
           
           Compiled Resource:
           ------------------
           # Declared in /tmp/kitchen/cache/cookbooks/e3s-java/recipes/install.rb:15:in `from_file'
           
           apt_package("oracle-java8-jdk") do
             package_name "oracle-java8-jdk"
             provider Chef::Provider::Package::Dpkg
             action [:install]
             ignore_failure true
             retries 0
             retry_delay 2
             default_guard_interpreter :default
             declared_type :package
             cookbook_name "e3s-java"
             recipe_name "install"
             source "/tmp/kitchen/cache/oracle-java8-jdk_8u111_amd64.deb"
           end
           
           Platform:
           ---------
           x86_64-linux
           
         * execute[fix-dependencies-for-oracle-java8-jdk] action nothing (skipped due to action :nothing)

Chef Version: '~> 12.14' (12.14.89)

Related to #2598

@lamont-granquist
Copy link
Contributor

That isn't a bug or isn't a fixable bug. The code that would set the resource as being updated is never getting executed because of the exception being thrown.

Maybe there needs to be some way to notify-on-failure.

But ignore_failure is usually a signal of abuse of the system. The code should really protect itself against that -- just write ruby code to detect if the command needs to run:

def need_to_fix_dependencies?
   if [ ... something .... ]
    return true
  end
end

execute 'fix-dependencies-for-oracle-java8-jdk' do
  command 'apt-get -yf install'
  only_if { need_to_fix_dependencies? }
end

@lamont-granquist
Copy link
Contributor

lamont-granquist commented Jan 2, 2017

def need_to_fix_dependencies?
  shell_out!("dpkg -i /tmp/kitchen/cache/oracle-java8-jdk_8u111_amd64.deb")
rescue Mixlib::ShellOut::ShellCommandFailed
  true
end

maybe something along those lines (typed from memory, before coffee)

@thommay
Copy link
Contributor

thommay commented Jan 25, 2017

Hi,
thanks for filing a feature request. In general, we handle feature requests with one of these techniques:

  • Write it up as a public RFC.
  • Share the request on the Chef feedback site - this is reviewed by Chef Software, Inc.'s product management team.
  • Mention this ticket (and/or your RFC, and/or you post on the feedback site) and solicit input on the discussion forum.

We'll be closing your ticket, since we try to keep this for issues in Chef.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants