[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

test branch puppet-dev at googlegroups.com
Wed Jul 14 10:32:52 UTC 2010


The following commit has been merged in the upstream branch:
commit a166d50c3c555a38ae13c1658b9afaefd583cfc9
Author: Rein Henrichs <rein at puppetlabs.com>
Date:   Tue Apr 13 16:47:16 2010 -0700

    Fix for #3399 zone type should handle exclusive IP stacks
    
    * corrected missing status
    * added cloning and support for default router
    * RH: Fix spec to return accurate value for @resource[:clone]
    * RH: Add spec for untested install case when @resource[:clone] returns
      a (non-falsy) value
    
    Signed-off-by: Rein Henrichs <rein at puppetlabs.com>

diff --git a/lib/puppet/provider/zone/solaris.rb b/lib/puppet/provider/zone/solaris.rb
index b047f69..1aaa70d 100644
--- a/lib/puppet/provider/zone/solaris.rb
+++ b/lib/puppet/provider/zone/solaris.rb
@@ -65,7 +65,9 @@ Puppet::Type.type(:zone).provide(:solaris) do
     end
 
     def install(dummy_argument=:work_arround_for_ruby_GC_bug)
-        if @resource[:install_args]
+        if @resource[:clone] # TODO: add support for "-s snapshot"
+            zoneadm :clone, @resource[:clone]
+        elsif @resource[:install_args]
             zoneadm :install, @resource[:install_args].split(" ")
         else
             zoneadm :install
@@ -227,8 +229,17 @@ Puppet::Type.type(:zone).provide(:solaris) do
         if dir = config["inherit-pkg-dir"]
             result[:inherit] = dir.collect { |dirs| dirs[:dir] }
         end
+        result[:iptype] = config[:"ip-type"]
         if net = config["net"]
-            result[:ip] = net.collect { |params| "%s:%s" % [params[:physical], params[:address]] }
+            result[:ip] = net.collect do |params|
+                if params[:defrouter]
+                    "%s:%s:%s" % [params[:physical], params[:address], params[:defrouter]]
+                elsif params[:address]
+                    "%s:%s" % [params[:physical], params[:address]]
+                else
+                    params[:physical]
+                end
+            end
         end
 
         result
diff --git a/lib/puppet/type/zone.rb b/lib/puppet/type/zone.rb
index b8a7e9a..70dd3e0 100644
--- a/lib/puppet/type/zone.rb
+++ b/lib/puppet/type/zone.rb
@@ -173,7 +173,7 @@ Puppet::Type.newtype(:zone) do
                     provider.send(method)
                 else
                     raise Puppet::DevError, "Cannot move %s from %s" %
-                        [direction, st[:name]]
+                    [direction, st[:name]]
                 end
             end
 
@@ -198,6 +198,13 @@ Puppet::Type.newtype(:zone) do
             and cannot be changed."
     end
 
+    newparam(:clone) do
+        desc "Instead of installing the zone, clone it from another zone.
+          If the zone root resides on a zfs file system, a snapshot will be
+          used to create the clone, is it redisides on ufs, a copy of the zone
+          will be used. The zone you clone from must not be running."
+    end
+
     newproperty(:ip, :parent => ZoneMultiConfigProperty) do
         require 'ipaddr'
 
@@ -205,44 +212,49 @@ Puppet::Type.newtype(:zone) do
             with the interface, separated by a colon, e.g.: bge0:192.168.0.1.
             For multiple interfaces, specify them in an array."
 
-        validate do |value|
-            unless value =~ /:/
-                raise ArgumentError,
-                    "IP addresses must specify the interface and the address, separated by a colon."
-            end
-
-            interface, address = value.split(':')
-
-            begin
-                IPAddr.new(address)
-            rescue ArgumentError
-                raise ArgumentError, "'%s' is an invalid IP address" % address
-            end
-        end
-
         # Add an interface.
         def add(str)
-            interface, ip = ipsplit(str)
-            "add net
-set address=#{ip}
-set physical=#{interface}
-end
-"
+            interface, ip, defrouter = ipsplit(str)
+            cmd = "add net\n"
+            cmd += "set physical=#{interface}\n" if interface
+            cmd += "set address=#{ip}\n" if ip
+            cmd += "set defrouter=#{defrouter}\n" if defrouter
+            #if @resource[:iptype] == :shared
+            cmd += "end\n"
         end
 
-        # Convert a string into the component interface and address
+        # Convert a string into the component interface, address and defrouter
         def ipsplit(str)
-            interface, address = str.split(':')
-            return interface, address
+            interface, address, defrouter = str.split(':')
+            return interface, address, defrouter
         end
 
         # Remove an interface.
         def rm(str)
-            interface, ip = ipsplit(str)
+            interface, ip, defrouter = ipsplit(str)
             # Reality seems to disagree with the documentation here; the docs
             # specify that braces are required, but they're apparently only
             # required if you're specifying multiple values.
-            "remove net address=#{ip}"
+            if ip
+                "remove net address=#{ip}"
+            elsif interface
+                "remove net interface=#{interface}"
+            else
+                raise ArgumentError, "can not remove network based on default router"
+            end
+        end
+    end
+
+    newproperty(:iptype, :parent => ZoneConfigProperty) do
+        desc "The IP stack type of the zone. Can either be 'shared' or 'exclusive'."
+
+        defaultto :shared
+
+        newvalue :shared
+        newvalue :exclusive
+
+        def configtext
+            "set ip-type=#{self.should}"
         end
     end
 
@@ -380,6 +392,34 @@ end
         end
     end
 
+    def validate_ip(ip, name)
+        begin
+            IPAddr.new(ip) if ip
+        rescue ArgumentError
+            self.fail "'%s' is an invalid %s" % [ip, name]
+        end
+    end
+
+    validate do
+        value = self[:ip]
+        interface, address, defrouter = value.split(':')
+        if self[:iptype] == :shared
+            if (interface && address && defrouter.nil?) ||
+               (interface && address && defrouter)
+               validate_ip(address, "IP address")
+               validate_ip(defrouter, "default router")
+            else
+                self.fail "ip must contain interface name and ip address separated by a \":\""
+            end
+        else
+            unless interface && address.nil? && defrouter.nil?
+                self.fail "only interface may be specified when using exclusive IP stack: %s" % value
+            end
+        end
+
+        self.fail "zone path is required" unless self[:path]
+    end
+
     def retrieve
         provider.flush
         if hash = provider.properties() and hash[:ensure] != :absent
@@ -412,4 +452,3 @@ end
         return prophash
     end
 end
-
diff --git a/spec/unit/provider/zone/solaris.rb b/spec/unit/provider/zone/solaris.rb
index 4f061fe..0459e5e 100755
--- a/spec/unit/provider/zone/solaris.rb
+++ b/spec/unit/provider/zone/solaris.rb
@@ -26,16 +26,29 @@ describe provider_class do
             @provider.install
         end
 
-        it "should just install if there are no install args" do
-            @resource.stubs(:[]).with(:install_args).returns(nil)
-            @provider.expects(:zoneadm).with(:install)
-            @provider.install
+        describe "when cloning" do
+            before { @resource.stubs(:[]).with(:clone).returns(:clone_argument) }
+
+            it "sohuld clone with the resource's clone attribute" do
+                @provider.expects(:zoneadm).with(:clone, :clone_argument)
+                @provider.install
+            end
         end
 
-        it "should add the install args to the command if they exist" do
-            @resource.stubs(:[]).with(:install_args).returns("install args")
-            @provider.expects(:zoneadm).with(:install, ["install", "args"])
-            @provider.install
+        describe "when not cloning" do
+            before { @resource.stubs(:[]).with(:clone).returns(nil)}
+
+            it "should just install if there are no install args" do
+                @resource.stubs(:[]).with(:install_args).returns(nil)
+                @provider.expects(:zoneadm).with(:install)
+                @provider.install
+            end
+
+            it "should add the install args to the command if they exist" do
+                @resource.stubs(:[]).with(:install_args).returns("install args")
+                @provider.expects(:zoneadm).with(:install, ["install", "args"])
+                @provider.install
+            end
         end
     end
 
diff --git a/spec/unit/type/zone.rb b/spec/unit/type/zone.rb
index c993026..679141e 100755
--- a/spec/unit/type/zone.rb
+++ b/spec/unit/type/zone.rb
@@ -6,15 +6,58 @@ zone = Puppet::Type.type(:zone)
 
 describe zone do
     before do
-        @provider = stub 'provider'
-        @resource = stub 'resource', :resource => nil, :provider => @provider, :line => nil, :file => nil
+	zone = Puppet::Type.type(:zone)
+        provider = stub 'provider'
+	provider.stubs(:name).returns(:solaris)
+	zone.stubs(:defaultprovider).returns(provider)
+        resource = stub 'resource', :resource => nil, :provider => provider, :line => nil, :file => nil
     end
 
-    parameters = [:create_args, :install_args]
+    parameters = [:create_args, :install_args, :sysidcfg, :path, :realhostname]
 
     parameters.each do |parameter|
         it "should have a %s parameter" % parameter do
             zone.attrclass(parameter).ancestors.should be_include(Puppet::Parameter)
         end
     end
+
+    properties = [:ip, :iptype, :autoboot, :pool, :shares, :inherit]
+
+    properties.each do |property|
+        it "should have a %s property" % property do
+            zone.attrclass(property).ancestors.should be_include(Puppet::Property)
+        end
+    end
+
+    it "should be invalid when :path is missing" do
+        lambda { zone.new(:name => "dummy") }.should raise_error
+    end
+
+    it "should be invalid when :ip is missing a \":\" and iptype is :shared" do
+        lambda { zone.new(:name => "dummy", :ip => "if") }.should raise_error
+    end
+
+    it "should be invalid when :ip has a \":\" and iptype is :exclusive" do
+        lambda { zone.new(:name => "dummy", :ip => "if:1.2.3.4",
+	    :iptype => :exclusive) }.should raise_error
+    end
+
+    it "should be invalid when :ip has two \":\" and iptype is :exclusive" do
+        lambda { zone.new(:name => "dummy", :ip => "if:1.2.3.4:2.3.4.5",
+	    :iptype => :exclusive) }.should raise_error
+    end
+
+    it "should be valid when :iptype is :shared and using interface and ip" do
+        zone.new(:name => "dummy", :path => "/dummy", :ip => "if:1.2.3.4")
+    end
+
+    it "should be valid when :iptype is :shared and using interface, ip and default route" do
+        zone.new(:name => "dummy", :path => "/dummy", :ip => "if:1.2.3.4:2.3.4.5")
+    end
+
+    it "should be valid when :iptype is :exclusive and using interface" do
+        zone.new(:name => "dummy", :path => "/dummy", :ip => "if",
+	    :iptype => :exclusive)
+    end
+
 end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list