elasticsearch icon indicating copy to clipboard operation
elasticsearch copied to clipboard

elasticsearch_install action :remove failure

Open joshbranham opened this issue 7 years ago • 2 comments

When attempting to remove an elasticsearch_install with the block below, it fails as it attempts to tell dpkg to remove the package version listed while prepending #{Chef::Config[:file_cache_path]} to the name, which if you are just trying to dpkg uninstall something, fails.

My question is: I know this cookbook does not support upgrading, but should it not allow the following for sake of people writing their own upgrade recipe? I worked around this by having an explicit dpkg_package block with action :remove

I am happy to submit a PR for this, just wanted to gauge the response first. Thanks!

The spec I was trying is:

elasticsearch_install 'elasticsearch' do
    type 'package'
    version <existing_version>
    action :remove
end

Here is some output from test-kitchen for my wrapper cookbook

           Error executing action `remove` on resource 'elasticsearch_install[elasticsearch]'
           ================================================================================

           Mixlib::ShellOut::ShellCommandFailed
           ------------------------------------
           dpkg_package[/tmp/kitchen/cache/elasticsearch-6.4.1.deb] (/tmp/kitchen/cache/cookbooks/elasticsearch/libraries/provider_install.rb line 143) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0, 1], but received '2'
           ---- Begin output of ["dpkg", "-s", "/tmp/kitchen/cache/elasticsearch-6.4.1.deb"] ----
           STDOUT:
           STDERR: dpkg-query: error: --status needs a valid package name but '/tmp/kitchen/cache/elasticsearch-6.4.1.deb' is not: illegal package name in specifier '/tmp/kitchen/cache/elasticsearch-6.4.1.deb': must start with an alphanumeric character

           Use --help for help about querying packages.
           ---- End output of ["dpkg", "-s", "/tmp/kitchen/cache/elasticsearch-6.4.1.deb"] ----
           Ran ["dpkg", "-s", "/tmp/kitchen/cache/elasticsearch-6.4.1.deb"] returned 2

           Cookbook Trace:
           ---------------
           /tmp/kitchen/cache/cookbooks/elasticsearch/libraries/provider_install.rb:152:in `remove_package_wrapper_action'
           /tmp/kitchen/cache/cookbooks/elasticsearch/libraries/provider_install.rb:28:in `action_remove'

           Resource Declaration:
           ---------------------
           # In /tmp/kitchen/cache/cookbooks/elasticsearch_6/recipes/upgrade.rb

            33: elasticsearch_install 'elasticsearch' do
            34:     type 'package'
            35:     version '6.4.1'
            36:     action :remove
            37: end
            38:

           Compiled Resource:
           ------------------
           # Declared in /tmp/kitchen/cache/cookbooks/elasticsearch_6/recipes/upgrade.rb:33:in `from_file'

           elasticsearch_install("elasticsearch") do
             action [:remove]
             default_guard_interpreter :default
             declared_type :elasticsearch_install
             cookbook_name "elasticsearch_6"
             recipe_name "upgrade"
             type "package"
             version "6.4.1"
           end

           System Info:
           ------------
           chef_version=14.6.47
           platform=ubuntu
           platform_version=16.04
           ruby=ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]
           program_name=/opt/chef/bin/chef-client
           executable=/opt/chef/bin/chef-client


       Running handlers:
       [2018-11-02T18:53:53+00:00] ERROR: Running exception handlers
       Running handlers complete
       [2018-11-02T18:53:53+00:00] ERROR: Exception handlers complete
       Chef Client failed. 2 resources updated in 06 seconds
       [2018-11-02T18:53:53+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       [2018-11-02T18:53:53+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2018-11-02T18:53:53+00:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: elasticsearch_install[elasticsearch] (elasticsearch_6::upgrade line 33) had an error: Mixlib::ShellOut::ShellCommandFailed: dpkg_package[/tmp/kitchen/cache/elasticsearch-6.4.1.deb] (/tmp/kitchen/cache/cookbooks/elasticsearch/libraries/provider_install.rb line 143) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0, 1], but received '2'
       ---- Begin output of ["dpkg", "-s", "/tmp/kitchen/cache/elasticsearch-6.4.1.deb"] ----
       STDOUT:
       STDERR: dpkg-query: error: --status needs a valid package name but '/tmp/kitchen/cache/elasticsearch-6.4.1.deb' is not: illegal package name in specifier '/tmp/kitchen/cache/elasticsearch-6.4.1.deb': must start with an alphanumeric character

       Use --help for help about querying packages.
       ---- End output of ["dpkg", "-s", "/tmp/kitchen/cache/elasticsearch-6.4.1.deb"] ----
       Ran ["dpkg", "-s", "/tmp/kitchen/cache/elasticsearch-6.4.1.deb"] returned 2

joshbranham avatar Nov 02 '18 18:11 joshbranham

Hey there --

I'd be glad to drop the path from the dpkg_package :remove action; it does seem like it's probably unnecessary. Alternately, I'll note you could also use the regular install action with package_options and give dpkg some direction on upgrading the package, which would side-step needing to remove the old package directly.

Hope that helps. Feel free to submit a PR to fix that path in the remove action 👍

martinb3 avatar Nov 06 '18 11:11 martinb3

Hey there --

I'd be glad to drop the path from the dpkg_package :remove action; it does seem like it's probably unnecessary. Alternately, I'll note you could also use the regular install action with package_options and give dpkg some direction on upgrading the package, which would side-step needing to remove the old package directly.

Hope that helps. Feel free to submit a PR to fix that path in the remove action 👍

I think that is a good option as well, although removal should still probably work. PR is up

joshbranham avatar Nov 06 '18 21:11 joshbranham