diff options
author | Luke Kanies <luke@madstop.com> | 2008-10-01 19:06:10 -0500 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2008-10-02 13:36:26 +1000 |
commit | e32256af93a9c2c272f12576bdcf7005a83bb90f (patch) | |
tree | 86ba2c0424241c765642bd88e9909292055ebadc /lib/puppet | |
parent | ddda80a05d723271c4a2f7229129f1929a06ba71 (diff) | |
download | puppet-e32256af93a9c2c272f12576bdcf7005a83bb90f.tar.gz puppet-e32256af93a9c2c272f12576bdcf7005a83bb90f.tar.xz puppet-e32256af93a9c2c272f12576bdcf7005a83bb90f.zip |
Migrating the apt and dpkg tests to rspec.
I left the aptitude and aptrpm tests as an exercise
for the reader.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet')
-rwxr-xr-x | lib/puppet/provider/package/apt.rb | 33 | ||||
-rwxr-xr-x | lib/puppet/provider/package/dpkg.rb | 82 |
2 files changed, 45 insertions, 70 deletions
diff --git a/lib/puppet/provider/package/apt.rb b/lib/puppet/provider/package/apt.rb index d0e520f0a..80465129d 100755 --- a/lib/puppet/provider/package/apt.rb +++ b/lib/puppet/provider/package/apt.rb @@ -45,9 +45,19 @@ Puppet::Type.type(:package).provide :apt, :parent => :dpkg, :source => :dpkg do if @resource[:responsefile] self.run_preseed end - should = @resource.should(:ensure) + should = @resource[:ensure] checkforcdrom() + cmd = %w{-q -y} + + keep = "" + if config = @resource[:configfiles] + if config == :keep + cmd << "-o" << 'DPkg::Options::=--force-confold' + else + cmd << "-o" << 'DPkg::Options::=--force-confnew' + end + end str = @resource[:name] case should @@ -57,19 +67,6 @@ Puppet::Type.type(:package).provide :apt, :parent => :dpkg, :source => :dpkg do # Add the package version str += "=%s" % should end - cmd = %w{-q -y} - - keep = "" - if config = @resource[:configfiles] - case config - when :keep - cmd << "-o" << 'DPkg::Options::=--force-confold' - when :replace - cmd << "-o" << 'DPkg::Options::=--force-confnew' - else - raise Puppet::Error, "Invalid 'configfiles' value %s" % config - end - end cmd << :install << str @@ -92,7 +89,7 @@ Puppet::Type.type(:package).provide :apt, :parent => :dpkg, :source => :dpkg do # preseeds answers to dpkg-set-selection from the "responsefile" # def run_preseed - if response = @resource[:responsefile] and FileTest.exists?(response) + if response = @resource[:responsefile] and FileTest.exist?(response) self.info("Preseeding %s to debconf-set-selections" % response) preseed response @@ -101,16 +98,12 @@ Puppet::Type.type(:package).provide :apt, :parent => :dpkg, :source => :dpkg do end end - def update - self.install - end - def uninstall aptget "-y", "-q", :remove, @resource[:name] end def purge - aptget '-y', '-q', 'remove', '--purge', @resource[:name] + aptget '-y', '-q', :remove, '--purge', @resource[:name] # workaround a "bug" in apt, that already removed packages are not purged super end diff --git a/lib/puppet/provider/package/dpkg.rb b/lib/puppet/provider/package/dpkg.rb index ae79f714c..67d31a592 100755 --- a/lib/puppet/provider/package/dpkg.rb +++ b/lib/puppet/provider/package/dpkg.rb @@ -23,30 +23,39 @@ Puppet::Type.type(:package).provide :dpkg, :parent => Puppet::Provider::Package # now turn each returned line into a package object process.each { |line| - if match = regex.match(line) - hash = {} + if hash = parse_line(line) + packages << new(hash) + end + } + end - fields.zip(match.captures) { |field,value| - hash[field] = value - } + return packages + end - hash[:provider] = self.name + REGEX = %r{^(\S+) +(\S+) +(\S+) (\S+) (\S*)$} + FIELDS = [:desired, :error, :status, :name, :ensure] - if hash[:status] == 'not-installed' - hash[:ensure] = :purged - elsif hash[:status] != "installed" - hash[:ensure] = :absent - end + def self.parse_line(line) + if match = REGEX.match(line) + hash = {} - packages << new(hash) - else - Puppet.warning "Failed to match dpkg-query line %s" % - line.inspect - end + FIELDS.zip(match.captures) { |field,value| + hash[field] = value } + + hash[:provider] = self.name + + if hash[:status] == 'not-installed' + hash[:ensure] = :purged + elsif hash[:status] != "installed" + hash[:ensure] = :absent + end + else + Puppet.warning "Failed to match dpkg-query line %s" % line.inspect + return nil end - return packages + return hash end def install @@ -56,15 +65,10 @@ Puppet::Type.type(:package).provide :dpkg, :parent => Puppet::Provider::Package args = [] - if config = @resource[:configfiles] - case config - when :keep - args << '--force-confold' - when :replace - args << '--force-confnew' - else - raise Puppet::Error, "Invalid 'configfiles' value %s" % config - end + if @resource[:configfiles] == :keep + args << '--force-confold' + else + args << '--force-confnew' end args << '-i' << file @@ -80,7 +84,7 @@ Puppet::Type.type(:package).provide :dpkg, :parent => Puppet::Provider::Package output = dpkg_deb "--show", @resource[:source] matches = /^(\S+)\t(\S+)$/.match(output).captures unless matches[0].match(@resource[:name]) - Puppet.warning "source doesn't contain named package, but %s" % matches[0] + warning "source doesn't contain named package, but %s" % matches[0] end matches[1] end @@ -103,22 +107,8 @@ Puppet::Type.type(:package).provide :dpkg, :parent => Puppet::Provider::Package :name => @resource[:name], :error => 'ok'} end - # Our regex for matching dpkg-query output. We could probably just - # use split here, but I'm not positive that dpkg-query will never - # return whitespace. - regex = %r{^(\S+) (\S+) (\S+) (\S+) (\S*)$} - line = output.split("\n").shift.chomp - - if match = regex.match(line) - fields.zip(match.captures) { |field,value| - hash[field] = value - } - else - notice "Failed to handle dpkg-query line %s" % line.inspect - return {:ensure => :absent, :status => 'missing', - :name => @resource[:name], :error => 'ok'} - end + hash = self.class.parse_line(output) || {:ensure => :absent, :status => 'missing', :name => @resource[:name], :error => 'ok'} if hash[:error] != "ok" raise Puppet::Error.new( @@ -127,13 +117,6 @@ Puppet::Type.type(:package).provide :dpkg, :parent => Puppet::Provider::Package ) end - # DPKG can discuss packages that are no longer installed, so allow that. - if hash[:status] == "not-installed" - hash[:ensure] = :purged - elsif hash[:status] != "installed" - hash[:ensure] = :absent - end - return hash end @@ -145,4 +128,3 @@ Puppet::Type.type(:package).provide :dpkg, :parent => Puppet::Provider::Package dpkg "--purge", @resource[:name] end end - |