diff options
44 files changed, 1028 insertions, 146 deletions
@@ -18,11 +18,8 @@ # # = Options # -# debug:: -# Enable debugging. -# -# help:: -# Print this help message +# yaml:: +# Emit facts in YAML format. # # puppet:: # Load the Puppet libraries, thus allowing Facter to load Puppet-specific facts. @@ -30,8 +27,17 @@ # version:: # Print the version and exit. # -# yaml:: -# Emit facts in YAML format. +# help:: +# Print this help message. +# +# debug:: +# Enable debugging. +# +# trace:: +# Enable backtraces. +# +# timing:: +# Enable timing. # # = Example # @@ -46,120 +52,6 @@ # Copyright (c) 2006 Reductive Labs, LLC # Licensed under the GNU Public License -require 'getoptlong' -require 'facter' - -$haveusage = true - -begin - require 'rdoc/ri/ri_paths' - require 'rdoc/usage' -rescue Exception - $haveusage = false -end - -def load_puppet - require 'puppet' - Puppet.parse_config - - # If you've set 'vardir' but not 'libdir' in your - # puppet.conf, then the hook to add libdir to $: - # won't get triggered. This makes sure that it's setup - # correctly. - unless $LOAD_PATH.include?(Puppet[:libdir]) - $LOAD_PATH << Puppet[:libdir] - end -end - -$debug = 0 - -config = nil - -result = GetoptLong.new( - [ "--version", "-v", GetoptLong::NO_ARGUMENT ], - [ "--help", "-h", GetoptLong::NO_ARGUMENT ], - [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], - [ "--yaml", "-y", GetoptLong::NO_ARGUMENT ], - [ "--config", "-c", GetoptLong::REQUIRED_ARGUMENT ], - [ "--puppet", "-p", GetoptLong::NO_ARGUMENT ] -) - -options = { - :yaml => false -} - -begin - result.each { |opt,arg| - case opt - when "--version" - puts "%s" % Facter.version - exit - when "--puppet" - begin - load_puppet() - rescue LoadError => detail - $stderr.puts "Could not load Puppet: %s" % detail - end - when "--yaml" - options[:yaml] = true - when "--debug" - Facter.debugging(1) - when "--help" - if $haveusage - RDoc::usage && exit - else - puts "No help available unless you have RDoc::usage installed" - exit - end - else - $stderr.puts "Invalid option '#{opt}'" - exit(12) - end - } -rescue - exit(12) -end - -names = [] - -unless config.nil? - File.open(config) { |file| - names = file.readlines.collect { |line| - line.chomp - } - } -end - -ARGV.each { |item| - names.push item -} - -facts = Facter.to_hash - -unless names.empty? - facts = {} - names.each { |name| - begin - facts[name] = Facter.value(name) - rescue => error - STDERR.puts "Could not retrieve %s: #{error}" % name - exit 10 - end - } -end - -if options[:yaml] - require 'yaml' - puts YAML.dump(facts) - exit(0) -end +require 'facter/application' -facts.sort { |a, b| a[0].to_s <=> b[0].to_s }.each { |name,value| - if facts.length == 1 - unless value.nil? - puts value - end - else - puts "%s => %s" % [name,value] - end -} +Facter::Application.run(ARGV) diff --git a/ext/facter-diff b/ext/facter-diff new file mode 100755 index 0000000..6616318 --- /dev/null +++ b/ext/facter-diff @@ -0,0 +1,74 @@ + +#!/usr/bin/env sh +# +# Output the difference between a facter command run on two different versions +# of facter. Uses unified diff format. + +OPTIONS_SPEC="\ +facter-diff [options] <rev1> <rev2> [fact]... + +Example: + + ./ext/facter-diff 1.5.7 1.0.2 + +-- +h,help Display this help" + +. "$(git --exec-path)/git-sh-setup" +eval "$(echo "$OPTIONS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)" +trap 'err=$?; cleanup; exit $err' 0 + +cleanup() { + test $origin && git checkout -q "$origin" +} + +facter() { + ruby -Ilib bin/facter "$@" +} + +log_facter_run() { + local ref=$1 && shift + local tmpfile=$1 && shift + + git checkout -qf "$ref" || + die "fatal: unable to checkout $ref" + facter "$@" > $tmpfile +} + +verify_revision() { + git rev-parse --verify --quiet "$1" > /dev/null || + die "fatal: '$1' is not a valid revision" +} + +test $1 = "--" && shift # git rev-parse seems to leave the -- in +test $# -eq 0 && usage + +test $# -gt 1 || + die "fatal: must specify two revisions" + +status=$(git status -s) +test -z "$status" || + die "fatal: $0 cannot be used with a dirty working copy" + +origin=$(git rev-parse --symbolic-full-name HEAD) +test "$origin" = "HEAD" && + origin=$(git rev-parse HEAD) + +test -x "bin/facter" || + die "fatal: $0 must be run from the project root" + +ref1="$1" && shift +ref2="$1" && shift + +verify_revision $ref1 +verify_revision $ref2 + +tmpfile1="/tmp/$(basename $0).$$.1.tmp" +tmpfile2="/tmp/$(basename $0).$$.2.tmp" + +log_facter_run $ref1 $tmpfile1 $@ +log_facter_run $ref2 $tmpfile2 $@ + +git checkout -f "$origin" > /dev/null 2>&1 + +diff --label "$ref1" --label "$ref2" -u $tmpfile1 $tmpfile2 diff --git a/lib/facter.rb b/lib/facter.rb index 42d5371..f48138a 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -48,6 +48,7 @@ module Facter GREEN = "[0;32m" RESET = "[0m" @@debug = 0 + @@timing = 0 # module methods @@ -77,6 +78,15 @@ module Facter @@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? + @@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) @@ -177,6 +187,22 @@ module Facter end end + # Set timing on or off. + def self.timing(bit) + if bit + case bit + when TrueClass; @@timing = 1 + when Fixnum + if bit > 0 + @@timing = 1 + else + @@timing = 0 + end + end + else + @@timing = 0 + end + end def self.warn(msg) if Facter.debugging? and msg and not msg.empty? diff --git a/lib/facter/application.rb b/lib/facter/application.rb new file mode 100644 index 0000000..9de9249 --- /dev/null +++ b/lib/facter/application.rb @@ -0,0 +1,108 @@ +module Facter + module Application + def self.run(argv) + require 'optparse' + require 'facter' + + options = parse(argv) + + # Accept fact names to return from the command line + names = argv + + # Create the facts hash that is printed to standard out + if names.empty? + facts = Facter.to_hash + else + facts = {} + names.each { |name| + begin + facts[name] = Facter.value(name) + rescue => error + $stderr.puts "Could not retrieve #{name}: #{error}" + exit 10 + end + } + end + + # Print the facts as YAML and exit + if options[:yaml] + require 'yaml' + puts YAML.dump(facts) + exit(0) + end + + # Print the value of a single fact, otherwise print a list sorted by fact + # name and separated by "=>" + if facts.length == 1 + if value = facts.values.first + puts value + end + else + facts.sort_by{ |fact| fact.first }.each do |name,value| + puts "#{name} => #{value}" + end + end + + rescue => e + if options && options[:trace] + raise e + else + $stderr.puts "Error: #{e}" + exit(12) + end + end + + private + + def self.parse(argv) + options = {} + OptionParser.new do |opts| + opts.on("-y", "--yaml") { |v| options[:yaml] = v } + opts.on( "--trace") { |v| options[:trace] = v } + opts.on("-d", "--debug") { |v| Facter.debugging(1) } + opts.on("-t", "--timing") { |v| Facter.timing(1) } + opts.on("-p", "--puppet") { |v| load_puppet } + + opts.on_tail("-v", "--version") do + puts Facter.version + exit(0) + end + + opts.on_tail("-h", "--help") do + begin + require 'rdoc/ri/ri_paths' + require 'rdoc/usage' + puts RDoc.usage + rescue LoadError + $stderr.puts "No help available unless your RDoc has RDoc.usage" + exit(1) + rescue => e + $stderr.puts "fatal: #{e}" + exit(1) + end + end + end.parse! + + options + rescue OptionParser::InvalidOption => e + $stderr.puts e.message + exit(12) + end + + def self.load_puppet + require 'puppet' + Puppet.parse_config + + # If you've set 'vardir' but not 'libdir' in your + # puppet.conf, then the hook to add libdir to $: + # won't get triggered. This makes sure that it's setup + # correctly. + unless $LOAD_PATH.include?(Puppet[:libdir]) + $LOAD_PATH << Puppet[:libdir] + end + rescue LoadError => detail + $stderr.puts "Could not load Puppet: #{detail}" + end + + end +end diff --git a/lib/facter/macaddress.rb b/lib/facter/macaddress.rb index 889feea..adc2c64 100644 --- a/lib/facter/macaddress.rb +++ b/lib/facter/macaddress.rb @@ -1,3 +1,5 @@ +require 'facter/util/macaddress' + Facter.add(:macaddress) do confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Gentoo Ubuntu OEL OVS} setcode do @@ -26,19 +28,7 @@ end Facter.add(:macaddress) do confine :kernel => :darwin - setcode do - ether = nil - output = %x{/sbin/ifconfig} - - output.split(/^\S/).each do |str| - if str =~ /10baseT/ # we're wired - str =~ /ether (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/ - ether = $1 - end - end - - ether - end + setcode { Facter::Util::Macaddress::Darwin.macaddress } end Facter.add(:macaddress) do diff --git a/lib/facter/util/macaddress.rb b/lib/facter/util/macaddress.rb new file mode 100644 index 0000000..fc0a043 --- /dev/null +++ b/lib/facter/util/macaddress.rb @@ -0,0 +1,28 @@ +# A module to gather macaddress facts +# +module Facter::Util::Macaddress + + module Darwin + def self.macaddress + iface = default_interface + Facter.warn "Could not find a default route. Using first non-loopback interface" if iface.empty? + + macaddress = `#{ifconfig_command} #{iface} | /usr/bin/awk '/ether/{print $2;exit}'`.chomp + macaddress.empty? ? nil : macaddress + end + + def self.default_interface + `#{netstat_command} | /usr/bin/awk '/^default/{print $6}'`.chomp + end + + private + + def self.netstat_command + '/usr/sbin/netstat -rn' + end + + def self.ifconfig_command + '/sbin/ifconfig' + end + end +end diff --git a/lib/facter/util/resolution.rb b/lib/facter/util/resolution.rb index f837f64..4a99c35 100644 --- a/lib/facter/util/resolution.rb +++ b/lib/facter/util/resolution.rb @@ -135,6 +135,9 @@ class Facter::Util::Resolution def value result = nil return result if @code == nil and @interpreter == nil + + starttime = Time.now.to_f + begin Timeout.timeout(limit) do if @code.is_a?(Proc) @@ -156,6 +159,10 @@ class Facter::Util::Resolution return nil end + finishtime = Time.now.to_f + ms = (finishtime - starttime) * 1000 + Facter.show_time "#{self.name}: #{"%.2f" % ms}ms" + return nil if result == "" return result end diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb index 5a03117..e94070d 100644 --- a/lib/facter/util/virtual.rb +++ b/lib/facter/util/virtual.rb @@ -22,7 +22,7 @@ module Facter::Util::Virtual 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:]]*[1-9]/ + return true if txt =~ /^(s_context|VxID):[[:blank:]]*[0-9]/ return false end diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb index faefb29..a8afb60 100644 --- a/lib/facter/virtual.rb +++ b/lib/facter/virtual.rb @@ -85,9 +85,9 @@ Facter.add("is_virtual") do setcode do case Facter.value(:virtual) when "xenu", "openvzve", "vmware", "kvm", "vserver", "jail", "zone", "hpvm" - true + "true" else - false + "false" end end end diff --git a/spec/fixtures/ifconfig/centos_5_5 b/spec/fixtures/ifconfig/centos_5_5 new file mode 100644 index 0000000..7f57d1d --- /dev/null +++ b/spec/fixtures/ifconfig/centos_5_5 @@ -0,0 +1,17 @@ +eth0 Link encap:Ethernet HWaddr 16:8D:2A:15:17:91 + inet addr:100.100.100.92 Bcast:100.100.100.255 Mask:255.255.255.0 + inet6 addr: fe80::148d:2aff:fe15:1791/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:1914742 errors:0 dropped:0 overruns:0 frame:0 + TX packets:3933 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:178728699 (170.4 MiB) TX bytes:389936 (380.7 KiB) + +lo Link encap:Local Loopback + inet addr:127.0.0.1 Mask:255.0.0.0 + inet6 addr: ::1/128 Scope:Host + UP LOOPBACK RUNNING MTU:16436 Metric:1 + RX packets:0 errors:0 dropped:0 overruns:0 frame:0 + TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
\ No newline at end of file diff --git a/spec/fixtures/ifconfig/centos_5_5_eth0 b/spec/fixtures/ifconfig/centos_5_5_eth0 new file mode 100644 index 0000000..c18d936 --- /dev/null +++ b/spec/fixtures/ifconfig/centos_5_5_eth0 @@ -0,0 +1,8 @@ +eth0 Link encap:Ethernet HWaddr 16:8D:2A:15:17:91 + inet addr:100.100.100.92 Bcast:100.100.100.255 Mask:255.255.255.0 + inet6 addr: fe80::148d:2aff:fe15:1791/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:1914871 errors:0 dropped:0 overruns:0 frame:0 + TX packets:3960 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:178738891 (170.4 MiB) TX bytes:393862 (384.6 KiB)
\ No newline at end of file diff --git a/spec/fixtures/ifconfig/darwin_10_3_0 b/spec/fixtures/ifconfig/darwin_10_3_0 new file mode 100644 index 0000000..23707dd --- /dev/null +++ b/spec/fixtures/ifconfig/darwin_10_3_0 @@ -0,0 +1,26 @@ +lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384 + inet6 ::1 prefixlen 128 + inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 + inet 127.0.0.1 netmask 0xff000000 +gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280 +stf0: flags=0<> mtu 1280 +en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 + ether 00:17:f2:06:e3:c2 + inet6 fe80::217:f2ff:fe06:e3c2%en0 prefixlen 64 scopeid 0x4 + inet 100.100.104.12 netmask 0xffffff00 broadcast 100.100.104.255 + media: autoselect (1000baseT <full-duplex>) + status: active +en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 + ether 00:17:f2:06:e3:c3 + media: autoselect + status: inactive +fw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 2030 + lladdr 00:16:cb:ff:fe:76:6e:be + media: autoselect <full-duplex> + status: inactive +vmnet8: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 + ether 00:50:56:c0:00:08 + inet 172.16.95.1 netmask 0xffffff00 broadcast 172.16.95.255 +vmnet1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 + ether 00:50:56:c0:00:01 + inet 172.16.201.1 netmask 0xffffff00 broadcast 172.16.201.255
\ No newline at end of file diff --git a/spec/fixtures/ifconfig/darwin_10_3_0_en0 b/spec/fixtures/ifconfig/darwin_10_3_0_en0 new file mode 100644 index 0000000..1e33f71 --- /dev/null +++ b/spec/fixtures/ifconfig/darwin_10_3_0_en0 @@ -0,0 +1,6 @@ +en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 + ether 00:17:f2:06:e3:c2 + inet6 fe80::217:f2ff:fe06:e3c2%en0 prefixlen 64 scopeid 0x4 + inet 100.100.104.12 netmask 0xffffff00 broadcast 100.100.104.255 + media: autoselect (1000baseT <full-duplex>) + status: active
\ No newline at end of file diff --git a/spec/fixtures/ifconfig/darwin_10_6_4 b/spec/fixtures/ifconfig/darwin_10_6_4 new file mode 100644 index 0000000..9fa04b0 --- /dev/null +++ b/spec/fixtures/ifconfig/darwin_10_6_4 @@ -0,0 +1,28 @@ +lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384 + inet6 ::1 prefixlen 128 + inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 + inet 127.0.0.1 netmask 0xff000000 +gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280 +stf0: flags=0<> mtu 1280 +en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 + ether 58:b0:35:fa:08:b1 + media: autoselect + status: inactive +en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 + ether 58:b0:35:7f:25:b3 + inet6 fe80::5ab0:35ff:fe7f:25b3%en1 prefixlen 64 scopeid 0x5 + inet 192.168.100.230 netmask 0xffffff00 broadcast 192.168.100.255 + media: <unknown subtype> + status: active +fw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 4078 + lladdr c4:2c:03:ff:fe:fc:c8:aa + media: autoselect <full-duplex> + status: inactive +vboxnet0: flags=8842<BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500 + ether 0a:00:27:00:00:00 +vmnet1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 + ether 00:50:56:c0:00:01 + inet 172.16.135.1 netmask 0xffffff00 broadcast 172.16.135.255 +vmnet8: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 + ether 00:50:56:c0:00:08 + inet 172.16.38.1 netmask 0xffffff00 broadcast 172.16.38.255 diff --git a/spec/fixtures/ifconfig/darwin_10_6_4_en1 b/spec/fixtures/ifconfig/darwin_10_6_4_en1 new file mode 100644 index 0000000..10e6c48 --- /dev/null +++ b/spec/fixtures/ifconfig/darwin_10_6_4_en1 @@ -0,0 +1,6 @@ +en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 + ether 58:b0:35:7f:25:b3 + inet6 fe80::5ab0:35ff:fe7f:25b3%en1 prefixlen 64 scopeid 0x5 + inet 192.168.100.230 netmask 0xffffff00 broadcast 192.168.100.255 + media: <unknown subtype> + status: active diff --git a/spec/fixtures/ifconfig/darwin_9_8_0 b/spec/fixtures/ifconfig/darwin_9_8_0 new file mode 100644 index 0000000..80f5d94 --- /dev/null +++ b/spec/fixtures/ifconfig/darwin_9_8_0 @@ -0,0 +1,26 @@ +lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384 + inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 + inet 127.0.0.1 netmask 0xff000000 + inet6 ::1 prefixlen 128 +gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280 +stf0: flags=0<> mtu 1280 +en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 + inet6 fe80::217:f2ff:fe06:e42e%en0 prefixlen 64 scopeid 0x4 + inet 100.100.107.4 netmask 0xffffff00 broadcast 100.100.107.255 + ether 00:17:f2:06:e4:2e + media: autoselect (1000baseT <full-duplex>) status: active + supported media: autoselect 10baseT/UTP <half-duplex> 10baseT/UTP <full-duplex> 10baseT/UTP <full-duplex,hw-loopback> 10baseT/UTP <full-duplex,flow-control> 100baseTX <half-duplex> 100baseTX <full-duplex> 100baseTX <full-duplex,hw-loopback> 100baseTX <full-duplex,flow-control> 1000baseT <full-duplex> 1000baseT <full-duplex,hw-loopback> 1000baseT <full-duplex,flow-control> +en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 + ether 00:17:f2:06:e4:2f + media: autoselect status: inactive + supported media: autoselect 10baseT/UTP <half-duplex> 10baseT/UTP <full-duplex> 10baseT/UTP <full-duplex,hw-loopback> 10baseT/UTP <full-duplex,flow-control> 100baseTX <half-duplex> 100baseTX <full-duplex> 100baseTX <full-duplex,hw-loopback> 100baseTX <full-duplex,flow-control> 1000baseT <full-duplex> 1000baseT <full-duplex,hw-loopback> 1000baseT <full-duplex,flow-control> +fw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 2030 + lladdr 00:16:cb:ff:fe:76:66:f2 + media: autoselect <full-duplex> status: inactive + supported media: autoselect <full-duplex> +vmnet8: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 + inet 192.168.210.1 netmask 0xffffff00 broadcast 192.168.210.255 + ether 00:50:56:c0:00:08 +vmnet1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 + inet 192.168.61.1 netmask 0xffffff00 broadcast 192.168.61.255 + ether 00:50:56:c0:00:01
\ No newline at end of file diff --git a/spec/fixtures/ifconfig/darwin_9_8_0_en0 b/spec/fixtures/ifconfig/darwin_9_8_0_en0 new file mode 100644 index 0000000..658ae77 --- /dev/null +++ b/spec/fixtures/ifconfig/darwin_9_8_0_en0 @@ -0,0 +1,6 @@ +en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 + inet6 fe80::217:f2ff:fe06:e42e%en0 prefixlen 64 scopeid 0x4 + inet 100.100.107.4 netmask 0xffffff00 broadcast 100.100.107.255 + ether 00:17:f2:06:e4:2e + media: autoselect (1000baseT <full-duplex>) status: active + supported media: autoselect 10baseT/UTP <half-duplex> 10baseT/UTP <full-duplex> 10baseT/UTP <full-duplex,hw-loopback> 10baseT/UTP <full-duplex,flow-control> 100baseTX <half-duplex> 100baseTX <full-duplex> 100baseTX <full-duplex,hw-loopback> 100baseTX <full-duplex,flow-control> 1000baseT <full-duplex> 1000baseT <full-duplex,hw-loopback> 1000baseT <full-duplex,flow-control>
\ No newline at end of file diff --git a/spec/fixtures/ifconfig/fedora_10 b/spec/fixtures/ifconfig/fedora_10 new file mode 100644 index 0000000..42b06ca --- /dev/null +++ b/spec/fixtures/ifconfig/fedora_10 @@ -0,0 +1,36 @@ +eth0 Link encap:Ethernet HWaddr 00:17:F2:06:E4:26 + inet addr:100.100.108.9 Bcast:100.100.108.255 Mask:255.255.255.0 + inet6 addr: fe80::217:f2ff:fe06:e426/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:47711100 errors:0 dropped:0 overruns:0 frame:0 + TX packets:45446436 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:17037006736 (15.8 GiB) TX bytes:9198820680 (8.5 GiB) + Memory:92c20000-92c40000 + +lo Link encap:Local Loopback + inet addr:127.0.0.1 Mask:255.0.0.0 + inet6 addr: ::1/128 Scope:Host + UP LOOPBACK RUNNING MTU:16436 Metric:1 + RX packets:366974 errors:0 dropped:0 overruns:0 frame:0 + TX packets:366974 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:33867944 (32.2 MiB) TX bytes:33867944 (32.2 MiB) + +vmnet1 Link encap:Ethernet HWaddr 00:50:56:C0:00:01 + inet addr:172.16.131.1 Bcast:172.16.131.255 Mask:255.255.255.0 + inet6 addr: fe80::250:56ff:fec0:1/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:0 errors:0 dropped:0 overruns:0 frame:0 + TX packets:20 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) + +vmnet8 Link encap:Ethernet HWaddr 00:50:56:C0:00:08 + inet addr:192.168.183.1 Bcast:192.168.183.255 Mask:255.255.255.0 + inet6 addr: fe80::250:56ff:fec0:8/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:0 errors:0 dropped:0 overruns:0 frame:0 + TX packets:20 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
\ No newline at end of file diff --git a/spec/fixtures/ifconfig/fedora_10_eth0 b/spec/fixtures/ifconfig/fedora_10_eth0 new file mode 100644 index 0000000..fa957d9 --- /dev/null +++ b/spec/fixtures/ifconfig/fedora_10_eth0 @@ -0,0 +1,9 @@ +eth0 Link encap:Ethernet HWaddr 00:17:F2:06:E4:26 + inet addr:100.100.108.9 Bcast:100.100.108.255 Mask:255.255.255.0 + inet6 addr: fe80::217:f2ff:fe06:e426/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:47711864 errors:0 dropped:0 overruns:0 frame:0 + TX packets:45447195 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:17037147877 (15.8 GiB) TX bytes:9198873602 (8.5 GiB) + Memory:92c20000-92c40000
\ No newline at end of file diff --git a/spec/fixtures/ifconfig/fedora_13 b/spec/fixtures/ifconfig/fedora_13 new file mode 100644 index 0000000..23491df --- /dev/null +++ b/spec/fixtures/ifconfig/fedora_13 @@ -0,0 +1,18 @@ +eth0 Link encap:Ethernet HWaddr 00:17:F2:0D:9B:A8 + inet addr:100.100.108.27 Bcast:100.100.108.255 Mask:255.255.255.0 + inet6 addr: fe80::217:f2ff:fe0d:9ba8/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:1813272 errors:0 dropped:0 overruns:0 frame:0 + TX packets:1539207 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:1729725903 (1.6 GiB) TX bytes:1606599540 (1.4 GiB) + Memory:f2c20000-f2c40000 + +lo Link encap:Local Loopback + inet addr:127.0.0.1 Mask:255.0.0.0 + inet6 addr: ::1/128 Scope:Host + UP LOOPBACK RUNNING MTU:16436 Metric:1 + RX packets:482 errors:0 dropped:0 overruns:0 frame:0 + TX packets:482 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:48488 (47.3 KiB) TX bytes:48488 (47.3 KiB)
\ No newline at end of file diff --git a/spec/fixtures/ifconfig/fedora_13_eth0 b/spec/fixtures/ifconfig/fedora_13_eth0 new file mode 100644 index 0000000..ca7afd9 --- /dev/null +++ b/spec/fixtures/ifconfig/fedora_13_eth0 @@ -0,0 +1,9 @@ +eth0 Link encap:Ethernet HWaddr 00:17:F2:0D:9B:A8 + inet addr:100.100.108.27 Bcast:100.100.108.255 Mask:255.255.255.0 + inet6 addr: fe80::217:f2ff:fe0d:9ba8/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:1813275 errors:0 dropped:0 overruns:0 frame:0 + TX packets:1539208 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:1729726282 (1.6 GiB) TX bytes:1606599653 (1.4 GiB) + Memory:f2c20000-f2c40000
\ No newline at end of file diff --git a/spec/fixtures/ifconfig/fedora_8 b/spec/fixtures/ifconfig/fedora_8 new file mode 100644 index 0000000..f54caa4 --- /dev/null +++ b/spec/fixtures/ifconfig/fedora_8 @@ -0,0 +1,38 @@ +eth0 Link encap:Ethernet HWaddr 00:18:F3:F6:33:E5 + inet addr:64.71.191.242 Bcast:64.71.191.247 Mask:255.255.255.248 + inet6 addr: fe80::218:f3ff:fef6:33e5/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:834422948 errors:0 dropped:0 overruns:0 frame:0 + TX packets:1241890353 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:3777804409 (3.5 GiB) TX bytes:2061587234 (1.9 GiB) + Interrupt:21 + +eth0:0 Link encap:Ethernet HWaddr 00:18:F3:F6:33:E5 + inet addr:64.71.191.243 Bcast:64.71.191.247 Mask:255.255.255.248 + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + Interrupt:21 + +eth0:1 Link encap:Ethernet HWaddr 00:18:F3:F6:33:E5 + inet addr:64.71.191.244 Bcast:64.71.191.247 Mask:255.255.255.248 + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + Interrupt:21 + +eth0:2 Link encap:Ethernet HWaddr 00:18:F3:F6:33:E5 + inet addr:64.71.191.245 Bcast:64.71.191.247 Mask:255.255.255.248 + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + Interrupt:21 + +eth0:3 Link encap:Ethernet HWaddr 00:18:F3:F6:33:E5 + inet addr:64.71.191.246 Bcast:64.71.191.247 Mask:255.255.255.248 + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + Interrupt:21 + +lo Link encap:Local Loopback + inet addr:127.0.0.1 Mask:255.0.0.0 + inet6 addr: ::1/128 Scope:Host + UP LOOPBACK RUNNING MTU:16436 Metric:1 + RX packets:59385736 errors:0 dropped:0 overruns:0 frame:0 + TX packets:59385736 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:3519026710 (3.2 GiB) TX bytes:3519026710 (3.2 GiB)
\ No newline at end of file diff --git a/spec/fixtures/ifconfig/fedora_8_eth0 b/spec/fixtures/ifconfig/fedora_8_eth0 new file mode 100644 index 0000000..a7789dc --- /dev/null +++ b/spec/fixtures/ifconfig/fedora_8_eth0 @@ -0,0 +1,9 @@ +eth0 Link encap:Ethernet HWaddr 00:18:F3:F6:33:E5 + inet addr:64.71.191.242 Bcast:64.71.191.247 Mask:255.255.255.248 + inet6 addr: fe80::218:f3ff:fef6:33e5/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:834423032 errors:0 dropped:0 overruns:0 frame:0 + TX packets:1241890434 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:3777811119 (3.5 GiB) TX bytes:2061606027 (1.9 GiB) + Interrupt:21
\ No newline at end of file diff --git a/spec/fixtures/ifconfig/freebsd_6_0 b/spec/fixtures/ifconfig/freebsd_6_0 new file mode 100644 index 0000000..3339a45 --- /dev/null +++ b/spec/fixtures/ifconfig/freebsd_6_0 @@ -0,0 +1,12 @@ +fxp0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500 + options=b<RXCSUM,TXCSUM,VLAN_MTU> + inet x.x.58.26 netmask 0xfffffff8 broadcast x.x.58.31 + inet x.x.58.27 netmask 0xffffffff broadcast x.x.58.27 + inet x.x.58.28 netmask 0xffffffff broadcast x.x.58.28 + inet x.x.58.29 netmask 0xffffffff broadcast x.x.58.29 + inet x.x.58.30 netmask 0xffffffff broadcast x.x.58.30 + ether 00:0e:0c:68:67:7c + media: Ethernet autoselect (100baseTX <full-duplex>) + status: active +lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384 + inet 127.0.0.1 netmask 0xff000000
\ No newline at end of file diff --git a/spec/fixtures/ifconfig/open_solaris_10 b/spec/fixtures/ifconfig/open_solaris_10 new file mode 100644 index 0000000..ed5dcbe --- /dev/null +++ b/spec/fixtures/ifconfig/open_solaris_10 @@ -0,0 +1,12 @@ +lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1 + inet 127.0.0.1 netmask ff000000 +hme0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2 + inet 192.168.2.83 netmask ffffff00 broadcast 192.168.2.255 + ether 8:0:20:d1:6d:79 +lo0: flags=2002000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv6,VIRTUAL> mtu 8252 index 1 + inet6 ::1/128 +hme0: flags=2000841<UP,RUNNING,MULTICAST,IPv6> mtu 1500 index 2 + inet6 fe80::a00:20ff:fed1:6d79/10 + ether 8:0:20:d1:6d:79 +hme0:1: flags=2080841<UP,RUNNING,MULTICAST,ADDRCONF,IPv6> mtu 1500 index 2 + inet6 2404:130:0:1000:a00:20ff:fed1:6d79/64
\ No newline at end of file diff --git a/spec/fixtures/ifconfig/open_solaris_b132 b/spec/fixtures/ifconfig/open_solaris_b132 new file mode 100644 index 0000000..c674a41 --- /dev/null +++ b/spec/fixtures/ifconfig/open_solaris_b132 @@ -0,0 +1,20 @@ +lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1 + inet 127.0.0.1 netmask ff000000 +bge0: flags=1100943<UP,BROADCAST,RUNNING,PROMISC,MULTICAST,ROUTER,IPv4> mtu 1500 index 2 + inet 202.78.241.97 netmask fffffff8 broadcast 202.78.241.103 + ether 0:1e:c9:43:55:f9 +int0: flags=1100843<UP,BROADCAST,RUNNING,MULTICAST,ROUTER,IPv4> mtu 9000 index 3 + inet 172.31.255.254 netmask ffffff00 broadcast 172.31.255.255 + ether 2:8:20:89:75:75 +lo0: flags=2002000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv6,VIRTUAL> mtu 8252 index 1 + inet6 ::1/128 +bge0: flags=2100941<UP,RUNNING,PROMISC,MULTICAST,ROUTER,IPv6> mtu 1500 index 2 + inet6 fe80::ff:0/10 + ether 0:1e:c9:43:55:f9 +bge0:1: flags=2180941<UP,RUNNING,PROMISC,MULTICAST,ADDRCONF,ROUTER,IPv6> mtu 1500 index 2 + inet6 2404:130:40:10::ff:0/64 +int0: flags=2100841<UP,RUNNING,MULTICAST,ROUTER,IPv6> mtu 9000 index 3 + inet6 fe80::ff:0/10 + ether 2:8:20:89:75:75 +int0:1: flags=2180841<UP,RUNNING,MULTICAST,ADDRCONF,ROUTER,IPv6> mtu 9000 index 3 + inet6 2404:130:40:18::ff:0/64
\ No newline at end of file diff --git a/spec/fixtures/ifconfig/ubuntu_7_04 b/spec/fixtures/ifconfig/ubuntu_7_04 new file mode 100644 index 0000000..8310576 --- /dev/null +++ b/spec/fixtures/ifconfig/ubuntu_7_04 @@ -0,0 +1,38 @@ +ath0 Link encap:Ethernet HWaddr 00:17:F2:49:E0:E6 + inet6 addr: fe80::217:f2ff:fe49:e0e6/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:0 errors:0 dropped:0 overruns:0 frame:0 + TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) + +ath0:avah Link encap:Ethernet HWaddr 00:17:F2:49:E0:E6 + inet addr:169.254.10.213 Bcast:169.254.255.255 Mask:255.255.0.0 + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + +eth0 Link encap:Ethernet HWaddr 00:16:CB:A6:D4:3A + inet addr:100.100.106.200 Bcast:100.100.106.255 Mask:255.255.255.0 + inet6 addr: fe80::216:cbff:fea6:d43a/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:1070 errors:0 dropped:0 overruns:0 frame:0 + TX packets:236 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:69905 (68.2 KiB) TX bytes:28435 (27.7 KiB) + Interrupt:17 + +lo Link encap:Local Loopback + inet addr:127.0.0.1 Mask:255.0.0.0 + inet6 addr: ::1/128 Scope:Host + UP LOOPBACK RUNNING MTU:16436 Metric:1 + RX packets:33 errors:0 dropped:0 overruns:0 frame:0 + TX packets:33 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:3067 (2.9 KiB) TX bytes:3067 (2.9 KiB) + +wifi0 Link encap:UNSPEC HWaddr 00-17-F2-49-E0-E6-00-00-00-00-00-00-00-00-00-00 + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:2655 errors:0 dropped:0 overruns:0 frame:24795 + TX packets:193 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:199 + RX bytes:754290 (736.6 KiB) TX bytes:8878 (8.6 KiB) + Interrupt:16
\ No newline at end of file diff --git a/spec/fixtures/ifconfig/ubuntu_7_04_eth0 b/spec/fixtures/ifconfig/ubuntu_7_04_eth0 new file mode 100644 index 0000000..b9fc759 --- /dev/null +++ b/spec/fixtures/ifconfig/ubuntu_7_04_eth0 @@ -0,0 +1,9 @@ +eth0 Link encap:Ethernet HWaddr 00:16:CB:A6:D4:3A + inet addr:100.100.106.200 Bcast:100.100.106.255 Mask:255.255.255.0 + inet6 addr: fe80::216:cbff:fea6:d43a/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:1131 errors:0 dropped:0 overruns:0 frame:0 + TX packets:280 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:73859 (72.1 KiB) TX bytes:35243 (34.4 KiB) + Interrupt:17
\ No newline at end of file diff --git a/spec/fixtures/netstat/centos_5_5 b/spec/fixtures/netstat/centos_5_5 new file mode 100644 index 0000000..f2c593e --- /dev/null +++ b/spec/fixtures/netstat/centos_5_5 @@ -0,0 +1,5 @@ +Kernel IP routing table +Destination Gateway Genmask Flags MSS Window irtt Iface +100.100.100.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 +169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 +0.0.0.0 100.100.100.1 0.0.0.0 UG 0 0 0 eth0
\ No newline at end of file diff --git a/spec/fixtures/netstat/darwin_10_3_0 b/spec/fixtures/netstat/darwin_10_3_0 new file mode 100644 index 0000000..62533e2 --- /dev/null +++ b/spec/fixtures/netstat/darwin_10_3_0 @@ -0,0 +1,35 @@ +Routing tables + +Internet: +Destination Gateway Flags Refs Use Netif Expire +default 100.100.104.1 UGSc 21 0 en0 +100.100.104/24 link#4 UCS 11 0 en0 +100.100.104.1 0:26:f1:23:2d:0 UHLWI 21 70927 en0 1188 +100.100.104.12 127.0.0.1 UHS 2 109 lo0 +100.100.104.16 0:1d:4f:44:cf:8 UHLWI 0 1369 en0 700 +100.100.104.48 0:1d:4f:45:5a:8c UHLWI 0 2 en0 1173 +100.100.104.52 0:1d:4f:44:ef:e0 UHLWI 0 184 en0 543 +100.100.104.62 0:1d:4f:45:5f:8c UHLWI 0 4 en0 478 +100.100.104.67 0:1d:4f:45:97:2c UHLWI 0 75 en0 851 +100.100.104.71 0:1d:4f:45:4a:b4 UHLWI 0 12 en0 890 +100.100.104.76 0:1d:4f:45:99:a8 UHLWI 0 2 en0 1056 +100.100.104.154 0:25:64:c1:d6:35 UHLWI 0 2640 en0 1200 +100.100.104.157 0:25:64:c1:cf:67 UHLWI 0 1 en0 1054 +100.100.104.255 ff:ff:ff:ff:ff:ff UHLWbI 0 2 en0 +127 127.0.0.1 UCS 0 0 lo0 +127.0.0.1 127.0.0.1 UH 0 10 lo0 +169.254 link#4 UCS 0 0 en0 +172.16.95/24 link#7 UC 0 0 vmnet8 +172.16.201/24 link#8 UC 0 0 vmnet1 + +Internet6: +Destination Gateway Flags Netif Expire +::1 ::1 UH lo0 +fe80::%lo0/64 fe80::1%lo0 Uc lo0 +fe80::1%lo0 link#1 UHL lo0 +fe80::%en0/64 link#4 UC en0 +fe80::217:f2ff:fe06:e3c2%en0 0:17:f2:6:e3:c2 UHL lo0 +ff01::/32 ::1 Um lo0 +ff02::/32 ::1 UmC lo0 +ff02::/32 link#4 UmC en0 +ff02::fb link#4 UHmLW en0
\ No newline at end of file diff --git a/spec/fixtures/netstat/darwin_10_6_4 b/spec/fixtures/netstat/darwin_10_6_4 new file mode 100644 index 0000000..ad1537e --- /dev/null +++ b/spec/fixtures/netstat/darwin_10_6_4 @@ -0,0 +1,29 @@ +Routing tables + +Internet: +Destination Gateway Flags Refs Use Netif Expire +default imana.puppetlabs.l UGSc 18 0 en1 +127 localhost UCS 0 0 lo0 +localhost localhost UH 2 161629 lo0 +169.254 link#5 UCS 0 0 en1 +172.16.38/24 link#9 UC 1 0 vmnet8 +172.16.38.255 ff:ff:ff:ff:ff:ff UHLWbI 1 2 vmnet8 +172.16.135/24 link#8 UC 1 0 vmnet1 +172.16.135.255 ff:ff:ff:ff:ff:ff UHLWbI 0 2 vmnet1 +192.168.100 link#5 UCS 17 0 en1 +imana.puppetlabs.l 0:25:bc:e2:e:56 UHLWI 9 12 en1 1145 +odys-iphone.puppet 5c:59:48:16:37:86 UHLWI 0 0 en1 1159 +reinh.puppetlabs.l localhost UHS 0 0 lo0 +192.168.100.255 ff:ff:ff:ff:ff:ff UHLWbI 0 2 en1 + +Internet6: +Destination Gateway Flags Netif Expire +localhost localhost UH lo0 +fe80::%lo0 localhost Uc lo0 +localhost link#1 UHL lo0 +fe80::%en1 link#5 UC en1 +fe80::226:b0ff:fef 0:26:b0:f9:ef:cb UHLW en1 +reinh.local 58:b0:35:7f:25:b3 UHL lo0 +ff01:: localhost Um lo0 +ff02:: localhost UmC lo0 +ff02:: link#5 UmC en1 diff --git a/spec/fixtures/netstat/darwin_9_8_0 b/spec/fixtures/netstat/darwin_9_8_0 new file mode 100644 index 0000000..d552d3d --- /dev/null +++ b/spec/fixtures/netstat/darwin_9_8_0 @@ -0,0 +1,28 @@ +Routing tables + +Internet: +Destination Gateway Flags Refs Use Netif Expire +default 100.100.107.1 UGSc 25 45789 en0 +100.100.107/24 link#4 UCS 3 0 en0 +100.100.107.1 0:26:f1:23:2d:0 UHLW 25 212733 en0 687 +100.100.107.4 127.0.0.1 UHS 0 332 lo0 +100.100.107.6 0:17:f2:6:e3:b0 UHLW 0 633 en0 1168 +100.100.107.255 ff:ff:ff:ff:ff:ff UHLWb 0 6 en0 +127 127.0.0.1 UCS 0 0 lo0 +127.0.0.1 127.0.0.1 UH 3 230 lo0 +169.254 link#4 UCS 0 0 en0 +192.168.61 link#8 UC 1 0 vmnet1 +192.168.61.255 ff:ff:ff:ff:ff:ff UHLWb 0 6 vmnet1 +192.168.210 link#7 UC 1 0 vmnet8 +192.168.210.255 ff:ff:ff:ff:ff:ff UHLWb 0 6 vmnet8 + +Internet6: +Destination Gateway Flags Netif Expire +::1 link#1 UHL lo0 +fe80::%lo0/64 fe80::1%lo0 Uc lo0 +fe80::1%lo0 link#1 UHL lo0 +fe80::%en0/64 link#4 UC en0 +fe80::217:f2ff:fe06:e42e%en0 0:17:f2:6:e4:2e UHL lo0 +ff01::/32 ::1 U lo0 +ff02::/32 fe80::1%lo0 UC lo0 +ff02::/32 link#4 UC en0
\ No newline at end of file diff --git a/spec/fixtures/netstat/fedora_10 b/spec/fixtures/netstat/fedora_10 new file mode 100644 index 0000000..991bc3a --- /dev/null +++ b/spec/fixtures/netstat/fedora_10 @@ -0,0 +1,7 @@ +Kernel IP routing table +Destination Gateway Genmask Flags MSS Window irtt Iface +172.16.131.0 0.0.0.0 255.255.255.0 U 0 0 0 vmnet1 +192.168.183.0 0.0.0.0 255.255.255.0 U 0 0 0 vmnet8 +100.100.108.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 +169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 +0.0.0.0 100.100.108.1 0.0.0.0 UG 0 0 0 eth0
\ No newline at end of file diff --git a/spec/fixtures/netstat/open_solaris_10 b/spec/fixtures/netstat/open_solaris_10 new file mode 100644 index 0000000..7e50620 --- /dev/null +++ b/spec/fixtures/netstat/open_solaris_10 @@ -0,0 +1,16 @@ +Routing Table: IPv4 + Destination Gateway Flags Ref Use Interface +-------------------- -------------------- ----- ----- ---------- --------- +default 192.168.2.1 UG 1 10 +192.168.2.0 192.168.2.83 U 1 1022 hme0 +224.0.0.0 192.168.2.83 U 1 0 hme0 +127.0.0.1 127.0.0.1 UH 1 0 lo0 + +Routing Table: IPv6 + Destination/Mask Gateway Flags Ref Use If +--------------------------- --------------------------- ----- --- ------- ----- +2404:130:0:1000::/64 2404:130:0:1000:a00:20ff:fed1:6d79 U 1 0 hme0:1 +fe80::/10 fe80::a00:20ff:fed1:6d79 U 1 0 hme0 +ff00::/8 fe80::a00:20ff:fed1:6d79 U 1 0 hme0 +default fe80::214:22ff:fe0a:1c46 UG 1 0 hme0 +::1 ::1 UH 1 140 lo0
\ No newline at end of file diff --git a/spec/fixtures/netstat/open_solaris_b132 b/spec/fixtures/netstat/open_solaris_b132 new file mode 100644 index 0000000..a75fab6 --- /dev/null +++ b/spec/fixtures/netstat/open_solaris_b132 @@ -0,0 +1,17 @@ +Routing Table: IPv4 + Destination Gateway Flags Ref Use Interface +-------------------- -------------------- ----- ----- ---------- --------- +default 202.78.241.102 UG 4 56215415 +127.0.0.1 127.0.0.1 UH 2 15396 lo0 +172.31.255.0 172.31.255.254 U 12 62487076 int0 +202.78.241.96 202.78.241.97 U 6 2213722 bge0 + +Routing Table: IPv6 + Destination/Mask Gateway Flags Ref Use If +--------------------------- --------------------------- ----- --- ------- ----- +::1 ::1 UH 2 4 lo0 +2404:130:40:10::/64 2404:130:40:10::ff:0 U 4 1050430 bge0 +2404:130:40:18::/64 2404:130:40:18::ff:0 U 4 1302106 int0 +fe80::/10 fe80::ff:0 U 3 16283 int0 +fe80::/10 fe80::ff:0 U 5 314822 bge0 +default fe80::20d:edff:fe9d:782e UG 2 420100 bge0
\ No newline at end of file diff --git a/spec/fixtures/netstat/ubuntu_7_04 b/spec/fixtures/netstat/ubuntu_7_04 new file mode 100644 index 0000000..40b8060 --- /dev/null +++ b/spec/fixtures/netstat/ubuntu_7_04 @@ -0,0 +1,7 @@ +Kernel IP routing table +Destination Gateway Genmask Flags MSS Window irtt Iface +100.100.106.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 +169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 ath0 +169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 +0.0.0.0 100.100.106.1 0.0.0.0 UG 0 0 0 eth0 +0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 ath0
\ No newline at end of file diff --git a/spec/fixtures/virtual/proc_self_status/vserver_2_1/guest b/spec/fixtures/virtual/proc_self_status/vserver_2_1/guest new file mode 100644 index 0000000..760cc24 --- /dev/null +++ b/spec/fixtures/virtual/proc_self_status/vserver_2_1/guest @@ -0,0 +1,37 @@ +Name: cat +State: R (running) +SleepAVG: 58% +Tgid: 24671 +Pid: 24671 +PPid: 24670 +TracerPid: 0 +Uid: 0 0 0 0 +Gid: 0 0 0 0 +FDSize: 32 +Groups: 0 +VmPeak: 1580 kB +VmSize: 1580 kB +VmLck: 0 kB +VmHWM: 372 kB +VmRSS: 372 kB +VmData: 152 kB +VmStk: 88 kB +VmExe: 16 kB +VmLib: 1280 kB +VmPTE: 12 kB +Threads: 1 +SigQ: 0/4294967295 +SigPnd: 0000000000000000 +ShdPnd: 0000000000000000 +SigBlk: 0000000000000000 +SigIgn: 0000000000000000 +SigCgt: 0000000000000000 +CapInh: 0000000000000000 +CapPrm: 00000000344c04ff +CapEff: 00000000344c04ff +s_context: 40074 +ctxflags: 1602020010 +initpid: 0 +ipv4root: 4a00007f/ffffffff 4a24f6d5/00ffffff +ipv4root_bcast: 00000000 + diff --git a/spec/fixtures/virtual/proc_self_status/vserver_2_1/host b/spec/fixtures/virtual/proc_self_status/vserver_2_1/host new file mode 100644 index 0000000..61a0845 --- /dev/null +++ b/spec/fixtures/virtual/proc_self_status/vserver_2_1/host @@ -0,0 +1,36 @@ +Name: cat +State: R (running) +SleepAVG: 88% +Tgid: 24625 +Pid: 24625 +PPid: 24618 +TracerPid: 0 +Uid: 47000 47000 47000 47000 +Gid: 4733 4733 4733 4733 +FDSize: 32 +Groups: 0 4733 +VmPeak: 1768 kB +VmSize: 1768 kB +VmLck: 0 kB +VmHWM: 396 kB +VmRSS: 396 kB +VmData: 160 kB +VmStk: 88 kB +VmExe: 28 kB +VmLib: 1468 kB +VmPTE: 12 kB +Threads: 1 +SigQ: 0/4294967295 +SigPnd: 0000000000000000 +ShdPnd: 0000000000000000 +SigBlk: 0000000000000000 +SigIgn: 0000000000000000 +SigCgt: 0000000000000000 +CapInh: 0000000000000000 +CapPrm: 0000000000000000 +CapEff: 0000000000000000 +s_context: 0 +ctxflags: none +initpid: none +ipv4root: 0 +ipv4root_bcast: 0 diff --git a/spec/fixtures/virtual/proc_self_status/vserver_2_3/guest b/spec/fixtures/virtual/proc_self_status/vserver_2_3/guest new file mode 100644 index 0000000..7567c38 --- /dev/null +++ b/spec/fixtures/virtual/proc_self_status/vserver_2_3/guest @@ -0,0 +1,39 @@ +Name: cat +State: R (running) +Tgid: 21149 +Pid: 21149 +PPid: 21142 +TracerPid: 0 +Uid: 0 0 0 0 +Gid: 0 0 0 0 +FDSize: 64 +Groups: 0 +VmPeak: 1564 kB +VmSize: 1564 kB +VmLck: 0 kB +VmHWM: 384 kB +VmRSS: 384 kB +VmData: 160 kB +VmStk: 84 kB +VmExe: 16 kB +VmLib: 1284 kB +VmPTE: 20 kB +Threads: 1 +SigQ: 0/71680 +SigPnd: 0000000000000000 +ShdPnd: 0000000000000000 +SigBlk: 0000000000000000 +SigIgn: 0000000000000000 +SigCgt: 0000000000000000 +CapInh: 0000000000000000 +CapPrm: fffffffffffffeff +CapEff: fffffffffffffeff +CapBnd: fffffffffffffeff +Cpus_allowed: ff +Cpus_allowed_list: 0-7 +Mems_allowed: 1 +Mems_allowed_list: 0 +VxID: 40128 +NxID: 40128 +voluntary_ctxt_switches: 1 +nonvoluntary_ctxt_switches: 0 diff --git a/spec/fixtures/virtual/proc_self_status/vserver_2_3/host b/spec/fixtures/virtual/proc_self_status/vserver_2_3/host new file mode 100644 index 0000000..15b17e9 --- /dev/null +++ b/spec/fixtures/virtual/proc_self_status/vserver_2_3/host @@ -0,0 +1,39 @@ +Name: cat +State: R (running) +Tgid: 21074 +Pid: 21074 +PPid: 21020 +TracerPid: 0 +Uid: 47000 47000 47000 47000 +Gid: 4733 4733 4733 4733 +FDSize: 64 +Groups: 0 4733 +VmPeak: 3800 kB +VmSize: 3800 kB +VmLck: 0 kB +VmHWM: 468 kB +VmRSS: 468 kB +VmData: 176 kB +VmStk: 84 kB +VmExe: 32 kB +VmLib: 1432 kB +VmPTE: 28 kB +Threads: 1 +SigQ: 0/71680 +SigPnd: 0000000000000000 +ShdPnd: 0000000000000000 +SigBlk: 0000000000000000 +SigIgn: 0000000000000000 +SigCgt: 0000000000000000 +CapInh: 0000000000000000 +CapPrm: 0000000000000000 +CapEff: 0000000000000000 +CapBnd: fffffffffffffeff +Cpus_allowed: ff +Cpus_allowed_list: 0-7 +Mems_allowed: 1 +Mems_allowed_list: 0 +VxID: 0 +NxID: 0 +voluntary_ctxt_switches: 2 +nonvoluntary_ctxt_switches: 0 diff --git a/spec/unit/facter.rb b/spec/unit/facter.rb index 9f7b4cf..20f9ed1 100755 --- a/spec/unit/facter.rb +++ b/spec/unit/facter.rb @@ -135,6 +135,14 @@ describe Facter 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 @@ -204,6 +212,25 @@ describe Facter do end 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 + end + describe "when registering directories to search" do after { Facter.instance_variable_set("@search_path", []) } diff --git a/spec/unit/util/macaddress.rb b/spec/unit/util/macaddress.rb new file mode 100644 index 0000000..8349b36 --- /dev/null +++ b/spec/unit/util/macaddress.rb @@ -0,0 +1,75 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'facter/util/macaddress' + +context "Darwin" do + test_cases = [ + # version, iface, real macaddress, fallback macaddress + ["9.8.0", 'en0', "00:17:f2:06:e4:2e", "00:17:f2:06:e4:2e"], + ["10.3.0", 'en0', "00:17:f2:06:e3:c2", "00:17:f2:06:e3:c2"], + ["10.6.4", 'en1', "58:b0:35:7f:25:b3", "58:b0:35:fa:08:b1"] + ] + + test_cases.each do |version, default_iface, macaddress, fallback_macaddress| + netstat_file = File.join(SPECDIR, "fixtures", "netstat", "darwin_#{version.tr('.', '_')}") + ifconfig_file_no_iface = File.join(SPECDIR, "fixtures", "ifconfig", "darwin_#{version.tr('.', '_')}") + ifconfig_file = "#{ifconfig_file_no_iface}_#{default_iface}" + + context "version #{version}" do + + describe Facter::Util::Macaddress::Darwin do + + describe ".default_interface" do + context "when netstat has a default interface" do + + before do + Facter::Util::Macaddress::Darwin.stubs(:netstat_command).returns("cat #{netstat_file}") + end + + it "should return the default interface name" do + Facter::Util::Macaddress::Darwin.default_interface.should == default_iface + end + end + + end + + describe ".macaddress" do + context "when netstat has a default interface" do + before do + Facter.stubs(:warn) + Facter::Util::Macaddress::Darwin.stubs(:default_interface).returns('') + Facter::Util::Macaddress::Darwin.stubs(:ifconfig_command).returns("cat #{ifconfig_file}") + end + + it "should return the macaddress of the default interface" do + Facter::Util::Macaddress::Darwin.macaddress.should == macaddress + end + + end + + context "when netstat does not have a default interface" do + before do + Facter::Util::Macaddress::Darwin.stubs(:default_interface).returns("") + Facter::Util::Macaddress::Darwin.stubs(:ifconfig_command).returns("cat #{ifconfig_file_no_iface}") + end + + it "should warn about the lack of default" do + Facter.expects(:warn).with("Could not find a default route. Using first non-loopback interface") + Facter::Util::Macaddress::Darwin.stubs(:default_interface).returns('') + Facter::Util::Macaddress::Darwin.macaddress + end + + it "should return the macaddress of the first non-loopback interface" do + Facter::Util::Macaddress::Darwin.macaddress.should == fallback_macaddress + end + + end + end + + end + + end + end +end diff --git a/spec/unit/util/virtual.rb b/spec/unit/util/virtual.rb index 57ef440..72186f7 100644 --- a/spec/unit/util/virtual.rb +++ b/spec/unit/util/virtual.rb @@ -57,6 +57,26 @@ describe Facter::Util::Virtual do 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| + context "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) @@ -101,6 +121,7 @@ describe Facter::Util::Virtual do 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 diff --git a/spec/unit/virtual.rb b/spec/unit/virtual.rb index ee673be..a7767c9 100644 --- a/spec/unit/virtual.rb +++ b/spec/unit/virtual.rb @@ -40,43 +40,49 @@ 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 + 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 + 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 + Facter.fact(:is_virtual).value.should == "true" end it "should be true when running on openvz" do Facter.fact(:kernel).stubs(:value).returns("Linux") Facter.fact(:virtual).stubs(:value).returns("openvzve") - Facter.fact(:is_virtual).value.should == true + 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 + 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 + 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 + Facter.fact(:is_virtual).value.should == "true" end end |