wearetherobots | 1 Oct 2011 01:45

(puppetlabs/puppet-dashboard) New pull request: (#9366) allows version link to be customized

Greetings!

Please review the pull request #36: (#9366) allows version link to be customized opened by (djsauble2)

Some more information about the pull request:

  • Opened: Fri Sep 30 23:45:08 UTC 2011
  • Based on: puppetlabs:master (e1e949222f95bf0468947eb6fdc480396b543e73)
  • Requested merge: djsauble2:9366_custom_version_link (9ed1c19a41350cc4afecfde1f162a5134bd514f1)

Description:

When a 'VERSION_LINK' file is found in the root of the app, the
contents are read and used as a custom URL for the version link
in the header.

This behavior is similar to when a 'VERSION' file is found in
the root. If the file is missing--and the app is a git checkout,
a link to the current changelog version on github is constructed.

Thanks!
The Pull Request Bot

Diff follows:

diff --git a/app/views/shared/_global_nav.html.haml b/app/views/shared/_global_nav.html.haml index a00cd6c..791c084 100644 --- a/app/views/shared/_global_nav.html.haml +++ b/app/views/shared/_global_nav.html.haml <at> <at> -9,7 +9,7 <at> <at> - css << "width: #{SETTINGS.custom_logo_width}" %a{:href => root_path, :title => SETTINGS.custom_logo_alt_text, :style => css.join('; ')} Puppet Dashboard %li#dashboard-version{:class => active_if(request.url == release_notes_url)} - = link_to APP_VERSION, "https://github.com/puppetlabs/puppet-dashboard/blob/#{APP_VERSION.sub(/.*?g([0-9a-f]*)/, "\\1")}/CHANGELOG" + = link_to APP_VERSION, APP_VERSION_LINK %li{:class => active_if(request.url == root_url)} = link_to "Home", root_path %li{:class => active_if(controller_name == "nodes" && action_name == "index")} diff --git a/config/initializers/app_version_init.rb b/config/initializers/app_version_init.rb index 91409c5..0bb987e 100644 --- a/config/initializers/app_version_init.rb +++ b/config/initializers/app_version_init.rb <at> <at> -16,4 +16,13 <at> <at> def get_app_version 'unknown' end +def get_app_version_link + if File.exists?(Rails.root.join('VERSION_LINK')) + return File.read(Rails.root.join('VERSION_LINK')).strip + elsif File.directory?(Rails.root.join('.git')) + return "https://github.com/puppetlabs/puppet-dashboard/blob/#{APP_VERSION.sub(/.*?g([0-9a-f]*)/, "\\1")}/CHANGELOG" + end +end + APP_VERSION = get_app_version +APP_VERSION_LINK = get_app_version_link

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to puppet-dev <at> googlegroups.com.
To unsubscribe from this group, send email to puppet-dev+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
wearetherobots | 1 Oct 2011 02:15

(puppetlabs/puppet) Closed pull request: Bug/2.7.x/9832 storeconfigs postgresql regression

Greetings!

On Sat Oct 01 00:12:33 UTC 2011 pull request #147 was closed.

Bug/2.7.x/9832 storeconfigs postgresql regression requested by (daniel-pittman)

The pull request was merged by: daniel-pittman

Thanks!
The Pull Request Bot

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to puppet-dev <at> googlegroups.com.
To unsubscribe from this group, send email to puppet-dev+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
wearetherobots | 1 Oct 2011 03:00

(puppetlabs/facter) New pull request: Ticket/9555 fix whitespace

Greetings!

Please review the pull request #74: Ticket/9555 fix whitespace opened by (kbarber)

Some more information about the pull request:

  • Opened: Sat Oct 01 00:52:24 UTC 2011
  • Based on: puppetlabs:1.6.x (6ff4d3e62bddd3450228559dbfa50a48099f073d)
  • Requested merge: kbarber:ticket/9555-fix_whitespace (abf636e3cff0990d40d9402549014c68ac04b7da)

Description:

(#9555) Change all cases of tabs and 4 space indentation to 2 space indentation.

Since 2 space indentation seems to be Puppets (and the ruby communities)
standard this patch converts all incorrect indentation to 2 spaces.

The fact that we were mixing the indentation was causing people to mix them
within files - sometimes using 4 space, sometimes 2 space. This single change
makes it consistent across all the code.

Thanks!
The Pull Request Bot

Diff follows:

diff --git a/Rakefile b/Rakefile index 5b0d072..380416b 100644 --- a/Rakefile +++ b/Rakefile <at> <at> -7,7 +7,7 <at> <at> require 'rubygems' require 'rspec' require 'rspec/core/rake_task' begin - require 'rcov' + require 'rcov' rescue LoadError end <at> <at> -18,48 +18,48 <at> <at> require 'rake/packagetask' require 'rake/gempackagetask' module Facter - FACTERVERSION = File.read('lib/facter.rb')[/FACTERVERSION *= *'(.*)'/,1] or fail "Couldn't find FACTERVERSION" + FACTERVERSION = File.read('lib/facter.rb')[/FACTERVERSION *= *'(.*)'/,1] or fail "Couldn't find FACTERVERSION" end FILES = FileList[ - '[A-Z]*', - 'install.rb', - 'bin/**/*', - 'lib/**/*', - 'conf/**/*', - 'etc/**/*', - 'spec/**/*' + '[A-Z]*', + 'install.rb', + 'bin/**/*', + 'lib/**/*', + 'conf/**/*', + 'etc/**/*', + 'spec/**/*' ] spec = Gem::Specification.new do |spec| - spec.platform = Gem::Platform::RUBY - spec.name = 'facter' - spec.files = FILES.to_a - spec.executables = %w{facter} - spec.version = Facter::FACTERVERSION - spec.summary = 'Facter, a system inventory tool' - spec.author = 'Puppet Labs' - spec.email = 'info <at> puppetlabs.com' - spec.homepage = 'http://puppetlabs.com' - spec.rubyforge_project = 'facter' - spec.has_rdoc = true - spec.rdoc_options << - '--title' << 'Facter - System Inventory Tool' << - '--main' << 'README' << - '--line-numbers' + spec.platform = Gem::Platform::RUBY + spec.name = 'facter' + spec.files = FILES.to_a + spec.executables = %w{facter} + spec.version = Facter::FACTERVERSION + spec.summary = 'Facter, a system inventory tool' + spec.author = 'Puppet Labs' + spec.email = 'info <at> puppetlabs.com' + spec.homepage = 'http://puppetlabs.com' + spec.rubyforge_project = 'facter' + spec.has_rdoc = true + spec.rdoc_options << + '--title' << 'Facter - System Inventory Tool' << + '--main' << 'README' << + '--line-numbers' end Rake::PackageTask.new("facter", Facter::FACTERVERSION) do |pkg| - pkg.package_dir = 'pkg' - pkg.need_tar_gz = true - pkg.package_files = FILES.to_a + pkg.package_dir = 'pkg' + pkg.need_tar_gz = true + pkg.package_files = FILES.to_a end Rake::GemPackageTask.new(spec) do |pkg| end task :default do - sh %{rake -T} + sh %{rake -T} end # Aliases for spec <at> <at> -68,15 +68,15 <at> <at> task :tests => [:spec] task :specs => [:spec] RSpec::Core::RakeTask.new do |t| - t.pattern ='spec/{unit,integration}/**/*_spec.rb' - t.fail_on_error = true + t.pattern ='spec/{unit,integration}/**/*_spec.rb' + t.fail_on_error = true end RSpec::Core::RakeTask.new('spec:rcov') do |t| - t.pattern ='spec/{unit,integration}/**/*_spec.rb' - t.fail_on_error = true - if defined?(Rcov) - t.rcov = true - t.rcov_opts = ['--exclude', 'spec/*,test/*,results/*,/usr/lib/*,/usr/local/lib/*,gems/*'] - end + t.pattern ='spec/{unit,integration}/**/*_spec.rb' + t.fail_on_error = true + if defined?(Rcov) + t.rcov = true + t.rcov_opts = ['--exclude', 'spec/*,test/*,results/*,/usr/lib/*,/usr/local/lib/*,gems/*'] + end end diff --git a/acceptance/tests/ticket_7039_facter_multiple_facts_one_file.rb b/acceptance/tests/ticket_7039_facter_multiple_facts_one_file.rb index fb78628..76da065 100644 --- a/acceptance/tests/ticket_7039_facter_multiple_facts_one_file.rb +++ b/acceptance/tests/ticket_7039_facter_multiple_facts_one_file.rb <at> <at> -2,15 +2,15 <at> <at> test_name "#7039: Facter having issue handling multiple facts in a single file" fact_file= %q{ Facter.add(:test_fact1) do - setcode do - "test fact 1" - end + setcode do + "test fact 1" + end end Facter.add(:test_fact2) do - setcode do - "test fact 2" - end + setcode do + "test fact 2" + end end } <at> <at> -20,12 +20,12 <at> <at> create_remote_file(agent1, '/tmp/test_facts.rb', fact_file ) step "Agent: Verify test_fact1 from /tmp/test_facts.rb" on(agent1, "export FACTERLIB=/tmp && facter --puppet test_fact1") do - fail_test "Fact 1 not returned by facter --puppet test_fact1" unless - stdout.include? 'test fact 1' + fail_test "Fact 1 not returned by facter --puppet test_fact1" unless + stdout.include? 'test fact 1' end step "Agent: Verify test_fact2 from /tmp/test_facts.rb" on(agent1, "export FACTERLIB=/tmp && facter --puppet test_fact2") do - fail_test "Fact 1 not returned by facter --puppet test_fact2" unless - stdout.include? 'test fact 2' + fail_test "Fact 1 not returned by facter --puppet test_fact2" unless + stdout.include? 'test fact 2' end diff --git a/documentation/custom.page b/documentation/custom.page index 0708a70..991071c 100644 --- a/documentation/custom.page +++ b/documentation/custom.page <at> <at> -12,10 +12,10 <at> <at> search through your environment for any variables whose names start with As a simple example, here is how I publish my home directory to Puppet: Facter.add("home") do - setcode do - ENV['HOME'] - end - end + setcode do + ENV['HOME'] + end + end I have ~/lib/ruby in my $RUBYLIB environment variable, so I just created ~/lib/ruby/facter and dropped the above code into a ``home.rb`` file diff --git a/install.rb b/install.rb index 37154ba..a1a3884 100755 --- a/install.rb +++ b/install.rb <at> <at> -12,23 +12,23 <at> <at> # In most cases, if you have a typical project layout, you will need to do # absolutely nothing to make this work for you. This layout is: # -# bin/ # executable files -- "commands" -# lib/ # the source of the library +# bin/ # executable files -- "commands" +# lib/ # the source of the library # tests/ # unit tests # # The default behaviour: # 1) Run all unit test files (ending in .rb) found in all directories under -# tests/. +# tests/. # 2) Build Rdoc documentation from all files in bin/ (excluding .bat and .cmd), -# all .rb files in lib/, ./README, ./ChangeLog, and ./Install. +# all .rb files in lib/, ./README, ./ChangeLog, and ./Install. # 3) Build ri documentation from all files in bin/ (excluding .bat and .cmd), -# and all .rb files in lib/. This is disabled by default on Win32. +# and all .rb files in lib/. This is disabled by default on Win32. # 4) Install commands from bin/ into the Ruby bin directory. On Windows, if a -# if a corresponding batch file (.bat or .cmd) exists in the bin directory, -# it will be copied over as well. Otherwise, a batch file (always .bat) will -# be created to run the specified command. +# if a corresponding batch file (.bat or .cmd) exists in the bin directory, +# it will be copied over as well. Otherwise, a batch file (always .bat) will +# be created to run the specified command. # 5) Install all library files ending in .rb from lib/ into Ruby's -# site_lib/version directory. +# site_lib/version directory. # #++ <at> <at> -39,23 +39,23 <at> <at> require 'optparse' require 'ostruct' begin - require 'rdoc/rdoc' - $haverdoc = true + require 'rdoc/rdoc' + $haverdoc = true rescue LoadError - puts "Missing rdoc; skipping documentation" - $haverdoc = false + puts "Missing rdoc; skipping documentation" + $haverdoc = false end begin - if $haverdoc - rst2man = %x{which rst2man.py} - $haveman = true - else - $haveman = false - end + if $haverdoc + rst2man = %x{which rst2man.py} + $haveman = true + else + $haveman = false + end rescue - puts "Missing rst2man; skipping man page creation" - $haveman = false + puts "Missing rst2man; skipping man page creation" + $haveman = false end $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib') <at> <at> -67,66 +67,66 <at> <at> PREREQS = %w{openssl xmlrpc/client xmlrpc/server cgi} InstallOptions = OpenStruct.new def glob(list) - g = list.map { |i| Dir.glob(i) } - g.flatten! - g.compact! - g.reject! { |e| e =~ /\.svn/ } - g + g = list.map { |i| Dir.glob(i) } + g.flatten! + g.compact! + g.reject! { |e| e =~ /\.svn/ } + g end # Set these values to what you want installed. sbins = glob(%w{sbin/*}) bins = glob(%w{bin/*}) rdoc = glob(%w{bin/* sbin/* lib/**/*.rb README README-library CHANGELOG TODO Install}).reject { |e| e=~ /\.(bat|cmd)$/ } -ri = glob(%w(bin/*.rb sbin/* lib/**/*.rb)).reject { |e| e=~ /\.(bat|cmd)$/ } +ri = glob(%w(bin/*.rb sbin/* lib/**/*.rb)).reject { |e| e=~ /\.(bat|cmd)$/ } man = glob(%w{man/man8/*}) libs = glob(%w{lib/**/*.rb lib/**/*.py}) tests = glob(%w{tests/**/*.rb}) def do_bins(bins, target, strip = 's?bin/') - bins.each do |bf| - obf = bf.gsub(/#{strip}/, '') - install_binfile(bf, obf, target) - end + bins.each do |bf| + obf = bf.gsub(/#{strip}/, '') + install_binfile(bf, obf, target) + end end def do_libs(libs, strip = 'lib/') - libs.each do |lf| - olf = File.join(InstallOptions.site_dir, lf.gsub(/#{strip}/, '')) - op = File.dirname(olf) - FileUtils.makedirs(op, {:mode => 0755, :verbose => true}) - FileUtils.chmod(0755, op) - FileUtils.install(lf, olf, {:mode => 0644, :verbose => true}) - end + libs.each do |lf| + olf = File.join(InstallOptions.site_dir, lf.gsub(/#{strip}/, '')) + op = File.dirname(olf) + FileUtils.makedirs(op, {:mode => 0755, :verbose => true}) + FileUtils.chmod(0755, op) + FileUtils.install(lf, olf, {:mode => 0644, :verbose => true}) + end end def do_man(man, strip = 'man/') if (InstallOptions.man == true) - man.each do |mf| - omf = File.join(InstallOptions.man_dir, mf.gsub(/#{strip}/, '')) - om = File.dirname(omf) - FileUtils.makedirs(om, {:mode => 0755, :verbose => true}) - FileUtils.chmod(0755, om) - FileUtils.install(mf, omf, {:mode => 0644, :verbose => true}) - gzip = %x{which gzip} - gzip.chomp! - %x{#{gzip} -f #{omf}} - end + man.each do |mf| + omf = File.join(InstallOptions.man_dir, mf.gsub(/#{strip}/, '')) + om = File.dirname(omf) + FileUtils.makedirs(om, {:mode => 0755, :verbose => true}) + FileUtils.chmod(0755, om) + FileUtils.install(mf, omf, {:mode => 0644, :verbose => true}) + gzip = %x{which gzip} + gzip.chomp! + %x{#{gzip} -f #{omf}} + end else - puts "Skipping Man Page Generation" + puts "Skipping Man Page Generation" end end # Verify that all of the prereqs are installed def check_prereqs - PREREQS.each { |pre| - begin - require pre - rescue LoadError - puts "Could not load #{pre} Ruby library; cannot install" - exit -1 - end - } + PREREQS.each { |pre| + begin + require pre + rescue LoadError + puts "Could not load #{pre} Ruby library; cannot install" + exit -1 + end + } end def is_windows? <at> <at> -137,160 +137,160 <at> <at> end # Prepare the file installation. # def prepare_installation - # Only try to do docs if we're sure they have rdoc - if $haverdoc - InstallOptions.rdoc = true - if is_windows? - InstallOptions.ri = false - else - InstallOptions.ri = true - end + # Only try to do docs if we're sure they have rdoc + if $haverdoc + InstallOptions.rdoc = true + if is_windows? + InstallOptions.ri = false else - InstallOptions.rdoc = false - InstallOptions.ri = false + InstallOptions.ri = true end + else + InstallOptions.rdoc = false + InstallOptions.ri = false + end - if $haveman - InstallOptions.man = true - if is_windows? - InstallOptions.man = false - end - else - InstallOptions.man = false + if $haveman + InstallOptions.man = true + if is_windows? + InstallOptions.man = false end + else + InstallOptions.man = false + end + + InstallOptions.tests = true - InstallOptions.tests = true - - ARGV.options do |opts| - opts.banner = "Usage: #{File.basename($0)} [options]" - opts.separator "" - opts.on('--[no-]rdoc', 'Prevents the creation of RDoc output.', 'Default on.') do |onrdoc| - InstallOptions.rdoc = onrdoc - end - opts.on('--[no-]ri', 'Prevents the creation of RI output.', 'Default off on mswin32.') do |onri| - InstallOptions.ri = onri - end - opts.on('--[no-]man', 'Presents the creation of man pages.', 'Default on.') do |onman| - InstallOptions.man = onman - end - opts.on('--[no-]tests', 'Prevents the execution of unit tests.', 'Default on.') do |ontest| - InstallOptions.tests = ontest - end - opts.on('--destdir[=OPTIONAL]', 'Installation prefix for all targets', 'Default essentially /') do |destdir| - InstallOptions.destdir = destdir - end - opts.on('--bindir[=OPTIONAL]', 'Installation directory for binaries', 'overrides Config::CONFIG["bindir"]') do |bindir| - InstallOptions.bindir = bindir - end - opts.on('--sbindir[=OPTIONAL]', 'Installation directory for system binaries', 'overrides Config::CONFIG["sbindir"]') do |sbindir| - InstallOptions.sbindir = sbindir - end - opts.on('--sitelibdir[=OPTIONAL]', 'Installation directory for libraries', 'overrides Config::CONFIG["sitelibdir"]') do |sitelibdir| - InstallOptions.sitelibdir = sitelibdir - end - opts.on('--mandir[=OPTIONAL]', 'Installation directory for man pages', 'overrides Config::CONFIG["mandir"]') do |mandir| - InstallOptions.mandir = mandir - end - opts.on('--quick', 'Performs a quick installation. Only the', 'installation is done.') do |quick| - InstallOptions.rdoc = false - InstallOptions.ri = false - InstallOptions.tests = false - end - opts.on('--full', 'Performs a full installation. All', 'optional installation steps are run.') do |full| - InstallOptions.rdoc = true - InstallOptions.ri = true - InstallOptions.tests = true - end - opts.separator("") - opts.on_tail('--help', "Shows this help text.") do - $stderr.puts opts - exit - end - - opts.parse! + ARGV.options do |opts| + opts.banner = "Usage: #{File.basename($0)} [options]" + opts.separator "" + opts.on('--[no-]rdoc', 'Prevents the creation of RDoc output.', 'Default on.') do |onrdoc| + InstallOptions.rdoc = onrdoc + end + opts.on('--[no-]ri', 'Prevents the creation of RI output.', 'Default off on mswin32.') do |onri| + InstallOptions.ri = onri + end + opts.on('--[no-]man', 'Presents the creation of man pages.', 'Default on.') do |onman| + InstallOptions.man = onman + end + opts.on('--[no-]tests', 'Prevents the execution of unit tests.', 'Default on.') do |ontest| + InstallOptions.tests = ontest + end + opts.on('--destdir[=OPTIONAL]', 'Installation prefix for all targets', 'Default essentially /') do |destdir| + InstallOptions.destdir = destdir + end + opts.on('--bindir[=OPTIONAL]', 'Installation directory for binaries', 'overrides Config::CONFIG["bindir"]') do |bindir| + InstallOptions.bindir = bindir + end + opts.on('--sbindir[=OPTIONAL]', 'Installation directory for system binaries', 'overrides Config::CONFIG["sbindir"]') do |sbindir| + InstallOptions.sbindir = sbindir + end + opts.on('--sitelibdir[=OPTIONAL]', 'Installation directory for libraries', 'overrides Config::CONFIG["sitelibdir"]') do |sitelibdir| + InstallOptions.sitelibdir = sitelibdir + end + opts.on('--mandir[=OPTIONAL]', 'Installation directory for man pages', 'overrides Config::CONFIG["mandir"]') do |mandir| + InstallOptions.mandir = mandir + end + opts.on('--quick', 'Performs a quick installation. Only the', 'installation is done.') do |quick| + InstallOptions.rdoc = false + InstallOptions.ri = false + InstallOptions.tests = false + end + opts.on('--full', 'Performs a full installation. All', 'optional installation steps are run.') do |full| + InstallOptions.rdoc = true + InstallOptions.ri = true + InstallOptions.tests = true + end + opts.separator("") + opts.on_tail('--help', "Shows this help text.") do + $stderr.puts opts + exit end - tmpdirs = [ENV['TMP'], ENV['TEMP'], "/tmp", "/var/tmp", "."] + opts.parse! + end - version = [Config::CONFIG["MAJOR"], Config::CONFIG["MINOR"]].join(".") - libdir = File.join(Config::CONFIG["libdir"], "ruby", version) + tmpdirs = [ENV['TMP'], ENV['TEMP'], "/tmp", "/var/tmp", "."] - # Mac OS X 10.5 and higher declare bindir and sbindir as - # /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin - # /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/sbin - # which is not generally where people expect executables to be installed - # These settings are appropriate defaults for all OS X versions. - if RUBY_PLATFORM =~ /^universal-darwin[\d\.]+$/ - Config::CONFIG['bindir'] = "/usr/bin" - Config::CONFIG['sbindir'] = "/usr/sbin" - end + version = [Config::CONFIG["MAJOR"], Config::CONFIG["MINOR"]].join(".") + libdir = File.join(Config::CONFIG["libdir"], "ruby", version) - if not InstallOptions.bindir.nil? - bindir = InstallOptions.bindir - else - bindir = Config::CONFIG['bindir'] - end + # Mac OS X 10.5 and higher declare bindir and sbindir as + # /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin + # /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/sbin + # which is not generally where people expect executables to be installed + # These settings are appropriate defaults for all OS X versions. + if RUBY_PLATFORM =~ /^universal-darwin[\d\.]+$/ + Config::CONFIG['bindir'] = "/usr/bin" + Config::CONFIG['sbindir'] = "/usr/sbin" + end - if not InstallOptions.sbindir.nil? - sbindir = InstallOptions.sbindir - else - sbindir = Config::CONFIG['sbindir'] - end + if not InstallOptions.bindir.nil? + bindir = InstallOptions.bindir + else + bindir = Config::CONFIG['bindir'] + end - if not InstallOptions.sitelibdir.nil? - sitelibdir = InstallOptions.sitelibdir - else - sitelibdir = Config::CONFIG["sitelibdir"] - if sitelibdir.nil? - sitelibdir = $:.find { |x| x =~ /site_ruby/ } - if sitelibdir.nil? - sitelibdir = File.join(libdir, "site_ruby") - elsif sitelibdir !~ Regexp.quote(version) - sitelibdir = File.join(sitelibdir, version) - end - end - end + if not InstallOptions.sbindir.nil? + sbindir = InstallOptions.sbindir + else + sbindir = Config::CONFIG['sbindir'] + end - if not InstallOptions.mandir.nil? - mandir = InstallOptions.mandir - else - mandir = Config::CONFIG['mandir'] + if not InstallOptions.sitelibdir.nil? + sitelibdir = InstallOptions.sitelibdir + else + sitelibdir = Config::CONFIG["sitelibdir"] + if sitelibdir.nil? + sitelibdir = $:.find { |x| x =~ /site_ruby/ } + if sitelibdir.nil? + sitelibdir = File.join(libdir, "site_ruby") + elsif sitelibdir !~ Regexp.quote(version) + sitelibdir = File.join(sitelibdir, version) + end end + end - # To be deprecated once people move over to using --destdir option - if (destdir = ENV['DESTDIR']) - warn "DESTDIR is deprecated. Use --destdir instead." - bindir = join(destdir, bindir) - sbindir = join(destdir, sbindir) - mandir = join(destdir, mandir) - sitelibdir = join(destdir, sitelibdir) - - FileUtils.makedirs(bindir) - FileUtils.makedirs(sbindir) - FileUtils.makedirs(mandir) - FileUtils.makedirs(sitelibdir) - # This is the new way forward - elsif (destdir = InstallOptions.destdir) - bindir = join(destdir, bindir) - sbindir = join(destdir, sbindir) - mandir = join(destdir, mandir) - sitelibdir = join(destdir, sitelibdir) - - FileUtils.makedirs(bindir) - FileUtils.makedirs(sbindir) - FileUtils.makedirs(mandir) - FileUtils.makedirs(sitelibdir) - end + if not InstallOptions.mandir.nil? + mandir = InstallOptions.mandir + else + mandir = Config::CONFIG['mandir'] + end + + # To be deprecated once people move over to using --destdir option + if (destdir = ENV['DESTDIR']) + warn "DESTDIR is deprecated. Use --destdir instead." + bindir = join(destdir, bindir) + sbindir = join(destdir, sbindir) + mandir = join(destdir, mandir) + sitelibdir = join(destdir, sitelibdir) + + FileUtils.makedirs(bindir) + FileUtils.makedirs(sbindir) + FileUtils.makedirs(mandir) + FileUtils.makedirs(sitelibdir) + # This is the new way forward + elsif (destdir = InstallOptions.destdir) + bindir = join(destdir, bindir) + sbindir = join(destdir, sbindir) + mandir = join(destdir, mandir) + sitelibdir = join(destdir, sitelibdir) + + FileUtils.makedirs(bindir) + FileUtils.makedirs(sbindir) + FileUtils.makedirs(mandir) + FileUtils.makedirs(sitelibdir) + end - tmpdirs << bindir + tmpdirs << bindir - InstallOptions.tmp_dirs = tmpdirs.compact - InstallOptions.site_dir = sitelibdir - InstallOptions.bin_dir = bindir - InstallOptions.sbin_dir = sbindir - InstallOptions.lib_dir = libdir - InstallOptions.man_dir = mandir + InstallOptions.tmp_dirs = tmpdirs.compact + InstallOptions.site_dir = sitelibdir + InstallOptions.bin_dir = bindir + InstallOptions.sbin_dir = sbindir + InstallOptions.lib_dir = libdir + InstallOptions.man_dir = mandir end ## <at> <at> -307,69 +307,69 <at> <at> end # Build the rdoc documentation. Also, try to build the RI documentation. # def build_rdoc(files) - return unless $haverdoc - begin - r = RDoc::RDoc.new - r.document(["--main", "README", "--title", - "Puppet -- Site Configuration Management", "--line-numbers"] + files) - rescue RDoc::RDocError => e - $stderr.puts e.message - rescue Exception => e - $stderr.puts "Couldn't build RDoc documentation\n#{e.message}" - end + return unless $haverdoc + begin + r = RDoc::RDoc.new + r.document(["--main", "README", "--title", + "Puppet -- Site Configuration Management", "--line-numbers"] + files) + rescue RDoc::RDocError => e + $stderr.puts e.message + rescue Exception => e + $stderr.puts "Couldn't build RDoc documentation\n#{e.message}" + end end def build_ri(files) - return unless $haverdoc - begin - ri = RDoc::RDoc.new - #ri.document(["--ri-site", "--merge"] + files) - ri.document(["--ri-site"] + files) - rescue RDoc::RDocError => e - $stderr.puts e.message - rescue Exception => e - $stderr.puts "Couldn't build Ri documentation\n#{e.message}" - $stderr.puts "Continuing with install..." - end + return unless $haverdoc + begin + ri = RDoc::RDoc.new + #ri.document(["--ri-site", "--merge"] + files) + ri.document(["--ri-site"] + files) + rescue RDoc::RDocError => e + $stderr.puts e.message + rescue Exception => e + $stderr.puts "Couldn't build Ri documentation\n#{e.message}" + $stderr.puts "Continuing with install..." + end end def build_man(bins) - return unless $haveman - begin - # Locate rst2man - rst2man = %x{which rst2man.py} - rst2man.chomp! - bins.each do |bin| - b = bin.gsub( "bin/", "") - %x{#{bin} --help > ./#{b}.rst} - %x{#{rst2man} ./#{b}.rst ./man/man8/#{b}.8} - File.unlink("./#{b}.rst") - end - rescue SystemCallError - $stderr.puts "Couldn't build man pages: " + $! - $stderr.puts "Continuing with install..." + return unless $haveman + begin + # Locate rst2man + rst2man = %x{which rst2man.py} + rst2man.chomp! + bins.each do |bin| + b = bin.gsub( "bin/", "") + %x{#{bin} --help > ./#{b}.rst} + %x{#{rst2man} ./#{b}.rst ./man/man8/#{b}.8} + File.unlink("./#{b}.rst") end + rescue SystemCallError + $stderr.puts "Couldn't build man pages: " + $! + $stderr.puts "Continuing with install..." + end end def run_tests(test_list) - begin - require 'test/unit/ui/console/testrunner' - $:.unshift "lib" - test_list.each do |test| - next if File.directory?(test) - require test - end - - tests = [] - ObjectSpace.each_object { |o| tests << o if o.kind_of?(Class) } - tests.delete_if { |o| !o.ancestors.include?(Test::Unit::TestCase) } - tests.delete_if { |o| o == Test::Unit::TestCase } - - tests.each { |test| Test::Unit::UI::Console::TestRunner.run(test) } - $:.shift - rescue LoadError - puts "Missing testrunner library; skipping tests" + begin + require 'test/unit/ui/console/testrunner' + $:.unshift "lib" + test_list.each do |test| + next if File.directory?(test) + require test end + + tests = [] + ObjectSpace.each_object { |o| tests << o if o.kind_of?(Class) } + tests.delete_if { |o| !o.ancestors.include?(Test::Unit::TestCase) } + tests.delete_if { |o| o == Test::Unit::TestCase } + + tests.each { |test| Test::Unit::UI::Console::TestRunner.run(test) } + $:.shift + rescue LoadError + puts "Missing testrunner library; skipping tests" + end end ## <at> <at> -378,57 +378,57 <at> <at> end # (e.g., bin/rdoc becomes rdoc); the shebang line handles running it. Under # windows, we add an '.rb' extension and let file associations do their stuff. def install_binfile(from, op_file, target) - tmp_dir = nil - InstallOptions.tmp_dirs.each do |t| - if File.directory?(t) and File.writable?(t) - tmp_dir = t - break - end + tmp_dir = nil + InstallOptions.tmp_dirs.each do |t| + if File.directory?(t) and File.writable?(t) + tmp_dir = t + break end + end - fail "Cannot find a temporary directory" unless tmp_dir - tmp_file = File.join(tmp_dir, '_tmp') - ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) - - File.open(from) do |ip| - File.open(tmp_file, "w") do |op| - ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) - op.puts "#!#{ruby}" - contents = ip.readlines - if contents[0] =~ /^#!/ - contents.shift - end - op.write contents.join() - end + fail "Cannot find a temporary directory" unless tmp_dir + tmp_file = File.join(tmp_dir, '_tmp') + ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) + + File.open(from) do |ip| + File.open(tmp_file, "w") do |op| + ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) + op.puts "#!#{ruby}" + contents = ip.readlines + if contents[0] =~ /^#!/ + contents.shift + end + op.write contents.join() end + end - if is_windows? - installed_wrapper = false + if is_windows? + installed_wrapper = false - if File.exists?("#{from}.bat") - FileUtils.install("#{from}.bat", File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true) - installed_wrapper = true - end + if File.exists?("#{from}.bat") + FileUtils.install("#{from}.bat", File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true) + installed_wrapper = true + end - if File.exists?("#{from}.cmd") - FileUtils.install("#{from}.cmd", File.join(target, "#{op_file}.cmd"), :mode => 0755, :verbose => true) - installed_wrapper = true - end + if File.exists?("#{from}.cmd") + FileUtils.install("#{from}.cmd", File.join(target, "#{op_file}.cmd"), :mode => 0755, :verbose => true) + installed_wrapper = true + end - if not installed_wrapper - tmp_file2 = File.join(tmp_dir, '_tmp_wrapper') - cwn = File.join(Config::CONFIG['bindir'], op_file) - cwv = CMD_WRAPPER.gsub('<ruby>', ruby.gsub(%r{/}) { "\\" }).gsub!('<command>', cwn.gsub(%r{/}) { "\\" } ) + if not installed_wrapper + tmp_file2 = File.join(tmp_dir, '_tmp_wrapper') + cwn = File.join(Config::CONFIG['bindir'], op_file) + cwv = CMD_WRAPPER.gsub('<ruby>', ruby.gsub(%r{/}) { "\\" }).gsub!('<command>', cwn.gsub(%r{/}) { "\\" } ) - File.open(tmp_file2, "wb") { |cw| cw.puts cwv } - FileUtils.install(tmp_file2, File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true) + File.open(tmp_file2, "wb") { |cw| cw.puts cwv } + FileUtils.install(tmp_file2, File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true) - File.unlink(tmp_file2) - installed_wrapper = true - end + File.unlink(tmp_file2) + installed_wrapper = true end - FileUtils.install(tmp_file, File.join(target, op_file), :mode => 0755, :verbose => true) - File.unlink(tmp_file) + end + FileUtils.install(tmp_file, File.join(target, op_file), :mode => 0755, :verbose => true) + File.unlink(tmp_file) end CMD_WRAPPER = <<-EOS diff --git a/lib/facter.rb b/lib/facter.rb index d862cd3..f56a52c 100644 --- a/lib/facter.rb +++ b/lib/facter.rb <at> <at> -15,233 +15,233 <at> <at> # limitations under the License. module Facter - # This is just so the other classes have the constant. - module Util; end - - require 'facter/util/fact' - require 'facter/util/collection' - - include Comparable - include Enumerable - - FACTERVERSION = '1.6.1' - # = Facter - # Functions as a hash of 'facts' you might care about about your - # system, such as mac address, IP address, Video card, etc. - # returns them dynamically - - # == Synopsis - # - # Generally, treat <tt>Facter</tt> as a hash: - # == Example - # require 'facter' - # puts Facter['operatingsystem'] - # - - # Set LANG to force i18n to C - # - ENV['LANG'] = 'C' - - GREEN = " [0;32m" - RESET = " [0m" - <at> <at> debug = 0 - <at> <at> timing = 0 - <at> <at> messages = {} - - # module methods - - def self.collection - unless defined?( <at> collection) and <at> collection - <at> collection = Facter::Util::Collection.new - end - <at> collection - end - - # Return the version of the library. - def self.version - return FACTERVERSION - end - - # Add some debugging - def self.debug(string) - if string.nil? - return - end - if self.debugging? - puts GREEN + string + RESET - end - end - - def self.debugging? - <at> <at> debug != 0 - end - - # show the timing information - def self.show_time(string) - puts "#{GREEN}#{string}#{RESET}" if string and Facter.timing? - end - - def self.timing? - <at> <at> timing != 0 - end - - # Return a fact object by name. If you use this, you still have to call - # 'value' on it to retrieve the actual value. - def self.[](name) - collection.fact(name) - end - - class << self - [:fact, :flush, :list, :value].each do |method| - define_method(method) do |*args| - collection.send(method, *args) - end - end - - [:list, :to_hash].each do |method| - define_method(method) do |*args| - collection.load_all - collection.send(method, *args) - end - end - end - - - # Add a resolution mechanism for a named fact. This does not distinguish - # between adding a new fact and adding a new way to resolve a fact. - def self.add(name, options = {}, &block) - collection.add(name, options, &block) - end - - def self.each - # Make sure all facts are loaded. + # This is just so the other classes have the constant. + module Util; end + + require 'facter/util/fact' + require 'facter/util/collection' + + include Comparable + include Enumerable + + FACTERVERSION = '1.6.1' + # = Facter + # Functions as a hash of 'facts' you might care about about your + # system, such as mac address, IP address, Video card, etc. + # returns them dynamically + + # == Synopsis + # + # Generally, treat <tt>Facter</tt> as a hash: + # == Example + # require 'facter' + # puts Facter['operatingsystem'] + # + + # Set LANG to force i18n to C + # + ENV['LANG'] = 'C' + + GREEN = " [0;32m" + RESET = " [0m" + <at> <at> debug = 0 + <at> <at> timing = 0 + <at> <at> messages = {} + + # module methods + + def self.collection + unless defined?( <at> collection) and <at> collection + <at> collection = Facter::Util::Collection.new + end + <at> collection + end + + # Return the version of the library. + def self.version + return FACTERVERSION + end + + # Add some debugging + def self.debug(string) + if string.nil? + return + end + if self.debugging? + puts GREEN + string + RESET + end + end + + def self.debugging? + <at> <at> debug != 0 + end + + # show the timing information + def self.show_time(string) + puts "#{GREEN}#{string}#{RESET}" if string and Facter.timing? + end + + def self.timing? + <at> <at> timing != 0 + end + + # Return a fact object by name. If you use this, you still have to call + # 'value' on it to retrieve the actual value. + def self.[](name) + collection.fact(name) + end + + class << self + [:fact, :flush, :list, :value].each do |method| + define_method(method) do |*args| + collection.send(method, *args) + end + end + + [:list, :to_hash].each do |method| + define_method(method) do |*args| collection.load_all - - collection.each do |*args| - yield(*args) - end - end - - class << self - # Allow users to call fact names directly on the Facter class, - # either retrieving the value or comparing it to an existing value. - def method_missing(name, *args) - question = false - if name.to_s =~ /\?$/ - question = true - name = name.to_s.sub(/\?$/,'') + collection.send(method, *args) + end + end + end + + + # Add a resolution mechanism for a named fact. This does not distinguish + # between adding a new fact and adding a new way to resolve a fact. + def self.add(name, options = {}, &block) + collection.add(name, options, &block) + end + + def self.each + # Make sure all facts are loaded. + collection.load_all + + collection.each do |*args| + yield(*args) + end + end + + class << self + # Allow users to call fact names directly on the Facter class, + # either retrieving the value or comparing it to an existing value. + def method_missing(name, *args) + question = false + if name.to_s =~ /\?$/ + question = true + name = name.to_s.sub(/\?$/,'') + end + + if fact = collection.fact(name) + if question + value = fact.value.downcase + args.each do |arg| + if arg.to_s.downcase == value + return true end + end - if fact = collection.fact(name) - if question - value = fact.value.downcase - args.each do |arg| - if arg.to_s.downcase == value - return true - end - end - - # If we got this far, there was no match. - return false - else - return fact.value - end - else - # Else, fail like a normal missing method. - raise NoMethodError, "Could not find fact '%s'" % name - end + # If we got this far, there was no match. + return false + else + return fact.value end - end - - # Clear all facts. Mostly used for testing. - def self.clear - Facter.flush - Facter.reset - end - - # Clear all messages. Used only in testing. Can't add to self.clear - # because we don't want to warn multiple times for items that are warnonce'd - def self.clear_messages - <at> <at> messages.clear - end - - # Set debugging on or off. - def self.debugging(bit) - if bit - case bit - when TrueClass; <at> <at> debug = 1 - when FalseClass; <at> <at> debug = 0 - when Fixnum - if bit > 0 - <at> <at> debug = 1 - else - <at> <at> debug = 0 - end - when String; - if bit.downcase == 'off' - <at> <at> debug = 0 - else - <at> <at> debug = 1 - end - else - <at> <at> debug = 0 - end + else + # Else, fail like a normal missing method. + raise NoMethodError, "Could not find fact '%s'" % name + end + end + end + + # Clear all facts. Mostly used for testing. + def self.clear + Facter.flush + Facter.reset + end + + # Clear all messages. Used only in testing. Can't add to self.clear + # because we don't want to warn multiple times for items that are warnonce'd + def self.clear_messages + <at> <at> messages.clear + end + + # Set debugging on or off. + def self.debugging(bit) + if bit + case bit + when TrueClass; <at> <at> debug = 1 + when FalseClass; <at> <at> debug = 0 + when Fixnum + if bit > 0 + <at> <at> debug = 1 else - <at> <at> debug = 0 + <at> <at> debug = 0 end - end - - # Set timing on or off. - def self.timing(bit) - if bit - case bit - when TrueClass; <at> <at> timing = 1 - when Fixnum - if bit > 0 - <at> <at> timing = 1 - else - <at> <at> timing = 0 - end - end + when String; + if bit.downcase == 'off' + <at> <at> debug = 0 else - <at> <at> timing = 0 + <at> <at> debug = 1 end - end - - def self.warn(msg) - if Facter.debugging? and msg and not msg.empty? - msg = [msg] unless msg.respond_to? :each - msg.each { |line| Kernel.warn line } + else + <at> <at> debug = 0 + end + else + <at> <at> debug = 0 + end + end + + # Set timing on or off. + def self.timing(bit) + if bit + case bit + when TrueClass; <at> <at> timing = 1 + when Fixnum + if bit > 0 + <at> <at> timing = 1 + else + <at> <at> timing = 0 end + end + else + <at> <at> timing = 0 end + end - # Warn once. - def self.warnonce(msg) - if msg and not msg.empty? and <at> <at> messages[msg].nil? - <at> <at> messages[msg] = true - Kernel.warn(msg) - end + def self.warn(msg) + if Facter.debugging? and msg and not msg.empty? + msg = [msg] unless msg.respond_to? :each + msg.each { |line| Kernel.warn line } end + end - # Remove them all. - def self.reset - <at> collection = nil + # Warn once. + def self.warnonce(msg) + if msg and not msg.empty? and <at> <at> messages[msg].nil? + <at> <at> messages[msg] = true + Kernel.warn(msg) end + end - # Load all of the default facts, and then everything from disk. - def self.loadfacts - collection.load_all - end + # Remove them all. + def self.reset + <at> collection = nil + end - <at> search_path = [] + # Load all of the default facts, and then everything from disk. + def self.loadfacts + collection.load_all + end - # Register a directory to search through. - def self.search(*dirs) - <at> search_path += dirs - end + <at> search_path = [] - # Return our registered search directories. - def self.search_path - <at> search_path.dup - end + # Register a directory to search through. + def self.search(*dirs) + <at> search_path += dirs + end + + # Return our registered search directories. + def self.search_path + <at> search_path.dup + end end diff --git a/lib/facter/Cfkey.rb b/lib/facter/Cfkey.rb index e54aeb0..e4e03f0 100644 --- a/lib/facter/Cfkey.rb +++ b/lib/facter/Cfkey.rb <at> <at> -14,29 +14,29 <at> <at> ## Facter.add(:Cfkey) do - setcode do - value = nil - ["/usr/local/etc/cfkey.pub", - "/etc/cfkey.pub", - "/var/cfng/keys/localhost.pub", - "/var/cfengine/ppkeys/localhost.pub", - "/var/lib/cfengine/ppkeys/localhost.pub", - "/var/lib/cfengine2/ppkeys/localhost.pub" - ].each do |file| - if FileTest.file?(file) - File.open(file) { |openfile| - value = openfile.readlines.reject { |line| - line =~ /PUBLIC KEY/ - }.collect { |line| - line.chomp - }.join("") - } - end - if value - break - end - end - - value + setcode do + value = nil + ["/usr/local/etc/cfkey.pub", + "/etc/cfkey.pub", + "/var/cfng/keys/localhost.pub", + "/var/cfengine/ppkeys/localhost.pub", + "/var/lib/cfengine/ppkeys/localhost.pub", + "/var/lib/cfengine2/ppkeys/localhost.pub" + ].each do |file| + if FileTest.file?(file) + File.open(file) { |openfile| + value = openfile.readlines.reject { |line| + line =~ /PUBLIC KEY/ + }.collect { |line| + line.chomp + }.join("") + } + end + if value + break + end end + + value + end end diff --git a/lib/facter/architecture.rb b/lib/facter/architecture.rb index 5be1bcb..cd0017c 100644 --- a/lib/facter/architecture.rb +++ b/lib/facter/architecture.rb <at> <at> -12,27 +12,27 <at> <at> # Facter.add(:architecture) do - setcode do - model = Facter.value(:hardwaremodel) - case model - # most linuxen use "x86_64" - when "x86_64" - case Facter.value(:operatingsystem) - when "Debian", "Gentoo", "GNU/kFreeBSD", "Ubuntu" - "amd64" - else - model - end - when /(i[3456]86|pentium)/ - case Facter.value(:operatingsystem) - when "Gentoo" - "x86" - else - "i386" - end - else - model - end + setcode do + model = Facter.value(:hardwaremodel) + case model + # most linuxen use "x86_64" + when "x86_64" + case Facter.value(:operatingsystem) + when "Debian", "Gentoo", "GNU/kFreeBSD", "Ubuntu" + "amd64" + else + model + end + when /(i[3456]86|pentium)/ + case Facter.value(:operatingsystem) + when "Gentoo" + "x86" + else + "i386" + end + else + model end + end end diff --git a/lib/facter/domain.rb b/lib/facter/domain.rb index a14c3e6..92eafa3 100644 --- a/lib/facter/domain.rb +++ b/lib/facter/domain.rb <at> <at> -19,45 +19,45 <at> <at> # Facter.add(:domain) do - setcode do - # Get the domain from various sources; the order of these - # steps is important + setcode do + # Get the domain from various sources; the order of these + # steps is important - if name = Facter::Util::Resolution.exec('hostname') and - name =~ /.*?\.(.+$)/ + if name = Facter::Util::Resolution.exec('hostname') and + name =~ /.*?\.(.+$)/ - $1 - elsif domain = Facter::Util::Resolution.exec('dnsdomainname') and - domain =~ /.+\..+/ + $1 + elsif domain = Facter::Util::Resolution.exec('dnsdomainname') and + domain =~ /.+\..+/ - domain - elsif FileTest.exists?("/etc/resolv.conf") - domain = nil - search = nil - File.open("/etc/resolv.conf") { |file| - file.each { |line| - if line =~ /^\s*domain\s+(\S+)/ - domain = $1 - elsif line =~ /^\s*search\s+(\S+)/ - search = $1 - end - } - } - next domain if domain - next search if search - end + domain + elsif FileTest.exists?("/etc/resolv.conf") + domain = nil + search = nil + File.open("/etc/resolv.conf") { |file| + file.each { |line| + if line =~ /^\s*domain\s+(\S+)/ + domain = $1 + elsif line =~ /^\s*search\s+(\S+)/ + search = $1 + end + } + } + next domain if domain + next search if search end + end end Facter.add(:domain) do - confine :kernel => :windows - setcode do - require 'facter/util/wmi' - domain = "" - Facter::Util::WMI.execquery("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").each { |nic| - domain = nic.DNSDomain - break - } - domain - end + confine :kernel => :windows + setcode do + require 'facter/util/wmi' + domain = "" + Facter::Util::WMI.execquery("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").each { |nic| + domain = nic.DNSDomain + break + } + domain + end end diff --git a/lib/facter/facterversion.rb b/lib/facter/facterversion.rb index 574da99..519d660 100644 --- a/lib/facter/facterversion.rb +++ b/lib/facter/facterversion.rb <at> <at> -8,5 +8,5 <at> <at> # Facter.add(:facterversion) do - setcode { Facter::FACTERVERSION.to_s } + setcode { Facter::FACTERVERSION.to_s } end diff --git a/lib/facter/fqdn.rb b/lib/facter/fqdn.rb index 090ca63..68597f3 100644 --- a/lib/facter/fqdn.rb +++ b/lib/facter/fqdn.rb <at> <at> -10,13 +10,13 <at> <at> # Facter.add(:fqdn) do - setcode do - host = Facter.value(:hostname) - domain = Facter.value(:domain) - if host and domain - [host, domain].join(".") - else - nil - end + setcode do + host = Facter.value(:hostname) + domain = Facter.value(:domain) + if host and domain + [host, domain].join(".") + else + nil end + end end diff --git a/lib/facter/hardwareisa.rb b/lib/facter/hardwareisa.rb index 323983e..a58a043 100644 --- a/lib/facter/hardwareisa.rb +++ b/lib/facter/hardwareisa.rb <at> <at> -11,6 +11,6 <at> <at> # Facter.add(:hardwareisa) do - setcode 'uname -p' - confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS Scientific SLC SuSE SLES Debian Ubuntu Gentoo FreeBSD OpenBSD NetBSD DragonFly OEL OracleLinux OVS GNU/kFreeBSD} + setcode 'uname -p' + confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS Scientific SLC SuSE SLES Debian Ubuntu Gentoo FreeBSD OpenBSD NetBSD DragonFly OEL OracleLinux OVS GNU/kFreeBSD} end diff --git a/lib/facter/hardwaremodel.rb b/lib/facter/hardwaremodel.rb index 8f52fef..07e7501 100644 --- a/lib/facter/hardwaremodel.rb +++ b/lib/facter/hardwaremodel.rb <at> <at> -12,23 +12,23 <at> <at> # Facter.add(:hardwaremodel) do - setcode 'uname -m' + setcode 'uname -m' end Facter.add(:hardwaremodel) do - confine :operatingsystem => :aix - setcode do - model = Facter::Util::Resolution.exec('lsattr -El sys0 -a modelname') - if model =~ /modelname\s(\S+)\s/ - $1 - end + confine :operatingsystem => :aix + setcode do + model = Facter::Util::Resolution.exec('lsattr -El sys0 -a modelname') + if model =~ /modelname\s(\S+)\s/ + $1 end + end end Facter.add(:hardwaremodel) do - confine :operatingsystem => :windows - setcode do - require 'rbconfig' - Config::CONFIG['host_cpu'] - end + confine :operatingsystem => :windows + setcode do + require 'rbconfig' + Config::CONFIG['host_cpu'] + end end diff --git a/lib/facter/hostname.rb b/lib/facter/hostname.rb index 36c353f..2371ec8 100644 --- a/lib/facter/hostname.rb +++ b/lib/facter/hostname.rb <at> <at> -12,22 +12,22 <at> <at> # Facter.add(:hostname, :ldapname => "cn") do - setcode do - hostname = nil - if name = Facter::Util::Resolution.exec('hostname') - if name =~ /(.*?)\./ - hostname = $1 - else - hostname = name - end - end - hostname + setcode do + hostname = nil + if name = Facter::Util::Resolution.exec('hostname') + if name =~ /(.*?)\./ + hostname = $1 + else + hostname = name + end end + hostname + end end Facter.add(:hostname) do - confine :kernel => :darwin, :kernelrelease => "R7" - setcode do - Facter::Util::Resolution.exec('/usr/sbin/scutil --get LocalHostName') - end + confine :kernel => :darwin, :kernelrelease => "R7" + setcode do + Facter::Util::Resolution.exec('/usr/sbin/scutil --get LocalHostName') + end end diff --git a/lib/facter/id.rb b/lib/facter/id.rb index cc0a0a6..0d80f98 100644 --- a/lib/facter/id.rb +++ b/lib/facter/id.rb <at> <at> -12,10 +12,10 <at> <at> # Facter.add(:id) do - setcode "whoami" + setcode "whoami" end Facter.add(:id) do - confine :kernel => :SunOS - setcode "/usr/xpg4/bin/id -un" + confine :kernel => :SunOS + setcode "/usr/xpg4/bin/id -un" end diff --git a/lib/facter/interfaces.rb b/lib/facter/interfaces.rb index 04b1c19..d02a4f7 100644 --- a/lib/facter/interfaces.rb +++ b/lib/facter/interfaces.rb <at> <at> -20,22 +20,22 <at> <at> require 'facter/util/ip' # is missing. Facter.add(:interfaces) do - confine :kernel => Facter::Util::IP.supported_platforms - setcode do - Facter::Util::IP.get_interfaces.collect { |iface| Facter::Util::IP.alphafy(iface) }.join(",") - end + confine :kernel => Facter::Util::IP.supported_platforms + setcode do + Facter::Util::IP.get_interfaces.collect { |iface| Facter::Util::IP.alphafy(iface) }.join(",") + end end Facter::Util::IP.get_interfaces.each do |interface| - # Make a fact for each detail of each interface. Yay. - # There's no point in confining these facts, since we wouldn't be able to create - # them if we weren't running on a supported platform. - %w{ipaddress ipaddress6 macaddress netmask}.each do |label| - Facter.add(label + "_" + Facter::Util::IP.alphafy(interface)) do - setcode do - Facter::Util::IP.get_interface_value(interface, label) - end - end + # Make a fact for each detail of each interface. Yay. + # There's no point in confining these facts, since we wouldn't be able to create + # them if we weren't running on a supported platform. + %w{ipaddress ipaddress6 macaddress netmask}.each do |label| + Facter.add(label + "_" + Facter::Util::IP.alphafy(interface)) do + setcode do + Facter::Util::IP.get_interface_value(interface, label) + end end + end end diff --git a/lib/facter/ipaddress.rb b/lib/facter/ipaddress.rb index 41b22e2..42d0282 100644 --- a/lib/facter/ipaddress.rb +++ b/lib/facter/ipaddress.rb <at> <at> -23,138 +23,138 <at> <at> # Facter.add(:ipaddress) do - confine :kernel => :linux - setcode do - ip = nil - output = %x{/sbin/ifconfig} + confine :kernel => :linux + setcode do + ip = nil + output = %x{/sbin/ifconfig} - output.split(/^\S/).each { |str| - if str =~ /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ - tmp = $1 - unless tmp =~ /^127\./ - ip = tmp - break - end - end - } + output.split(/^\S/).each { |str| + if str =~ /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ + tmp = $1 + unless tmp =~ /^127\./ + ip = tmp + break + end + end + } - ip - end + ip + end end Facter.add(:ipaddress) do - confine :kernel => %w{FreeBSD OpenBSD Darwin DragonFly} - setcode do - ip = nil - output = %x{/sbin/ifconfig} + confine :kernel => %w{FreeBSD OpenBSD Darwin DragonFly} + setcode do + ip = nil + output = %x{/sbin/ifconfig} - output.split(/^\S/).each { |str| - if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ - tmp = $1 - unless tmp =~ /^127\./ - ip = tmp - break - end - end - } + output.split(/^\S/).each { |str| + if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ + tmp = $1 + unless tmp =~ /^127\./ + ip = tmp + break + end + end + } - ip - end + ip + end end Facter.add(:ipaddress) do - confine :kernel => %w{NetBSD SunOS} - setcode do - ip = nil - output = %x{/sbin/ifconfig -a} + confine :kernel => %w{NetBSD SunOS} + setcode do + ip = nil + output = %x{/sbin/ifconfig -a} - output.split(/^\S/).each { |str| - if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ - tmp = $1 - unless tmp =~ /^127\./ or tmp == "0.0.0.0" - ip = tmp - break - end - end - } + output.split(/^\S/).each { |str| + if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ + tmp = $1 + unless tmp =~ /^127\./ or tmp == "0.0.0.0" + ip = tmp + break + end + end + } - ip - end + ip + end end Facter.add(:ipaddress) do - confine :kernel => %w{AIX} - setcode do - ip = nil - output = %x{/usr/sbin/ifconfig -a} + confine :kernel => %w{AIX} + setcode do + ip = nil + output = %x{/usr/sbin/ifconfig -a} - output.split(/^\S/).each { |str| - if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ - tmp = $1 - unless tmp =~ /^127\./ - ip = tmp - break - end - end - } + output.split(/^\S/).each { |str| + if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ + tmp = $1 + unless tmp =~ /^127\./ + ip = tmp + break + end + end + } - ip - end + ip + end end Facter.add(:ipaddress) do - confine :kernel => %w{windows} - setcode do - require 'socket' - IPSocket.getaddress(Socket.gethostname) - end + confine :kernel => %w{windows} + setcode do + require 'socket' + IPSocket.getaddress(Socket.gethostname) + end end Facter.add(:ipaddress, :ldapname => "iphostnumber", :timeout => 2) do - setcode do + setcode do + if Facter.value(:kernel) == 'windows' + require 'win32/resolv' + else + require 'resolv' + end + + begin + if hostname = Facter.value(:hostname) if Facter.value(:kernel) == 'windows' - require 'win32/resolv' + ip = Win32::Resolv.get_resolv_info.last[0] else - require 'resolv' + ip = Resolv.getaddress(hostname) end - - begin - if hostname = Facter.value(:hostname) - if Facter.value(:kernel) == 'windows' - ip = Win32::Resolv.get_resolv_info.last[0] - else - ip = Resolv.getaddress(hostname) - end - unless ip == "127.0.0.1" - ip - end - else - nil - end - rescue Resolv::ResolvError - nil - rescue NoMethodError # i think this is a bug in resolv.rb? - nil + unless ip == "127.0.0.1" + ip end + else + nil + end + rescue Resolv::ResolvError + nil + rescue NoMethodError # i think this is a bug in resolv.rb? + nil end + end end Facter.add(:ipaddress, :timeout => 2) do - setcode do - if hostname = Facter.value(:hostname) - # we need Hostname to exist for this to work - host = nil - if host = Facter::Util::Resolution.exec("host #{hostname}") - list = host.chomp.split(/\s/) - if defined? list[-1] and - list[-1] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ - list[-1] - end - else - nil - end - else - nil + setcode do + if hostname = Facter.value(:hostname) + # we need Hostname to exist for this to work + host = nil + if host = Facter::Util::Resolution.exec("host #{hostname}") + list = host.chomp.split(/\s/) + if defined? list[-1] and + list[-1] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ + list[-1] end + else + nil + end + else + nil end + end end diff --git a/lib/facter/iphostnumber.rb b/lib/facter/iphostnumber.rb index cddaadd..2d22017 100644 --- a/lib/facter/iphostnumber.rb +++ b/lib/facter/iphostnumber.rb <at> <at> -10,20 +10,20 <at> <at> # Facter.add(:iphostnumber) do - confine :kernel => :darwin, :kernelrelease => "R6" - setcode do - %x{/usr/sbin/scutil --get LocalHostName} - end + confine :kernel => :darwin, :kernelrelease => "R6" + setcode do + %x{/usr/sbin/scutil --get LocalHostName} + end end Facter.add(:iphostnumber) do - confine :kernel => :darwin, :kernelrelease => "R6" - setcode do - ether = nil - output = %x{/sbin/ifconfig} + confine :kernel => :darwin, :kernelrelease => "R6" + setcode do + ether = nil + output = %x{/sbin/ifconfig} - output =~ /HWaddr (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/ - ether = $1 + output =~ /HWaddr (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/ + ether = $1 - ether - end + ether + end end diff --git a/lib/facter/kernel.rb b/lib/facter/kernel.rb index 2c925eb..31ac22d 100644 --- a/lib/facter/kernel.rb +++ b/lib/facter/kernel.rb <at> <at> -10,13 +10,13 <at> <at> # Facter.add(:kernel) do - setcode do - require 'facter/util/config' + setcode do + require 'facter/util/config' - if Facter::Util::Config.is_windows? - 'windows' - else - Facter::Util::Resolution.exec("uname -s") - end + if Facter::Util::Config.is_windows? + 'windows' + else + Facter::Util::Resolution.exec("uname -s") end + end end diff --git a/lib/facter/kernelmajversion.rb b/lib/facter/kernelmajversion.rb index 84f71d4..f7302d4 100644 --- a/lib/facter/kernelmajversion.rb +++ b/lib/facter/kernelmajversion.rb <at> <at> -9,7 +9,7 <at> <at> # Facter.add("kernelmajversion") do - setcode do - Facter.value(:kernelversion).split('.')[0..1].join('.') - end + setcode do + Facter.value(:kernelversion).split('.')[0..1].join('.') + end end diff --git a/lib/facter/kernelrelease.rb b/lib/facter/kernelrelease.rb index 1d34826..a38b128 100644 --- a/lib/facter/kernelrelease.rb +++ b/lib/facter/kernelrelease.rb <at> <at> -12,23 +12,23 <at> <at> # Facter.add(:kernelrelease) do - setcode 'uname -r' + setcode 'uname -r' end Facter.add(:kernelrelease) do - confine :kernel => :aix - setcode 'oslevel -s' + confine :kernel => :aix + setcode 'oslevel -s' end Facter.add(:kernelrelease) do - confine :kernel => %{windows} - setcode do - require 'facter/util/wmi' - version = "" - Facter::Util::WMI.execquery("SELECT Version from Win32_OperatingSystem").each do |ole| - version = "#{ole.Version}" - break - end - version + confine :kernel => %{windows} + setcode do + require 'facter/util/wmi' + version = "" + Facter::Util::WMI.execquery("SELECT Version from Win32_OperatingSystem").each do |ole| + version = "#{ole.Version}" + break end + version + end end diff --git a/lib/facter/kernelversion.rb b/lib/facter/kernelversion.rb index 7e0d95c..b8fc34c 100644 --- a/lib/facter/kernelversion.rb +++ b/lib/facter/kernelversion.rb <at> <at> -11,12 +11,12 <at> <at> # Facter.add("kernelversion") do - setcode do - Facter['kernelrelease'].value.split('-')[0] - end + setcode do + Facter['kernelrelease'].value.split('-')[0] + end end Facter.add("kernelversion") do - confine :kernel => :sunos - setcode 'uname -v' + confine :kernel => :sunos + setcode 'uname -v' end diff --git a/lib/facter/lsb.rb b/lib/facter/lsb.rb index 7beb41d..7cefb5c 100644 --- a/lib/facter/lsb.rb +++ b/lib/facter/lsb.rb <at> <at> -20,20 +20,20 <at> <at> "LSBDistDescription" => %r{^Description:\t(.*)$}, "LSBDistCodeName" => %r{^Codename:\t(.*)$} }.each do |fact, pattern| - Facter.add(fact) do - confine :kernel => [ :linux, :"gnu/kfreebsd" ] - setcode do - unless defined?(lsbdata) and defined?(lsbtime) and (Time.now.to_i - lsbtime.to_i < 5) - type = nil - lsbtime = Time.now - lsbdata = Facter::Util::Resolution.exec('lsb_release -a 2>/dev/null') - end + Facter.add(fact) do + confine :kernel => [ :linux, :"gnu/kfreebsd" ] + setcode do + unless defined?(lsbdata) and defined?(lsbtime) and (Time.now.to_i - lsbtime.to_i < 5) + type = nil + lsbtime = Time.now + lsbdata = Facter::Util::Resolution.exec('lsb_release -a 2>/dev/null') + end - if pattern.match(lsbdata) - $1 - else - nil - end - end + if pattern.match(lsbdata) + $1 + else + nil + end end + end end diff --git a/lib/facter/lsbmajdistrelease.rb b/lib/facter/lsbmajdistrelease.rb index 1d97158..df1e887 100644 --- a/lib/facter/lsbmajdistrelease.rb +++ b/lib/facter/lsbmajdistrelease.rb <at> <at> -15,13 +15,13 <at> <at> require 'facter' Facter.add("lsbmajdistrelease") do - confine :operatingsystem => %w{Linux Fedora RedHat CentOS Scientific SLC SuSE SLES Debian Ubuntu Gentoo OEL OracleLinux OVS GNU/kFreeBSD} - setcode do - if /(\d*)\./i =~ Facter.value(:lsbdistrelease) - result=$1 - else - result=Facter.value(:lsbdistrelease) - end - result + confine :operatingsystem => %w{Linux Fedora RedHat CentOS Scientific SLC SuSE SLES Debian Ubuntu Gentoo OEL OracleLinux OVS GNU/kFreeBSD} + setcode do + if /(\d*)\./i =~ Facter.value(:lsbdistrelease) + result=$1 + else + result=Facter.value(:lsbdistrelease) end + result + end end diff --git a/lib/facter/macaddress.rb b/lib/facter/macaddress.rb index 341654a..25e2ef4 100644 --- a/lib/facter/macaddress.rb +++ b/lib/facter/macaddress.rb <at> <at> -10,69 +10,69 <at> <at> require 'facter/util/macaddress' Facter.add(:macaddress) do - confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS Scientific SLC SuSE SLES Debian Gentoo Ubuntu OEL OracleLinux OVS GNU/kFreeBSD} - setcode do - ether = [] - output = Facter::Util::Resolution.exec("/sbin/ifconfig -a") - output.each_line do |s| - ether.push($1) if s =~ /(?:ether|HWaddr) (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/ - end - Facter::Util::Macaddress.standardize(ether[0]) + confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS Scientific SLC SuSE SLES Debian Gentoo Ubuntu OEL OracleLinux OVS GNU/kFreeBSD} + setcode do + ether = [] + output = Facter::Util::Resolution.exec("/sbin/ifconfig -a") + output.each_line do |s| + ether.push($1) if s =~ /(?:ether|HWaddr) (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/ end + Facter::Util::Macaddress.standardize(ether[0]) + end end Facter.add(:macaddress) do - confine :operatingsystem => "Solaris" - setcode do - ether = [] - output = Facter::Util::Resolution.exec("/usr/bin/netstat -np") - output.each_line do |s| - ether.push($1) if s =~ /(?:SPLA)\s+(\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2})/ - end - Facter::Util::Macaddress.standardize(ether[0]) + confine :operatingsystem => "Solaris" + setcode do + ether = [] + output = Facter::Util::Resolution.exec("/usr/bin/netstat -np") + output.each_line do |s| + ether.push($1) if s =~ /(?:SPLA)\s+(\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2})/ end + Facter::Util::Macaddress.standardize(ether[0]) + end end Facter.add(:macaddress) do - confine :operatingsystem => %w{FreeBSD OpenBSD DragonFly} - setcode do + confine :operatingsystem => %w{FreeBSD OpenBSD DragonFly} + setcode do ether = [] - output = Facter::Util::Resolution.exec("/sbin/ifconfig") - output.each_line do |s| - if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/ - ether.push($1) - end - end - Facter::Util::Macaddress.standardize(ether[0]) + output = Facter::Util::Resolution.exec("/sbin/ifconfig") + output.each_line do |s| + if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/ + ether.push($1) + end end + Facter::Util::Macaddress.standardize(ether[0]) + end end Facter.add(:macaddress) do - confine :kernel => :darwin - setcode { Facter::Util::Macaddress::Darwin.macaddress } + confine :kernel => :darwin + setcode { Facter::Util::Macaddress::Darwin.macaddress } end Facter.add(:macaddress) do - confine :kernel => %w{AIX} - setcode do - ether = [] - ip = nil - output = %x{/usr/sbin/ifconfig -a} - output.each_line do |str| - if str =~ /([a-z]+\d+): flags=/ - devname = $1 - unless devname =~ /lo0/ - output2 = %x{/usr/bin/entstat #{devname}} - output2.each_line do |str2| - if str2 =~ /^Hardware Address: (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/ - ether.push($1) - end - end - end + confine :kernel => %w{AIX} + setcode do + ether = [] + ip = nil + output = %x{/usr/sbin/ifconfig -a} + output.each_line do |str| + if str =~ /([a-z]+\d+): flags=/ + devname = $1 + unless devname =~ /lo0/ + output2 = %x{/usr/bin/entstat #{devname}} + output2.each_line do |str2| + if str2 =~ /^Hardware Address: (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/ + ether.push($1) end + end end - Facter::Util::Macaddress.standardize(ether[0]) + end end + Facter::Util::Macaddress.standardize(ether[0]) + end end Facter.add(:macaddress) do diff --git a/lib/facter/macosx.rb b/lib/facter/macosx.rb index 7c8562d..74a0cc7 100644 --- a/lib/facter/macosx.rb +++ b/lib/facter/macosx.rb <at> <at> -27,30 +27,30 <at> <at> require 'facter/util/macosx' if Facter.value(:kernel) == "Darwin" - Facter::Util::Macosx.hardware_overview.each do |fact, value| - Facter.add("sp_#{fact}") do - confine :kernel => :darwin - setcode do - value.to_s - end - end + Facter::Util::Macosx.hardware_overview.each do |fact, value| + Facter.add("sp_#{fact}") do + confine :kernel => :darwin + setcode do + value.to_s + end end + end - Facter::Util::Macosx.os_overview.each do |fact, value| - Facter.add("sp_#{fact}") do - confine :kernel => :darwin - setcode do - value.to_s - end - end + Facter::Util::Macosx.os_overview.each do |fact, value| + Facter.add("sp_#{fact}") do + confine :kernel => :darwin + setcode do + value.to_s + end end + end - Facter::Util::Macosx.sw_vers.each do |fact, value| - Facter.add(fact) do - confine :kernel => :darwin - setcode do - value - end - end + Facter::Util::Macosx.sw_vers.each do |fact, value| + Facter.add(fact) do + confine :kernel => :darwin + setcode do + value + end end + end end diff --git a/lib/facter/manufacturer.rb b/lib/facter/manufacturer.rb index 98ed29e..1857d09 100644 --- a/lib/facter/manufacturer.rb +++ b/lib/facter/manufacturer.rb <at> <at> -19,39 +19,39 <at> <at> require 'facter/util/manufacturer' if Facter.value(:kernel) == "OpenBSD" - mfg_keys = { - 'hw.vendor' => 'manufacturer', - 'hw.product' => 'productname', - 'hw.serialno' => 'serialnumber' - } + mfg_keys = { + 'hw.vendor' => 'manufacturer', + 'hw.product' => 'productname', + 'hw.serialno' => 'serialnumber' + } - Facter::Manufacturer.sysctl_find_system_info(mfg_keys) + Facter::Manufacturer.sysctl_find_system_info(mfg_keys) elsif Facter.value(:kernel) == "Darwin" - mfg_keys = { - 'hw.model' => 'productname' - } - Facter::Manufacturer.sysctl_find_system_info(mfg_keys) + mfg_keys = { + 'hw.model' => 'productname' + } + Facter::Manufacturer.sysctl_find_system_info(mfg_keys) elsif Facter.value(:kernel) == "SunOS" and Facter.value(:hardwareisa) == "sparc" - Facter::Manufacturer.prtdiag_sparc_find_system_info() + Facter::Manufacturer.prtdiag_sparc_find_system_info() elsif Facter.value(:kernel) == "windows" - win32_keys = { - 'manufacturer' => ['Manufacturer', 'Bios'], - 'serialNumber' => ['Serialnumber', 'Bios'], - 'productname' => ['Name', 'ComputerSystemProduct'] - } - Facter::Manufacturer.win32_find_system_info(win32_keys) + win32_keys = { + 'manufacturer' => ['Manufacturer', 'Bios'], + 'serialNumber' => ['Serialnumber', 'Bios'], + 'productname' => ['Name', 'ComputerSystemProduct'] + } + Facter::Manufacturer.win32_find_system_info(win32_keys) else - query = { - '[Ss]ystem [Ii]nformation' => [ - { 'Manufacturer:' => 'manufacturer' }, - { 'Product(?: Name)?:' => 'productname' }, - { 'Serial Number:' => 'serialnumber' } - ], - '(Chassis Information|system enclosure or chassis)' => [ - { '(?:Chassis )?Type:' => 'type' } - ] - } + query = { + '[Ss]ystem [Ii]nformation' => [ + { 'Manufacturer:' => 'manufacturer' }, + { 'Product(?: Name)?:' => 'productname' }, + { 'Serial Number:' => 'serialnumber' } + ], + '(Chassis Information|system enclosure or chassis)' => [ + { '(?:Chassis )?Type:' => 'type' } + ] + } - Facter::Manufacturer.dmi_find_system_info(query) + Facter::Manufacturer.dmi_find_system_info(query) end diff --git a/lib/facter/memory.rb b/lib/facter/memory.rb index f7e9f67..0b7731f 100644 --- a/lib/facter/memory.rb +++ b/lib/facter/memory.rb <at> <at> -29,180 +29,180 <at> <at> require 'facter/util/memory' :SwapSize => "SwapTotal", :SwapFree => "SwapFree" }.each do |fact, name| - Facter.add(fact) do - confine :kernel => [ :linux, :"gnu/kfreebsd" ] - setcode do - Facter::Memory.meminfo_number(name) - end + Facter.add(fact) do + confine :kernel => [ :linux, :"gnu/kfreebsd" ] + setcode do + Facter::Memory.meminfo_number(name) end + end end Facter.add("SwapSize") do - confine :kernel => :Darwin - setcode do + confine :kernel => :Darwin + setcode do swap = Facter::Util::Resolution.exec('sysctl vm.swapusage') swaptotal = 0 if swap =~ /total = (\S+)/ then swaptotal = $1; end - swaptotal - end + swaptotal + end end Facter.add("SwapFree") do - confine :kernel => :Darwin - setcode do + confine :kernel => :Darwin + setcode do swap = Facter::Util::Resolution.exec('sysctl vm.swapusage') swapfree = 0 if swap =~ /free = (\S+)/ then swapfree = $1; end - swapfree - end + swapfree + end end Facter.add("SwapEncrypted") do - confine :kernel => :Darwin - setcode do + confine :kernel => :Darwin + setcode do swap = Facter::Util::Resolution.exec('sysctl vm.swapusage') encrypted = false if swap =~ /\(encrypted\)/ then encrypted = true; end - encrypted - end + encrypted + end end if Facter.value(:kernel) == "AIX" and Facter.value(:id) == "root" - swap = Facter::Util::Resolution.exec('swap -l') - swapfree, swaptotal = 0, 0 - swap.each_line do |dev| - if dev =~ /^\/\S+\s.*\s+(\S+)MB\s+(\S+)MB/ - swaptotal += $1.to_i - swapfree += $2.to_i - end + swap = Facter::Util::Resolution.exec('swap -l') + swapfree, swaptotal = 0, 0 + swap.each_line do |dev| + if dev =~ /^\/\S+\s.*\s+(\S+)MB\s+(\S+)MB/ + swaptotal += $1.to_i + swapfree += $2.to_i end + end - Facter.add("SwapSize") do - confine :kernel => :aix - setcode do - Facter::Memory.scale_number(swaptotal.to_f,"MB") - end + Facter.add("SwapSize") do + confine :kernel => :aix + setcode do + Facter::Memory.scale_number(swaptotal.to_f,"MB") end + end - Facter.add("SwapFree") do - confine :kernel => :aix - setcode do - Facter::Memory.scale_number(swapfree.to_f,"MB") - end + Facter.add("SwapFree") do + confine :kernel => :aix + setcode do + Facter::Memory.scale_number(swapfree.to_f,"MB") end + end end if Facter.value(:kernel) == "OpenBSD" - swap = Facter::Util::Resolution.exec('swapctl -s') - swapfree, swaptotal = 0, 0 - if swap =~ /^total: (\d+)k bytes allocated = \d+k used, (\d+)k available$/ - swaptotal = $1.to_i - swapfree = $2.to_i - end + swap = Facter::Util::Resolution.exec('swapctl -s') + swapfree, swaptotal = 0, 0 + if swap =~ /^total: (\d+)k bytes allocated = \d+k used, (\d+)k available$/ + swaptotal = $1.to_i + swapfree = $2.to_i + end - Facter.add("SwapSize") do - confine :kernel => :openbsd - setcode do - Facter::Memory.scale_number(swaptotal.to_f,"kB") - end + Facter.add("SwapSize") do + confine :kernel => :openbsd + setcode do + Facter::Memory.scale_number(swaptotal.to_f,"kB") end + end - Facter.add("SwapFree") do - confine :kernel => :openbsd - setcode do - Facter::Memory.scale_number(swapfree.to_f,"kB") - end + Facter.add("SwapFree") do + confine :kernel => :openbsd + setcode do + Facter::Memory.scale_number(swapfree.to_f,"kB") end + end - Facter::Memory.vmstat_find_free_memory() + Facter::Memory.vmstat_find_free_memory() - Facter.add("MemoryTotal") do - confine :kernel => :openbsd - memtotal = Facter::Util::Resolution.exec("sysctl hw.physmem | cut -d'=' -f2") - setcode do - Facter::Memory.scale_number(memtotal.to_f,"") - end + Facter.add("MemoryTotal") do + confine :kernel => :openbsd + memtotal = Facter::Util::Resolution.exec("sysctl hw.physmem | cut -d'=' -f2") + setcode do + Facter::Memory.scale_number(memtotal.to_f,"") end + end end if Facter.value(:kernel) == "Darwin" - swap = Facter::Util::Resolution.exec('sysctl vm.swapusage') - swapfree, swaptotal = 0, 0 - unless swap.empty? - # Parse the line: - # vm.swapusage: total = 128.00M used = 0.37M free = 127.63M (encrypted) - if swap =~ /total\s=\s(\S+)\s+used\s=\s(\S+)\s+free\s=\s(\S+)\s/ - swaptotal += $1.to_i - swapfree += $3.to_i - end + swap = Facter::Util::Resolution.exec('sysctl vm.swapusage') + swapfree, swaptotal = 0, 0 + unless swap.empty? + # Parse the line: + # vm.swapusage: total = 128.00M used = 0.37M free = 127.63M (encrypted) + if swap =~ /total\s=\s(\S+)\s+used\s=\s(\S+)\s+free\s=\s(\S+)\s/ + swaptotal += $1.to_i + swapfree += $3.to_i end + end - Facter.add("SwapSize") do - confine :kernel => :Darwin - setcode do - Facter::Memory.scale_number(swaptotal.to_f,"MB") - end + Facter.add("SwapSize") do + confine :kernel => :Darwin + setcode do + Facter::Memory.scale_number(swaptotal.to_f,"MB") end + end - Facter.add("SwapFree") do - confine :kernel => :Darwin - setcode do - Facter::Memory.scale_number(swapfree.to_f,"MB") - end + Facter.add("SwapFree") do + confine :kernel => :Darwin + setcode do + Facter::Memory.scale_number(swapfree.to_f,"MB") end + end - Facter::Memory.vmstat_darwin_find_free_memory() + Facter::Memory.vmstat_darwin_find_free_memory() - Facter.add("MemoryTotal") do - confine :kernel => :Darwin - memtotal = Facter::Util::Resolution.exec("sysctl hw.memsize | cut -d':' -f2") - setcode do - Facter::Memory.scale_number(memtotal.to_f,"") - end + Facter.add("MemoryTotal") do + confine :kernel => :Darwin + memtotal = Facter::Util::Resolution.exec("sysctl hw.memsize | cut -d':' -f2") + setcode do + Facter::Memory.scale_number(memtotal.to_f,"") end + end end if Facter.value(:kernel) == "SunOS" - swap = Facter::Util::Resolution.exec('/usr/sbin/swap -l') - swapfree, swaptotal = 0, 0 - swap.each_line do |dev| - if dev =~ /^\/\S+\s.*\s+(\d+)\s+(\d+)$/ - swaptotal += $1.to_i / 2 - swapfree += $2.to_i / 2 - end + swap = Facter::Util::Resolution.exec('/usr/sbin/swap -l') + swapfree, swaptotal = 0, 0 + swap.each_line do |dev| + if dev =~ /^\/\S+\s.*\s+(\d+)\s+(\d+)$/ + swaptotal += $1.to_i / 2 + swapfree += $2.to_i / 2 end + end - Facter.add("SwapSize") do - confine :kernel => :sunos - setcode do - Facter::Memory.scale_number(swaptotal.to_f,"kB") - end + Facter.add("SwapSize") do + confine :kernel => :sunos + setcode do + Facter::Memory.scale_number(swaptotal.to_f,"kB") end + end - Facter.add("SwapFree") do - confine :kernel => :sunos - setcode do - Facter::Memory.scale_number(swapfree.to_f,"kB") - end + Facter.add("SwapFree") do + confine :kernel => :sunos + setcode do + Facter::Memory.scale_number(swapfree.to_f,"kB") end + end - # Total memory size available from prtconf - pconf = Facter::Util::Resolution.exec('/usr/sbin/prtconf 2>/dev/null') - phymem = "" - pconf.each_line do |line| - if line =~ /^Memory size:\s+(\d+) Megabytes/ - phymem = $1 - end + # Total memory size available from prtconf + pconf = Facter::Util::Resolution.exec('/usr/sbin/prtconf 2>/dev/null') + phymem = "" + pconf.each_line do |line| + if line =~ /^Memory size:\s+(\d+) Megabytes/ + phymem = $1 end + end - Facter.add("MemorySize") do - confine :kernel => :sunos - setcode do - Facter::Memory.scale_number(phymem.to_f,"MB") - end + Facter.add("MemorySize") do + confine :kernel => :sunos + setcode do + Facter::Memory.scale_number(phymem.to_f,"MB") end + end - Facter::Memory.vmstat_find_free_memory() + Facter::Memory.vmstat_find_free_memory() end if Facter.value(:kernel) == "windows" <at> <at> -234,31 +234,31 <at> <at> if Facter.value(:kernel) == "windows" end Facter.add("SwapSize") do - confine :kernel => :dragonfly - setcode do - page_size = Facter::Util::Resolution.exec("/sbin/sysctl -n hw.pagesize").to_f - swaptotal = Facter::Util::Resolution.exec("/sbin/sysctl -n vm.swap_size").to_f * page_size - Facter::Memory.scale_number(swaptotal.to_f,"") - end + confine :kernel => :dragonfly + setcode do + page_size = Facter::Util::Resolution.exec("/sbin/sysctl -n hw.pagesize").to_f + swaptotal = Facter::Util::Resolution.exec("/sbin/sysctl -n vm.swap_size").to_f * page_size + Facter::Memory.scale_number(swaptotal.to_f,"") + end end Facter.add("SwapFree") do - confine :kernel => :dragonfly - setcode do - page_size = Facter::Util::Resolution.exec("/sbin/sysctl -n hw.pagesize").to_f - swaptotal = Facter::Util::Resolution.exec("/sbin/sysctl -n vm.swap_size").to_f * page_size - swap_anon_use = Facter::Util::Resolution.exec("/sbin/sysctl -n vm.swap_anon_use").to_f * page_size - swap_cache_use = Facter::Util::Resolution.exec("/sbin/sysctl -n vm.swap_cache_use").to_f * page_size - swapfree = swaptotal - swap_anon_use - swap_cache_use - Facter::Memory.scale_number(swapfree.to_f,"") - end + confine :kernel => :dragonfly + setcode do + page_size = Facter::Util::Resolution.exec("/sbin/sysctl -n hw.pagesize").to_f + swaptotal = Facter::Util::Resolution.exec("/sbin/sysctl -n vm.swap_size").to_f * page_size + swap_anon_use = Facter::Util::Resolution.exec("/sbin/sysctl -n vm.swap_anon_use").to_f * page_size + swap_cache_use = Facter::Util::Resolution.exec("/sbin/sysctl -n vm.swap_cache_use").to_f * page_size + swapfree = swaptotal - swap_anon_use - swap_cache_use + Facter::Memory.scale_number(swapfree.to_f,"") + end end Facter.add("MemoryTotal") do - confine :kernel => :dragonfly - setcode do - Facter::Memory.vmstat_find_free_memory() - memtotal = Facter::Util::Resolution.exec("sysctl -n hw.physmem") - Facter::Memory.scale_number(memtotal.to_f,"") - end + confine :kernel => :dragonfly + setcode do + Facter::Memory.vmstat_find_free_memory() + memtotal = Facter::Util::Resolution.exec("sysctl -n hw.physmem") + Facter::Memory.scale_number(memtotal.to_f,"") + end end diff --git a/lib/facter/netmask.rb b/lib/facter/netmask.rb index e3979fd..bc32073 100644 --- a/lib/facter/netmask.rb +++ b/lib/facter/netmask.rb <at> <at> -18,9 +18,9 <at> <at> require 'facter/util/netmask' Facter.add("netmask") do - confine :kernel => [ :sunos, :linux, :freebsd, :openbsd, :netbsd, :darwin, :"gnu/kfreebsd", :dragonfly ] - setcode do - Facter::NetMask.get_netmask - end + confine :kernel => [ :sunos, :linux, :freebsd, :openbsd, :netbsd, :darwin, :"gnu/kfreebsd", :dragonfly ] + setcode do + Facter::NetMask.get_netmask + end end diff --git a/lib/facter/network.rb b/lib/facter/network.rb index d4faaac..9e28c6b 100644 --- a/lib/facter/network.rb +++ b/lib/facter/network.rb <at> <at> -13,9 +13,9 <at> <at> require 'facter/util/ip' Facter::Util::IP.get_interfaces.each do |interface| - Facter.add("network_" + Facter::Util::IP.alphafy(interface)) do - setcode do - Facter::Util::IP.get_network_value(interface) - end + Facter.add("network_" + Facter::Util::IP.alphafy(interface)) do + setcode do + Facter::Util::IP.get_network_value(interface) end + end end diff --git a/lib/facter/operatingsystem.rb b/lib/facter/operatingsystem.rb index eb8ad85..b1ffeb8 100644 --- a/lib/facter/operatingsystem.rb +++ b/lib/facter/operatingsystem.rb <at> <at> -14,87 +14,87 <at> <at> require 'facter/lsb' Facter.add(:operatingsystem) do - confine :kernel => :sunos - setcode do "Solaris" end + confine :kernel => :sunos + setcode do "Solaris" end end Facter.add(:operatingsystem) do - confine :kernel => :linux - setcode do - if Facter.value(:lsbdistid) == "Ubuntu" - "Ubuntu" - elsif FileTest.exists?("/etc/debian_version") - "Debian" - elsif FileTest.exists?("/etc/gentoo-release") - "Gentoo" - elsif FileTest.exists?("/etc/fedora-release") - "Fedora" - elsif FileTest.exists?("/etc/mandriva-release") - "Mandriva" - elsif FileTest.exists?("/etc/mandrake-release") - "Mandrake" - elsif FileTest.exists?("/etc/meego-release") - "MeeGo" - elsif FileTest.exists?("/etc/arch-release") - "Archlinux" - elsif FileTest.exists?("/etc/oracle-release") - "OracleLinux" - elsif FileTest.exists?("/etc/enterprise-release") - if FileTest.exists?("/etc/ovs-release") - "OVS" - else - "OEL" - end - elsif FileTest.exists?("/etc/arch-release") - "Arch" - elsif FileTest.exists?("/etc/vmware-release") - "VMWareESX" - elsif FileTest.exists?("/etc/redhat-release") - txt = File.read("/etc/redhat-release") - if txt =~ /centos/i - "CentOS" - elsif txt =~ /CERN/ - "SLC" - elsif txt =~ /scientific/i - "Scientific" - elsif txt =~ /^cloudlinux/i - "CloudLinux" - else - "RedHat" - end - elsif FileTest.exists?("/etc/SuSE-release") - txt = File.read("/etc/SuSE-release") - if txt =~ /^SUSE LINUX Enterprise Server/i - "SLES" - elsif txt =~ /^SUSE LINUX Enterprise Desktop/i - "SLED" - elsif txt =~ /^openSUSE/i - "OpenSuSE" - else - "SuSE" - end - elsif FileTest.exists?("/etc/bluewhite64-version") - "Bluewhite64" - elsif FileTest.exists?("/etc/slamd64-version") - "Slamd64" - elsif FileTest.exists?("/etc/slackware-version") - "Slackware" - elsif FileTest.exists?("/etc/alpine-release") - "Alpine" - elsif Facter.value(:lsbdistdescription) =~ /Amazon Linux/ - "Amazon" - end + confine :kernel => :linux + setcode do + if Facter.value(:lsbdistid) == "Ubuntu" + "Ubuntu" + elsif FileTest.exists?("/etc/debian_version") + "Debian" + elsif FileTest.exists?("/etc/gentoo-release") + "Gentoo" + elsif FileTest.exists?("/etc/fedora-release") + "Fedora" + elsif FileTest.exists?("/etc/mandriva-release") + "Mandriva" + elsif FileTest.exists?("/etc/mandrake-release") + "Mandrake" + elsif FileTest.exists?("/etc/meego-release") + "MeeGo" + elsif FileTest.exists?("/etc/arch-release") + "Archlinux" + elsif FileTest.exists?("/etc/oracle-release") + "OracleLinux" + elsif FileTest.exists?("/etc/enterprise-release") + if FileTest.exists?("/etc/ovs-release") + "OVS" + else + "OEL" + end + elsif FileTest.exists?("/etc/arch-release") + "Arch" + elsif FileTest.exists?("/etc/vmware-release") + "VMWareESX" + elsif FileTest.exists?("/etc/redhat-release") + txt = File.read("/etc/redhat-release") + if txt =~ /centos/i + "CentOS" + elsif txt =~ /CERN/ + "SLC" + elsif txt =~ /scientific/i + "Scientific" + elsif txt =~ /^cloudlinux/i + "CloudLinux" + else + "RedHat" + end + elsif FileTest.exists?("/etc/SuSE-release") + txt = File.read("/etc/SuSE-release") + if txt =~ /^SUSE LINUX Enterprise Server/i + "SLES" + elsif txt =~ /^SUSE LINUX Enterprise Desktop/i + "SLED" + elsif txt =~ /^openSUSE/i + "OpenSuSE" + else + "SuSE" + end + elsif FileTest.exists?("/etc/bluewhite64-version") + "Bluewhite64" + elsif FileTest.exists?("/etc/slamd64-version") + "Slamd64" + elsif FileTest.exists?("/etc/slackware-version") + "Slackware" + elsif FileTest.exists?("/etc/alpine-release") + "Alpine" + elsif Facter.value(:lsbdistdescription) =~ /Amazon Linux/ + "Amazon" end + end end Facter.add(:operatingsystem) do - confine :kernel => "VMkernel" - setcode do - "ESXi" - end + confine :kernel => "VMkernel" + setcode do + "ESXi" + end end Facter.add(:operatingsystem) do - # Default to just returning the kernel as the operating system - setcode do Facter[:kernel].value end + # Default to just returning the kernel as the operating system + setcode do Facter[:kernel].value end end diff --git a/lib/facter/operatingsystemrelease.rb b/lib/facter/operatingsystemrelease.rb index 972ffa8..c4d7862 100644 --- a/lib/facter/operatingsystemrelease.rb +++ b/lib/facter/operatingsystemrelease.rb <at> <at> -17,112 +17,112 <at> <at> # Facter.add(:operatingsystemrelease) do - confine :operatingsystem => %w{CentOS Fedora oel ovs OracleLinux RedHat MeeGo Scientific SLC CloudLinux} - setcode do - case Facter.value(:operatingsystem) - when "CentOS", "RedHat", "Scientific", "SLC", "CloudLinux" - releasefile = "/etc/redhat-release" - when "Fedora" - releasefile = "/etc/fedora-release" - when "MeeGo" - releasefile = "/etc/meego-release" - when "OracleLinux" - releasefile = "/etc/oracle-release" - when "OEL", "oel" - releasefile = "/etc/enterprise-release" - when "OVS", "ovs" - releasefile = "/etc/ovs-release" - end - File::open(releasefile, "r") do |f| - line = f.readline.chomp - if line =~ /\(Rawhide\)$/ - "Rawhide" - elsif line =~ /release (\d[\d.]*)/ - $1 - end - end + confine :operatingsystem => %w{CentOS Fedora oel ovs OracleLinux RedHat MeeGo Scientific SLC CloudLinux} + setcode do + case Facter.value(:operatingsystem) + when "CentOS", "RedHat", "Scientific", "SLC", "CloudLinux" + releasefile = "/etc/redhat-release" + when "Fedora" + releasefile = "/etc/fedora-release" + when "MeeGo" + releasefile = "/etc/meego-release" + when "OracleLinux" + releasefile = "/etc/oracle-release" + when "OEL", "oel" + releasefile = "/etc/enterprise-release" + when "OVS", "ovs" + releasefile = "/etc/ovs-release" + end + File::open(releasefile, "r") do |f| + line = f.readline.chomp + if line =~ /\(Rawhide\)$/ + "Rawhide" + elsif line =~ /release (\d[\d.]*)/ + $1 + end end + end end Facter.add(:operatingsystemrelease) do - confine :operatingsystem => %w{Debian} - setcode do - release = Facter::Util::Resolution.exec('cat /etc/debian_version') - end + confine :operatingsystem => %w{Debian} + setcode do + release = Facter::Util::Resolution.exec('cat /etc/debian_version') + end end Facter.add(:operatingsystemrelease) do - confine :operatingsystem => %w{Ubuntu} - setcode do - release = Facter::Util::Resolution.exec('cat /etc/issue') - if release =~ /Ubuntu (\d+.\d+)/ - $1 - end + confine :operatingsystem => %w{Ubuntu} + setcode do + release = Facter::Util::Resolution.exec('cat /etc/issue') + if release =~ /Ubuntu (\d+.\d+)/ + $1 end + end end Facter.add(:operatingsystemrelease) do - confine :operatingsystem => %w{SLES SLED OpenSuSE} - setcode do - releasefile = Facter::Util::Resolution.exec('cat /etc/SuSE-release') - if releasefile =~ /^VERSION\s*=\s*(\d+)/ - releasemajor = $1 - if releasefile =~ /^PATCHLEVEL\s*=\s*(\d+)/ - releaseminor = $1 - elsif releasefile =~ /^VERSION\s=.*.(\d+)/ - releaseminor = $1 - else - releaseminor = "0" - end - releasemajor + "." + releaseminor - else - "unknown" - end + confine :operatingsystem => %w{SLES SLED OpenSuSE} + setcode do + releasefile = Facter::Util::Resolution.exec('cat /etc/SuSE-release') + if releasefile =~ /^VERSION\s*=\s*(\d+)/ + releasemajor = $1 + if releasefile =~ /^PATCHLEVEL\s*=\s*(\d+)/ + releaseminor = $1 + elsif releasefile =~ /^VERSION\s=.*.(\d+)/ + releaseminor = $1 + else + releaseminor = "0" + end + releasemajor + "." + releaseminor + else + "unknown" end + end end Facter.add(:operatingsystemrelease) do - confine :operatingsystem => %w{Slackware} - setcode do - release = Facter::Util::Resolution.exec('cat /etc/slackware-version') - if release =~ /Slackware ([0-9.]+)/ - $1 - end + confine :operatingsystem => %w{Slackware} + setcode do + release = Facter::Util::Resolution.exec('cat /etc/slackware-version') + if release =~ /Slackware ([0-9.]+)/ + $1 end + end end Facter.add(:operatingsystemrelease) do - confine :operatingsystem => %w{Bluewhite64} - setcode do - releasefile = Facter::Util::Resolution.exec('cat /etc/bluewhite64-version') - if releasefile =~ /^\s*\w+\s+(\d+)\.(\d+)/ - $1 + "." + $2 - else - "unknown" - end + confine :operatingsystem => %w{Bluewhite64} + setcode do + releasefile = Facter::Util::Resolution.exec('cat /etc/bluewhite64-version') + if releasefile =~ /^\s*\w+\s+(\d+)\.(\d+)/ + $1 + "." + $2 + else + "unknown" end + end end Facter.add(:operatingsystemrelease) do - confine :operatingsystem => %w{VMwareESX} - setcode do - release = Facter::Util::Resolution.exec('vmware -v') - if release =~ /VMware ESX .*?(\d.*)/ - $1 - end + confine :operatingsystem => %w{VMwareESX} + setcode do + release = Facter::Util::Resolution.exec('vmware -v') + if release =~ /VMware ESX .*?(\d.*)/ + $1 end + end end Facter.add(:operatingsystemrelease) do - confine :operatingsystem => %w{Slamd64} - setcode do - releasefile = Facter::Util::Resolution.exec('cat /etc/slamd64-version') - if releasefile =~ /^\s*\w+\s+(\d+)\.(\d+)/ - $1 + "." + $2 - else - "unknown" - end + confine :operatingsystem => %w{Slamd64} + setcode do + releasefile = Facter::Util::Resolution.exec('cat /etc/slamd64-version') + if releasefile =~ /^\s*\w+\s+(\d+)\.(\d+)/ + $1 + "." + $2 + else + "unknown" end + end end Facter.add(:operatingsystemrelease) do <at> <at> -133,10 +133,10 <at> <at> Facter.add(:operatingsystemrelease) do end Facter.add(:operatingsystemrelease) do - confine :operatingsystem => %W{Amazon} - setcode do Facter[:lsbdistrelease].value end + confine :operatingsystem => %W{Amazon} + setcode do Facter[:lsbdistrelease].value end end Facter.add(:operatingsystemrelease) do - setcode do Facter[:kernelrelease].value end + setcode do Facter[:kernelrelease].value end end diff --git a/lib/facter/path.rb b/lib/facter/path.rb index 71df6cd..5c45a58 100644 --- a/lib/facter/path.rb +++ b/lib/facter/path.rb <at> <at> -8,7 +8,7 <at> <at> # Facter.add(:path) do - setcode do - ENV['PATH'] - end + setcode do + ENV['PATH'] + end end diff --git a/lib/facter/processor.rb b/lib/facter/processor.rb index 2ef7dd9..1de20f7 100644 --- a/lib/facter/processor.rb +++ b/lib/facter/processor.rb <at> <at> -57,10 +57,10 <at> <at> Facter.add("ProcessorCount") do end Facter.add("Processor") do - confine :kernel => :openbsd - setcode do - Facter::Util::Resolution.exec("uname -p") - end + confine :kernel => :openbsd + setcode do + Facter::Util::Resolution.exec("uname -p") + end end Facter.add("ProcessorCount") do diff --git a/lib/facter/ps.rb b/lib/facter/ps.rb index 1d4f01c..5d8cb0a 100644 --- a/lib/facter/ps.rb +++ b/lib/facter/ps.rb <at> <at> -11,12 +11,12 <at> <at> # Facter.add(:ps) do - setcode do 'ps -ef' end + setcode do 'ps -ef' end end Facter.add(:ps) do - confine :operatingsystem => %w{FreeBSD NetBSD OpenBSD Darwin DragonFly} - setcode do 'ps auxwww' end + confine :operatingsystem => %w{FreeBSD NetBSD OpenBSD Darwin DragonFly} + setcode do 'ps auxwww' end end Facter.add(:ps) do diff --git a/lib/facter/puppetversion.rb b/lib/facter/puppetversion.rb index 01422f0..837a6e8 100644 --- a/lib/facter/puppetversion.rb +++ b/lib/facter/puppetversion.rb <at> <at> -9,12 +9,12 <at> <at> # Facter.add(:puppetversion) do - setcode do - begin - require 'puppet' - Puppet::PUPPETVERSION.to_s - rescue LoadError - nil - end + setcode do + begin + require 'puppet' + Puppet::PUPPETVERSION.to_s + rescue LoadError + nil end + end end diff --git a/lib/facter/rubysitedir.rb b/lib/facter/rubysitedir.rb index 9973329..73aa215 100644 --- a/lib/facter/rubysitedir.rb +++ b/lib/facter/rubysitedir.rb <at> <at> -9,10 +9,10 <at> <at> # Facter.add :rubysitedir do - setcode do - version = RUBY_VERSION.to_s.sub(/\.\d+$/, '') - $:.find do |dir| - dir =~ /#{File.join("site_ruby", version)}$/ - end + setcode do + version = RUBY_VERSION.to_s.sub(/\.\d+$/, '') + $:.find do |dir| + dir =~ /#{File.join("site_ruby", version)}$/ end + end end diff --git a/lib/facter/rubyversion.rb b/lib/facter/rubyversion.rb index e578400..32bf254 100644 --- a/lib/facter/rubyversion.rb +++ b/lib/facter/rubyversion.rb <at> <at> -8,5 +8,5 <at> <at> # Facter.add(:rubyversion) do - setcode { RUBY_VERSION.to_s } + setcode { RUBY_VERSION.to_s } end diff --git a/lib/facter/ssh.rb b/lib/facter/ssh.rb index 7bdf803..6aa7e08 100644 --- a/lib/facter/ssh.rb +++ b/lib/facter/ssh.rb <at> <at> -12,20 +12,20 <at> <at> ## ["/etc/ssh","/usr/local/etc/ssh","/etc","/usr/local/etc"].each do |dir| - {"SSHDSAKey" => "ssh_host_dsa_key.pub", "SSHRSAKey" => "ssh_host_rsa_key.pub", "SSHECDSAKey" => "ssh_host_ecdsa_key.pub"}.each do |name,file| - Facter.add(name) do - setcode do - value = nil - filepath = File.join(dir,file) - if FileTest.file?(filepath) - begin - File.open(filepath) { |f| value = f.read.chomp.split(/\s+/)[1] } - rescue - value = nil - end - end - value - end # end of proc - end # end of add - end # end of hash each + {"SSHDSAKey" => "ssh_host_dsa_key.pub", "SSHRSAKey" => "ssh_host_rsa_key.pub", "SSHECDSAKey" => "ssh_host_ecdsa_key.pub"}.each do |name,file| + Facter.add(name) do + setcode do + value = nil + filepath = File.join(dir,file) + if FileTest.file?(filepath) + begin + File.open(filepath) { |f| value = f.read.chomp.split(/\s+/)[1] } + rescue + value = nil + end + end + value + end # end of proc + end # end of add + end # end of hash each end # end of dir each diff --git a/lib/facter/timezone.rb b/lib/facter/timezone.rb index 462c9ba..246d295 100644 --- a/lib/facter/timezone.rb +++ b/lib/facter/timezone.rb <at> <at> -8,7 +8,7 <at> <at> # Facter.add("timezone") do - setcode do - Time.new.zone - end + setcode do + Time.new.zone + end end diff --git a/lib/facter/uniqueid.rb b/lib/facter/uniqueid.rb index ac13003..6c1c563 100644 --- a/lib/facter/uniqueid.rb +++ b/lib/facter/uniqueid.rb <at> <at> -1,4 +1,4 <at> <at> Facter.add(:uniqueid) do - setcode 'hostid' - confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS Scientific SLC SuSE SLES Debian Ubuntu Gentoo AIX OEL OracleLinux OVS GNU/kFreeBSD} + setcode 'hostid' + confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS Scientific SLC SuSE SLES Debian Ubuntu Gentoo AIX OEL OracleLinux OVS GNU/kFreeBSD} end diff --git a/lib/facter/util/collection.rb b/lib/facter/util/collection.rb index b3d3a45..d165ff0 100644 --- a/lib/facter/util/collection.rb +++ b/lib/facter/util/collection.rb <at> <at> -5,126 +5,126 <at> <at> require 'facter/util/loader' # Manage which facts exist and how we access them. Largely just a wrapper # around a hash of facts. class Facter::Util::Collection - # Return a fact object by name. If you use this, you still have to call - # 'value' on it to retrieve the actual value. - def [](name) - value(name) - end - - # Add a resolution mechanism for a named fact. This does not distinguish - # between adding a new fact and adding a new way to resolve a fact. - def add(name, options = {}, &block) - name = canonize(name) + # Return a fact object by name. If you use this, you still have to call + # 'value' on it to retrieve the actual value. + def [](name) + value(name) + end - unless fact = <at> facts[name] - fact = Facter::Util::Fact.new(name) + # Add a resolution mechanism for a named fact. This does not distinguish + # between adding a new fact and adding a new way to resolve a fact. + def add(name, options = {}, &block) + name = canonize(name) - <at> facts[name] = fact - end + unless fact = <at> facts[name] + fact = Facter::Util::Fact.new(name) - # Set any fact-appropriate options. - options.each do |opt, value| - method = opt.to_s + "=" - if fact.respond_to?(method) - fact.send(method, value) - options.delete(opt) - end - end + <at> facts[name] = fact + end - if block - resolve = fact.add(&block) - # Set any resolve-appropriate options - options.each do |opt, value| - method = opt.to_s + "=" - if resolve.respond_to?(method) - resolve.send(method, value) - options.delete(opt) - end - end - end + # Set any fact-appropriate options. + options.each do |opt, value| + method = opt.to_s + "=" + if fact.respond_to?(method) + fact.send(method, value) + options.delete(opt) + end + end - unless options.empty? - raise ArgumentError, "Invalid facter option(s) %s" % options.keys.collect { |k| k.to_s }.join(",") + if block + resolve = fact.add(&block) + # Set any resolve-appropriate options + options.each do |opt, value| + method = opt.to_s + "=" + if resolve.respond_to?(method) + resolve.send(method, value) + options.delete(opt) end + end + end - return fact + unless options.empty? + raise ArgumentError, "Invalid facter option(s) %s" % options.keys.collect { |k| k.to_s }.join(",") end - include Enumerable + return fact + end - # Iterate across all of the facts. - def each - <at> facts.each do |name, fact| - value = fact.value - unless value.nil? - yield name.to_s, value - end - end + include Enumerable + + # Iterate across all of the facts. + def each + <at> facts.each do |name, fact| + value = fact.value + unless value.nil? + yield name.to_s, value + end end + end - # Return a fact by name. - def fact(name) - name = canonize(name) + # Return a fact by name. + def fact(name) + name = canonize(name) - # Try to load the fact if necessary - loader.load(name) unless <at> facts[name] + # Try to load the fact if necessary + loader.load(name) unless <at> facts[name] - # Try HARDER - loader.load_all unless <at> facts[name] + # Try HARDER + loader.load_all unless <at> facts[name] - <at> facts[name] - end + <at> facts[name] + end - # Flush all cached values. - def flush - <at> facts.each { |name, fact| fact.flush } - end + # Flush all cached values. + def flush + <at> facts.each { |name, fact| fact.flush } + end - def initialize - <at> facts = Hash.new - end + def initialize + <at> facts = Hash.new + end - # Return a list of all of the facts. - def list - return <at> facts.keys - end + # Return a list of all of the facts. + def list + return <at> facts.keys + end - # Load all known facts. - def load_all - loader.load_all - end + # Load all known facts. + def load_all + loader.load_all + end - # The thing that loads facts if we don't have them. - def loader - unless defined?( <at> loader) - <at> loader = Facter::Util::Loader.new - end - <at> loader + # The thing that loads facts if we don't have them. + def loader + unless defined?( <at> loader) + <at> loader = Facter::Util::Loader.new end - - # Return a hash of all of our facts. - def to_hash - <at> facts.inject({}) do |h, ary| - value = ary[1].value - if ! value.nil? - # For backwards compatibility, convert the fact name to a string. - h[ary[0].to_s] = value - end - h - end + <at> loader + end + + # Return a hash of all of our facts. + def to_hash + <at> facts.inject({}) do |h, ary| + value = ary[1].value + if ! value.nil? + # For backwards compatibility, convert the fact name to a string. + h[ary[0].to_s] = value + end + h end + end - def value(name) - if fact = fact(name) - fact.value - end + def value(name) + if fact = fact(name) + fact.value end + end - private + private - # Provide a consistent means of getting the exact same fact name - # every time. - def canonize(name) - name.to_s.downcase.to_sym - end + # Provide a consistent means of getting the exact same fact name + # every time. + def canonize(name) + name.to_s.downcase.to_sym + end end diff --git a/lib/facter/util/confine.rb b/lib/facter/util/confine.rb index 4cbb32c..1f9e11e 100644 --- a/lib/facter/util/confine.rb +++ b/lib/facter/util/confine.rb <at> <at> -4,38 +4,38 <at> <at> require 'facter/util/values' class Facter::Util::Confine - attr_accessor :fact, :values - - include Facter::Util::Values - - # Add the restriction. Requires the fact name, an operator, and the value - # we're comparing to. - def initialize(fact, *values) - raise ArgumentError, "The fact name must be provided" unless fact - raise ArgumentError, "One or more values must be provided" if values.empty? - <at> fact = fact - <at> values = values + attr_accessor :fact, :values + + include Facter::Util::Values + + # Add the restriction. Requires the fact name, an operator, and the value + # we're comparing to. + def initialize(fact, *values) + raise ArgumentError, "The fact name must be provided" unless fact + raise ArgumentError, "One or more values must be provided" if values.empty? + <at> fact = fact + <at> values = values + end + + def to_s + return "'%s' '%s'" % [ <at> fact, <at> values.join(",")] + end + + # Evaluate the fact, returning true or false. + def true? + unless fact = Facter[ <at> fact] + Facter.debug "No fact for %s" % <at> fact + return false end + value = convert(fact.value) - def to_s - return "'%s' '%s'" % [ <at> fact, <at> values.join(",")] - end + return false if value.nil? - # Evaluate the fact, returning true or false. - def true? - unless fact = Facter[ <at> fact] - Facter.debug "No fact for %s" % <at> fact - return false - end - value = convert(fact.value) - - return false if value.nil? - - <at> values.each do |v| - v = convert(v) - next unless v.class == value.class - return true if value == v - end - return false + <at> values.each do |v| + v = convert(v) + next unless v.class == value.class + return true if value == v end + return false + end end diff --git a/lib/facter/util/fact.rb b/lib/facter/util/fact.rb index 935b3c1..070087b 100644 --- a/lib/facter/util/fact.rb +++ b/lib/facter/util/fact.rb <at> <at> -2,119 +2,119 <at> <at> require 'facter' require 'facter/util/resolution' class Facter::Util::Fact - TIMEOUT = 5 + TIMEOUT = 5 + + attr_accessor :name, :ldapname + + # Create a new fact, with no resolution mechanisms. + def initialize(name, options = {}) + <at> name = name.to_s.downcase.intern + + # LAK:NOTE: This is slow for many options, but generally we won't have any and at + # worst we'll have one. If we add more, this should be made more efficient. + options.each do |name, value| + case name + when :ldapname; self.ldapname = value + else + raise ArgumentError, "Invalid fact option '%s'" % name + end + end - attr_accessor :name, :ldapname + <at> ldapname ||= <at> name.to_s - # Create a new fact, with no resolution mechanisms. - def initialize(name, options = {}) - <at> name = name.to_s.downcase.intern + <at> resolves = [] + <at> searching = false - # LAK:NOTE: This is slow for many options, but generally we won't have any and at - # worst we'll have one. If we add more, this should be made more efficient. - options.each do |name, value| - case name - when :ldapname; self.ldapname = value - else - raise ArgumentError, "Invalid fact option '%s'" % name - end - end + <at> value = nil + end - <at> ldapname ||= <at> name.to_s + # Add a new resolution mechanism. This requires a block, which will then + # be evaluated in the context of the new mechanism. + def add(&block) + raise ArgumentError, "You must pass a block to Fact<instance>.add" unless block_given? - <at> resolves = [] - <at> searching = false + resolve = Facter::Util::Resolution.new( <at> name) - <at> value = nil - end + resolve.instance_eval(&block) - # Add a new resolution mechanism. This requires a block, which will then - # be evaluated in the context of the new mechanism. - def add(&block) - raise ArgumentError, "You must pass a block to Fact<instance>.add" unless block_given? + <at> resolves << resolve - resolve = Facter::Util::Resolution.new( <at> name) + # Immediately sort the resolutions, so that we always have + # a sorted list for looking up values. + <at> resolves.sort! { |a, b| b.weight <=> a.weight } - resolve.instance_eval(&block) + return resolve + end - <at> resolves << resolve + # Flush any cached values. + def flush + <at> value = nil + <at> suitable = nil + end - # Immediately sort the resolutions, so that we always have - # a sorted list for looking up values. - <at> resolves.sort! { |a, b| b.weight <=> a.weight } + # Return the value for a given fact. Searches through all of the mechanisms + # and returns either the first value or nil. + def value + return <at> value if <at> value - return resolve + if <at> resolves.length == 0 + Facter.debug "No resolves for %s" % <at> name + return nil end - # Flush any cached values. - def flush - <at> value = nil - <at> suitable = nil - end + searching do + <at> value = nil - # Return the value for a given fact. Searches through all of the mechanisms - # and returns either the first value or nil. - def value - return <at> value if <at> value - - if <at> resolves.length == 0 - Facter.debug "No resolves for %s" % <at> name - return nil - end - - searching do - <at> value = nil - - foundsuits = false - <at> value = <at> resolves.inject(nil) { |result, resolve| - next unless resolve.suitable? - foundsuits = true - - tmp = resolve.value - - break tmp unless tmp.nil? or tmp == "" - } - - unless foundsuits - Facter.debug "Found no suitable resolves of %s for %s" % [ <at> resolves.length, <at> name] - end - end - - if <at> value.nil? - # nothing - Facter.debug("value for %s is still nil" % <at> name) - return nil - else - return <at> value - end - end + foundsuits = false + <at> value = <at> resolves.inject(nil) { |result, resolve| + next unless resolve.suitable? + foundsuits = true - private + tmp = resolve.value - # Are we in the midst of a search? - def searching? - <at> searching + break tmp unless tmp.nil? or tmp == "" + } + + unless foundsuits + Facter.debug "Found no suitable resolves of %s for %s" % [ <at> resolves.length, <at> name] + end + end + + if <at> value.nil? + # nothing + Facter.debug("value for %s is still nil" % <at> name) + return nil + else + return <at> value + end + end + + private + + # Are we in the midst of a search? + def searching? + <at> searching + end + + # Lock our searching process, so we never ge stuck in recursion. + def searching + if searching? + Facter.debug "Caught recursion on %s" % <at> name + + # return a cached value if we've got it + if <at> value + return <at> value + else + return nil + end end - # Lock our searching process, so we never ge stuck in recursion. - def searching - if searching? - Facter.debug "Caught recursion on %s" % <at> name - - # return a cached value if we've got it - if <at> value - return <at> value - else - return nil - end - end - - # If we've gotten this far, we're not already searching, so go ahead and do so. - <at> searching = true - begin - yield - ensure - <at> searching = false - end + # If we've gotten this far, we're not already searching, so go ahead and do so. + <at> searching = true + begin + yield + ensure + <at> searching = false end + end end diff --git a/lib/facter/util/ip.rb b/lib/facter/util/ip.rb index 0e4af16..b7395e0 100644 --- a/lib/facter/util/ip.rb +++ b/lib/facter/util/ip.rb <at> <at> -1,202 +1,202 <at> <at> # A base module for collecting IP-related # information from all kinds of platforms. module Facter::Util::IP - # A map of all the different regexes that work for - # a given platform or set of platforms. - REGEX_MAP = { - :linux => { - :ipaddress => /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, - :ipaddress6 => /inet6 addr: ((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/, - :macaddress => /(?:ether|HWaddr)\s+(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/, - :netmask => /Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ - }, - :bsd => { - :aliases => [:openbsd, :netbsd, :freebsd, :darwin, :"gnu/kfreebsd", :dragonfly], - :ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, - :ipaddress6 => /inet6 ((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/, - :macaddress => /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/, - :netmask => /netmask\s+0x(\w{8})/ - }, - :sunos => { - :ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, - :ipaddress6 => /inet6 ((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/, - :macaddress => /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/, - :netmask => /netmask\s+(\w{8})/ - }, - :"hp-ux" => { - :ipaddress => /\s+inet (\S+)\s.*/, - :macaddress => /(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/, - :netmask => /.*\s+netmask (\S+)\s.*/ - }, - :windows => { - :ipaddress => /\s+IP Address:\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, - :ipaddress6 => /Address ((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/, - :netmask => /\s+Subnet Prefix:\s+\S+\s+\(mask ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\)/ - } + # A map of all the different regexes that work for + # a given platform or set of platforms. + REGEX_MAP = { + :linux => { + :ipaddress => /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, + :ipaddress6 => /inet6 addr: ((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/, + :macaddress => /(?:ether|HWaddr)\s+(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/, + :netmask => /Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ + }, + :bsd => { + :aliases => [:openbsd, :netbsd, :freebsd, :darwin, :"gnu/kfreebsd", :dragonfly], + :ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, + :ipaddress6 => /inet6 ((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/, + :macaddress => /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/, + :netmask => /netmask\s+0x(\w{8})/ + }, + :sunos => { + :ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, + :ipaddress6 => /inet6 ((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/, + :macaddress => /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/, + :netmask => /netmask\s+(\w{8})/ + }, + :"hp-ux" => { + :ipaddress => /\s+inet (\S+)\s.*/, + :macaddress => /(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/, + :netmask => /.*\s+netmask (\S+)\s.*/ + }, + :windows => { + :ipaddress => /\s+IP Address:\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, + :ipaddress6 => /Address ((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/, + :netmask => /\s+Subnet Prefix:\s+\S+\s+\(mask ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\)/ } - - # Convert an interface name into purely alphanumeric characters. - def self.alphafy(interface) - interface.gsub(/[^a-z0-9_]/i, '_') + } + + # Convert an interface name into purely alphanumeric characters. + def self.alphafy(interface) + interface.gsub(/[^a-z0-9_]/i, '_') + end + + def self.convert_from_hex?(kernel) + kernels_to_convert = [:sunos, :openbsd, :netbsd, :freebsd, :darwin, :"hp-ux", :"gnu/kfreebsd", :dragonfly] + kernels_to_convert.include?(kernel) + end + + def self.supported_platforms + REGEX_MAP.inject([]) do |result, tmp| + key, map = tmp + if map[:aliases] + result += map[:aliases] + else + result << key + end + result end - - def self.convert_from_hex?(kernel) - kernels_to_convert = [:sunos, :openbsd, :netbsd, :freebsd, :darwin, :"hp-ux", :"gnu/kfreebsd", :dragonfly] - kernels_to_convert.include?(kernel) + end + + def self.get_interfaces + return [] unless output = Facter::Util::IP.get_all_interface_output() + + # windows interface names contain spaces and are quoted and can appear multiple + # times as ipv4 and ipv6 + return output.scan(/\s* connected\s*(\S.*)/).flatten.uniq if Facter.value(:kernel) == 'windows' + + # Our regex appears to be stupid, in that it leaves colons sitting + # at the end of interfaces. So, we have to trim those trailing + # characters. I tried making the regex better but supporting all + # platforms with a single regex is probably a bit too much. + output.scan(/^\S+/).collect { |i| i.sub(/:$/, '') }.uniq + end + + def self.get_all_interface_output + case Facter.value(:kernel) + when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin', 'GNU/kFreeBSD', 'DragonFly' + output = %x{/sbin/ifconfig -a} + when 'SunOS' + output = %x{/usr/sbin/ifconfig -a} + when 'HP-UX' + output = %x{/bin/netstat -in | sed -e 1d} + when 'windows' + output = %x|#{ENV['SYSTEMROOT']}/system32/netsh interface ip show interface| + output += %x|#{ENV['SYSTEMROOT']}/system32/netsh interface ipv6 show interface| end - - def self.supported_platforms - REGEX_MAP.inject([]) do |result, tmp| - key, map = tmp - if map[:aliases] - result += map[:aliases] - else - result << key - end - result - end + output + end + + def self.get_single_interface_output(interface) + output = "" + case Facter.value(:kernel) + when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin', 'GNU/kFreeBSD', 'DragonFly' + output = %x{/sbin/ifconfig #{interface}} + when 'SunOS' + output = %x{/usr/sbin/ifconfig #{interface}} + when 'HP-UX' + mac = "" + ifc = %x{/usr/sbin/ifconfig #{interface}} + %x{/usr/sbin/lanscan}.scan(/(\dx\S+).*UP\s+(\w+\d+)/).each {|i| mac = i[0] if i.include?(interface) } + mac = mac.sub(/0x(\S+)/,'\1').scan(/../).join(":") + output = ifc + "\n" + mac end + output + end - def self.get_interfaces - return [] unless output = Facter::Util::IP.get_all_interface_output() - - # windows interface names contain spaces and are quoted and can appear multiple - # times as ipv4 and ipv6 - return output.scan(/\s* connected\s*(\S.*)/).flatten.uniq if Facter.value(:kernel) == 'windows' + def self.get_output_for_interface_and_label(interface, label) + return get_single_interface_output(interface) unless Facter.value(:kernel) == 'windows' - # Our regex appears to be stupid, in that it leaves colons sitting - # at the end of interfaces. So, we have to trim those trailing - # characters. I tried making the regex better but supporting all - # platforms with a single regex is probably a bit too much. - output.scan(/^\S+/).collect { |i| i.sub(/:$/, '') }.uniq + if label == 'ipaddress6' + output = %x|#{ENV['SYSTEMROOT']}/system32/netsh interface ipv6 show address \"#{interface}\"| + else + output = %x|#{ENV['SYSTEMROOT']}/system32/netsh interface ip show address \"#{interface}\"| end + output + end - def self.get_all_interface_output - case Facter.value(:kernel) - when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin', 'GNU/kFreeBSD', 'DragonFly' - output = %x{/sbin/ifconfig -a} - when 'SunOS' - output = %x{/usr/sbin/ifconfig -a} - when 'HP-UX' - output = %x{/bin/netstat -in | sed -e 1d} - when 'windows' - output = %x|#{ENV['SYSTEMROOT']}/system32/netsh interface ip show interface| - output += %x|#{ENV['SYSTEMROOT']}/system32/netsh interface ipv6 show interface| - end - output + def self.get_bonding_master(interface) + if Facter.value(:kernel) != 'Linux' + return nil end - - def self.get_single_interface_output(interface) - output = "" - case Facter.value(:kernel) - when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin', 'GNU/kFreeBSD', 'DragonFly' - output = %x{/sbin/ifconfig #{interface}} - when 'SunOS' - output = %x{/usr/sbin/ifconfig #{interface}} - when 'HP-UX' - mac = "" - ifc = %x{/usr/sbin/ifconfig #{interface}} - %x{/usr/sbin/lanscan}.scan(/(\dx\S+).*UP\s+(\w+\d+)/).each {|i| mac = i[0] if i.include?(interface) } - mac = mac.sub(/0x(\S+)/,'\1').scan(/../).join(":") - output = ifc + "\n" + mac - end - output + # We need ip instead of ifconfig because it will show us + # the bonding master device. + if not FileTest.executable?("/sbin/ip") + return nil end - - def self.get_output_for_interface_and_label(interface, label) - return get_single_interface_output(interface) unless Facter.value(:kernel) == 'windows' - - if label == 'ipaddress6' - output = %x|#{ENV['SYSTEMROOT']}/system32/netsh interface ipv6 show address \"#{interface}\"| - else - output = %x|#{ENV['SYSTEMROOT']}/system32/netsh interface ip show address \"#{interface}\"| - end - output + # A bonding interface can never be an alias interface. Alias + # interfaces do have a colon in their name and the ip link show + # command throws an error message when we pass it an alias + # interface. + if interface =~ /:/ + return nil end - - def self.get_bonding_master(interface) - if Facter.value(:kernel) != 'Linux' - return nil - end - # We need ip instead of ifconfig because it will show us - # the bonding master device. - if not FileTest.executable?("/sbin/ip") - return nil - end - # A bonding interface can never be an alias interface. Alias - # interfaces do have a colon in their name and the ip link show - # command throws an error message when we pass it an alias - # interface. - if interface =~ /:/ - return nil - end - regex = /SLAVE[,>].* (bond[0-9]+)/ - ethbond = regex.match(%x{/sbin/ip link show #{interface}}) - if ethbond - device = ethbond[1] - else - device = nil - end - device + regex = /SLAVE[,>].* (bond[0-9]+)/ + ethbond = regex.match(%x{/sbin/ip link show #{interface}}) + if ethbond + device = ethbond[1] + else + device = nil end + device + end - def self.get_interface_value(interface, label) - tmp1 = [] - - kernel = Facter.value(:kernel).downcase.to_sym + def self.get_interface_value(interface, label) + tmp1 = [] - # If it's not directly in the map or aliased in the map, then we don't know how to deal with it. - unless map = REGEX_MAP[kernel] || REGEX_MAP.values.find { |tmp| tmp[:aliases] and tmp[:aliases].include?(kernel) } - return [] - end + kernel = Facter.value(:kernel).downcase.to_sym - # Pull the correct regex out of the map. - regex = map[label.to_sym] - - # Linux changes the MAC address reported via ifconfig when an ethernet interface - # becomes a slave of a bonding device to the master MAC address. - # We have to dig a bit to get the original/real MAC address of the interface. - bonddev = get_bonding_master(interface) - if label == 'macaddress' and bonddev - bondinfo = IO.readlines("/proc/net/bonding/#{bonddev}") - hwaddrre = /^Slave Interface: #{interface}\n[^\n].+?\nPermanent HW addr: (([0-9a-fA-F]{2}:?)*)$/m - value = hwaddrre.match(bondinfo.to_s)[1].upcase - else - output_int = get_output_for_interface_and_label(interface, label) - - output_int.each_line do |s| - if s =~ regex - value = $1 - if label == 'netmask' && convert_from_hex?(kernel) - value = value.scan(/../).collect do |byte| byte.to_i(16) end.join('.') - end - tmp1.push(value) - end - end + # If it's not directly in the map or aliased in the map, then we don't know how to deal with it. + unless map = REGEX_MAP[kernel] || REGEX_MAP.values.find { |tmp| tmp[:aliases] and tmp[:aliases].include?(kernel) } + return [] + end - if tmp1 - value = tmp1.shift + # Pull the correct regex out of the map. + regex = map[label.to_sym] + + # Linux changes the MAC address reported via ifconfig when an ethernet interface + # becomes a slave of a bonding device to the master MAC address. + # We have to dig a bit to get the original/real MAC address of the interface. + bonddev = get_bonding_master(interface) + if label == 'macaddress' and bonddev + bondinfo = IO.readlines("/proc/net/bonding/#{bonddev}") + hwaddrre = /^Slave Interface: #{interface}\n[^\n].+?\nPermanent HW addr: (([0-9a-fA-F]{2}:?)*)$/m + value = hwaddrre.match(bondinfo.to_s)[1].upcase + else + output_int = get_output_for_interface_and_label(interface, label) + + output_int.each_line do |s| + if s =~ regex + value = $1 + if label == 'netmask' && convert_from_hex?(kernel) + value = value.scan(/../).collect do |byte| byte.to_i(16) end.join('.') end + tmp1.push(value) end + end + + if tmp1 + value = tmp1.shift + end end + end - def self.get_network_value(interface) - require 'ipaddr' + def self.get_network_value(interface) + require 'ipaddr' - ipaddress = get_interface_value(interface, "ipaddress") - netmask = get_interface_value(interface, "netmask") + ipaddress = get_interface_value(interface, "ipaddress") + netmask = get_interface_value(interface, "netmask") - if ipaddress && netmask - ip = IPAddr.new(ipaddress, Socket::AF_INET) - subnet = IPAddr.new(netmask, Socket::AF_INET) - network = ip.mask(subnet.to_s).to_s - end + if ipaddress && netmask + ip = IPAddr.new(ipaddress, Socket::AF_INET) + subnet = IPAddr.new(netmask, Socket::AF_INET) + network = ip.mask(subnet.to_s).to_s end + end - def self.get_arp_value(interface) - arp = Facter::Util::Resolution.exec("arp -en -i #{interface} | sed -e 1d") - if arp =~ /^\S+\s+\w+\s+(\S+)\s+\w\s+\S+$/ - return $1 - end + def self.get_arp_value(interface) + arp = Facter::Util::Resolution.exec("arp -en -i #{interface} | sed -e 1d") + if arp =~ /^\S+\s+\w+\s+(\S+)\s+\w\s+\S+$/ + return $1 end + end end diff --git a/lib/facter/util/loader.rb b/lib/facter/util/loader.rb index 29a1de0..4bdc82f 100644 --- a/lib/facter/util/loader.rb +++ b/lib/facter/util/loader.rb <at> <at> -3,110 +3,110 <at> <at> require 'facter' # Load facts on demand. class Facter::Util::Loader - def initialize - <at> loaded = [] + def initialize + <at> loaded = [] + end + + # Load all resolutions for a single fact. + def load(fact) + # Now load from the search path + shortname = fact.to_s.downcase + load_env(shortname) + + filename = shortname + ".rb" + search_path.each do |dir| + # Load individual files + file = File.join(dir, filename) + + load_file(file) if FileTest.exist?(file) + + # And load any directories matching the name + factdir = File.join(dir, shortname) + load_dir(factdir) if FileTest.directory?(factdir) end + end - # Load all resolutions for a single fact. - def load(fact) - # Now load from the search path - shortname = fact.to_s.downcase - load_env(shortname) + # Load all facts from all directories. + def load_all + return if defined?( <at> loaded_all) - filename = shortname + ".rb" - search_path.each do |dir| - # Load individual files - file = File.join(dir, filename) + load_env - load_file(file) if FileTest.exist?(file) + search_path.each do |dir| + next unless FileTest.directory?(dir) - # And load any directories matching the name - factdir = File.join(dir, shortname) - load_dir(factdir) if FileTest.directory?(factdir) + Dir.entries(dir).sort.each do |file| + path = File.join(dir, file) + if File.directory?(path) + load_dir(path) + elsif file =~ /\.rb$/ + load_file(File.join(dir, file)) end + end end - # Load all facts from all directories. - def load_all - return if defined?( <at> loaded_all) + <at> loaded_all = true + end - load_env - - search_path.each do |dir| - next unless FileTest.directory?(dir) - - Dir.entries(dir).sort.each do |file| - path = File.join(dir, file) - if File.directory?(path) - load_dir(path) - elsif file =~ /\.rb$/ - load_file(File.join(dir, file)) - end - end - end - - <at> loaded_all = true + # The list of directories we're going to search through for facts. + def search_path + result = [] + result += $LOAD_PATH.collect { |d| File.join(d, "facter") } + if ENV.include?("FACTERLIB") + result += ENV["FACTERLIB"].split(":") end - # The list of directories we're going to search through for facts. - def search_path - result = [] - result += $LOAD_PATH.collect { |d| File.join(d, "facter") } - if ENV.include?("FACTERLIB") - result += ENV["FACTERLIB"].split(":") - end - - # This allows others to register additional paths we should search. - result += Facter.search_path + # This allows others to register additional paths we should search. + result += Facter.search_path - result - end + result + end - private + private - def load_dir(dir) - return if dir =~ /\/\.+$/ or dir =~ /\/util$/ or dir =~ /\/lib$/ + def load_dir(dir) + return if dir =~ /\/\.+$/ or dir =~ /\/util$/ or dir =~ /\/lib$/ - Dir.entries(dir).find_all { |f| f =~ /\.rb$/ }.sort.each do |file| - load_file(File.join(dir, file)) - end + Dir.entries(dir).find_all { |f| f =~ /\.rb$/ }.sort.each do |file| + load_file(File.join(dir, file)) end - - def load_file(file) - return if <at> loaded.include? file - # We have to specify Kernel.load, because we have a load method. - begin - # Store the file path so we don't try to reload it - <at> loaded << file - Kernel.load(file) - rescue ScriptError => detail - # Don't store the path if the file can't be loaded - # in case it's loadable later on. - <at> loaded.delete(file) - warn "Error loading fact #{file} #{detail}" - end + end + + def load_file(file) + return if <at> loaded.include? file + # We have to specify Kernel.load, because we have a load method. + begin + # Store the file path so we don't try to reload it + <at> loaded << file + Kernel.load(file) + rescue ScriptError => detail + # Don't store the path if the file can't be loaded + # in case it's loadable later on. + <at> loaded.delete(file) + warn "Error loading fact #{file} #{detail}" end - - # Load facts from the environment. If no name is provided, - # all will be loaded. - def load_env(fact = nil) - # Load from the environment, if possible - ENV.each do |name, value| - # Skip anything that doesn't match our regex. - next unless name =~ /^facter_?(\w+)$/i - env_name = $1 - - # If a fact name was specified, skip anything that doesn't - # match it. - next if fact and env_name != fact - - Facter.add($1) do - has_weight 1_000_000 - setcode { value } - end - - # Short-cut, if we are only looking for one value. - break if fact - end + end + + # Load facts from the environment. If no name is provided, + # all will be loaded. + def load_env(fact = nil) + # Load from the environment, if possible + ENV.each do |name, value| + # Skip anything that doesn't match our regex. + next unless name =~ /^facter_?(\w+)$/i + env_name = $1 + + # If a fact name was specified, skip anything that doesn't + # match it. + next if fact and env_name != fact + + Facter.add($1) do + has_weight 1_000_000 + setcode { value } + end + + # Short-cut, if we are only looking for one value. + break if fact end + end end diff --git a/lib/facter/util/macosx.rb b/lib/facter/util/macosx.rb index cc9b2df..dffa102 100644 --- a/lib/facter/util/macosx.rb +++ b/lib/facter/util/macosx.rb <at> <at> -6,56 +6,56 <at> <at> ## module Facter::Util::Macosx - require 'thread' - require 'facter/util/plist' - require 'facter/util/resolution' - - # JJM I'd really like to dynamically generate these methods - # by looking at the _name key of the _items dict for each _dataType - - def self.profiler_xml(data_field) - Facter::Util::Resolution.exec("/usr/sbin/system_profiler -xml #{data_field}") + require 'thread' + require 'facter/util/plist' + require 'facter/util/resolution' + + # JJM I'd really like to dynamically generate these methods + # by looking at the _name key of the _items dict for each _dataType + + def self.profiler_xml(data_field) + Facter::Util::Resolution.exec("/usr/sbin/system_profiler -xml #{data_field}") + end + + def self.intern_xml(xml) + return nil unless xml + Plist::parse_xml(xml) + end + + # Return an xml result, modified as we need it. + def self.profiler_data(data_field) + begin + return nil unless parsed_xml = intern_xml(profiler_xml(data_field)) + return nil unless data = parsed_xml[0]['_items'][0] + data.delete '_name' + data + rescue + return nil end + end - def self.intern_xml(xml) - return nil unless xml - Plist::parse_xml(xml) - end + def self.hardware_overview + profiler_data("SPHardwareDataType") + end - # Return an xml result, modified as we need it. - def self.profiler_data(data_field) - begin - return nil unless parsed_xml = intern_xml(profiler_xml(data_field)) - return nil unless data = parsed_xml[0]['_items'][0] - data.delete '_name' - data - rescue - return nil - end - end + def self.os_overview + profiler_data("SPSoftwareDataType") + end - def self.hardware_overview - profiler_data("SPHardwareDataType") + def self.sw_vers + ver = Hash.new + [ "productName", "productVersion", "buildVersion" ].each do |option| + ver["macosx_#{option}"] = Facter::Util::Resolution.exec("/usr/bin/sw_vers -#{option}").strip end - - def self.os_overview - profiler_data("SPSoftwareDataType") - end - - def self.sw_vers - ver = Hash.new - [ "productName", "productVersion", "buildVersion" ].each do |option| - ver["macosx_#{option}"] = Facter::Util::Resolution.exec("/usr/bin/sw_vers -#{option}").strip - end - productversion = ver["macosx_productVersion"] - if not productversion.nil? - versions = productversion.scan(/(\d+)\.(\d+)\.*(\d*)/)[0] - ver["macosx_productversion_major"] = "#{versions[0]}.#{versions[1]}" - if versions[2].empty? # 10.x should be treated as 10.x.0 - versions[2] = "0" - end - ver["macosx_productversion_minor"] = versions[2] - end - ver + productversion = ver["macosx_productVersion"] + if not productversion.nil? + versions = productversion.scan(/(\d+)\.(\d+)\.*(\d*)/)[0] + ver["macosx_productversion_major"] = "#{versions[0]}.#{versions[1]}" + if versions[2].empty? # 10.x should be treated as 10.x.0 + versions[2] = "0" + end + ver["macosx_productversion_minor"] = versions[2] end + ver + end end diff --git a/lib/facter/util/manufacturer.rb b/lib/facter/util/manufacturer.rb index 9beb2b4..d6fde05 100644 --- a/lib/facter/util/manufacturer.rb +++ b/lib/facter/util/manufacturer.rb <at> <at> -3,103 +3,103 <at> <at> module Facter::Manufacturer - def self.get_dmi_table() - case Facter.value(:kernel) - when 'Linux', 'GNU/kFreeBSD' - return nil unless FileTest.exists?("/usr/sbin/dmidecode") + def self.get_dmi_table() + case Facter.value(:kernel) + when 'Linux', 'GNU/kFreeBSD' + return nil unless FileTest.exists?("/usr/sbin/dmidecode") - output=%x{/usr/sbin/dmidecode 2>/dev/null} - when 'FreeBSD' - return nil unless FileTest.exists?("/usr/local/sbin/dmidecode") + output=%x{/usr/sbin/dmidecode 2>/dev/null} + when 'FreeBSD' + return nil unless FileTest.exists?("/usr/local/sbin/dmidecode") - output=%x{/usr/local/sbin/dmidecode 2>/dev/null} - when 'NetBSD' - return nil unless FileTest.exists?("/usr/pkg/sbin/dmidecode") + output=%x{/usr/local/sbin/dmidecode 2>/dev/null} + when 'NetBSD' + return nil unless FileTest.exists?("/usr/pkg/sbin/dmidecode") - output=%x{/usr/pkg/sbin/dmidecode 2>/dev/null} - when 'SunOS' - return nil unless FileTest.exists?("/usr/sbin/smbios") + output=%x{/usr/pkg/sbin/dmidecode 2>/dev/null} + when 'SunOS' + return nil unless FileTest.exists?("/usr/sbin/smbios") - output=%x{/usr/sbin/smbios 2>/dev/null} - else - output=nil - end - return output + output=%x{/usr/sbin/smbios 2>/dev/null} + else + output=nil end + return output + end - def self.dmi_find_system_info(name) - splitstr= Facter.value(:kernel) == 'SunOS' ? "ID SIZE TYPE" : /^Handle/ - output = self.get_dmi_table() - return if output.nil? - name.each_pair do |key,v| - v.each do |v2| - v2.each_pair do |value,facterkey| - output.split(splitstr).each do |line| - if line =~ /#{key}/ and line =~ /\n\s+#{value} (.+)\n/ - result = $1.strip - Facter.add(facterkey) do - confine :kernel => [ :linux, :freebsd, :netbsd, :sunos, :"gnu/kfreebsd" ] - setcode do - result - end - end - end - end + def self.dmi_find_system_info(name) + splitstr= Facter.value(:kernel) == 'SunOS' ? "ID SIZE TYPE" : /^Handle/ + output = self.get_dmi_table() + return if output.nil? + name.each_pair do |key,v| + v.each do |v2| + v2.each_pair do |value,facterkey| + output.split(splitstr).each do |line| + if line =~ /#{key}/ and line =~ /\n\s+#{value} (.+)\n/ + result = $1.strip + Facter.add(facterkey) do + confine :kernel => [ :linux, :freebsd, :netbsd, :sunos, :"gnu/kfreebsd" ] + setcode do + result end + end end + end end + end end + end - def self.sysctl_find_system_info(name) - name.each do |sysctlkey,facterkey| - Facter.add(facterkey) do - confine :kernel => [:openbsd, :darwin] - setcode do - Facter::Util::Resolution.exec("sysctl -n #{sysctlkey} 2>/dev/null") - end - end + def self.sysctl_find_system_info(name) + name.each do |sysctlkey,facterkey| + Facter.add(facterkey) do + confine :kernel => [:openbsd, :darwin] + setcode do + Facter::Util::Resolution.exec("sysctl -n #{sysctlkey} 2>/dev/null") end + end end + end - def self.prtdiag_sparc_find_system_info() - # Parses prtdiag for a SPARC architecture string, won't work with Solaris x86 - output = Facter::Util::Resolution.exec('/usr/sbin/prtdiag') + def self.prtdiag_sparc_find_system_info() + # Parses prtdiag for a SPARC architecture string, won't work with Solaris x86 + output = Facter::Util::Resolution.exec('/usr/sbin/prtdiag') - # System Configuration: Sun Microsystems sun4u Sun SPARC Enterprise M3000 Server - sysconfig = output.split("\n")[0] - if sysconfig =~ /^System Configuration:\s+(.+?)\s+(sun\d+\S+)\s+(.+)/ then - Facter.add('manufacturer') do - setcode do - $1 - end - end - Facter.add('productname') do - setcode do - $3 - end - end + # System Configuration: Sun Microsystems sun4u Sun SPARC Enterprise M3000 Server + sysconfig = output.split("\n")[0] + if sysconfig =~ /^System Configuration:\s+(.+?)\s+(sun\d+\S+)\s+(.+)/ then + Facter.add('manufacturer') do + setcode do + $1 end - - Facter.add('serialnumber') do - setcode do - Facter::Util::Resolution.exec("/usr/sbin/sneep") - end + end + Facter.add('productname') do + setcode do + $3 end + end end - def self.win32_find_system_info(name) - require 'facter/util/wmi' - value = "" - wmi = Facter::Util::WMI.connect() - name.each do |facterkey, win32key| - query = wmi.ExecQuery("select * from Win32_#{win32key.last}") - Facter.add(facterkey) do - confine :kernel => :windows - setcode do - query.each { |x| value = x.__send__( (win32key.first).to_sym) } - value - end - end + Facter.add('serialnumber') do + setcode do + Facter::Util::Resolution.exec("/usr/sbin/sneep") + end + end + end + + def self.win32_find_system_info(name) + require 'facter/util/wmi' + value = "" + wmi = Facter::Util::WMI.connect() + name.each do |facterkey, win32key| + query = wmi.ExecQuery("select * from Win32_#{win32key.last}") + Facter.add(facterkey) do + confine :kernel => :windows + setcode do + query.each { |x| value = x.__send__( (win32key.first).to_sym) } + value end + end end + end end diff --git a/lib/facter/util/memory.rb b/lib/facter/util/memory.rb index d49079d..09a8166 100644 --- a/lib/facter/util/memory.rb +++ b/lib/facter/util/memory.rb <at> <at> -3,83 +3,83 <at> <at> ## module Facter::Memory - require 'thread' + require 'thread' - def self.meminfo_number(tag) - memsize = "" - Thread::exclusive do - size, scale = [0, ""] - File.readlines("/proc/meminfo").each do |l| - size, scale = [$1.to_f, $2] if l =~ /^#{tag}:\s+(\d+)\s+(\S+)/ - # MemoryFree == memfree + cached + buffers - # (assume scales are all the same as memfree) - if tag == "MemFree" && - l =~ /^(?:Buffers|Cached):\s+(\d+)\s+(?:\S+)/ - size += $1.to_f - end - end - memsize = scale_number(size, scale) + def self.meminfo_number(tag) + memsize = "" + Thread::exclusive do + size, scale = [0, ""] + File.readlines("/proc/meminfo").each do |l| + size, scale = [$1.to_f, $2] if l =~ /^#{tag}:\s+(\d+)\s+(\S+)/ + # MemoryFree == memfree + cached + buffers + # (assume scales are all the same as memfree) + if tag == "MemFree" && + l =~ /^(?:Buffers|Cached):\s+(\d+)\s+(?:\S+)/ + size += $1.to_f end - - memsize + end + memsize = scale_number(size, scale) end - def self.scale_number(size, multiplier) - suffixes = ['', 'kB', 'MB', 'GB', 'TB'] + memsize + end - s = suffixes.shift - while s != multiplier - s = suffixes.shift - end + def self.scale_number(size, multiplier) + suffixes = ['', 'kB', 'MB', 'GB', 'TB'] - while size > 1024.0 - size /= 1024.0 - s = suffixes.shift - end + s = suffixes.shift + while s != multiplier + s = suffixes.shift + end - return "%.2f %s" % [size, s] + while size > 1024.0 + size /= 1024.0 + s = suffixes.shift end - def self.vmstat_find_free_memory() - row = Facter::Util::Resolution.exec('vmstat').split("\n")[-1] - if row =~ /^\s*\d+\s*\d+\s*\d+\s*\d+\s*(\d+)/ - Facter.add("MemoryFree") do - memfree = $1 - setcode do - Facter::Memory.scale_number(memfree.to_f, "kB") - end - end + return "%.2f %s" % [size, s] + end + + def self.vmstat_find_free_memory() + row = Facter::Util::Resolution.exec('vmstat').split("\n")[-1] + if row =~ /^\s*\d+\s*\d+\s*\d+\s*\d+\s*(\d+)/ + Facter.add("MemoryFree") do + memfree = $1 + setcode do + Facter::Memory.scale_number(memfree.to_f, "kB") end + end end + end - # Darwin had to be different. It's generally opaque with how much RAM it is - # using, and this figure could be improved upon too I fear. - # Parses the output of "vm_stat", takes the pages free & pages speculative - # and multiples that by the page size (also given in output). Ties in with - # what activity monitor outputs for free memory. - def self.vmstat_darwin_find_free_memory() + # Darwin had to be different. It's generally opaque with how much RAM it is + # using, and this figure could be improved upon too I fear. + # Parses the output of "vm_stat", takes the pages free & pages speculative + # and multiples that by the page size (also given in output). Ties in with + # what activity monitor outputs for free memory. + def self.vmstat_darwin_find_free_memory() - memfree = 0 - pagesize = 0 - memspecfree = 0 + memfree = 0 + pagesize = 0 + memspecfree = 0 - vmstats = Facter::Util::Resolution.exec('vm_stat') - vmstats.each_line do |vmline| - case - when vmline =~ /page\ssize\sof\s(\d+)\sbytes/ - pagesize = $1.to_i - when vmline =~ /^Pages\sfree:\s+(\d+)\./ - memfree = $1.to_i - when vmline =~ /^Pages\sspeculative:\s+(\d+)\./ - memspecfree = $1.to_i - end - end + vmstats = Facter::Util::Resolution.exec('vm_stat') + vmstats.each_line do |vmline| + case + when vmline =~ /page\ssize\sof\s(\d+)\sbytes/ + pagesize = $1.to_i + when vmline =~ /^Pages\sfree:\s+(\d+)\./ + memfree = $1.to_i + when vmline =~ /^Pages\sspeculative:\s+(\d+)\./ + memspecfree = $1.to_i + end + end - freemem = ( memfree + memspecfree ) * pagesize - Facter.add("MemoryFree") do - setcode do - Facter::Memory.scale_number(freemem.to_f, "") - end - end + freemem = ( memfree + memspecfree ) * pagesize + Facter.add("MemoryFree") do + setcode do + Facter::Memory.scale_number(freemem.to_f, "") + end end + end end diff --git a/lib/facter/util/netmask.rb b/lib/facter/util/netmask.rb index 60b57d9..b78b173 100644 --- a/lib/facter/util/netmask.rb +++ b/lib/facter/util/netmask.rb <at> <at> -1,40 +1,40 <at> <at> module Facter::NetMask - def self.get_netmask - netmask = nil; - ipregex = %r{(\d{1,3}\.){3}\d{1,3}} + def self.get_netmask + netmask = nil; + ipregex = %r{(\d{1,3}\.){3}\d{1,3}} - ops = nil - case Facter.value(:kernel) - when 'Linux' - ops = { - :ifconfig => '/sbin/ifconfig', - :regex => %r{\s+ inet\saddr: #{Facter.ipaddress} .*? Mask: (#{ipregex})}x, - :munge => nil, - } - when 'SunOS' - ops = { - :ifconfig => '/usr/sbin/ifconfig -a', - :regex => %r{\s+ inet \s #{Facter.ipaddress} \s netmask \s (\w{8})}x, - :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') } - } - when 'FreeBSD','NetBSD','OpenBSD', 'Darwin', 'GNU/kFreeBSD', 'DragonFly' - ops = { - :ifconfig => '/sbin/ifconfig -a', - :regex => %r{\s+ inet \s #{Facter.ipaddress} \s netmask \s 0x(\w{8})}x, - :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') } - } - end + ops = nil + case Facter.value(:kernel) + when 'Linux' + ops = { + :ifconfig => '/sbin/ifconfig', + :regex => %r{\s+ inet\saddr: #{Facter.ipaddress} .*? Mask: (#{ipregex})}x, + :munge => nil, + } + when 'SunOS' + ops = { + :ifconfig => '/usr/sbin/ifconfig -a', + :regex => %r{\s+ inet \s #{Facter.ipaddress} \s netmask \s (\w{8})}x, + :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') } + } + when 'FreeBSD','NetBSD','OpenBSD', 'Darwin', 'GNU/kFreeBSD', 'DragonFly' + ops = { + :ifconfig => '/sbin/ifconfig -a', + :regex => %r{\s+ inet \s #{Facter.ipaddress} \s netmask \s 0x(\w{8})}x, + :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') } + } + end - %x{#{ops[:ifconfig]}}.split(/\n/).collect do |line| - matches = line.match(ops[:regex]) - if !matches.nil? - if ops[:munge].nil? - netmask = matches[1] - else - netmask = ops[:munge].call(matches[1]) - end - end + %x{#{ops[:ifconfig]}}.split(/\n/).collect do |line| + matches = line.match(ops[:regex]) + if !matches.nil? + if ops[:munge].nil? + netmask = matches[1] + else + netmask = ops[:munge].call(matches[1]) end - netmask + end end + netmask + end end diff --git a/lib/facter/util/plist.rb b/lib/facter/util/plist.rb index 54f5248..32e9e2b 100644 --- a/lib/facter/util/plist.rb +++ b/lib/facter/util/plist.rb <at> <at> -18,7 +18,7 <at> <at> require 'facter/util/plist/generator' require 'facter/util/plist/parser' module Plist - VERSION = '3.0.0' + VERSION = '3.0.0' end # $Id: plist.rb 1781 2006-10-16 01:01:35Z luke $ diff --git a/lib/facter/util/plist/generator.rb b/lib/facter/util/plist/generator.rb index 6c0796b..8f9ea3a 100644 --- a/lib/facter/util/plist/generator.rb +++ b/lib/facter/util/plist/generator.rb <at> <at> -1,228 +1,228 <at> <at> #--########################################################### -# Copyright 2006, Ben Bleything <ben <at> bleything.net> and # -# Patrick May <patrick <at> hexane.org> # -# # -# Distributed under the MIT license. # +# Copyright 2006, Ben Bleything <ben <at> bleything.net> and # +# Patrick May <patrick <at> hexane.org> # +# # +# Distributed under the MIT license. # ############################################################## #++ # See Plist::Emit. module Plist - # === Create a plist - # You can dump an object to a plist in one of two ways: + # === Create a plist + # You can dump an object to a plist in one of two ways: + # + # * <tt>Plist::Emit.dump(obj)</tt> + # * <tt>obj.to_plist</tt> + # * This requires that you mixin the <tt>Plist::Emit</tt> module, which is already done for +Array+ and +Hash+. + # + # The following Ruby classes are converted into native plist types: + # Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time, true, false + # * +Array+ and +Hash+ are both recursive; their elements will be converted into plist nodes inside the <array> and <dict> containers (respectively). + # * +IO+ (and its descendants) and +StringIO+ objects are read from and their contents placed in a <data> element. + # * User classes may implement +to_plist_node+ to dictate how they should be serialized; otherwise the object will be passed to <tt>Marshal.dump</tt> and the result placed in a <data> element. + # + # For detailed usage instructions, refer to USAGE[link:files/docs/USAGE.html] and the methods documented below. + module Emit + # Helper method for injecting into classes. Calls <tt>Plist::Emit.dump</tt> with +self+. + def to_plist(envelope = true) + return Plist::Emit.dump(self, envelope) + end + + # Helper method for injecting into classes. Calls <tt>Plist::Emit.save_plist</tt> with +self+. + def save_plist(filename) + Plist::Emit.save_plist(self, filename) + end + + # The following Ruby classes are converted into native plist types: + # Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time # - # * <tt>Plist::Emit.dump(obj)</tt> - # * <tt>obj.to_plist</tt> - # * This requires that you mixin the <tt>Plist::Emit</tt> module, which is already done for +Array+ and +Hash+. + # Write us (via RubyForge) if you think another class can be coerced safely into one of the expected plist classes. # - # The following Ruby classes are converted into native plist types: - # Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time, true, false - # * +Array+ and +Hash+ are both recursive; their elements will be converted into plist nodes inside the <array> and <dict> containers (respectively). - # * +IO+ (and its descendants) and +StringIO+ objects are read from and their contents placed in a <data> element. - # * User classes may implement +to_plist_node+ to dictate how they should be serialized; otherwise the object will be passed to <tt>Marshal.dump</tt> and the result placed in a <data> element. + # +IO+ and +StringIO+ objects are encoded and placed in <data> elements; other objects are <tt>Marshal.dump</tt>'ed unless they implement +to_plist_node+. # - # For detailed usage instructions, refer to USAGE[link:files/docs/USAGE.html] and the methods documented below. - module Emit - # Helper method for injecting into classes. Calls <tt>Plist::Emit.dump</tt> with +self+. - def to_plist(envelope = true) - return Plist::Emit.dump(self, envelope) - end - - # Helper method for injecting into classes. Calls <tt>Plist::Emit.save_plist</tt> with +self+. - def save_plist(filename) - Plist::Emit.save_plist(self, filename) - end + # The +envelope+ parameters dictates whether or not the resultant plist fragment is wrapped in the normal XML/plist header and footer. Set it to false if you only want the fragment. + def self.dump(obj, envelope = true) + output = plist_node(obj) - # The following Ruby classes are converted into native plist types: - # Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time - # - # Write us (via RubyForge) if you think another class can be coerced safely into one of the expected plist classes. - # - # +IO+ and +StringIO+ objects are encoded and placed in <data> elements; other objects are <tt>Marshal.dump</tt>'ed unless they implement +to_plist_node+. - # - # The +envelope+ parameters dictates whether or not the resultant plist fragment is wrapped in the normal XML/plist header and footer. Set it to false if you only want the fragment. - def self.dump(obj, envelope = true) - output = plist_node(obj) + output = wrap(output) if envelope - output = wrap(output) if envelope + return output + end - return output - end + # Writes the serialized object's plist to the specified filename. + def self.save_plist(obj, filename) + File.open(filename, 'wb') do |f| + f.write(obj.to_plist) + end + end - # Writes the serialized object's plist to the specified filename. - def self.save_plist(obj, filename) - File.open(filename, 'wb') do |f| - f.write(obj.to_plist) + private + def self.plist_node(element) + output = '' + + if element.respond_to? :to_plist_node + output << element.to_plist_node + else + case element + when Array + if element.empty? + output << "<array/>\n" + else + output << tag('array') { + element.collect {|e| plist_node(e)} + } + end + when Hash + if element.empty? + output << "<dict/>\n" + else + inner_tags = [] + + element.keys.sort.each do |k| + v = element[k] + inner_tags << tag('key', CGI::escapeHTML(k.to_s)) + inner_tags << plist_node(v) end + + output << tag('dict') { + inner_tags + } + end + when true, false + output << "<#{element}/>\n" + when Time + output << tag('date', element.utc.strftime('%Y-%m-%dT%H:%M:%SZ')) + when Date # also catches DateTime + output << tag('date', element.strftime('%Y-%m-%dT%H:%M:%SZ')) + when String, Symbol, Fixnum, Bignum, Integer, Float + output << tag(element_type(element), CGI::escapeHTML(element.to_s)) + when IO, StringIO + element.rewind + contents = element.read + # note that apple plists are wrapped at a different length then + # what ruby's base64 wraps by default. + # I used #encode64 instead of #b64encode (which allows a length arg) + # because b64encode is b0rked and ignores the length arg. + data = "\n" + Base64::encode64(contents).gsub(/\s+/, '').scan(/.{1,68}/o) { data << $& << "\n" } + output << tag('data', data) + else + output << comment( 'The <data> element below contains a Ruby object which has been serialized with Marshal.dump.' ) + data = "\n" + Base64::encode64(Marshal.dump(element)).gsub(/\s+/, '').scan(/.{1,68}/o) { data << $& << "\n" } + output << tag('data', data ) end + end - private - def self.plist_node(element) - output = '' - - if element.respond_to? :to_plist_node - output << element.to_plist_node - else - case element - when Array - if element.empty? - output << "<array/>\n" - else - output << tag('array') { - element.collect {|e| plist_node(e)} - } - end - when Hash - if element.empty? - output << "<dict/>\n" - else - inner_tags = [] - - element.keys.sort.each do |k| - v = element[k] - inner_tags << tag('key', CGI::escapeHTML(k.to_s)) - inner_tags << plist_node(v) - end - - output << tag('dict') { - inner_tags - } - end - when true, false - output << "<#{element}/>\n" - when Time - output << tag('date', element.utc.strftime('%Y-%m-%dT%H:%M:%SZ')) - when Date # also catches DateTime - output << tag('date', element.strftime('%Y-%m-%dT%H:%M:%SZ')) - when String, Symbol, Fixnum, Bignum, Integer, Float - output << tag(element_type(element), CGI::escapeHTML(element.to_s)) - when IO, StringIO - element.rewind - contents = element.read - # note that apple plists are wrapped at a different length then - # what ruby's base64 wraps by default. - # I used #encode64 instead of #b64encode (which allows a length arg) - # because b64encode is b0rked and ignores the length arg. - data = "\n" - Base64::encode64(contents).gsub(/\s+/, '').scan(/.{1,68}/o) { data << $& << "\n" } - output << tag('data', data) - else - output << comment( 'The <data> element below contains a Ruby object which has been serialized with Marshal.dump.' ) - data = "\n" - Base64::encode64(Marshal.dump(element)).gsub(/\s+/, '').scan(/.{1,68}/o) { data << $& << "\n" } - output << tag('data', data ) - end - end + return output + end - return output - end + def self.comment(content) + return "<!-- #{content} -->\n" + end - def self.comment(content) - return "<!-- #{content} -->\n" - end + def self.tag(type, contents = '', &block) + out = nil - def self.tag(type, contents = '', &block) - out = nil + if block_given? + out = IndentedString.new + out << "<#{type}>" + out.raise_indent - if block_given? - out = IndentedString.new - out << "<#{type}>" - out.raise_indent + out << block.call - out << block.call + out.lower_indent + out << "</#{type}>" + else + out = "<#{type}>#{contents.to_s}</#{type}>\n" + end - out.lower_indent - out << "</#{type}>" - else - out = "<#{type}>#{contents.to_s}</#{type}>\n" - end + return out.to_s + end - return out.to_s - end + def self.wrap(contents) + output = '' - def self.wrap(contents) - output = '' + output << '<?xml version="1.0" encoding="UTF-8"?>' + "\n" + output << '<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' + "\n" + output << '<plist version="1.0">' + "\n" - output << '<?xml version="1.0" encoding="UTF-8"?>' + "\n" - output << '<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' + "\n" - output << '<plist version="1.0">' + "\n" + output << contents - output << contents + output << '</plist>' + "\n" - output << '</plist>' + "\n" + return output + end - return output - end + def self.element_type(item) + return case item + when String, Symbol; 'string' + when Fixnum, Bignum, Integer; 'integer' + when Float; 'real' + else + raise "Don't know about this data type... something must be wrong!" + end + end - def self.element_type(item) - return case item - when String, Symbol; 'string' - when Fixnum, Bignum, Integer; 'integer' - when Float; 'real' - else - raise "Don't know about this data type... something must be wrong!" - end - end + private - private + class IndentedString #:nodoc: + attr_accessor :indent_string - class IndentedString #:nodoc: - attr_accessor :indent_string + <at> <at> indent_level = 0 - <at> <at> indent_level = 0 + def initialize(str = "\t") + <at> indent_string = str + <at> contents = '' + end - def initialize(str = "\t") - <at> indent_string = str - <at> contents = '' - end + def to_s + return <at> contents + end - def to_s - return <at> contents - end + def raise_indent + <at> <at> indent_level += 1 + end - def raise_indent - <at> <at> indent_level += 1 - end + def lower_indent + <at> <at> indent_level -= 1 if <at> <at> indent_level > 0 + end - def lower_indent - <at> <at> indent_level -= 1 if <at> <at> indent_level > 0 - end + def <<(val) + if val.is_a? Array + val.each do |f| + self << f + end + else + # if it's already indented, don't bother indenting further + unless val =~ /\A#{ <at> indent_string}/ + indent = <at> indent_string * <at> <at> indent_level - def <<(val) - if val.is_a? Array - val.each do |f| - self << f - end - else - # if it's already indented, don't bother indenting further - unless val =~ /\A#{ <at> indent_string}/ - indent = <at> indent_string * <at> <at> indent_level - - <at> contents << val.gsub(/^/, indent) - else - <at> contents << val - end - - # it already has a newline, don't add another - <at> contents << "\n" unless val =~ /\n$/ - end - end + <at> contents << val.gsub(/^/, indent) + else + <at> contents << val + end + + # it already has a newline, don't add another + <at> contents << "\n" unless val =~ /\n$/ end + end end + end end # we need to add this so sorting hash keys works properly class Symbol #:nodoc: - def <=> (other) - self.to_s <=> other.to_s - end + def <=> (other) + self.to_s <=> other.to_s + end end class Array #:nodoc: - include Plist::Emit + include Plist::Emit end class Hash #:nodoc: - include Plist::Emit + include Plist::Emit end # $Id: generator.rb 1781 2006-10-16 01:01:35Z luke $ diff --git a/lib/facter/util/plist/parser.rb b/lib/facter/util/plist/parser.rb index 48e1034..ffbb7ba 100644 --- a/lib/facter/util/plist/parser.rb +++ b/lib/facter/util/plist/parser.rb <at> <at> -1,8 +1,8 <at> <at> #--########################################################### -# Copyright 2006, Ben Bleything <ben <at> bleything.net> and # -# Patrick May <patrick <at> hexane.org> # -# # -# Distributed under the MIT license. # +# Copyright 2006, Ben Bleything <ben <at> bleything.net> and # +# Patrick May <patrick <at> hexane.org> # +# # +# Distributed under the MIT license. # ############################################################## #++ # Plist parses Mac OS X xml property list files into ruby data structures. <at> <at> -21,206 +21,206 <at> <at> module Plist # If you encounter such an error, or if you have a Date element which # can't be parsed into a Time object, please send your plist file to # plist <at> hexane.org so that I can implement the proper support. - def Plist::parse_xml( filename_or_xml ) - listener = Listener.new - #parser = REXML::Parsers::StreamParser.new(File.new(filename), listener) - parser = StreamParser.new(filename_or_xml, listener) - parser.parse - listener.result + def Plist::parse_xml( filename_or_xml ) + listener = Listener.new + #parser = REXML::Parsers::StreamParser.new(File.new(filename), listener) + parser = StreamParser.new(filename_or_xml, listener) + parser.parse + listener.result + end + + class Listener + #include REXML::StreamListener + + attr_accessor :result, :open + + def initialize + <at> result = nil + <at> open = Array.new end - class Listener - #include REXML::StreamListener - attr_accessor :result, :open - - def initialize - <at> result = nil - <at> open = Array.new - end - - - def tag_start(name, attributes) - <at> open.push PTag::mappings[name].new - end - - def text( contents ) - <at> open.last.text = contents if <at> open.last - end + def tag_start(name, attributes) + <at> open.push PTag::mappings[name].new + end - def tag_end(name) - last = <at> open.pop - if <at> open.empty? - <at> result = last.to_ruby - else - <at> open.last.children.push last - end - end + def text( contents ) + <at> open.last.text = contents if <at> open.last end - class StreamParser - def initialize( filename_or_xml, listener ) - <at> filename_or_xml = filename_or_xml - <at> listener = listener - end + def tag_end(name) + last = <at> open.pop + if <at> open.empty? + <at> result = last.to_ruby + else + <at> open.last.children.push last + end + end + end - TEXT = /([^<]+)/ - XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>*/um - DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/um - COMMENT_START = /\A<!--/u - COMMENT_END = /.*?-->/um - - def parse - plist_tags = PTag::mappings.keys.join('|') - start_tag = /<(#{plist_tags})([^>]*)>/i - end_tag = /<\/(#{plist_tags})[^>]*>/i - - require 'strscan' - - contents = ( - if (File.exists? <at> filename_or_xml) - File.open( <at> filename_or_xml) {|f| f.read} - else - <at> filename_or_xml - end - ) - - <at> scanner = StringScanner.new( contents ) - until <at> scanner.eos? - if <at> scanner.scan(COMMENT_START) - <at> scanner.scan(COMMENT_END) - elsif <at> scanner.scan(XMLDECL_PATTERN) - elsif <at> scanner.scan(DOCTYPE_PATTERN) - elsif <at> scanner.scan(start_tag) - <at> listener.tag_start( <at> scanner[1], nil) - if ( <at> scanner[2] =~ /\/$/) - <at> listener.tag_end( <at> scanner[1]) - end - elsif <at> scanner.scan(TEXT) - <at> listener.text( <at> scanner[1]) - elsif <at> scanner.scan(end_tag) - <at> listener.tag_end( <at> scanner[1]) - else - raise "Unimplemented element" - end - end - end + class StreamParser + def initialize( filename_or_xml, listener ) + <at> filename_or_xml = filename_or_xml + <at> listener = listener end - class PTag - <at> <at> mappings = { } - def PTag::mappings - <at> <at> mappings - end + TEXT = /([^<]+)/ + XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>*/um + DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/um + COMMENT_START = /\A<!--/u + COMMENT_END = /.*?-->/um + + def parse + plist_tags = PTag::mappings.keys.join('|') + start_tag = /<(#{plist_tags})([^>]*)>/i + end_tag = /<\/(#{plist_tags})[^>]*>/i + + require 'strscan' + + contents = ( + if (File.exists? <at> filename_or_xml) + File.open( <at> filename_or_xml) {|f| f.read} + else + <at> filename_or_xml + end + ) + + <at> scanner = StringScanner.new( contents ) + until <at> scanner.eos? + if <at> scanner.scan(COMMENT_START) + <at> scanner.scan(COMMENT_END) + elsif <at> scanner.scan(XMLDECL_PATTERN) + elsif <at> scanner.scan(DOCTYPE_PATTERN) + elsif <at> scanner.scan(start_tag) + <at> listener.tag_start( <at> scanner[1], nil) + if ( <at> scanner[2] =~ /\/$/) + <at> listener.tag_end( <at> scanner[1]) + end + elsif <at> scanner.scan(TEXT) + <at> listener.text( <at> scanner[1]) + elsif <at> scanner.scan(end_tag) + <at> listener.tag_end( <at> scanner[1]) + else + raise "Unimplemented element" + end + end + end + end - def PTag::inherited( sub_class ) - key = sub_class.to_s.downcase - key.gsub!(/^plist::/, '' ) - key.gsub!(/^p/, '') unless key == "plist" + class PTag + <at> <at> mappings = { } + def PTag::mappings + <at> <at> mappings + end - <at> <at> mappings[key] = sub_class - end + def PTag::inherited( sub_class ) + key = sub_class.to_s.downcase + key.gsub!(/^plist::/, '' ) + key.gsub!(/^p/, '') unless key == "plist" - attr_accessor :text, :children - def initialize - <at> children = Array.new - end + <at> <at> mappings[key] = sub_class + end - def to_ruby - raise "Unimplemented: " + self.class.to_s + "#to_ruby on #{self.inspect}" - end + attr_accessor :text, :children + def initialize + <at> children = Array.new end - class PList < PTag - def to_ruby - children.first.to_ruby if children.first - end + def to_ruby + raise "Unimplemented: " + self.class.to_s + "#to_ruby on #{self.inspect}" end + end - class PDict < PTag - def to_ruby - dict = Hash.new - key = nil + class PList < PTag + def to_ruby + children.first.to_ruby if children.first + end + end - children.each do |c| - if key.nil? - key = c.to_ruby - else - dict[key] = c.to_ruby - key = nil - end - end + class PDict < PTag + def to_ruby + dict = Hash.new + key = nil - dict + children.each do |c| + if key.nil? + key = c.to_ruby + else + dict[key] = c.to_ruby + key = nil end - end + end - class PKey < PTag - def to_ruby - CGI::unescapeHTML(text || '') - end + dict end + end - class PString < PTag - def to_ruby - CGI::unescapeHTML(text || '') - end + class PKey < PTag + def to_ruby + CGI::unescapeHTML(text || '') end + end - class PArray < PTag - def to_ruby - children.collect do |c| - c.to_ruby - end - end + class PString < PTag + def to_ruby + CGI::unescapeHTML(text || '') end + end - class PInteger < PTag - def to_ruby - text.to_i - end + class PArray < PTag + def to_ruby + children.collect do |c| + c.to_ruby + end end + end - class PTrue < PTag - def to_ruby - true - end + class PInteger < PTag + def to_ruby + text.to_i end + end - class PFalse < PTag - def to_ruby - false - end + class PTrue < PTag + def to_ruby + true end + end - class PReal < PTag - def to_ruby - text.to_f - end + class PFalse < PTag + def to_ruby + false end + end - require 'date' - class PDate < PTag - def to_ruby - DateTime.parse(text) - end + class PReal < PTag + def to_ruby + text.to_f end + end - require 'base64' - class PData < PTag - def to_ruby - data = Base64.decode64(text.gsub(/\s+/, '')) - - begin - return Marshal.load(data) - rescue Exception => e - io = StringIO.new - io.write data - io.rewind - return io - end - end + require 'date' + class PDate < PTag + def to_ruby + DateTime.parse(text) + end + end + + require 'base64' + class PData < PTag + def to_ruby + data = Base64.decode64(text.gsub(/\s+/, '')) + + begin + return Marshal.load(data) + rescue Exception => e + io = StringIO.new + io.write data + io.rewind + return io + end end + end end # $Id: parser.rb 1781 2006-10-16 01:01:35Z luke $ diff --git a/lib/facter/util/processor.rb b/lib/facter/util/processor.rb index d4b4de9..8438482 100644 --- a/lib/facter/util/processor.rb +++ b/lib/facter/util/processor.rb <at> <at> -26,7 +26,7 <at> <at> module Facter::Util::Processor Thread::exclusive do File.readlines(cpuinfo).each do |l| if l =~ /processor\s+:\s+(\d+)/ - processor_num = $1.to_i + processor_num = $1.to_i elsif l =~ /cpu\s+:\s+(.*)\s*$/ processor_list[processor_num] = $1 unless processor_num == -1 processor_num = -1 diff --git a/lib/facter/util/resolution.rb b/lib/facter/util/resolution.rb index 4388c81..0270be1 100644 --- a/lib/facter/util/resolution.rb +++ b/lib/facter/util/resolution.rb <at> <at> -9,179 +9,179 <at> <at> require 'facter/util/config' require 'timeout' class Facter::Util::Resolution - attr_accessor :interpreter, :code, :name, :timeout - - INTERPRETER = Facter::Util::Config.is_windows? ? "cmd.exe" : "/bin/sh" - - def self.have_which - if ! defined?( <at> have_which) or <at> have_which.nil? - if Facter.value(:kernel) == 'windows' - <at> have_which = false - else - %x{which which >/dev/null 2>&1} - <at> have_which = ($? == 0) - end - end - <at> have_which + attr_accessor :interpreter, :code, :name, :timeout + + INTERPRETER = Facter::Util::Config.is_windows? ? "cmd.exe" : "/bin/sh" + + def self.have_which + if ! defined?( <at> have_which) or <at> have_which.nil? + if Facter.value(:kernel) == 'windows' + <at> have_which = false + else + %x{which which >/dev/null 2>&1} + <at> have_which = ($? == 0) + end end - - # Execute a program and return the output of that program. + <at> have_which + end + + # Execute a program and return the output of that program. + # + # Returns nil if the program can't be found, or if there is a problem + # executing the code. + # + def self.exec(code, interpreter = nil) + Facter.warnonce "The interpreter parameter to 'exec' is deprecated and will be removed in a future version." if interpreter + + # Try to guess whether the specified code can be executed by looking at the + # first word. If it cannot be found on the PATH defer on resolving the fact + # by returning nil. + # This only fails on shell built-ins, most of which are masked by stuff in + # /bin or of dubious value anyways. In the worst case, "sh -c 'builtin'" can + # be used to work around this limitation # - # Returns nil if the program can't be found, or if there is a problem - # executing the code. - # - def self.exec(code, interpreter = nil) - Facter.warnonce "The interpreter parameter to 'exec' is deprecated and will be removed in a future version." if interpreter - - # Try to guess whether the specified code can be executed by looking at the - # first word. If it cannot be found on the PATH defer on resolving the fact - # by returning nil. - # This only fails on shell built-ins, most of which are masked by stuff in - # /bin or of dubious value anyways. In the worst case, "sh -c 'builtin'" can - # be used to work around this limitation - # - # Windows' %x{} throws Errno::ENOENT when the command is not found, so we - # can skip the check there. This is good, since builtins cannot be found - # elsewhere. - if have_which and !Facter::Util::Config.is_windows? - path = nil - binary = code.split.first - if code =~ /^\// - path = binary - else - path = %x{which #{binary} 2>/dev/null}.chomp - # we don't have the binary necessary - return nil if path == "" or path.match(/Command not found\./) - end - - return nil unless FileTest.exists?(path) - end - - out = nil - - begin - out = %x{#{code}}.chomp - rescue Errno::ENOENT => detail - # command not found on Windows - return nil - rescue => detail - $stderr.puts detail - return nil - end - - if out == "" - return nil - else - return out - end + # Windows' %x{} throws Errno::ENOENT when the command is not found, so we + # can skip the check there. This is good, since builtins cannot be found + # elsewhere. + if have_which and !Facter::Util::Config.is_windows? + path = nil + binary = code.split.first + if code =~ /^\// + path = binary + else + path = %x{which #{binary} 2>/dev/null}.chomp + # we don't have the binary necessary + return nil if path == "" or path.match(/Command not found\./) + end + + return nil unless FileTest.exists?(path) end - # Add a new confine to the resolution mechanism. - def confine(confines) - confines.each do |fact, values| - <at> confines.push Facter::Util::Confine.new(fact, *values) - end - end + out = nil - def has_weight(weight) - <at> weight = weight + begin + out = %x{#{code}}.chomp + rescue Errno::ENOENT => detail + # command not found on Windows + return nil + rescue => detail + $stderr.puts detail + return nil end - # Create a new resolution mechanism. - def initialize(name) - <at> name = name - <at> confines = [] - <at> value = nil - <at> timeout = 0 - <at> weight = nil + if out == "" + return nil + else + return out end + end - # Return the importance of this resolution. - def weight - if <at> weight - <at> weight - else - <at> confines.length - end + # Add a new confine to the resolution mechanism. + def confine(confines) + confines.each do |fact, values| + <at> confines.push Facter::Util::Confine.new(fact, *values) end - - # We need this as a getter for 'timeout', because some versions - # of ruby seem to already have a 'timeout' method and we can't - # seem to override the instance methods, somehow. - def limit - <at> timeout + end + + def has_weight(weight) + <at> weight = weight + end + + # Create a new resolution mechanism. + def initialize(name) + <at> name = name + <at> confines = [] + <at> value = nil + <at> timeout = 0 + <at> weight = nil + end + + # Return the importance of this resolution. + def weight + if <at> weight + <at> weight + else + <at> confines.length end - - # Set our code for returning a value. - def setcode(string = nil, interp = nil, &block) - Facter.warnonce "The interpreter parameter to 'setcode' is deprecated and will be removed in a future version." if interp - if string - <at> code = string - <at> interpreter = interp || INTERPRETER - else - unless block_given? - raise ArgumentError, "You must pass either code or a block" - end - <at> code = block - end + end + + # We need this as a getter for 'timeout', because some versions + # of ruby seem to already have a 'timeout' method and we can't + # seem to override the instance methods, somehow. + def limit + <at> timeout + end + + # Set our code for returning a value. + def setcode(string = nil, interp = nil, &block) + Facter.warnonce "The interpreter parameter to 'setcode' is deprecated and will be removed in a future version." if interp + if string + <at> code = string + <at> interpreter = interp || INTERPRETER + else + unless block_given? + raise ArgumentError, "You must pass either code or a block" + end + <at> code = block end - - def interpreter - Facter.warnonce "The 'Facter::Util::Resolution.interpreter' method is deprecated and will be removed in a future version." - <at> interpreter + end + + def interpreter + Facter.warnonce "The 'Facter::Util::Resolution.interpreter' method is deprecated and will be removed in a future version." + <at> interpreter + end + + def interpreter=(interp) + Facter.warnonce "The 'Facter::Util::Resolution.interpreter=' method is deprecated and will be removed in a future version." + <at> interpreter = interp + end + + # Is this resolution mechanism suitable on the system in question? + def suitable? + unless defined? <at> suitable + <at> suitable = ! <at> confines.detect { |confine| ! confine.true? } end - def interpreter=(interp) - Facter.warnonce "The 'Facter::Util::Resolution.interpreter=' method is deprecated and will be removed in a future version." - <at> interpreter = interp - end + return <at> suitable + end - # Is this resolution mechanism suitable on the system in question? - def suitable? - unless defined? <at> suitable - <at> suitable = ! <at> confines.detect { |confine| ! confine.true? } - end + def to_s + return self.value() + end - return <at> suitable - end + # How we get a value for our resolution mechanism. + def value + result = nil + return result if <at> code == nil - def to_s - return self.value() - end + starttime = Time.now.to_f - # How we get a value for our resolution mechanism. - def value - result = nil - return result if <at> code == nil - - starttime = Time.now.to_f - - begin - Timeout.timeout(limit) do - if <at> code.is_a?(Proc) - result = <at> code.call() - else - result = Facter::Util::Resolution.exec( <at> code) - end - end - rescue Timeout::Error => detail - warn "Timed out seeking value for %s" % self.name - - # This call avoids zombies -- basically, create a thread that will - # dezombify all of the child processes that we're ignoring because - # of the timeout. - Thread.new { Process.waitall } - return nil - rescue => details - warn "Could not retrieve %s: %s" % [self.name, details] - return nil + begin + Timeout.timeout(limit) do + if <at> code.is_a?(Proc) + result = <at> code.call() + else + result = Facter::Util::Resolution.exec( <at> code) end + end + rescue Timeout::Error => detail + warn "Timed out seeking value for %s" % self.name + + # This call avoids zombies -- basically, create a thread that will + # dezombify all of the child processes that we're ignoring because + # of the timeout. + Thread.new { Process.waitall } + return nil + rescue => details + warn "Could not retrieve %s: %s" % [self.name, details] + return nil + end - finishtime = Time.now.to_f - ms = (finishtime - starttime) * 1000 - Facter.show_time "#{self.name}: #{"%.2f" % ms}ms" + finishtime = Time.now.to_f + ms = (finishtime - starttime) * 1000 + Facter.show_time "#{self.name}: #{"%.2f" % ms}ms" - return nil if result == "" - return result - end + return nil if result == "" + return result + end end diff --git a/lib/facter/util/uptime.rb b/lib/facter/util/uptime.rb index a816623..772cc87 100644 --- a/lib/facter/util/uptime.rb +++ b/lib/facter/util/uptime.rb <at> <at> -3,63 +3,63 <at> <at> require 'time' # A module to gather uptime facts # module Facter::Util::Uptime - def self.get_uptime_seconds_unix - uptime_proc_uptime or uptime_sysctl or uptime_kstat or uptime_who_dash_b - end + def self.get_uptime_seconds_unix + uptime_proc_uptime or uptime_sysctl or uptime_kstat or uptime_who_dash_b + end - def self.get_uptime_seconds_win - require 'facter/util/wmi' + def self.get_uptime_seconds_win + require 'facter/util/wmi' - last_boot = "" - Facter::Util::WMI.execquery("select * from Win32_OperatingSystem").each do |x| - last_boot = x.LastBootupTime - end - self.compute_uptime(Time.parse(last_boot.split('.').first)) + last_boot = "" + Facter::Util::WMI.execquery("select * from Win32_OperatingSystem").each do |x| + last_boot = x.LastBootupTime end + self.compute_uptime(Time.parse(last_boot.split('.').first)) + end - private + private - def self.uptime_proc_uptime - if output = Facter::Util::Resolution.exec("/bin/cat #{uptime_file} 2>/dev/null") - output.chomp.split(" ").first.to_i - end + def self.uptime_proc_uptime + if output = Facter::Util::Resolution.exec("/bin/cat #{uptime_file} 2>/dev/null") + output.chomp.split(" ").first.to_i end + end - def self.uptime_sysctl - if output = Facter::Util::Resolution.exec("#{uptime_sysctl_cmd} 2>/dev/null") - compute_uptime(Time.at(output.unpack('L').first)) - end + def self.uptime_sysctl + if output = Facter::Util::Resolution.exec("#{uptime_sysctl_cmd} 2>/dev/null") + compute_uptime(Time.at(output.unpack('L').first)) end + end - def self.uptime_kstat - if output = Facter::Util::Resolution.exec("#{uptime_kstat_cmd} 2>/dev/null") - compute_uptime(Time.at(output.chomp.split(/\s/).last.to_i)) - end + def self.uptime_kstat + if output = Facter::Util::Resolution.exec("#{uptime_kstat_cmd} 2>/dev/null") + compute_uptime(Time.at(output.chomp.split(/\s/).last.to_i)) end + end - def self.uptime_who_dash_b - if output = Facter::Util::Resolution.exec("#{uptime_who_cmd} 2>/dev/null") - compute_uptime(Time.parse(output)) - end + def self.uptime_who_dash_b + if output = Facter::Util::Resolution.exec("#{uptime_who_cmd} 2>/dev/null") + compute_uptime(Time.parse(output)) end + end - def self.compute_uptime(time) - (Time.now - time).to_i - end + def self.compute_uptime(time) + (Time.now - time).to_i + end - def self.uptime_file - "/proc/uptime" - end + def self.uptime_file + "/proc/uptime" + end - def self.uptime_sysctl_cmd - 'sysctl -b kern.boottime' - end + def self.uptime_sysctl_cmd + 'sysctl -b kern.boottime' + end - def self.uptime_kstat_cmd - 'kstat -p unix:::boot_time' - end + def self.uptime_kstat_cmd + 'kstat -p unix:::boot_time' + end - def self.uptime_who_cmd - 'who -b' - end + def self.uptime_who_cmd + 'who -b' + end end diff --git a/lib/facter/util/values.rb b/lib/facter/util/values.rb index ebc7614..68ace34 100644 --- a/lib/facter/util/values.rb +++ b/lib/facter/util/values.rb <at> <at> -1,14 +1,14 <at> <at> # A util module for facter containing helper methods module Facter - module Util - module Values - module_function + module Util + module Values + module_function - def convert(value) - value = value.to_s if value.is_a?(Symbol) - value = value.downcase if value.is_a?(String) - value - end - end + def convert(value) + value = value.to_s if value.is_a?(Symbol) + value = value.downcase if value.is_a?(String) + value + end end + end end diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb index 0ae7c8f..01b71b3 100644 --- a/lib/facter/util/virtual.rb +++ b/lib/facter/util/virtual.rb <at> <at> -1,86 +1,86 <at> <at> module Facter::Util::Virtual - def self.openvz? - FileTest.directory?("/proc/vz") and not self.openvz_cloudlinux? - end + def self.openvz? + FileTest.directory?("/proc/vz") and not self.openvz_cloudlinux? + end - # So one can either have #6728 work on OpenVZ or Cloudlinux. Whoo. - def self.openvz_type - return false unless self.openvz? - return false unless FileTest.exists?( '/proc/self/status' ) + # So one can either have #6728 work on OpenVZ or Cloudlinux. Whoo. + def self.openvz_type + return false unless self.openvz? + return false unless FileTest.exists?( '/proc/self/status' ) - envid = Facter::Util::Resolution.exec( 'grep "envID" /proc/self/status' ) - if envid =~ /^envID:\s+0$/i - return 'openvzhn' - elsif envid =~ /^envID:\s+(\d+)$/i - return 'openvzve' - end + envid = Facter::Util::Resolution.exec( 'grep "envID" /proc/self/status' ) + if envid =~ /^envID:\s+0$/i + return 'openvzhn' + elsif envid =~ /^envID:\s+(\d+)$/i + return 'openvzve' end + end - # Cloudlinux uses OpenVZ to a degree, but always has an empty /proc/vz/ and - # has /proc/lve/list present - def self.openvz_cloudlinux? - FileTest.file?("/proc/lve/list") or Dir.glob('/proc/vz/*').empty? - end + # Cloudlinux uses OpenVZ to a degree, but always has an empty /proc/vz/ and + # has /proc/lve/list present + def self.openvz_cloudlinux? + FileTest.file?("/proc/lve/list") or Dir.glob('/proc/vz/*').empty? + end - def self.zone? - return true if FileTest.directory?("/.SUNWnative") - z = Facter::Util::Resolution.exec("/sbin/zonename") - return false unless z - return z.chomp != 'global' - end + def self.zone? + return true if FileTest.directory?("/.SUNWnative") + z = Facter::Util::Resolution.exec("/sbin/zonename") + return false unless z + return z.chomp != 'global' + end - def self.vserver? - return false unless FileTest.exists?("/proc/self/status") - txt = File.read("/proc/self/status") - return true if txt =~ /^(s_context|VxID):[[:blank:]]*[0-9]/ - return false - end + def self.vserver? + return false unless FileTest.exists?("/proc/self/status") + txt = File.read("/proc/self/status") + return true if txt =~ /^(s_context|VxID):[[:blank:]]*[0-9]/ + return false + end - def self.vserver_type - if self.vserver? - if FileTest.exists?("/proc/virtual") - "vserver_host" - else - "vserver" - end - end + def self.vserver_type + if self.vserver? + if FileTest.exists?("/proc/virtual") + "vserver_host" + else + "vserver" + end end + end - def self.xen? - ["/proc/sys/xen", "/sys/bus/xen", "/proc/xen" ].detect do |f| - FileTest.exists?(f) - end + def self.xen? + ["/proc/sys/xen", "/sys/bus/xen", "/proc/xen" ].detect do |f| + FileTest.exists?(f) end + end - def self.kvm? - txt = if FileTest.exists?("/proc/cpuinfo") - File.read("/proc/cpuinfo") - elsif Facter.value(:kernel)=="FreeBSD" - Facter::Util::Resolution.exec("/sbin/sysctl -n hw.model") - end - (txt =~ /QEMU Virtual CPU/) ? true : false - end + def self.kvm? + txt = if FileTest.exists?("/proc/cpuinfo") + File.read("/proc/cpuinfo") + elsif Facter.value(:kernel)=="FreeBSD" + Facter::Util::Resolution.exec("/sbin/sysctl -n hw.model") + end + (txt =~ /QEMU Virtual CPU/) ? true : false + end - def self.kvm_type - # TODO Tell the difference between kvm and qemu - # Can't work out a way to do this at the moment that doesn't - # require a special binary - "kvm" - end + def self.kvm_type + # TODO Tell the difference between kvm and qemu + # Can't work out a way to do this at the moment that doesn't + # require a special binary + "kvm" + end - def self.jail? - path = case Facter.value(:kernel) - when "FreeBSD" then "/sbin" - when "GNU/kFreeBSD" then "/bin" - end - Facter::Util::Resolution.exec("#{path}/sysctl -n security.jail.jailed") == "1" + def self.jail? + path = case Facter.value(:kernel) + when "FreeBSD" then "/sbin" + when "GNU/kFreeBSD" then "/bin" end + Facter::Util::Resolution.exec("#{path}/sysctl -n security.jail.jailed") == "1" + end - def self.hpvm? - Facter::Util::Resolution.exec("/usr/bin/getconf MACHINE_MODEL").chomp =~ /Virtual Machine/ - end + def self.hpvm? + Facter::Util::Resolution.exec("/usr/bin/getconf MACHINE_MODEL").chomp =~ /Virtual Machine/ + end def self.zlinux? - "zlinux" + "zlinux" end end diff --git a/lib/facter/util/vlans.rb b/lib/facter/util/vlans.rb index 2b2a72f..0a48ec8 100644 --- a/lib/facter/util/vlans.rb +++ b/lib/facter/util/vlans.rb <at> <at> -1,24 +1,24 <at> <at> # A module to gather vlan facts # module Facter::Util::Vlans - def self.get_vlan_config - output = "" - if File.exists?('/proc/net/vlan/config') and File.readable?('/proc/net/vlan/config') - output = File.open('/proc/net/vlan/config').read - end - output - end + def self.get_vlan_config + output = "" + if File.exists?('/proc/net/vlan/config') and File.readable?('/proc/net/vlan/config') + output = File.open('/proc/net/vlan/config').read + end + output + end - def self.get_vlans - vlans = Array.new - if self.get_vlan_config - self.get_vlan_config.each_line do |line| - if line =~ /^([0-9A-Za-z]+)\.([0-9]+) / - vlans.insert(-1, $~[2]) if $~[2] - end - end + def self.get_vlans + vlans = Array.new + if self.get_vlan_config + self.get_vlan_config.each_line do |line| + if line =~ /^([0-9A-Za-z]+)\.([0-9]+) / + vlans.insert(-1, $~[2]) if $~[2] end - - vlans.join(',') + end end + + vlans.join(',') + end end diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb index 578562a..d46d4a9 100644 --- a/lib/facter/virtual.rb +++ b/lib/facter/virtual.rb <at> <at> -10,8 +10,8 <at> <at> # display. # # On Linux, BSD, Solaris and HPUX: -# Much of the logic here is obscured behind util/virtual.rb, which rather -# than document here, which would encourage drift, just refer to it. +# Much of the logic here is obscured behind util/virtual.rb, which rather +# than document here, which would encourage drift, just refer to it. # The Xen tests in here rely on /sys and /proc, and check for the presence and # contents of files in there. # If after all the other tests, it's still seen as physical, then it tries to <at> <at> -27,120 +27,120 <at> <at> require 'facter/util/virtual' Facter.add("virtual") do - confine :kernel => "Darwin" - - setcode do - require 'facter/util/macosx' - result = "physical" - output = Facter::Util::Macosx.profiler_data("SPDisplaysDataType") - if output.is_a?(Hash) - result = "parallels" if output["spdisplays_vendor-id"] =~ /0x1ab8/ - result = "parallels" if output["spdisplays_vendor"] =~ /[Pp]arallels/ - result = "vmware" if output["spdisplays_vendor-id"] =~ /0x15ad/ - result = "vmware" if output["spdisplays_vendor"] =~ /VM[wW]are/ - result = "virtualbox" if output["spdisplays_vendor-id"] =~ /0x80ee/ - end - result + confine :kernel => "Darwin" + + setcode do + require 'facter/util/macosx' + result = "physical" + output = Facter::Util::Macosx.profiler_data("SPDisplaysDataType") + if output.is_a?(Hash) + result = "parallels" if output["spdisplays_vendor-id"] =~ /0x1ab8/ + result = "parallels" if output["spdisplays_vendor"] =~ /[Pp]arallels/ + result = "vmware" if output["spdisplays_vendor-id"] =~ /0x15ad/ + result = "vmware" if output["spdisplays_vendor"] =~ /VM[wW]are/ + result = "virtualbox" if output["spdisplays_vendor-id"] =~ /0x80ee/ end + result + end end Facter.add("virtual") do - confine :kernel => %w{Linux FreeBSD OpenBSD SunOS HP-UX GNU/kFreeBSD} + confine :kernel => %w{Linux FreeBSD OpenBSD SunOS HP-UX GNU/kFreeBSD} - result = "physical" + result = "physical" - setcode do + setcode do - if Facter.value(:operatingsystem) == "Solaris" and Facter::Util::Virtual.zone? - result = "zone" - end + if Facter.value(:operatingsystem) == "Solaris" and Facter::Util::Virtual.zone? + result = "zone" + end - if Facter.value(:kernel)=="HP-UX" - result = "hpvm" if Facter::Util::Virtual.hpvm? - end + if Facter.value(:kernel)=="HP-UX" + result = "hpvm" if Facter::Util::Virtual.hpvm? + end - if Facter.value(:architecture)=="s390x" - result = "zlinux" if Facter::Util::Virtual.zlinux? - end + if Facter.value(:architecture)=="s390x" + result = "zlinux" if Facter::Util::Virtual.zlinux? + end - if Facter::Util::Virtual.openvz? - result = Facter::Util::Virtual.openvz_type() - end + if Facter::Util::Virtual.openvz? + result = Facter::Util::Virtual.openvz_type() + end - if Facter::Util::Virtual.vserver? - result = Facter::Util::Virtual.vserver_type() - end + if Facter::Util::Virtual.vserver? + result = Facter::Util::Virtual.vserver_type() + end - if Facter::Util::Virtual.xen? - if FileTest.exists?("/proc/xen/xsd_kva") - result = "xen0" - elsif FileTest.exists?("/proc/xen/capabilities") - result = "xenu" - end - end + if Facter::Util::Virtual.xen? + if FileTest.exists?("/proc/xen/xsd_kva") + result = "xen0" + elsif FileTest.exists?("/proc/xen/capabilities") + result = "xenu" + end + end - if Facter::Util::Virtual.kvm? - result = Facter::Util::Virtual.kvm_type() - end + if Facter::Util::Virtual.kvm? + result = Facter::Util::Virtual.kvm_type() + end - if ["FreeBSD", "GNU/kFreeBSD"].include? Facter.value(:kernel) - result = "jail" if Facter::Util::Virtual.jail? - end + if ["FreeBSD", "GNU/kFreeBSD"].include? Facter.value(:kernel) + result = "jail" if Facter::Util::Virtual.jail? + end - if result == "physical" - output = Facter::Util::Resolution.exec('lspci') - if not output.nil? - output.each_line do |p| - # --- look for the vmware video card to determine if it is virtual => vmware. - # --- 00:0f.0 VGA compatible controller: VMware Inc [VMware SVGA II] PCI Display Adapter - result = "vmware" if p =~ /VM[wW]are/ - # --- look for virtualbox video card to determine if it is virtual => virtualbox. - # --- 00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter - result = "virtualbox" if p =~ /VirtualBox/ - # --- look for pci vendor id used by Parallels video card - # --- 01:00.0 VGA compatible controller: Unknown device 1ab8:4005 - result = "parallels" if p =~ /1ab8:|[Pp]arallels/ - # --- look for pci vendor id used by Xen HVM device - # --- 00:03.0 Unassigned class [ff80]: XenSource, Inc. Xen Platform Device (rev 01) - result = "xenhvm" if p =~ /XenSource/ - # --- look for Hyper-V video card - # --- 00:08.0 VGA compatible controller: Microsoft Corporation Hyper-V virtual VGA - result = "hyperv" if p =~ /Microsoft Corporation Hyper-V/ - end - else - output = Facter::Util::Resolution.exec('dmidecode') - if not output.nil? - output.each_line do |pd| - result = "parallels" if pd =~ /Parallels/ - result = "vmware" if pd =~ /VMware/ - result = "virtualbox" if pd =~ /VirtualBox/ - result = "xenhvm" if pd =~ /HVM domU/ - result = "hyperv" if pd =~ /Product Name: Virtual Machine/ - end - elsif Facter.value(:kernel) == 'SunOS' - res = Facter::Util::Resolution.new('prtdiag') - res.timeout = 6 - res.setcode('prtdiag') - output = res.value - if not output.nil? - output.each_line do |pd| - result = "parallels" if pd =~ /Parallels/ - result = "vmware" if pd =~ /VMware/ - result = "virtualbox" if pd =~ /VirtualBox/ - result = "xenhvm" if pd =~ /HVM domU/ - end - end - end - end - - if output = Facter::Util::Resolution.exec("vmware -v") - result = output.sub(/(\S+)\s+(\S+).*/) { | text | "#{$1}_#{$2}"}.downcase + if result == "physical" + output = Facter::Util::Resolution.exec('lspci') + if not output.nil? + output.each_line do |p| + # --- look for the vmware video card to determine if it is virtual => vmware. + # --- 00:0f.0 VGA compatible controller: VMware Inc [VMware SVGA II] PCI Display Adapter + result = "vmware" if p =~ /VM[wW]are/ + # --- look for virtualbox video card to determine if it is virtual => virtualbox. + # --- 00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter + result = "virtualbox" if p =~ /VirtualBox/ + # --- look for pci vendor id used by Parallels video card + # --- 01:00.0 VGA compatible controller: Unknown device 1ab8:4005 + result = "parallels" if p =~ /1ab8:|[Pp]arallels/ + # --- look for pci vendor id used by Xen HVM device + # --- 00:03.0 Unassigned class [ff80]: XenSource, Inc. Xen Platform Device (rev 01) + result = "xenhvm" if p =~ /XenSource/ + # --- look for Hyper-V video card + # --- 00:08.0 VGA compatible controller: Microsoft Corporation Hyper-V virtual VGA + result = "hyperv" if p =~ /Microsoft Corporation Hyper-V/ + end + else + output = Facter::Util::Resolution.exec('dmidecode') + if not output.nil? + output.each_line do |pd| + result = "parallels" if pd =~ /Parallels/ + result = "vmware" if pd =~ /VMware/ + result = "virtualbox" if pd =~ /VirtualBox/ + result = "xenhvm" if pd =~ /HVM domU/ + result = "hyperv" if pd =~ /Product Name: Virtual Machine/ + end + elsif Facter.value(:kernel) == 'SunOS' + res = Facter::Util::Resolution.new('prtdiag') + res.timeout = 6 + res.setcode('prtdiag') + output = res.value + if not output.nil? + output.each_line do |pd| + result = "parallels" if pd =~ /Parallels/ + result = "vmware" if pd =~ /VMware/ + result = "virtualbox" if pd =~ /VirtualBox/ + result = "xenhvm" if pd =~ /HVM domU/ end + end end - - result + end + + if output = Facter::Util::Resolution.exec("vmware -v") + result = output.sub(/(\S+)\s+(\S+).*/) { | text | "#{$1}_#{$2}"}.downcase + end end + + result + end end # Fact: is_virtual <at> <at> -155,15 +155,15 <at> <at> end # Facter.add("is_virtual") do - confine :kernel => %w{Linux FreeBSD OpenBSD SunOS HP-UX Darwin GNU/kFreeBSD} + confine :kernel => %w{Linux FreeBSD OpenBSD SunOS HP-UX Darwin GNU/kFreeBSD} - setcode do - physical_types = %w{physical xen0 vmware_server vmware_workstation openvzhn} + setcode do + physical_types = %w{physical xen0 vmware_server vmware_workstation openvzhn} - if physical_types.include? Facter.value(:virtual) - "false" - else - "true" - end + if physical_types.include? Facter.value(:virtual) + "false" + else + "true" end + end end diff --git a/lib/facter/vlans.rb b/lib/facter/vlans.rb index 8c485a4..341d867 100644 --- a/lib/facter/vlans.rb +++ b/lib/facter/vlans.rb <at> <at> -10,9 +10,9 <at> <at> require 'facter/util/vlans' - Facter.add("vlans") do - confine :kernel => :linux - setcode do - Facter::Util::Vlans.get_vlans - end - end +Facter.add("vlans") do + confine :kernel => :linux + setcode do + Facter::Util::Vlans.get_vlans + end +end diff --git a/spec/integration/facter_spec.rb b/spec/integration/facter_spec.rb index 8351de1..cce148f 100755 --- a/spec/integration/facter_spec.rb +++ b/spec/integration/facter_spec.rb <at> <at> -3,25 +3,25 <at> <at> require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe Facter do - before do - Facter.reset - end + before do + Facter.reset + end - after do - Facter.reset - end + after do + Facter.reset + end - it "should create a new collection if one does not exist" do - Facter.reset - coll = mock('coll') - Facter::Util::Collection.stubs(:new).returns coll - Facter.collection.should equal(coll) - Facter.reset - end + it "should create a new collection if one does not exist" do + Facter.reset + coll = mock('coll') + Facter::Util::Collection.stubs(:new).returns coll + Facter.collection.should equal(coll) + Facter.reset + end - it "should remove the collection when reset" do - old = Facter.collection - Facter.reset - Facter.collection.should_not equal(old) - end + it "should remove the collection when reset" do + old = Facter.collection + Facter.reset + Facter.collection.should_not equal(old) + end end diff --git a/spec/unit/memory_spec.rb b/spec/unit/memory_spec.rb index 175904f..28f1638 100755 --- a/spec/unit/memory_spec.rb +++ b/spec/unit/memory_spec.rb <at> <at> -42,7 +42,7 <at> <at> describe "Memory facts" do swapusage = "vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)" swapusage =~ /\(encrypted\)/ - Facter.fact(:swapencrypted).value.should == true + Facter.fact(:swapencrypted).value.should == true end describe "on OpenBSD" do diff --git a/spec/unit/util/uptime_spec.rb b/spec/unit/util/uptime_spec.rb index 1c50d31..fe28d16 100755 --- a/spec/unit/util/uptime_spec.rb +++ b/spec/unit/util/uptime_spec.rb <at> <at> -28,10 +28,10 <at> <at> describe Facter::Util::Uptime do it "should use 'sysctl kern.boottime'" do if [1].pack("L") == [1].pack("V") # Determine endianness - sysctl_output_filename = 'sysctl_kern_boottime_little_endian' - else - sysctl_output_filename = 'sysctl_kern_boottime_big_endian' - end + sysctl_output_filename = 'sysctl_kern_boottime_little_endian' + else + sysctl_output_filename = 'sysctl_kern_boottime_big_endian' + end sysctl_output_file = File.join(SPECDIR, 'fixtures', 'uptime', sysctl_output_filename) # Aug 01 14:13:47 -0700 2010 Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat \"#{sysctl_output_file}\"") Time.stubs(:now).returns Time.parse("Aug 01 15:13:47 -0700 2010") # one hour later diff --git a/tasks/rake/changlog.rake b/tasks/rake/changlog.rake index 0c2f1d2..0dcd91c 100644 --- a/tasks/rake/changlog.rake +++ b/tasks/rake/changlog.rake <at> <at> -1,15 +1,15 <at> <at> desc "Create a ChangeLog based on git commits." task :changelog do - begin - gitc = %x{which git-changelog} - rescue - puts "This task needs the git-changelog binary - http://github.com/ReinH/git-changelog" - end + begin + gitc = %x{which git-changelog} + rescue + puts "This task needs the git-changelog binary - http://github.com/ReinH/git-changelog" + end - CHANGELOG_DIR = "#{Dir.pwd}" - mkdir(CHANGELOG_DIR) unless File.directory?(CHANGELOG_DIR) - change_body = `git-changelog --limit=99999` - File.open(File.join(CHANGELOG_DIR, "CHANGELOG"), 'w') do |f| - f << change_body - end + CHANGELOG_DIR = "#{Dir.pwd}" + mkdir(CHANGELOG_DIR) unless File.directory?(CHANGELOG_DIR) + change_body = `git-changelog --limit=99999` + File.open(File.join(CHANGELOG_DIR, "CHANGELOG"), 'w') do |f| + f << change_body + end end diff --git a/tasks/rake/ci.rake b/tasks/rake/ci.rake index e0e5aed..abd2754 100644 --- a/tasks/rake/ci.rake +++ b/tasks/rake/ci.rake <at> <at> -1,14 +1,14 <at> <at> desc "Prep CI RSpec tests" task :ci_prep do - require 'rubygems' - begin - gem 'ci_reporter' - require 'ci/reporter/rake/rspec' - require 'ci/reporter/rake/test_unit' - ENV['CI_REPORTS'] = 'results' - rescue LoadError - puts 'Missing ci_reporter gem. You must have the ci_reporter gem installed to run the CI spec tests' - end + require 'rubygems' + begin + gem 'ci_reporter' + require 'ci/reporter/rake/rspec' + require 'ci/reporter/rake/test_unit' + ENV['CI_REPORTS'] = 'results' + rescue LoadError + puts 'Missing ci_reporter gem. You must have the ci_reporter gem installed to run the CI spec tests' + end end desc "Run the CI RSpec tests" diff --git a/tasks/rake/mail_patches.rake b/tasks/rake/mail_patches.rake index 1346faa..7a9f2ea 100644 --- a/tasks/rake/mail_patches.rake +++ b/tasks/rake/mail_patches.rake <at> <at> -1,48 +1,48 <at> <at> desc "Send patch information to the puppet-dev list" task :mail_patches do - if Dir.glob("00*.patch").length > 0 - raise "Patches already exist matching '00*.patch'; clean up first" + if Dir.glob("00*.patch").length > 0 + raise "Patches already exist matching '00*.patch'; clean up first" + end + + unless %x{git status} =~ /On branch (.+)/ + raise "Could not get branch from 'git status'" + end + branch = $1 + + unless branch =~ %r{^([^\/]+)/([^\/]+)/([^\/]+)$} + raise "Branch name does not follow <type>/<parent>/<name> model; cannot autodetect parent branch" + end + + type, parent, name = $1, $2, $3 + + # Create all of the patches + sh "git format-patch -C -M -s -n --subject-prefix='PATCH/facter' #{parent}..HEAD" + + # Add info to the patches + additional_info = "Local-branch: #{branch}\n" + files = Dir.glob("00*.patch") + files.each do |file| + contents = File.read(file) + contents.sub!(/^---\n/, "---\n#{additional_info}") + File.open(file, 'w') do |file_handle| + file_handle.print contents end + end - unless %x{git status} =~ /On branch (.+)/ - raise "Could not get branch from 'git status'" - end - branch = $1 - - unless branch =~ %r{^([^\/]+)/([^\/]+)/([^\/]+)$} - raise "Branch name does not follow <type>/<parent>/<name> model; cannot autodetect parent branch" - end - - type, parent, name = $1, $2, $3 - - # Create all of the patches - sh "git format-patch -C -M -s -n --subject-prefix='PATCH/facter' #{parent}..HEAD" + # And then mail them out. - # Add info to the patches - additional_info = "Local-branch: #{branch}\n" - files = Dir.glob("00*.patch") - files.each do |file| - contents = File.read(file) - contents.sub!(/^---\n/, "---\n#{additional_info}") - File.open(file, 'w') do |file_handle| - file_handle.print contents - end - end - - # And then mail them out. - - # If we've got more than one patch, add --compose - if files.length > 1 - compose = "--compose" - subject = %Q{--subject "#{type} #{name} against #{parent}"} - else - compose = "" - subject = "" - end + # If we've got more than one patch, add --compose + if files.length > 1 + compose = "--compose" + subject = %Q{--subject "#{type} #{name} against #{parent}"} + else + compose = "" + subject = "" + end - # Now send the mail. - sh "git send-email #{compose} #{subject} --no-signed-off-by-cc --suppress-from --to puppet-dev <at> googlegroups.com 00*.patch" + # Now send the mail. + sh "git send-email #{compose} #{subject} --no-signed-off-by-cc --suppress-from --to puppet-dev <at> googlegroups.com 00*.patch" - # Finally, clean up the patches - sh "rm 00*.patch" + # Finally, clean up the patches + sh "rm 00*.patch" end diff --git a/tasks/rake/metrics.rake b/tasks/rake/metrics.rake index 63af552..214cc99 100644 --- a/tasks/rake/metrics.rake +++ b/tasks/rake/metrics.rake <at> <at> -1,6 +1,6 <at> <at> begin - require 'metric_fu' + require 'metric_fu' rescue LoadError - # Metric-fu not installed - # http://metric-fu.rubyforge.org/ + # Metric-fu not installed + # http://metric-fu.rubyforge.org/ end diff --git a/tasks/rake/sign.rake b/tasks/rake/sign.rake index f0e9d83..7035166 100644 --- a/tasks/rake/sign.rake +++ b/tasks/rake/sign.rake <at> <at> -1,14 +1,14 <at> <at> desc "Sign the package with the Puppet Labs release key" task :sign_packages do -version = Facter::FACTERVERSION + version = Facter::FACTERVERSION -# Sign package + # Sign package -sh "gpg --homedir $HOME/pl_release_key --detach-sign --output pkg/facter-#{version}.tar.gz.sign --armor pkg/facter-#{version}.tar.gz" + sh "gpg --homedir $HOME/pl_release_key --detach-sign --output pkg/facter-#{version}.tar.gz.sign --armor pkg/facter-#{version}.tar.gz" -# Sign gem + # Sign gem -sh "gpg --homedir $HOME/pl_release_key --detach-sign --output pkg/facter-#{version}.gem.sign --armor pkg/facter-#{version}.gem" + sh "gpg --homedir $HOME/pl_release_key --detach-sign --output pkg/facter-#{version}.gem.sign --armor pkg/facter-#{version}.gem" end

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to puppet-dev <at> googlegroups.com.
To unsubscribe from this group, send email to puppet-dev+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
wearetherobots | 1 Oct 2011 03:15

(puppetlabs/facter) Closed pull request: Ticket/9555 fix whitespace

Greetings!

On Sat Oct 01 01:05:46 UTC 2011 pull request #74 was closed.

Ticket/9555 fix whitespace requested by (kbarber)

The pull request was merged by: jamtur01

Thanks!
The Pull Request Bot

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to puppet-dev <at> googlegroups.com.
To unsubscribe from this group, send email to puppet-dev+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
Ken Barber | 1 Oct 2011 03:45
Gravatar

Re: facter and indent spacing

So the Facter merge-a-thon this week was very successful. We managed
to merge in something like 15 patches between myself and Adrien Thebo
which is quite awesome. Only 2 requests are outstanding, 1 of my own
(external facts) and another which is a minor change. The work should
surface in the next release of 1.6. Thanks to everyone for their help
- and all the community contributors that provided enhancements and
bug fixes - you guys rock :-).

9555 has been merged in ... so we now have consistent spacing across Facter.

Enjoy :-).

ken.

On Tue, Sep 20, 2011 at 1:30 PM, Michael Stahnke <stahnma <at> puppetlabs.com> wrote:
> On Tue, Sep 20, 2011 at 4:55 AM, Ken Barber <ken <at> puppetlabs.com> wrote:
>> Interesting approach. I'll be in portland for a week after puppetconf.
>> Happy to lend a hand.
>>
>> On Tue, Sep 20, 2011 at 2:48 AM, Luke Kanies <luke <at> puppetlabs.com> wrote:
>>> I agree. Maybe it's worth a merge-a-thon to get as many merged as possible
>>> in a fixed amount of time, then just draw the line?
> I think a merge-a-thon sounds like the best bet.  We have quite a bit
> of outstanding code in topic branches, pulls, etc.  Let's get it
> tested and put in, then switch the spacing.
>
> Mike
>
>>>
>>> --
>>> Luke Kanies | +1-615-594-8199 | http:/about.me/lak
>>> On Sep 19, 2011, at 3:22 PM, Adrien Thebo <adrien <at> puppetlabs.com> wrote:
>>>
>>> I'm of two minds of this. On one hand, it would be terribly nice to get as
>>> many patches merged as possible before we do a whitespace change just so
>>> that we don't have to deal with any weird conflicts. On the other hand, as
>>> you said git can probably handle the whitespace change, and I would like to
>>> drive this change through as soon as possible. Since facter bugs do tend to
>>> sit for a while, I would like to get up the momentum to drive through the
>>> whitespace for 1.7.x before too much time passes.
>>>
>>> On Mon, Sep 19, 2011 at 6:36 AM, Ken Barber <ken <at> puppetlabs.com> wrote:
>>>>
>>>> Hi,
>>>>
>>>> So I raised a ticket for fixing mixed whitespace in facter:
>>>>
>>>> http://projects.puppetlabs.com/issues/9555
>>>>
>>>> And I've got a preliminary patch in a topic branch just to see how bad
>>>> the problem is. The reason I've raised this is that people making
>>>> changes across multiple files at the moment are finding that some
>>>> files are 4 space indents, some are 2 space - and sometimes people are
>>>> mixing 2 space indents within 4 space indent files.
>>>>
>>>> I know we've done this before for Puppet - so I wouldn't mind getting
>>>> some opinion and ideas on this kind of a change. From an offline
>>>> discussion with Adrien Thebo we obviously want to make this easy for
>>>> any forward porting of patches from 1.6 to other branches. It was
>>>> suggested this kind of change wait for 1.7 which is cool - but if we
>>>> still are doing active development on 1.6 the forward porting maybe
>>>> become painful. Should we just do this across all active 'supported'
>>>> branches so we can feel the pain once and cherry-picked patches for
>>>> forward porting can then be more trivial? There is 15 pending merges
>>>> that would _potentially_ need to be fixed (and who knows how many that
>>>> haven't been requested yet that would need rebasing/fixing).
>>>>
>>>> Looking at the whitespace merge techniques around the net I can see
>>>> there is a recursive merge strategy option for ignoring whitespace
>>>> (-Xignore-space-change) but this seems to be in the wrong direction to
>>>> what we would desire. While rebase has an option to ignore whitespace
>>>> so at the very least this could be made easier for active development
>>>> work.
>>>>
>>>> What do people think about this? Does anyone have any experience with
>>>> feeling the pain of such a change? Is there a good strategy to adopt
>>>> here? I guess my attitude is that the sooner this is done the better,
>>>> but perhaps I'm being naive.
>>>>
>>>> ken.
>>>>
>>>> --
>>>> "Join us for PuppetConf, September 22nd and 23rd in Portland, OR:
>>>> http://bit.ly/puppetconfsig"
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google Groups
>>>> "Puppet Developers" group.
>>>> To post to this group, send email to puppet-dev <at> googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> puppet-dev+unsubscribe <at> googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/puppet-dev?hl=en.
>>>>
>>>
>>>
>>>
>>> --
>>> Adrien Thebo
>>> adrien <at> puppetlabs.com
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Puppet Developers" group.
>>> To post to this group, send email to puppet-dev <at> googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> puppet-dev+unsubscribe <at> googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/puppet-dev?hl=en.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Puppet Developers" group.
>>> To post to this group, send email to puppet-dev <at> googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> puppet-dev+unsubscribe <at> googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/puppet-dev?hl=en.
>>>
>>
>>
>>
>> --
>> "Join us for PuppetConf, September 22nd and 23rd in Portland, OR:
>> http://bit.ly/puppetconfsig"
>>
>> --
>> You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
>> To post to this group, send email to puppet-dev <at> googlegroups.com.
>> To unsubscribe from this group, send email to puppet-dev+unsubscribe <at> googlegroups.com.
>> For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
> To post to this group, send email to puppet-dev <at> googlegroups.com.
> To unsubscribe from this group, send email to puppet-dev+unsubscribe <at> googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
>
>

--

-- 
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to puppet-dev <at> googlegroups.com.
To unsubscribe from this group, send email to puppet-dev+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.

wearetherobots | 2 Oct 2011 23:30

(puppetlabs/puppet-docs) New pull request: get equipped for vagrant users

Greetings!

Please review the pull request #17: get equipped for vagrant users opened by (lvnilesh)

Some more information about the pull request:

  • Opened: Sun Oct 02 21:24:54 UTC 2011
  • Based on: puppetlabs:master (184a2bb5fc58bd0f9a65d564a13cb89f76cb6f16)
  • Requested merge: fungibleclouds:master (26d8a7886ea39e3d644f8a35149948ddc3942dd7)

Description:

added get equipped section for vagrant users

Thanks!
The Pull Request Bot

Diff follows:

diff --git a/source/learning/index.markdown b/source/learning/index.markdown index bfeae44..01589e5 100644 --- a/source/learning/index.markdown +++ b/source/learning/index.markdown <at> <at> -52,6 +52,18 <at> <at> If you'd rather cook up your own VM than download one from the web, you can imit To begin with, you won't need separate agent and master VMs; you'll be running Puppet in its serverless mode on a single machine. When we get to agent/master Puppet, we'll walk through turning on the puppet master and duplicating this system into a new agent node. +Get Equipped (for users of vagrantup.com) +----------------------------------------- + +centos5_64.box is a CentOS 5.5 64 bit vagrant box with Puppet 2.6.6 installed and ready to provision using the Puppet provisioner in Vagrant. + +<pre> +$ gem install vagrant +$ vagrant box add puppet-centos-55-64 http://puppetlabs.s3.amazonaws.com/pub/centos5_64.box +$ vagrant init puppet-centos-55-64 +$ vagrant up +</pre> + ### Compatibility Notes The Learning Puppet VM is available in VMWare .vmx format and the cross-platform OVF format, and has been tested with VMWare Fusion and VirtualBox.

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to puppet-dev <at> googlegroups.com.
To unsubscribe from this group, send email to puppet-dev+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
wearetherobots | 3 Oct 2011 00:00

(puppetlabs/puppet-docs) Closed pull request: get equipped for vagrant users

Greetings!

On Sun Oct 02 21:52:24 UTC 2011 pull request #17 was closed.

get equipped for vagrant users requested by (lvnilesh)

Thanks!
The Pull Request Bot

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to puppet-dev <at> googlegroups.com.
To unsubscribe from this group, send email to puppet-dev+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
wearetherobots | 3 Oct 2011 01:00

(puppetlabs/facter) Closed pull request: (#2157) Tickets/master/2157 external fact support

Greetings!

On Sun Oct 02 22:59:28 UTC 2011 pull request #59 was closed.

(#2157) Tickets/master/2157 external fact support requested by (kbarber)

Thanks!
The Pull Request Bot

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to puppet-dev <at> googlegroups.com.
To unsubscribe from this group, send email to puppet-dev+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
wearetherobots | 3 Oct 2011 03:00

(puppetlabs/facter) New pull request: (#9555) Spec tests: Change all cases of tabs and 4 space indentation to 2

Greetings!

Please review the pull request #75: (#9555) Spec tests: Change all cases of tabs and 4 space indentation to 2 opened by (kbarber)

Some more information about the pull request:

  • Opened: Mon Oct 03 00:50:25 UTC 2011
  • Based on: puppetlabs:1.6.x (8a8903ea1f086438b44a8a48c0ce0c601c9557f6)
  • Requested merge: kbarber:ticket/9555-fix_whitespace_2 (f0ccb5e7a92add944bc2a1eeb147950a2fb53547)

Description:

(#9555) Spec tests: Change all cases of tabs and 4 space indentation to 2 space indentation.

Since 2 space indentation seems to be Puppets (and the ruby communities)
standard this patch converts all incorrect indentation to 2 spaces.

The fact that we were mixing the indentation was causing people to mix them
within files - sometimes using 4 space, sometimes 2 space. This single change
makes it consistent across all the code.

This commit fixes any whitespace cleanups for the spec tests missed in the last commit.

Thanks!
The Pull Request Bot

Diff follows:

diff --git a/spec/unit/architecture_spec.rb b/spec/unit/architecture_spec.rb index 253de57..91e07e3 100755 --- a/spec/unit/architecture_spec.rb +++ b/spec/unit/architecture_spec.rb <at> <at> -6,49 +6,49 <at> <at> require 'facter' describe "Architecture fact" do - it "should default to the hardware model" do - Facter.fact(:hardwaremodel).stubs(:value).returns("NonSpecialCasedHW") - - Facter.fact(:architecture).value.should == "NonSpecialCasedHW" - end - - os_archs = Hash.new - os_archs = { - ["Debian","x86_64"] => "amd64", - ["Gentoo","x86_64"] => "amd64", - ["GNU/kFreeBSD","x86_64"] => "amd64", - ["Ubuntu","x86_64"] => "amd64", - ["Gentoo","i386"] => "x86", - ["Gentoo","i486"] => "x86", - ["Gentoo","i586"] => "x86", - ["Gentoo","i686"] => "x86", - ["Gentoo","pentium"] => "x86", - } - generic_archs = Hash.new - generic_archs = { - "i386" => "i386", - "i486" => "i386", - "i586" => "i386", - "i686" => "i386", - "pentium" => "i386", - } - - os_archs.each do |pair, result| - it "should be #{result} if os is #{pair[0]} and hardwaremodel is #{pair[1]}" do - Facter.fact(:operatingsystem).stubs(:value).returns(pair[0]) - Facter.fact(:hardwaremodel).stubs(:value).returns(pair[1]) - - Facter.fact(:architecture).value.should == result - end + it "should default to the hardware model" do + Facter.fact(:hardwaremodel).stubs(:value).returns("NonSpecialCasedHW") + + Facter.fact(:architecture).value.should == "NonSpecialCasedHW" + end + + os_archs = Hash.new + os_archs = { + ["Debian","x86_64"] => "amd64", + ["Gentoo","x86_64"] => "amd64", + ["GNU/kFreeBSD","x86_64"] => "amd64", + ["Ubuntu","x86_64"] => "amd64", + ["Gentoo","i386"] => "x86", + ["Gentoo","i486"] => "x86", + ["Gentoo","i586"] => "x86", + ["Gentoo","i686"] => "x86", + ["Gentoo","pentium"] => "x86", + } + generic_archs = Hash.new + generic_archs = { + "i386" => "i386", + "i486" => "i386", + "i586" => "i386", + "i686" => "i386", + "pentium" => "i386", + } + + os_archs.each do |pair, result| + it "should be #{result} if os is #{pair[0]} and hardwaremodel is #{pair[1]}" do + Facter.fact(:operatingsystem).stubs(:value).returns(pair[0]) + Facter.fact(:hardwaremodel).stubs(:value).returns(pair[1]) + + Facter.fact(:architecture).value.should == result end + end - generic_archs.each do |hw, result| - it "should be #{result} if hardwaremodel is #{hw}" do - Facter.fact(:hardwaremodel).stubs(:value).returns(hw) - Facter.fact(:operatingsystem).stubs(:value).returns("NonSpecialCasedOS") + generic_archs.each do |hw, result| + it "should be #{result} if hardwaremodel is #{hw}" do + Facter.fact(:hardwaremodel).stubs(:value).returns(hw) + Facter.fact(:operatingsystem).stubs(:value).returns("NonSpecialCasedOS") - Facter.fact(:architecture).value.should == result - end + Facter.fact(:architecture).value.should == result end + end end diff --git a/spec/unit/facter_spec.rb b/spec/unit/facter_spec.rb index aea638c..0b4612f 100755 --- a/spec/unit/facter_spec.rb +++ b/spec/unit/facter_spec.rb <at> <at> -4,268 +4,268 <at> <at> require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe Facter do - it "should have a version" do - Facter.version.should =~ /^[0-9]+(\.[0-9]+)*$/ + it "should have a version" do + Facter.version.should =~ /^[0-9]+(\.[0-9]+)*$/ + end + + it "should have a method for returning its collection" do + Facter.should respond_to(:collection) + end + + it "should cache the collection" do + Facter.collection.should equal(Facter.collection) + end + + it "should delegate the :flush method to the collection" do + Facter.collection.expects(:flush) + Facter.flush + end + + it "should delegate the :fact method to the collection" do + Facter.collection.expects(:fact) + Facter.fact + end + + it "should delegate the :list method to the collection" do + Facter.collection.expects(:list) + Facter.list + end + + it "should load all facts when listing" do + Facter.collection.expects(:load_all) + Facter.collection.stubs(:list) + Facter.list + end + + it "should delegate the :to_hash method to the collection" do + Facter.collection.expects(:to_hash) + Facter.to_hash + end + + it "should load all facts when calling :to_hash" do + Facter.collection.expects(:load_all) + Facter.collection.stubs(:to_hash) + Facter.to_hash + end + + it "should delegate the :value method to the collection" do + Facter.collection.expects(:value) + Facter.value + end + + it "should delegate the :each method to the collection" do + Facter.collection.expects(:each) + Facter.each + end + + it "should load all facts when calling :each" do + Facter.collection.expects(:load_all) + Facter.collection.stubs(:each) + Facter.each + end + + it "should yield to the block when using :each" do + Facter.collection.stubs(:load_all) + Facter.collection.stubs(:each).yields "foo" + result = [] + Facter.each { |f| result << f } + result.should == %w{foo} + end + + describe "when provided code as a string" do + it "should execute the code in the shell" do + Facter.add("shell_testing") do + setcode "echo yup" + end + + Facter["shell_testing"].value.should == "yup" end - - it "should have a method for returning its collection" do - Facter.should respond_to(:collection) + end + + describe "when asked for a fact as an undefined Facter class method" do + describe "and the collection is already initialized" do + it "should return the fact's value" do + Facter.collection + Facter.ipaddress.should == Facter['ipaddress'].value + end end - it "should cache the collection" do - Facter.collection.should equal(Facter.collection) + describe "and the collection has been just reset" do + it "should return the fact's value" do + Facter.reset + Facter.ipaddress.should == Facter['ipaddress'].value + end end + end - it "should delegate the :flush method to the collection" do - Facter.collection.expects(:flush) - Facter.flush - end + describe "when passed code as a block" do + it "should execute the provided block" do + Facter.add("block_testing") { setcode { "foo" } } - it "should delegate the :fact method to the collection" do - Facter.collection.expects(:fact) - Facter.fact + Facter["block_testing"].value.should == "foo" end + end - it "should delegate the :list method to the collection" do - Facter.collection.expects(:list) - Facter.list + describe Facter[:hostname] do + it "should have its ldapname set to 'cn'" do + Facter[:hostname].ldapname.should == "cn" end + end - it "should load all facts when listing" do - Facter.collection.expects(:load_all) - Facter.collection.stubs(:list) - Facter.list + describe Facter[:ipaddress] do + it "should have its ldapname set to 'iphostnumber'" do + Facter[:ipaddress].ldapname.should == "iphostnumber" end - - it "should delegate the :to_hash method to the collection" do - Facter.collection.expects(:to_hash) - Facter.to_hash - end - - it "should load all facts when calling :to_hash" do - Facter.collection.expects(:load_all) - Facter.collection.stubs(:to_hash) - Facter.to_hash + end + + # #33 Make sure we only get one mac address + it "should only return one mac address" do + Facter.value(:macaddress).should_not be_include(" ") + end + + it "should have a method for registering directories to search" do + Facter.should respond_to(:search) + end + + it "should have a method for returning the registered search directories" do + Facter.should respond_to(:search_path) + end + + it "should have a method to query debugging mode" do + Facter.should respond_to(:debugging?) + end + + it "should have a method to query timing mode" do + Facter.should respond_to(:timing?) + end + + it "should have a method to show timing information" do + Facter.should respond_to(:show_time) + end + + it "should have a method to warn" do + Facter.should respond_to(:warn) + end + + describe "when warning" do + it "should warn if debugging is enabled" do + Facter.debugging(true) + Kernel.stubs(:warn) + Kernel.expects(:warn).with('foo') + Facter.warn('foo') end - it "should delegate the :value method to the collection" do - Facter.collection.expects(:value) - Facter.value + it "should not warn if debugging is enabled but nil is passed" do + Facter.debugging(true) + Kernel.stubs(:warn) + Kernel.expects(:warn).never + Facter.warn(nil) end - it "should delegate the :each method to the collection" do - Facter.collection.expects(:each) - Facter.each + it "should not warn if debugging is enabled but an empyt string is passed" do + Facter.debugging(true) + Kernel.stubs(:warn) + Kernel.expects(:warn).never + Facter.warn('') end - it "should load all facts when calling :each" do - Facter.collection.expects(:load_all) - Facter.collection.stubs(:each) - Facter.each + it "should not warn if debugging is disabled" do + Facter.debugging(false) + Kernel.stubs(:warn) + Kernel.expects(:warn).never + Facter.warn('foo') end - it "should yield to the block when using :each" do - Facter.collection.stubs(:load_all) - Facter.collection.stubs(:each).yields "foo" - result = [] - Facter.each { |f| result << f } - result.should == %w{foo} + it "should warn for any given element for an array if debugging is enabled" do + Facter.debugging(true) + Kernel.stubs(:warn) + Kernel.expects(:warn).with('foo') + Kernel.expects(:warn).with('bar') + Facter.warn( ['foo','bar']) end - - describe "when provided code as a string" do - it "should execute the code in the shell" do - Facter.add("shell_testing") do - setcode "echo yup" - end - - Facter["shell_testing"].value.should == "yup" - end + end + + describe "when warning once" do + it "should only warn once" do + Kernel.stubs(:warnonce) + Kernel.expects(:warn).with('foo').once + Facter.warnonce('foo') + Facter.warnonce('foo') end - describe "when asked for a fact as an undefined Facter class method" do - describe "and the collection is already initialized" do - it "should return the fact's value" do - Facter.collection - Facter.ipaddress.should == Facter['ipaddress'].value - end - end - - describe "and the collection has been just reset" do - it "should return the fact's value" do - Facter.reset - Facter.ipaddress.should == Facter['ipaddress'].value - end - end + it "should not warnonce if nil is passed" do + Kernel.stubs(:warn) + Kernel.expects(:warnonce).never + Facter.warnonce(nil) end - describe "when passed code as a block" do - it "should execute the provided block" do - Facter.add("block_testing") { setcode { "foo" } } - - Facter["block_testing"].value.should == "foo" - end + it "should not warnonce if an empty string is passed" do + Kernel.stubs(:warn) + Kernel.expects(:warnonce).never + Facter.warnonce('') end + end - describe Facter[:hostname] do - it "should have its ldapname set to 'cn'" do - Facter[:hostname].ldapname.should == "cn" - end + describe "when setting debugging mode" do + it "should have debugging enabled using 1" do + Facter.debugging(1) + Facter.should be_debugging end - - describe Facter[:ipaddress] do - it "should have its ldapname set to 'iphostnumber'" do - Facter[:ipaddress].ldapname.should == "iphostnumber" - end + it "should have debugging enabled using true" do + Facter.debugging(true) + Facter.should be_debugging end - - # #33 Make sure we only get one mac address - it "should only return one mac address" do - Facter.value(:macaddress).should_not be_include(" ") + it "should have debugging enabled using any string except off" do + Facter.debugging('aaaaa') + Facter.should be_debugging end - - it "should have a method for registering directories to search" do - Facter.should respond_to(:search) + it "should have debugging disabled using 0" do + Facter.debugging(0) + Facter.should_not be_debugging end - - it "should have a method for returning the registered search directories" do - Facter.should respond_to(:search_path) + it "should have debugging disabled using false" do + Facter.debugging(false) + Facter.should_not be_debugging end - - it "should have a method to query debugging mode" do - Facter.should respond_to(:debugging?) + it "should have debugging disabled using the string 'off'" do + Facter.debugging('off') + Facter.should_not be_debugging end + end - it "should have a method to query timing mode" do - Facter.should respond_to(:timing?) + describe "when setting timing mode" do + it "should have timing enabled using 1" do + Facter.timing(1) + Facter.should be_timing end - - it "should have a method to show timing information" do - Facter.should respond_to(:show_time) + it "should have timing enabled using true" do + Facter.timing(true) + Facter.should be_timing end - - it "should have a method to warn" do - Facter.should respond_to(:warn) + it "should have timing disabled using 0" do + Facter.timing(0) + Facter.should_not be_timing end - - describe "when warning" do - it "should warn if debugging is enabled" do - Facter.debugging(true) - Kernel.stubs(:warn) - Kernel.expects(:warn).with('foo') - Facter.warn('foo') - end - - it "should not warn if debugging is enabled but nil is passed" do - Facter.debugging(true) - Kernel.stubs(:warn) - Kernel.expects(:warn).never - Facter.warn(nil) - end - - it "should not warn if debugging is enabled but an empyt string is passed" do - Facter.debugging(true) - Kernel.stubs(:warn) - Kernel.expects(:warn).never - Facter.warn('') - end - - it "should not warn if debugging is disabled" do - Facter.debugging(false) - Kernel.stubs(:warn) - Kernel.expects(:warn).never - Facter.warn('foo') - end - - it "should warn for any given element for an array if debugging is enabled" do - Facter.debugging(true) - Kernel.stubs(:warn) - Kernel.expects(:warn).with('foo') - Kernel.expects(:warn).with('bar') - Facter.warn( ['foo','bar']) - end + it "should have timing disabled using false" do + Facter.timing(false) + Facter.should_not be_timing end + end - describe "when warning once" do - it "should only warn once" do - Kernel.stubs(:warnonce) - Kernel.expects(:warn).with('foo').once - Facter.warnonce('foo') - Facter.warnonce('foo') - end - - it "should not warnonce if nil is passed" do - Kernel.stubs(:warn) - Kernel.expects(:warnonce).never - Facter.warnonce(nil) - end - - it "should not warnonce if an empty string is passed" do - Kernel.stubs(:warn) - Kernel.expects(:warnonce).never - Facter.warnonce('') - end - end + describe "when registering directories to search" do + after { Facter.instance_variable_set(" <at> search_path", []) } - describe "when setting debugging mode" do - it "should have debugging enabled using 1" do - Facter.debugging(1) - Facter.should be_debugging - end - it "should have debugging enabled using true" do - Facter.debugging(true) - Facter.should be_debugging - end - it "should have debugging enabled using any string except off" do - Facter.debugging('aaaaa') - Facter.should be_debugging - end - it "should have debugging disabled using 0" do - Facter.debugging(0) - Facter.should_not be_debugging - end - it "should have debugging disabled using false" do - Facter.debugging(false) - Facter.should_not be_debugging - end - it "should have debugging disabled using the string 'off'" do - Facter.debugging('off') - Facter.should_not be_debugging - end + it "should allow registration of a directory" do + Facter.search "/my/dir" end - describe "when setting timing mode" do - it "should have timing enabled using 1" do - Facter.timing(1) - Facter.should be_timing - end - it "should have timing enabled using true" do - Facter.timing(true) - Facter.should be_timing - end - it "should have timing disabled using 0" do - Facter.timing(0) - Facter.should_not be_timing - end - it "should have timing disabled using false" do - Facter.timing(false) - Facter.should_not be_timing - end + it "should allow registration of multiple directories" do + Facter.search "/my/dir", "/other/dir" end - describe "when registering directories to search" do - after { Facter.instance_variable_set(" <at> search_path", []) } - - it "should allow registration of a directory" do - Facter.search "/my/dir" - end - - it "should allow registration of multiple directories" do - Facter.search "/my/dir", "/other/dir" - end - - it "should return all registered directories when asked" do - Facter.search "/my/dir", "/other/dir" - Facter.search_path.should == %w{/my/dir /other/dir} - end + it "should return all registered directories when asked" do + Facter.search "/my/dir", "/other/dir" + Facter.search_path.should == %w{/my/dir /other/dir} end + end end diff --git a/spec/unit/id_spec.rb b/spec/unit/id_spec.rb index aab343d..a3f0398 100755 --- a/spec/unit/id_spec.rb +++ b/spec/unit/id_spec.rb <at> <at> -4,25 +4,25 <at> <at> require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe "id fact" do - kernel = [ 'Linux', 'Darwin', 'windows', 'FreeBSD', 'OpenBSD', 'NetBSD', 'AIX', 'HP-UX' ] + kernel = [ 'Linux', 'Darwin', 'windows', 'FreeBSD', 'OpenBSD', 'NetBSD', 'AIX', 'HP-UX' ] - kernel.each do |k| - describe "with kernel reported as #{k}" do - it "should return the current user" do - Facter.fact(:kernel).stubs(:value).returns(k) - Facter::Util::Config.stubs(:is_windows?).returns(k == 'windows') - Facter::Util::Resolution.expects(:exec).once.with('whoami').returns 'bar' + kernel.each do |k| + describe "with kernel reported as #{k}" do + it "should return the current user" do + Facter.fact(:kernel).stubs(:value).returns(k) + Facter::Util::Config.stubs(:is_windows?).returns(k == 'windows') + Facter::Util::Resolution.expects(:exec).once.with('whoami').returns 'bar' - Facter.fact(:id).value.should == 'bar' - end - end + Facter.fact(:id).value.should == 'bar' + end end + end - it "should return the current user on Solaris" do - Facter::Util::Config.stubs(:is_windows?).returns(false) - Facter::Util::Resolution.stubs(:exec).with('uname -s').returns('SunOS') - Facter::Util::Resolution.expects(:exec).once.with('/usr/xpg4/bin/id -un').returns 'bar' + it "should return the current user on Solaris" do + Facter::Util::Config.stubs(:is_windows?).returns(false) + Facter::Util::Resolution.stubs(:exec).with('uname -s').returns('SunOS') + Facter::Util::Resolution.expects(:exec).once.with('/usr/xpg4/bin/id -un').returns 'bar' - Facter.fact(:id).value.should == 'bar' - end + Facter.fact(:id).value.should == 'bar' + end end diff --git a/spec/unit/interfaces_spec.rb b/spec/unit/interfaces_spec.rb index 28a8119..6ceca5e 100755 --- a/spec/unit/interfaces_spec.rb +++ b/spec/unit/interfaces_spec.rb <at> <at> -6,13 +6,13 <at> <at> require 'facter' require 'facter/util/ip' describe "Per Interface IP facts" do - it "should replace the ':' in an interface list with '_'" do - # So we look supported - Facter.fact(:kernel).stubs(:value).returns("SunOS") + it "should replace the ':' in an interface list with '_'" do + # So we look supported + Facter.fact(:kernel).stubs(:value).returns("SunOS") - Facter::Util::IP.stubs(:get_interfaces).returns %w{eth0:1 eth1:2} - Facter.fact(:interfaces).value.should == %{eth0_1,eth1_2} - end + Facter::Util::IP.stubs(:get_interfaces).returns %w{eth0:1 eth1:2} + Facter.fact(:interfaces).value.should == %{eth0_1,eth1_2} + end it "should replace non-alphanumerics in an interface list with '_'" do Facter.fact(:kernel).stubs(:value).returns("windows") diff --git a/spec/unit/memory_spec.rb b/spec/unit/memory_spec.rb index 28f1638..87a6f0c 100755 --- a/spec/unit/memory_spec.rb +++ b/spec/unit/memory_spec.rb <at> <at> -5,146 +5,146 <at> <at> require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'facter' describe "Memory facts" do - before do - # We need these facts loaded, but they belong to a file with a - # different name, so load the file explicitly. - Facter.collection.loader.load(:memory) - end + before do + # We need these facts loaded, but they belong to a file with a + # different name, so load the file explicitly. + Facter.collection.loader.load(:memory) + end - after do - Facter.clear - end + after do + Facter.clear + end - it "should return the current swap size" do + it "should return the current swap size" do - Facter.fact(:kernel).stubs(:value).returns("Darwin") - Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)") - swapusage = "vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)" + Facter.fact(:kernel).stubs(:value).returns("Darwin") + Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)") + swapusage = "vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)" - if swapusage =~ /total = (\S+).*/ - Facter.fact(:swapfree).value.should == $1 - end + if swapusage =~ /total = (\S+).*/ + Facter.fact(:swapfree).value.should == $1 end + end - it "should return the current swap free" do - Facter.fact(:kernel).stubs(:value).returns("Darwin") - Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)") - swapusage = "vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)" + it "should return the current swap free" do + Facter.fact(:kernel).stubs(:value).returns("Darwin") + Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)") + swapusage = "vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)" - if swapusage =~ /free = (\S+).*/ - Facter.fact(:swapfree).value.should == $1 - end + if swapusage =~ /free = (\S+).*/ + Facter.fact(:swapfree).value.should == $1 end + end - it "should return whether swap is encrypted" do - Facter.fact(:kernel).stubs(:value).returns("Darwin") - Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)") - swapusage = "vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)" + it "should return whether swap is encrypted" do + Facter.fact(:kernel).stubs(:value).returns("Darwin") + Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)") + swapusage = "vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)" - swapusage =~ /\(encrypted\)/ - Facter.fact(:swapencrypted).value.should == true - end + swapusage =~ /\(encrypted\)/ + Facter.fact(:swapencrypted).value.should == true + end - describe "on OpenBSD" do - before :each do - Facter.clear - Facter.fact(:kernel).stubs(:value).returns("OpenBSD") + describe "on OpenBSD" do + before :each do + Facter.clear + Facter.fact(:kernel).stubs(:value).returns("OpenBSD") - swapusage = "total: 148342k bytes allocated = 0k used, 148342k available" - Facter::Util::Resolution.stubs(:exec).with('swapctl -s').returns(swapusage) + swapusage = "total: 148342k bytes allocated = 0k used, 148342k available" + Facter::Util::Resolution.stubs(:exec).with('swapctl -s').returns(swapusage) - vmstat = <<EOS - procs memory page disks traps cpu - r b w avm fre flt re pi po fr sr cd0 sd0 int sys cs us sy id - 0 0 0 11048 181028 39 0 0 0 0 0 0 1 3 90 17 0 0 100 + vmstat = <<EOS + procs memory page disks traps cpu + r b w avm fre flt re pi po fr sr cd0 sd0 int sys cs us sy id + 0 0 0 11048 181028 39 0 0 0 0 0 0 1 3 90 17 0 0 100 EOS - Facter::Util::Resolution.stubs(:exec).with('vmstat').returns(vmstat) - - Facter::Util::Resolution.stubs(:exec).with("sysctl hw.physmem | cut -d'=' -f2").returns('267321344') + Facter::Util::Resolution.stubs(:exec).with('vmstat').returns(vmstat) - Facter.collection.loader.load(:memory) - end + Facter::Util::Resolution.stubs(:exec).with("sysctl hw.physmem | cut -d'=' -f2").returns('267321344') - after :each do - Facter.clear - end - - it "should return the current swap free" do - Facter.fact(:swapfree).value.should == "144.87 MB" - end - - it "should return the current swap size" do - Facter.fact(:swapsize).value.should == "144.87 MB" - end + Facter.collection.loader.load(:memory) + end - it "should return the current memorysize" do - Facter.fact(:memorytotal).value.should == "254.94 MB" - end + after :each do + Facter.clear end - describe "on DragonFly BSD" do - before :each do - Facter.clear - Facter.fact(:kernel).stubs(:value).returns("dragonfly") + it "should return the current swap free" do + Facter.fact(:swapfree).value.should == "144.87 MB" + end - swapusage = "total: 148342k bytes allocated = 0k used, 148342k available" - Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n hw.pagesize').returns("4096") - Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_size').returns("128461") - Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_anon_use').returns("2635") - Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_cache_use').returns("0") + it "should return the current swap size" do + Facter.fact(:swapsize).value.should == "144.87 MB" + end - vmstat = <<EOS - procs memory page disks faults cpu - r b w avm fre flt re pi po fr sr da0 sg1 in sy cs us sy id + it "should return the current memorysize" do + Facter.fact(:memorytotal).value.should == "254.94 MB" + end + end + + describe "on DragonFly BSD" do + before :each do + Facter.clear + Facter.fact(:kernel).stubs(:value).returns("dragonfly") + + swapusage = "total: 148342k bytes allocated = 0k used, 148342k available" + Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n hw.pagesize').returns("4096") + Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_size').returns("128461") + Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_anon_use').returns("2635") + Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_cache_use').returns("0") + + vmstat = <<EOS + procs memory page disks faults cpu + r b w avm fre flt re pi po fr sr da0 sg1 in sy cs us sy id 0 0 0 33152 13940 1902120 2198 53119 11642 6544597 5460994 0 0 6148243 7087927 3484264 0 1 9 EOS - Facter::Util::Resolution.stubs(:exec).with('vmstat').returns(vmstat) + Facter::Util::Resolution.stubs(:exec).with('vmstat').returns(vmstat) - Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.physmem").returns('248512512') + Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.physmem").returns('248512512') - Facter.collection.loader.load(:memory) - end + Facter.collection.loader.load(:memory) + end - after :each do - Facter.clear - end + after :each do + Facter.clear + end - it "should return the current swap free" do - Facter.fact(:swapfree).value.should == "491.51 MB" - end + it "should return the current swap free" do + Facter.fact(:swapfree).value.should == "491.51 MB" + end - it "should return the current swap size" do - Facter.fact(:swapsize).value.should == "501.80 MB" - end + it "should return the current swap size" do + Facter.fact(:swapsize).value.should == "501.80 MB" + end - it "should return the current memorysize" do - Facter.fact(:memorytotal).value.should == "237.00 MB" - end + it "should return the current memorysize" do + Facter.fact(:memorytotal).value.should == "237.00 MB" end + end - describe "on Windows" do - before :each do - Facter.clear - Facter.fact(:kernel).stubs(:value).returns("windows") - Facter.collection.loader.load(:memory) + describe "on Windows" do + before :each do + Facter.clear + Facter.fact(:kernel).stubs(:value).returns("windows") + Facter.collection.loader.load(:memory) - require 'facter/util/wmi' - end + require 'facter/util/wmi' + end - it "should return free memory" do - os = stubs 'os' - os.stubs(:FreePhysicalMemory).returns("3415624") - Facter::Util::WMI.stubs(:execquery).returns([os]) + it "should return free memory" do + os = stubs 'os' + os.stubs(:FreePhysicalMemory).returns("3415624") + Facter::Util::WMI.stubs(:execquery).returns([os]) - Facter.fact(:MemoryFree).value.should == '3.26 GB' - end + Facter.fact(:MemoryFree).value.should == '3.26 GB' + end - it "should return total memory" do - computer = stubs 'computer' - computer.stubs(:TotalPhysicalMemory).returns("4193837056") - Facter::Util::WMI.stubs(:execquery).returns([computer]) + it "should return total memory" do + computer = stubs 'computer' + computer.stubs(:TotalPhysicalMemory).returns("4193837056") + Facter::Util::WMI.stubs(:execquery).returns([computer]) - Facter.fact(:MemoryTotal).value.should == '3.91 GB' - end + Facter.fact(:MemoryTotal).value.should == '3.91 GB' end + end end diff --git a/spec/unit/operatingsystem_spec.rb b/spec/unit/operatingsystem_spec.rb index 89904fe..04084f6 100755 --- a/spec/unit/operatingsystem_spec.rb +++ b/spec/unit/operatingsystem_spec.rb <at> <at> -6,78 +6,78 <at> <at> require 'facter' describe "Operating System fact" do - before do - Facter.clear - end + before do + Facter.clear + end - after do - Facter.clear - end + after do + Facter.clear + end - it "should default to the kernel name" do - Facter.fact(:kernel).stubs(:value).returns("Nutmeg") + it "should default to the kernel name" do + Facter.fact(:kernel).stubs(:value).returns("Nutmeg") - Facter.fact(:operatingsystem).value.should == "Nutmeg" - end + Facter.fact(:operatingsystem).value.should == "Nutmeg" + end - it "should be Solaris for SunOS" do - Facter.fact(:kernel).stubs(:value).returns("SunOS") + it "should be Solaris for SunOS" do + Facter.fact(:kernel).stubs(:value).returns("SunOS") - Facter.fact(:operatingsystem).value.should == "Solaris" - end + Facter.fact(:operatingsystem).value.should == "Solaris" + end - it "should be ESXi for VMkernel" do - Facter.fact(:kernel).stubs(:value).returns("VMkernel") + it "should be ESXi for VMkernel" do + Facter.fact(:kernel).stubs(:value).returns("VMkernel") - Facter.fact(:operatingsystem).value.should == "ESXi" - end + Facter.fact(:operatingsystem).value.should == "ESXi" + end - it "should identify Oracle VM as OVS" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter.stubs(:value).with(:lsbdistid).returns(nil) - FileTest.stubs(:exists?).returns false + it "should identify Oracle VM as OVS" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.stubs(:value).with(:lsbdistid).returns(nil) + FileTest.stubs(:exists?).returns false - FileTest.expects(:exists?).with("/etc/ovs-release").returns true - FileTest.expects(:exists?).with("/etc/enterprise-release").returns true + FileTest.expects(:exists?).with("/etc/ovs-release").returns true + FileTest.expects(:exists?).with("/etc/enterprise-release").returns true - Facter.fact(:operatingsystem).value.should == "OVS" - end + Facter.fact(:operatingsystem).value.should == "OVS" + end - it "should identify VMWare ESX" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter.stubs(:value).with(:lsbdistid).returns(nil) - FileTest.stubs(:exists?).returns false - - FileTest.expects(:exists?).with("/etc/vmware-release").returns true - - Facter.fact(:operatingsystem).value.should == "VMWareESX" - end - - it "should identify Alpine Linux" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - - FileTest.stubs(:exists?).returns false - - FileTest.expects(:exists?).with("/etc/alpine-release").returns true - - Facter.fact(:operatingsystem).value.should == "Alpine" - end - - it "should identify Scientific Linux" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - FileTest.stubs(:exists?).returns false - - FileTest.expects(:exists?).with("/etc/redhat-release").returns true - File.expects(:read).with("/etc/redhat-release").returns("Scientific Linux SLC 5.7 (Boron)") - Facter.fact(:operatingsystem).value.should == "Scientific" - end - - it "should differentiate between Scientific Linux CERN and Scientific Linux" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - FileTest.stubs(:exists?).returns false - - FileTest.expects(:exists?).with("/etc/redhat-release").returns true - File.expects(:read).with("/etc/redhat-release").returns("Scientific Linux CERN SLC 5.7 (Boron)") - Facter.fact(:operatingsystem).value.should == "SLC" - end + it "should identify VMWare ESX" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.stubs(:value).with(:lsbdistid).returns(nil) + FileTest.stubs(:exists?).returns false + + FileTest.expects(:exists?).with("/etc/vmware-release").returns true + + Facter.fact(:operatingsystem).value.should == "VMWareESX" + end + + it "should identify Alpine Linux" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + + FileTest.stubs(:exists?).returns false + + FileTest.expects(:exists?).with("/etc/alpine-release").returns true + + Facter.fact(:operatingsystem).value.should == "Alpine" + end + + it "should identify Scientific Linux" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + FileTest.stubs(:exists?).returns false + + FileTest.expects(:exists?).with("/etc/redhat-release").returns true + File.expects(:read).with("/etc/redhat-release").returns("Scientific Linux SLC 5.7 (Boron)") + Facter.fact(:operatingsystem).value.should == "Scientific" + end + + it "should differentiate between Scientific Linux CERN and Scientific Linux" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + FileTest.stubs(:exists?).returns false + + FileTest.expects(:exists?).with("/etc/redhat-release").returns true + File.expects(:read).with("/etc/redhat-release").returns("Scientific Linux CERN SLC 5.7 (Boron)") + Facter.fact(:operatingsystem).value.should == "SLC" + end end diff --git a/spec/unit/operatingsystemrelease_spec.rb b/spec/unit/operatingsystemrelease_spec.rb index 056f5f5..189cb44 100755 --- a/spec/unit/operatingsystemrelease_spec.rb +++ b/spec/unit/operatingsystemrelease_spec.rb <at> <at> -6,55 +6,55 <at> <at> require 'facter' describe "Operating System Release fact" do - before do - Facter.clear - end + before do + Facter.clear + end + + after do + Facter.clear + end + + test_cases = { + "CentOS" => "/etc/redhat-release", + "RedHat" => "/etc/redhat-release", + "Scientific" => "/etc/redhat-release", + "Fedora" => "/etc/fedora-release", + "MeeGo" => "/etc/meego-release", + "OEL" => "/etc/enterprise-release", + "oel" => "/etc/enterprise-release", + "OVS" => "/etc/ovs-release", + "ovs" => "/etc/ovs-release", + "OracleLinux" => "/etc/oracle-release", + } + + test_cases.each do |system, file| + describe "with operatingsystem reported as #{system.inspect}" do + it "should read the #{file.inspect} file" do + Facter.fact(:operatingsystem).stubs(:value).returns(system) + + File.expects(:open).with(file, "r").at_least(1) - after do - Facter.clear + Facter.fact(:operatingsystemrelease).value + end end + end - test_cases = { - "CentOS" => "/etc/redhat-release", - "RedHat" => "/etc/redhat-release", - "Scientific" => "/etc/redhat-release", - "Fedora" => "/etc/fedora-release", - "MeeGo" => "/etc/meego-release", - "OEL" => "/etc/enterprise-release", - "oel" => "/etc/enterprise-release", - "OVS" => "/etc/ovs-release", - "ovs" => "/etc/ovs-release", - "OracleLinux" => "/etc/oracle-release", - } - - test_cases.each do |system, file| - describe "with operatingsystem reported as #{system.inspect}" do - it "should read the #{file.inspect} file" do - Facter.fact(:operatingsystem).stubs(:value).returns(system) - - File.expects(:open).with(file, "r").at_least(1) - - Facter.fact(:operatingsystemrelease).value - end - end - end + it "for VMWareESX it should run the vmware -v command" do + Facter.fact(:kernel).stubs(:value).returns("VMkernel") + Facter.fact(:kernelrelease).stubs(:value).returns("4.1.0") + Facter.fact(:operatingsystem).stubs(:value).returns("VMwareESX") - it "for VMWareESX it should run the vmware -v command" do - Facter.fact(:kernel).stubs(:value).returns("VMkernel") - Facter.fact(:kernelrelease).stubs(:value).returns("4.1.0") - Facter.fact(:operatingsystem).stubs(:value).returns("VMwareESX") + Facter::Util::Resolution.stubs(:exec).with('vmware -v').returns('foo') - Facter::Util::Resolution.stubs(:exec).with('vmware -v').returns('foo') + Facter.fact(:operatingsystemrelease).value + end - Facter.fact(:operatingsystemrelease).value - end - - it "for Alpine it should use the contents of /etc/alpine-release" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter.fact(:operatingsystem).stubs(:value).returns("Alpine") + it "for Alpine it should use the contents of /etc/alpine-release" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:operatingsystem).stubs(:value).returns("Alpine") - File.expects(:read).with("/etc/alpine-release").returns("foo") + File.expects(:read).with("/etc/alpine-release").returns("foo") - Facter.fact(:operatingsystemrelease).value.should == "foo" - end + Facter.fact(:operatingsystemrelease).value.should == "foo" + end end diff --git a/spec/unit/selinux_spec.rb b/spec/unit/selinux_spec.rb index 5d09897..25c75da 100755 --- a/spec/unit/selinux_spec.rb +++ b/spec/unit/selinux_spec.rb <at> <at> -7,84 +7,84 <at> <at> require 'facter' describe "SELinux facts" do - after do - Facter.clear - end + after do + Facter.clear + end - it "should return true if SELinux enabled" do - Facter.fact(:kernel).stubs(:value).returns("Linux") + it "should return true if SELinux enabled" do + Facter.fact(:kernel).stubs(:value).returns("Linux") - FileTest.stubs(:exists?).returns false - File.stubs(:read).with("/proc/self/attr/current").returns("notkernel") + FileTest.stubs(:exists?).returns false + File.stubs(:read).with("/proc/self/attr/current").returns("notkernel") - FileTest.expects(:exists?).with("/selinux/enforce").returns true - FileTest.expects(:exists?).with("/proc/self/attr/current").returns true - File.expects(:read).with("/proc/self/attr/current").returns("kernel") + FileTest.expects(:exists?).with("/selinux/enforce").returns true + FileTest.expects(:exists?).with("/proc/self/attr/current").returns true + File.expects(:read).with("/proc/self/attr/current").returns("kernel") - Facter.fact(:selinux).value.should == "true" - end + Facter.fact(:selinux).value.should == "true" + end - it "should return true if SELinux policy enabled" do - Facter.fact(:selinux).stubs(:value).returns("true") + it "should return true if SELinux policy enabled" do + Facter.fact(:selinux).stubs(:value).returns("true") - FileTest.stubs(:exists?).returns false - File.stubs(:read).with("/selinux/enforce").returns("0") + FileTest.stubs(:exists?).returns false + File.stubs(:read).with("/selinux/enforce").returns("0") - FileTest.expects(:exists?).with("/selinux/enforce").returns true - File.expects(:read).with("/selinux/enforce").returns("1") + FileTest.expects(:exists?).with("/selinux/enforce").returns true + File.expects(:read).with("/selinux/enforce").returns("1") - Facter.fact(:selinux_enforced).value.should == "true" - end + Facter.fact(:selinux_enforced).value.should == "true" + end - it "should return an SELinux policy version" do - Facter.fact(:selinux).stubs(:value).returns("true") - FileTest.stubs(:exists?).with("/proc/self/mountinfo").returns false + it "should return an SELinux policy version" do + Facter.fact(:selinux).stubs(:value).returns("true") + FileTest.stubs(:exists?).with("/proc/self/mountinfo").returns false - File.stubs(:read).with("/selinux/policyvers").returns("") + File.stubs(:read).with("/selinux/policyvers").returns("") - File.expects(:read).with("/selinux/policyvers").returns("1") + File.expects(:read).with("/selinux/policyvers").returns("1") - Facter.fact(:selinux_policyversion).value.should == "1" - end + Facter.fact(:selinux_policyversion).value.should == "1" + end - it "should return the SELinux current mode" do - Facter.fact(:selinux).stubs(:value).returns("true") + it "should return the SELinux current mode" do + Facter.fact(:selinux).stubs(:value).returns("true") - sample_output_file = File.dirname(__FILE__) + '/data/selinux_sestatus' - selinux_sestatus = File.read(sample_output_file) + sample_output_file = File.dirname(__FILE__) + '/data/selinux_sestatus' + selinux_sestatus = File.read(sample_output_file) - Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/sestatus').returns(selinux_sestatus) + Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/sestatus').returns(selinux_sestatus) - Facter.fact(:selinux_current_mode).value.should == "permissive" - end + Facter.fact(:selinux_current_mode).value.should == "permissive" + end - it "should return the SELinux mode from the configuration file" do - Facter.fact(:selinux).stubs(:value).returns("true") + it "should return the SELinux mode from the configuration file" do + Facter.fact(:selinux).stubs(:value).returns("true") - sample_output_file = File.dirname(__FILE__) + '/data/selinux_sestatus' - selinux_sestatus = File.read(sample_output_file) + sample_output_file = File.dirname(__FILE__) + '/data/selinux_sestatus' + selinux_sestatus = File.read(sample_output_file) - Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/sestatus').returns(selinux_sestatus) + Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/sestatus').returns(selinux_sestatus) - Facter.fact(:selinux_config_mode).value.should == "permissive" - end + Facter.fact(:selinux_config_mode).value.should == "permissive" + end - it "should return the SELinux configuration file policy" do - Facter.fact(:selinux).stubs(:value).returns("true") + it "should return the SELinux configuration file policy" do + Facter.fact(:selinux).stubs(:value).returns("true") - sample_output_file = File.dirname(__FILE__) + '/data/selinux_sestatus' - selinux_sestatus = File.read(sample_output_file) + sample_output_file = File.dirname(__FILE__) + '/data/selinux_sestatus' + selinux_sestatus = File.read(sample_output_file) - Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/sestatus').returns(selinux_sestatus) + Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/sestatus').returns(selinux_sestatus) - Facter.fact(:selinux_config_policy).value.should == "targeted" - end + Facter.fact(:selinux_config_policy).value.should == "targeted" + end - it "should ensure legacy selinux_mode facts returns same value as selinux_config_policy fact" do - Facter.fact(:selinux).stubs(:value).returns("true") + it "should ensure legacy selinux_mode facts returns same value as selinux_config_policy fact" do + Facter.fact(:selinux).stubs(:value).returns("true") - Facter.fact(:selinux_config_policy).stubs(:value).returns("targeted") + Facter.fact(:selinux_config_policy).stubs(:value).returns("targeted") - Facter.fact(:selinux_mode).value.should == "targeted" - end + Facter.fact(:selinux_mode).value.should == "targeted" + end end diff --git a/spec/unit/util/collection_spec.rb b/spec/unit/util/collection_spec.rb index 86b602f..c676727 100755 --- a/spec/unit/util/collection_spec.rb +++ b/spec/unit/util/collection_spec.rb <at> <at> -5,251 +5,251 <at> <at> require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/collection' describe Facter::Util::Collection do - it "should have a method for adding facts" do - Facter::Util::Collection.new.should respond_to(:add) - end + it "should have a method for adding facts" do + Facter::Util::Collection.new.should respond_to(:add) + end - it "should have a method for returning a loader" do - Facter::Util::Collection.new.should respond_to(:loader) - end + it "should have a method for returning a loader" do + Facter::Util::Collection.new.should respond_to(:loader) + end - it "should use an instance of the Loader class as its loader" do - Facter::Util::Collection.new.loader.should be_instance_of(Facter::Util::Loader) - end + it "should use an instance of the Loader class as its loader" do + Facter::Util::Collection.new.loader.should be_instance_of(Facter::Util::Loader) + end - it "should cache its loader" do - coll = Facter::Util::Collection.new - coll.loader.should equal(coll.loader) - end + it "should cache its loader" do + coll = Facter::Util::Collection.new + coll.loader.should equal(coll.loader) + end - it "should have a method for loading all facts" do - Facter::Util::Collection.new.should respond_to(:load_all) + it "should have a method for loading all facts" do + Facter::Util::Collection.new.should respond_to(:load_all) + end + + it "should delegate its load_all method to its loader" do + coll = Facter::Util::Collection.new + coll.loader.expects(:load_all) + coll.load_all + end + + describe "when adding facts" do + before do + <at> coll = Facter::Util::Collection.new end - it "should delegate its load_all method to its loader" do - coll = Facter::Util::Collection.new - coll.loader.expects(:load_all) - coll.load_all + it "should create a new fact if no fact with the same name already exists" do + fact = mock 'fact' + Facter::Util::Fact.expects(:new).with { |name, *args| name == :myname }.returns fact + + <at> coll.add(:myname) end - describe "when adding facts" do - before do - <at> coll = Facter::Util::Collection.new - end + it "should accept options" do + <at> coll.add(:myname, :ldapname => "whatever") { } + end - it "should create a new fact if no fact with the same name already exists" do - fact = mock 'fact' - Facter::Util::Fact.expects(:new).with { |name, *args| name == :myname }.returns fact + it "should set any appropriate options on the fact instances" do + # Use a real fact instance, because we're using respond_to? + fact = Facter::Util::Fact.new(:myname) + fact.expects(:ldapname=).with("testing") + Facter::Util::Fact.expects(:new).with(:myname).returns fact - <at> coll.add(:myname) - end + <at> coll.add(:myname, :ldapname => "testing") + end - it "should accept options" do - <at> coll.add(:myname, :ldapname => "whatever") { } - end + it "should set appropriate options on the resolution instance" do + fact = Facter::Util::Fact.new(:myname) + Facter::Util::Fact.expects(:new).with(:myname).returns fact - it "should set any appropriate options on the fact instances" do - # Use a real fact instance, because we're using respond_to? - fact = Facter::Util::Fact.new(:myname) - fact.expects(:ldapname=).with("testing") - Facter::Util::Fact.expects(:new).with(:myname).returns fact + resolve = Facter::Util::Resolution.new(:myname) {} + fact.expects(:add).returns resolve - <at> coll.add(:myname, :ldapname => "testing") - end + <at> coll.add(:myname, :timeout => "myval") {} + end - it "should set appropriate options on the resolution instance" do - fact = Facter::Util::Fact.new(:myname) - Facter::Util::Fact.expects(:new).with(:myname).returns fact + it "should not pass fact-specific options to resolutions" do + fact = Facter::Util::Fact.new(:myname) + Facter::Util::Fact.expects(:new).with(:myname).returns fact - resolve = Facter::Util::Resolution.new(:myname) {} - fact.expects(:add).returns resolve + resolve = Facter::Util::Resolution.new(:myname) {} + fact.expects(:add).returns resolve - <at> coll.add(:myname, :timeout => "myval") {} - end + fact.expects(:ldapname=).with("foo") + resolve.expects(:timeout=).with("myval") - it "should not pass fact-specific options to resolutions" do - fact = Facter::Util::Fact.new(:myname) - Facter::Util::Fact.expects(:new).with(:myname).returns fact + <at> coll.add(:myname, :timeout => "myval", :ldapname => "foo") {} + end - resolve = Facter::Util::Resolution.new(:myname) {} - fact.expects(:add).returns resolve + it "should fail if invalid options are provided" do + lambda { <at> coll.add(:myname, :foo => :bar) }.should raise_error(ArgumentError) + end - fact.expects(:ldapname=).with("foo") - resolve.expects(:timeout=).with("myval") + describe "and a block is provided" do + it "should use the block to add a resolution to the fact" do + fact = mock 'fact' + Facter::Util::Fact.expects(:new).returns fact - <at> coll.add(:myname, :timeout => "myval", :ldapname => "foo") {} - end + fact.expects(:add) - it "should fail if invalid options are provided" do - lambda { <at> coll.add(:myname, :foo => :bar) }.should raise_error(ArgumentError) - end + <at> coll.add(:myname) {} + end + end + end - describe "and a block is provided" do - it "should use the block to add a resolution to the fact" do - fact = mock 'fact' - Facter::Util::Fact.expects(:new).returns fact + it "should have a method for retrieving facts by name" do + Facter::Util::Collection.new.should respond_to(:fact) + end - fact.expects(:add) + describe "when retrieving facts" do + before do + <at> coll = Facter::Util::Collection.new - <at> coll.add(:myname) {} - end - end + <at> fact = <at> coll.add("YayNess") end - it "should have a method for retrieving facts by name" do - Facter::Util::Collection.new.should respond_to(:fact) + it "should return the fact instance specified by the name" do + <at> coll.fact("YayNess").should equal( <at> fact) end - describe "when retrieving facts" do - before do - <at> coll = Facter::Util::Collection.new + it "should be case-insensitive" do + <at> coll.fact("yayness").should equal( <at> fact) + end - <at> fact = <at> coll.add("YayNess") - end + it "should treat strings and symbols equivalently" do + <at> coll.fact(:yayness).should equal( <at> fact) + end - it "should return the fact instance specified by the name" do - <at> coll.fact("YayNess").should equal( <at> fact) - end + it "should use its loader to try to load the fact if no fact can be found" do + <at> coll.loader.expects(:load).with(:testing) + <at> coll.fact("testing") + end - it "should be case-insensitive" do - <at> coll.fact("yayness").should equal( <at> fact) - end + it "should return nil if it cannot find or load the fact" do + <at> coll.loader.expects(:load).with(:testing) + <at> coll.fact("testing").should be_nil + end + end - it "should treat strings and symbols equivalently" do - <at> coll.fact(:yayness).should equal( <at> fact) - end + it "should have a method for returning a fact's value" do + Facter::Util::Collection.new.should respond_to(:value) + end - it "should use its loader to try to load the fact if no fact can be found" do - <at> coll.loader.expects(:load).with(:testing) - <at> coll.fact("testing") - end + describe "when returning a fact's value" do + before do + <at> coll = Facter::Util::Collection.new + <at> fact = <at> coll.add("YayNess") - it "should return nil if it cannot find or load the fact" do - <at> coll.loader.expects(:load).with(:testing) - <at> coll.fact("testing").should be_nil - end + <at> fact.stubs(:value).returns "result" end - it "should have a method for returning a fact's value" do - Facter::Util::Collection.new.should respond_to(:value) + it "should use the 'fact' method to retrieve the fact" do + <at> coll.expects(:fact).with(:yayness).returns <at> fact + <at> coll.value(:yayness) end - describe "when returning a fact's value" do - before do - <at> coll = Facter::Util::Collection.new - <at> fact = <at> coll.add("YayNess") + it "should return the result of calling :value on the fact" do + <at> fact.expects(:value).returns "result" - <at> fact.stubs(:value).returns "result" - end + <at> coll.value("YayNess").should == "result" + end - it "should use the 'fact' method to retrieve the fact" do - <at> coll.expects(:fact).with(:yayness).returns <at> fact - <at> coll.value(:yayness) - end + it "should be case-insensitive" do + <at> coll.value("yayness").should_not be_nil + end - it "should return the result of calling :value on the fact" do - <at> fact.expects(:value).returns "result" + it "should treat strings and symbols equivalently" do + <at> coll.value(:yayness).should_not be_nil + end + end - <at> coll.value("YayNess").should == "result" - end + it "should return the fact's value when the array index method is used" do + <at> coll = Facter::Util::Collection.new + <at> coll.expects(:value).with("myfact").returns "foo" + <at> coll["myfact"].should == "foo" + end - it "should be case-insensitive" do - <at> coll.value("yayness").should_not be_nil - end + it "should have a method for flushing all facts" do + <at> coll = Facter::Util::Collection.new + <at> fact = <at> coll.add("YayNess") - it "should treat strings and symbols equivalently" do - <at> coll.value(:yayness).should_not be_nil - end - end + <at> fact.expects(:flush) - it "should return the fact's value when the array index method is used" do - <at> coll = Facter::Util::Collection.new - <at> coll.expects(:value).with("myfact").returns "foo" - <at> coll["myfact"].should == "foo" - end + <at> coll.flush + end - it "should have a method for flushing all facts" do - <at> coll = Facter::Util::Collection.new - <at> fact = <at> coll.add("YayNess") + it "should have a method that returns all fact names" do + <at> coll = Facter::Util::Collection.new + <at> coll.add(:one) + <at> coll.add(:two) - <at> fact.expects(:flush) + <at> coll.list.sort { |a,b| a.to_s <=> b.to_s }.should == [:one, :two] + end - <at> coll.flush - end + it "should have a method for returning a hash of fact values" do + Facter::Util::Collection.new.should respond_to(:to_hash) + end - it "should have a method that returns all fact names" do - <at> coll = Facter::Util::Collection.new - <at> coll.add(:one) - <at> coll.add(:two) + describe "when returning a hash of values" do + before do + <at> coll = Facter::Util::Collection.new + <at> fact = <at> coll.add(:one) + <at> fact.stubs(:value).returns "me" + end - <at> coll.list.sort { |a,b| a.to_s <=> b.to_s }.should == [:one, :two] + it "should return a hash of fact names and values with the fact names as strings" do + <at> coll.to_hash.should == {"one" => "me"} end - it "should have a method for returning a hash of fact values" do - Facter::Util::Collection.new.should respond_to(:to_hash) + it "should not include facts that did not return a value" do + f = <at> coll.add(:two) + f.stubs(:value).returns nil + <at> coll.to_hash.should_not be_include(:two) end + end - describe "when returning a hash of values" do - before do - <at> coll = Facter::Util::Collection.new - <at> fact = <at> coll.add(:one) - <at> fact.stubs(:value).returns "me" - end + it "should have a method for iterating over all facts" do + Facter::Util::Collection.new.should respond_to(:each) + end - it "should return a hash of fact names and values with the fact names as strings" do - <at> coll.to_hash.should == {"one" => "me"} - end + it "should include Enumerable" do + Facter::Util::Collection.ancestors.should be_include(Enumerable) + end - it "should not include facts that did not return a value" do - f = <at> coll.add(:two) - f.stubs(:value).returns nil - <at> coll.to_hash.should_not be_include(:two) - end + describe "when iterating over facts" do + before do + <at> coll = Facter::Util::Collection.new + <at> one = <at> coll.add(:one) + <at> two = <at> coll.add(:two) end - it "should have a method for iterating over all facts" do - Facter::Util::Collection.new.should respond_to(:each) + it "should yield each fact name and the fact value" do + <at> one.stubs(:value).returns "ONE" + <at> two.stubs(:value).returns "TWO" + facts = {} + <at> coll.each do |fact, value| + facts[fact] = value + end + facts.should == {"one" => "ONE", "two" => "TWO"} end - it "should include Enumerable" do - Facter::Util::Collection.ancestors.should be_include(Enumerable) + it "should convert the fact name to a string" do + <at> one.stubs(:value).returns "ONE" + <at> two.stubs(:value).returns "TWO" + facts = {} + <at> coll.each do |fact, value| + fact.should be_instance_of(String) + end end - describe "when iterating over facts" do - before do - <at> coll = Facter::Util::Collection.new - <at> one = <at> coll.add(:one) - <at> two = <at> coll.add(:two) - end - - it "should yield each fact name and the fact value" do - <at> one.stubs(:value).returns "ONE" - <at> two.stubs(:value).returns "TWO" - facts = {} - <at> coll.each do |fact, value| - facts[fact] = value - end - facts.should == {"one" => "ONE", "two" => "TWO"} - end - - it "should convert the fact name to a string" do - <at> one.stubs(:value).returns "ONE" - <at> two.stubs(:value).returns "TWO" - facts = {} - <at> coll.each do |fact, value| - fact.should be_instance_of(String) - end - end - - it "should only yield facts that have values" do - <at> one.stubs(:value).returns "ONE" - <at> two.stubs(:value).returns nil - facts = {} - <at> coll.each do |fact, value| - facts[fact] = value - end + it "should only yield facts that have values" do + <at> one.stubs(:value).returns "ONE" + <at> two.stubs(:value).returns nil + facts = {} + <at> coll.each do |fact, value| + facts[fact] = value + end - facts.should_not be_include("two") - end + facts.should_not be_include("two") end + end end diff --git a/spec/unit/util/confine_spec.rb b/spec/unit/util/confine_spec.rb index 147c70d..5e5706b 100755 --- a/spec/unit/util/confine_spec.rb +++ b/spec/unit/util/confine_spec.rb <at> <at> -8,133 +8,133 <at> <at> require 'facter/util/values' include Facter::Util::Values describe Facter::Util::Confine do - it "should require a fact name" do - Facter::Util::Confine.new("yay", true).fact.should == "yay" + it "should require a fact name" do + Facter::Util::Confine.new("yay", true).fact.should == "yay" + end + + it "should accept a value specified individually" do + Facter::Util::Confine.new("yay", "test").values.should == ["test"] + end + + it "should accept multiple values specified at once" do + Facter::Util::Confine.new("yay", "test", "other").values.should == ["test", "other"] + end + + it "should fail if no fact name is provided" do + lambda { Facter::Util::Confine.new(nil, :test) }.should raise_error(ArgumentError) + end + + it "should fail if no values were provided" do + lambda { Facter::Util::Confine.new("yay") }.should raise_error(ArgumentError) + end + + it "should have a method for testing whether it matches" do + Facter::Util::Confine.new("yay", :test).should respond_to(:true?) + end + + describe "when evaluating" do + before do + <at> confine = Facter::Util::Confine.new("yay", "one", "two", "Four", :xy, true, 1, [3,4]) + <at> fact = mock 'fact' + Facter.stubs(:[]).returns <at> fact end - it "should accept a value specified individually" do - Facter::Util::Confine.new("yay", "test").values.should == ["test"] - end + it "should return false if the fact does not exist" do + Facter.expects(:[]).with("yay").returns nil - it "should accept multiple values specified at once" do - Facter::Util::Confine.new("yay", "test", "other").values.should == ["test", "other"] + <at> confine.true?.should be_false end - it "should fail if no fact name is provided" do - lambda { Facter::Util::Confine.new(nil, :test) }.should raise_error(ArgumentError) - end + it "should use the returned fact to get the value" do + Facter.expects(:[]).with("yay").returns <at> fact - it "should fail if no values were provided" do - lambda { Facter::Util::Confine.new("yay") }.should raise_error(ArgumentError) - end + <at> fact.expects(:value).returns nil - it "should have a method for testing whether it matches" do - Facter::Util::Confine.new("yay", :test).should respond_to(:true?) + <at> confine.true? end - describe "when evaluating" do - before do - <at> confine = Facter::Util::Confine.new("yay", "one", "two", "Four", :xy, true, 1, [3,4]) - <at> fact = mock 'fact' - Facter.stubs(:[]).returns <at> fact - end - - it "should return false if the fact does not exist" do - Facter.expects(:[]).with("yay").returns nil - - <at> confine.true?.should be_false - end - - it "should use the returned fact to get the value" do - Facter.expects(:[]).with("yay").returns <at> fact + it "should return false if the fact has no value" do + <at> fact.stubs(:value).returns nil - <at> fact.expects(:value).returns nil - - <at> confine.true? - end - - it "should return false if the fact has no value" do - <at> fact.stubs(:value).returns nil - - <at> confine.true?.should be_false - end + <at> confine.true?.should be_false + end - it "should return true if any of the provided values matches the fact's value" do - <at> fact.stubs(:value).returns "two" + it "should return true if any of the provided values matches the fact's value" do + <at> fact.stubs(:value).returns "two" - <at> confine.true?.should be_true - end + <at> confine.true?.should be_true + end - it "should return true if any of the provided symbol values matches the fact's value" do - <at> fact.stubs(:value).returns :xy + it "should return true if any of the provided symbol values matches the fact's value" do + <at> fact.stubs(:value).returns :xy - <at> confine.true?.should be_true - end + <at> confine.true?.should be_true + end - it "should return true if any of the provided integer values matches the fact's value" do - <at> fact.stubs(:value).returns 1 + it "should return true if any of the provided integer values matches the fact's value" do + <at> fact.stubs(:value).returns 1 - <at> confine.true?.should be_true - end + <at> confine.true?.should be_true + end - it "should return true if any of the provided boolan values matches the fact's value" do - <at> fact.stubs(:value).returns true + it "should return true if any of the provided boolan values matches the fact's value" do + <at> fact.stubs(:value).returns true - <at> confine.true?.should be_true - end + <at> confine.true?.should be_true + end - it "should return true if any of the provided array values matches the fact's value" do - <at> fact.stubs(:value).returns [3,4] + it "should return true if any of the provided array values matches the fact's value" do + <at> fact.stubs(:value).returns [3,4] - <at> confine.true?.should be_true - end + <at> confine.true?.should be_true + end - it "should return true if any of the provided symbol values matches the fact's string value" do - <at> fact.stubs(:value).returns :one + it "should return true if any of the provided symbol values matches the fact's string value" do + <at> fact.stubs(:value).returns :one - <at> confine.true?.should be_true - end + <at> confine.true?.should be_true + end - it "should return true if any of the provided string values matches case-insensitive the fact's value" do - <at> fact.stubs(:value).returns "four" + it "should return true if any of the provided string values matches case-insensitive the fact's value" do + <at> fact.stubs(:value).returns "four" - <at> confine.true?.should be_true - end + <at> confine.true?.should be_true + end - it "should return true if any of the provided symbol values matches case-insensitive the fact's string value" do - <at> fact.stubs(:value).returns :four + it "should return true if any of the provided symbol values matches case-insensitive the fact's string value" do + <at> fact.stubs(:value).returns :four - <at> confine.true?.should be_true - end + <at> confine.true?.should be_true + end - it "should return true if any of the provided symbol values matches the fact's string value" do - <at> fact.stubs(:value).returns :Xy + it "should return true if any of the provided symbol values matches the fact's string value" do + <at> fact.stubs(:value).returns :Xy - <at> confine.true?.should be_true - end + <at> confine.true?.should be_true + end - it "should return false if none of the provided values matches the fact's value" do - <at> fact.stubs(:value).returns "three" + it "should return false if none of the provided values matches the fact's value" do + <at> fact.stubs(:value).returns "three" - <at> confine.true?.should be_false - end + <at> confine.true?.should be_false + end - it "should return false if none of the provided integer values matches the fact's value" do - <at> fact.stubs(:value).returns 2 + it "should return false if none of the provided integer values matches the fact's value" do + <at> fact.stubs(:value).returns 2 - <at> confine.true?.should be_false - end + <at> confine.true?.should be_false + end - it "should return false if none of the provided boolan values matches the fact's value" do - <at> fact.stubs(:value).returns false + it "should return false if none of the provided boolan values matches the fact's value" do + <at> fact.stubs(:value).returns false - <at> confine.true?.should be_false - end + <at> confine.true?.should be_false + end - it "should return false if none of the provided array values matches the fact's value" do - <at> fact.stubs(:value).returns [1,2] + it "should return false if none of the provided array values matches the fact's value" do + <at> fact.stubs(:value).returns [1,2] - <at> confine.true?.should be_false - end + <at> confine.true?.should be_false end + end end diff --git a/spec/unit/util/fact_spec.rb b/spec/unit/util/fact_spec.rb index 523c855..9b8c8d1 100755 --- a/spec/unit/util/fact_spec.rb +++ b/spec/unit/util/fact_spec.rb <at> <at> -5,125 +5,125 <at> <at> require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/fact' describe Facter::Util::Fact do - it "should require a name" do - lambda { Facter::Util::Fact.new }.should raise_error(ArgumentError) - end + it "should require a name" do + lambda { Facter::Util::Fact.new }.should raise_error(ArgumentError) + end - it "should always downcase the name and convert it to a symbol" do - Facter::Util::Fact.new("YayNess").name.should == :yayness - end + it "should always downcase the name and convert it to a symbol" do + Facter::Util::Fact.new("YayNess").name.should == :yayness + end - it "should default to its name converted to a string as its ldapname" do - Facter::Util::Fact.new("YayNess").ldapname.should == "yayness" - end + it "should default to its name converted to a string as its ldapname" do + Facter::Util::Fact.new("YayNess").ldapname.should == "yayness" + end - it "should allow specifying the ldap name at initialization" do - Facter::Util::Fact.new("YayNess", :ldapname => "fooness").ldapname.should == "fooness" - end + it "should allow specifying the ldap name at initialization" do + Facter::Util::Fact.new("YayNess", :ldapname => "fooness").ldapname.should == "fooness" + end + + it "should fail if an unknown option is provided" do + lambda { Facter::Util::Fact.new('yay', :foo => :bar) }.should raise_error(ArgumentError) + end + + it "should have a method for adding resolution mechanisms" do + Facter::Util::Fact.new("yay").should respond_to(:add) + end + + describe "when adding resolution mechanisms" do + before do + <at> fact = Facter::Util::Fact.new("yay") + + <at> resolution = mock 'resolution' + <at> resolution.stub_everything - it "should fail if an unknown option is provided" do - lambda { Facter::Util::Fact.new('yay', :foo => :bar) }.should raise_error(ArgumentError) end - it "should have a method for adding resolution mechanisms" do - Facter::Util::Fact.new("yay").should respond_to(:add) + it "should fail if no block is given" do + lambda { <at> fact.add }.should raise_error(ArgumentError) end - describe "when adding resolution mechanisms" do - before do - <at> fact = Facter::Util::Fact.new("yay") + it "should create a new resolution instance" do + Facter::Util::Resolution.expects(:new).returns <at> resolution + + <at> fact.add { } + end - <at> resolution = mock 'resolution' - <at> resolution.stub_everything + it "should instance_eval the passed block on the new resolution" do + <at> resolution.expects(:instance_eval) - end + Facter::Util::Resolution.stubs(:new).returns <at> resolution - it "should fail if no block is given" do - lambda { <at> fact.add }.should raise_error(ArgumentError) - end + <at> fact.add { } + end - it "should create a new resolution instance" do - Facter::Util::Resolution.expects(:new).returns <at> resolution + it "should re-sort the resolutions by weight, so the most restricted resolutions are first" do + r1 = stub 'r1', :weight => 1 + r2 = stub 'r2', :weight => 2 + r3 = stub 'r3', :weight => 0 + Facter::Util::Resolution.expects(:new).times(3).returns(r1).returns(r2).returns(r3) + <at> fact.add { } + <at> fact.add { } + <at> fact.add { } - <at> fact.add { } - end + <at> fact.instance_variable_get(" <at> resolves").should == [r2, r1, r3] + end + end - it "should instance_eval the passed block on the new resolution" do - <at> resolution.expects(:instance_eval) + it "should be able to return a value" do + Facter::Util::Fact.new("yay").should respond_to(:value) + end - Facter::Util::Resolution.stubs(:new).returns <at> resolution + describe "when returning a value" do + before do + <at> fact = Facter::Util::Fact.new("yay") + end - <at> fact.add { } - end + it "should return nil if there are no resolutions" do + Facter::Util::Fact.new("yay").value.should be_nil + end - it "should re-sort the resolutions by weight, so the most restricted resolutions are first" do - r1 = stub 'r1', :weight => 1 - r2 = stub 'r2', :weight => 2 - r3 = stub 'r3', :weight => 0 - Facter::Util::Resolution.expects(:new).times(3).returns(r1).returns(r2).returns(r3) - <at> fact.add { } - <at> fact.add { } - <at> fact.add { } + it "should return the first value returned by a resolution" do + r1 = stub 'r1', :weight => 2, :value => nil, :suitable? => true + r2 = stub 'r2', :weight => 1, :value => "yay", :suitable? => true + r3 = stub 'r3', :weight => 0, :value => "foo", :suitable? => true + Facter::Util::Resolution.expects(:new).times(3).returns(r1).returns(r2).returns(r3) + <at> fact.add { } + <at> fact.add { } + <at> fact.add { } - <at> fact.instance_variable_get(" <at> resolves").should == [r2, r1, r3] - end + <at> fact.value.should == "yay" end - it "should be able to return a value" do - Facter::Util::Fact.new("yay").should respond_to(:value) + it "should short-cut returning the value once one is found" do + r1 = stub 'r1', :weight => 2, :value => "foo", :suitable? => true + r2 = stub 'r2', :weight => 1, :suitable? => true # would fail if 'value' were asked for + Facter::Util::Resolution.expects(:new).times(2).returns(r1).returns(r2) + <at> fact.add { } + <at> fact.add { } + + <at> fact.value end - describe "when returning a value" do - before do - <at> fact = Facter::Util::Fact.new("yay") - end - - it "should return nil if there are no resolutions" do - Facter::Util::Fact.new("yay").value.should be_nil - end - - it "should return the first value returned by a resolution" do - r1 = stub 'r1', :weight => 2, :value => nil, :suitable? => true - r2 = stub 'r2', :weight => 1, :value => "yay", :suitable? => true - r3 = stub 'r3', :weight => 0, :value => "foo", :suitable? => true - Facter::Util::Resolution.expects(:new).times(3).returns(r1).returns(r2).returns(r3) - <at> fact.add { } - <at> fact.add { } - <at> fact.add { } - - <at> fact.value.should == "yay" - end - - it "should short-cut returning the value once one is found" do - r1 = stub 'r1', :weight => 2, :value => "foo", :suitable? => true - r2 = stub 'r2', :weight => 1, :suitable? => true # would fail if 'value' were asked for - Facter::Util::Resolution.expects(:new).times(2).returns(r1).returns(r2) - <at> fact.add { } - <at> fact.add { } - - <at> fact.value - end - - it "should skip unsuitable resolutions" do - r1 = stub 'r1', :weight => 2, :suitable? => false # would fail if 'value' were asked for' - r2 = stub 'r2', :weight => 1, :value => "yay", :suitable? => true - Facter::Util::Resolution.expects(:new).times(2).returns(r1).returns(r2) - <at> fact.add { } - <at> fact.add { } - - <at> fact.value.should == "yay" - end - - it "should return nil if the value is the empty string" do - r1 = stub 'r1', :suitable? => true, :value => "" - Facter::Util::Resolution.expects(:new).returns r1 - <at> fact.add { } - - <at> fact.value.should be_nil - end + it "should skip unsuitable resolutions" do + r1 = stub 'r1', :weight => 2, :suitable? => false # would fail if 'value' were asked for' + r2 = stub 'r2', :weight => 1, :value => "yay", :suitable? => true + Facter::Util::Resolution.expects(:new).times(2).returns(r1).returns(r2) + <at> fact.add { } + <at> fact.add { } + + <at> fact.value.should == "yay" end - it "should have a method for flushing the cached fact" do - Facter::Util::Fact.new(:foo).should respond_to(:flush) + it "should return nil if the value is the empty string" do + r1 = stub 'r1', :suitable? => true, :value => "" + Facter::Util::Resolution.expects(:new).returns r1 + <at> fact.add { } + + <at> fact.value.should be_nil end + end + + it "should have a method for flushing the cached fact" do + Facter::Util::Fact.new(:foo).should respond_to(:flush) + end end diff --git a/spec/unit/util/ip_spec.rb b/spec/unit/util/ip_spec.rb index 9649010..50035c5 100755 --- a/spec/unit/util/ip_spec.rb +++ b/spec/unit/util/ip_spec.rb <at> <at> -5,295 +5,295 <at> <at> require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/ip' describe Facter::Util::IP do - before :each do - Facter::Util::Config.stubs(:is_windows?).returns(false) - end - - [:freebsd, :linux, :netbsd, :openbsd, :sunos, :darwin, :"hp-ux", :"gnu/kfreebsd", :windows].each do |platform| - it "should be supported on #{platform}" do - Facter::Util::Config.stubs(:is_windows?).returns(platform == :windows) - Facter::Util::IP.supported_platforms.should be_include(platform) - end - end - - it "should return a list of interfaces" do - Facter::Util::IP.should respond_to(:get_interfaces) - end + before :each do + Facter::Util::Config.stubs(:is_windows?).returns(false) + end + + [:freebsd, :linux, :netbsd, :openbsd, :sunos, :darwin, :"hp-ux", :"gnu/kfreebsd", :windows].each do |platform| + it "should be supported on #{platform}" do + Facter::Util::Config.stubs(:is_windows?).returns(platform == :windows) + Facter::Util::IP.supported_platforms.should be_include(platform) + end + end + + it "should return a list of interfaces" do + Facter::Util::IP.should respond_to(:get_interfaces) + end + + it "should return an empty list of interfaces on an unknown kernel" do + Facter.stubs(:value).returns("UnknownKernel") + Facter::Util::IP.get_interfaces().should == [] + end + + it "should return a list with a single interface and the loopback interface on Linux with a single interface" do + sample_output_file = File.dirname(__FILE__) + '/../data/linux_ifconfig_all_with_single_interface' + linux_ifconfig = File.read(sample_output_file) + Facter::Util::IP.stubs(:get_all_interface_output).returns(linux_ifconfig) + Facter::Util::IP.get_interfaces().should == ["eth0", "lo"] + end + + it "should return a list two interfaces on Darwin with two interfaces" do + sample_output_file = File.dirname(__FILE__) + '/../data/darwin_ifconfig_all_with_multiple_interfaces' + darwin_ifconfig = File.read(sample_output_file) + Facter::Util::IP.stubs(:get_all_interface_output).returns(darwin_ifconfig) + Facter::Util::IP.get_interfaces().should == ["lo0", "en0"] + end + + it "should return a list two interfaces on Solaris with two interfaces multiply reporting" do + sample_output_file = File.dirname(__FILE__) + '/../data/solaris_ifconfig_all_with_multiple_interfaces' + solaris_ifconfig = File.read(sample_output_file) + Facter::Util::IP.stubs(:get_all_interface_output).returns(solaris_ifconfig) + Facter::Util::IP.get_interfaces().should == ["lo0", "e1000g0"] + end + + it "should return a list three interfaces on HP-UX with three interfaces multiply reporting" do + sample_output_file = File.dirname(__FILE__) + '/../data/hpux_netstat_all_interfaces' + hpux_netstat = File.read(sample_output_file) + Facter::Util::IP.stubs(:get_all_interface_output).returns(hpux_netstat) + Facter::Util::IP.get_interfaces().should == ["lan1", "lan0", "lo0"] + end + + it "should return a list of six interfaces on a GNU/kFreeBSD with six interfaces" do + sample_output_file = File.dirname(__FILE__) + '/../data/debian_kfreebsd_ifconfig' + kfreebsd_ifconfig = File.read(sample_output_file) + Facter::Util::IP.stubs(:get_all_interface_output).returns(kfreebsd_ifconfig) + Facter::Util::IP.get_interfaces().should == ["em0", "em1", "bge0", "bge1", "lo0", "vlan0"] + end + + it "should return a list of only connected interfaces on Windows" do + Facter.fact(:kernel).stubs(:value).returns("windows") + sample_output_file = File.dirname(__FILE__) + '/../data/windows_netsh_all_interfaces' + windows_netsh = File.read(sample_output_file) + Facter::Util::IP.stubs(:get_all_interface_output).returns(windows_netsh) + Facter::Util::IP.get_interfaces().should == ["Loopback Pseudo-Interface 1", "Local Area Connection", "Teredo Tunneling Pseudo-Interface"] + end - it "should return an empty list of interfaces on an unknown kernel" do - Facter.stubs(:value).returns("UnknownKernel") - Facter::Util::IP.get_interfaces().should == [] - end + it "should return a value for a specific interface" do + Facter::Util::IP.should respond_to(:get_interface_value) + end - it "should return a list with a single interface and the loopback interface on Linux with a single interface" do - sample_output_file = File.dirname(__FILE__) + '/../data/linux_ifconfig_all_with_single_interface' - linux_ifconfig = File.read(sample_output_file) - Facter::Util::IP.stubs(:get_all_interface_output).returns(linux_ifconfig) - Facter::Util::IP.get_interfaces().should == ["eth0", "lo"] - end + it "should not return interface information for unsupported platforms" do + Facter.stubs(:value).with(:kernel).returns("bleah") + Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == [] + end - it "should return a list two interfaces on Darwin with two interfaces" do - sample_output_file = File.dirname(__FILE__) + '/../data/darwin_ifconfig_all_with_multiple_interfaces' - darwin_ifconfig = File.read(sample_output_file) - Facter::Util::IP.stubs(:get_all_interface_output).returns(darwin_ifconfig) - Facter::Util::IP.get_interfaces().should == ["lo0", "en0"] - end + it "should return ipaddress information for Solaris" do + sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface" + solaris_ifconfig_interface = File.read(sample_output_file) - it "should return a list two interfaces on Solaris with two interfaces multiply reporting" do - sample_output_file = File.dirname(__FILE__) + '/../data/solaris_ifconfig_all_with_multiple_interfaces' - solaris_ifconfig = File.read(sample_output_file) - Facter::Util::IP.stubs(:get_all_interface_output).returns(solaris_ifconfig) - Facter::Util::IP.get_interfaces().should == ["lo0", "e1000g0"] - end + Facter::Util::IP.expects(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface) + Facter.stubs(:value).with(:kernel).returns("SunOS") - it "should return a list three interfaces on HP-UX with three interfaces multiply reporting" do - sample_output_file = File.dirname(__FILE__) + '/../data/hpux_netstat_all_interfaces' - hpux_netstat = File.read(sample_output_file) - Facter::Util::IP.stubs(:get_all_interface_output).returns(hpux_netstat) - Facter::Util::IP.get_interfaces().should == ["lan1", "lan0", "lo0"] - end + Facter::Util::IP.get_interface_value("e1000g0", "ipaddress").should == "172.16.15.138" + end - it "should return a list of six interfaces on a GNU/kFreeBSD with six interfaces" do - sample_output_file = File.dirname(__FILE__) + '/../data/debian_kfreebsd_ifconfig' - kfreebsd_ifconfig = File.read(sample_output_file) - Facter::Util::IP.stubs(:get_all_interface_output).returns(kfreebsd_ifconfig) - Facter::Util::IP.get_interfaces().should == ["em0", "em1", "bge0", "bge1", "lo0", "vlan0"] - end + it "should return netmask information for Solaris" do + sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface" + solaris_ifconfig_interface = File.read(sample_output_file) - it "should return a list of only connected interfaces on Windows" do - Facter.fact(:kernel).stubs(:value).returns("windows") - sample_output_file = File.dirname(__FILE__) + '/../data/windows_netsh_all_interfaces' - windows_netsh = File.read(sample_output_file) - Facter::Util::IP.stubs(:get_all_interface_output).returns(windows_netsh) - Facter::Util::IP.get_interfaces().should == ["Loopback Pseudo-Interface 1", "Local Area Connection", "Teredo Tunneling Pseudo-Interface"] - end + Facter::Util::IP.expects(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface) + Facter.stubs(:value).with(:kernel).returns("SunOS") - it "should return a value for a specific interface" do - Facter::Util::IP.should respond_to(:get_interface_value) - end + Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == "255.255.255.0" + end - it "should not return interface information for unsupported platforms" do - Facter.stubs(:value).with(:kernel).returns("bleah") - Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == [] - end + it "should return calculated network information for Solaris" do + sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface" + solaris_ifconfig_interface = File.read(sample_output_file) - it "should return ipaddress information for Solaris" do - sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface" - solaris_ifconfig_interface = File.read(sample_output_file) + Facter::Util::IP.stubs(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface) + Facter.stubs(:value).with(:kernel).returns("SunOS") - Facter::Util::IP.expects(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface) - Facter.stubs(:value).with(:kernel).returns("SunOS") + Facter::Util::IP.get_network_value("e1000g0").should == "172.16.15.0" + end - Facter::Util::IP.get_interface_value("e1000g0", "ipaddress").should == "172.16.15.138" - end + it "should return ipaddress information for HP-UX" do + sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface" + hpux_ifconfig_interface = File.read(sample_output_file) - it "should return netmask information for Solaris" do - sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface" - solaris_ifconfig_interface = File.read(sample_output_file) + Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface) + Facter.stubs(:value).with(:kernel).returns("HP-UX") - Facter::Util::IP.expects(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface) - Facter.stubs(:value).with(:kernel).returns("SunOS") + Facter::Util::IP.get_interface_value("lan0", "ipaddress").should == "168.24.80.71" + end - Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == "255.255.255.0" - end + it "should return macaddress information for HP-UX" do + sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface" + hpux_ifconfig_interface = File.read(sample_output_file) - it "should return calculated network information for Solaris" do - sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface" - solaris_ifconfig_interface = File.read(sample_output_file) + Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface) + Facter.stubs(:value).with(:kernel).returns("HP-UX") - Facter::Util::IP.stubs(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface) - Facter.stubs(:value).with(:kernel).returns("SunOS") + Facter::Util::IP.get_interface_value("lan0", "macaddress").should == "00:13:21:BD:9C:B7" + end - Facter::Util::IP.get_network_value("e1000g0").should == "172.16.15.0" - end + it "should return macaddress with leading zeros stripped off for GNU/kFreeBSD" do + sample_output_file = File.dirname(__FILE__) + "/../data/debian_kfreebsd_ifconfig" + kfreebsd_ifconfig = File.read(sample_output_file) - it "should return ipaddress information for HP-UX" do - sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface" - hpux_ifconfig_interface = File.read(sample_output_file) + Facter::Util::IP.expects(:get_single_interface_output).with("em0").returns(kfreebsd_ifconfig) + Facter.stubs(:value).with(:kernel).returns("GNU/kFreeBSD") - Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface) - Facter.stubs(:value).with(:kernel).returns("HP-UX") + Facter::Util::IP.get_interface_value("em0", "macaddress").should == "0:11:a:59:67:90" + end - Facter::Util::IP.get_interface_value("lan0", "ipaddress").should == "168.24.80.71" - end + it "should return netmask information for HP-UX" do + sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface" + hpux_ifconfig_interface = File.read(sample_output_file) - it "should return macaddress information for HP-UX" do - sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface" - hpux_ifconfig_interface = File.read(sample_output_file) + Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface) + Facter.stubs(:value).with(:kernel).returns("HP-UX") - Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface) - Facter.stubs(:value).with(:kernel).returns("HP-UX") + Facter::Util::IP.get_interface_value("lan0", "netmask").should == "255.255.255.0" + end - Facter::Util::IP.get_interface_value("lan0", "macaddress").should == "00:13:21:BD:9C:B7" - end + it "should return calculated network information for HP-UX" do + sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface" + hpux_ifconfig_interface = File.read(sample_output_file) - it "should return macaddress with leading zeros stripped off for GNU/kFreeBSD" do - sample_output_file = File.dirname(__FILE__) + "/../data/debian_kfreebsd_ifconfig" - kfreebsd_ifconfig = File.read(sample_output_file) + Facter::Util::IP.stubs(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface) + Facter.stubs(:value).with(:kernel).returns("HP-UX") - Facter::Util::IP.expects(:get_single_interface_output).with("em0").returns(kfreebsd_ifconfig) - Facter.stubs(:value).with(:kernel).returns("GNU/kFreeBSD") + Facter::Util::IP.get_network_value("lan0").should == "168.24.80.0" + end - Facter::Util::IP.get_interface_value("em0", "macaddress").should == "0:11:a:59:67:90" - end + it "should return interface information for FreeBSD supported via an alias" do + sample_output_file = File.dirname(__FILE__) + "/../data/6.0-STABLE_FreeBSD_ifconfig" + ifconfig_interface = File.read(sample_output_file) - it "should return netmask information for HP-UX" do - sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface" - hpux_ifconfig_interface = File.read(sample_output_file) + Facter::Util::IP.expects(:get_single_interface_output).with("fxp0").returns(ifconfig_interface) + Facter.stubs(:value).with(:kernel).returns("FreeBSD") - Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface) - Facter.stubs(:value).with(:kernel).returns("HP-UX") + Facter::Util::IP.get_interface_value("fxp0", "macaddress").should == "00:0e:0c:68:67:7c" + end - Facter::Util::IP.get_interface_value("lan0", "netmask").should == "255.255.255.0" - end + it "should return macaddress information for OS X" do + sample_output_file = File.dirname(__FILE__) + "/../data/Mac_OS_X_10.5.5_ifconfig" + ifconfig_interface = File.read(sample_output_file) - it "should return calculated network information for HP-UX" do - sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface" - hpux_ifconfig_interface = File.read(sample_output_file) + Facter::Util::IP.expects(:get_single_interface_output).with("en1").returns(ifconfig_interface) + Facter.stubs(:value).with(:kernel).returns("Darwin") - Facter::Util::IP.stubs(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface) - Facter.stubs(:value).with(:kernel).returns("HP-UX") + Facter::Util::IP.get_interface_value("en1", "macaddress").should == "00:1b:63:ae:02:66" + end - Facter::Util::IP.get_network_value("lan0").should == "168.24.80.0" - end + it "should return all interfaces correctly on OS X" do + sample_output_file = File.dirname(__FILE__) + "/../data/Mac_OS_X_10.5.5_ifconfig" + ifconfig_interface = File.read(sample_output_file) - it "should return interface information for FreeBSD supported via an alias" do - sample_output_file = File.dirname(__FILE__) + "/../data/6.0-STABLE_FreeBSD_ifconfig" - ifconfig_interface = File.read(sample_output_file) + Facter::Util::IP.expects(:get_all_interface_output).returns(ifconfig_interface) + Facter.stubs(:value).with(:kernel).returns("Darwin") - Facter::Util::IP.expects(:get_single_interface_output).with("fxp0").returns(ifconfig_interface) - Facter.stubs(:value).with(:kernel).returns("FreeBSD") + Facter::Util::IP.get_interfaces().should == ["lo0", "gif0", "stf0", "en0", "fw0", "en1", "vmnet8", "vmnet1"] + end - Facter::Util::IP.get_interface_value("fxp0", "macaddress").should == "00:0e:0c:68:67:7c" - end + it "should return a human readable netmask on Solaris" do + sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface" + solaris_ifconfig_interface = File.read(sample_output_file) - it "should return macaddress information for OS X" do - sample_output_file = File.dirname(__FILE__) + "/../data/Mac_OS_X_10.5.5_ifconfig" - ifconfig_interface = File.read(sample_output_file) + Facter::Util::IP.expects(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface) + Facter.stubs(:value).with(:kernel).returns("SunOS") - Facter::Util::IP.expects(:get_single_interface_output).with("en1").returns(ifconfig_interface) - Facter.stubs(:value).with(:kernel).returns("Darwin") + Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == "255.255.255.0" + end - Facter::Util::IP.get_interface_value("en1", "macaddress").should == "00:1b:63:ae:02:66" - end + it "should return a human readable netmask on HP-UX" do + sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface" + hpux_ifconfig_interface = File.read(sample_output_file) - it "should return all interfaces correctly on OS X" do - sample_output_file = File.dirname(__FILE__) + "/../data/Mac_OS_X_10.5.5_ifconfig" - ifconfig_interface = File.read(sample_output_file) + Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface) + Facter.stubs(:value).with(:kernel).returns("HP-UX") - Facter::Util::IP.expects(:get_all_interface_output).returns(ifconfig_interface) - Facter.stubs(:value).with(:kernel).returns("Darwin") + Facter::Util::IP.get_interface_value("lan0", "netmask").should == "255.255.255.0" + end - Facter::Util::IP.get_interfaces().should == ["lo0", "gif0", "stf0", "en0", "fw0", "en1", "vmnet8", "vmnet1"] - end + it "should return a human readable netmask on Darwin" do + sample_output_file = File.dirname(__FILE__) + "/../data/darwin_ifconfig_single_interface" - it "should return a human readable netmask on Solaris" do - sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface" - solaris_ifconfig_interface = File.read(sample_output_file) + darwin_ifconfig_interface = File.read(sample_output_file) - Facter::Util::IP.expects(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface) - Facter.stubs(:value).with(:kernel).returns("SunOS") + Facter::Util::IP.expects(:get_single_interface_output).with("en1").returns(darwin_ifconfig_interface) + Facter.stubs(:value).with(:kernel).returns("Darwin") - Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == "255.255.255.0" - end + Facter::Util::IP.get_interface_value("en1", "netmask").should == "255.255.255.0" + end - it "should return a human readable netmask on HP-UX" do - sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface" - hpux_ifconfig_interface = File.read(sample_output_file) + it "should return a human readable netmask on GNU/kFreeBSD" do + sample_output_file = File.dirname(__FILE__) + "/../data/debian_kfreebsd_ifconfig" - Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface) - Facter.stubs(:value).with(:kernel).returns("HP-UX") + kfreebsd_ifconfig = File.read(sample_output_file) - Facter::Util::IP.get_interface_value("lan0", "netmask").should == "255.255.255.0" - end + Facter::Util::IP.expects(:get_single_interface_output).with("em1").returns(kfreebsd_ifconfig) + Facter.stubs(:value).with(:kernel).returns("GNU/kFreeBSD") - it "should return a human readable netmask on Darwin" do - sample_output_file = File.dirname(__FILE__) + "/../data/darwin_ifconfig_single_interface" + Facter::Util::IP.get_interface_value("em1", "netmask").should == "255.255.255.0" + end - darwin_ifconfig_interface = File.read(sample_output_file) + it "should not get bonding master on interface aliases" do + Facter.stubs(:value).with(:kernel).returns("Linux") - Facter::Util::IP.expects(:get_single_interface_output).with("en1").returns(darwin_ifconfig_interface) - Facter.stubs(:value).with(:kernel).returns("Darwin") + Facter::Util::IP.get_bonding_master("eth0:1").should be_nil + end - Facter::Util::IP.get_interface_value("en1", "netmask").should == "255.255.255.0" + [:freebsd, :netbsd, :openbsd, :sunos, :darwin, :"hp-ux"].each do |platform| + it "should require conversion from hex on #{platform}" do + Facter::Util::IP.convert_from_hex?(platform).should == true end + end - it "should return a human readable netmask on GNU/kFreeBSD" do - sample_output_file = File.dirname(__FILE__) + "/../data/debian_kfreebsd_ifconfig" - - kfreebsd_ifconfig = File.read(sample_output_file) - - Facter::Util::IP.expects(:get_single_interface_output).with("em1").returns(kfreebsd_ifconfig) - Facter.stubs(:value).with(:kernel).returns("GNU/kFreeBSD") - - Facter::Util::IP.get_interface_value("em1", "netmask").should == "255.255.255.0" + [:windows].each do |platform| + it "should not require conversion from hex on #{platform}" do + Facter::Util::IP.convert_from_hex?(platform).should be_false end + end - it "should not get bonding master on interface aliases" do - Facter.stubs(:value).with(:kernel).returns("Linux") + it "should return an arp address on Linux" do + Facter.stubs(:value).with(:kernel).returns("Linux") - Facter::Util::IP.get_bonding_master("eth0:1").should be_nil - end + Facter::Util::IP.expects(:get_arp_value).with("eth0").returns("00:00:0c:9f:f0:04") + Facter::Util::IP.get_arp_value("eth0").should == "00:00:0c:9f:f0:04" + end - [:freebsd, :netbsd, :openbsd, :sunos, :darwin, :"hp-ux"].each do |platform| - it "should require conversion from hex on #{platform}" do - Facter::Util::IP.convert_from_hex?(platform).should == true - end + describe "on Windows" do + before :each do + Facter.stubs(:value).with(:kernel).returns("windows") end - [:windows].each do |platform| - it "should not require conversion from hex on #{platform}" do - Facter::Util::IP.convert_from_hex?(platform).should be_false - end - end + it "should return ipaddress information" do + sample_output_file = File.dirname(__FILE__) + "/../data/windows_netsh_single_interface" + windows_netsh = File.read(sample_output_file) - it "should return an arp address on Linux" do - Facter.stubs(:value).with(:kernel).returns("Linux") + Facter::Util::IP.expects(:get_output_for_interface_and_label).with("Local Area Connection", "ipaddress").returns(windows_netsh) - Facter::Util::IP.expects(:get_arp_value).with("eth0").returns("00:00:0c:9f:f0:04") - Facter::Util::IP.get_arp_value("eth0").should == "00:00:0c:9f:f0:04" + Facter::Util::IP.get_interface_value("Local Area Connection", "ipaddress").should == "172.16.138.216" end - describe "on Windows" do - before :each do - Facter.stubs(:value).with(:kernel).returns("windows") - end - - it "should return ipaddress information" do - sample_output_file = File.dirname(__FILE__) + "/../data/windows_netsh_single_interface" - windows_netsh = File.read(sample_output_file) + it "should return a human readable netmask" do + sample_output_file = File.dirname(__FILE__) + "/../data/windows_netsh_single_interface" + windows_netsh = File.read(sample_output_file) - Facter::Util::IP.expects(:get_output_for_interface_and_label).with("Local Area Connection", "ipaddress").returns(windows_netsh) + Facter::Util::IP.expects(:get_output_for_interface_and_label).with("Local Area Connection", "netmask").returns(windows_netsh) - Facter::Util::IP.get_interface_value("Local Area Connection", "ipaddress").should == "172.16.138.216" - end - - it "should return a human readable netmask" do - sample_output_file = File.dirname(__FILE__) + "/../data/windows_netsh_single_interface" - windows_netsh = File.read(sample_output_file) - - Facter::Util::IP.expects(:get_output_for_interface_and_label).with("Local Area Connection", "netmask").returns(windows_netsh) - - Facter::Util::IP.get_interface_value("Local Area Connection", "netmask").should == "255.255.255.0" - end + Facter::Util::IP.get_interface_value("Local Area Connection", "netmask").should == "255.255.255.0" + end - it "should return network information" do - sample_output_file = File.dirname(__FILE__) + "/../data/windows_netsh_single_interface" - windows_netsh = File.read(sample_output_file) + it "should return network information" do + sample_output_file = File.dirname(__FILE__) + "/../data/windows_netsh_single_interface" + windows_netsh = File.read(sample_output_file) - Facter::Util::IP.stubs(:get_output_for_interface_and_label).with("Local Area Connection", "ipaddress").returns(windows_netsh) - Facter::Util::IP.stubs(:get_output_for_interface_and_label).with("Local Area Connection", "netmask").returns(windows_netsh) + Facter::Util::IP.stubs(:get_output_for_interface_and_label).with("Local Area Connection", "ipaddress").returns(windows_netsh) + Facter::Util::IP.stubs(:get_output_for_interface_and_label).with("Local Area Connection", "netmask").returns(windows_netsh) - Facter::Util::IP.get_network_value("Local Area Connection").should == "172.16.138.0" - end + Facter::Util::IP.get_network_value("Local Area Connection").should == "172.16.138.0" + end - it "should return ipaddress6 information" do - sample_output_file = File.dirname(__FILE__) + "/../data/windows_netsh_single_interface6" - windows_netsh = File.read(sample_output_file) + it "should return ipaddress6 information" do + sample_output_file = File.dirname(__FILE__) + "/../data/windows_netsh_single_interface6" + windows_netsh = File.read(sample_output_file) - Facter::Util::IP.expects(:get_output_for_interface_and_label).with("Teredo Tunneling Pseudo-Interface", "ipaddress6").returns(windows_netsh) + Facter::Util::IP.expects(:get_output_for_interface_and_label).with("Teredo Tunneling Pseudo-Interface", "ipaddress6").returns(windows_netsh) - Facter::Util::IP.get_interface_value("Teredo Tunneling Pseudo-Interface", "ipaddress6").should == "2001:0:4137:9e76:2087:77a:53ef:7527" - end + Facter::Util::IP.get_interface_value("Teredo Tunneling Pseudo-Interface", "ipaddress6").should == "2001:0:4137:9e76:2087:77a:53ef:7527" end + end end diff --git a/spec/unit/util/loader_spec.rb b/spec/unit/util/loader_spec.rb index 3fb1f04..a3019d9 100755 --- a/spec/unit/util/loader_spec.rb +++ b/spec/unit/util/loader_spec.rb <at> <at> -19,273 +19,273 <at> <at> end describe Facter::Util::Loader do - before :each do - Facter::Util::Loader.any_instance.unstub(:load_all) - end + before :each do + Facter::Util::Loader.any_instance.unstub(:load_all) + end - def with_env(values) - old = {} - values.each do |var, value| - if old_val = ENV[var] - old[var] = old_val - end - ENV[var] = value - end - yield - values.each do |var, value| - if old.include?(var) - ENV[var] = old[var] - else - ENV.delete(var) - end - end + def with_env(values) + old = {} + values.each do |var, value| + if old_val = ENV[var] + old[var] = old_val + end + ENV[var] = value end - - it "should have a method for loading individual facts by name" do - Facter::Util::Loader.new.should respond_to(:load) + yield + values.each do |var, value| + if old.include?(var) + ENV[var] = old[var] + else + ENV.delete(var) + end end + end - it "should have a method for loading all facts" do - Facter::Util::Loader.new.should respond_to(:load_all) - end + it "should have a method for loading individual facts by name" do + Facter::Util::Loader.new.should respond_to(:load) + end - it "should have a method for returning directories containing facts" do - Facter::Util::Loader.new.should respond_to(:search_path) - end + it "should have a method for loading all facts" do + Facter::Util::Loader.new.should respond_to(:load_all) + end - describe "when determining the search path" do - before do - <at> loader = Facter::Util::Loader.new - <at> settings = mock 'settings' - <at> settings.stubs(:value).returns "/eh" - end + it "should have a method for returning directories containing facts" do + Facter::Util::Loader.new.should respond_to(:search_path) + end - it "should include the facter subdirectory of all paths in ruby LOAD_PATH" do - dirs = $LOAD_PATH.collect { |d| File.join(d, "facter") } - paths = <at> loader.search_path + describe "when determining the search path" do + before do + <at> loader = Facter::Util::Loader.new + <at> settings = mock 'settings' + <at> settings.stubs(:value).returns "/eh" + end - dirs.each do |dir| - paths.should be_include(dir) - end - end + it "should include the facter subdirectory of all paths in ruby LOAD_PATH" do + dirs = $LOAD_PATH.collect { |d| File.join(d, "facter") } + paths = <at> loader.search_path - it "should include all search paths registered with Facter" do - Facter.expects(:search_path).returns %w{/one /two} - paths = <at> loader.search_path - paths.should be_include("/one") - paths.should be_include("/two") - end + dirs.each do |dir| + paths.should be_include(dir) + end + end - describe "and the FACTERLIB environment variable is set" do - it "should include all paths in FACTERLIB" do - with_env "FACTERLIB" => "/one/path:/two/path" do - paths = <at> loader.search_path - %w{/one/path /two/path}.each do |dir| - paths.should be_include(dir) - end - end - end - end + it "should include all search paths registered with Facter" do + Facter.expects(:search_path).returns %w{/one /two} + paths = <at> loader.search_path + paths.should be_include("/one") + paths.should be_include("/two") end - describe "when loading facts" do - before do - <at> loader = Facter::Util::Loader.new - <at> loader.stubs(:search_path).returns [] + describe "and the FACTERLIB environment variable is set" do + it "should include all paths in FACTERLIB" do + with_env "FACTERLIB" => "/one/path:/two/path" do + paths = <at> loader.search_path + %w{/one/path /two/path}.each do |dir| + paths.should be_include(dir) + end end + end + end + end - it "should load values from the matching environment variable if one is present" do - Facter.expects(:add).with("testing") + describe "when loading facts" do + before do + <at> loader = Facter::Util::Loader.new + <at> loader.stubs(:search_path).returns [] + end - with_env "facter_testing" => "yayness" do - <at> loader.load(:testing) - end - end + it "should load values from the matching environment variable if one is present" do + Facter.expects(:add).with("testing") - it "should load any files in the search path with names matching the fact name" do - <at> loader.expects(:search_path).returns %w{/one/dir /two/dir} - FileTest.stubs(:exist?).returns false - FileTest.expects(:exist?).with("/one/dir/testing.rb").returns true - FileTest.expects(:exist?).with("/two/dir/testing.rb").returns true + with_env "facter_testing" => "yayness" do + <at> loader.load(:testing) + end + end - Kernel.expects(:load).with("/one/dir/testing.rb") - Kernel.expects(:load).with("/two/dir/testing.rb") + it "should load any files in the search path with names matching the fact name" do + <at> loader.expects(:search_path).returns %w{/one/dir /two/dir} + FileTest.stubs(:exist?).returns false + FileTest.expects(:exist?).with("/one/dir/testing.rb").returns true + FileTest.expects(:exist?).with("/two/dir/testing.rb").returns true - <at> loader.load(:testing) - end + Kernel.expects(:load).with("/one/dir/testing.rb") + Kernel.expects(:load).with("/two/dir/testing.rb") - it 'should load any ruby files in directories matching the fact name in the search path in sorted order regardless of the order returned by Dir.entries' do - <at> loader = TestLoader.new + <at> loader.load(:testing) + end - <at> loader.stubs(:search_path).returns %w{/one/dir} - FileTest.stubs(:exist?).returns false - FileTest.stubs(:directory?).with("/one/dir/testing").returns true - <at> loader.stubs(:search_path).returns %w{/one/dir} + it 'should load any ruby files in directories matching the fact name in the search path in sorted order regardless of the order returned by Dir.entries' do + <at> loader = TestLoader.new - Dir.stubs(:entries).with("/one/dir/testing").returns %w{foo.rb bar.rb} - %w{/one/dir/testing/foo.rb /one/dir/testing/bar.rb}.each do |f| - File.stubs(:directory?).with(f).returns false - Kernel.stubs(:load).with(f) - end + <at> loader.stubs(:search_path).returns %w{/one/dir} + FileTest.stubs(:exist?).returns false + FileTest.stubs(:directory?).with("/one/dir/testing").returns true + <at> loader.stubs(:search_path).returns %w{/one/dir} - <at> loader.load(:testing) - <at> loader.loaded_files.should == %w{/one/dir/testing/bar.rb /one/dir/testing/foo.rb} - end + Dir.stubs(:entries).with("/one/dir/testing").returns %w{foo.rb bar.rb} + %w{/one/dir/testing/foo.rb /one/dir/testing/bar.rb}.each do |f| + File.stubs(:directory?).with(f).returns false + Kernel.stubs(:load).with(f) + end - it "should load any ruby files in directories matching the fact name in the search path" do - <at> loader.expects(:search_path).returns %w{/one/dir} - FileTest.stubs(:exist?).returns false - FileTest.expects(:directory?).with("/one/dir/testing").returns true + <at> loader.load(:testing) + <at> loader.loaded_files.should == %w{/one/dir/testing/bar.rb /one/dir/testing/foo.rb} + end - Dir.expects(:entries).with("/one/dir/testing").returns %w{two.rb} + it "should load any ruby files in directories matching the fact name in the search path" do + <at> loader.expects(:search_path).returns %w{/one/dir} + FileTest.stubs(:exist?).returns false + FileTest.expects(:directory?).with("/one/dir/testing").returns true - Kernel.expects(:load).with("/one/dir/testing/two.rb") + Dir.expects(:entries).with("/one/dir/testing").returns %w{two.rb} - <at> loader.load(:testing) - end + Kernel.expects(:load).with("/one/dir/testing/two.rb") - it "should not load files that don't end in '.rb'" do - <at> loader.expects(:search_path).returns %w{/one/dir} - FileTest.stubs(:exist?).returns false - FileTest.expects(:directory?).with("/one/dir/testing").returns true + <at> loader.load(:testing) + end - Dir.expects(:entries).with("/one/dir/testing").returns %w{one} + it "should not load files that don't end in '.rb'" do + <at> loader.expects(:search_path).returns %w{/one/dir} + FileTest.stubs(:exist?).returns false + FileTest.expects(:directory?).with("/one/dir/testing").returns true - Kernel.expects(:load).never + Dir.expects(:entries).with("/one/dir/testing").returns %w{one} - <at> loader.load(:testing) - end + Kernel.expects(:load).never + + <at> loader.load(:testing) end + end - describe "when loading all facts" do - before do - <at> loader = Facter::Util::Loader.new - <at> loader.stubs(:search_path).returns [] + describe "when loading all facts" do + before do + <at> loader = Facter::Util::Loader.new + <at> loader.stubs(:search_path).returns [] - FileTest.stubs(:directory?).returns true - end + FileTest.stubs(:directory?).returns true + end - it "should skip directories that do not exist" do - <at> loader.expects(:search_path).returns %w{/one/dir} + it "should skip directories that do not exist" do + <at> loader.expects(:search_path).returns %w{/one/dir} - FileTest.expects(:directory?).with("/one/dir").returns false + FileTest.expects(:directory?).with("/one/dir").returns false - Dir.expects(:entries).with("/one/dir").never + Dir.expects(:entries).with("/one/dir").never - <at> loader.load_all - end + <at> loader.load_all + end - it "should load all files in all search paths" do - <at> loader.expects(:search_path).returns %w{/one/dir /two/dir} + it "should load all files in all search paths" do + <at> loader.expects(:search_path).returns %w{/one/dir /two/dir} - Dir.expects(:entries).with("/one/dir").returns %w{a.rb b.rb} - Dir.expects(:entries).with("/two/dir").returns %w{c.rb d.rb} + Dir.expects(:entries).with("/one/dir").returns %w{a.rb b.rb} + Dir.expects(:entries).with("/two/dir").returns %w{c.rb d.rb} - %w{/one/dir/a.rb /one/dir/b.rb /two/dir/c.rb /two/dir/d.rb}.each { |f| Kernel.expects(:load).with(f) } + %w{/one/dir/a.rb /one/dir/b.rb /two/dir/c.rb /two/dir/d.rb}.each { |f| Kernel.expects(:load).with(f) } - <at> loader.load_all - end + <at> loader.load_all + end - it "should load all files in all subdirectories in all search paths" do - <at> loader.expects(:search_path).returns %w{/one/dir /two/dir} + it "should load all files in all subdirectories in all search paths" do + <at> loader.expects(:search_path).returns %w{/one/dir /two/dir} - Dir.expects(:entries).with("/one/dir").returns %w{a} - Dir.expects(:entries).with("/two/dir").returns %w{b} + Dir.expects(:entries).with("/one/dir").returns %w{a} + Dir.expects(:entries).with("/two/dir").returns %w{b} - %w{/one/dir/a /two/dir/b}.each { |f| File.expects(:directory?).with(f).returns true } + %w{/one/dir/a /two/dir/b}.each { |f| File.expects(:directory?).with(f).returns true } - Dir.expects(:entries).with("/one/dir/a").returns %w{c.rb} - Dir.expects(:entries).with("/two/dir/b").returns %w{d.rb} + Dir.expects(:entries).with("/one/dir/a").returns %w{c.rb} + Dir.expects(:entries).with("/two/dir/b").returns %w{d.rb} - %w{/one/dir/a/c.rb /two/dir/b/d.rb}.each { |f| Kernel.expects(:load).with(f) } + %w{/one/dir/a/c.rb /two/dir/b/d.rb}.each { |f| Kernel.expects(:load).with(f) } - <at> loader.load_all - end + <at> loader.load_all + end - it 'should load all files in sorted order for any given directory regardless of the order returned by Dir.entries' do - <at> loader = TestLoader.new + it 'should load all files in sorted order for any given directory regardless of the order returned by Dir.entries' do + <at> loader = TestLoader.new - <at> loader.stubs(:search_path).returns %w{/one/dir} - Dir.stubs(:entries).with("/one/dir").returns %w{foo.rb bar.rb} + <at> loader.stubs(:search_path).returns %w{/one/dir} + Dir.stubs(:entries).with("/one/dir").returns %w{foo.rb bar.rb} - %w{/one/dir}.each { |f| File.stubs(:directory?).with(f).returns true } + %w{/one/dir}.each { |f| File.stubs(:directory?).with(f).returns true } - %w{/one/dir/foo.rb /one/dir/bar.rb}.each do |f| - File.stubs(:directory?).with(f).returns false - Kernel.expects(:load).with(f) - end + %w{/one/dir/foo.rb /one/dir/bar.rb}.each do |f| + File.stubs(:directory?).with(f).returns false + Kernel.expects(:load).with(f) + end - <at> loader.load_all + <at> loader.load_all - <at> loader.loaded_files.should == %w{/one/dir/bar.rb /one/dir/foo.rb} - end + <at> loader.loaded_files.should == %w{/one/dir/bar.rb /one/dir/foo.rb} + end - it "should not load files in the util subdirectory" do - <at> loader.expects(:search_path).returns %w{/one/dir} + it "should not load files in the util subdirectory" do + <at> loader.expects(:search_path).returns %w{/one/dir} - Dir.expects(:entries).with("/one/dir").returns %w{util} + Dir.expects(:entries).with("/one/dir").returns %w{util} - File.expects(:directory?).with("/one/dir/util").returns true + File.expects(:directory?).with("/one/dir/util").returns true - Dir.expects(:entries).with("/one/dir/util").never + Dir.expects(:entries).with("/one/dir/util").never - <at> loader.load_all - end + <at> loader.load_all + end - it "should not load files in a lib subdirectory" do - <at> loader.expects(:search_path).returns %w{/one/dir} + it "should not load files in a lib subdirectory" do + <at> loader.expects(:search_path).returns %w{/one/dir} - Dir.expects(:entries).with("/one/dir").returns %w{lib} + Dir.expects(:entries).with("/one/dir").returns %w{lib} - File.expects(:directory?).with("/one/dir/lib").returns true + File.expects(:directory?).with("/one/dir/lib").returns true - Dir.expects(:entries).with("/one/dir/lib").never + Dir.expects(:entries).with("/one/dir/lib").never - <at> loader.load_all - end + <at> loader.load_all + end - it "should not load files in '.' or '..'" do - <at> loader.expects(:search_path).returns %w{/one/dir} + it "should not load files in '.' or '..'" do + <at> loader.expects(:search_path).returns %w{/one/dir} - Dir.expects(:entries).with("/one/dir").returns %w{. ..} + Dir.expects(:entries).with("/one/dir").returns %w{. ..} - File.expects(:entries).with("/one/dir/.").never - File.expects(:entries).with("/one/dir/..").never + File.expects(:entries).with("/one/dir/.").never + File.expects(:entries).with("/one/dir/..").never - <at> loader.load_all - end + <at> loader.load_all + end - it "should not raise an exception when a file is unloadable" do - <at> loader.expects(:search_path).returns %w{/one/dir} - Dir.expects(:entries).with("/one/dir").returns %w{a.rb} + it "should not raise an exception when a file is unloadable" do + <at> loader.expects(:search_path).returns %w{/one/dir} + Dir.expects(:entries).with("/one/dir").returns %w{a.rb} - Kernel.expects(:load).with("/one/dir/a.rb").raises(LoadError) - <at> loader.expects(:warn) + Kernel.expects(:load).with("/one/dir/a.rb").raises(LoadError) + <at> loader.expects(:warn) - lambda { <at> loader.load_all }.should_not raise_error - end + lambda { <at> loader.load_all }.should_not raise_error + end - it "should load all facts from the environment" do - Facter.expects(:add).with('one') - Facter.expects(:add).with('two') + it "should load all facts from the environment" do + Facter.expects(:add).with('one') + Facter.expects(:add).with('two') - with_env "facter_one" => "yayness", "facter_two" => "boo" do - <at> loader.load_all - end - end + with_env "facter_one" => "yayness", "facter_two" => "boo" do + <at> loader.load_all + end + end - it "should only load all facts one time" do - <at> loader.expects(:load_env).once - <at> loader.load_all - <at> loader.load_all - end + it "should only load all facts one time" do + <at> loader.expects(:load_env).once + <at> loader.load_all + <at> loader.load_all end + end - it "should load facts on the facter search path only once" do - facterlibdir = File.expand_path(File.dirname(__FILE__) + '../../../fixtures/unit/util/loader') - with_env 'FACTERLIB' => facterlibdir do - Facter::Util::Loader.new.load_all - Facter.value(:nosuchfact).should be_nil - end + it "should load facts on the facter search path only once" do + facterlibdir = File.expand_path(File.dirname(__FILE__) + '../../../fixtures/unit/util/loader') + with_env 'FACTERLIB' => facterlibdir do + Facter::Util::Loader.new.load_all + Facter.value(:nosuchfact).should be_nil end + end end diff --git a/spec/unit/util/macosx_spec.rb b/spec/unit/util/macosx_spec.rb index 44ba460..dab4a9f 100755 --- a/spec/unit/util/macosx_spec.rb +++ b/spec/unit/util/macosx_spec.rb <at> <at> -5,77 +5,77 <at> <at> require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/macosx' describe Facter::Util::Macosx do - it "should be able to retrieve profiler data as xml for a given data field" do - Facter::Util::Resolution.expects(:exec).with("/usr/sbin/system_profiler -xml foo").returns "yay" - Facter::Util::Macosx.profiler_xml("foo").should == "yay" - end - - it "should use PList to convert xml to data structures" do - Plist.expects(:parse_xml).with("foo").returns "bar" + it "should be able to retrieve profiler data as xml for a given data field" do + Facter::Util::Resolution.expects(:exec).with("/usr/sbin/system_profiler -xml foo").returns "yay" + Facter::Util::Macosx.profiler_xml("foo").should == "yay" + end - Facter::Util::Macosx.intern_xml("foo").should == "bar" - end + it "should use PList to convert xml to data structures" do + Plist.expects(:parse_xml).with("foo").returns "bar" - describe "when collecting profiler data" do - it "should return the first value in the '_items' hash in the first value of the results of the system_profiler data, with the '_name' field removed, if the profiler returns data" do - <at> result = [ - '_items' => [ - {'_name' => "foo", "yay" => "bar"} - ] - ] - Facter::Util::Macosx.expects(:profiler_xml).with("foo").returns "eh" - Facter::Util::Macosx.expects(:intern_xml).with("eh").returns <at> result - Facter::Util::Macosx.profiler_data("foo").should == {"yay" => "bar"} - end + Facter::Util::Macosx.intern_xml("foo").should == "bar" + end - it "should return nil if an exception is thrown during parsing of xml" do - Facter::Util::Macosx.expects(:profiler_xml).with("foo").returns "eh" - Facter::Util::Macosx.expects(:intern_xml).with("eh").raises "boo!" - Facter::Util::Macosx.profiler_data("foo").should be_nil - end + describe "when collecting profiler data" do + it "should return the first value in the '_items' hash in the first value of the results of the system_profiler data, with the '_name' field removed, if the profiler returns data" do + <at> result = [ + '_items' => [ + {'_name' => "foo", "yay" => "bar"} + ] + ] + Facter::Util::Macosx.expects(:profiler_xml).with("foo").returns "eh" + Facter::Util::Macosx.expects(:intern_xml).with("eh").returns <at> result + Facter::Util::Macosx.profiler_data("foo").should == {"yay" => "bar"} end - it "should return the profiler data for 'SPHardwareDataType' as the hardware information" do - Facter::Util::Macosx.expects(:profiler_data).with("SPHardwareDataType").returns "eh" - Facter::Util::Macosx.hardware_overview.should == "eh" + it "should return nil if an exception is thrown during parsing of xml" do + Facter::Util::Macosx.expects(:profiler_xml).with("foo").returns "eh" + Facter::Util::Macosx.expects(:intern_xml).with("eh").raises "boo!" + Facter::Util::Macosx.profiler_data("foo").should be_nil end + end - it "should return the profiler data for 'SPSoftwareDataType' as the os information" do - Facter::Util::Macosx.expects(:profiler_data).with("SPSoftwareDataType").returns "eh" - Facter::Util::Macosx.os_overview.should == "eh" - end - - describe "when working out software version" do - - before do - Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productName").returns "Mac OS X" - Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -buildVersion").returns "9J62" - end - - it "should have called sw_vers three times when determining software version" do - Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productVersion").returns "10.5.7" - Facter::Util::Macosx.sw_vers - end - - it "should return a hash with the correct keys when determining software version" do - Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productVersion").returns "10.5.7" - Facter::Util::Macosx.sw_vers.keys.sort.should == ["macosx_productName", - "macosx_buildVersion", - "macosx_productversion_minor", - "macosx_productversion_major", - "macosx_productVersion"].sort - end + it "should return the profiler data for 'SPHardwareDataType' as the hardware information" do + Facter::Util::Macosx.expects(:profiler_data).with("SPHardwareDataType").returns "eh" + Facter::Util::Macosx.hardware_overview.should == "eh" + end + + it "should return the profiler data for 'SPSoftwareDataType' as the os information" do + Facter::Util::Macosx.expects(:profiler_data).with("SPSoftwareDataType").returns "eh" + Facter::Util::Macosx.os_overview.should == "eh" + end + + describe "when working out software version" do - it "should split a product version of 'x.y.z' into separate hash entries correctly" do - Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productVersion").returns "1.2.3" - sw_vers = Facter::Util::Macosx.sw_vers - sw_vers["macosx_productversion_major"].should == "1.2" - sw_vers["macosx_productversion_minor"].should == "3" - end + before do + Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productName").returns "Mac OS X" + Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -buildVersion").returns "9J62" + end - it "should treat a product version of 'x.y' as 'x.y.0" do - Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productVersion").returns "2.3" - Facter::Util::Macosx.sw_vers["macosx_productversion_minor"].should == "0" - end + it "should have called sw_vers three times when determining software version" do + Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productVersion").returns "10.5.7" + Facter::Util::Macosx.sw_vers + end + + it "should return a hash with the correct keys when determining software version" do + Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productVersion").returns "10.5.7" + Facter::Util::Macosx.sw_vers.keys.sort.should == ["macosx_productName", + "macosx_buildVersion", + "macosx_productversion_minor", + "macosx_productversion_major", + "macosx_productVersion"].sort + end + + it "should split a product version of 'x.y.z' into separate hash entries correctly" do + Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productVersion").returns "1.2.3" + sw_vers = Facter::Util::Macosx.sw_vers + sw_vers["macosx_productversion_major"].should == "1.2" + sw_vers["macosx_productversion_minor"].should == "3" + end + + it "should treat a product version of 'x.y' as 'x.y.0" do + Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productVersion").returns "2.3" + Facter::Util::Macosx.sw_vers["macosx_productversion_minor"].should == "0" end + end end diff --git a/spec/unit/util/manufacturer_spec.rb b/spec/unit/util/manufacturer_spec.rb index c738811..ed248ca 100644 --- a/spec/unit/util/manufacturer_spec.rb +++ b/spec/unit/util/manufacturer_spec.rb <at> <at> -3,52 +3,52 <at> <at> require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/manufacturer' describe Facter::Manufacturer do - before :each do - Facter.clear - end - - it "should return the system DMI table" do - Facter::Manufacturer.should respond_to(:get_dmi_table) - end - - it "should return nil on non-supported operating systems" do - Facter.stubs(:value).with(:kernel).returns("SomeThing") - Facter::Manufacturer.get_dmi_table().should be_nil - end - - it "should parse prtdiag output" do - Facter::Util::Resolution.stubs(:exec).returns("System Configuration: Sun Microsystems sun4u Sun SPARC Enterprise M3000 Server") - Facter::Manufacturer.prtdiag_sparc_find_system_info() - Facter.value(:manufacturer).should == "Sun Microsystems" - Facter.value(:productname).should == "Sun SPARC Enterprise M3000 Server" - end - - it "should strip white space on dmi output with spaces" do - sample_output_file = File.dirname(__FILE__) + "/../data/linux_dmidecode_with_spaces" - dmidecode_output = File.new(sample_output_file).read() - Facter::Manufacturer.expects(:get_dmi_table).returns(dmidecode_output) - Facter.fact(:kernel).stubs(:value).returns("Linux") - - query = { '[Ss]ystem [Ii]nformation' => [ { 'Product(?: Name)?:' => 'productname' } ] } - - Facter::Manufacturer.dmi_find_system_info(query) - Facter.value(:productname).should == "MS-6754" - end - - it "should handle output from smbios when run under sunos" do - sample_output_file = File.dirname(__FILE__) + "/../data/opensolaris_smbios" - smbios_output = File.new(sample_output_file).read() - Facter::Manufacturer.expects(:get_dmi_table).returns(smbios_output) - Facter.fact(:kernel).stubs(:value).returns("SunOS") - - query = { 'BIOS information' => [ { 'Release Date:' => 'reldate' } ] } - - Facter::Manufacturer.dmi_find_system_info(query) - Facter.value(:reldate).should == "12/01/2006" - end - - it "should not split on dmi keys containing the string Handle" do - dmidecode_output = <<-eos + before :each do + Facter.clear + end + + it "should return the system DMI table" do + Facter::Manufacturer.should respond_to(:get_dmi_table) + end + + it "should return nil on non-supported operating systems" do + Facter.stubs(:value).with(:kernel).returns("SomeThing") + Facter::Manufacturer.get_dmi_table().should be_nil + end + + it "should parse prtdiag output" do + Facter::Util::Resolution.stubs(:exec).returns("System Configuration: Sun Microsystems sun4u Sun SPARC Enterprise M3000 Server") + Facter::Manufacturer.prtdiag_sparc_find_system_info() + Facter.value(:manufacturer).should == "Sun Microsystems" + Facter.value(:productname).should == "Sun SPARC Enterprise M3000 Server" + end + + it "should strip white space on dmi output with spaces" do + sample_output_file = File.dirname(__FILE__) + "/../data/linux_dmidecode_with_spaces" + dmidecode_output = File.new(sample_output_file).read() + Facter::Manufacturer.expects(:get_dmi_table).returns(dmidecode_output) + Facter.fact(:kernel).stubs(:value).returns("Linux") + + query = { '[Ss]ystem [Ii]nformation' => [ { 'Product(?: Name)?:' => 'productname' } ] } + + Facter::Manufacturer.dmi_find_system_info(query) + Facter.value(:productname).should == "MS-6754" + end + + it "should handle output from smbios when run under sunos" do + sample_output_file = File.dirname(__FILE__) + "/../data/opensolaris_smbios" + smbios_output = File.new(sample_output_file).read() + Facter::Manufacturer.expects(:get_dmi_table).returns(smbios_output) + Facter.fact(:kernel).stubs(:value).returns("SunOS") + + query = { 'BIOS information' => [ { 'Release Date:' => 'reldate' } ] } + + Facter::Manufacturer.dmi_find_system_info(query) + Facter.value(:reldate).should == "12/01/2006" + end + + it "should not split on dmi keys containing the string Handle" do + dmidecode_output = <<-eos Handle 0x1000, DMI type 16, 15 bytes Physical Memory Array Location: System Board Or Motherboard <at> <at> -61,16 +61,16 <at> <at> Physical Memory Array Handle 0x001F DMI type 127, 4 bytes. End Of Table - eos - Facter::Manufacturer.expects(:get_dmi_table).returns(dmidecode_output) - Facter.fact(:kernel).stubs(:value).returns("Linux") - query = { 'Physical Memory Array' => [ { 'Number Of Devices:' => 'ramslots'}]} - Facter::Manufacturer.dmi_find_system_info(query) - Facter.value(:ramslots).should == "123" - end - - it "should match the key in the defined section and not the first one found" do - dmidecode_output = <<-eos + eos + Facter::Manufacturer.expects(:get_dmi_table).returns(dmidecode_output) + Facter.fact(:kernel).stubs(:value).returns("Linux") + query = { 'Physical Memory Array' => [ { 'Number Of Devices:' => 'ramslots'}]} + Facter::Manufacturer.dmi_find_system_info(query) + Facter.value(:ramslots).should == "123" + end + + it "should match the key in the defined section and not the first one found" do + dmidecode_output = <<-eos Handle 0x000C, DMI type 7, 19 bytes Cache Information Socket Designation: Internal L2 Cache <at> <at> -99,55 +99,55 <at> <at> Physical Memory Array Handle 0x001F DMI type 127, 4 bytes. End Of Table - eos - Facter::Manufacturer.expects(:get_dmi_table).returns(dmidecode_output) - Facter.fact(:kernel).stubs(:value).returns("Linux") - query = { 'Physical Memory Array' => [ { 'Location:' => 'ramlocation'}]} - Facter::Manufacturer.dmi_find_system_info(query) - Facter.value(:ramlocation).should == "System Board Or Motherboard" - end - - def find_product_name(os) - output_file = case os - when "FreeBSD" then File.dirname(__FILE__) + "/../data/freebsd_dmidecode" - when "SunOS" then File.dirname(__FILE__) + "/../data/opensolaris_smbios" - end - - output = File.new(output_file).read() - query = { '[Ss]ystem [Ii]nformation' => [ { 'Product(?: Name)?:' => "product_name_#{os}" } ] } - - Facter.fact(:kernel).stubs(:value).returns(os) - Facter::Manufacturer.expects(:get_dmi_table).returns(output) - - Facter::Manufacturer.dmi_find_system_info(query) - - return Facter.value("product_name_#{os}") - end - - it "should return the same result with smbios than with dmidecode" do - find_product_name("FreeBSD").should_not == nil - find_product_name("FreeBSD").should == find_product_name("SunOS") - end - - it "should find information on Windows" do - Facter.fact(:kernel).stubs(:value).returns("windows") - require 'facter/util/wmi' - - bios = stubs 'bios' - bios.stubs(:Manufacturer).returns("Phoenix Technologies LTD") - bios.stubs(:Serialnumber).returns("56 4d 40 2b 4d 81 94 d6-e6 c5 56 a4 56 0c 9e 9f") - - product = stubs 'product' - product.stubs(:Name).returns("VMware Virtual Platform") - - wmi = stubs 'wmi' - wmi.stubs(:ExecQuery).with("select * from Win32_Bios").returns([bios]) - wmi.stubs(:ExecQuery).with("select * from Win32_Bios").returns([bios]) - wmi.stubs(:ExecQuery).with("select * from Win32_ComputerSystemProduct").returns([product]) - - Facter::Util::WMI.stubs(:connect).returns(wmi) - Facter.value(:manufacturer).should == "Phoenix Technologies LTD" - Facter.value(:serialnumber).should == "56 4d 40 2b 4d 81 94 d6-e6 c5 56 a4 56 0c 9e 9f" - Facter.value(:productname).should == "VMware Virtual Platform" - end + eos + Facter::Manufacturer.expects(:get_dmi_table).returns(dmidecode_output) + Facter.fact(:kernel).stubs(:value).returns("Linux") + query = { 'Physical Memory Array' => [ { 'Location:' => 'ramlocation'}]} + Facter::Manufacturer.dmi_find_system_info(query) + Facter.value(:ramlocation).should == "System Board Or Motherboard" + end + + def find_product_name(os) + output_file = case os + when "FreeBSD" then File.dirname(__FILE__) + "/../data/freebsd_dmidecode" + when "SunOS" then File.dirname(__FILE__) + "/../data/opensolaris_smbios" + end + + output = File.new(output_file).read() + query = { '[Ss]ystem [Ii]nformation' => [ { 'Product(?: Name)?:' => "product_name_#{os}" } ] } + + Facter.fact(:kernel).stubs(:value).returns(os) + Facter::Manufacturer.expects(:get_dmi_table).returns(output) + + Facter::Manufacturer.dmi_find_system_info(query) + + return Facter.value("product_name_#{os}") + end + + it "should return the same result with smbios than with dmidecode" do + find_product_name("FreeBSD").should_not == nil + find_product_name("FreeBSD").should == find_product_name("SunOS") + end + + it "should find information on Windows" do + Facter.fact(:kernel).stubs(:value).returns("windows") + require 'facter/util/wmi' + + bios = stubs 'bios' + bios.stubs(:Manufacturer).returns("Phoenix Technologies LTD") + bios.stubs(:Serialnumber).returns("56 4d 40 2b 4d 81 94 d6-e6 c5 56 a4 56 0c 9e 9f") + + product = stubs 'product' + product.stubs(:Name).returns("VMware Virtual Platform") + + wmi = stubs 'wmi' + wmi.stubs(:ExecQuery).with("select * from Win32_Bios").returns([bios]) + wmi.stubs(:ExecQuery).with("select * from Win32_Bios").returns([bios]) + wmi.stubs(:ExecQuery).with("select * from Win32_ComputerSystemProduct").returns([product]) + + Facter::Util::WMI.stubs(:connect).returns(wmi) + Facter.value(:manufacturer).should == "Phoenix Technologies LTD" + Facter.value(:serialnumber).should == "56 4d 40 2b 4d 81 94 d6-e6 c5 56 a4 56 0c 9e 9f" + Facter.value(:productname).should == "VMware Virtual Platform" + end end diff --git a/spec/unit/util/resolution_spec.rb b/spec/unit/util/resolution_spec.rb index fca56d2..005ccfd 100755 --- a/spec/unit/util/resolution_spec.rb +++ b/spec/unit/util/resolution_spec.rb <at> <at> -5,295 +5,295 <at> <at> require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/resolution' describe Facter::Util::Resolution do - it "should require a name" do - lambda { Facter::Util::Resolution.new }.should raise_error(ArgumentError) + it "should require a name" do + lambda { Facter::Util::Resolution.new }.should raise_error(ArgumentError) + end + + it "should have a name" do + Facter::Util::Resolution.new("yay").name.should == "yay" + end + + it "should have a method for setting the weight" do + Facter::Util::Resolution.new("yay").should respond_to(:has_weight) + end + + it "should have a method for setting the code" do + Facter::Util::Resolution.new("yay").should respond_to(:setcode) + end + + it "should support a timeout value" do + Facter::Util::Resolution.new("yay").should respond_to(:timeout=) + end + + it "should default to a timeout of 0 seconds" do + Facter::Util::Resolution.new("yay").limit.should == 0 + end + + it "should default to nil for code" do + Facter::Util::Resolution.new("yay").code.should be_nil + end + + it "should default to nil for interpreter" do + Facter.expects(:warnonce).with("The 'Facter::Util::Resolution.interpreter' method is deprecated and will be removed in a future version.") + Facter::Util::Resolution.new("yay").interpreter.should be_nil + end + + it "should provide a 'limit' method that returns the timeout" do + res = Facter::Util::Resolution.new("yay") + res.timeout = "testing" + res.limit.should == "testing" + end + + describe "when setting the code" do + before do + Facter.stubs(:warnonce) + <at> resolve = Facter::Util::Resolution.new("yay") end - it "should have a name" do - Facter::Util::Resolution.new("yay").name.should == "yay" + it "should deprecate the interpreter argument to 'setcode'" do + Facter.expects(:warnonce).with("The interpreter parameter to 'setcode' is deprecated and will be removed in a future version.") + <at> resolve.setcode "foo", "bar" + <at> resolve.interpreter.should == "bar" end - it "should have a method for setting the weight" do - Facter::Util::Resolution.new("yay").should respond_to(:has_weight) + it "should deprecate the interpreter= method" do + Facter.expects(:warnonce).with("The 'Facter::Util::Resolution.interpreter=' method is deprecated and will be removed in a future version.") + <at> resolve.interpreter = "baz" + <at> resolve.interpreter.should == "baz" end - it "should have a method for setting the code" do - Facter::Util::Resolution.new("yay").should respond_to(:setcode) + it "should deprecate the interpreter method" do + Facter.expects(:warnonce).with("The 'Facter::Util::Resolution.interpreter' method is deprecated and will be removed in a future version.") + <at> resolve.interpreter end - it "should support a timeout value" do - Facter::Util::Resolution.new("yay").should respond_to(:timeout=) + it "should set the code to any provided string" do + <at> resolve.setcode "foo" + <at> resolve.code.should == "foo" end - it "should default to a timeout of 0 seconds" do - Facter::Util::Resolution.new("yay").limit.should == 0 + it "should set the code to any provided block" do + block = lambda { } + <at> resolve.setcode(&block) + <at> resolve.code.should equal(block) end - it "should default to nil for code" do - Facter::Util::Resolution.new("yay").code.should be_nil + it "should prefer the string over a block" do + <at> resolve.setcode("foo") { } + <at> resolve.code.should == "foo" end - it "should default to nil for interpreter" do - Facter.expects(:warnonce).with("The 'Facter::Util::Resolution.interpreter' method is deprecated and will be removed in a future version.") - Facter::Util::Resolution.new("yay").interpreter.should be_nil + it "should fail if neither a string nor block has been provided" do + lambda { <at> resolve.setcode }.should raise_error(ArgumentError) end + end - it "should provide a 'limit' method that returns the timeout" do - res = Facter::Util::Resolution.new("yay") - res.timeout = "testing" - res.limit.should == "testing" - end - - describe "when setting the code" do - before do - Facter.stubs(:warnonce) - <at> resolve = Facter::Util::Resolution.new("yay") - end - - it "should deprecate the interpreter argument to 'setcode'" do - Facter.expects(:warnonce).with("The interpreter parameter to 'setcode' is deprecated and will be removed in a future version.") - <at> resolve.setcode "foo", "bar" - <at> resolve.interpreter.should == "bar" - end + it "should be able to return a value" do + Facter::Util::Resolution.new("yay").should respond_to(:value) + end - it "should deprecate the interpreter= method" do - Facter.expects(:warnonce).with("The 'Facter::Util::Resolution.interpreter=' method is deprecated and will be removed in a future version.") - <at> resolve.interpreter = "baz" - <at> resolve.interpreter.should == "baz" - end + describe "when returning the value" do + before do + <at> resolve = Facter::Util::Resolution.new("yay") + end - it "should deprecate the interpreter method" do - Facter.expects(:warnonce).with("The 'Facter::Util::Resolution.interpreter' method is deprecated and will be removed in a future version.") - <at> resolve.interpreter - end + describe "and setcode has not been called" do + it "should return nil" do + Facter::Util::Resolution.expects(:exec).with(nil, nil).never + <at> resolve.value.should be_nil + end + end - it "should set the code to any provided string" do - <at> resolve.setcode "foo" - <at> resolve.code.should == "foo" + describe "and the code is a string" do + describe "on windows" do + before do + Facter::Util::Resolution::WINDOWS = true end - it "should set the code to any provided block" do - block = lambda { } - <at> resolve.setcode(&block) - <at> resolve.code.should equal(block) - end + it "should return the result of executing the code" do + <at> resolve.setcode "/bin/foo" + Facter::Util::Resolution.expects(:exec).once.with("/bin/foo").returns "yup" - it "should prefer the string over a block" do - <at> resolve.setcode("foo") { } - <at> resolve.code.should == "foo" + <at> resolve.value.should == "yup" end - it "should fail if neither a string nor block has been provided" do - lambda { <at> resolve.setcode }.should raise_error(ArgumentError) + it "should return nil if the value is an empty string" do + <at> resolve.setcode "/bin/foo" + Facter::Util::Resolution.expects(:exec).once.returns "" + <at> resolve.value.should be_nil end - end - - it "should be able to return a value" do - Facter::Util::Resolution.new("yay").should respond_to(:value) - end + end - describe "when returning the value" do + describe "on non-windows systems" do before do - <at> resolve = Facter::Util::Resolution.new("yay") + Facter::Util::Resolution::WINDOWS = false end - describe "and setcode has not been called" do - it "should return nil" do - Facter::Util::Resolution.expects(:exec).with(nil, nil).never - <at> resolve.value.should be_nil - end - end + it "should return the result of executing the code" do + <at> resolve.setcode "/bin/foo" + Facter::Util::Resolution.expects(:exec).once.with("/bin/foo").returns "yup" - describe "and the code is a string" do - describe "on windows" do - before do - Facter::Util::Resolution::WINDOWS = true - end - - it "should return the result of executing the code" do - <at> resolve.setcode "/bin/foo" - Facter::Util::Resolution.expects(:exec).once.with("/bin/foo").returns "yup" - - <at> resolve.value.should == "yup" - end - - it "should return nil if the value is an empty string" do - <at> resolve.setcode "/bin/foo" - Facter::Util::Resolution.expects(:exec).once.returns "" - <at> resolve.value.should be_nil - end - end - - describe "on non-windows systems" do - before do - Facter::Util::Resolution::WINDOWS = false - end - - it "should return the result of executing the code" do - <at> resolve.setcode "/bin/foo" - Facter::Util::Resolution.expects(:exec).once.with("/bin/foo").returns "yup" - - <at> resolve.value.should == "yup" - end - - it "should return nil if the value is an empty string" do - <at> resolve.setcode "/bin/foo" - Facter::Util::Resolution.expects(:exec).once.returns "" - <at> resolve.value.should be_nil - end - end + <at> resolve.value.should == "yup" end - describe "and the code is a block" do - it "should warn but not fail if the code fails" do - <at> resolve.setcode { raise "feh" } - <at> resolve.expects(:warn) - <at> resolve.value.should be_nil - end - - it "should return the value returned by the block" do - <at> resolve.setcode { "yayness" } - <at> resolve.value.should == "yayness" - end - - it "should return nil if the value is an empty string" do - <at> resolve.setcode { "" } - <at> resolve.value.should be_nil - end - - it "should return nil if the value is an empty block" do - <at> resolve.setcode { "" } - <at> resolve.value.should be_nil - end - - it "should use its limit method to determine the timeout, to avoid conflict when a 'timeout' method exists for some other reason" do - <at> resolve.expects(:timeout).never - <at> resolve.expects(:limit).returns "foo" - Timeout.expects(:timeout).with("foo") - - <at> resolve.setcode { sleep 2; "raise This is a test"} - <at> resolve.value - end - - it "should timeout after the provided timeout" do - <at> resolve.expects(:warn) - <at> resolve.timeout = 0.1 - <at> resolve.setcode { sleep 2; raise "This is a test" } - Thread.expects(:new).yields - - <at> resolve.value.should be_nil - end - - it "should waitall to avoid zombies if the timeout is exceeded" do - <at> resolve.stubs(:warn) - <at> resolve.timeout = 0.1 - <at> resolve.setcode { sleep 2; raise "This is a test" } - - Thread.expects(:new).yields - Process.expects(:waitall) - - <at> resolve.value - end + it "should return nil if the value is an empty string" do + <at> resolve.setcode "/bin/foo" + Facter::Util::Resolution.expects(:exec).once.returns "" + <at> resolve.value.should be_nil end + end end - it "should return its value when converted to a string" do - <at> resolve = Facter::Util::Resolution.new("yay") - <at> resolve.expects(:value).returns "myval" - <at> resolve.to_s.should == "myval" + describe "and the code is a block" do + it "should warn but not fail if the code fails" do + <at> resolve.setcode { raise "feh" } + <at> resolve.expects(:warn) + <at> resolve.value.should be_nil + end + + it "should return the value returned by the block" do + <at> resolve.setcode { "yayness" } + <at> resolve.value.should == "yayness" + end + + it "should return nil if the value is an empty string" do + <at> resolve.setcode { "" } + <at> resolve.value.should be_nil + end + + it "should return nil if the value is an empty block" do + <at> resolve.setcode { "" } + <at> resolve.value.should be_nil + end + + it "should use its limit method to determine the timeout, to avoid conflict when a 'timeout' method exists for some other reason" do + <at> resolve.expects(:timeout).never + <at> resolve.expects(:limit).returns "foo" + Timeout.expects(:timeout).with("foo") + + <at> resolve.setcode { sleep 2; "raise This is a test"} + <at> resolve.value + end + + it "should timeout after the provided timeout" do + <at> resolve.expects(:warn) + <at> resolve.timeout = 0.1 + <at> resolve.setcode { sleep 2; raise "This is a test" } + Thread.expects(:new).yields + + <at> resolve.value.should be_nil + end + + it "should waitall to avoid zombies if the timeout is exceeded" do + <at> resolve.stubs(:warn) + <at> resolve.timeout = 0.1 + <at> resolve.setcode { sleep 2; raise "This is a test" } + + Thread.expects(:new).yields + Process.expects(:waitall) + + <at> resolve.value + end end - - it "should allow the adding of confines" do - Facter::Util::Resolution.new("yay").should respond_to(:confine) + end + + it "should return its value when converted to a string" do + <at> resolve = Facter::Util::Resolution.new("yay") + <at> resolve.expects(:value).returns "myval" + <at> resolve.to_s.should == "myval" + end + + it "should allow the adding of confines" do + Facter::Util::Resolution.new("yay").should respond_to(:confine) + end + + it "should provide a method for returning the number of confines" do + <at> resolve = Facter::Util::Resolution.new("yay") + <at> resolve.confine "one" => "foo", "two" => "fee" + <at> resolve.weight.should == 2 + end + + it "should return 0 confines when no confines have been added" do + Facter::Util::Resolution.new("yay").weight.should == 0 + end + + it "should provide a way to set the weight" do + <at> resolve = Facter::Util::Resolution.new("yay") + <at> resolve.has_weight(45) + <at> resolve.weight.should == 45 + end + + it "should allow the weight to override the number of confines" do + <at> resolve = Facter::Util::Resolution.new("yay") + <at> resolve.confine "one" => "foo", "two" => "fee" + <at> resolve.weight.should == 2 + <at> resolve.has_weight(45) + <at> resolve.weight.should == 45 + end + + it "should have a method for determining if it is suitable" do + Facter::Util::Resolution.new("yay").should respond_to(:suitable?) + end + + describe "when adding confines" do + before do + <at> resolve = Facter::Util::Resolution.new("yay") end - it "should provide a method for returning the number of confines" do - <at> resolve = Facter::Util::Resolution.new("yay") - <at> resolve.confine "one" => "foo", "two" => "fee" - <at> resolve.weight.should == 2 + it "should accept a hash of fact names and values" do + lambda { <at> resolve.confine :one => "two" }.should_not raise_error end - it "should return 0 confines when no confines have been added" do - Facter::Util::Resolution.new("yay").weight.should == 0 - end + it "should create a Util::Confine instance for every argument in the provided hash" do + Facter::Util::Confine.expects(:new).with("one", "foo") + Facter::Util::Confine.expects(:new).with("two", "fee") - it "should provide a way to set the weight" do - <at> resolve = Facter::Util::Resolution.new("yay") - <at> resolve.has_weight(45) - <at> resolve.weight.should == 45 + <at> resolve.confine "one" => "foo", "two" => "fee" end - it "should allow the weight to override the number of confines" do - <at> resolve = Facter::Util::Resolution.new("yay") - <at> resolve.confine "one" => "foo", "two" => "fee" - <at> resolve.weight.should == 2 - <at> resolve.has_weight(45) - <at> resolve.weight.should == 45 - end + end - it "should have a method for determining if it is suitable" do - Facter::Util::Resolution.new("yay").should respond_to(:suitable?) + describe "when determining suitability" do + before do + <at> resolve = Facter::Util::Resolution.new("yay") end - describe "when adding confines" do - before do - <at> resolve = Facter::Util::Resolution.new("yay") - end - - it "should accept a hash of fact names and values" do - lambda { <at> resolve.confine :one => "two" }.should_not raise_error - end - - it "should create a Util::Confine instance for every argument in the provided hash" do - Facter::Util::Confine.expects(:new).with("one", "foo") - Facter::Util::Confine.expects(:new).with("two", "fee") - - <at> resolve.confine "one" => "foo", "two" => "fee" - end - + it "should always be suitable if no confines have been added" do + <at> resolve.should be_suitable end - describe "when determining suitability" do - before do - <at> resolve = Facter::Util::Resolution.new("yay") - end + it "should be unsuitable if any provided confines return false" do + confine1 = mock 'confine1', :true? => true + confine2 = mock 'confine2', :true? => false + Facter::Util::Confine.expects(:new).times(2).returns(confine1).then.returns(confine2) + <at> resolve.confine :one => :two, :three => :four - it "should always be suitable if no confines have been added" do - <at> resolve.should be_suitable - end - - it "should be unsuitable if any provided confines return false" do - confine1 = mock 'confine1', :true? => true - confine2 = mock 'confine2', :true? => false - Facter::Util::Confine.expects(:new).times(2).returns(confine1).then.returns(confine2) - <at> resolve.confine :one => :two, :three => :four - - <at> resolve.should_not be_suitable - end + <at> resolve.should_not be_suitable + end - it "should be suitable if all provided confines return true" do - confine1 = mock 'confine1', :true? => true - confine2 = mock 'confine2', :true? => true - Facter::Util::Confine.expects(:new).times(2).returns(confine1).then.returns(confine2) - <at> resolve.confine :one => :two, :three => :four + it "should be suitable if all provided confines return true" do + confine1 = mock 'confine1', :true? => true + confine2 = mock 'confine2', :true? => true + Facter::Util::Confine.expects(:new).times(2).returns(confine1).then.returns(confine2) + <at> resolve.confine :one => :two, :three => :four - <at> resolve.should be_suitable - end + <at> resolve.should be_suitable end + end - it "should have a class method for executing code" do - Facter::Util::Resolution.should respond_to(:exec) - end + it "should have a class method for executing code" do + Facter::Util::Resolution.should respond_to(:exec) + end - # It's not possible, AFAICT, to mock %x{}, so I can't really test this bit. - describe "when executing code" do - it "should deprecate the interpreter parameter" do - Facter.expects(:warnonce).with("The interpreter parameter to 'exec' is deprecated and will be removed in a future version.") - Facter::Util::Resolution.exec("/something", "/bin/perl") - end + # It's not possible, AFAICT, to mock %x{}, so I can't really test this bit. + describe "when executing code" do + it "should deprecate the interpreter parameter" do + Facter.expects(:warnonce).with("The interpreter parameter to 'exec' is deprecated and will be removed in a future version.") + Facter::Util::Resolution.exec("/something", "/bin/perl") + end - it "should execute the binary" do - Facter::Util::Resolution.exec("echo foo").should == "foo" - end + it "should execute the binary" do + Facter::Util::Resolution.exec("echo foo").should == "foo" end + end end diff --git a/spec/unit/util/virtual_spec.rb b/spec/unit/util/virtual_spec.rb index 82eb71c..52d6568 100644 --- a/spec/unit/util/virtual_spec.rb +++ b/spec/unit/util/virtual_spec.rb <at> <at> -4,172 +4,172 <at> <at> require 'facter/util/virtual' describe Facter::Util::Virtual do - after do - Facter.clear - end - it "should detect openvz" do - FileTest.stubs(:directory?).with("/proc/vz").returns(true) - Dir.stubs(:glob).with("/proc/vz/*").returns(['vzquota']) - Facter::Util::Virtual.should be_openvz - end - - it "should not detect openvz when /proc/lve/list is present" do - FileTest.stubs(:file?).with("/proc/lve/list").returns(true) - Facter::Util::Virtual.should_not be_openvz - end - - it "should not detect openvz when /proc/vz/ is empty" do - FileTest.stubs(:file?).with("/proc/lve/list").returns(false) - FileTest.stubs(:directory?).with("/proc/vz").returns(true) - Dir.stubs(:glob).with("/proc/vz/*").returns([]) - Facter::Util::Virtual.should_not be_openvz - end - - it "should identify openvzhn when /proc/self/status has envID of 0" do - Facter::Util::Virtual.stubs(:openvz?).returns(true) + after do + Facter.clear + end + it "should detect openvz" do + FileTest.stubs(:directory?).with("/proc/vz").returns(true) + Dir.stubs(:glob).with("/proc/vz/*").returns(['vzquota']) + Facter::Util::Virtual.should be_openvz + end + + it "should not detect openvz when /proc/lve/list is present" do + FileTest.stubs(:file?).with("/proc/lve/list").returns(true) + Facter::Util::Virtual.should_not be_openvz + end + + it "should not detect openvz when /proc/vz/ is empty" do + FileTest.stubs(:file?).with("/proc/lve/list").returns(false) + FileTest.stubs(:directory?).with("/proc/vz").returns(true) + Dir.stubs(:glob).with("/proc/vz/*").returns([]) + Facter::Util::Virtual.should_not be_openvz + end + + it "should identify openvzhn when /proc/self/status has envID of 0" do + Facter::Util::Virtual.stubs(:openvz?).returns(true) + FileTest.stubs(:exists?).with("/proc/self/status").returns(true) + Facter::Util::Resolution.stubs(:exec).with('grep "envID" /proc/self/status').returns("envID: 0") + Facter::Util::Virtual.openvz_type().should == "openvzhn" + end + + it "should identify openvzve when /proc/self/status has envID of 0" do + Facter::Util::Virtual.stubs(:openvz?).returns(true) + FileTest.stubs(:exists?).with('/proc/self/status').returns(true) + Facter::Util::Resolution.stubs(:exec).with('grep "envID" /proc/self/status').returns("envID: 666") + Facter::Util::Virtual.openvz_type().should == "openvzve" + end + + it "should not attempt to identify openvz when /proc/self/status has no envID" do + Facter::Util::Virtual.stubs(:openvz?).returns(true) + FileTest.stubs(:exists?).with('/proc/self/status').returns(true) + Facter::Util::Resolution.stubs(:exec).with('grep "envID" /proc/self/status').returns("") + Facter::Util::Virtual.openvz_type().should be_nil + end + + it "should identify Solaris zones when non-global zone" do + Facter::Util::Resolution.stubs(:exec).with("/sbin/zonename").returns("somezone") + Facter::Util::Virtual.should be_zone + end + + it "should not identify Solaris zones when global zone" do + Facter::Util::Resolution.stubs(:exec).with("/sbin/zonename").returns("global") + Facter::Util::Virtual.should_not be_zone + end + + it "should not detect vserver if no self status" do + FileTest.stubs(:exists?).with("/proc/self/status").returns(false) + Facter::Util::Virtual.should_not be_vserver + end + + it "should detect vserver when vxid present in process status" do + FileTest.stubs(:exists?).with("/proc/self/status").returns(true) + File.stubs(:read).with("/proc/self/status").returns("VxID: 42\n") + Facter::Util::Virtual.should be_vserver + end + + it "should detect vserver when s_context present in process status" do + FileTest.stubs(:exists?).with("/proc/self/status").returns(true) + File.stubs(:read).with("/proc/self/status").returns("s_context: 42\n") + Facter::Util::Virtual.should be_vserver + end + + it "should not detect vserver when vserver flags not present in process status" do + FileTest.stubs(:exists?).with("/proc/self/status").returns(true) + File.stubs(:read).with("/proc/self/status").returns("wibble: 42\n") + Facter::Util::Virtual.should_not be_vserver + end + + fixture_path = File.join(SPECDIR, 'fixtures', 'virtual', 'proc_self_status') + + test_cases = [ + [File.join(fixture_path, 'vserver_2_1', 'guest'), true, 'vserver 2.1 guest'], + [File.join(fixture_path, 'vserver_2_1', 'host'), true, 'vserver 2.1 host'], + [File.join(fixture_path, 'vserver_2_3', 'guest'), true, 'vserver 2.3 guest'], + [File.join(fixture_path, 'vserver_2_3', 'host'), true, 'vserver 2.3 host'] + ] + + test_cases.each do |status_file, expected, description| + describe "with /proc/self/status from #{description}" do + it "should detect vserver as #{expected.inspect}" do + status = File.read(status_file) FileTest.stubs(:exists?).with("/proc/self/status").returns(true) - Facter::Util::Resolution.stubs(:exec).with('grep "envID" /proc/self/status').returns("envID: 0") - Facter::Util::Virtual.openvz_type().should == "openvzhn" - end - - it "should identify openvzve when /proc/self/status has envID of 0" do - Facter::Util::Virtual.stubs(:openvz?).returns(true) - FileTest.stubs(:exists?).with('/proc/self/status').returns(true) - Facter::Util::Resolution.stubs(:exec).with('grep "envID" /proc/self/status').returns("envID: 666") - Facter::Util::Virtual.openvz_type().should == "openvzve" - end - - it "should not attempt to identify openvz when /proc/self/status has no envID" do - Facter::Util::Virtual.stubs(:openvz?).returns(true) - FileTest.stubs(:exists?).with('/proc/self/status').returns(true) - Facter::Util::Resolution.stubs(:exec).with('grep "envID" /proc/self/status').returns("") - Facter::Util::Virtual.openvz_type().should be_nil - end - - it "should identify Solaris zones when non-global zone" do - Facter::Util::Resolution.stubs(:exec).with("/sbin/zonename").returns("somezone") - Facter::Util::Virtual.should be_zone - end - - it "should not identify Solaris zones when global zone" do - Facter::Util::Resolution.stubs(:exec).with("/sbin/zonename").returns("global") - Facter::Util::Virtual.should_not be_zone - end - - it "should not detect vserver if no self status" do - FileTest.stubs(:exists?).with("/proc/self/status").returns(false) - Facter::Util::Virtual.should_not be_vserver - end - - it "should detect vserver when vxid present in process status" do - FileTest.stubs(:exists?).with("/proc/self/status").returns(true) - File.stubs(:read).with("/proc/self/status").returns("VxID: 42\n") - Facter::Util::Virtual.should be_vserver - end - - it "should detect vserver when s_context present in process status" do - FileTest.stubs(:exists?).with("/proc/self/status").returns(true) - File.stubs(:read).with("/proc/self/status").returns("s_context: 42\n") - Facter::Util::Virtual.should be_vserver - end - - it "should not detect vserver when vserver flags not present in process status" do - FileTest.stubs(:exists?).with("/proc/self/status").returns(true) - File.stubs(:read).with("/proc/self/status").returns("wibble: 42\n") - Facter::Util::Virtual.should_not be_vserver - end - - fixture_path = File.join(SPECDIR, 'fixtures', 'virtual', 'proc_self_status') - - test_cases = [ - [File.join(fixture_path, 'vserver_2_1', 'guest'), true, 'vserver 2.1 guest'], - [File.join(fixture_path, 'vserver_2_1', 'host'), true, 'vserver 2.1 host'], - [File.join(fixture_path, 'vserver_2_3', 'guest'), true, 'vserver 2.3 guest'], - [File.join(fixture_path, 'vserver_2_3', 'host'), true, 'vserver 2.3 host'] - ] - - test_cases.each do |status_file, expected, description| - describe "with /proc/self/status from #{description}" do - it "should detect vserver as #{expected.inspect}" do - status = File.read(status_file) - FileTest.stubs(:exists?).with("/proc/self/status").returns(true) - File.stubs(:read).with("/proc/self/status").returns(status) - Facter::Util::Virtual.vserver?.should == expected - end - end - end - - it "should identify vserver_host when /proc/virtual exists" do - Facter::Util::Virtual.expects(:vserver?).returns(true) - FileTest.stubs(:exists?).with("/proc/virtual").returns(true) - Facter::Util::Virtual.vserver_type().should == "vserver_host" - end - - it "should identify vserver_type as vserver when /proc/virtual does not exist" do - Facter::Util::Virtual.expects(:vserver?).returns(true) - FileTest.stubs(:exists?).with("/proc/virtual").returns(false) - Facter::Util::Virtual.vserver_type().should == "vserver" - end - - it "should detect xen when /proc/sys/xen exists" do - FileTest.expects(:exists?).with("/proc/sys/xen").returns(true) - Facter::Util::Virtual.should be_xen - end - - it "should detect xen when /sys/bus/xen exists" do - FileTest.expects(:exists?).with("/proc/sys/xen").returns(false) - FileTest.expects(:exists?).with("/sys/bus/xen").returns(true) - Facter::Util::Virtual.should be_xen - end - - it "should detect xen when /proc/xen exists" do - FileTest.expects(:exists?).with("/proc/sys/xen").returns(false) - FileTest.expects(:exists?).with("/sys/bus/xen").returns(false) - FileTest.expects(:exists?).with("/proc/xen").returns(true) - Facter::Util::Virtual.should be_xen - end - - it "should not detect xen when no sysfs/proc xen directories exist" do - FileTest.expects(:exists?).with("/proc/sys/xen").returns(false) - FileTest.expects(:exists?).with("/sys/bus/xen").returns(false) - FileTest.expects(:exists?).with("/proc/xen").returns(false) - Facter::Util::Virtual.should_not be_xen - end - - it "should detect kvm" do - FileTest.stubs(:exists?).with("/proc/cpuinfo").returns(true) - File.stubs(:read).with("/proc/cpuinfo").returns("model name : QEMU Virtual CPU version 0.9.1\n") - Facter::Util::Virtual.should be_kvm - end - - it "should detect kvm on FreeBSD" do - FileTest.stubs(:exists?).with("/proc/cpuinfo").returns(false) - Facter.fact(:kernel).stubs(:value).returns("FreeBSD") - Facter::Util::Resolution.stubs(:exec).with("/sbin/sysctl -n hw.model").returns("QEMU Virtual CPU version 0.12.4") - Facter::Util::Virtual.should be_kvm - end - - it "should identify FreeBSD jail when in jail" do - Facter.fact(:kernel).stubs(:value).returns("FreeBSD") - Facter::Util::Resolution.stubs(:exec).with("/sbin/sysctl -n security.jail.jailed").returns("1") - Facter::Util::Virtual.should be_jail - end - - it "should not identify GNU/kFreeBSD jail when not in jail" do - Facter.fact(:kernel).stubs(:value).returns("GNU/kFreeBSD") - Facter::Util::Resolution.stubs(:exec).with("/bin/sysctl -n security.jail.jailed").returns("0") - Facter::Util::Virtual.should_not be_jail - end - - it "should detect hpvm on HP-UX" do - Facter.fact(:kernel).stubs(:value).returns("HP-UX") - Facter::Util::Resolution.stubs(:exec).with("/usr/bin/getconf MACHINE_MODEL").returns('ia64 hp server Integrity Virtual Machine') - Facter::Util::Virtual.should be_hpvm - end - - it "should not detect hpvm on HP-UX when not in hpvm" do - Facter.fact(:kernel).stubs(:value).returns("HP-UX") - Facter::Util::Resolution.stubs(:exec).with("/usr/bin/getconf MACHINE_MODEL").returns('ia64 hp server rx660') - Facter::Util::Virtual.should_not be_hpvm - end + File.stubs(:read).with("/proc/self/status").returns(status) + Facter::Util::Virtual.vserver?.should == expected + end + end + end + + it "should identify vserver_host when /proc/virtual exists" do + Facter::Util::Virtual.expects(:vserver?).returns(true) + FileTest.stubs(:exists?).with("/proc/virtual").returns(true) + Facter::Util::Virtual.vserver_type().should == "vserver_host" + end + + it "should identify vserver_type as vserver when /proc/virtual does not exist" do + Facter::Util::Virtual.expects(:vserver?).returns(true) + FileTest.stubs(:exists?).with("/proc/virtual").returns(false) + Facter::Util::Virtual.vserver_type().should == "vserver" + end + + it "should detect xen when /proc/sys/xen exists" do + FileTest.expects(:exists?).with("/proc/sys/xen").returns(true) + Facter::Util::Virtual.should be_xen + end + + it "should detect xen when /sys/bus/xen exists" do + FileTest.expects(:exists?).with("/proc/sys/xen").returns(false) + FileTest.expects(:exists?).with("/sys/bus/xen").returns(true) + Facter::Util::Virtual.should be_xen + end + + it "should detect xen when /proc/xen exists" do + FileTest.expects(:exists?).with("/proc/sys/xen").returns(false) + FileTest.expects(:exists?).with("/sys/bus/xen").returns(false) + FileTest.expects(:exists?).with("/proc/xen").returns(true) + Facter::Util::Virtual.should be_xen + end + + it "should not detect xen when no sysfs/proc xen directories exist" do + FileTest.expects(:exists?).with("/proc/sys/xen").returns(false) + FileTest.expects(:exists?).with("/sys/bus/xen").returns(false) + FileTest.expects(:exists?).with("/proc/xen").returns(false) + Facter::Util::Virtual.should_not be_xen + end + + it "should detect kvm" do + FileTest.stubs(:exists?).with("/proc/cpuinfo").returns(true) + File.stubs(:read).with("/proc/cpuinfo").returns("model name : QEMU Virtual CPU version 0.9.1\n") + Facter::Util::Virtual.should be_kvm + end + + it "should detect kvm on FreeBSD" do + FileTest.stubs(:exists?).with("/proc/cpuinfo").returns(false) + Facter.fact(:kernel).stubs(:value).returns("FreeBSD") + Facter::Util::Resolution.stubs(:exec).with("/sbin/sysctl -n hw.model").returns("QEMU Virtual CPU version 0.12.4") + Facter::Util::Virtual.should be_kvm + end + + it "should identify FreeBSD jail when in jail" do + Facter.fact(:kernel).stubs(:value).returns("FreeBSD") + Facter::Util::Resolution.stubs(:exec).with("/sbin/sysctl -n security.jail.jailed").returns("1") + Facter::Util::Virtual.should be_jail + end + + it "should not identify GNU/kFreeBSD jail when not in jail" do + Facter.fact(:kernel).stubs(:value).returns("GNU/kFreeBSD") + Facter::Util::Resolution.stubs(:exec).with("/bin/sysctl -n security.jail.jailed").returns("0") + Facter::Util::Virtual.should_not be_jail + end + + it "should detect hpvm on HP-UX" do + Facter.fact(:kernel).stubs(:value).returns("HP-UX") + Facter::Util::Resolution.stubs(:exec).with("/usr/bin/getconf MACHINE_MODEL").returns('ia64 hp server Integrity Virtual Machine') + Facter::Util::Virtual.should be_hpvm + end + + it "should not detect hpvm on HP-UX when not in hpvm" do + Facter.fact(:kernel).stubs(:value).returns("HP-UX") + Facter::Util::Resolution.stubs(:exec).with("/usr/bin/getconf MACHINE_MODEL").returns('ia64 hp server rx660') + Facter::Util::Virtual.should_not be_hpvm + end end diff --git a/spec/unit/util/vlans_spec.rb b/spec/unit/util/vlans_spec.rb index 0331234..6f76b73 100755 --- a/spec/unit/util/vlans_spec.rb +++ b/spec/unit/util/vlans_spec.rb <at> <at> -5,10 +5,10 <at> <at> require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/vlans' describe Facter::Util::Vlans do - it "should return a list of vlans on Linux" do - sample_output_file = File.dirname(__FILE__) + '/../data/linux_vlan_config' - linux_vlanconfig = File.new(sample_output_file).read(); - Facter::Util::Vlans.stubs(:get_vlan_config).returns(linux_vlanconfig) - Facter::Util::Vlans.get_vlans().should == %{400,300,200,100} - end + it "should return a list of vlans on Linux" do + sample_output_file = File.dirname(__FILE__) + '/../data/linux_vlan_config' + linux_vlanconfig = File.new(sample_output_file).read(); + Facter::Util::Vlans.stubs(:get_vlan_config).returns(linux_vlanconfig) + Facter::Util::Vlans.get_vlans().should == %{400,300,200,100} + end end diff --git a/spec/unit/virtual_spec.rb b/spec/unit/virtual_spec.rb index 72182c0..8090358 100644 --- a/spec/unit/virtual_spec.rb +++ b/spec/unit/virtual_spec.rb <at> <at> -6,302 +6,302 <at> <at> require 'facter/util/macosx' describe "Virtual fact" do before do - Facter::Util::Virtual.stubs(:zone?).returns(false) - Facter::Util::Virtual.stubs(:openvz?).returns(false) - Facter::Util::Virtual.stubs(:vserver?).returns(false) - Facter::Util::Virtual.stubs(:xen?).returns(false) - Facter::Util::Virtual.stubs(:kvm?).returns(false) - Facter::Util::Virtual.stubs(:hpvm?).returns(false) - Facter::Util::Virtual.stubs(:zlinux?).returns(false) + Facter::Util::Virtual.stubs(:zone?).returns(false) + Facter::Util::Virtual.stubs(:openvz?).returns(false) + Facter::Util::Virtual.stubs(:vserver?).returns(false) + Facter::Util::Virtual.stubs(:xen?).returns(false) + Facter::Util::Virtual.stubs(:kvm?).returns(false) + Facter::Util::Virtual.stubs(:hpvm?).returns(false) + Facter::Util::Virtual.stubs(:zlinux?).returns(false) end it "should be zone on Solaris when a zone" do - Facter.fact(:kernel).stubs(:value).returns("SunOS") - Facter::Util::Virtual.stubs(:zone?).returns(true) - Facter::Util::Virtual.stubs(:vserver?).returns(false) - Facter::Util::Virtual.stubs(:xen?).returns(false) - Facter.fact(:virtual).value.should == "zone" + Facter.fact(:kernel).stubs(:value).returns("SunOS") + Facter::Util::Virtual.stubs(:zone?).returns(true) + Facter::Util::Virtual.stubs(:vserver?).returns(false) + Facter::Util::Virtual.stubs(:xen?).returns(false) + Facter.fact(:virtual).value.should == "zone" end it "should be jail on FreeBSD when a jail in kvm" do - Facter.fact(:kernel).stubs(:value).returns("FreeBSD") - Facter::Util::Virtual.stubs(:jail?).returns(true) - Facter::Util::Virtual.stubs(:kvm?).returns(true) - Facter.fact(:virtual).value.should == "jail" + Facter.fact(:kernel).stubs(:value).returns("FreeBSD") + Facter::Util::Virtual.stubs(:jail?).returns(true) + Facter::Util::Virtual.stubs(:kvm?).returns(true) + Facter.fact(:virtual).value.should == "jail" end it "should be hpvm on HP-UX when in HP-VM" do - Facter.fact(:kernel).stubs(:value).returns("HP-UX") - Facter::Util::Virtual.stubs(:hpvm?).returns(true) - Facter.fact(:virtual).value.should == "hpvm" + Facter.fact(:kernel).stubs(:value).returns("HP-UX") + Facter::Util::Virtual.stubs(:hpvm?).returns(true) + Facter.fact(:virtual).value.should == "hpvm" end it "should be zlinux on s390x" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter.fact(:architecture).stubs(:value).returns("s390x") - Facter::Util::Virtual.stubs(:zlinux?).returns(true) - Facter.fact(:virtual).value.should == "zlinux" + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:architecture).stubs(:value).returns("s390x") + Facter::Util::Virtual.stubs(:zlinux?).returns(true) + Facter.fact(:virtual).value.should == "zlinux" end describe "on Darwin" do - it "should be parallels with Parallels vendor id" do - Facter.fact(:kernel).stubs(:value).returns("Darwin") - Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor-id" => "0x1ab8" }) - Facter.fact(:virtual).value.should == "parallels" - end - - it "should be parallels with Parallels vendor name" do - Facter.fact(:kernel).stubs(:value).returns("Darwin") - Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor" => "Parallels" }) - Facter.fact(:virtual).value.should == "parallels" - end - - it "should be vmware with VMWare vendor id" do - Facter.fact(:kernel).stubs(:value).returns("Darwin") - Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor-id" => "0x15ad" }) - Facter.fact(:virtual).value.should == "vmware" - end - - it "should be vmware with VMWare vendor name" do - Facter.fact(:kernel).stubs(:value).returns("Darwin") - Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor" => "VMWare" }) - Facter.fact(:virtual).value.should == "vmware" - end - end + it "should be parallels with Parallels vendor id" do + Facter.fact(:kernel).stubs(:value).returns("Darwin") + Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor-id" => "0x1ab8" }) + Facter.fact(:virtual).value.should == "parallels" + end - describe "on Linux" do + it "should be parallels with Parallels vendor name" do + Facter.fact(:kernel).stubs(:value).returns("Darwin") + Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor" => "Parallels" }) + Facter.fact(:virtual).value.should == "parallels" + end - before do - Facter::Util::Resolution.stubs(:exec).with("vmware -v").returns false - Facter.fact(:operatingsystem).stubs(:value).returns(true) - # Ensure the tests don't fail on Xen - FileTest.stubs(:exists?).with("/proc/sys/xen").returns false - FileTest.stubs(:exists?).with("/sys/bus/xen").returns false - FileTest.stubs(:exists?).with("/proc/xen").returns false - Facter.fact(:architecture).stubs(:value).returns(true) - end - - it "should be parallels with Parallels vendor id from lspci" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter::Util::Resolution.stubs(:exec).with('lspci').returns("01:00.0 VGA compatible controller: Unknown device 1ab8:4005") - Facter.fact(:virtual).value.should == "parallels" - end - - it "should be parallels with Parallels vendor name from lspci" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter::Util::Resolution.stubs(:exec).with('lspci').returns("01:00.0 VGA compatible controller: Parallels Display Adapter") - Facter.fact(:virtual).value.should == "parallels" - end - - it "should be vmware with VMware vendor name from lspci" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter::Util::Resolution.stubs(:exec).with('lspci').returns("00:0f.0 VGA compatible controller: VMware Inc [VMware SVGA II] PCI Display Adapter") - Facter.fact(:virtual).value.should == "vmware" - end - - it "should be virtualbox with VirtualBox vendor name from lspci" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter::Util::Resolution.stubs(:exec).with('lspci').returns("00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter") - Facter.fact(:virtual).value.should == "virtualbox" - end - - it "should be vmware with VMWare vendor name from dmidecode" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) - Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("On Board Device 1 Information\nType: Video\nStatus: Disabled\nDescription: VMware SVGA II") - Facter.fact(:virtual).value.should == "vmware" - end - - it "should be xenhvm with Xen HVM vendor name from lspci" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter::Util::Resolution.stubs(:exec).with('lspci').returns("00:03.0 Unassigned class [ff80]: XenSource, Inc. Xen Platform Device (rev 01)") - Facter.fact(:virtual).value.should == "xenhvm" - end - - it "should be xenhvm with Xen HVM vendor name from dmidecode" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) - Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("System Information\nManufacturer: Xen\nProduct Name: HVM domU") - Facter.fact(:virtual).value.should == "xenhvm" - end - - it "should be parallels with Parallels vendor name from dmidecode" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) - Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("On Board Device Information\nType: Video\nStatus: Disabled\nDescription: Parallels Video Adapter") - Facter.fact(:virtual).value.should == "parallels" - end - - it "should be virtualbox with VirtualBox vendor name from dmidecode" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) - Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("BIOS Information\nVendor: innotek GmbH\nVersion: VirtualBox\n\nSystem Information\nManufacturer: innotek GmbH\nProduct Name: VirtualBox\nFamily: Virtual Machine") - Facter.fact(:virtual).value.should == "virtualbox" - end - - it "should be hyperv with Microsoft vendor name from lspci" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter::Util::Resolution.stubs(:exec).with('lspci').returns("00:08.0 VGA compatible controller: Microsoft Corporation Hyper-V virtual VGA") - Facter.fact(:virtual).value.should == "hyperv" - end - - it "should be hyperv with Microsoft vendor name from dmidecode" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) - Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("System Information\nManufacturer: Microsoft Corporation\nProduct Name: Virtual Machine") - Facter.fact(:virtual).value.should == "hyperv" - end + it "should be vmware with VMWare vendor id" do + Facter.fact(:kernel).stubs(:value).returns("Darwin") + Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor-id" => "0x15ad" }) + Facter.fact(:virtual).value.should == "vmware" + end + it "should be vmware with VMWare vendor name" do + Facter.fact(:kernel).stubs(:value).returns("Darwin") + Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor" => "VMWare" }) + Facter.fact(:virtual).value.should == "vmware" + end end - describe "on Solaris" do - before(:each) do - Facter::Util::Resolution.stubs(:exec).with("vmware -v").returns false - end - - it "should be vmware with VMWare vendor name from prtdiag" do - Facter.fact(:kernel).stubs(:value).returns("SunOS") - Facter.fact(:hardwaremodel).stubs(:value).returns(nil) - Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) - Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil) - Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: VMware, Inc. VMware Virtual Platform") - Facter.fact(:virtual).value.should == "vmware" - end - - it "should be parallels with Parallels vendor name from prtdiag" do - Facter.fact(:kernel).stubs(:value).returns("SunOS") - Facter.fact(:hardwaremodel).stubs(:value).returns(nil) - Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) - Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil) - Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: Parallels Virtual Platform") - Facter.fact(:virtual).value.should == "parallels" - end - - it "should be virtualbox with VirtualBox vendor name from prtdiag" do - Facter.fact(:kernel).stubs(:value).returns("SunOS") - Facter.fact(:hardwaremodel).stubs(:value).returns(nil) - Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) - Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil) - Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: innotek GmbH VirtualBox") - Facter.fact(:virtual).value.should == "virtualbox" - end - - it "should be xen0 with xen dom0 files in /proc" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter.fact(:operatingsystem).stubs(:value).returns("Linux") - Facter.fact(:hardwaremodel).stubs(:value).returns("i386") - Facter::Util::Virtual.expects(:xen?).returns(true) - FileTest.expects(:exists?).with("/proc/xen/xsd_kva").returns(true) - Facter.fact(:virtual).value.should == "xen0" - end - - it "should be xenu with xen domU files in /proc" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter.fact(:operatingsystem).stubs(:value).returns("Linux") - Facter.fact(:hardwaremodel).stubs(:value).returns("i386") - Facter::Util::Virtual.expects(:xen?).returns(true) - FileTest.expects(:exists?).with("/proc/xen/xsd_kva").returns(false) - FileTest.expects(:exists?).with("/proc/xen/capabilities").returns(true) - Facter.fact(:virtual).value.should == "xenu" - end - end -end -describe "is_virtual fact" do + describe "on Linux" do - it "should be virtual when running on xen" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter.fact(:virtual).stubs(:value).returns("xenu") - Facter.fact(:is_virtual).value.should == "true" + before do + Facter::Util::Resolution.stubs(:exec).with("vmware -v").returns false + Facter.fact(:operatingsystem).stubs(:value).returns(true) + # Ensure the tests don't fail on Xen + FileTest.stubs(:exists?).with("/proc/sys/xen").returns false + FileTest.stubs(:exists?).with("/sys/bus/xen").returns false + FileTest.stubs(:exists?).with("/proc/xen").returns false + Facter.fact(:architecture).stubs(:value).returns(true) end - it "should be false when running on xen0" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter.fact(:virtual).stubs(:value).returns("xen0") - Facter.fact(:is_virtual).value.should == "false" + it "should be parallels with Parallels vendor id from lspci" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns("01:00.0 VGA compatible controller: Unknown device 1ab8:4005") + Facter.fact(:virtual).value.should == "parallels" end - it "should be true when running on xenhvm" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter.fact(:virtual).stubs(:value).returns("xenhvm") - Facter.fact(:is_virtual).value.should == "true" + it "should be parallels with Parallels vendor name from lspci" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns("01:00.0 VGA compatible controller: Parallels Display Adapter") + Facter.fact(:virtual).value.should == "parallels" end - it "should be false when running on physical" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter.fact(:virtual).stubs(:value).returns("physical") - Facter.fact(:is_virtual).value.should == "false" + it "should be vmware with VMware vendor name from lspci" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns("00:0f.0 VGA compatible controller: VMware Inc [VMware SVGA II] PCI Display Adapter") + Facter.fact(:virtual).value.should == "vmware" end - it "should be true when running on vmware" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter.fact(:virtual).stubs(:value).returns("vmware") - Facter.fact(:is_virtual).value.should == "true" + it "should be virtualbox with VirtualBox vendor name from lspci" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns("00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter") + Facter.fact(:virtual).value.should == "virtualbox" end - it "should be true when running on virtualbox" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter.fact(:virtual).stubs(:value).returns("virtualbox") - Facter.fact(:is_virtual).value.should == "true" + it "should be vmware with VMWare vendor name from dmidecode" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("On Board Device 1 Information\nType: Video\nStatus: Disabled\nDescription: VMware SVGA II") + Facter.fact(:virtual).value.should == "vmware" end - it "should be true when running on openvzve" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter.fact(:virtual).stubs(:value).returns("openvzve") - Facter.fact(:is_virtual).value.should == "true" + it "should be xenhvm with Xen HVM vendor name from lspci" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns("00:03.0 Unassigned class [ff80]: XenSource, Inc. Xen Platform Device (rev 01)") + Facter.fact(:virtual).value.should == "xenhvm" end - it "should be true when running on kvm" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter.fact(:virtual).stubs(:value).returns("kvm") - Facter.fact(:is_virtual).value.should == "true" + it "should be xenhvm with Xen HVM vendor name from dmidecode" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("System Information\nManufacturer: Xen\nProduct Name: HVM domU") + Facter.fact(:virtual).value.should == "xenhvm" end - it "should be true when running in jail" do - Facter.fact(:kernel).stubs(:value).returns("FreeBSD") - Facter.fact(:virtual).stubs(:value).returns("jail") - Facter.fact(:is_virtual).value.should == "true" + it "should be parallels with Parallels vendor name from dmidecode" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("On Board Device Information\nType: Video\nStatus: Disabled\nDescription: Parallels Video Adapter") + Facter.fact(:virtual).value.should == "parallels" end - it "should be true when running in zone" do - Facter.fact(:kernel).stubs(:value).returns("SunOS") - Facter.fact(:virtual).stubs(:value).returns("zone") - Facter.fact(:is_virtual).value.should == "true" + it "should be virtualbox with VirtualBox vendor name from dmidecode" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("BIOS Information\nVendor: innotek GmbH\nVersion: VirtualBox\n\nSystem Information\nManufacturer: innotek GmbH\nProduct Name: VirtualBox\nFamily: Virtual Machine") + Facter.fact(:virtual).value.should == "virtualbox" end - it "should be true when running on hp-vm" do - Facter.fact(:kernel).stubs(:value).returns("HP-UX") - Facter.fact(:virtual).stubs(:value).returns("hpvm") - Facter.fact(:is_virtual).value.should == "true" + it "should be hyperv with Microsoft vendor name from lspci" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns("00:08.0 VGA compatible controller: Microsoft Corporation Hyper-V virtual VGA") + Facter.fact(:virtual).value.should == "hyperv" end - it "should be true when running on S390" do - Facter.fact(:architecture).stubs(:value).returns("s390x") - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter.fact(:virtual).stubs(:value).returns("zlinux") - Facter.fact(:is_virtual).value.should == "true" + it "should be hyperv with Microsoft vendor name from dmidecode" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("System Information\nManufacturer: Microsoft Corporation\nProduct Name: Virtual Machine") + Facter.fact(:virtual).value.should == "hyperv" end - it "should be true when running on parallels" do - Facter.fact(:kernel).stubs(:value).returns("Darwin") - Facter.fact(:virtual).stubs(:value).returns("parallels") - Facter.fact(:is_virtual).value.should == "true" + end + describe "on Solaris" do + before(:each) do + Facter::Util::Resolution.stubs(:exec).with("vmware -v").returns false end - it "should be false on vmware_server" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter.fact(:virtual).stubs(:value).returns("vmware_server") - Facter.fact(:is_virtual).value.should == "false" + it "should be vmware with VMWare vendor name from prtdiag" do + Facter.fact(:kernel).stubs(:value).returns("SunOS") + Facter.fact(:hardwaremodel).stubs(:value).returns(nil) + Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: VMware, Inc. VMware Virtual Platform") + Facter.fact(:virtual).value.should == "vmware" end - it "should be false on openvz host nodes" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter.fact(:virtual).stubs(:value).returns("openvzhn") - Facter.fact(:is_virtual).value.should == "false" + it "should be parallels with Parallels vendor name from prtdiag" do + Facter.fact(:kernel).stubs(:value).returns("SunOS") + Facter.fact(:hardwaremodel).stubs(:value).returns(nil) + Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: Parallels Virtual Platform") + Facter.fact(:virtual).value.should == "parallels" + end + + it "should be virtualbox with VirtualBox vendor name from prtdiag" do + Facter.fact(:kernel).stubs(:value).returns("SunOS") + Facter.fact(:hardwaremodel).stubs(:value).returns(nil) + Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: innotek GmbH VirtualBox") + Facter.fact(:virtual).value.should == "virtualbox" end - it "should be true when running on hyperv" do - Facter.fact(:kernel).stubs(:value).returns("Linux") - Facter.fact(:virtual).stubs(:value).returns("hyperv") - Facter.fact(:is_virtual).value.should == "true" + it "should be xen0 with xen dom0 files in /proc" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:operatingsystem).stubs(:value).returns("Linux") + Facter.fact(:hardwaremodel).stubs(:value).returns("i386") + Facter::Util::Virtual.expects(:xen?).returns(true) + FileTest.expects(:exists?).with("/proc/xen/xsd_kva").returns(true) + Facter.fact(:virtual).value.should == "xen0" end + + it "should be xenu with xen domU files in /proc" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:operatingsystem).stubs(:value).returns("Linux") + Facter.fact(:hardwaremodel).stubs(:value).returns("i386") + Facter::Util::Virtual.expects(:xen?).returns(true) + FileTest.expects(:exists?).with("/proc/xen/xsd_kva").returns(false) + FileTest.expects(:exists?).with("/proc/xen/capabilities").returns(true) + Facter.fact(:virtual).value.should == "xenu" + end + end +end + +describe "is_virtual fact" do + + it "should be virtual when running on xen" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:virtual).stubs(:value).returns("xenu") + Facter.fact(:is_virtual).value.should == "true" + end + + it "should be false when running on xen0" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:virtual).stubs(:value).returns("xen0") + Facter.fact(:is_virtual).value.should == "false" + end + + it "should be true when running on xenhvm" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:virtual).stubs(:value).returns("xenhvm") + Facter.fact(:is_virtual).value.should == "true" + end + + it "should be false when running on physical" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:virtual).stubs(:value).returns("physical") + Facter.fact(:is_virtual).value.should == "false" + end + + it "should be true when running on vmware" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:virtual).stubs(:value).returns("vmware") + Facter.fact(:is_virtual).value.should == "true" + end + + it "should be true when running on virtualbox" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:virtual).stubs(:value).returns("virtualbox") + Facter.fact(:is_virtual).value.should == "true" + end + + it "should be true when running on openvzve" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:virtual).stubs(:value).returns("openvzve") + Facter.fact(:is_virtual).value.should == "true" + end + + it "should be true when running on kvm" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:virtual).stubs(:value).returns("kvm") + Facter.fact(:is_virtual).value.should == "true" + end + + it "should be true when running in jail" do + Facter.fact(:kernel).stubs(:value).returns("FreeBSD") + Facter.fact(:virtual).stubs(:value).returns("jail") + Facter.fact(:is_virtual).value.should == "true" + end + + it "should be true when running in zone" do + Facter.fact(:kernel).stubs(:value).returns("SunOS") + Facter.fact(:virtual).stubs(:value).returns("zone") + Facter.fact(:is_virtual).value.should == "true" + end + + it "should be true when running on hp-vm" do + Facter.fact(:kernel).stubs(:value).returns("HP-UX") + Facter.fact(:virtual).stubs(:value).returns("hpvm") + Facter.fact(:is_virtual).value.should == "true" + end + + it "should be true when running on S390" do + Facter.fact(:architecture).stubs(:value).returns("s390x") + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:virtual).stubs(:value).returns("zlinux") + Facter.fact(:is_virtual).value.should == "true" + end + + it "should be true when running on parallels" do + Facter.fact(:kernel).stubs(:value).returns("Darwin") + Facter.fact(:virtual).stubs(:value).returns("parallels") + Facter.fact(:is_virtual).value.should == "true" + end + + it "should be false on vmware_server" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:virtual).stubs(:value).returns("vmware_server") + Facter.fact(:is_virtual).value.should == "false" + end + + it "should be false on openvz host nodes" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:virtual).stubs(:value).returns("openvzhn") + Facter.fact(:is_virtual).value.should == "false" + end + + it "should be true when running on hyperv" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:virtual).stubs(:value).returns("hyperv") + Facter.fact(:is_virtual).value.should == "true" + end end

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to puppet-dev <at> googlegroups.com.
To unsubscribe from this group, send email to puppet-dev+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
wearetherobots | 3 Oct 2011 03:15

(puppetlabs/facter) New pull request: (#9852) Fixing watchr on facter

Greetings!

Please review the pull request #76: (#9852) Fixing watchr on facter opened by (kbarber)

Some more information about the pull request:

  • Opened: Mon Oct 03 01:11:19 UTC 2011
  • Based on: puppetlabs:1.6.x (8a8903ea1f086438b44a8a48c0ce0c601c9557f6)
  • Requested merge: kbarber:ticket/9852-watchr (d7c00f60c3302dbc61451173d4e49e0a01012029)

Description:

Signed-off-by: Luke Kanies luke <at> puppetlabs.com

Thanks!
The Pull Request Bot

Diff follows:

diff --git a/spec/watchr.rb b/spec/watchr.rb new file mode 100755 index 0000000..9d4d3ae --- /dev/null +++ b/spec/watchr.rb <at> <at> -0,0 +1,125 <at> <at> +ENV["WATCHR"] = "1" +ENV['AUTOTEST'] = 'true' + +def run_comp(cmd) + puts cmd + results = [] + old_sync = $stdout.sync + $stdout.sync = true + line = [] + begin + open("| #{cmd}", "r") do |f| + until f.eof? do + c = f.getc + putc c + line << c + if c == ?\n + results << if RUBY_VERSION >= "1.9" then + line.join + else + line.pack "c*" + end + line.clear + end + end + end + ensure + $stdout.sync = old_sync + end + results.join +end + +def clear + #system("clear") +end + +def growl(message, status) + # Strip the color codes + message.gsub!(/ \[\d+m/, '') + + growlnotify = `which growlnotify`.chomp + return if growlnotify.empty? + title = "Watchr Test Results" + image = status == :pass ? "autotest/images/pass.png" : "autotest/images/fail.png" + options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'" + system %(#{growlnotify} #{options} &) +end + +def file2specs(file) + %w{spec/unit spec/integration}.collect { |d| + file.sub('lib/facter', d).sub('.rb', '_spec.rb') + }.find_all { |f| + FileTest.exist?(f) + } +end + +def run_spec(command) + clear + result = run_comp(command).split("\n").last + status = result.include?('0 failures') ? :pass : :fail + growl result, status +end + +def run_spec_files(files) + files = Array(files) + return if files.empty? + opts = File.readlines('.rspec').collect { |l| l.chomp }.join(" ") + begin + run_spec("rspec --tty #{opts} #{files.join(' ')}") + rescue => detail + puts detail.backtrace + warn "Failed to run #{files.join(', ')}: #{detail}" + end +end + +def run_suite + files = files("unit") + files("integration") + opts = File.readlines('.rspec').collect { |l| l.chomp }.join(" ") + run_spec("rspec --tty #{opts} #{files.join(' ')}") +end + +def files(dir) + require 'find' + + result = [] + Find.find(File.join("spec", dir)) do |path| + result << path if path =~ /\.rb/ + end + + result +end + +watch('spec/spec_helper.rb') { run_suite } +watch(%r{^spec/(unit|integration)/.*\.rb$}) { |md| run_spec_files(md[0]) } +watch(%r{^lib/facter/(.*)\.rb$}) { |md| + run_spec_files(file2specs(md[0])) +} +watch(%r{^spec/lib/spec.*}) { |md| run_suite } +watch(%r{^spec/lib/monkey_patches/.*}) { |md| run_suite } + +# Ctrl-\ +Signal.trap 'QUIT' do + puts " --- Running all tests ---\n\n" + run_suite +end + + <at> interrupted = false + +# Ctrl-C +Signal.trap 'INT' do + if <at> interrupted + <at> wants_to_quit = true + abort("\n") + else + puts "Interrupt a second time to quit; wait for rerun of tests" + <at> interrupted = true + Kernel.sleep 1.5 + # raise Interrupt, nil # let the run loop catch it + begin + run_suite + rescue => detail + puts detail.backtrace + puts "Could not run suite: #{detail}" + end + end +end

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to puppet-dev <at> googlegroups.com.
To unsubscribe from this group, send email to puppet-dev+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.

Gmane