One or more URLs to pkgutil repositories can be supplied in the "source"
attribute and are given to pkgutil via the -t option as temporary repos.

Signed-off-by: Dominic Cleal <dcl...@redhat.com>
---
Local-branch: tickets/master/8011
 lib/puppet/provider/package/pkgutil.rb     |   45 ++++++++++-------
 spec/unit/provider/package/pkgutil_spec.rb |   72 ++++++++++++++++++++++++----
 2 files changed, 90 insertions(+), 27 deletions(-)

diff --git a/lib/puppet/provider/package/pkgutil.rb 
b/lib/puppet/provider/package/pkgutil.rb
index a1d844f..c4fd913 100755
--- a/lib/puppet/provider/package/pkgutil.rb
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -39,7 +39,8 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => 
:sun, :source => :sun d
 
     # The -c pkglist lists installed packages
     pkginsts = []
-    pkglist(hash).each do |pkg|
+    output = pkguti(["-c"])
+    parse_pkglist(output).each do |pkg|
       pkg.delete(:avail)
       pkginsts << new(pkg)
 
@@ -72,19 +73,17 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => 
:sun, :source => :sun d
     end.reject { |h| h.nil? }
   end
 
-  # Turn our pkgutil -c listing into a bunch of hashes.
-  # Supports :justme => packagename, which uses the optimised --single arg
-  def self.pkglist(hash)
-    command = ["-c"]
-
-    if hash[:justme]
-      # The --single option speeds up the execution, because it queries
-      # the package managament system for one package only.
-      command << "--single"
-      command << hash[:justme]
-    end
+  # Turn our pkgutil -c listing into a hash for a single package.
+  def pkgsingle(resource)
+    # The --single option speeds up the execution, because it queries
+    # the package managament system for one package only.
+    command = ["-c", "--single", resource[:name]]
+    self.class.parse_pkglist(run_pkgutil(resource, command), { :justme => 
resource[:name] })
+  end
 
-    output = pkguti(command).split("\n")
+  # Turn our pkgutil -c listing into a bunch of hashes.
+  def self.parse_pkglist(output, hash = {})
+    output = output.split("\n")
 
     if output[-1] == "Not in catalog"
       Puppet.warning "Package not in pkgutil catalog: %s" % hash[:justme]
@@ -146,18 +145,28 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => 
:sun, :source => :sun d
     end
   end
 
+  def run_pkgutil(resource, *args)
+    # Allow source to be one or more URLs pointing to a repository that all
+    # get passed to pkgutil via one or more -t options
+    if resource[:source]
+      pkguti *[resource[:source].map{|src| [ "-t", src ]}, *args].flatten
+    else
+      pkguti *args.flatten
+    end
+  end
+
   def install
-    pkguti "-y", "-i", @resource[:name]
+    run_pkgutil @resource, "-y", "-i", @resource[:name]
   end
 
   # Retrieve the version from the current package file.
   def latest
-    hash = self.class.pkglist(:justme => @resource[:name])
+    hash = pkgsingle(@resource)
     hash[:avail] if hash
   end
 
   def query
-    if hash = self.class.pkglist(:justme => @resource[:name])
+    if hash = pkgsingle(@resource)
       hash
     else
       {:ensure => :absent}
@@ -165,11 +174,11 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => 
:sun, :source => :sun d
   end
 
   def update
-    pkguti "-y", "-u", @resource[:name]
+    run_pkgutil @resource, "-y", "-u", @resource[:name]
   end
 
   def uninstall
-    pkguti "-y", "-r", @resource[:name]
+    run_pkgutil @resource, "-y", "-r", @resource[:name]
   end
 end
 
diff --git a/spec/unit/provider/package/pkgutil_spec.rb 
b/spec/unit/provider/package/pkgutil_spec.rb
index dcae212..e51add8 100755
--- a/spec/unit/provider/package/pkgutil_spec.rb
+++ b/spec/unit/provider/package/pkgutil_spec.rb
@@ -38,6 +38,20 @@ describe provider do
       @provider.expects(:pkguti).with('-y', '-i', 'TESTpkg')
       @provider.install
     end
+
+    it "should support a single temp repo URL" do
+      @resource[:ensure] = :latest
+      @resource[:source] = "http://example.net/repo";
+      @provider.expects(:pkguti).with('-t', 'http://example.net/repo', '-y', 
'-i', 'TESTpkg')
+      @provider.install
+    end
+
+    it "should support multiple temp repo URLs" do
+      @resource[:ensure] = :latest
+      @resource[:source] = [ 'http://example.net/repo', 
'http://example.net/foo' ]
+      @provider.expects(:pkguti).with('-t', 'http://example.net/repo', '-t', 
'http://example.net/foo', '-y', '-i', 'TESTpkg')
+      @provider.install
+    end
   end
 
   describe "when updating" do
@@ -45,6 +59,18 @@ describe provider do
       @provider.expects(:pkguti).with('-y', '-u', 'TESTpkg')
       @provider.update
     end
+
+    it "should support a single temp repo URL" do
+      @resource[:source] = "http://example.net/repo";
+      @provider.expects(:pkguti).with('-t', 'http://example.net/repo', '-y', 
'-u', 'TESTpkg')
+      @provider.update
+    end
+
+    it "should support multiple temp repo URLs" do
+      @resource[:source] = [ 'http://example.net/repo', 
'http://example.net/foo' ]
+      @provider.expects(:pkguti).with('-t', 'http://example.net/repo', '-t', 
'http://example.net/foo', '-y', '-u', 'TESTpkg')
+      @provider.update
+    end
   end
 
   describe "when uninstalling" do
@@ -52,6 +78,18 @@ describe provider do
       @provider.expects(:pkguti).with('-y', '-r', 'TESTpkg')
       @provider.uninstall
     end
+
+    it "should support a single temp repo URL" do
+      @resource[:source] = "http://example.net/repo";
+      @provider.expects(:pkguti).with('-t', 'http://example.net/repo', '-y', 
'-r', 'TESTpkg')
+      @provider.uninstall
+    end
+
+    it "should support multiple temp repo URLs" do
+      @resource[:source] = [ 'http://example.net/repo', 
'http://example.net/foo' ]
+      @provider.expects(:pkguti).with('-t', 'http://example.net/repo', '-t', 
'http://example.net/foo', '-y', '-r', 'TESTpkg')
+      @provider.uninstall
+    end
   end
 
   describe "when getting latest version" do
@@ -59,7 +97,16 @@ describe provider do
       fake_data = "
 noisy output here
 TESTpkg                   1.4.5,REV=2007.11.18      1.4.5,REV=2007.11.20"
-      provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns 
fake_data
+      provider.expects(:pkguti).with('-c', '--single', 'TESTpkg').returns 
fake_data
+      @provider.latest.should == "1.4.5,REV=2007.11.20"
+    end
+
+    it "should support a temp repo URL" do
+      @resource[:source] = "http://example.net/repo";
+      fake_data = "
+noisy output here
+TESTpkg                   1.4.5,REV=2007.11.18      1.4.5,REV=2007.11.20"
+      provider.expects(:pkguti).with('-t', 'http://example.net/repo', '-c', 
'--single', 'TESTpkg').returns fake_data
       @provider.latest.should == "1.4.5,REV=2007.11.20"
     end
 
@@ -67,19 +114,19 @@ TESTpkg                   1.4.5,REV=2007.11.18      
1.4.5,REV=2007.11.20"
       fake_data = "
 noisy output here
 TESTpkg                   1.4.5,REV=2007.11.18      SAME"
-      provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns 
fake_data
+      provider.expects(:pkguti).with('-c', '--single', 'TESTpkg').returns 
fake_data
       @provider.latest.should == "1.4.5,REV=2007.11.18"
     end
 
     it "should handle a non-existent package" do
       fake_data = "noisy output here
 Not in catalog"
-      provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns 
fake_data
+      provider.expects(:pkguti).with('-c', '--single', 'TESTpkg').returns 
fake_data
       @provider.latest.should == nil
     end
 
     it "should warn on unknown pkgutil noise" do
-      provider.expects(:pkguti).with(['-c', '--single', 
'TESTpkg']).returns("testingnoise")
+      provider.expects(:pkguti).with('-c', '--single', 
'TESTpkg').returns("testingnoise")
       @provider.latest.should == nil
     end
 
@@ -93,7 +140,7 @@ gpg: Good signature from \"Distribution Manager 
<d...@blastwave.org>\"
 ==> 2770 packages loaded from 
/var/opt/csw/pkgutil/catalog.mirror.opencsw.org_opencsw_unstable_i386_5.11
 package                   installed                 catalog
 TESTpkg                   1.4.5,REV=2007.11.18      1.4.5,REV=2007.11.20"
-      provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns 
fake_data
+      provider.expects(:pkguti).with('-c', '--single', 'TESTpkg').returns 
fake_data
       @provider.latest.should == "1.4.5,REV=2007.11.20"
     end
 
@@ -101,7 +148,7 @@ TESTpkg                   1.4.5,REV=2007.11.18      
1.4.5,REV=2007.11.20"
       fake_data = "
 noisy output here
 REALpkg                   1.4.5,REV=2007.11.18      1.4.5,REV=2007.11.20"
-      provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns 
fake_data
+      provider.expects(:pkguti).with('-c', '--single', 'TESTpkg').returns 
fake_data
       @provider.query[:name].should == "TESTpkg"
     end
   end
@@ -109,22 +156,29 @@ REALpkg                   1.4.5,REV=2007.11.18      
1.4.5,REV=2007.11.20"
   describe "when querying current version" do
     it "should return TESTpkg's version string" do
       fake_data = "TESTpkg  1.4.5,REV=2007.11.18  1.4.5,REV=2007.11.20"
-      provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns 
fake_data
+      provider.expects(:pkguti).with('-c', '--single', 'TESTpkg').returns 
fake_data
       @provider.query[:ensure].should == "1.4.5,REV=2007.11.18"
     end
 
     it "should handle a package that isn't installed" do
       fake_data = "TESTpkg  notinst  1.4.5,REV=2007.11.20"
-      provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns 
fake_data
+      provider.expects(:pkguti).with('-c', '--single', 'TESTpkg').returns 
fake_data
       @provider.query[:ensure].should == :absent
     end
 
     it "should handle a non-existent package" do
       fake_data = "noisy output here
 Not in catalog"
-      provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns 
fake_data
+      provider.expects(:pkguti).with('-c', '--single', 'TESTpkg').returns 
fake_data
       @provider.query[:ensure].should == :absent
     end
+
+    it "should support a temp repo URL" do
+      @resource[:source] = "http://example.net/repo";
+      fake_data = "TESTpkg  1.4.5,REV=2007.11.18  1.4.5,REV=2007.11.20"
+      provider.expects(:pkguti).with('-t', 'http://example.net/repo', '-c', 
'--single', 'TESTpkg').returns fake_data
+      @provider.query[:ensure].should == "1.4.5,REV=2007.11.18"
+    end
   end
 
   describe "when querying current instances" do
-- 
1.7.4.4

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to puppet-dev@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to