diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-28 19:14:11 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-28 19:14:11 +0000 |
| commit | d07570b78d6c6cc670b4e6c770fb409b64c5b24d (patch) | |
| tree | 117df623fb2bb01a0fdcdc2e77355ec9b90bb66f | |
| parent | 652982257d7d4b1fdfada25880d70b29702a4c69 (diff) | |
| download | puppet-d07570b78d6c6cc670b4e6c770fb409b64c5b24d.tar.gz puppet-d07570b78d6c6cc670b4e6c770fb409b64c5b24d.tar.xz puppet-d07570b78d6c6cc670b4e6c770fb409b64c5b24d.zip | |
Looks like providers work again on Solaris.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1980 980ebf18-57e1-0310-9a29-db15c13687c0
| -rwxr-xr-x | lib/puppet/provider/package/blastwave.rb | 6 | ||||
| -rwxr-xr-x | lib/puppet/provider/package/sun.rb | 1 | ||||
| -rw-r--r-- | lib/puppet/type/zone.rb | 179 | ||||
| -rw-r--r-- | lib/puppet/util.rb | 5 | ||||
| -rwxr-xr-x | test/lib/puppettest.rb | 2 | ||||
| -rwxr-xr-x | test/providers/package.rb | 5 | ||||
| -rwxr-xr-x | test/types/zone.rb | 17 |
7 files changed, 27 insertions, 188 deletions
diff --git a/lib/puppet/provider/package/blastwave.rb b/lib/puppet/provider/package/blastwave.rb index 61c5bc1da..e8a925b2c 100755 --- a/lib/puppet/provider/package/blastwave.rb +++ b/lib/puppet/provider/package/blastwave.rb @@ -24,7 +24,7 @@ Puppet::Type.type(:package).provide :blastwave, :parent => :sun do end def self.list(hash = {}) - blastlist(hash).each do |bhash| + blastlist(hash).collect do |bhash| bhash.delete(:avail) Puppet::Type.type(:package).installedpkg(bhash) end @@ -74,7 +74,9 @@ Puppet::Type.type(:package).provide :blastwave, :parent => :sun do if hash[:avail] == "SAME" hash[:avail] = hash[:ensure] end - hash[:provider] = :blastwave + + # Use the name method, so it works with subclasses. + hash[:provider] = self.name return hash else diff --git a/lib/puppet/provider/package/sun.rb b/lib/puppet/provider/package/sun.rb index 5263c5821..c9a71e200 100755 --- a/lib/puppet/provider/package/sun.rb +++ b/lib/puppet/provider/package/sun.rb @@ -130,7 +130,6 @@ Puppet::Type.type(:package).provide :sun do cmd << "-d" << @model[:source] cmd << "-n" << @model[:name] - cmd = cmd pkgadd cmd end diff --git a/lib/puppet/type/zone.rb b/lib/puppet/type/zone.rb index 7576d173f..30051d52e 100644 --- a/lib/puppet/type/zone.rb +++ b/lib/puppet/type/zone.rb @@ -7,7 +7,7 @@ Puppet::Type.newtype(:zone) do class ZoneConfigState < Puppet::State # Perform the config operation. def sync - @parent.cfg self.configtext + provider.setconfig self.configtext end end @@ -151,7 +151,7 @@ Puppet::Type.newtype(:zone) do end sleep 1 end - @parent.send(method) + provider.send(method) else raise Puppet::DevError, "Cannot move %s from %s" % [dir, st[:name]] @@ -354,51 +354,6 @@ end end end - # Convert the output of a list into a hash - def self.line2hash(line) - fields = [:id, :name, :ensure, :path] - - hash = {} - line.split(":").each_with_index { |value, index| - hash[fields[index]] = value - } - - # Configured but not installed zones do not have IDs - if hash[:id] == "-" - hash.delete(:id) - end - - return hash - end - - def self.list - %x{/usr/sbin/zoneadm list -cp}.split("\n").collect do |line| - hash = line2hash(line) - - obj = nil - unless obj = @objects[hash[:name]] - obj = create(:name => hash[:name]) - end - - obj.setstatus(hash) - - obj - end - end - - # Execute a configuration string. Can't be private because it's called - # by the states. - def cfg(str) - debug "Executing '%s' in zone %s" % [str, self[:name]] - IO.popen("/usr/sbin/zonecfg -z %s -f - 2>&1" % self[:name], "w") do |pipe| - pipe.puts str - end - - unless $? == 0 - raise ArgumentError, "Failed to apply configuration" - end - end - # Perform all of our configuration steps. def configure # If the thing is entirely absent, then we need to create the config. @@ -414,29 +369,13 @@ set zonepath=%s end str += "commit\n" - cfg(str) - end - - def destroy - begin - execute(["/usr/sbin/zonecfg", "-z", self[:name], :delete, "-F"]) - rescue Puppet::ExecutionFailure => detail - self.fail "Could not destroy zone: %s" % detail - end - end - - def install - begin - execute(["/usr/sbin/zoneadm", "-z", self[:name], :install]) - rescue Puppet::ExecutionFailure => detail - self.fail "Could not install zone: %s" % detail - end + provider.setconfig(str) end # We need a way to test whether a zone is in process. Our 'ensure' # state models the static states, but we need to handle the temporary ones. def processing? - if hash = statushash() + if hash = provider.statushash() case hash[:ensure] when "incomplete", "ready", "shutting_down" true @@ -449,11 +388,11 @@ set zonepath=%s end def retrieve - if hash = statushash() + if hash = provider.statushash() setstatus(hash) # Now retrieve the configuration itself and set appropriately. - getconfig() + config2status(provider.getconfig()) else @states.each do |name, state| state.is = :absent @@ -472,69 +411,9 @@ set zonepath=%s self[param] = value end end - - # For any configured items that are not found, mark absent. - @states.each do |name, st| - next unless st.is_a? ZoneConfigState - - unless hash.has_key? st.name - st.is = :absent - end - end - end - - def start - # Check the sysidcfg stuff - if cfg = self[:sysidcfg] - path = File.join(self[:path], "root", "etc", "sysidcfg") - - unless File.exists?(path) - begin - File.open(path, "w", 0600) do |f| - f.puts cfg - end - rescue => detail - if Puppet[:debug] - puts detail.stacktrace - end - raise Puppet::Error, "Could not create sysidcfg: %s" % detail - end - end - end - - begin - execute("/usr/sbin/zoneadm -z #{self[:name]} boot") - rescue Puppet::ExecutionFailure => detail - self.fail "Could not start zone: %s" % detail - end - end - - def stop - begin - execute("/usr/sbin/zoneadm -z #{self[:name]} halt") - rescue Puppet::ExecutionFailure => detail - self.fail "Could not halt zone: %s" % detail - end - end - - def unconfigure - begin - execute("/usr/sbin/zonecfg -z #{self[:name]} delete -F") - rescue Puppet::ExecutionFailure => detail - self.fail "Could not unconfigure zone: %s" % detail - end - end - - def uninstall - begin - execute("/usr/sbin/zoneadm -z #{self[:name]} uninstall -F") - rescue Puppet::ExecutionFailure => detail - self.fail "Could not halt zone: %s" % detail - end end private - # Turn the results of getconfig into status information. def config2status(config) config.each do |name, value| @@ -561,52 +440,6 @@ set zonepath=%s end end end - - # Collect the configuration of the zone. - def getconfig - output = execute("/usr/sbin/zonecfg -z %s info" % self[:name]) - - name = nil - current = nil - hash = {} - output.split("\n").each do |line| - case line - when /^(\S+):\s*$/: - name = $1 - current = nil # reset it - when /^(\S+):\s*(.+)$/: - hash[$1.intern] = $2 - #self.is = [$1.intern, $2] - when /^\s+(\S+):\s*(.+)$/: - if name - unless hash.include? name - hash[name] = [] - end - - unless current - current = {} - hash[name] << current - end - current[$1.intern] = $2 - else - err "Ignoring '%s'" % line - end - else - debug "Ignoring zone output '%s'" % line - end - end - config2status(hash) - end - - def statushash - begin - output = execute("/usr/sbin/zoneadm -z #{self[:name]} list -p 2>/dev/null") - rescue Puppet::ExecutionFailure => detail - return nil - end - - return self.class.line2hash(output.chomp) - end end # $Id$ diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb index ef9f390f1..9e40251e2 100644 --- a/lib/puppet/util.rb +++ b/lib/puppet/util.rb @@ -269,7 +269,7 @@ module Util # Execute the desired command, and return the status and output. def execute(command, failonfail = true, uid = nil, gid = nil) if command.is_a?(Array) - command = command.collect { |i| i.to_s } + command = command.flatten.collect { |i| i.to_s } str = command.join(" ") else # We require an array here so we know where we're incorrectly @@ -278,9 +278,6 @@ module Util raise ArgumentError, "Must pass an array to execute()" end - if command[0].is_a?(Array) - raise ArgumentError, "Will not flatten arrays" - end if respond_to? :debug debug "Executing '%s'" % str else diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb index 385dff901..2e1bde685 100755 --- a/test/lib/puppettest.rb +++ b/test/lib/puppettest.rb @@ -169,8 +169,6 @@ module PuppetTest end def teardown - stopservices - @@cleaners.each { |cleaner| cleaner.call() } @@tmpfiles.each { |file| diff --git a/test/providers/package.rb b/test/providers/package.rb index 7511fde30..6bfd7ee52 100755 --- a/test/providers/package.rb +++ b/test/providers/package.rb @@ -242,7 +242,10 @@ class TestPackageProvider < Test::Unit::TestCase result = provider.list end result.each do |pkg| - assert_instance_of(Puppet::Type.type(:package), pkg) + assert_instance_of(Puppet::Type.type(:package), pkg, + "%s returned non-package" % provider.name) + assert_equal(provider.name, pkg.provider.class.name, + "%s did not set provider correctly" % provider.name) end end end diff --git a/test/types/zone.rb b/test/types/zone.rb index dfdcc90a4..e0df6d28a 100755 --- a/test/types/zone.rb +++ b/test/types/zone.rb @@ -142,8 +142,11 @@ class TestZone < Test::Unit::TestCase } methods.each do |m| - assert(Puppet::Type.type(:zone).method_defined?(m), - "Zones do not define method %s" % m) + Puppet::Type.type(:zone).suitableprovider.each do |prov| + assert(prov.method_defined?(m), + "Zone provider %s does not define method %s" % + [prov.name, m]) + end end end @@ -245,11 +248,15 @@ end #@@zones << "configtesting" + hash = nil assert_nothing_raised { - zone.send(:getconfig) + hash = zone.provider.send(:getconfig) } - # Now, make sure everything is right. + # Now set the configuration + assert_nothing_raised { zone.send(:config2status, hash) } + + # And make sure it gets set correctly. assert_equal(%w{/sbin /usr /opt/csw /lib /platform}.sort, zone.is(:inherit).sort, "Inherited dirs did not get collected correctly." ) @@ -385,7 +392,7 @@ end zone.retrieve } assert_nothing_raised { - zone.send(method) + zone.provider.send(method) } assert_nothing_raised { zone.retrieve |
