From c373b6272ddd4daabf15d1b459ef3e86072e3f26 Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Sat, 12 Feb 2011 16:58:20 +0100 Subject: Fix #6269 - Hashes only work with two levels of access The following manifest was failing: $hash = { 'a' => { 'b' => { 'c' => 'it works' } } } $out = $hash['a']['b']['c'] because of a typo in the grammar. Signed-off-by: Brice Figureau --- spec/integration/parser/parser_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'spec/integration') diff --git a/spec/integration/parser/parser_spec.rb b/spec/integration/parser/parser_spec.rb index 7b85bcacb..20d87c228 100755 --- a/spec/integration/parser/parser_spec.rb +++ b/spec/integration/parser/parser_spec.rb @@ -109,5 +109,12 @@ describe Puppet::Parser::Parser do it "should correctly set the arrow type of a relationship" do "Notify[foo] <~ Notify[bar]".should parse_with { |rel| rel.arrow == "<~" } end + + it "should be able to parse deep hash access" do + %q{ + $hash = { 'a' => { 'b' => { 'c' => 'it works' } } } + $out = $hash['a']['b']['c'] + }.should parse_with { |v| v.value.is_a?(Puppet::Parser::AST::ASTHash) } + end end end -- cgit From e3c59df2b246fe5e764272f21b631a5d2f28687f Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Thu, 17 Feb 2011 13:52:40 -0800 Subject: (#5935) Allow functions to accept negated values function(-1) was failing because the grammar wasn't allowing negated values in function calls. This fix makes the negation of any value which was previously legal as a function argument also now legal as a function argument. Paired-With: Max Martin Paired-With: Markus Roberts --- spec/integration/parser/parser_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'spec/integration') diff --git a/spec/integration/parser/parser_spec.rb b/spec/integration/parser/parser_spec.rb index 20d87c228..000e68dd8 100755 --- a/spec/integration/parser/parser_spec.rb +++ b/spec/integration/parser/parser_spec.rb @@ -116,5 +116,18 @@ describe Puppet::Parser::Parser do $out = $hash['a']['b']['c'] }.should parse_with { |v| v.value.is_a?(Puppet::Parser::AST::ASTHash) } end + + it "should be able to pass numbers to functions" do + %q{ + my_function(1) + }.should parse_as(Puppet::Parser::AST::Function) + end + + it "should be able to pass negative numbers to functions" do + %q{ + my_function(-1) + }.should parse_as(Puppet::Parser::AST::Function) + end + end end -- cgit From 2ecf91367c911a87dc5680108222dcc48ecca888 Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Mon, 21 Feb 2011 09:39:19 -0800 Subject: Revert "(#5935) Allow functions to accept negated values" This reverts commit e3c59df2b246fe5e764272f21b631a5d2f28687f. This commit is being reverted because the solution is incomplete, and a better solution is out of scope for this release. A more complete solution will be implemented in the future. --- spec/integration/parser/parser_spec.rb | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'spec/integration') diff --git a/spec/integration/parser/parser_spec.rb b/spec/integration/parser/parser_spec.rb index 000e68dd8..20d87c228 100755 --- a/spec/integration/parser/parser_spec.rb +++ b/spec/integration/parser/parser_spec.rb @@ -116,18 +116,5 @@ describe Puppet::Parser::Parser do $out = $hash['a']['b']['c'] }.should parse_with { |v| v.value.is_a?(Puppet::Parser::AST::ASTHash) } end - - it "should be able to pass numbers to functions" do - %q{ - my_function(1) - }.should parse_as(Puppet::Parser::AST::Function) - end - - it "should be able to pass negative numbers to functions" do - %q{ - my_function(-1) - }.should parse_as(Puppet::Parser::AST::Function) - end - end end -- cgit From 4e29f439189e0a40364724f50971c83652463085 Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Tue, 1 Mar 2011 21:45:07 -0800 Subject: (#6541) maint: whitespace cleanup on the file integration spec --- spec/integration/type/file_spec.rb | 61 ++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 29 deletions(-) (limited to 'spec/integration') diff --git a/spec/integration/type/file_spec.rb b/spec/integration/type/file_spec.rb index 4b91e5ef9..31f4adee6 100755 --- a/spec/integration/type/file_spec.rb +++ b/spec/integration/type/file_spec.rb @@ -173,7 +173,12 @@ describe Puppet::Type.type(:file) do it "should be able to recurse over a nonexistent file" do @path = tmpfile("file_integration_tests") - @file = Puppet::Type::File.new(:name => @path, :mode => 0644, :recurse => true, :backup => false) + @file = Puppet::Type::File.new( + :name => @path, + :mode => 0644, + :recurse => true, + :backup => false + ) @catalog = Puppet::Resource::Catalog.new @catalog.add_resource @file @@ -186,7 +191,12 @@ describe Puppet::Type.type(:file) do build_path(@path) - @file = Puppet::Type::File.new(:name => @path, :mode => 0644, :recurse => true, :backup => false) + @file = Puppet::Type::File.new( + :name => @path, + :mode => 0644, + :recurse => true, + :backup => false + ) @catalog = Puppet::Resource::Catalog.new @catalog.add_resource @file @@ -393,10 +403,8 @@ describe Puppet::Type.type(:file) do dest = tmpfile("files_with_content") - file = Puppet::Type.type(:file).new( - - :name => dest, - + file = Puppet::Type.type(:file).new( + :name => dest, :content => "this is some content, yo" ) @@ -411,11 +419,9 @@ describe Puppet::Type.type(:file) do dest = tmpfile("files_with_content") - file = Puppet::Type.type(:file).new( - - :name => dest, - :ensure => "file", - + file = Puppet::Type.type(:file).new( + :name => dest, + :ensure => "file", :content => "this is some content, yo" ) @@ -433,12 +439,10 @@ describe Puppet::Type.type(:file) do File.open(dest, "w") { |f| f.puts "boo" } - file = Puppet::Type.type(:file).new( - - :name => dest, + file = Puppet::Type.type(:file).new( + :name => dest, :ensure => :absent, :source => source, - :backup => false ) @@ -465,24 +469,23 @@ describe Puppet::Type.type(:file) do File.open(@purgee, "w") { |f| f.puts "footest" } - @lfobj = Puppet::Type.newfile( - - :title => "localfile", - :path => @localfile, + @lfobj = Puppet::Type.newfile( + :title => "localfile", + :path => @localfile, :content => "rahtest\n", - :ensure => :file, - - :backup => false + :ensure => :file, + :backup => false ) - @destobj = Puppet::Type.newfile( - :title => "destdir", :path => @destdir, - :source => @sourcedir, - :backup => false, - :purge => true, - - :recurse => true) + @destobj = Puppet::Type.newfile( + :title => "destdir", + :path => @destdir, + :source => @sourcedir, + :backup => false, + :purge => true, + :recurse => true + ) @catalog = Puppet::Resource::Catalog.new @catalog.add_resource @lfobj, @destobj -- cgit From 9d2fceb7141e4cc7a6215aa2529239eb2eb6c8fd Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 1 Mar 2011 14:06:42 -0800 Subject: Maint: Begin adding integration tests for the mount provider These tests form a starting point for integration testing the mount provider, using the new Puppet::Util::ExecutionStub mechanism to simulate the state of the machine in response to the execution of "mount" and "umount" commands. The tests currently work around some known bugs (6628, 6632, and 6633). Reviewed-by: Max Martin --- spec/integration/provider/mount_spec.rb | 93 +++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 spec/integration/provider/mount_spec.rb (limited to 'spec/integration') diff --git a/spec/integration/provider/mount_spec.rb b/spec/integration/provider/mount_spec.rb new file mode 100644 index 000000000..69a9eeb56 --- /dev/null +++ b/spec/integration/provider/mount_spec.rb @@ -0,0 +1,93 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/file_bucket/dipper' + +describe "mount provider (integration)" do + include PuppetSpec::Files + + before :each do + @fake_fstab = tmpfile('fstab') + File.open(@fake_fstab, 'w') do |f| + # leave file empty + end + Puppet::Type.type(:mount).defaultprovider.stubs(:default_target).returns(@fake_fstab) + Facter.stubs(:value).with(:operatingsystem).returns('Darwin') + Puppet::Util::ExecutionStub.set do |command, options| + case command[0] + when '/sbin/mount' + if command.length == 1 + if @mounted + "/dev/disk1s1 on /Volumes/foo_disk (msdos, local)\n" + else + '' + end + else + command.length.should == 4 + command[1].should == '-o' + command[2].should == 'local' + command[3].should == '/Volumes/foo_disk' + @mounted.should == false # verify that we don't try to call "mount" redundantly + check_fstab + @mounted = true + '' + end + when '/sbin/umount' + fail "unexpected umount" unless @umount_permitted + command.length.should == 2 + command[1].should == '/Volumes/foo_disk' + @mounted = false + '' + else + fail "Unexpected command #{command.inspect} executed" + end + end + end + + after :each do + Puppet::Type::Mount::ProviderParsed.clear # Work around bug #6628 + end + + def check_fstab + # Verify that the fake fstab has the expected data in it + File.read(@fake_fstab).lines.reject { |x| x =~ /^#/ }.should == ["/dev/disk1s1\t/Volumes/foo_disk\tmsdos\tlocal\t0\t0\n"] + end + + def run_in_catalog(ensure_setting) + resource = Puppet::Type.type(:mount).new(:name => "/Volumes/foo_disk", :ensure => ensure_setting, + :device => "/dev/disk1s1", :options => "local", :fstype => "msdos") + Puppet::FileBucket::Dipper.any_instance.stubs(:backup) # Don't backup to the filebucket + resource.expects(:err).never + catalog = Puppet::Resource::Catalog.new + catalog.host_config = false # Stop Puppet from doing a bunch of magic + catalog.add_resource resource + catalog.apply + end + + [:defined, :present].each do |ensure_setting| + describe "When setting ensure => #{ensure_setting}" do + it "should create an fstab entry if none exists" do + @mounted = false + @umount_permitted = false + run_in_catalog(ensure_setting) + @mounted.should == false + check_fstab + end + end + end + + it "should be able to create and mount a brand new mount point" do + @mounted = false + @umount_permitted = true # Work around bug #6632 + run_in_catalog(:mounted) + @mounted.should == true + check_fstab + end + + it "should be able to create an fstab entry for an already-mounted device" do + @mounted = true + @umount_permitted = true # Work around bug #6633 + run_in_catalog(:mounted) + @mounted.should == true + check_fstab + end +end -- cgit From bd5517dd9cd8e10f488713d9654957746e687378 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Mon, 7 Mar 2011 17:56:41 -0800 Subject: Adjust Darwin mount provider tests to pass on Linux mount, and umount are located under /bin, instead of /sbin on Linux, so we adjust the ExecutionStub to accept either location. Paired-with: Jacob Helwig --- spec/integration/provider/mount_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/integration') diff --git a/spec/integration/provider/mount_spec.rb b/spec/integration/provider/mount_spec.rb index 69a9eeb56..c28707dd9 100644 --- a/spec/integration/provider/mount_spec.rb +++ b/spec/integration/provider/mount_spec.rb @@ -14,7 +14,7 @@ describe "mount provider (integration)" do Facter.stubs(:value).with(:operatingsystem).returns('Darwin') Puppet::Util::ExecutionStub.set do |command, options| case command[0] - when '/sbin/mount' + when %r{/s?bin/mount} if command.length == 1 if @mounted "/dev/disk1s1 on /Volumes/foo_disk (msdos, local)\n" @@ -31,7 +31,7 @@ describe "mount provider (integration)" do @mounted = true '' end - when '/sbin/umount' + when %r{/s?bin/umount} fail "unexpected umount" unless @umount_permitted command.length.should == 2 command[1].should == '/Volumes/foo_disk' -- cgit From 5ef10315705b8e4d69d13b8df86b9585f2bcc29a Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 8 Mar 2011 11:35:58 -0800 Subject: (#6632) Adding a new mount no longer causes error with umount There were two problems: * In lib/puppet/type/mount.rb, we were calling provider.mounted? to determine whether we needed to execute "mount" after updating the in-memory fstab record. This wasn't working properly because provider.mounted? makes its decision based on the data stored in the in-memory fstab record. Since the fstab record had just been updated, provider.mounted? was incorrectly returning true even though the device wasn't actually mounted. Fixed this by checking provider.mounted? before updating the in-memory fstab record. * Calling mount from this point in lib/puppet/type/mount.rb is actually too early, because even though the in-memory fstab record has been created, its contents have not been written to `/etc/fstab` yet. Fixed this by storing a :needs_mount entry in the property_hash and checking it at the end of the flush() method. Reviewed-by: Jacob Helwig --- spec/integration/provider/mount_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'spec/integration') diff --git a/spec/integration/provider/mount_spec.rb b/spec/integration/provider/mount_spec.rb index c28707dd9..518b2956f 100644 --- a/spec/integration/provider/mount_spec.rb +++ b/spec/integration/provider/mount_spec.rb @@ -35,6 +35,7 @@ describe "mount provider (integration)" do fail "unexpected umount" unless @umount_permitted command.length.should == 2 command[1].should == '/Volumes/foo_disk' + @mounted.should == true # "umount" doesn't work when device not mounted (see #6632) @mounted = false '' else @@ -77,7 +78,7 @@ describe "mount provider (integration)" do it "should be able to create and mount a brand new mount point" do @mounted = false - @umount_permitted = true # Work around bug #6632 + @umount_permitted = true # Work around bug #6633 run_in_catalog(:mounted) @mounted.should == true check_fstab -- cgit From 1ef83cb750896f997a347a144e20aa6c96daf171 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 8 Mar 2011 13:26:43 -0800 Subject: Added integration tests for the mount provider Paired-with: Max Martin --- spec/integration/provider/mount_spec.rb | 99 +++++++++++++++++++++------------ 1 file changed, 64 insertions(+), 35 deletions(-) (limited to 'spec/integration') diff --git a/spec/integration/provider/mount_spec.rb b/spec/integration/provider/mount_spec.rb index 518b2956f..a62505d6d 100644 --- a/spec/integration/provider/mount_spec.rb +++ b/spec/integration/provider/mount_spec.rb @@ -5,11 +5,17 @@ require 'puppet/file_bucket/dipper' describe "mount provider (integration)" do include PuppetSpec::Files - before :each do - @fake_fstab = tmpfile('fstab') + def create_fake_fstab(initially_contains_entry) File.open(@fake_fstab, 'w') do |f| - # leave file empty + if initially_contains_entry + f.puts("/dev/disk1s1\t/Volumes/foo_disk\tmsdos\tlocal\t0\t0") + end end + end + + before :each do + @fake_fstab = tmpfile('fstab') + @current_options = "local" Puppet::Type.type(:mount).defaultprovider.stubs(:default_target).returns(@fake_fstab) Facter.stubs(:value).with(:operatingsystem).returns('Darwin') Puppet::Util::ExecutionStub.set do |command, options| @@ -17,22 +23,21 @@ describe "mount provider (integration)" do when %r{/s?bin/mount} if command.length == 1 if @mounted - "/dev/disk1s1 on /Volumes/foo_disk (msdos, local)\n" + "/dev/disk1s1 on /Volumes/foo_disk (msdos, #{@current_options})\n" else '' end else command.length.should == 4 command[1].should == '-o' - command[2].should == 'local' command[3].should == '/Volumes/foo_disk' @mounted.should == false # verify that we don't try to call "mount" redundantly - check_fstab + @current_options = command[2] + check_fstab(true) @mounted = true '' end when %r{/s?bin/umount} - fail "unexpected umount" unless @umount_permitted command.length.should == 2 command[1].should == '/Volumes/foo_disk' @mounted.should == true # "umount" doesn't work when device not mounted (see #6632) @@ -48,14 +53,15 @@ describe "mount provider (integration)" do Puppet::Type::Mount::ProviderParsed.clear # Work around bug #6628 end - def check_fstab + def check_fstab(expected_to_be_present) # Verify that the fake fstab has the expected data in it - File.read(@fake_fstab).lines.reject { |x| x =~ /^#/ }.should == ["/dev/disk1s1\t/Volumes/foo_disk\tmsdos\tlocal\t0\t0\n"] + expected_data = expected_to_be_present ? ["/dev/disk1s1\t/Volumes/foo_disk\tmsdos\t#{@desired_options}\t0\t0"] : [] + File.read(@fake_fstab).lines.map(&:chomp).reject { |x| x =~ /^#|^$/ }.should == expected_data end - def run_in_catalog(ensure_setting) - resource = Puppet::Type.type(:mount).new(:name => "/Volumes/foo_disk", :ensure => ensure_setting, - :device => "/dev/disk1s1", :options => "local", :fstype => "msdos") + def run_in_catalog(settings) + resource = Puppet::Type.type(:mount).new(settings.merge(:name => "/Volumes/foo_disk", + :device => "/dev/disk1s1", :fstype => "msdos")) Puppet::FileBucket::Dipper.any_instance.stubs(:backup) # Don't backup to the filebucket resource.expects(:err).never catalog = Puppet::Resource::Catalog.new @@ -64,31 +70,54 @@ describe "mount provider (integration)" do catalog.apply end - [:defined, :present].each do |ensure_setting| - describe "When setting ensure => #{ensure_setting}" do - it "should create an fstab entry if none exists" do - @mounted = false - @umount_permitted = false - run_in_catalog(ensure_setting) - @mounted.should == false - check_fstab + [false, true].each do |initial_state| + describe "When initially #{initial_state ? 'mounted' : 'unmounted'}" do + before :each do + @mounted = initial_state end - end - end - it "should be able to create and mount a brand new mount point" do - @mounted = false - @umount_permitted = true # Work around bug #6633 - run_in_catalog(:mounted) - @mounted.should == true - check_fstab - end + [false, true].each do |initial_fstab_entry| + describe "When there is #{initial_fstab_entry ? 'an' : 'no'} initial fstab entry" do + before :each do + create_fake_fstab(initial_fstab_entry) + end - it "should be able to create an fstab entry for an already-mounted device" do - @mounted = true - @umount_permitted = true # Work around bug #6633 - run_in_catalog(:mounted) - @mounted.should == true - check_fstab + [:defined, :present, :mounted, :unmounted, :absent].each do |ensure_setting| + expected_final_state = case ensure_setting + when :mounted + true + when :unmounted, :absent + false + when :defined, :present + initial_state + else + fail "Unknown ensure_setting #{ensure_setting}" + end + expected_fstab_data = (ensure_setting != :absent) + describe "When setting ensure => #{ensure_setting}" do + ["local", "journaled"].each do |options_setting| + describe "When setting options => #{options_setting}" do + it "should leave the system in the #{expected_final_state ? 'mounted' : 'unmounted'} state, #{expected_fstab_data ? 'with' : 'without'} data in /etc/fstab" do + @desired_options = options_setting + run_in_catalog(:ensure=>ensure_setting, :options => options_setting) + @mounted.should == expected_final_state + check_fstab(expected_fstab_data) + if @mounted + if ![:defined, :present].include?(ensure_setting) + @current_options.should == @desired_options + elsif initial_fstab_entry + @current_options.should == @desired_options + else + @current_options.should == 'local' #Workaround for #6645 + end + end + end + end + end + end + end + end + end + end end end -- cgit From 7764412aacb4132d40561e2ba47d52f5e333c16e Mon Sep 17 00:00:00 2001 From: Max Martin Date: Tue, 8 Mar 2011 16:20:53 -0800 Subject: maint:Refactor of mount provider integration tests When adding a test for #6309, decided to refactor mount provider integration tests by adding return value to check_fstab method. Paired-with:Paul Berry --- spec/integration/provider/mount_spec.rb | 38 ++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'spec/integration') diff --git a/spec/integration/provider/mount_spec.rb b/spec/integration/provider/mount_spec.rb index a62505d6d..d6f25fe1d 100644 --- a/spec/integration/provider/mount_spec.rb +++ b/spec/integration/provider/mount_spec.rb @@ -16,6 +16,7 @@ describe "mount provider (integration)" do before :each do @fake_fstab = tmpfile('fstab') @current_options = "local" + @current_device = "/dev/disk1s1" Puppet::Type.type(:mount).defaultprovider.stubs(:default_target).returns(@fake_fstab) Facter.stubs(:value).with(:operatingsystem).returns('Darwin') Puppet::Util::ExecutionStub.set do |command, options| @@ -23,7 +24,7 @@ describe "mount provider (integration)" do when %r{/s?bin/mount} if command.length == 1 if @mounted - "/dev/disk1s1 on /Volumes/foo_disk (msdos, #{@current_options})\n" + "#{@current_device} on /Volumes/foo_disk (msdos, #{@current_options})\n" else '' end @@ -33,7 +34,7 @@ describe "mount provider (integration)" do command[3].should == '/Volumes/foo_disk' @mounted.should == false # verify that we don't try to call "mount" redundantly @current_options = command[2] - check_fstab(true) + @current_device = check_fstab(true) @mounted = true '' end @@ -55,8 +56,16 @@ describe "mount provider (integration)" do def check_fstab(expected_to_be_present) # Verify that the fake fstab has the expected data in it - expected_data = expected_to_be_present ? ["/dev/disk1s1\t/Volumes/foo_disk\tmsdos\t#{@desired_options}\t0\t0"] : [] - File.read(@fake_fstab).lines.map(&:chomp).reject { |x| x =~ /^#|^$/ }.should == expected_data + fstab_contents = File.read(@fake_fstab).lines.map(&:chomp).reject { |x| x =~ /^#|^$/ } + if expected_to_be_present + fstab_contents.length().should == 1 + device, rest_of_line = fstab_contents[0].split(/\t/,2) + rest_of_line.should == "/Volumes/foo_disk\tmsdos\t#{@desired_options}\t0\t0" + device + else + fstab_contents.length().should == 0 + nil + end end def run_in_catalog(settings) @@ -101,7 +110,11 @@ describe "mount provider (integration)" do @desired_options = options_setting run_in_catalog(:ensure=>ensure_setting, :options => options_setting) @mounted.should == expected_final_state - check_fstab(expected_fstab_data) + if expected_fstab_data + check_fstab(expected_fstab_data).should == "/dev/disk1s1" + else + check_fstab(expected_fstab_data).should == nil + end if @mounted if ![:defined, :present].include?(ensure_setting) @current_options.should == @desired_options @@ -120,4 +133,19 @@ describe "mount provider (integration)" do end end end + + describe "When the wrong device is mounted" do + it "should remount the correct device" do + pending "Due to bug 6309" + @mounted = true + @current_device = "/dev/disk2s2" + create_fake_fstab(true) + @desired_options = "local" + run_in_catalog(:ensure=>:mounted, :options=>'local') + @current_device.should=="/dev/disk1s1" + @mounted.should==true + @current_options.should=='local' + check_fstab(true).should == "/dev/disk1s1" + end + end end -- cgit