summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gemfile5
-rw-r--r--.travis.yml16
-rw-r--r--README.markdown7
-rw-r--r--Rakefile18
-rw-r--r--lib/facter/facter_dot_d.rb193
-rwxr-xr-xspec/lib/puppet_spec/files.rb53
-rwxr-xr-xspec/lib/puppet_spec/fixtures.rb28
-rw-r--r--spec/lib/puppet_spec/matchers.rb87
-rwxr-xr-xspec/lib/puppet_spec/verbose.rb9
-rw-r--r--spec/spec_helper.rb1
10 files changed, 30 insertions, 387 deletions
diff --git a/.gemfile b/.gemfile
new file mode 100644
index 0000000..9aad840
--- /dev/null
+++ b/.gemfile
@@ -0,0 +1,5 @@
+source :rubygems
+
+puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 2.7']
+gem 'puppet', puppetversion
+gem 'puppetlabs_spec_helper', '>= 0.1.0'
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..0ec5a08
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,16 @@
+language: ruby
+rvm:
+ - 1.8.7
+before_script:
+after_script:
+script: "rake spec_full"
+branches:
+ only:
+ - master
+env:
+ - PUPPET_VERSION=2.7.13
+ - PUPPET_VERSION=2.7.6
+ - PUPPET_VERSION=2.6.9
+notifications:
+ email: false
+gemfile: .gemfile
diff --git a/README.markdown b/README.markdown
index 9fa4c38..027c2d2 100644
--- a/README.markdown
+++ b/README.markdown
@@ -80,3 +80,10 @@ automatically. This is a direct copy of R.I. Pienaar's custom facter fact
located at:
[https://github.com/ripienaar/facter-facts/tree/master/facts-dot-d](https://github.com/ripienaar/facter-facts/tree/master/facts-dot-d)
+stdlib releases beyond 2.x will not include external fact support using
+facts-dot-d. Instead, these versions of stdlib require Facter 2.0 which
+includes external fact support in the main Facter codebase.
+
+Please see [2157](http://projects.puppetlabs.com/issues/2157) for more
+information.
+
diff --git a/Rakefile b/Rakefile
index 01b2a31..14f1c24 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,16 +1,2 @@
-require 'rake'
-require 'rspec/core/rake_task'
-
-task :default => [:test]
-
-desc 'Run RSpec'
-RSpec::Core::RakeTask.new(:test) do |t|
- t.pattern = 'spec/{unit}/**/*.rb'
- t.rspec_opts = ['--color']
-end
-
-desc 'Generate code coverage'
-RSpec::Core::RakeTask.new(:coverage) do |t|
- t.rcov = true
- t.rcov_opts = ['--exclude', 'spec']
-end
+require 'rubygems'
+require 'puppetlabs_spec_helper/rake_tasks'
diff --git a/lib/facter/facter_dot_d.rb b/lib/facter/facter_dot_d.rb
deleted file mode 100644
index c43801c..0000000
--- a/lib/facter/facter_dot_d.rb
+++ /dev/null
@@ -1,193 +0,0 @@
-# A Facter plugin that loads facts from /etc/facter/facts.d
-# and /etc/puppetlabs/facter/facts.d.
-#
-# Facts can be in the form of JSON, YAML or Text files
-# and any executable that returns key=value pairs.
-#
-# In the case of scripts you can also create a file that
-# contains a cache TTL. For foo.sh store the ttl as just
-# a number in foo.sh.ttl
-#
-# The cache is stored in /tmp/facts_cache.yaml as a mode
-# 600 file and will have the end result of not calling your
-# fact scripts more often than is needed
-
-class Facter::Util::DotD
- require 'yaml'
-
- def initialize(dir="/etc/facts.d", cache_file="/tmp/facts_cache.yml")
- @dir = dir
- @cache_file = cache_file
- @cache = nil
- @types = {".txt" => :txt, ".json" => :json, ".yaml" => :yaml}
- end
-
- def entries
- Dir.entries(@dir).reject{|f| f =~ /^\.|\.ttl$/}.sort.map {|f| File.join(@dir, f) }
- rescue
- []
- end
-
- def fact_type(file)
- extension = File.extname(file)
-
- type = @types[extension] || :unknown
-
- type = :script if type == :unknown && File.executable?(file)
-
- return type
- end
-
- def txt_parser(file)
- File.readlines(file).each do |line|
- if line =~ /^(.+)=(.+)$/
- var = $1; val = $2
-
- Facter.add(var) do
- setcode { val }
- end
- end
- end
- rescue Exception => e
- Facter.warn("Failed to handle #{file} as text facts: #{e.class}: #{e}")
- end
-
- def json_parser(file)
- begin
- require 'json'
- rescue LoadError
- retry if require 'rubygems'
- raise
- end
-
- JSON.load(File.read(file)).each_pair do |f, v|
- Facter.add(f) do
- setcode { v }
- end
- end
- rescue Exception => e
- Facter.warn("Failed to handle #{file} as json facts: #{e.class}: #{e}")
- end
-
- def yaml_parser(file)
- require 'yaml'
-
- YAML.load_file(file).each_pair do |f, v|
- Facter.add(f) do
- setcode { v }
- end
- end
- rescue Exception => e
- Facter.warn("Failed to handle #{file} as yaml facts: #{e.class}: #{e}")
- end
-
- def script_parser(file)
- result = cache_lookup(file)
- ttl = cache_time(file)
-
- unless result
- result = Facter::Util::Resolution.exec(file)
-
- if ttl > 0
- Facter.debug("Updating cache for #{file}")
- cache_store(file, result)
- cache_save!
- end
- else
- Puppet.deprecation_warning("TTL for external facts is being removed. See http://links.puppetlabs.com/factercaching for more information.")
- Facter.debug("Using cached data for #{file}")
- end
-
- result.split("\n").each do |line|
- if line =~ /^(.+)=(.+)$/
- var = $1; val = $2
-
- Facter.add(var) do
- setcode { val }
- end
- end
- end
- rescue Exception => e
- Facter.warn("Failed to handle #{file} as script facts: #{e.class}: #{e}")
- Facter.debug(e.backtrace.join("\n\t"))
- end
-
- def cache_save!
- cache = load_cache
- File.open(@cache_file, "w", 0600) {|f| f.write(YAML.dump(cache)) }
- rescue
- end
-
- def cache_store(file, data)
- load_cache
-
- @cache[file] = {:data => data, :stored => Time.now.to_i}
- rescue
- end
-
- def cache_lookup(file)
- cache = load_cache
-
- return nil if cache.empty?
-
- ttl = cache_time(file)
-
- if cache[file]
- now = Time.now.to_i
-
- return cache[file][:data] if ttl == -1
- return cache[file][:data] if (now - cache[file][:stored]) <= ttl
- return nil
- else
- return nil
- end
- rescue
- return nil
- end
-
- def cache_time(file)
- meta = file + ".ttl"
-
- return File.read(meta).chomp.to_i
- rescue
- return 0
- end
-
- def load_cache
- unless @cache
- if File.exist?(@cache_file)
- @cache = YAML.load_file(@cache_file)
- else
- @cache = {}
- end
- end
-
- return @cache
- rescue
- @cache = {}
- return @cache
- end
-
- def create
- entries.each do |fact|
- type = fact_type(fact)
- parser = "#{type}_parser"
-
- if respond_to?("#{type}_parser")
- Facter.debug("Parsing #{fact} using #{parser}")
-
- send(parser, fact)
- end
- end
- end
-end
-
-Facter::Util::DotD.new("/etc/facter/facts.d").create
-Facter::Util::DotD.new("/etc/puppetlabs/facter/facts.d").create
-
-# Windows has a different configuration directory that defaults to a vendor
-# specific sub directory of the %COMMON_APPDATA% directory.
-if Dir.const_defined? 'COMMON_APPDATA' then
- windows_facts_dot_d = File.join(Dir::COMMON_APPDATA, 'PuppetLabs', 'facter', 'facts.d')
- Facter::Util::DotD.new(windows_facts_dot_d).create
-end
diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb
deleted file mode 100755
index 30fb4fc..0000000
--- a/spec/lib/puppet_spec/files.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-require 'fileutils'
-require 'tempfile'
-
-# A support module for testing files.
-module PuppetSpec::Files
- # This code exists only to support tests that run as root, pretty much.
- # Once they have finally been eliminated this can all go... --daniel 2011-04-08
- if Puppet.features.posix? then
- def self.in_tmp(path)
- path =~ /^\/tmp/ or path =~ /^\/var\/folders/
- end
- elsif Puppet.features.microsoft_windows?
- def self.in_tmp(path)
- tempdir = File.expand_path(File.join(Dir::LOCAL_APPDATA, "Temp"))
- path =~ /^#{tempdir}/
- end
- else
- fail "Help! Can't find in_tmp for this platform"
- end
-
- def self.cleanup
- $global_tempfiles ||= []
- while path = $global_tempfiles.pop do
- fail "Not deleting tmpfile #{path} outside regular tmpdir" unless in_tmp(path)
-
- begin
- FileUtils.rm_r path, :secure => true
- rescue Errno::ENOENT
- # nothing to do
- end
- end
- end
-
- def tmpfile(name)
- # Generate a temporary file, just for the name...
- source = Tempfile.new(name)
- path = source.path
- source.close!
-
- # ...record it for cleanup,
- $global_tempfiles ||= []
- $global_tempfiles << File.expand_path(path)
-
- # ...and bam.
- path
- end
-
- def tmpdir(name)
- path = tmpfile(name)
- FileUtils.mkdir_p(path)
- path
- end
-end
diff --git a/spec/lib/puppet_spec/fixtures.rb b/spec/lib/puppet_spec/fixtures.rb
deleted file mode 100755
index 7f6bc2a..0000000
--- a/spec/lib/puppet_spec/fixtures.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-module PuppetSpec::Fixtures
- def fixtures(*rest)
- File.join(PuppetSpec::FIXTURE_DIR, *rest)
- end
- def my_fixture_dir
- callers = caller
- while line = callers.shift do
- next unless found = line.match(%r{/spec/(.*)_spec\.rb:})
- return fixtures(found[1])
- end
- fail "sorry, I couldn't work out your path from the caller stack!"
- end
- def my_fixture(name)
- file = File.join(my_fixture_dir, name)
- unless File.readable? file then
- fail Puppet::DevError, "fixture '#{name}' for #{my_fixture_dir} is not readable"
- end
- return file
- end
- def my_fixtures(glob = '*', flags = 0)
- files = Dir.glob(File.join(my_fixture_dir, glob), flags)
- unless files.length > 0 then
- fail Puppet::DevError, "fixture '#{glob}' for #{my_fixture_dir} had no files!"
- end
- block_given? and files.each do |file| yield file end
- files
- end
-end
diff --git a/spec/lib/puppet_spec/matchers.rb b/spec/lib/puppet_spec/matchers.rb
deleted file mode 100644
index 77f5803..0000000
--- a/spec/lib/puppet_spec/matchers.rb
+++ /dev/null
@@ -1,87 +0,0 @@
-require 'stringio'
-
-########################################################################
-# Backward compatibility for Jenkins outdated environment.
-module RSpec
- module Matchers
- module BlockAliases
- alias_method :to, :should unless method_defined? :to
- alias_method :to_not, :should_not unless method_defined? :to_not
- alias_method :not_to, :should_not unless method_defined? :not_to
- end
- end
-end
-
-
-########################################################################
-# Custom matchers...
-RSpec::Matchers.define :have_matching_element do |expected|
- match do |actual|
- actual.any? { |item| item =~ expected }
- end
-end
-
-
-RSpec::Matchers.define :exit_with do |expected|
- actual = nil
- match do |block|
- begin
- block.call
- rescue SystemExit => e
- actual = e.status
- end
- actual and actual == expected
- end
- failure_message_for_should do |block|
- "expected exit with code #{expected} but " +
- (actual.nil? ? " exit was not called" : "we exited with #{actual} instead")
- end
- failure_message_for_should_not do |block|
- "expected that exit would not be called with #{expected}"
- end
- description do
- "expect exit with #{expected}"
- end
-end
-
-
-RSpec::Matchers.define :have_printed do |expected|
- match do |block|
- $stderr = $stdout = StringIO.new
-
- begin
- block.call
- ensure
- $stdout.rewind
- @actual = $stdout.read
-
- $stdout = STDOUT
- $stderr = STDERR
- end
-
- if @actual then
- case expected
- when String
- @actual.include? expected
- when Regexp
- expected.match @actual
- else
- raise ArgumentError, "No idea how to match a #{@actual.class.name}"
- end
- end
- end
-
- failure_message_for_should do |actual|
- if actual.nil? then
- "expected #{expected.inspect}, but nothing was printed"
- else
- "expected #{expected.inspect} to be printed; got:\n#{actual}"
- end
- end
-
- description do
- "expect #{expected.inspect} to be printed"
- end
-
- diffable
-end
diff --git a/spec/lib/puppet_spec/verbose.rb b/spec/lib/puppet_spec/verbose.rb
deleted file mode 100755
index d9834f2..0000000
--- a/spec/lib/puppet_spec/verbose.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-# Support code for running stuff with warnings disabled.
-module Kernel
- def with_verbose_disabled
- verbose, $VERBOSE = $VERBOSE, nil
- result = yield
- $VERBOSE = verbose
- return result
- end
-end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 8ae9ad3..e269b90 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -11,4 +11,3 @@ gem 'rspec', '>=2.0.0'
require 'rspec/expectations'
require 'puppetlabs_spec_helper/module_spec_helper'
-