[prev in list] [next in list] [prev in thread] [next in thread] 

List:       puppet-commit
Subject:    [Puppet-commit] puppet revision 1982
From:       svn () madstop ! com
Date:       2006-12-29 0:05:03
Message-ID: 20061229000503.C14E2152166 () culain ! madstop ! com
[Download RAW message or body]

luke 2006-12-28 18:05:03 -0600 (Thu, 28 Dec 2006)
A couple of small bug fixes
Modified: trunk/lib/puppet/client/pelement.rb
===================================================================
--- trunk/lib/puppet/client/pelement.rb	2006-12-29 00:01:52 UTC (rev 1981)
+++ trunk/lib/puppet/client/pelement.rb	2006-12-29 00:05:03 UTC (rev 1982)
@@ -28,7 +28,7 @@
     end
 
     def describe(type, name, retrieve = false, ignore = false)
-        Puppet.info "Describing %s[%s]" % [type.capitalize, name]
+        Puppet.info "Describing %s[%s]" % [type.to_s.capitalize, name]
         text = @driver.describe(type, name, retrieve, ignore, "yaml")
 
         object = nil

Added: trunk/lib/puppet/provider/zone/solaris.rb
===================================================================
--- trunk/lib/puppet/provider/zone/solaris.rb	                        (rev 0)
+++ trunk/lib/puppet/provider/zone/solaris.rb	2006-12-29 00:05:03 UTC (rev 1982)
@@ -0,0 +1,208 @@
+Puppet::Type.type(:zone).provide(:solaris) do
+    desc "Provider for Solaris Zones."
+
+    commands :adm => "/usr/sbin/zoneadm", :cfg => "/usr/sbin/zonecfg"
+    defaultfor :operatingsystem => :solaris
+
+    # 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
+        adm(:list, "-cp").split("
").collect do |line|
+            hash = line2hash(line)
+
+            obj = nil
+            unless obj = @model[hash[:name]]
+                obj = @model.create(:name => hash[:name])
+            end
+
+            obj.setstatus(hash)
+
+            obj
+        end
+    end
+
+    # Perform all of our configuration steps.
+    def configure
+        # If the thing is entirely absent, then we need to create the config.
+        str = %{create -b
+set zonepath=%s
+} % @model[:path]
+
+        # Then perform all of our configuration steps.  It's annoying
+        # that we need this much internal info on the model.
+        @model.send(:states).each do |state|
+            if state.is_a? ZoneConfigState and ! state.insync?
+                str += state.configtext + "
"
+            end
+        end
+
+        str += "commit
"
+        setconfig(str)
+    end
+
+    def destroy
+        zonecfg :delete, "-F"
+    end
+
+    def install
+        zoneadm :install
+    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()
+            case hash[:ensure]
+            when "incomplete", "ready", "shutting_down"
+                true
+            else
+                false
+            end
+        else
+            false
+        end
+    end
+
+    # Collect the configuration of the zone.
+    def getconfig
+        output = zonecfg :info
+
+        name = nil
+        current = nil
+        hash = {}
+        output.split("
").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
+        return hash
+    end
+
+    def retrieve
+        if hash = statushash()
+            setstatus(hash)
+
+            # Now retrieve the configuration itself and set appropriately.
+            getconfig()
+        else
+            @states.each do |name, state|
+                state.is = :absent
+            end
+        end
+    end
+
+    # Execute a configuration string.  Can't be private because it's called
+    # by the states.
+    def setconfig(str)
+        command = "#{command(:cfg)} -z %s -f -" % @model[:name]
+        debug "Executing '%s' in zone %s with '%s'" % [command, @model[:name], str]
+        IO.popen(command, "w") do |pipe|
+            pipe.puts str
+        end
+
+        unless $? == 0
+            raise ArgumentError, "Failed to apply configuration"
+        end
+    end
+
+    def start
+        # Check the sysidcfg stuff
+        if cfg = @model[:sysidcfg]
+            path = File.join(@model[: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
+
+        zoneadm :boot
+    end
+
+    # Return a hash of the current status of this zone.
+    def statushash
+        begin
+            output = adm "-z", @model[:name], :list, "-p"
+        rescue Puppet::ExecutionFailure
+            return nil
+        end
+
+        return self.class.line2hash(output.chomp)
+    end
+
+    def stop
+        zoneadm :halt
+    end
+
+    def unconfigure
+        zonecfg :delete, "-F"
+    end
+
+    def uninstall
+        zoneadm :uninstall, "-F"
+    end
+
+    private
+
+    def zoneadm(*cmd)
+        begin
+            adm("-z", @model[:name], *cmd)
+        rescue Puppet::ExecutionFailure => detail
+            self.fail "Could not %s zone: %s" % [cmd[0], detail]
+        end
+    end
+
+    def zonecfg(*cmd)
+        begin
+            cfg("-z", @model[:name], *cmd)
+        rescue Puppet::ExecutionFailure => detail
+            self.fail "Could not %s zone: %s" % [cmd[0], detail]
+        end
+    end
+end
+
+# $Id$


Property changes on: trunk/lib/puppet/provider/zone/solaris.rb
___________________________________________________________________
Name: svn:keywords
   + Author URL Id Date Rev

Modified: trunk/lib/puppet/server/pelement.rb
===================================================================
--- trunk/lib/puppet/server/pelement.rb	2006-12-29 00:01:52 UTC (rev 1981)
+++ trunk/lib/puppet/server/pelement.rb	2006-12-29 00:05:03 UTC (rev 1982)
@@ -52,7 +52,7 @@
     # Describe a given object.  This returns the 'is' values for every state
     # available on the object type.
     def describe(type, name, retrieve = nil, ignore = [], format = "yaml", client = nil, clientip = nil)
-        Puppet.info "Describing %s[%s]" % [type, name]
+        Puppet.info "Describing %s[%s]" % [type.to_s.capitalize, name]
         @local = true unless client
         typeklass = nil
         unless typeklass = Puppet.type(type)

Modified: trunk/lib/puppet/transaction.rb
===================================================================
--- trunk/lib/puppet/transaction.rb	2006-12-29 00:01:52 UTC (rev 1981)
+++ trunk/lib/puppet/transaction.rb	2006-12-29 00:05:03 UTC (rev 1982)
@@ -202,10 +202,11 @@
                 end
             end
             
-            # A bit of hackery here -- if skipcheck is true, then we're the top-level
-            # resource.  If that's the case, then make sure all of the changes list this resource
-            # as a proxy.  This is really only necessary for rollback, since we know the generating
-            # resource during forward changes.
+            # A bit of hackery here -- if skipcheck is true, then we're the
+            # top-level resource.  If that's the case, then make sure all of
+            # the changes list this resource as a proxy.  This is really only
+            # necessary for rollback, since we know the generating resource
+            # during forward changes.
             if children and checkskip
                 @changes[changecount..-1].each { |change| change.proxy = resource }
             end
@@ -219,9 +220,9 @@
             events += triggedevents
         end
 
-        # Collect the targets of any subscriptions to those events.  We pass the parent resource
-        # in so it will override the source in the events, since eval_generated children can't
-        # have direct relationships.
+        # Collect the targets of any subscriptions to those events.  We pass
+        # the parent resource in so it will override the source in the events,
+        # since eval_generated children can't have direct relationships.
         @relgraph.matching_edges(events, resource).each do |edge|
             @targets[edge.target] << edge
         end

Modified: trunk/test/language/snippets.rb
===================================================================
--- trunk/test/language/snippets.rb	2006-12-29 00:01:52 UTC (rev 1981)
+++ trunk/test/language/snippets.rb	2006-12-29 00:05:03 UTC (rev 1982)
@@ -197,7 +197,7 @@
 
         assert_nothing_raised {
             assert_equal(
-                "//testing/component[componentname]/file=/tmp/classtest",
+                "//testing/component[componentname]/File[/tmp/classtest]",
                 obj.path)
             #Puppet.err obj.path
         }

Modified: trunk/test/lib/puppettest/graph.rb
===================================================================
--- trunk/test/lib/puppettest/graph.rb	2006-12-29 00:01:52 UTC (rev 1981)
+++ trunk/test/lib/puppettest/graph.rb	2006-12-29 00:05:03 UTC (rev 1982)
@@ -31,10 +31,11 @@
     def build_tree
         one = Container.new("one", %w{a b})
         two = Container.new("two", ["c", "d"])
+        three = Container.new("three", ["i", "j"])
         middle = Container.new("middle", ["e", "f", two])
-        top = Container.new("top", ["g", "h", middle, one])
-        return one, two, middle, top
+        top = Container.new("top", ["g", "h", middle, one, three])
+        return one, two, three, middle, top
     end
 end
 
-# $Id$
\ No newline at end of file
+# $Id$

Modified: trunk/test/types/mount.rb
===================================================================
--- trunk/test/types/mount.rb	2006-12-29 00:01:52 UTC (rev 1981)
+++ trunk/test/types/mount.rb	2006-12-29 00:05:03 UTC (rev 1982)
@@ -120,6 +120,11 @@
         assert_nothing_raised { mount.retrieve }
 
         assert_equal(:mounted, mount.is(:ensure))
+
+        # Now modify a field
+        mount[:dump] = 2
+
+        assert_events([:mount_changed], mount)
     end
 
     # Make sure fs mounting behaves appropriately.  This is more a test of


[Attachment #3 (text/html)]

<p><b>luke</b> 2006-12-28 18:05:03 -0600 (Thu, 28 Dec 2006)</p><p>A couple of small \
bug fixes<br> </p><hr noshade><pre><font color="gray">Modified: \
trunk/lib/puppet/client/pelement.rb \
                ===================================================================
--- trunk/lib/puppet/client/pelement.rb	2006-12-29 00:01:52 UTC (rev 1981)
+++ trunk/lib/puppet/client/pelement.rb	2006-12-29 00:05:03 UTC (rev 1982)
@@ -28,7 +28,7 @@
     end
 
     def describe(type, name, retrieve = false, ignore = false)
-        Puppet.info &quot;Describing %s[%s]&quot; % [type.capitalize, name]
+        Puppet.info &quot;Describing %s[%s]&quot; % [type.to_s.capitalize, name]
         text = @driver.describe(type, name, retrieve, ignore, &quot;yaml&quot;)
 
         object = nil

Added: trunk/lib/puppet/provider/zone/solaris.rb
===================================================================
--- trunk/lib/puppet/provider/zone/solaris.rb	                        (rev 0)
+++ trunk/lib/puppet/provider/zone/solaris.rb	2006-12-29 00:05:03 UTC (rev 1982)
@@ -0,0 +1,208 @@
+Puppet::Type.type(:zone).provide(:solaris) do
+    desc &quot;Provider for Solaris Zones.&quot;
+
+    commands :adm =&gt; &quot;/usr/sbin/zoneadm&quot;, :cfg =&gt; \
&quot;/usr/sbin/zonecfg&quot; +    defaultfor :operatingsystem =&gt; :solaris
+
+    # Convert the output of a list into a hash
+    def self.line2hash(line)
+        fields = [:id, :name, :ensure, :path]
+
+        hash = {}
+        line.split(&quot;:&quot;).each_with_index { |value, index|
+            hash[fields[index]] = value
+        }
+
+        # Configured but not installed zones do not have IDs
+        if hash[:id] == &quot;-&quot;
+            hash.delete(:id)
+        end
+
+        return hash
+    end
+
+    def self.list
+        adm(:list, &quot;-cp&quot;).split(&quot;</font>
<font color="blue">&quot;).collect do |line|
+            hash = line2hash(line)
+
+            obj = nil
+            unless obj = @model[hash[:name]]
+                obj = @model.create(:name =&gt; hash[:name])
+            end
+
+            obj.setstatus(hash)
+
+            obj
+        end
+    end
+
+    # Perform all of our configuration steps.
+    def configure
+        # If the thing is entirely absent, then we need to create the config.
+        str = %{create -b
+set zonepath=%s
+} % @model[:path]
+
+        # Then perform all of our configuration steps.  It's annoying
+        # that we need this much internal info on the model.
+        @model.send(:states).each do |state|
+            if state.is_a? ZoneConfigState and ! state.insync?
+                str += state.configtext + &quot;</font>
<font color="blue">&quot;
+            end
+        end
+
+        str += &quot;commit</font>
<font color="blue">&quot;
+        setconfig(str)
+    end
+
+    def destroy
+        zonecfg :delete, &quot;-F&quot;
+    end
+
+    def install
+        zoneadm :install
+    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()
+            case hash[:ensure]
+            when &quot;incomplete&quot;, &quot;ready&quot;, \
&quot;shutting_down&quot; +                true
+            else
+                false
+            end
+        else
+            false
+        end
+    end
+
+    # Collect the configuration of the zone.
+    def getconfig
+        output = zonecfg :info
+
+        name = nil
+        current = nil
+        hash = {}
+        output.split(&quot;</font>
<font color="gray">&quot;).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] &lt;&lt; current
+                    end
+                    current[$1.intern] = $2
+                else
+                    err &quot;Ignoring '%s'&quot; % line
+                end
+            else
+                debug &quot;Ignoring zone output '%s'&quot; % line
+            end
+        end
+        return hash
+    end
+
+    def retrieve
+        if hash = statushash()
+            setstatus(hash)
+
+            # Now retrieve the configuration itself and set appropriately.
+            getconfig()
+        else
+            @states.each do |name, state|
+                state.is = :absent
+            end
+        end
+    end
+
+    # Execute a configuration string.  Can't be private because it's called
+    # by the states.
+    def setconfig(str)
+        command = &quot;#{command(:cfg)} -z %s -f -&quot; % @model[:name]
+        debug &quot;Executing '%s' in zone %s with '%s'&quot; % [command, \
@model[:name], str] +        IO.popen(command, &quot;w&quot;) do |pipe|
+            pipe.puts str
+        end
+
+        unless $? == 0
+            raise ArgumentError, &quot;Failed to apply configuration&quot;
+        end
+    end
+
+    def start
+        # Check the sysidcfg stuff
+        if cfg = @model[:sysidcfg]
+            path = File.join(@model[:path], &quot;root&quot;, &quot;etc&quot;, \
&quot;sysidcfg&quot;) +
+            unless File.exists?(path)
+                begin
+                    File.open(path, &quot;w&quot;, 0600) do |f|
+                        f.puts cfg
+                    end
+                rescue =&gt; detail
+                    if Puppet[:debug]
+                        puts detail.stacktrace
+                    end
+                    raise Puppet::Error, &quot;Could not create sysidcfg: %s&quot; % \
detail +                end
+            end
+        end
+
+        zoneadm :boot
+    end
+
+    # Return a hash of the current status of this zone.
+    def statushash
+        begin
+            output = adm &quot;-z&quot;, @model[:name], :list, &quot;-p&quot;
+        rescue Puppet::ExecutionFailure
+            return nil
+        end
+
+        return self.class.line2hash(output.chomp)
+    end
+
+    def stop
+        zoneadm :halt
+    end
+
+    def unconfigure
+        zonecfg :delete, &quot;-F&quot;
+    end
+
+    def uninstall
+        zoneadm :uninstall, &quot;-F&quot;
+    end
+
+    private
+
+    def zoneadm(*cmd)
+        begin
+            adm(&quot;-z&quot;, @model[:name], *cmd)
+        rescue Puppet::ExecutionFailure =&gt; detail
+            self.fail &quot;Could not %s zone: %s&quot; % [cmd[0], detail]
+        end
+    end
+
+    def zonecfg(*cmd)
+        begin
+            cfg(&quot;-z&quot;, @model[:name], *cmd)
+        rescue Puppet::ExecutionFailure =&gt; detail
+            self.fail &quot;Could not %s zone: %s&quot; % [cmd[0], detail]
+        end
+    end
+end
+
+# $Id$


Property changes on: trunk/lib/puppet/provider/zone/solaris.rb
___________________________________________________________________
Name: svn:keywords
   + Author URL Id Date Rev

Modified: trunk/lib/puppet/server/pelement.rb
===================================================================
--- trunk/lib/puppet/server/pelement.rb	2006-12-29 00:01:52 UTC (rev 1981)
+++ trunk/lib/puppet/server/pelement.rb	2006-12-29 00:05:03 UTC (rev 1982)
@@ -52,7 +52,7 @@
     # Describe a given object.  This returns the 'is' values for every state
     # available on the object type.
     def describe(type, name, retrieve = nil, ignore = [], format = &quot;yaml&quot;, \
                client = nil, clientip = nil)
-        Puppet.info &quot;Describing %s[%s]&quot; % [type, name]
+        Puppet.info &quot;Describing %s[%s]&quot; % [type.to_s.capitalize, name]
         @local = true unless client
         typeklass = nil
         unless typeklass = Puppet.type(type)

Modified: trunk/lib/puppet/transaction.rb
===================================================================
--- trunk/lib/puppet/transaction.rb	2006-12-29 00:01:52 UTC (rev 1981)
+++ trunk/lib/puppet/transaction.rb	2006-12-29 00:05:03 UTC (rev 1982)
@@ -202,10 +202,11 @@
                 end
             end
             
-            # A bit of hackery here -- if skipcheck is true, then we're the \
                top-level
-            # resource.  If that's the case, then make sure all of the changes list \
                this resource
-            # as a proxy.  This is really only necessary for rollback, since we know \
                the generating
-            # resource during forward changes.
+            # A bit of hackery here -- if skipcheck is true, then we're the
+            # top-level resource.  If that's the case, then make sure all of
+            # the changes list this resource as a proxy.  This is really only
+            # necessary for rollback, since we know the generating resource
+            # during forward changes.
             if children and checkskip
                 @changes[changecount..-1].each { |change| change.proxy = resource }
             end
@@ -219,9 +220,9 @@
             events += triggedevents
         end
 
-        # Collect the targets of any subscriptions to those events.  We pass the \
                parent resource
-        # in so it will override the source in the events, since eval_generated \
                children can't
-        # have direct relationships.
+        # Collect the targets of any subscriptions to those events.  We pass
+        # the parent resource in so it will override the source in the events,
+        # since eval_generated children can't have direct relationships.
         @relgraph.matching_edges(events, resource).each do |edge|
             @targets[edge.target] &lt;&lt; edge
         end

Modified: trunk/test/language/snippets.rb
===================================================================
--- trunk/test/language/snippets.rb	2006-12-29 00:01:52 UTC (rev 1981)
+++ trunk/test/language/snippets.rb	2006-12-29 00:05:03 UTC (rev 1982)
@@ -197,7 +197,7 @@
 
         assert_nothing_raised {
             assert_equal(
-                &quot;//testing/component[componentname]/file=/tmp/classtest&quot;,
+                &quot;//testing/component[componentname]/File[/tmp/classtest]&quot;,
                 obj.path)
             #Puppet.err obj.path
         }

Modified: trunk/test/lib/puppettest/graph.rb
===================================================================
--- trunk/test/lib/puppettest/graph.rb	2006-12-29 00:01:52 UTC (rev 1981)
+++ trunk/test/lib/puppettest/graph.rb	2006-12-29 00:05:03 UTC (rev 1982)
@@ -31,10 +31,11 @@
     def build_tree
         one = Container.new(&quot;one&quot;, %w{a b})
         two = Container.new(&quot;two&quot;, [&quot;c&quot;, &quot;d&quot;])
+        three = Container.new(&quot;three&quot;, [&quot;i&quot;, &quot;j&quot;])
         middle = Container.new(&quot;middle&quot;, [&quot;e&quot;, &quot;f&quot;, \
                two])
-        top = Container.new(&quot;top&quot;, [&quot;g&quot;, &quot;h&quot;, middle, \
                one])
-        return one, two, middle, top
+        top = Container.new(&quot;top&quot;, [&quot;g&quot;, &quot;h&quot;, middle, \
one, three]) +        return one, two, three, middle, top
     end
 end
 
-# $Id$
\ No newline at end of file
+# $Id$

Modified: trunk/test/types/mount.rb
===================================================================
--- trunk/test/types/mount.rb	2006-12-29 00:01:52 UTC (rev 1981)
+++ trunk/test/types/mount.rb	2006-12-29 00:05:03 UTC (rev 1982)
@@ -120,6 +120,11 @@
         assert_nothing_raised { mount.retrieve }
 
         assert_equal(:mounted, mount.is(:ensure))
+
+        # Now modify a field
+        mount[:dump] = 2
+
+        assert_events([:mount_changed], mount)
     end
 
     # Make sure fs mounting behaves appropriately.  This is more a test of

</font>
</pre>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic