Chef

no package provider for Solaris

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 0.7.10
  • Fix Version/s: 0.9.8
  • Component/s: Providers
  • Labels:
    None
  • Environment:

    Solaris 10, Ruby 1.8.7 via openCSW

  • Triage Status:
    Triaged

Description

There is no provider for services via Solaris. In lib/chef/provider/platform.rb, there is only a "solaris" platform with nothing in it. Note that even if this were populated, chef on Solaris wouldn't find it due to the OS being declared as "solaris2".

This will require several different provider options:

  • pkgadd (the standard Solaris package installer, analogous to dpkg on Debian Linux)
  • pkg-get (older/deprecated interface to the OpenCSW and Blastwave repositories, analogous to apt on Debian Linux)
  • pkgutil (newer interface to the OpenCSW and Blastwave repositories, analogous to apt on Debian Linux)
  • whatever opensolaris will be using (still under development?)

Activity

Hide
Kurt Yoder added a comment - 26/Feb/10 8:24 PM

Here is my attempt at supporting Solaris "pkg" packages (works locally for me):

— package.rb 2010-02-26 15:19:04.956006337 -0500
+++ chef/chef/lib/chef/resource/package.rb 2009-11-20 10:28:49.219605036 -0500
@@ -29,7 +29,6 @@
@version = nil
@candidate_version = nil
@response_file = nil

  • @admin_file = nil
    @source = nil
    @action = "install"
    @options = nil
    @@ -52,14 +51,6 @@
    )
    end
  • def admin_file(arg=nil)
  • set_or_return(
  • :admin_file,
  • arg,
  • :kind_of => [ String ]
  • )
  • end
  • def response_file(arg=nil)
    set_or_return(
    :response_file,

— package.rb 2010-02-26 15:20:37.826017504 -0500
+++ chef/chef/lib/chef/provider/package.rb 2009-11-20 10:28:49.209605192 -0500
@@ -52,10 +52,6 @@

Chef::Log.info("Installing #{@new_resource} version #{install_version}")

- if @new_resource.admin_file
- admin_package(@new_resource.package_name, install_version)
- end
-
# We need to make sure we handle the preseed file
if @new_resource.response_file
preseed_package(@new_resource.package_name, install_version)
@@ -81,9 +77,6 @@
def action_remove
if should_remove_package(@current_resource.version, @new_resource.version)
Chef::Log.info("Removing #{@new_resource}")

  • if @new_resource.admin_file
  • admin_package(@new_resource.package_name, install_version)
  • end
    remove_package(@current_resource.package_name, @new_resource.version)
    @new_resource.updated = true
    end
    @@ -131,10 +124,6 @@
    raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support pre-seeding package install/upgrade instructions - don't ask it to!"
    end

    - def admin_package(name, version)
    - raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support an admin file - don't ask it to!"
  • end
  • def get_preseed_file(name, version)
    full_cache_dir = Chef::FileCache.create_cache_path("preseed/#{@new_resource.cookbook_name}")
    full_cache_file = "#{full_cache_dir}/#{name}-#{version}.seed"






    Plus an entirely new provider chef/provider/package/pkg.rb:
    require 'chef/provider/package'
    require 'chef/mixin/command'
    require 'chef/resource/package'

    class Chef
    class Provider
    class Package
    class Pkg < Chef::Provider::Package

    def load_current_resource
    @current_resource = Chef::Resource::Package.new(@new_resource.name)
    @current_resource.package_name(@new_resource.package_name)
    @new_resource.version(nil)

    if @new_resource.source
    unless ::File.exists?(@new_resource.source)
    raise Chef::Exceptions::Package, "Package #{@new_resource.name} not found: #{@new_resource.source}"
    end

    Chef::Log.debug("Checking pkg status for #{@new_resource.package_name}")
    status = popen4("pkginfo -d #{@new_resource.source} -l") do |pid, stdin, stdout, stderr|
    stdout.each do |line|
    case line
    when /PKGINST:\s+(.+)/
    @current_resource.package_name($1)
    when /VERSION:\s+(.+)/
    @new_resource.version($1)
    end
    end
    end
    else
    if @new_resource.action.include?(:install)
    raise Chef::Exceptions::Package, "Source for package #{@new_resource.name} required for action install"
    end
    end

    Chef::Log.debug("Checking install state for #{@current_resource.package_name}")
    status = popen4("pkginfo -i -l #{@current_resource.package_name}") do |pid, stdin, stdout, stderr|
    stdout.each do |line|
    case line
    when /VERSION:\s+(.+)/
    Chef::Log.debug("Current version is #{$1}")
    @current_resource.version($1)
    end
    end
    end

    unless status.exitstatus == 0 || status.exitstatus == 1
    raise Chef::Exceptions::Package, "pkginfo failed - #{status.inspect}!"
    end

    @current_resource
    end

    def install_package(name, version)
    admin_file = admin_file_argument
    run_command_with_systems_locale(
    :command => "pkgadd#{admin_file} -G -n -d #{@new_resource.source} all"
    )
    end

    def remove_package(name, version)
    admin_file = admin_file_argument
    run_command_with_systems_locale(
    :command => "pkgrm#{admin_file} -n #{name}"
    )
    end

    def admin_file_argument()
    admin_file = ''
    if (@new_resource.admin_file)
    admin_file = " -a #{@new_resource.admin_file}"
    else
    Chef::Log.info("attempting action without an admin file; probably will not complete!")
    end
    return admin_file
    end

    def admin_package(name, version)

    # if we have a system-wide admin file already, use it
    solaris_admin_dir = '/var/sadm/install/admin'
    if ::File.exists?("#{solaris_admin_dir}/#{@new_resource.admin_file}")
    Chef::Log.debug("Using existing admin file: #{solaris_admin_dir}/#{@new_resource.admin_file}")

    # otherwise, assume it's a local file and download it
    else
    cache_sub_path = "admin/#{@new_resource.cookbook_name}"
    cache_full_path = Chef::FileCache.create_cache_path(cache_sub_path)
    cache_file = "#{name}-#{version}"

Chef::Log.debug("Fetching admin file to #{cache_full_path}/#{cache_file}")

remote_file = Chef::Resource::RemoteFile.new(
"#{cache_full_path}/#{cache_file}",
nil,
@node
)
remote_file.cookbook_name = @new_resource.cookbook_name
remote_file.source(@new_resource.admin_file)
remote_file.backup(false)

rf_provider = Chef::Platform.provider_for_node(@node, remote_file)
rf_provider.load_current_resource
rf_provider.action_create

if remote_file.updated
Chef::FileCache.load("#{cache_sub_path}/#{cache_file}", false)
Chef::Log.debug("Setting up admin file before installing #{@new_resource}.")
end

@new_resource.admin_file("#{cache_full_path}/#{cache_file}")
end

end

end
end
end
end

Show
Kurt Yoder added a comment - 26/Feb/10 8:24 PM Here is my attempt at supporting Solaris "pkg" packages (works locally for me): — package.rb 2010-02-26 15:19:04.956006337 -0500 +++ chef/chef/lib/chef/resource/package.rb 2009-11-20 10:28:49.219605036 -0500 @@ -29,7 +29,6 @@ @version = nil @candidate_version = nil @response_file = nil
  • @admin_file = nil @source = nil @action = "install" @options = nil @@ -52,14 +51,6 @@ ) end
  • def admin_file(arg=nil)
  • set_or_return(
  • :admin_file,
  • arg,
  • :kind_of => [ String ]
  • )
  • end
  • def response_file(arg=nil) set_or_return( :response_file,
— package.rb 2010-02-26 15:20:37.826017504 -0500 +++ chef/chef/lib/chef/provider/package.rb 2009-11-20 10:28:49.209605192 -0500 @@ -52,10 +52,6 @@ Chef::Log.info("Installing #{@new_resource} version #{install_version}") - if @new_resource.admin_file - admin_package(@new_resource.package_name, install_version) - end - # We need to make sure we handle the preseed file if @new_resource.response_file preseed_package(@new_resource.package_name, install_version) @@ -81,9 +77,6 @@ def action_remove if should_remove_package(@current_resource.version, @new_resource.version) Chef::Log.info("Removing #{@new_resource}")
  • if @new_resource.admin_file
  • admin_package(@new_resource.package_name, install_version)
  • end remove_package(@current_resource.package_name, @new_resource.version) @new_resource.updated = true end @@ -131,10 +124,6 @@ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support pre-seeding package install/upgrade instructions - don't ask it to!" end - def admin_package(name, version) - raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support an admin file - don't ask it to!"
  • end
  • def get_preseed_file(name, version) full_cache_dir = Chef::FileCache.create_cache_path("preseed/#{@new_resource.cookbook_name}") full_cache_file = "#{full_cache_dir}/#{name}-#{version}.seed" Plus an entirely new provider chef/provider/package/pkg.rb: require 'chef/provider/package' require 'chef/mixin/command' require 'chef/resource/package' class Chef class Provider class Package class Pkg < Chef::Provider::Package def load_current_resource @current_resource = Chef::Resource::Package.new(@new_resource.name) @current_resource.package_name(@new_resource.package_name) @new_resource.version(nil) if @new_resource.source unless ::File.exists?(@new_resource.source) raise Chef::Exceptions::Package, "Package #{@new_resource.name} not found: #{@new_resource.source}" end Chef::Log.debug("Checking pkg status for #{@new_resource.package_name}") status = popen4("pkginfo -d #{@new_resource.source} -l") do |pid, stdin, stdout, stderr| stdout.each do |line| case line when /PKGINST:\s+(.+)/ @current_resource.package_name($1) when /VERSION:\s+(.+)/ @new_resource.version($1) end end end else if @new_resource.action.include?(:install) raise Chef::Exceptions::Package, "Source for package #{@new_resource.name} required for action install" end end Chef::Log.debug("Checking install state for #{@current_resource.package_name}") status = popen4("pkginfo -i -l #{@current_resource.package_name}") do |pid, stdin, stdout, stderr| stdout.each do |line| case line when /VERSION:\s+(.+)/ Chef::Log.debug("Current version is #{$1}") @current_resource.version($1) end end end unless status.exitstatus == 0 || status.exitstatus == 1 raise Chef::Exceptions::Package, "pkginfo failed - #{status.inspect}!" end @current_resource end def install_package(name, version) admin_file = admin_file_argument run_command_with_systems_locale( :command => "pkgadd#{admin_file} -G -n -d #{@new_resource.source} all" ) end def remove_package(name, version) admin_file = admin_file_argument run_command_with_systems_locale( :command => "pkgrm#{admin_file} -n #{name}" ) end def admin_file_argument() admin_file = '' if (@new_resource.admin_file) admin_file = " -a #{@new_resource.admin_file}" else Chef::Log.info("attempting action without an admin file; probably will not complete!") end return admin_file end def admin_package(name, version) # if we have a system-wide admin file already, use it solaris_admin_dir = '/var/sadm/install/admin' if ::File.exists?("#{solaris_admin_dir}/#{@new_resource.admin_file}") Chef::Log.debug("Using existing admin file: #{solaris_admin_dir}/#{@new_resource.admin_file}") # otherwise, assume it's a local file and download it else cache_sub_path = "admin/#{@new_resource.cookbook_name}" cache_full_path = Chef::FileCache.create_cache_path(cache_sub_path) cache_file = "#{name}-#{version}"
Chef::Log.debug("Fetching admin file to #{cache_full_path}/#{cache_file}") remote_file = Chef::Resource::RemoteFile.new( "#{cache_full_path}/#{cache_file}", nil, @node ) remote_file.cookbook_name = @new_resource.cookbook_name remote_file.source(@new_resource.admin_file) remote_file.backup(false) rf_provider = Chef::Platform.provider_for_node(@node, remote_file) rf_provider.load_current_resource rf_provider.action_create if remote_file.updated Chef::FileCache.load("#{cache_sub_path}/#{cache_file}", false) Chef::Log.debug("Setting up admin file before installing #{@new_resource}.") end @new_resource.admin_file("#{cache_full_path}/#{cache_file}") end end end end end end
Hide
Adam Jacob added a comment - 26/Mar/10 4:21 AM

CHEF-529 includes package support for opensolaris - will that work for you?

greenmoss can you point us at a git repostiory for the code contained in this ticket?

See the instructions at http://wiki.opscode.com/display/opscode/Contributing to make this path easier/faster in the future.

Show
Adam Jacob added a comment - 26/Mar/10 4:21 AM CHEF-529 includes package support for opensolaris - will that work for you? greenmoss can you point us at a git repostiory for the code contained in this ticket? See the instructions at http://wiki.opscode.com/display/opscode/Contributing to make this path easier/faster in the future.
Hide
Kurt Yoder added a comment - 26/Mar/10 7:34 PM

Sadly, I'm using Solaris 10, so OpenSolaris package provider doesn't help me.

Show
Kurt Yoder added a comment - 26/Mar/10 7:34 PM Sadly, I'm using Solaris 10, so OpenSolaris package provider doesn't help me.
Hide
Toomas Pelberg added a comment - 04/May/10 7:02 AM

Created http://github.com/toomasp/chef/tree/CHEF-587

Tests seem to pass:

spec -f s -c spec/unit/provider/package/solaris_spec.rb

Chef::Provider::Package::Solaris load_current_resource

  • should create a current resource with the name of new_resource
  • should set the current reource package name to the new resource package name
  • should raise an exception if a source is supplied but not found
  • should get the source package version from pkginfo if provided
  • should return the current version installed if found by pkginfo
  • should raise an exception if the source is not set but we are installing
  • should raise an exception if rpm fails to run
  • should return a current resource with a nil version if the package is not found

Chef::Provider::Package::Solaris candidate_version

  • should return the candidate_version variable if already setup
  • should lookup the candidate_version if the variable is not already set
  • should throw and exception if the exitstatus is not 0

Chef::Provider::Package::Solaris install and upgrade

  • should run pkgadd -n -d with the package source to install
  • should run pkgadd -n -a /tmp/myadmin -d with the package options -a /tmp/myadmin

Chef::Provider::Package::Solaris remove

  • should run pkgrm -n to remove the package
  • should run pkgrm -n -a /tmp/myadmin with options -a /tmp/myadmin

Finished in 0.123658 seconds

15 examples, 0 failures

And I can confirm that it works on Solaris Sparc 5.10 u8

Show
Toomas Pelberg added a comment - 04/May/10 7:02 AM Created http://github.com/toomasp/chef/tree/CHEF-587 Tests seem to pass: spec -f s -c spec/unit/provider/package/solaris_spec.rb Chef::Provider::Package::Solaris load_current_resource
  • should create a current resource with the name of new_resource
  • should set the current reource package name to the new resource package name
  • should raise an exception if a source is supplied but not found
  • should get the source package version from pkginfo if provided
  • should return the current version installed if found by pkginfo
  • should raise an exception if the source is not set but we are installing
  • should raise an exception if rpm fails to run
  • should return a current resource with a nil version if the package is not found
Chef::Provider::Package::Solaris candidate_version
  • should return the candidate_version variable if already setup
  • should lookup the candidate_version if the variable is not already set
  • should throw and exception if the exitstatus is not 0
Chef::Provider::Package::Solaris install and upgrade
  • should run pkgadd -n -d with the package source to install
  • should run pkgadd -n -a /tmp/myadmin -d with the package options -a /tmp/myadmin
Chef::Provider::Package::Solaris remove
  • should run pkgrm -n to remove the package
  • should run pkgrm -n -a /tmp/myadmin with options -a /tmp/myadmin
Finished in 0.123658 seconds 15 examples, 0 failures And I can confirm that it works on Solaris Sparc 5.10 u8
Hide
Daniel DeLeo added a comment - 08/Jul/10 2:43 AM

This is now merged to master, thank you for the patch Toomas.

Show
Daniel DeLeo added a comment - 08/Jul/10 2:43 AM This is now merged to master, thank you for the patch Toomas.
Hide
Kurt Yoder added a comment - 08/Jul/10 1:02 PM

I didn't notice this before, but this fix does not include support for pkg-get or pkgutil.

Show
Kurt Yoder added a comment - 08/Jul/10 1:02 PM I didn't notice this before, but this fix does not include support for pkg-get or pkgutil.
Hide
Kurt Yoder added a comment - 08/Jul/10 1:11 PM

I've added a new ticket for the pkg-get/pkgutil issue:

CHEF-1431

Show
Kurt Yoder added a comment - 08/Jul/10 1:11 PM I've added a new ticket for the pkg-get/pkgutil issue: CHEF-1431

People

Vote (3)
Watch (3)

Dates

  • Created:
    02/Oct/09 9:24 PM
    Updated:
    08/Jul/10 1:11 PM
    Resolved:
    10/May/10 5:00 AM