From 17e7223526f3ec0b7eefc42e48fc215f5e1717c4 Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Fri, 20 May 2011 12:17:41 -0700 Subject: (#7507) Add exclude filter for ruby 1.9 spec failures Exclude spec test for multiple writer processes as this fails intermittently on ruby 1.9. Reviewed-by: Jacob Helwig --- spec/integration/util/file_locking_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/integration/util/file_locking_spec.rb b/spec/integration/util/file_locking_spec.rb index 3b6964e8b..624ba033c 100755 --- a/spec/integration/util/file_locking_spec.rb +++ b/spec/integration/util/file_locking_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require 'puppet/util/file_locking' -describe Puppet::Util::FileLocking do +describe Puppet::Util::FileLocking, :'fails_on_ruby_1.9.2' => true do before :each do @file = Tempfile.new("puppetspec") filepath = @file.path @@ -13,7 +13,7 @@ describe Puppet::Util::FileLocking do File.open(@file, "w") { |f| f.puts YAML.dump(@data) } end - it "should be able to keep file corruption from happening when there are multiple writers threads", :'fails_in_ruby_1.9.2' => true do + it "should be able to keep file corruption from happening when there are multiple writers threads" do threads = [] sync = Sync.new 9.times { |a| -- cgit From 4645c99166f415b87ac1bfd01caebdcbeb65d19f Mon Sep 17 00:00:00 2001 From: Dominic Maraglia Date: Fri, 20 May 2011 15:45:57 -0700 Subject: add puppet master polling step for ticket 7117 The test for ticket 7117 producedes spurious failures due to timing: a curl command is executed from an agent to a freshly started Puppet Master; if the Puppet Master is not ready to accept the connection the test will fail. Added an until loop that issues simple curl command to see if the Puppet Master is up and ready --- acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb b/acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb index 3f762bcca..79f56c07a 100644 --- a/acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb +++ b/acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb @@ -17,7 +17,17 @@ on master, "ps -U puppet | awk '/puppet/ { print \$1 }' | xargs kill || echo \"P step "Master: Start Puppet Master" on master, puppet_master("--certdnsnames=\"puppet:$(hostname -s):$(hostname -f)\" --verbose --noop") # allow Master to start and initialize environment -sleep 1 + +step "Verify Puppet Master is ready to accept connections" +host=agents.first +time1 = Time.new +until + on(host, "curl -k https://#{master}:8140") do + sleep 1 + end +time2 = Time.new +elapsed = time2 - time1 +Log.notify "Slept for #{elapsed} seconds waiting for Puppet Master to become ready" -- cgit From 8eea3f5481f429a415159a716b7a8f60f3c9be5a Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Mon, 23 May 2011 06:19:28 +1000 Subject: Added the vcsrepo type and providers to the core --- lib/puppet/provider/vcsrepo.rb | 34 +++++ lib/puppet/provider/vcsrepo/bzr.rb | 64 +++++++++ lib/puppet/provider/vcsrepo/cvs.rb | 80 +++++++++++ lib/puppet/provider/vcsrepo/git.rb | 264 +++++++++++++++++++++++++++++++++++++ lib/puppet/provider/vcsrepo/hg.rb | 101 ++++++++++++++ lib/puppet/provider/vcsrepo/svn.rb | 82 ++++++++++++ lib/puppet/type/vcsrepo.rb | 138 +++++++++++++++++++ 7 files changed, 763 insertions(+) create mode 100644 lib/puppet/provider/vcsrepo.rb create mode 100644 lib/puppet/provider/vcsrepo/bzr.rb create mode 100644 lib/puppet/provider/vcsrepo/cvs.rb create mode 100644 lib/puppet/provider/vcsrepo/git.rb create mode 100644 lib/puppet/provider/vcsrepo/hg.rb create mode 100644 lib/puppet/provider/vcsrepo/svn.rb create mode 100644 lib/puppet/type/vcsrepo.rb diff --git a/lib/puppet/provider/vcsrepo.rb b/lib/puppet/provider/vcsrepo.rb new file mode 100644 index 000000000..2c026ba86 --- /dev/null +++ b/lib/puppet/provider/vcsrepo.rb @@ -0,0 +1,34 @@ +require 'tmpdir' +require 'digest/md5' +require 'fileutils' + +# Abstract +class Puppet::Provider::Vcsrepo < Puppet::Provider + + private + + def set_ownership + owner = @resource.value(:owner) || nil + group = @resource.value(:group) || nil + FileUtils.chown_R(owner, group, @resource.value(:path)) + end + + def path_exists? + File.directory?(@resource.value(:path)) + end + + # Note: We don't rely on Dir.chdir's behavior of automatically returning the + # value of the last statement -- for easier stubbing. + def at_path(&block) #:nodoc: + value = nil + Dir.chdir(@resource.value(:path)) do + value = yield + end + value + end + + def tempdir + @tempdir ||= File.join(Dir.tmpdir, 'vcsrepo-' + Digest::MD5.hexdigest(@resource.value(:path))) + end + +end diff --git a/lib/puppet/provider/vcsrepo/bzr.rb b/lib/puppet/provider/vcsrepo/bzr.rb new file mode 100644 index 000000000..a0605624b --- /dev/null +++ b/lib/puppet/provider/vcsrepo/bzr.rb @@ -0,0 +1,64 @@ +require File.join(File.dirname(__FILE__), '..', 'vcsrepo') + +Puppet::Type.type(:vcsrepo).provide(:bzr, :parent => Puppet::Provider::Vcsrepo) do + desc "Supports Bazaar repositories" + + commands :bzr => 'bzr' + defaultfor :bzr => :exists + has_features :reference_tracking + + def create + if !@resource.value(:source) + create_repository(@resource.value(:path)) + else + clone_repository(@resource.value(:revision)) + end + end + + def exists? + File.directory?(File.join(@resource.value(:path), '.bzr')) + end + + def destroy + FileUtils.rm_rf(@resource.value(:path)) + end + + def revision + at_path do + current_revid = bzr('version-info')[/^revision-id:\s+(\S+)/, 1] + desired = @resource.value(:revision) + begin + desired_revid = bzr('revision-info', desired).strip.split(/\s+/).last + rescue Puppet::ExecutionFailure + # Possible revid available during update (but definitely not current) + desired_revid = nil + end + if current_revid == desired_revid + desired + else + current_revid + end + end + end + + def revision=(desired) + bzr('update', '-r', desired, @resource.value(:path)) + end + + private + + def create_repository(path) + bzr('init', path) + end + + def clone_repository(revision) + args = ['branch'] + if revision + args.push('-r', revision) + end + args.push(@resource.value(:source), + @resource.value(:path)) + bzr(*args) + end + +end diff --git a/lib/puppet/provider/vcsrepo/cvs.rb b/lib/puppet/provider/vcsrepo/cvs.rb new file mode 100644 index 000000000..e82c23afe --- /dev/null +++ b/lib/puppet/provider/vcsrepo/cvs.rb @@ -0,0 +1,80 @@ +require File.join(File.dirname(__FILE__), '..', 'vcsrepo') + +Puppet::Type.type(:vcsrepo).provide(:cvs, :parent => Puppet::Provider::Vcsrepo) do + desc "Supports CVS repositories/workspaces" + + commands :cvs => 'cvs' + defaultfor :cvs => :exists + has_features :gzip_compression, :reference_tracking + + def create + if !@resource.value(:source) + create_repository(@resource.value(:path)) + else + checkout_repository + end + end + + def exists? + if @resource.value(:source) + directory = File.join(@resource.value(:path), 'CVS') + else + directory = File.join(@resource.value(:path), 'CVSROOT') + end + File.directory?(directory) + end + + def destroy + FileUtils.rm_rf(@resource.value(:path)) + end + + def revision + if File.exist?(tag_file) + contents = File.read(tag_file) + # Note: Doesn't differentiate between N and T entries + contents[1..-1] + else + 'MAIN' + end + end + + def revision=(desired) + at_path do + cvs('update', '-r', desired, '.') + end + end + + private + + def tag_file + File.join(@resource.value(:path), 'CVS', 'Tag') + end + + def checkout_repository + dirname, basename = File.split(@resource.value(:path)) + Dir.chdir(dirname) do + args = ['-d', @resource.value(:source)] + if @resource.value(:compression) + args.push('-z', @resource.value(:compression)) + end + args.push('checkout', '-d', basename, module_name) + cvs(*args) + end + if @resource.value(:revision) + self.revision = @resource.value(:revision) + end + end + + # When the source: + # * Starts with ':' (eg, :pserver:...) + def module_name + if (source = @resource.value(:source)) + source[0, 1] == ':' ? File.basename(source) : '.' + end + end + + def create_repository(path) + cvs('-d', path, 'init') + end + +end diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb new file mode 100644 index 000000000..fa7e492cf --- /dev/null +++ b/lib/puppet/provider/vcsrepo/git.rb @@ -0,0 +1,264 @@ +require File.join(File.dirname(__FILE__), '..', 'vcsrepo') + +Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) do + desc "Supports Git repositories" + + ##TODO modify the commands below so that the su - is included + commands :git => 'git' + defaultfor :git => :exists + has_features :bare_repositories, :reference_tracking + + def create + if !@resource.value(:source) + init_repository(@resource.value(:path)) + else + clone_repository(@resource.value(:source), @resource.value(:path)) + if @resource.value(:revision) + if @resource.value(:ensure) == :bare + notice "Ignoring revision for bare repository" + else + checkout_or_reset + end + end + if @resource.value(:ensure) != :bare + update_submodules + end + end + update_owner_and_excludes + end + + def destroy + FileUtils.rm_rf(@resource.value(:path)) + end + + def latest? + at_path do + return self.revision == self.latest + end + end + + def latest + branch = on_branch? + if branch == 'master' + return get_revision('origin/HEAD') + else + return get_revision('origin/%s' % branch) + end + end + + def revision + update_references + current = at_path { git('rev-parse', 'HEAD') } + canonical = at_path { git('rev-parse', @resource.value(:revision)) } + if current == canonical + @resource.value(:revision) + else + current + end + end + + def revision=(desired) + checkout_or_reset(desired) + if local_branch_revision?(desired) + # reset instead of pull to avoid merge conflicts. assuming remote is + # authoritative. + # might be worthwhile to have an allow_local_changes param to decide + # whether to reset or pull when we're ensuring latest. + at_path { git('reset', '--hard', "origin/#{desired}") } + end + if @resource.value(:ensure) != :bare + update_submodules + end + update_owner_and_excludes + end + + def bare_exists? + bare_git_config_exists? && !working_copy_exists? + end + + def working_copy_exists? + File.directory?(File.join(@resource.value(:path), '.git')) + end + + def exists? + working_copy_exists? || bare_exists? + end + + def update_references + at_path do + git('fetch', '--tags', 'origin') + end + end + + private + + def bare_git_config_exists? + File.exist?(File.join(@resource.value(:path), 'config')) + end + + def clone_repository(source, path) + check_force + args = ['clone'] + if @resource.value(:ensure) == :bare + args << '--bare' + end + if !File.exist?(File.join(@resource.value(:path), '.git')) + args.push(source, path) + git(*args) + else + notice "Repo has already been cloned" + end + end + + def check_force + if path_exists? + if @resource.value(:force) + notice "Removing %s to replace with vcsrepo." % @resource.value(:path) + destroy + else + raise Puppet::Error, "Could not create repository (non-repository at path)" + end + end + end + + def init_repository(path) + check_force + if @resource.value(:ensure) == :bare && working_copy_exists? + convert_working_copy_to_bare + elsif @resource.value(:ensure) == :present && bare_exists? + convert_bare_to_working_copy + else + # normal init + FileUtils.mkdir(@resource.value(:path)) + args = ['init'] + if @resource.value(:ensure) == :bare + args << '--bare' + end + at_path do + git(*args) + end + end + end + + # Convert working copy to bare + # + # Moves: + # /.git + # to: + # / + def convert_working_copy_to_bare + notice "Converting working copy repository to bare repository" + FileUtils.mv(File.join(@resource.value(:path), '.git'), tempdir) + FileUtils.rm_rf(@resource.value(:path)) + FileUtils.mv(tempdir, @resource.value(:path)) + end + + # Convert bare to working copy + # + # Moves: + # / + # to: + # /.git + def convert_bare_to_working_copy + notice "Converting bare repository to working copy repository" + FileUtils.mv(@resource.value(:path), tempdir) + FileUtils.mkdir(@resource.value(:path)) + FileUtils.mv(tempdir, File.join(@resource.value(:path), '.git')) + if commits_in?(File.join(@resource.value(:path), '.git')) + reset('HEAD') + git('checkout', '-f') + update_owner_and_excludes + end + end + + def commits_in?(dot_git) + Dir.glob(File.join(dot_git, 'objects/info/*'), File::FNM_DOTMATCH) do |e| + return true unless %w(. ..).include?(File::basename(e)) + end + false + end + + def checkout_or_reset(revision = @resource.value(:revision)) + if local_branch_revision? + reset(revision) + elsif tag_revision? + at_path { git('checkout', '-b', revision) } + elsif remote_branch_revision? + at_path { git('checkout', '-b', revision, '--track', "origin/#{revision}") } + end + end + + def reset(desired) + at_path do + git('reset', '--hard', desired) + end + end + + def update_submodules + at_path do + git('submodule', 'init') + git('submodule', 'update') + git('submodule', 'foreach', 'git', 'submodule', 'init') + git('submodule', 'foreach', 'git', 'submodule', 'update') + end + end + + def remote_branch_revision?(revision = @resource.value(:revision)) + # git < 1.6 returns 'origin/#{revision}' + # git 1.6+ returns 'remotes/origin/#{revision}' + at_path { branches.grep /(remotes\/)?origin\/#{revision}/ } + end + + def local_branch_revision?(revision = @resource.value(:revision)) + at_path { branches.include?(revision) } + end + + def tag_revision?(revision = @resource.value(:revision)) + at_path { tags.include?(revision) } + end + + def branches + at_path { git('branch', '-a') }.gsub('*', ' ').split(/\n/).map { |line| line.strip } + end + + def on_branch? + at_path { git('branch', '-a') }.split(/\n/).grep(/\*/).to_s.gsub('*', '').strip + end + + def tags + at_path { git('tag', '-l') }.split(/\n/).map { |line| line.strip } + end + + def set_excludes + at_path { open('.git/info/exclude', 'w') { |f| @resource.value(:excludes).each { |ex| f.write(ex + "\n") }}} + end + + def get_revision(rev) + if !working_copy_exists? + create + end + at_path do + git('fetch', 'origin') + git('fetch', '--tags', 'origin') + end + current = at_path { git('rev-parse', rev).strip } + if @resource.value(:revision) + if local_branch_revision? + canonical = at_path { git('rev-parse', @resource.value(:revision)).strip } + elsif remote_branch_revision? + canonical = at_path { git('rev-parse', 'origin/' + @resource.value(:revision)).strip } + end + current = @resource.value(:revision) if current == canonical + end + return current + end + + def update_owner_and_excludes + if @resource.value(:owner) or @resource.value(:group) + set_ownership + end + if @resource.value(:excludes) + set_excludes + end + end +end diff --git a/lib/puppet/provider/vcsrepo/hg.rb b/lib/puppet/provider/vcsrepo/hg.rb new file mode 100644 index 000000000..f96758612 --- /dev/null +++ b/lib/puppet/provider/vcsrepo/hg.rb @@ -0,0 +1,101 @@ +require File.join(File.dirname(__FILE__), '..', 'vcsrepo') + +Puppet::Type.type(:vcsrepo).provide(:hg, :parent => Puppet::Provider::Vcsrepo) do + desc "Supports Mercurial repositories" + + commands :hg => 'hg' + defaultfor :hg => :exists + has_features :reference_tracking + + def create + if !@resource.value(:source) + create_repository(@resource.value(:path)) + else + clone_repository(@resource.value(:revision)) + end + update_owner + end + + def working_copy_exists? + File.directory?(File.join(@resource.value(:path), '.hg')) + end + + def exists? + working_copy_exists? + end + + def destroy + FileUtils.rm_rf(@resource.value(:path)) + end + + def latest? + at_path do + return self.revision == self.latest + end + end + + def latest + at_path do + begin + hg('incoming', '--branch', '.', '--newest-first', '--limit', '1')[/^changeset:\s+(?:-?\d+):(\S+)/m, 1] + rescue Puppet::ExecutionFailure + # If there are no new changesets, return the current nodeid + self.revision + end + end + end + + def revision + at_path do + current = hg('parents')[/^changeset:\s+(?:-?\d+):(\S+)/m, 1] + desired = @resource.value(:revision) + if desired + # Return the tag name if it maps to the current nodeid + mapped = hg('tags')[/^#{Regexp.quote(desired)}\s+\d+:(\S+)/m, 1] + if current == mapped + desired + else + current + end + else + current + end + end + end + + def revision=(desired) + at_path do + hg('pull') + begin + hg('merge') + rescue Puppet::ExecutionFailure + # If there's nothing to merge, just skip + end + hg('update', '--clean', '-r', desired) + end + update_owner + end + + private + + def create_repository(path) + hg('init', path) + end + + def clone_repository(revision) + args = ['clone'] + if revision + args.push('-u', revision) + end + args.push(@resource.value(:source), + @resource.value(:path)) + hg(*args) + end + + def update_owner + if @resource.value(:owner) or @resource.value(:group) + set_ownership + end + end + +end diff --git a/lib/puppet/provider/vcsrepo/svn.rb b/lib/puppet/provider/vcsrepo/svn.rb new file mode 100644 index 000000000..680188c1e --- /dev/null +++ b/lib/puppet/provider/vcsrepo/svn.rb @@ -0,0 +1,82 @@ +require File.join(File.dirname(__FILE__), '..', 'vcsrepo') + +Puppet::Type.type(:vcsrepo).provide(:svn, :parent => Puppet::Provider::Vcsrepo) do + desc "Supports Subversion repositories" + + commands :svn => 'svn', + :svnadmin => 'svnadmin' + + defaultfor :svn => :exists + has_features :filesystem_types, :reference_tracking + + def create + if !@resource.value(:source) + create_repository(@resource.value(:path)) + else + checkout_repository(@resource.value(:source), + @resource.value(:path), + @resource.value(:revision)) + end + end + + def working_copy_exists? + File.directory?(File.join(@resource.value(:path), '.svn')) + end + + def exists? + working_copy_exists? + end + + def destroy + FileUtils.rm_rf(@resource.value(:path)) + end + + def latest? + at_path do + if self.revision < self.latest then + return false + else + return true + end + end + end + + def latest + at_path do + svn('info', '-r', 'HEAD')[/^Revision:\s+(\d+)/m, 1] + end + end + + def revision + at_path do + svn('info')[/^Revision:\s+(\d+)/m, 1] + end + end + + def revision=(desired) + at_path do + svn('update', '-r', desired) + end + end + + private + + def checkout_repository(source, path, revision = nil) + args = ['checkout'] + if revision + args.push('-r', revision) + end + args.push(source, path) + svn(*args) + end + + def create_repository(path) + args = ['create'] + if @resource.value(:fstype) + args.push('--fs-type', @resource.value(:fstype)) + end + args << path + svnadmin(*args) + end + +end diff --git a/lib/puppet/type/vcsrepo.rb b/lib/puppet/type/vcsrepo.rb new file mode 100644 index 000000000..f0d2613ca --- /dev/null +++ b/lib/puppet/type/vcsrepo.rb @@ -0,0 +1,138 @@ +require 'pathname' + +Puppet::Type.newtype(:vcsrepo) do + desc "A local version control repository" + + feature :gzip_compression, + "The provider supports explicit GZip compression levels" + + feature :bare_repositories, + "The provider differentiates between bare repositories + and those with working copies", + :methods => [:bare_exists?, :working_copy_exists?] + + feature :filesystem_types, + "The provider supports different filesystem types" + + feature :reference_tracking, + "The provider supports tracking revision references that can change + over time (eg, some VCS tags and branch names)" + + ensurable do + attr_accessor :latest + + def insync?(is) + @should ||= [] + + case should + when :present + return true unless [:absent, :purged, :held].include?(is) + when :latest + if is == :latest + return true + else + self.debug "%s repo revision is %s, latest is %s" % + [@resource.name, provider.revision, provider.latest] + return false + end + end + end + + newvalue :present do + provider.create + end + + newvalue :bare, :required_features => [:bare_repositories] do + provider.create + end + + newvalue :absent do + provider.destroy + end + + newvalue :latest, :required_features => [:reference_tracking] do + if provider.exists? + if provider.respond_to?(:update_references) + provider.update_references + end + if provider.respond_to?(:latest?) + reference = provider.latest || provider.revision + else + reference = resource.value(:revision) || provider.revision + end + notice "Updating to latest '#{reference}' revision" + provider.revision = reference + else + provider.create + end + end + + def retrieve + prov = @resource.provider + if prov + if prov.working_copy_exists? + prov.latest? ? :latest : :present + elsif prov.class.feature?(:bare_repositories) and prov.bare_exists? + :bare + else + :absent + end + else + raise Puppet::Error, "Could not find provider" + end + end + + end + + newparam(:path) do + desc "Absolute path to repository" + isnamevar + validate do |value| + path = Pathname.new(value) + unless path.absolute? + raise ArgumentError, "Path must be absolute: #{path}" + end + end + end + + newparam(:source) do + desc "The source URI for the repository" + end + + newparam(:fstype, :required_features => [:filesystem_types]) do + desc "Filesystem type" + end + + newproperty(:revision) do + desc "The revision of the repository" + newvalue(/^\S+$/) + end + + newparam(:owner) do + desc "The user/uid that owns the repository files" + end + + newparam(:group) do + desc "The group/gid that owns the repository files" + end + + newparam(:excludes) do + desc "Files to be excluded from the repository" + end + + newparam(:force) do + desc "Force repository creation, destroying any files on the path in the process." + newvalues(:true, :false) + defaultto false + end + + newparam :compression, :required_features => [:gzip_compression] do + desc "Compression level" + validate do |amount| + unless Integer(amount).between?(0, 6) + raise ArgumentError, "Unsupported compression level: #{amount} (expected 0-6)" + end + end + end + +end -- cgit From 9145569f8a11216b9b8f99c1b2dd12da832cf9d4 Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Tue, 24 May 2011 10:11:50 -0700 Subject: maint: Remove reliance on system clock from schedule spec tests Several schedule spec tests made assumptions about the system clock, which resulted in intermittent failures. Also found some issues with schedule ranges, filed it as bug #7369 and created a pending schedule test for it. Reviewed-by: Jacob Helwig --- spec/unit/type/schedule_spec.rb | 115 +++++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 42 deletions(-) diff --git a/spec/unit/type/schedule_spec.rb b/spec/unit/type/schedule_spec.rb index 08ec70cd7..b302d95cd 100755 --- a/spec/unit/type/schedule_spec.rb +++ b/spec/unit/type/schedule_spec.rb @@ -3,10 +3,6 @@ require 'spec_helper' module ScheduleTesting - def format(time) - time.strftime("%H:%M:%S") - end - def diff(unit, incr, method, count) diff = Time.now.to_i.send(method, incr * count) Time.at(diff) @@ -54,7 +50,7 @@ describe Puppet::Type.type(:schedule) do it "should never match when the period is :never" do @schedule[:period] = :never - @schedule.match?.should be_false + @schedule.should_not be_match end end @@ -80,19 +76,44 @@ describe Puppet::Type.type(:schedule) do describe Puppet::Type.type(:schedule), "when matching ranges" do include ScheduleTesting + before do + Time.stubs(:now).returns(Time.local(2011, "may", 23, 11, 0, 0)) + end + it "should match when the start time is before the current time and the end time is after the current time" do - @schedule[:range] = "#{format(Time.now - 10)} - #{format(Time.now + 10)}" - @schedule.match?.should be_true + @schedule[:range] = "10:59:50 - 11:00:10" + @schedule.should be_match end it "should not match when the start time is after the current time" do - @schedule[:range] = "#{format(Time.now + 5)} - #{format(Time.now + 10)}" - @schedule.match?.should be_false + @schedule[:range] = "11:00:05 - 11:00:10" + @schedule.should_not be_match end it "should not match when the end time is previous to the current time" do - @schedule[:range] = "#{format(Time.now - 10)} - #{format(Time.now - 5)}" - @schedule.match?.should be_false + @schedule[:range] = "10:59:50 - 10:59:55" + @schedule.should be_match + end + + it "should throw an error if the upper limit is less than the lower limit" do + pending "bug #7639" + @schedule[:range] = "01:02:03 - 01:00:00" + @schedule.should_throw Puppet::Error + end + + it "should not match the current time fails between an array of ranges" do + @schedule[:range] = ["4-6", "20-23"] + @schedule.should_not be_match + end + + it "should match the lower array of ranges" do + @schedule[:range] = ["9-11", "14-16"] + @schedule.should be_match + end + + it "should match the upper array of ranges" do + @schedule[:range] = ["4-6", "11-12"] + @schedule.should be_match end end @@ -102,18 +123,20 @@ describe Puppet::Type.type(:schedule) do before do @schedule[:period] = :hourly @schedule[:periodmatch] = :distance + + Time.stubs(:now).returns(Time.local(2011, "may", 23, 11, 0, 0)) end - it "should match an hour ago" do - @schedule.match?(hour("-", 1)).should be_true + it "should match when the previous time was an hour ago" do + @schedule.should be_match(hour("-", 1)) end - it "should not match now" do - @schedule.match?(Time.now).should be_false + it "should not match when the previous time was now" do + @schedule.should_not be_match(Time.now) end - it "should not match 59 minutes ago" do - @schedule.match?(min("-", 59)).should be_false + it "should not match when the previous time was 59 minutes ago" do + @schedule.should_not be_match(min("-", 59)) end end @@ -123,18 +146,20 @@ describe Puppet::Type.type(:schedule) do before do @schedule[:period] = :daily @schedule[:periodmatch] = :distance + + Time.stubs(:now).returns(Time.local(2011, "may", 23, 11, 0, 0)) end it "should match when the previous time was one day ago" do - @schedule.match?(day("-", 1)).should be_true + @schedule.should be_match(day("-", 1)) end it "should not match when the previous time is now" do - @schedule.match?(Time.now).should be_false + @schedule.should_not be_match(Time.now) end it "should not match when the previous time was 23 hours ago" do - @schedule.match?(hour("-", 23)).should be_false + @schedule.should_not be_match(hour("-", 23)) end end @@ -144,18 +169,20 @@ describe Puppet::Type.type(:schedule) do before do @schedule[:period] = :weekly @schedule[:periodmatch] = :distance + + Time.stubs(:now).returns(Time.local(2011, "may", 23, 11, 0, 0)) end - it "should match seven days ago" do - @schedule.match?(day("-", 7)).should be_true + it "should match when the previous time was seven days ago" do + @schedule.should be_match(day("-", 7)) end - it "should not match now" do - @schedule.match?(Time.now).should be_false + it "should not match when the previous time was now" do + @schedule.should be_match(Time.now) end - it "should not match six days ago" do - @schedule.match?(day("-", 6)).should be_false + it "should not match when the previous time was six days ago" do + @schedule.should_not be_match(day("-", 6)) end end @@ -165,18 +192,20 @@ describe Puppet::Type.type(:schedule) do before do @schedule[:period] = :monthly @schedule[:periodmatch] = :distance + + Time.stubs(:now).returns(Time.local(2011, "may", 23, 11, 0, 0)) end - it "should match 32 days ago" do - @schedule.match?(day("-", 32)).should be_true + it "should match when the previous time was 32 days ago" do + @schedule.should be_match(day("-", 32)) end - it "should not match now" do - @schedule.match?(Time.now).should be_false + it "should not match when the previous time was now" do + @schedule.should_not be_match(Time.now) end - it "should not match 27 days ago" do - @schedule.match?(day("-", 27)).should be_false + it "should not match when the previous time was 27 days ago" do + @schedule.should_not be_match(day("-", 27)) end end @@ -193,7 +222,7 @@ describe Puppet::Type.type(:schedule) do previous = Time.utc(2007, 12, 31, 23, 59, 0) Time.stubs(:now).returns(current) - @schedule.match?(previous).should be_true + @schedule.should be_match(previous) end it "should not match if the times are 59 minutes apart and the current minute is 59" do @@ -201,7 +230,7 @@ describe Puppet::Type.type(:schedule) do previous = Time.utc(2009, 2, 1, 12, 0, 0) Time.stubs(:now).returns(current) - @schedule.match?(previous).should be_false + @schedule.should_not be_match(previous) end end @@ -220,7 +249,7 @@ describe Puppet::Type.type(:schedule) do previous = current - 60 Time.stubs(:now).returns(current) - @schedule.match?(previous).should be_true + @schedule.should be_match(previous) end it "should not match if the times are 23 hours and 58 minutes apart and the current hour is 23 and the current minute is 59" do @@ -232,7 +261,7 @@ describe Puppet::Type.type(:schedule) do now = previous + (23 * 3600) + (59 * 60) Time.stubs(:now).returns(now) - @schedule.match?(previous).should be_false + @schedule.should_not be_match(previous) end end @@ -249,7 +278,7 @@ describe Puppet::Type.type(:schedule) do Time.stubs(:now).returns(now) previous = Time.utc(2010, "nov", 6, 23, 59, 59) # Sat - @schedule.match?(previous).should be_true + @schedule.should be_match(previous) end it "should not match if the previous time is after the most recent Saturday" do @@ -257,7 +286,7 @@ describe Puppet::Type.type(:schedule) do Time.stubs(:now).returns(now) previous = Time.utc(2010, "nov", 7, 0, 0, 0) # Sunday - @schedule.match?(previous).should be_false + @schedule.should_not be_match(previous) end end @@ -274,7 +303,7 @@ describe Puppet::Type.type(:schedule) do Time.stubs(:now).returns(now) previous = Time.utc(2010, "oct", 31, 23, 59, 59) - @schedule.match?(previous).should be_true + @schedule.should be_match(previous) end it "should not match when the previous time is after the last day of last month" do @@ -282,7 +311,7 @@ describe Puppet::Type.type(:schedule) do Time.stubs(:now).returns(now) previous = Time.utc(2010, "nov", 1, 0, 0, 0) - @schedule.match?(previous).should be_false + @schedule.should_not be_match(previous) end end @@ -292,6 +321,8 @@ describe Puppet::Type.type(:schedule) do before do @schedule[:period] = :daily @schedule[:repeat] = 2 + + Time.stubs(:now).returns(Time.local(2011, "may", 23, 11, 0, 0)) end it "should fail if the periodmatch is 'number'" do @@ -301,12 +332,12 @@ describe Puppet::Type.type(:schedule) do it "should match if the previous run was further away than the distance divided by the repeat" do previous = Time.now - (3600 * 13) - @schedule.match?(previous).should be_true + @schedule.should be_match(previous) end it "should not match if the previous run was closer than the distance divided by the repeat" do previous = Time.now - (3600 * 11) - @schedule.match?(previous).should be_false + @schedule.should_not be_match(previous) end end end -- cgit