[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

test branch puppet-dev at googlegroups.com
Wed Jul 14 10:32:53 UTC 2010


The following commit has been merged in the upstream branch:
commit 0f2d3ce686f7e706537e03ebb2166478fa55f649
Author: Rein Henrichs <rein at puppetlabs.com>
Date:   Tue Apr 13 14:20:48 2010 -0700

    Fixes #1223 Add Zypper support for SuSE machines
    
    Zypper is the replacement for `rug' from earlier SuSE releases.  Zypper
    is backward compatible with the rug command (mostly) and supports most
    of the same commands that rug does.
    
    This version fixes a number of bugs in the original:
    
    * when installing with a specified version, fix bug where the package
      name was being doubled ("foo" became "foofoo").
    
    * fix bug where package name and version were separated by a "=" when it
      should have been a "-".
    
    * Update specs to reflect the implementation's use of the "-l" flag as
      recommended in http://groups.google.com/group/puppet-dev/msg/d86416c079bd3faf
    
    Signed-off-by: Rein Henrichs <reinh at reinh.com>

diff --git a/lib/puppet/provider/package/rug.rb b/lib/puppet/provider/package/zypper.rb
similarity index 65%
copy from lib/puppet/provider/package/rug.rb
copy to lib/puppet/provider/package/zypper.rb
index 9f09b35..2a9c2b3 100644
--- a/lib/puppet/provider/package/rug.rb
+++ b/lib/puppet/provider/package/zypper.rb
@@ -1,14 +1,14 @@
-Puppet::Type.type(:package).provide :rug, :parent => :rpm do
-    desc "Support for suse ``rug`` package manager."
+Puppet::Type.type(:package).provide :zypper, :parent => :rpm do
+    desc "Support for SuSE ``zypper`` package manager. Found in SLES10sp2+ and SLES11"
 
     has_feature :versionable
 
-    commands :rug => "/usr/bin/rug"
+    commands :rug => "/usr/bin/zypper"
     commands :rpm => "rpm"
-    defaultfor :operatingsystem => [:suse, :sles]
-    confine    :operatingsystem => [:suse, :sles]
 
-    # Install a package using 'rug'.
+    confine    :operatingsystem => [:suse, :sles, :sled, :opensuse]
+
+    # Install a package using 'zypper'.
     def install
         should = @resource.should(:ensure)
         self.debug "Ensuring => #{should}"
@@ -20,9 +20,9 @@ Puppet::Type.type(:package).provide :rug, :parent => :rpm do
             # pass
         else
             # Add the package version
-            wanted += "-%s" % should
+            wanted = "%s-%s" % [wanted, should]
         end
-        output = rug "--quiet", :install, "-y", wanted
+        output = zypper "--quiet", :install, "-l", "-y", wanted
 
         unless self.query
             raise Puppet::ExecutionFailure.new(
@@ -33,8 +33,8 @@ Puppet::Type.type(:package).provide :rug, :parent => :rpm do
 
     # What's the latest package version available?
     def latest
-        #rug can only get a list of *all* available packages?
-        output = rug "list-updates"
+        #zypper can only get a list of *all* available packages?
+        output = zypper "list-updates"
 
         if output =~ /#{Regexp.escape @resource[:name]}\s*\|\s*([^\s\|]+)/
             return $1
diff --git a/spec/unit/provider/package/zypper.rb b/spec/unit/provider/package/zypper.rb
new file mode 100644
index 0000000..be45a4c
--- /dev/null
+++ b/spec/unit/provider/package/zypper.rb
@@ -0,0 +1,81 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+provider_class = Puppet::Type.type(:package).provider(:zypper)
+
+describe provider_class do
+    before(:each) do
+        # Create a mock resource
+        @resource = stub 'resource'
+
+        # A catch all; no parameters set
+        @resource.stubs(:[]).returns(nil)
+
+        # But set name and source
+        @resource.stubs(:[]).with(:name).returns "mypackage"
+        @resource.stubs(:[]).with(:ensure).returns :installed
+        @resource.stubs(:command).with(:zypper).returns "/usr/bin/zypper"
+
+        @provider = provider_class.new(@resource)
+    end
+
+    it "should have an install method" do
+        @provider = provider_class.new
+        @provider.should respond_to(:install)
+    end
+
+    it "should have a latest method" do
+        @provider = provider_class.new
+        @provider.should respond_to(:uninstall)
+    end
+
+    it "should have an update method" do
+        @provider = provider_class.new
+        @provider.should respond_to(:update)
+    end
+
+    it "should have a latest method" do
+        @provider = provider_class.new
+        @provider.should respond_to(:latest)
+    end
+
+    describe "when installing" do
+        it "should use a command-line with versioned package'" do
+            @resource.stubs(:should).with(:ensure).returns "1.2.3-4.5.6"
+            @provider.expects(:zypper).with('--quiet', :install, '-l', '-y', 'mypackage-1.2.3-4.5.6')
+            @provider.expects(:query).returns "mypackage 0 1.2.3 4.5.6 x86_64"
+            @provider.install
+        end
+
+        it "should use a command-line without versioned package" do
+            @resource.stubs(:should).with(:ensure).returns :latest
+            @provider.expects(:zypper).with('--quiet', :install, '-l', '-y', 'mypackage')
+            @provider.expects(:query).returns "mypackage 0 1.2.3 4.5.6 x86_64"
+            @provider.install
+        end
+    end
+
+    describe "when updating" do
+        it "should call install method of instance" do
+            @provider.expects(:install)
+            @provider.update
+        end
+    end
+
+    describe "when getting latest version" do
+        it "should return a version string" do
+
+            fake_data = "Loading repository data...
+Reading installed packages...
+S | Repository     | Name                  | Version         | Arch  
+--+----------------+-----------------------+-----------------+-------
+v | SLES11-Updates | cups                  | 1.1.1           | x86_64
+v | SLES11-Updates | mypackage             | 1.3.9h-8.20.1   | x86_64"
+
+            @provider.expects(:zypper).with("list-updates").returns fake_data
+            @provider.latest.should == "1.3.9h-8.20.1"
+        end
+    end
+
+ end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list