diff options
| author | Roy Nielsen <rsn@lanl.gov> | 2010-03-26 13:25:21 -0600 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | eafde5cacaac79da79d9d1415618801fcc37edcc (patch) | |
| tree | 5b16f5257095d37af8fe70e49e6e374fe455f614 | |
| parent | c9e3d75951d507059d25b76720d36a8d6d33be65 (diff) | |
| download | puppet-eafde5cacaac79da79d9d1415618801fcc37edcc.tar.gz puppet-eafde5cacaac79da79d9d1415618801fcc37edcc.tar.xz puppet-eafde5cacaac79da79d9d1415618801fcc37edcc.zip | |
Added support for flat packages in the pkgdmg package provider.
Added a test in:
./spec/unit/provider/package/pkgdmg.rb
To test flat package support.
The case where a package is a .pkg bundle, curl will attempt
to download and not work. The "installer" command will then
fail, as the source will be "not found" and the resource will
fail. The puppet run will continue.
Signed-off-by: Roy Nielsen <rsn@lanl.gov>
| -rw-r--r-- | lib/puppet/provider/package/pkgdmg.rb | 49 | ||||
| -rwxr-xr-x | spec/unit/provider/package/pkgdmg.rb | 21 |
2 files changed, 44 insertions, 26 deletions
diff --git a/lib/puppet/provider/package/pkgdmg.rb b/lib/puppet/provider/package/pkgdmg.rb index 8a916d5c4..25edc9109 100644 --- a/lib/puppet/provider/package/pkgdmg.rb +++ b/lib/puppet/provider/package/pkgdmg.rb @@ -68,8 +68,8 @@ Puppet::Type.type(:package).provide :pkgdmg, :parent => Puppet::Provider::Packag end def self.installpkgdmg(source, name) - unless source =~ /\.dmg$/i - raise Puppet::Error.new("Mac OS X PKG DMG's must specificy a source string ending in .dmg") + unless source =~ /\.dmg$/i || source =~ /\.pkg$/i + raise Puppet::Error.new("Mac OS X PKG DMG's must specificy a source string ending in .dmg or flat .pkg file") end require 'open-uri' cached_source = source @@ -85,28 +85,34 @@ Puppet::Type.type(:package).provide :pkgdmg, :parent => Puppet::Provider::Packag end begin - File.open(cached_source) do |dmg| - xml_str = hdiutil "mount", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", "/tmp", dmg.path - hdiutil_info = Plist::parse_xml(xml_str) - unless hdiutil_info.has_key?("system-entities") - raise Puppet::Error.new("No disk entities returned by mount at %s" % dmg.path) - end - mounts = hdiutil_info["system-entities"].collect { |entity| - entity["mount-point"] - }.compact - begin - mounts.each do |mountpoint| - Dir.entries(mountpoint).select { |f| - f =~ /\.m{0,1}pkg$/i - }.each do |pkg| - installpkg("#{mountpoint}/#{pkg}", name, source) - end + if source =~ /\.dmg$/i + File.open(cached_source) do |dmg| + xml_str = hdiutil "mount", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", "/tmp", dmg.path + hdiutil_info = Plist::parse_xml(xml_str) + unless hdiutil_info.has_key?("system-entities") + raise Puppet::Error.new("No disk entities returned by mount at %s" % dmg.path) end - ensure - mounts.each do |mountpoint| - hdiutil "eject", mountpoint + mounts = hdiutil_info["system-entities"].collect { |entity| + entity["mount-point"] + }.compact + begin + mounts.each do |mountpoint| + Dir.entries(mountpoint).select { |f| + f =~ /\.m{0,1}pkg$/i + }.each do |pkg| + installpkg("#{mountpoint}/#{pkg}", name, source) + end + end + ensure + mounts.each do |mountpoint| + hdiutil "eject", mountpoint + end end end + elsif source =~ /\.pkg$/i + installpkg(cached_source, name, source) + else + raise Puppet::Error.new("Mac OS X PKG DMG's must specificy a source string ending in .dmg or flat .pkg file") end ensure # JJM Remove the file if open-uri didn't already do so. @@ -116,6 +122,7 @@ Puppet::Type.type(:package).provide :pkgdmg, :parent => Puppet::Provider::Packag def query if FileTest.exists?("/var/db/.puppet_pkgdmg_installed_#{@resource[:name]}") + Puppet.debug "/var/db/.puppet_pkgdmg_installed_#{@resource[:name]} found" return {:name => @resource[:name], :ensure => :present} else return nil diff --git a/spec/unit/provider/package/pkgdmg.rb b/spec/unit/provider/package/pkgdmg.rb index d43757401..3f007e01b 100755 --- a/spec/unit/provider/package/pkgdmg.rb +++ b/spec/unit/provider/package/pkgdmg.rb @@ -9,8 +9,9 @@ describe provider do @resource = stub 'resource', :[] => "dummypkgdmg" @provider = provider.new(@resource) - @fakemountpoint = "/tmp/dmg.foo" - @fakehdiutilinfo = {"system-entities" => [{"mount-point" => @fakemountpoint}] } + @fakemountpoint = "/tmp/dmg.foo" + @fakepkgfile = "/tmp/test.pkg" + @fakehdiutilinfo = {"system-entities" => [{"mount-point" => @fakemountpoint}] } @fakehdiutilplist = Plist::Emit.dump(@fakehdiutilinfo) @hdiutilmountargs = ["mount", "-plist", "-nobrowse", "-readonly", @@ -36,8 +37,8 @@ describe provider do lambda { @provider.install }.should raise_error(Puppet::Error) end - it "the source does not end in .dmg" do - @resource.stubs(:[]).with(:source).returns "notendingindotdmg" + it "the source does not end in .dmg or .pkg" do + @resource.stubs(:[]).with(:source).returns "notendingindotdmgorpkg" lambda { @provider.install }.should raise_error(Puppet::Error) end @@ -48,7 +49,7 @@ describe provider do end # These tests shouldn't be this messy. The pkgdmg provider needs work... - describe "when installing" do + describe "when installing a pkgdmg" do before do fh = mock 'filehandle' fh.stubs(:path).yields "/tmp/foo" @@ -70,4 +71,14 @@ describe provider do @provider.install end end + + describe "when installing flat pkg file" do + it "should call installpkg if a flat pkg file is found instead of a .dmg image" do + @resource.stubs(:[]).with(:source).returns "/tmp/test.pkg" + @resource.stubs(:[]).with(:name).returns "testpkg" + @provider.class.expects(:installpkgdmg).with("#{@fakepkgfile}", "testpkg").returns "" + @provider.install + end + end + end |
