From 0a2a58c8650e8956a4ae464d364310ced244303b Mon Sep 17 00:00:00 2001 From: Derek Olsen Date: Thu, 13 Jan 2011 14:07:00 -0800 Subject: (#5479) Autorequire zfs filesystem when zone dataset is configured A zone dataset is just a zfs filesystem in the global zone. This zfs filesystem needs to exist before it can be given to a zone as a dataset. It seemed to make sense to autorequire the zfs filesystem. This patch just autorequires the zfs filesystem which will be the dataset and let's the zfs type manage autorequiring the parent zfs filesystems and zpool. Reviewed-By: Daniel Pittman Reviewed-By: Matt Robinson --- lib/puppet/type/zone.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/puppet/type/zone.rb b/lib/puppet/type/zone.rb index fc524a541..c7c2aa143 100644 --- a/lib/puppet/type/zone.rb +++ b/lib/puppet/type/zone.rb @@ -413,6 +413,23 @@ Puppet::Type.newtype(:zone) do end end + # If Puppet is also managing the zfs filesystem which is the zone dataset + # then list it as a prerequisite. Zpool's get autorequired by the zfs + # type. We just need to autorequire the dataset zfs itself as the zfs type + # will autorequire all of the zfs parents and zpool. + autorequire(:zfs) do + + # Check if we have datasets in our zone configuration + if @parameters.include? :dataset + reqs = [] + # Autorequire each dataset + self[:dataset].each { |value| + reqs << value + } + reqs + end + end + def validate_ip(ip, name) IPAddr.new(ip) if ip rescue ArgumentError -- cgit From 1a55c7a4c225dc022fa640bf46f7bc940013151d Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Thu, 10 Mar 2011 16:08:26 -0800 Subject: (#5479) Test that we auto-require the zone dataset. This adds a test at the catalog level to ensure that we generate the right graph relationships; this indirectly tests that the underlying code does the right thing, but importantly also makes us fairly immune to low level changes. Reviewed-By: Daniel Pittman Reviewed-By: Matt Robinson --- spec/unit/type/zone_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spec/unit/type/zone_spec.rb b/spec/unit/type/zone_spec.rb index 726ccc28d..a3e748bde 100755 --- a/spec/unit/type/zone_spec.rb +++ b/spec/unit/type/zone_spec.rb @@ -57,4 +57,24 @@ describe zone do zone.new(:name => "dummy", :path => "/dummy", :ip => "if", :iptype => :exclusive) end + it "should auto-require :dataset entries" do + fs = 'random-pool/some-zfs' + + # ick + provider = stub 'zfs::provider' + provider.stubs(:name).returns(:solaris) + Puppet::Type.type(:zfs).stubs(:defaultprovider).returns(provider) + + catalog = Puppet::Resource::Catalog.new + zfs_instance = Puppet::Type.type(:zfs).new(:name => fs) + catalog.add_resource zfs_instance + + zone_instance = zone.new(:name => "dummy", + :path => "/foo", + :ip => 'en1:1.0.0.0', + :dataset => fs) + catalog.add_resource zone_instance + + catalog.relationship_graph.dependencies(zone_instance).should == [zfs_instance] + end end -- cgit