Signed-off-by: Martin Englund <[email protected]>
---
lib/puppet/type/zone.rb | 47 ++++++++++++++++++++++++++++++++---------------
spec/unit/type/zone.rb | 40 +++++++++++++++++++++++++++++++++++++---
2 files changed, 69 insertions(+), 18 deletions(-)
diff --git a/lib/puppet/type/zone.rb b/lib/puppet/type/zone.rb
index b8a7e9a..be23912 100644
--- a/lib/puppet/type/zone.rb
+++ b/lib/puppet/type/zone.rb
@@ -205,21 +205,6 @@ 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)
@@ -246,6 +231,19 @@ 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
+
newproperty(:autoboot, :parent => ZoneConfigProperty) do
desc "Whether the zone should automatically boot."
@@ -380,6 +378,25 @@ end
end
end
+ validate do
+ value = self[:ip]
+ if self[:iptype] == :exclusive
+ self.fail "ip must only contain interface name" if value =~ /:/
+ elsif value
+ self.fail "ip must contain interface name and ip address separated
by a \":\"" unless value =~ /:/
+ interface, address = value.split(':')
+ begin
+ IPAddr.new(address)
+ rescue ArgumentError
+ self.fail "'%s' is an invalid IP address" % address
+ end
+ end
+
+ unless self[:path]
+ self.fail "zone path is required"
+ end
+ end
+
def retrieve
provider.flush
if hash = provider.properties() and hash[:ensure] != :absent
diff --git a/spec/unit/type/zone.rb b/spec/unit/type/zone.rb
index c993026..6744b09 100755
--- a/spec/unit/type/zone.rb
+++ b/spec/unit/type/zone.rb
@@ -6,15 +6,49 @@ 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 valid when :iptype is :shared" do
+ zone.new(:name => "dummy", :path => "/dummy", :ip => "if:1.2.3.4")
+ end
+
+ it "should be valid when :iptype is :exclusive" do
+ zone.new(:name => "dummy", :path => "/dummy", :ip => "if",
+ :iptype => :exclusive)
+ end
+
end
--
1.6.4.4
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en.