Imported Upstream version 1.7.3
Stig Sandbeck Mathisen
10 years ago
19 | 19 | See the [Adding Facts](http://docs.puppetlabs.com/guides/custom_facts.html) |
20 | 20 | page for details of how to add your own custom facts to Facter. |
21 | 21 | |
22 | Running Specs | |
23 | ------------- | |
24 | ||
25 | * bundle install --path .bundle/gems | |
26 | * bundle exec rake spec | |
27 | ||
28 | Note: external facts in the system facts.d directory can cause spec failures. | |
29 | ||
22 | 30 | Further Information |
23 | 31 | ------------------- |
24 | 32 |
9 | 9 | |
10 | 10 | begin |
11 | 11 | load File.join(File.dirname(__FILE__), 'ext', 'packaging', 'packaging.rake') |
12 | require 'rubygems' | |
13 | require 'rspec' | |
14 | require 'rspec/core/rake_task' | |
15 | require 'rcov' | |
16 | 12 | rescue LoadError |
13 | end | |
14 | ||
15 | ['rubygems', | |
16 | 'rspec', | |
17 | 'rspec/core/rake_task', | |
18 | 'rcov',].each do |lib| | |
19 | begin | |
20 | require lib | |
21 | rescue LoadError | |
22 | end | |
17 | 23 | end |
18 | 24 | |
19 | 25 | Dir['tasks/**/*.rake'].each { |t| load t } |
0 | test_name "Running facter should not output anything to stderr" | |
1 | ||
2 | on(hosts, facter) do |result| | |
3 | fail_test "Hostname fact is missing" unless stdout =~ /hostname\s*=>\s*\S*/ | |
4 | fail_test "Facter should not have written to stderr: #{stderr}" unless stderr == "" | |
5 | end |
8 | 8 | gpg_key: '4BD6EC30' |
9 | 9 | sign_tar: FALSE |
10 | 10 | # a space separated list of mock configs |
11 | final_mocks: 'pl-el-5-i386 pl-el-5-x86_64 pl-el-6-i386 pl-el-6-x86_64 pl-fedora-17-i386 pl-fedora-17-x86_64 pl-fedora-18-i386 pl-fedora-18-x86_64' | |
12 | yum_host: 'burji.puppetlabs.com' | |
11 | final_mocks: 'pl-el-5-i386 pl-el-5-x86_64 pl-el-6-i386 pl-el-6-x86_64 pl-fedora-17-i386 pl-fedora-17-x86_64 pl-fedora-18-i386 pl-fedora-18-x86_64 pl-fedora-19-i386 pl-fedora-19-x86_64' | |
12 | yum_host: 'yum.puppetlabs.com' | |
13 | 13 | yum_repo_path: '/opt/repository/yum/' |
14 | 14 | build_gem: TRUE |
15 | 15 | build_dmg: TRUE |
16 | 16 | build_ips: TRUE |
17 | apt_host: 'burji.puppetlabs.com' | |
17 | apt_host: 'apt.puppetlabs.com' | |
18 | 18 | apt_repo_url: 'http://apt.puppetlabs.com' |
19 | 19 | apt_repo_path: '/opt/repository/incoming' |
20 | 20 | ips_repo: '/var/pkgrepo' |
21 | 21 | ips_store: '/opt/repository' |
22 | 22 | ips_host: 'solaris-11-ips-repo.acctest.dc1.puppetlabs.net' |
23 | tar_host: 'downloads.puppetlabs.com' |
0 | facter (1.7.2-1puppetlabs1) hardy lucid oneiric unstable sid wheezy lucid squeeze precise quantal; urgency=low | |
0 | facter (1.7.3-1puppetlabs1) lucid unstable sid wheezy lucid squeeze precise quantal raring; urgency=low | |
1 | 1 | |
2 | 2 | * Update to version |
3 | 3 | |
4 | -- Puppet Labs Release <info@puppetlabs.com> Wed, 10 Jul 2013 23:00:17 +0000 | |
4 | -- Puppet Labs Release <info@puppetlabs.com> Mon, 09 Sep 2013 16:24:04 -0700 | |
5 | ||
6 | facter (1.7.2-1puppetlabs2) lucid unstable sid wheezy lucid squeeze precise; urgency=low | |
7 | ||
8 | * Remove dependenices on libssl-ruby from facter as they are not used | |
9 | ||
10 | -- Matthaus Owens <matthaus@puppetlabs.com> Thu, 11 Jul 2013 13:11:30 +0000 | |
5 | 11 | |
6 | 12 | facter (1.7.0-0.1rc1puppetlabs1) hardy lucid oneiric unstable sid wheezy lucid squeeze precise; urgency=low |
7 | 13 |
1 | 1 | Section: ruby |
2 | 2 | Priority: optional |
3 | 3 | Maintainer: Puppet Labs <info@puppetlabs.com> |
4 | Build-Depends: cdbs, debhelper (>> 7), ruby | ruby-interpreter, libopenssl-ruby | libopenssl-ruby1.8 | libopenssl-ruby1.9.1, rdoc | |
4 | Build-Depends: cdbs, debhelper (>> 7), ruby | ruby-interpreter | |
5 | 5 | Standards-Version: 3.9.1 |
6 | 6 | Homepage: http://www.puppetlabs.com |
7 | 7 | |
8 | 8 | Package: facter |
9 | 9 | Architecture: any |
10 | Depends: ${shlibs:Depends}, ${misc:Depends}, ruby | ruby-interpreter, libopenssl-ruby | libopenssl-ruby1.8 | libopenssl-ruby1.9.1, dmidecode [i386 amd64 ia64], virt-what, pciutils | |
10 | Depends: ${shlibs:Depends}, ${misc:Depends}, ruby | ruby-interpreter, dmidecode [i386 amd64 ia64], virt-what, pciutils | |
11 | 11 | Description: Ruby module for collecting simple facts about a host operating system |
12 | 12 | Some of the facts are preconfigured, such as the hostname and the operating |
13 | 13 | system. Additional facts can be added through simple Ruby scripts. |
0 | set name=pkg.fmri value=pkg://puppetlabs.com/application/facter@1.7.2,11.4.2-0 | |
0 | set name=pkg.fmri value=pkg://puppetlabs.com/application/facter@1.7.3,11.4.2-0 | |
1 | 1 | set name=pkg.summary value="Facter, a system inventory tool" |
2 | set name=pkg.human-version value="1.7.2" | |
2 | set name=pkg.human-version value="1.7.3" | |
3 | 3 | set name=pkg.description value="You can prove anything with facts!" |
4 | 4 | set name=info.classification value="org.opensolaris.category.2008:Applications/System Utilities" |
5 | 5 | set name=org.opensolaris.consolidation value="puppet" |
0 | <?xml version="1.0" encoding="UTF-8"?> | |
1 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
2 | <plist version="1.0"> | |
3 | <dict> | |
4 | <key>CFBundleIdentifier</key> | |
5 | <string>com.reductivelabs.facter</string> | |
6 | <key>CFBundleShortVersionString</key> | |
7 | <string>{SHORTVERSION}</string> | |
8 | <key>IFMajorVersion</key> | |
9 | <integer>{MAJORVERSION}</integer> | |
10 | <key>IFMinorVersion</key> | |
11 | <integer>{MINORVERSION}</integer> | |
12 | <key>IFPkgFlagAllowBackRev</key> | |
13 | <false/> | |
14 | <key>IFPkgFlagAuthorizationAction</key> | |
15 | <string>RootAuthorization</string> | |
16 | <key>IFPkgFlagDefaultLocation</key> | |
17 | <string>/</string> | |
18 | <key>IFPkgFlagFollowLinks</key> | |
19 | <true/> | |
20 | <key>IFPkgFlagInstallFat</key> | |
21 | <false/> | |
22 | <key>IFPkgFlagIsRequired</key> | |
23 | <false/> | |
24 | <key>IFPkgFlagOverwritePermissions</key> | |
25 | <false/> | |
26 | <key>IFPkgFlagRelocatable</key> | |
27 | <false/> | |
28 | <key>IFPkgFlagRestartAction</key> | |
29 | <string>None</string> | |
30 | <key>IFPkgFlagRootVolumeOnly</key> | |
31 | <true/> | |
32 | <key>IFPkgFlagUpdateInstalledLanguages</key> | |
33 | <false/> | |
34 | </dict> | |
35 | </plist> |
0 | #!/bin/bash | |
1 | # | |
2 | # Script to build an "old style" not flat pkg out of the facter repository. | |
3 | # | |
4 | # Author: Nigel Kersten (nigelk@google.com) | |
5 | # | |
6 | # Last Updated: 2008-07-31 | |
7 | # | |
8 | # Copyright 2008 Google Inc. | |
9 | # | |
10 | # Licensed under the Apache License, Version 2.0 (the "License"); | |
11 | # you may not use this file except in compliance with the License. | |
12 | # You may obtain a copy of the License at | |
13 | # | |
14 | # http://www.apache.org/licenses/LICENSE-2.0 | |
15 | # | |
16 | # Unless required by applicable law or agreed to in writing, software | |
17 | # distributed under the License is distributed on an "AS IS" BASIS, | |
18 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
19 | # See the License for the specific language governing permissions and | |
20 | # limitations under the License | |
21 | ||
22 | ||
23 | INSTALLRB="install.rb" | |
24 | BINDIR="/usr/bin" | |
25 | SITELIBDIR="/usr/lib/ruby/site_ruby/1.8" | |
26 | PACKAGEMAKER="/Developer/usr/bin/packagemaker" | |
27 | PROTO_PLIST="PackageInfo.plist" | |
28 | PREFLIGHT="preflight" | |
29 | ||
30 | ||
31 | function find_installer() { | |
32 | # we walk up three directories to make this executable from the root, | |
33 | # root/conf or root/conf/osx | |
34 | if [ -f "./${INSTALLRB}" ]; then | |
35 | installer="$(pwd)/${INSTALLRB}" | |
36 | elif [ -f "../${INSTALLRB}" ]; then | |
37 | installer="$(pwd)/../${INSTALLRB}" | |
38 | elif [ -f "../../${INSTALLRB}" ]; then | |
39 | installer="$(pwd)/../../${INSTALLRB}" | |
40 | else | |
41 | installer="" | |
42 | fi | |
43 | } | |
44 | ||
45 | function find_facter_root() { | |
46 | facter_root=$(dirname "${installer}") | |
47 | } | |
48 | ||
49 | function install_facter() { | |
50 | echo "Installing Facter to ${pkgroot}" | |
51 | cd "$facter_root" | |
52 | ./"${INSTALLRB}" --destdir="${pkgroot}" --bindir="${BINDIR}" --sitelibdir="${SITELIBDIR}" | |
53 | chown -R root:admin "${pkgroot}" | |
54 | } | |
55 | ||
56 | function install_docs() { | |
57 | echo "Installing docs to ${pkgroot}" | |
58 | docdir="${pkgroot}/usr/share/doc/facter" | |
59 | mkdir -p "${docdir}" | |
60 | for docfile in ChangeLog COPYING LICENSE README README.rst TODO; do | |
61 | install -m 0644 "${facter_root}/${docfile}" "${docdir}" | |
62 | done | |
63 | chown -R root:wheel "${docdir}" | |
64 | chmod 0755 "${docdir}" | |
65 | } | |
66 | ||
67 | function get_facter_version() { | |
68 | facter_version=$(RUBYLIB="${pkgroot}/${SITELIBDIR}:${RUBYLIB}" ruby -e "require 'facter'; puts Facter.version") | |
69 | } | |
70 | ||
71 | function prepare_package() { | |
72 | # As we can't specify to follow symlinks from the command line, we have | |
73 | # to go through the hassle of creating an Info.plist file for packagemaker | |
74 | # to look at for package creation and substitue the version strings out. | |
75 | # Major/Minor versions can only be integers, so we have "1" and "50" for | |
76 | # facter version 1.5 | |
77 | # Note too that for 10.5 compatibility this Info.plist *must* be set to | |
78 | # follow symlinks. | |
79 | VER1=$(echo ${facter_version} | awk -F "." '{print $1}') | |
80 | VER2=$(echo ${facter_version} | awk -F "." '{print $2}') | |
81 | VER3=$(echo ${facter_version} | awk -F "." '{print $3}') | |
82 | major_version="${VER1}" | |
83 | minor_version="${VER2}${VER3}" | |
84 | cp "${facter_root}/conf/osx/${PROTO_PLIST}" "${pkgtemp}" | |
85 | sed -i '' "s/{SHORTVERSION}/${facter_version}/g" "${pkgtemp}/${PROTO_PLIST}" | |
86 | sed -i '' "s/{MAJORVERSION}/${major_version}/g" "${pkgtemp}/${PROTO_PLIST}" | |
87 | sed -i '' "s/{MINORVERSION}/${minor_version}/g" "${pkgtemp}/${PROTO_PLIST}" | |
88 | ||
89 | # We need to create a preflight script to remove traces of previous | |
90 | # facter installs due to limitations in Apple's pkg format. | |
91 | mkdir "${pkgtemp}/scripts" | |
92 | cp "${facter_root}/conf/osx/${PREFLIGHT}" "${pkgtemp}/scripts" | |
93 | ||
94 | # substitute in the sitelibdir specified above on the assumption that this | |
95 | # is where any previous facter install exists that should be cleaned out. | |
96 | sed -i '' "s|{SITELIBDIR}|${SITELIBDIR}|g" "${pkgtemp}/scripts/${PREFLIGHT}" | |
97 | chmod 0755 "${pkgtemp}/scripts/${PREFLIGHT}" | |
98 | } | |
99 | ||
100 | function create_package() { | |
101 | rm -fr "$(pwd)/facter-${facter_version}.pkg" | |
102 | echo "Building package" | |
103 | echo "Note that packagemaker is reknowned for spurious errors. Don't panic." | |
104 | "${PACKAGEMAKER}" --root "${pkgroot}" \ | |
105 | --info "${pkgtemp}/${PROTO_PLIST}" \ | |
106 | --scripts ${pkgtemp}/scripts \ | |
107 | --out "$(pwd)/facter-${facter_version}.pkg" | |
108 | if [ $? -ne 0 ]; then | |
109 | echo "There was a problem building the package." | |
110 | cleanup_and_exit 1 | |
111 | exit 1 | |
112 | else | |
113 | echo "The package has been built at:" | |
114 | echo "$(pwd)/facter-${facter_version}.pkg" | |
115 | fi | |
116 | } | |
117 | ||
118 | function cleanup_and_exit() { | |
119 | if [ -d "${pkgroot}" ]; then | |
120 | rm -fr "${pkgroot}" | |
121 | fi | |
122 | if [ -d "${pkgtemp}" ]; then | |
123 | rm -fr "${pkgtemp}" | |
124 | fi | |
125 | exit $1 | |
126 | } | |
127 | ||
128 | # Program entry point | |
129 | function main() { | |
130 | ||
131 | if [ $(whoami) != "root" ]; then | |
132 | echo "This script needs to be run as root via su or sudo." | |
133 | cleanup_and_exit 1 | |
134 | fi | |
135 | ||
136 | find_installer | |
137 | ||
138 | if [ ! "${installer}" ]; then | |
139 | echo "Unable to find ${INSTALLRB}" | |
140 | cleanup_and_exit 1 | |
141 | fi | |
142 | ||
143 | find_facter_root | |
144 | ||
145 | if [ ! "${facter_root}" ]; then | |
146 | echo "Unable to find facter repository root." | |
147 | cleanup_and_exit 1 | |
148 | fi | |
149 | ||
150 | pkgroot=$(mktemp -d -t facterpkg) | |
151 | ||
152 | if [ ! "${pkgroot}" ]; then | |
153 | echo "Unable to create temporary package root." | |
154 | cleanup_and_exit 1 | |
155 | fi | |
156 | ||
157 | pkgtemp=$(mktemp -d -t factertmp) | |
158 | ||
159 | if [ ! "${pkgtemp}" ]; then | |
160 | echo "Unable to create temporary package root." | |
161 | cleanup_and_exit 1 | |
162 | fi | |
163 | ||
164 | install_facter | |
165 | get_facter_version | |
166 | ||
167 | if [ ! "${facter_version}" ]; then | |
168 | echo "Unable to retrieve facter version" | |
169 | cleanup_and_exit 1 | |
170 | fi | |
171 | ||
172 | prepare_package | |
173 | create_package | |
174 | ||
175 | cleanup_and_exit 0 | |
176 | } | |
177 | ||
178 | main "$@" |
0 | #!/bin/bash | |
1 | # | |
2 | # Make sure that old facter cruft is removed | |
3 | # This also allows us to downgrade facter as | |
4 | # it's more likely that installing old versions | |
5 | # over new will cause issues. | |
6 | # | |
7 | # ${3} is the destination volume so that this works correctly | |
8 | # when being installed to volumes other than the current OS. | |
9 | ||
10 | ||
11 | ||
12 | ||
13 | ||
14 | ||
15 | # remove libdir | |
16 | ||
17 | ||
18 | /bin/rm -Rf "${3}/facter/util/loader.rb" | |
19 | ||
20 | /bin/rm -Rf "${3}/facter/util/uptime.rb" | |
21 | ||
22 | /bin/rm -Rf "${3}/facter/util/virtual.rb" | |
23 | ||
24 | /bin/rm -Rf "${3}/facter/util/netmask.rb" | |
25 | ||
26 | /bin/rm -Rf "${3}/facter/util/nothing_loader.rb" | |
27 | ||
28 | /bin/rm -Rf "${3}/facter/util/macaddress.rb" | |
29 | ||
30 | /bin/rm -Rf "${3}/facter/util/cfpropertylist/README" | |
31 | ||
32 | /bin/rm -Rf "${3}/facter/util/cfpropertylist/THANKS" | |
33 | ||
34 | /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbCFTypes.rb" | |
35 | ||
36 | /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbCFPlistError.rb" | |
37 | ||
38 | /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbBinaryCFPropertyList.rb" | |
39 | ||
40 | /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbCFPropertyList.rb" | |
41 | ||
42 | /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbNokogiriParser.rb" | |
43 | ||
44 | /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbREXMLParser.rb" | |
45 | ||
46 | /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/cfpropertylist.rb" | |
47 | ||
48 | /bin/rm -Rf "${3}/facter/util/cfpropertylist/lib/rbLibXMLParser.rb" | |
49 | ||
50 | /bin/rm -Rf "${3}/facter/util/cfpropertylist/LICENSE" | |
51 | ||
52 | /bin/rm -Rf "${3}/facter/util/cfpropertylist/Rakefile" | |
53 | ||
54 | /bin/rm -Rf "${3}/facter/util/xendomains.rb" | |
55 | ||
56 | /bin/rm -Rf "${3}/facter/util/wmi.rb" | |
57 | ||
58 | /bin/rm -Rf "${3}/facter/util/file_read.rb" | |
59 | ||
60 | /bin/rm -Rf "${3}/facter/util/registry.rb" | |
61 | ||
62 | /bin/rm -Rf "${3}/facter/util/values.rb" | |
63 | ||
64 | /bin/rm -Rf "${3}/facter/util/parser.rb" | |
65 | ||
66 | /bin/rm -Rf "${3}/facter/util/vlans.rb" | |
67 | ||
68 | /bin/rm -Rf "${3}/facter/util/processor.rb" | |
69 | ||
70 | /bin/rm -Rf "${3}/facter/util/plist.rb" | |
71 | ||
72 | /bin/rm -Rf "${3}/facter/util/ec2.rb" | |
73 | ||
74 | /bin/rm -Rf "${3}/facter/util/manufacturer.rb" | |
75 | ||
76 | /bin/rm -Rf "${3}/facter/util/fact.rb" | |
77 | ||
78 | /bin/rm -Rf "${3}/facter/util/resolution.rb" | |
79 | ||
80 | /bin/rm -Rf "${3}/facter/util/collection.rb" | |
81 | ||
82 | /bin/rm -Rf "${3}/facter/util/memory.rb" | |
83 | ||
84 | /bin/rm -Rf "${3}/facter/util/ip.rb" | |
85 | ||
86 | /bin/rm -Rf "${3}/facter/util/solaris_zones.rb" | |
87 | ||
88 | /bin/rm -Rf "${3}/facter/util/cfpropertylist.rb" | |
89 | ||
90 | /bin/rm -Rf "${3}/facter/util/config.rb" | |
91 | ||
92 | /bin/rm -Rf "${3}/facter/util/monkey_patches.rb" | |
93 | ||
94 | /bin/rm -Rf "${3}/facter/util/plist/parser.rb" | |
95 | ||
96 | /bin/rm -Rf "${3}/facter/util/plist/generator.rb" | |
97 | ||
98 | /bin/rm -Rf "${3}/facter/util/directory_loader.rb" | |
99 | ||
100 | /bin/rm -Rf "${3}/facter/util/confine.rb" | |
101 | ||
102 | /bin/rm -Rf "${3}/facter/util/composite_loader.rb" | |
103 | ||
104 | /bin/rm -Rf "${3}/facter/util/macosx.rb" | |
105 | ||
106 | /bin/rm -Rf "${3}/facter/lsbrelease.rb" | |
107 | ||
108 | /bin/rm -Rf "${3}/facter/hardwareisa.rb" | |
109 | ||
110 | /bin/rm -Rf "${3}/facter/zonename.rb" | |
111 | ||
112 | /bin/rm -Rf "${3}/facter/lsbdistcodename.rb" | |
113 | ||
114 | /bin/rm -Rf "${3}/facter/kernelmajversion.rb" | |
115 | ||
116 | /bin/rm -Rf "${3}/facter/uptime_seconds.rb" | |
117 | ||
118 | /bin/rm -Rf "${3}/facter/interfaces.rb" | |
119 | ||
120 | /bin/rm -Rf "${3}/facter/augeasversion.rb" | |
121 | ||
122 | /bin/rm -Rf "${3}/facter/ipaddress6.rb" | |
123 | ||
124 | /bin/rm -Rf "${3}/facter/uptime.rb" | |
125 | ||
126 | /bin/rm -Rf "${3}/facter/virtual.rb" | |
127 | ||
128 | /bin/rm -Rf "${3}/facter/operatingsystem.rb" | |
129 | ||
130 | /bin/rm -Rf "${3}/facter/physicalprocessorcount.rb" | |
131 | ||
132 | /bin/rm -Rf "${3}/facter/ldom.rb" | |
133 | ||
134 | /bin/rm -Rf "${3}/facter/blockdevices.rb" | |
135 | ||
136 | /bin/rm -Rf "${3}/facter/netmask.rb" | |
137 | ||
138 | /bin/rm -Rf "${3}/facter/version.rb" | |
139 | ||
140 | /bin/rm -Rf "${3}/facter/uptime_days.rb" | |
141 | ||
142 | /bin/rm -Rf "${3}/facter/uptime_hours.rb" | |
143 | ||
144 | /bin/rm -Rf "${3}/facter/operatingsystemrelease.rb" | |
145 | ||
146 | /bin/rm -Rf "${3}/facter/selinux.rb" | |
147 | ||
148 | /bin/rm -Rf "${3}/facter/kernelversion.rb" | |
149 | ||
150 | /bin/rm -Rf "${3}/facter/macaddress.rb" | |
151 | ||
152 | /bin/rm -Rf "${3}/facter/xendomains.rb" | |
153 | ||
154 | /bin/rm -Rf "${3}/facter/hostname.rb" | |
155 | ||
156 | /bin/rm -Rf "${3}/facter/rubyversion.rb" | |
157 | ||
158 | /bin/rm -Rf "${3}/facter/path.rb" | |
159 | ||
160 | /bin/rm -Rf "${3}/facter/zones.rb" | |
161 | ||
162 | /bin/rm -Rf "${3}/facter/operatingsystemmajrelease.rb" | |
163 | ||
164 | /bin/rm -Rf "${3}/facter/vlans.rb" | |
165 | ||
166 | /bin/rm -Rf "${3}/facter/application.rb" | |
167 | ||
168 | /bin/rm -Rf "${3}/facter/processor.rb" | |
169 | ||
170 | /bin/rm -Rf "${3}/facter/id.rb" | |
171 | ||
172 | /bin/rm -Rf "${3}/facter/fqdn.rb" | |
173 | ||
174 | /bin/rm -Rf "${3}/facter/ec2.rb" | |
175 | ||
176 | /bin/rm -Rf "${3}/facter/architecture.rb" | |
177 | ||
178 | /bin/rm -Rf "${3}/facter/ssh.rb" | |
179 | ||
180 | /bin/rm -Rf "${3}/facter/ipaddress.rb" | |
181 | ||
182 | /bin/rm -Rf "${3}/facter/uniqueid.rb" | |
183 | ||
184 | /bin/rm -Rf "${3}/facter/manufacturer.rb" | |
185 | ||
186 | /bin/rm -Rf "${3}/facter/kernel.rb" | |
187 | ||
188 | /bin/rm -Rf "${3}/facter/kernelrelease.rb" | |
189 | ||
190 | /bin/rm -Rf "${3}/facter/timezone.rb" | |
191 | ||
192 | /bin/rm -Rf "${3}/facter/puppetversion.rb" | |
193 | ||
194 | /bin/rm -Rf "${3}/facter/rubysitedir.rb" | |
195 | ||
196 | /bin/rm -Rf "${3}/facter/facterversion.rb" | |
197 | ||
198 | /bin/rm -Rf "${3}/facter/filesystems.rb" | |
199 | ||
200 | /bin/rm -Rf "${3}/facter/lsbdistid.rb" | |
201 | ||
202 | /bin/rm -Rf "${3}/facter/memory.rb" | |
203 | ||
204 | /bin/rm -Rf "${3}/facter/lsbdistdescription.rb" | |
205 | ||
206 | /bin/rm -Rf "${3}/facter/network.rb" | |
207 | ||
208 | /bin/rm -Rf "${3}/facter/zpool_version.rb" | |
209 | ||
210 | /bin/rm -Rf "${3}/facter/zfs_version.rb" | |
211 | ||
212 | /bin/rm -Rf "${3}/facter/domain.rb" | |
213 | ||
214 | /bin/rm -Rf "${3}/facter/lsbdistrelease.rb" | |
215 | ||
216 | /bin/rm -Rf "${3}/facter/Cfkey.rb" | |
217 | ||
218 | /bin/rm -Rf "${3}/facter/osfamily.rb" | |
219 | ||
220 | /bin/rm -Rf "${3}/facter/ps.rb" | |
221 | ||
222 | /bin/rm -Rf "${3}/facter/hardwaremodel.rb" | |
223 | ||
224 | /bin/rm -Rf "${3}/facter/macosx.rb" | |
225 | ||
226 | /bin/rm -Rf "${3}/facter/lsbmajdistrelease.rb" | |
227 | ||
228 | /bin/rm -Rf "${3}/facter/iphostnumber.rb" | |
229 | ||
230 | /bin/rm -Rf "${3}/facter.rb" | |
231 | ||
232 | # remove bin files | |
233 | ||
234 | ||
235 | /bin/rm -Rf "${3}/facter" | |
236 | ||
237 | ||
238 | ||
239 | # remove old doc files | |
240 | /bin/rm -Rf "${3}/" |
0 | #!/bin/bash | |
1 | # | |
2 | # Make sure that old facter cruft is removed | |
3 | # This also allows us to downgrade facter as | |
4 | # it's more likely that installing old versions | |
5 | # over new will cause issues. | |
6 | # | |
7 | # ${3} is the destination volume so that this works correctly | |
8 | # when being installed to volumes other than the current OS. | |
9 | ||
10 | <% begin %> | |
11 | <% require 'rubygems' %> | |
12 | <% rescue LoadError %> | |
13 | <% end %> | |
14 | <% require 'rake' %> | |
15 | ||
16 | # remove libdir | |
17 | <% Dir.chdir("lib") %> | |
18 | <% FileList["**/*"].select {|i| File.file?(i)}.each do |file| %> | |
19 | /bin/rm -Rf "${3}<%= @apple_libdir %>/<%=file%>" | |
20 | <% end %> | |
21 | # remove bin files | |
22 | <% Dir.chdir("../bin") %> | |
23 | <% FileList["**/*"].select {|i| File.file?(i)}.each do |file| %> | |
24 | /bin/rm -Rf "${3}<%= @apple_bindir %>/<%=file%>" | |
25 | <% end %> | |
26 | <% Dir.chdir("..") %> | |
27 | ||
28 | # remove old doc files | |
29 | /bin/rm -Rf "${3}<%= @apple_docdir %>/<%=@package_name%>" |
0 | <?xml version="1.0" encoding="UTF-8"?> | |
1 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
2 | <plist version="1.0"> | |
3 | <dict> | |
4 | <key>CFBundleIdentifier</key> | |
5 | <string></string> | |
6 | <key>CFBundleShortVersionString</key> | |
7 | <string>1.7.2</string> | |
8 | <key>IFMajorVersion</key> | |
9 | <integer></integer> | |
10 | <key>IFMinorVersion</key> | |
11 | <integer></integer> | |
12 | <key>IFPkgBuildDate</key> | |
13 | <date></date> | |
14 | <key>IFPkgFlagAllowBackRev</key> | |
15 | <false/> | |
16 | <key>IFPkgFlagAuthorizationAction</key> | |
17 | <string>RootAuthorization</string> | |
18 | <key>IFPkgFlagDefaultLocation</key> | |
19 | <string>/</string> | |
20 | <key>IFPkgFlagFollowLinks</key> | |
21 | <true/> | |
22 | <key>IFPkgFlagInstallFat</key> | |
23 | <false/> | |
24 | <key>IFPkgFlagIsRequired</key> | |
25 | <false/> | |
26 | <key>IFPkgFlagOverwritePermissions</key> | |
27 | <false/> | |
28 | <key>IFPkgFlagRelocatable</key> | |
29 | <false/> | |
30 | <key>IFPkgFlagRestartAction</key> | |
31 | <string></string> | |
32 | <key>IFPkgFlagRootVolumeOnly</key> | |
33 | <true/> | |
34 | <key>IFPkgFlagUpdateInstalledLanguages</key> | |
35 | <false/> | |
36 | </dict> | |
37 | </plist> |
0 | <?xml version="1.0" encoding="UTF-8"?> | |
1 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
2 | <plist version="1.0"> | |
3 | <dict> | |
4 | <key>CFBundleIdentifier</key> | |
5 | <string><%= @title %></string> | |
6 | <key>CFBundleShortVersionString</key> | |
7 | <string><%= @version %></string> | |
8 | <key>IFMajorVersion</key> | |
9 | <integer><%= @package_major_version %></integer> | |
10 | <key>IFMinorVersion</key> | |
11 | <integer><%= @package_minor_version %></integer> | |
12 | <key>IFPkgBuildDate</key> | |
13 | <date><%= @build_date %></date> | |
14 | <key>IFPkgFlagAllowBackRev</key> | |
15 | <false/> | |
16 | <key>IFPkgFlagAuthorizationAction</key> | |
17 | <string>RootAuthorization</string> | |
18 | <key>IFPkgFlagDefaultLocation</key> | |
19 | <string>/</string> | |
20 | <key>IFPkgFlagFollowLinks</key> | |
21 | <true/> | |
22 | <key>IFPkgFlagInstallFat</key> | |
23 | <false/> | |
24 | <key>IFPkgFlagIsRequired</key> | |
25 | <false/> | |
26 | <key>IFPkgFlagOverwritePermissions</key> | |
27 | <false/> | |
28 | <key>IFPkgFlagRelocatable</key> | |
29 | <false/> | |
30 | <key>IFPkgFlagRestartAction</key> | |
31 | <string><%= @pm_restart %></string> | |
32 | <key>IFPkgFlagRootVolumeOnly</key> | |
33 | <true/> | |
34 | <key>IFPkgFlagUpdateInstalledLanguages</key> | |
35 | <false/> | |
36 | </dict> | |
37 | </plist> |
6 | 6 | %endif |
7 | 7 | |
8 | 8 | # VERSION is subbed out during rake srpm process |
9 | %global realversion 1.7.2 | |
10 | %global rpmversion 1.7.2 | |
9 | %global realversion 1.7.3 | |
10 | %global rpmversion 1.7.3 | |
11 | 11 | |
12 | 12 | Summary: Ruby module for collecting simple facts about a host operating system |
13 | 13 | Name: facter |
31 | 31 | Requires: pciutils |
32 | 32 | %endif |
33 | 33 | Requires: virt-what |
34 | Requires: ruby(abi) >= 1.8 | |
34 | Requires: ruby >= 1.8.5 | |
35 | 35 | BuildRequires: ruby >= 1.8.5 |
36 | 36 | |
37 | 37 | # In Fedora 17 ruby-rdoc is called rubygem-rdoc |
69 | 69 | |
70 | 70 | |
71 | 71 | %changelog |
72 | * Wed Jul 10 2013 Puppet Labs Release <info@puppetlabs.com> - 1:1.7.2-1 | |
73 | - Build for 1.7.2 | |
72 | * Mon Sep 09 2013 Puppet Labs Release <info@puppetlabs.com> - 1:1.7.3-1 | |
73 | - Build for 1.7.3 | |
74 | 74 | |
75 | 75 | * Mon Apr 01 2013 Matthaus Owens <matthaus@puppetlabs.com> - 1:1.7.0-0.1rc1 |
76 | 76 | - Add dependency on virt-what to facter for better virutalization detection |
59 | 59 | require 'facter' |
60 | 60 | @operatingsystem = Facter[:operatingsystem].value |
61 | 61 | |
62 | PREREQS = %w{openssl xmlrpc/client xmlrpc/server cgi} | |
62 | PREREQS = %w{cgi} | |
63 | 63 | |
64 | 64 | InstallOptions = OpenStruct.new |
65 | 65 |
28 | 28 | # Due to dangerous behavior of 'hostname -f' on old OS, we will explicitly opt-in |
29 | 29 | # 'hostname -f' --hkenney May 9, 2012 |
30 | 30 | basic_hostname = 'hostname 2> /dev/null' |
31 | windows_hostname = 'hostname > NUL' | |
31 | 32 | full_hostname = 'hostname -f 2> /dev/null' |
32 | 33 | can_do_hostname_f = Regexp.union /Linux/i, /FreeBSD/i, /Darwin/i |
33 | 34 | |
34 | 35 | hostname_command = if Facter.value(:kernel) =~ can_do_hostname_f |
35 | 36 | full_hostname |
37 | elsif Facter.value(:kernel) == "windows" | |
38 | windows_hostname | |
36 | 39 | else |
37 | 40 | basic_hostname |
38 | 41 | end |
41 | 44 | and name =~ /.*?\.(.+$)/ |
42 | 45 | |
43 | 46 | return_value = $1 |
44 | elsif domain = Facter::Util::Resolution.exec('dnsdomainname 2> /dev/null') \ | |
47 | elsif Facter.value(:kernel) != "windows" and domain = Facter::Util::Resolution.exec('dnsdomainname 2> /dev/null') \ | |
45 | 48 | and domain =~ /.+/ |
46 | 49 | |
47 | 50 | return_value = domain |
75 | 78 | if domain == "" |
76 | 79 | require 'facter/util/wmi' |
77 | 80 | Facter::Util::WMI.execquery("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").each { |nic| |
78 | domain = nic.DNSDomain | |
79 | break | |
81 | if nic.DNSDomain && nic.DNSDomain.length > 0 | |
82 | domain = nic.DNSDomain | |
83 | break | |
84 | end | |
80 | 85 | } |
81 | 86 | end |
87 | ||
88 | domain ||= '' | |
89 | ||
82 | 90 | domain.gsub(/\.$/, '') |
83 | 91 | end |
84 | 92 | end |
31 | 31 | # http://source.winehq.org/source/include/winnt.h#L568 |
32 | 32 | # http://msdn.microsoft.com/en-us/library/windows/desktop/aa394373(v=vs.85).aspx |
33 | 33 | # http://msdn.microsoft.com/en-us/library/windows/desktop/windows.system.processorarchitecture.aspx |
34 | # http://linux.derkeiler.com/Mailing-Lists/Kernel/2008-05/msg12924.html (anything over 6 is still i686) | |
34 | 35 | # Also, arm and neutral are included because they are valid for the upcoming |
35 | 36 | # windows 8 release. --jeffweiss 23 May 2012 |
36 | 37 | require 'facter/util/wmi' |
37 | 38 | model = "" |
39 | architecture_level = nil | |
40 | ||
38 | 41 | Facter::Util::WMI.execquery("select Architecture, Level, AddressWidth from Win32_Processor").each do |cpu| |
42 | architecture_level = (cpu.Level > 5) ? 6 : cpu.Level; | |
43 | ||
39 | 44 | model = |
40 | 45 | case cpu.Architecture |
41 | 46 | when 11 then 'neutral' # PROCESSOR_ARCHITECTURE_NEUTRAL |
42 | 47 | when 10 then 'i686' # PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 |
43 | 48 | when 9 then # PROCESSOR_ARCHITECTURE_AMD64 |
44 | cpu.AddressWidth == 32 ? "i#{cpu.Level}86" : 'x64' # 32 bit OS on 64 bit CPU | |
49 | cpu.AddressWidth == 32 ? "i#{architecture_level}86" : 'x64' # 32 bit OS on 64 bit CPU | |
45 | 50 | when 8 then 'msil' # PROCESSOR_ARCHITECTURE_MSIL |
46 | 51 | when 7 then 'alpha64' # PROCESSOR_ARCHITECTURE_ALPHA64 |
47 | 52 | when 6 then 'ia64' # PROCESSOR_ARCHITECTURE_IA64 |
50 | 55 | when 3 then 'powerpc' # PROCESSOR_ARCHITECTURE_PPC |
51 | 56 | when 2 then 'alpha' # PROCESSOR_ARCHITECTURE_ALPHA |
52 | 57 | when 1 then 'mips' # PROCESSOR_ARCHITECTURE_MIPS |
53 | when 0 then "i#{cpu.Level}86" # PROCESSOR_ARCHITECTURE_INTEL | |
58 | when 0 then "i#{architecture_level}86" # PROCESSOR_ARCHITECTURE_INTEL | |
54 | 59 | else 'unknown' # PROCESSOR_ARCHITECTURE_UNKNOWN |
55 | 60 | end |
56 | 61 | break |
32 | 32 | regexp = /inet (?:addr:)?([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ |
33 | 33 | output.split("\n").each do |line| |
34 | 34 | match = regexp.match(line) |
35 | if match | |
36 | break match[1] unless /^127/.match(match[1]) | |
35 | if match and not /^127\./.match(match[1]) | |
36 | ip = match[1] | |
37 | break | |
37 | 38 | end |
38 | 39 | end |
39 | 40 | end |
41 | ip | |
40 | 42 | end |
41 | 43 | end |
42 | 44 | |
103 | 105 | Facter.add(:ipaddress) do |
104 | 106 | confine :kernel => %w{windows} |
105 | 107 | setcode do |
106 | require 'socket' | |
107 | IPSocket.getaddress(Socket.gethostname) | |
108 | require 'facter/util/ip/windows' | |
109 | ipaddr = nil | |
110 | ||
111 | adapters = Facter::Util::IP::Windows.get_preferred_ipv4_adapters | |
112 | adapters.find do |nic| | |
113 | nic.IPAddress.any? do |addr| | |
114 | ipaddr = addr if Facter::Util::IP::Windows.valid_ipv4_address?(addr) | |
115 | ipaddr | |
116 | end | |
117 | end | |
118 | ||
119 | ipaddr | |
108 | 120 | end |
109 | 121 | end |
110 | 122 |
25 | 25 | def get_address_after_token(output, token, return_first=false) |
26 | 26 | ip = nil |
27 | 27 | |
28 | output.scan(/#{token} ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each do |match| | |
28 | String(output).scan(/#{token}\s?((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each do |match| | |
29 | 29 | match = match.first |
30 | 30 | unless match =~ /fe80.*/ or match == "::1" |
31 | 31 | ip = match |
65 | 65 | Facter.add(:ipaddress6) do |
66 | 66 | confine :kernel => :windows |
67 | 67 | setcode do |
68 | output = Facter::Util::Resolution.exec("#{ENV['SYSTEMROOT']}/system32/netsh.exe interface ipv6 show address level=verbose") | |
68 | require 'facter/util/ip/windows' | |
69 | ipaddr = nil | |
69 | 70 | |
70 | get_address_after_token(output, 'Address', true) | |
71 | adapters = Facter::Util::IP::Windows.get_preferred_ipv6_adapters | |
72 | adapters.find do |nic| | |
73 | nic.IPAddress.any? do |addr| | |
74 | ipaddr = addr if Facter::Util::IP::Windows.valid_ipv6_address?(addr) | |
75 | ipaddr | |
76 | end | |
77 | end | |
78 | ||
79 | ipaddr | |
71 | 80 | end |
72 | 81 | end |
28 | 28 | ether = [] |
29 | 29 | output = Facter::Util::IP.exec_ifconfig(["-a","2>/dev/null"]) |
30 | 30 | |
31 | output.each_line do |s| | |
31 | String(output).each_line do |s| | |
32 | 32 | ether.push($1) if s =~ /(?:ether|HWaddr) ((\w{1,2}:){5,}\w{1,2})/ |
33 | 33 | end |
34 | 34 | Facter::Util::Macaddress.standardize(ether[0]) |
20 | 20 | Facter::NetMask.get_netmask |
21 | 21 | end |
22 | 22 | end |
23 | ||
24 | Facter.add(:netmask) do | |
25 | confine :kernel => :windows | |
26 | setcode do | |
27 | require 'facter/util/ip/windows' | |
28 | ||
29 | mask = nil | |
30 | ||
31 | adapters = Facter::Util::IP::Windows.get_preferred_ipv4_adapters | |
32 | adapters.find do |nic| | |
33 | nic.IPSubnet.any? do |subnet| | |
34 | mask = subnet if Facter::Util::IP::Windows.valid_ipv4_address?(subnet) | |
35 | mask | |
36 | end | |
37 | end | |
38 | ||
39 | mask | |
40 | end | |
41 | end |
0 | 0 | # A Facter plugin that loads external facts. |
1 | 1 | # |
2 | 2 | # Default Unix Directories: |
3 | # /etc/facter/facts.d, /etc/puppetlbas/facter/facts.d | |
3 | # /etc/facter/facts.d", "/etc/puppetlabs/facter/facts.d" | |
4 | 4 | # |
5 | 5 | # Default Windows Direcotires: |
6 | 6 | # C:\ProgramData\Puppetlabs\facter\facts.d (2008) |
0 | # encoding: UTF-8 | |
1 | ||
2 | require 'facter/util/wmi' | |
3 | require 'facter/util/ip' | |
4 | ||
5 | class Facter::Util::IP::Windows | |
6 | # The WMI query used to return ip information | |
7 | # | |
8 | # @return [String] | |
9 | # | |
10 | # @api private | |
11 | WMI_IP_INFO_QUERY = 'SELECT Description, ServiceName, IPAddress, IPConnectionMetric, InterfaceIndex, Index, IPSubnet, MACAddress, MTU, SettingID FROM Win32_NetworkAdapterConfiguration WHERE IPConnectionMetric IS NOT NULL AND IPEnabled = TRUE' | |
12 | ||
13 | # Mapping fact names to WMI properties of the Win32_NetworkAdapterConfiguration | |
14 | # | |
15 | # @api private | |
16 | WINDOWS_LABEL_WMI_MAP = { | |
17 | :ipaddress => 'IPAddress', | |
18 | :ipaddress6 => 'IPAddress', | |
19 | :macaddress => 'MACAddress', | |
20 | :netmask => 'IPSubnet' | |
21 | } | |
22 | ||
23 | def self.to_s | |
24 | 'windows' | |
25 | end | |
26 | ||
27 | # Windows doesn't display netmask in hex. | |
28 | # | |
29 | # @return [Boolean] false by default | |
30 | # | |
31 | # @api private | |
32 | def self.convert_netmask_from_hex? | |
33 | false | |
34 | end | |
35 | ||
36 | # Retrieves a list of unique interfaces names. | |
37 | # | |
38 | # @return [Array<String>] | |
39 | # | |
40 | # @api private | |
41 | def self.interfaces | |
42 | interface_names = [] | |
43 | ||
44 | network_adapter_configurations.map do |nic| | |
45 | Facter::Util::WMI.execquery("SELECT * FROM Win32_NetworkAdapter WHERE Index = #{nic.Index}").each do |nic| | |
46 | interface_names << nic.NetConnectionId | |
47 | end | |
48 | end | |
49 | ||
50 | interface_names.uniq | |
51 | end | |
52 | ||
53 | # Get the value of an interface and label. For example, you may want to find | |
54 | # the MTU for eth0. | |
55 | # | |
56 | # @param [String] interface the name of the interface returned by the {#interfaces} method. | |
57 | # @param [String] label the type of value to return, e.g. ipaddress | |
58 | # @return [String] the value, or nil if not defined | |
59 | # | |
60 | # @api private | |
61 | def self.value_for_interface_and_label(interface, label) | |
62 | wmi_value = WINDOWS_LABEL_WMI_MAP[label.downcase.to_sym] | |
63 | label_value = nil | |
64 | Facter::Util::WMI.execquery("SELECT Index FROM Win32_NetworkAdapter WHERE NetConnectionID = '#{interface}'").each do |nic| | |
65 | Facter::Util::WMI.execquery("SELECT #{wmi_value} FROM Win32_NetworkAdapterConfiguration WHERE Index = #{nic.Index}").each do |nic_config| | |
66 | case label.downcase.to_sym | |
67 | when :ipaddress | |
68 | nic_config.IPAddress.any? do |addr| | |
69 | label_value = addr if valid_ipv4_address?(addr) | |
70 | label_value | |
71 | end | |
72 | when :ipaddress6 | |
73 | nic_config.IPAddress.any? do |addr| | |
74 | label_value = addr if Facter::Util::IP::Windows.valid_ipv6_address?(addr) | |
75 | label_value | |
76 | end | |
77 | when :netmask | |
78 | nic_config.IPSubnet.any? do |addr| | |
79 | label_value = addr if Facter::Util::IP::Windows.valid_ipv4_address?(addr) | |
80 | label_value | |
81 | end | |
82 | when :macaddress | |
83 | label_value = nic_config.MACAddress | |
84 | end | |
85 | end | |
86 | end | |
87 | ||
88 | label_value | |
89 | end | |
90 | ||
91 | # Returns an array of partial Win32_NetworkAdapterConfiguration objects. | |
92 | # | |
93 | # @return [Array<WIN32OLE>] objects | |
94 | # | |
95 | # @api private | |
96 | def self.network_adapter_configurations | |
97 | nics = [] | |
98 | # WIN32OLE doesn't implement Enumerable | |
99 | Facter::Util::WMI.execquery(WMI_IP_INFO_QUERY).each do |nic| | |
100 | nics << nic | |
101 | end | |
102 | nics | |
103 | end | |
104 | ||
105 | # Gets a list of active IPv4 network adapter configurations sorted by the | |
106 | # lowest IP connection metric. If two configurations have the same metric, | |
107 | # then the IPv4 specific binding order as specified in the registry will | |
108 | # be used. | |
109 | # | |
110 | # @return [Array<WIN32OLE>] | |
111 | # | |
112 | # @api private | |
113 | def self.get_preferred_ipv4_adapters | |
114 | get_preferred_network_adapters(Bindings4.new) | |
115 | end | |
116 | ||
117 | # Gets a list of active IPv6 network adapter configurations sorted by the | |
118 | # lowest IP connection metric. If two configurations have the same metric, | |
119 | # then the IPv6 specific binding order as specified in the registry will | |
120 | # be used. | |
121 | # | |
122 | # @return [Array<WIN32OLE>] | |
123 | # | |
124 | # @api private | |
125 | def self.get_preferred_ipv6_adapters | |
126 | get_preferred_network_adapters(Bindings6.new) | |
127 | end | |
128 | ||
129 | # Gets a list of active network adapter configurations sorted by the lowest | |
130 | # IP connection metric. If two configurations have the same metric, then | |
131 | # the adapter binding order as specified in the registry will be used. | |
132 | # Note the order may different for IPv4 vs IPv6 addresses. | |
133 | # | |
134 | # @see http://support.microsoft.com/kb/894564 | |
135 | # @return [Array<WIN32OLE>] | |
136 | # | |
137 | # @api private | |
138 | def self.get_preferred_network_adapters(bindings) | |
139 | network_adapter_configurations.select do |nic| | |
140 | bindings.bindings.include?(nic.SettingID) | |
141 | end.sort do |nic_left,nic_right| | |
142 | cmp = nic_left.IPConnectionMetric <=> nic_right.IPConnectionMetric | |
143 | if cmp == 0 | |
144 | bindings.bindings[nic_left.SettingID] <=> bindings.bindings[nic_right.SettingID] | |
145 | else | |
146 | cmp | |
147 | end | |
148 | end | |
149 | end | |
150 | ||
151 | class Bindings4 | |
152 | def initialize | |
153 | @key = 'SYSTEM\CurrentControlSet\Services\Tcpip\Linkage' | |
154 | end | |
155 | ||
156 | def bindings | |
157 | require 'facter/util/registry' | |
158 | bindings = {} | |
159 | ||
160 | Facter::Util::Registry.hklm_read(@key, 'Bind').each_with_index do |entry, index| | |
161 | match_data = entry.match(/\\Device\\(\{.*\})/) | |
162 | unless match_data.nil? | |
163 | bindings[match_data[1]] = index | |
164 | end | |
165 | end | |
166 | ||
167 | bindings | |
168 | rescue | |
169 | {} | |
170 | end | |
171 | end | |
172 | ||
173 | class Bindings6 < Bindings4 | |
174 | def initialize | |
175 | @key = 'SYSTEM\CurrentControlSet\Services\Tcpip6\Linkage' | |
176 | end | |
177 | end | |
178 | ||
179 | # Determines if the value passed in is a valid ipv4 address. | |
180 | # | |
181 | # @param [String] ip_address the IPv4 address to validate | |
182 | # @return [Boolean] | |
183 | # | |
184 | # @api private | |
185 | def self.valid_ipv4_address?(ip_address) | |
186 | String(ip_address).scan(/(?:[0-9]{1,3}\.){3}[0-9]{1,3}/).each do |match| | |
187 | # excluding 169.254.x.x in Windows - this is the DHCP APIPA | |
188 | # meaning that if the node cannot get an ip address from the dhcp server, | |
189 | # it auto-assigns a private ip address | |
190 | unless match == "127.0.0.1" or match =~ /^169.254.*/ | |
191 | return !!match | |
192 | end | |
193 | end | |
194 | ||
195 | false | |
196 | end | |
197 | ||
198 | # Determines if the value passed in is a valid ipv6 address. | |
199 | # | |
200 | # @param [String] ip_address the IPv6 address to validate | |
201 | # @return [Boolean] | |
202 | # | |
203 | # @api private | |
204 | def self.valid_ipv6_address?(ip_address) | |
205 | String(ip_address).scan(/(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4}/).each do |match| | |
206 | unless match =~ /fe80.*/ or match == "::1" | |
207 | return !!match | |
208 | end | |
209 | end | |
210 | ||
211 | false | |
212 | end | |
213 | ||
214 | end |
30 | 30 | :macaddress => /(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/, |
31 | 31 | :netmask => /.*\s+netmask (\S+)\s.*/ |
32 | 32 | }, |
33 | :windows => { | |
34 | :ipaddress => /\s+IP Address:\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, | |
35 | :ipaddress6 => /Address ((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/, | |
36 | :netmask => /\s+Subnet Prefix:\s+\S+\s+\(mask ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\)/ | |
37 | } | |
33 | :windows => {} | |
38 | 34 | } |
39 | 35 | |
40 | 36 | # Convert an interface name into purely alphanumeric characters. |
60 | 56 | end |
61 | 57 | |
62 | 58 | def self.get_interfaces |
59 | if Facter.value(:kernel) == 'windows' | |
60 | require 'facter/util/ip/windows' | |
61 | return Facter::Util::IP::Windows.interfaces | |
62 | end | |
63 | ||
63 | 64 | return [] unless output = Facter::Util::IP.get_all_interface_output() |
64 | ||
65 | # windows interface names contain spaces and are quoted and can appear multiple | |
66 | # times as ipv4 and ipv6 | |
67 | return output.scan(/\s* connected\s*(\S.*)/).flatten.uniq if Facter.value(:kernel) == 'windows' | |
68 | 65 | |
69 | 66 | # Our regex appears to be stupid, in that it leaves colons sitting |
70 | 67 | # at the end of interfaces. So, we have to trim those trailing |
88 | 85 | output.sub!(/^[^\n]*\n/, "") # delete the header line. |
89 | 86 | output |
90 | 87 | end |
91 | when 'windows' | |
92 | output = %x|#{ENV['SYSTEMROOT']}/system32/netsh.exe interface ip show interface| | |
93 | output += %x|#{ENV['SYSTEMROOT']}/system32/netsh.exe interface ipv6 show interface| | |
94 | 88 | end |
95 | 89 | output |
96 | 90 | end |
171 | 165 | def self.get_output_for_interface_and_label(interface, label) |
172 | 166 | return get_single_interface_output(interface) unless Facter.value(:kernel) == 'windows' |
173 | 167 | |
174 | if label == 'ipaddress6' | |
175 | output = %x|#{ENV['SYSTEMROOT']}/system32/netsh.exe interface ipv6 show address \"#{interface}\"| | |
176 | else | |
177 | output = %x|#{ENV['SYSTEMROOT']}/system32/netsh.exe interface ip show address \"#{interface}\"| | |
178 | end | |
179 | output | |
168 | require 'facter/util/ip/windows' | |
169 | output = Facter::Util::IP::Windows.value_for_interface_and_label(interface, label) | |
170 | output ? output : "" | |
180 | 171 | end |
181 | 172 | |
182 | 173 | def self.get_bonding_master(interface) |
219 | 210 | # @return [String] representing the requested value. An empty array is |
220 | 211 | # returned if the kernel is not supported by the REGEX_MAP constant. |
221 | 212 | def self.get_interface_value(interface, label) |
213 | if Facter.value(:kernel) == 'windows' | |
214 | require 'facter/util/ip/windows' | |
215 | return Facter::Util::IP::Windows.value_for_interface_and_label(interface, label) | |
216 | end | |
217 | ||
222 | 218 | tmp1 = [] |
223 | 219 | |
224 | 220 | kernel = Facter.value(:kernel).downcase.to_sym |
32 | 32 | |
33 | 33 | module Windows |
34 | 34 | def macaddress |
35 | require 'facter/util/wmi' | |
35 | require 'facter/util/ip/windows' | |
36 | 36 | |
37 | query = "select MACAddress from Win32_NetworkAdapterConfiguration where IPEnabled = True" | |
38 | ||
39 | ether = nil | |
40 | Facter::Util::WMI.execquery(query).each do |nic| | |
41 | ether = nic.MacAddress | |
42 | break | |
43 | end | |
44 | ether | |
37 | adapter = Facter::Util::IP::Windows.get_preferred_ipv4_adapters.first | |
38 | adapter ? adapter.MACAddress : nil | |
45 | 39 | end |
46 | 40 | module_function :macaddress |
47 | 41 | end |
24 | 24 | } |
25 | 25 | end |
26 | 26 | |
27 | Facter::Util::IP.exec_ifconfig(ops[:ifconfig_opts]).split(/\n/).collect do |line| | |
27 | String(Facter::Util::IP.exec_ifconfig(ops[:ifconfig_opts])).split(/\n/).collect do |line| | |
28 | 28 | matches = line.match(ops[:regex]) |
29 | 29 | if !matches.nil? |
30 | 30 | if ops[:munge].nil? |
65 | 65 | end |
66 | 66 | end |
67 | 67 | |
68 | module KeyValuePairOutputFormat | |
69 | def self.parse(output) | |
70 | result = {} | |
71 | re = /^(.+?)=(.+)$/ | |
72 | output.each_line do |line| | |
73 | if match_data = re.match(line.chomp) | |
74 | result[match_data[1]] = match_data[2] | |
75 | end | |
76 | end | |
77 | result | |
78 | end | |
79 | end | |
80 | ||
68 | 81 | class YamlParser < Base |
69 | 82 | def parse_results |
70 | 83 | YAML.load(content) |
77 | 90 | |
78 | 91 | class TextParser < Base |
79 | 92 | def parse_results |
80 | re = /^(.+?)=(.+)$/ | |
81 | result = {} | |
82 | content.each_line do |line| | |
83 | if match_data = re.match(line.chomp) | |
84 | result[match_data[1]] = match_data[2] | |
85 | end | |
86 | end | |
87 | result | |
93 | KeyValuePairOutputFormat.parse content | |
88 | 94 | end |
89 | 95 | end |
90 | 96 | |
110 | 116 | |
111 | 117 | class ScriptParser < Base |
112 | 118 | def results |
113 | output = Facter::Util::Resolution.exec(filename) | |
114 | ||
115 | result = {} | |
116 | re = /^(.+)=(.+)$/ | |
117 | output.each_line do |line| | |
118 | if match_data = re.match(line.chomp) | |
119 | result[match_data[1]] = match_data[2] | |
120 | end | |
121 | end | |
122 | result | |
119 | KeyValuePairOutputFormat.parse Facter::Util::Resolution.exec(filename) | |
123 | 120 | end |
124 | 121 | end |
125 | 122 | |
126 | 123 | register(ScriptParser) do |filename| |
127 | if not Facter::Util::Config.is_windows? | |
124 | if Facter::Util::Config.is_windows? | |
125 | extension_matches?(filename, %w{bat cmd com exe}) && File.file?(filename) | |
126 | else | |
128 | 127 | File.executable?(filename) && File.file?(filename) |
129 | 128 | end |
130 | 129 | end |
131 | 130 | |
131 | # Executes and parses the key value output of Powershell scripts | |
132 | class PowershellParser < Base | |
133 | # Returns a hash of facts from powershell output | |
134 | def results | |
135 | shell_command = "powershell -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -File \"#{filename}\"" | |
136 | KeyValuePairOutputFormat.parse Facter::Util::Resolution.exec(shell_command) | |
137 | end | |
138 | end | |
139 | ||
140 | register(PowershellParser) do |filename| | |
141 | Facter::Util::Config.is_windows? && extension_matches?(filename, "ps1") && File.file?(filename) | |
142 | end | |
132 | 143 | |
133 | 144 | # A parser that is used when there is no other parser that can handle the file |
134 | 145 | # The return from results indicates to the caller the file was not parsed correctly. |
0 | 0 | module Facter |
1 | 1 | if not defined? FACTERVERSION then |
2 | FACTERVERSION = '1.7.2' | |
2 | FACTERVERSION = '1.7.3' | |
3 | 3 | end |
4 | 4 | |
5 | 5 | ## |
45 | 45 | |
46 | 46 | Facter.add("virtual") do |
47 | 47 | confine :kernel => ["FreeBSD", "GNU/kFreeBSD"] |
48 | ||
48 | has_weight 10 | |
49 | 49 | setcode do |
50 | 50 | "jail" if Facter::Util::Virtual.jail? |
51 | 51 | end |
53 | 53 | |
54 | 54 | Facter.add("virtual") do |
55 | 55 | confine :kernel => 'SunOS' |
56 | ||
56 | has_weight 10 | |
57 | 57 | setcode do |
58 | 58 | next "zone" if Facter::Util::Virtual.zone? |
59 | 59 | |
73 | 73 | |
74 | 74 | Facter.add("virtual") do |
75 | 75 | confine :kernel => 'HP-UX' |
76 | ||
76 | has_weight 10 | |
77 | 77 | setcode do |
78 | 78 | "hpvm" if Facter::Util::Virtual.hpvm? |
79 | 79 | end |
81 | 81 | |
82 | 82 | Facter.add("virtual") do |
83 | 83 | confine :architecture => 's390x' |
84 | ||
84 | has_weight 10 | |
85 | 85 | setcode do |
86 | 86 | "zlinux" if Facter::Util::Virtual.zlinux? |
87 | 87 | end |
89 | 89 | |
90 | 90 | Facter.add("virtual") do |
91 | 91 | confine :kernel => 'OpenBSD' |
92 | ||
92 | has_weight 10 | |
93 | 93 | setcode do |
94 | 94 | output = Facter::Util::Resolution.exec('sysctl -n hw.product 2>/dev/null') |
95 | 95 | if output |
0 | Address ::1 Parameters | |
1 | --------------------------------------------------------- | |
2 | Interface Luid : Loopback Pseudo-Interface 1 | |
3 | Scope Id : 0.0 | |
4 | Valid Lifetime : infinite | |
5 | Preferred Lifetime : infinite | |
6 | DAD State : Preferred | |
7 | Address Type : Other | |
8 | ||
9 | Address fe80::7128:aa90:8f2a:8375%9 Parameters | |
10 | --------------------------------------------------------- | |
11 | Interface Luid : Local Area Connection | |
12 | Scope Id : 0.9 | |
13 | Valid Lifetime : infinite | |
14 | Preferred Lifetime : infinite | |
15 | DAD State : Preferred | |
16 | Address Type : Other | |
17 | ||
18 | Address fe80::5efe:172.16.138.216%11 Parameters | |
19 | --------------------------------------------------------- | |
20 | Interface Luid : isatap.localdomain | |
21 | Scope Id : 0.11 | |
22 | Valid Lifetime : infinite | |
23 | Preferred Lifetime : infinite | |
24 | DAD State : Deprecated | |
25 | Address Type : Other | |
26 | ||
27 | Address 2001:0:4137:9e76:2087:77a:53ef:7527 Parameters | |
28 | --------------------------------------------------------- | |
29 | Interface Luid : Teredo Tunneling Pseudo-Interface | |
30 | Scope Id : 0.0 | |
31 | Valid Lifetime : infinite | |
32 | Preferred Lifetime : infinite | |
33 | DAD State : Preferred | |
34 | Address Type : Public |
0 | lo Link encap:Boucle locale | |
1 | inet adr:127.0.0.1 Masque:255.0.0.0 | |
2 | adr inet6: ::1/128 Scope:Hote | |
3 | UP LOOPBACK RUNNING MTU:65536 Metric:1 | |
4 | RX packets:1001 errors:0 dropped:0 overruns:0 frame:0 | |
5 | TX packets:1001 errors:0 dropped:0 overruns:0 carrier:0 | |
6 | collisions:0 lg file transmission:0 | |
7 | RX bytes:52562 (51.3 KiB) TX bytes:52562 (51.3 KiB) | |
8 | ||
9 | wlan0 Link encap:Ethernet HWaddr ac:81:12:2d:86:25 | |
10 | inet adr:192.168.1.83 Bcast:192.168.1.255 Masque:255.255.255.0 | |
11 | adr inet6: fe80::ae81:12ff:fe2d:8625/64 Scope:Lien | |
12 | UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 | |
13 | RX packets:493220 errors:0 dropped:0 overruns:0 frame:0 | |
14 | TX packets:390375 errors:0 dropped:0 overruns:0 carrier:0 | |
15 | collisions:0 lg file transmission:1000 | |
16 | RX bytes:569234568 (542.8 MiB) TX bytes:69778980 (66.5 MiB) | |
17 |
0 | require 'spec_helper' | |
1 | ||
2 | module FacterSpec::WindowsNetwork | |
3 | ||
4 | def settingId0 | |
5 | '{4AE6B55C-6DD6-427D-A5BB-13535D4BE926}' | |
6 | end | |
7 | ||
8 | def settingId1 | |
9 | '{38762816-7957-42AC-8DAA-3B08D0C857C7}' | |
10 | end | |
11 | ||
12 | def nic_bindings | |
13 | ["\\Device\\#{settingId0}", "\\Device\\#{settingId1}" ] | |
14 | end | |
15 | ||
16 | def macAddress0 | |
17 | '23:24:df:12:12:00' | |
18 | end | |
19 | ||
20 | def macAddress1 | |
21 | '00:0C:29:0C:9E:9F' | |
22 | end | |
23 | ||
24 | def ipAddress0 | |
25 | '12.123.12.12' | |
26 | end | |
27 | ||
28 | def ipAddress1 | |
29 | '12.123.12.13' | |
30 | end | |
31 | ||
32 | def subnet0 | |
33 | '255.255.255.0' | |
34 | end | |
35 | ||
36 | def subnet1 | |
37 | '255.255.0.0' | |
38 | end | |
39 | ||
40 | def ipv6Address0 | |
41 | '2011:0:4137:9e76:2087:77a:53ef:7527' | |
42 | end | |
43 | ||
44 | def ipv6Address1 | |
45 | '2013:0:4137:9e76:2087:77a:53ef:7527' | |
46 | end | |
47 | ||
48 | def ipv6LinkLocal | |
49 | 'fe80::2db2:5b42:4e30:b508' | |
50 | end | |
51 | ||
52 | def given_a_valid_windows_nic_with_ipv4_and_ipv6 | |
53 | stub('network0', :IPAddress => [ipAddress0, ipv6Address0], :SettingID => settingId0, :IPConnectionMetric => 10,:MACAddress => macAddress0,:IPSubnet => [subnet0, '48','2']) | |
54 | end | |
55 | ||
56 | def given_two_valid_windows_nics_with_ipv4_and_ipv6 | |
57 | { | |
58 | :nic0 => given_a_valid_windows_nic_with_ipv4_and_ipv6, | |
59 | :nic1 => stub('network1', :IPAddress => [ipAddress1, ipv6Address1], :SettingID => settingId1, :IPConnectionMetric => 10,:MACAddress => macAddress1,:IPSubnet => [subnet1, '48','2']) | |
60 | } | |
61 | end | |
62 | ||
63 | end |
0 | # Add the projects lib directory to our load path so we can require libraries | |
1 | # within it easily. | |
2 | dir = File.expand_path(File.dirname(__FILE__)) | |
3 | ||
4 | SPECDIR = dir | |
5 | $LOAD_PATH.unshift("#{dir}/../lib") | |
6 | ||
7 | 0 | require 'rubygems' |
8 | 1 | require 'mocha' |
9 | 2 | require 'rspec' |
12 | 5 | require 'puppetlabs_spec_helper' |
13 | 6 | require 'pathname' |
14 | 7 | |
8 | # load shared_context within this project's spec directory | |
9 | dir = File.expand_path(File.dirname(__FILE__)) | |
10 | $LOAD_PATH.unshift File.join(dir, 'lib') | |
11 | ||
15 | 12 | Pathname.glob("#{dir}/shared_contexts/*.rb") do |file| |
16 | 13 | require file.relative_path_from(Pathname.new(dir)) |
17 | 14 | end |
15 | ||
16 | module LogSpecOrder | |
17 | # Log the spec order to a file, but only if the LOG_SPEC_ORDER environment | |
18 | # variable is set. This could be enabled on Jenkins runs, as it can | |
19 | # be used with Nick L.'s bisect script to help identify and debug | |
20 | # order-dependent spec failures. | |
21 | # | |
22 | # jpartlow 2013-07-05: this was in puppet and I pulled it into facter because | |
23 | # I was seeing similar ordering issues in the specs...and needed to bisect them :/ | |
24 | def self.log_spec_order | |
25 | if ENV['LOG_SPEC_ORDER'] | |
26 | File.open("./spec_order.txt", "w") do |logfile| | |
27 | RSpec.configuration.files_to_run.each { |f| logfile.puts f } | |
28 | end | |
29 | end | |
30 | end | |
31 | end | |
32 | ||
33 | # Executing here rather than after :suite, so that we can get the order output | |
34 | # even when the issue breaks rspec when specs are first loaded. | |
35 | LogSpecOrder.log_spec_order | |
18 | 36 | |
19 | 37 | RSpec.configure do |config| |
20 | 38 | config.mock_with :mocha |
21 | 21 | ["Gentoo","i686"] => "x86", |
22 | 22 | ["Gentoo","pentium"] => "x86", |
23 | 23 | ["windows","i386"] => "x86", |
24 | ["windows","i686"] => "x86", | |
24 | 25 | ["windows","x64"] => "x64", |
25 | 26 | } |
26 | 27 | generic_archs = Hash.new |
159 | 159 | Facter::Util::Registry.stubs(:hklm_read).returns('') |
160 | 160 | end |
161 | 161 | |
162 | it "should use the DNSDomain for the first nic where ip is enabled" do | |
163 | nic = stubs 'nic' | |
164 | nic.stubs(:DNSDomain).returns("foo.com") | |
165 | ||
166 | nic2 = stubs 'nic' | |
167 | nic2.stubs(:DNSDomain).returns("bar.com") | |
162 | def expects_dnsdomains(domains) | |
163 | nics = [] | |
164 | ||
165 | domains.each do |domain| | |
166 | nic = stubs 'nic' | |
167 | nic.stubs(:DNSDomain).returns(domain) | |
168 | nics << nic | |
169 | end | |
168 | 170 | |
169 | 171 | require 'facter/util/wmi' |
170 | Facter::Util::WMI.stubs(:execquery).with("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").returns([nic, nic2]) | |
172 | Facter::Util::WMI.stubs(:execquery).with("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").returns(nics) | |
173 | end | |
174 | ||
175 | it "uses the first DNSDomain" do | |
176 | expects_dnsdomains(['foo.com', 'bar.com']) | |
171 | 177 | |
172 | 178 | Facter.fact(:domain).value.should == 'foo.com' |
179 | end | |
180 | ||
181 | it "uses the first non-nil DNSDomain" do | |
182 | expects_dnsdomains([nil, 'bar.com']) | |
183 | ||
184 | Facter.fact(:domain).value.should == 'bar.com' | |
185 | end | |
186 | ||
187 | it "uses the first non-empty DNSDomain" do | |
188 | expects_dnsdomains(['', 'bar.com']) | |
189 | ||
190 | Facter.fact(:domain).value.should == 'bar.com' | |
191 | end | |
192 | ||
193 | context "without any network adapters with a specified DNSDomain" do | |
194 | let(:hostname_command) { 'hostname > NUL' } | |
195 | ||
196 | it "should return nil" do | |
197 | expects_dnsdomains([nil]) | |
198 | ||
199 | Facter::Util::Resolution.stubs(:exec).with(hostname_command).returns('sometest') | |
200 | FileTest.stubs(:exists?).with("/etc/resolv.conf").returns(false) | |
201 | ||
202 | Facter.fact(:domain).value.should be_nil | |
203 | end | |
173 | 204 | end |
174 | 205 | end |
175 | 206 | end |
135 | 135 | end |
136 | 136 | |
137 | 137 | it "should return nil if open fails" do |
138 | Facter.expects(:warn).with('Could not retrieve ec2 metadata: host unreachable').twice | |
138 | Facter.expects(:warn).with('Could not retrieve ec2 metadata: host unreachable') | |
139 | 139 | Facter::Util::Resolution.any_instance.stubs(:warn) # do not pollute test output |
140 | 140 | |
141 | 141 | Object.any_instance.expects(:open). |
101 | 101 | end |
102 | 102 | end |
103 | 103 | |
104 | describe Facter[:hostname] do | |
104 | describe "Facter[:hostname]" do | |
105 | 105 | it "should have its ldapname set to 'cn'" do |
106 | 106 | Facter[:hostname].ldapname.should == "cn" |
107 | 107 | end |
108 | 108 | end |
109 | 109 | |
110 | describe Facter[:ipaddress] do | |
110 | describe "Facter[:ipaddress]" do | |
111 | 111 | it "should have its ldapname set to 'iphostnumber'" do |
112 | 112 | Facter[:ipaddress].ldapname.should == "iphostnumber" |
113 | 113 | end |
16 | 16 | Facter.fact(:kernel).stubs(:value).returns("windows") |
17 | 17 | end |
18 | 18 | |
19 | it "should detect i486" do | |
20 | cpu = mock('cpu', :Architecture => 0) | |
21 | cpu.expects(:Level).returns(4).twice | |
22 | Facter::Util::WMI.expects(:execquery).returns([cpu]) | |
23 | ||
24 | Facter.fact(:hardwaremodel).value.should == "i486" | |
25 | end | |
26 | ||
19 | 27 | it "should detect i686" do |
20 | 28 | cpu = mock('cpu', :Architecture => 0, :Level => 6) |
21 | 29 | Facter::Util::WMI.expects(:execquery).returns([cpu]) |
24 | 32 | end |
25 | 33 | |
26 | 34 | it "should detect x64" do |
27 | cpu = mock('cpu', :Architecture => 9, :AddressWidth => 64) | |
35 | cpu = mock('cpu', :Architecture => 9, :AddressWidth => 64, :Level => 6) | |
28 | 36 | Facter::Util::WMI.expects(:execquery).returns([cpu]) |
29 | 37 | |
30 | 38 | Facter.fact(:hardwaremodel).value.should == "x64" |
36 | 44 | |
37 | 45 | Facter.fact(:hardwaremodel).value.should == "i686" |
38 | 46 | end |
47 | ||
48 | it "(#20989) should report i686 when a 32 bit OS is running on a 64 bit CPU and when level is greater than 6 (and not something like i1586)" do | |
49 | cpu = mock('cpu', :Architecture => 9, :AddressWidth => 32, :Level => 15) | |
50 | Facter::Util::WMI.expects(:execquery).returns([cpu]) | |
51 | ||
52 | Facter.fact(:hardwaremodel).value.should == "i686" | |
53 | end | |
39 | 54 | end |
40 | 55 | end |
6 | 6 | File.read(fixtures('ifconfig', filename)) |
7 | 7 | end |
8 | 8 | |
9 | def netsh_fixture(filename) | |
10 | File.read(fixtures('netsh', filename)) | |
11 | end | |
12 | ||
13 | ||
14 | describe "IPv6 address fact" do | |
9 | describe "The IPv6 address fact" do | |
15 | 10 | include FacterSpec::ConfigHelper |
16 | 11 | |
17 | 12 | before do |
54 | 49 | Facter.value(:ipaddress6).should == "2610:10:20:209:203:baff:fe27:a7c" |
55 | 50 | end |
56 | 51 | |
57 | it "should return ipaddress6 information for Windows" do | |
58 | ENV.stubs(:[]).with('SYSTEMROOT').returns('d:/windows') | |
59 | given_a_configuration_of(:is_windows => true) | |
52 | context "on Windows" do | |
53 | require 'facter/util/wmi' | |
54 | require 'facter/util/registry' | |
55 | require 'facter/util/ip/windows' | |
56 | require 'facter_spec/windows_network' | |
60 | 57 | |
61 | fixture = netsh_fixture('windows_netsh_addresses_with_multiple_interfaces') | |
62 | Facter::Util::Resolution.stubs(:exec).with('d:/windows/system32/netsh.exe interface ipv6 show address level=verbose'). | |
63 | returns(fixture) | |
58 | include FacterSpec::WindowsNetwork | |
64 | 59 | |
65 | Facter.value(:ipaddress6).should == "2001:0:4137:9e76:2087:77a:53ef:7527" | |
60 | before :each do | |
61 | Facter.fact(:kernel).stubs(:value).returns(:windows) | |
62 | Facter::Util::Registry.stubs(:hklm_read).returns(nic_bindings) | |
63 | given_a_configuration_of(:is_windows => true) | |
64 | end | |
65 | ||
66 | it "should do what when VPN is turned on?" | |
67 | ||
68 | context "when you have no active network adapter" do | |
69 | it "should return nil if there are no active (or any) network adapters" do | |
70 | Facter::Util::WMI.expects(:execquery).with(Facter::Util::IP::Windows::WMI_IP_INFO_QUERY).returns([]) | |
71 | ||
72 | Facter.value(:ipaddress6).should == nil | |
73 | end | |
74 | end | |
75 | ||
76 | it "should return nil if the system doesn't have ipv6 installed", :if => Facter::Util::Config.is_windows? do | |
77 | Facter::Util::Resolution.any_instance.expects(:warn).never | |
78 | Facter::Util::Registry.stubs(:hklm_read).raises(Win32::Registry::Error, 2) | |
79 | ||
80 | Facter.value(:ipaddress6).should == nil | |
81 | end | |
82 | ||
83 | context "when you have one network adapter" do | |
84 | it "should return empty if ipv6 is not on" do | |
85 | nic = given_a_valid_windows_nic_with_ipv4_and_ipv6 | |
86 | nic.expects(:IPAddress).returns([ipAddress1]) | |
87 | Facter::Util::WMI.expects(:execquery).returns([nic]) | |
88 | ||
89 | Facter.value(:ipaddress6).should == nil | |
90 | end | |
91 | ||
92 | it "should return the ipv6 address properly" do | |
93 | Facter::Util::WMI.expects(:execquery).returns([given_a_valid_windows_nic_with_ipv4_and_ipv6]) | |
94 | ||
95 | Facter.value(:ipaddress6).should == ipv6Address0 | |
96 | end | |
97 | ||
98 | it "should return the first ipv6 address if there is more than one (multi-homing)" do | |
99 | nic = given_a_valid_windows_nic_with_ipv4_and_ipv6 | |
100 | nic.expects(:IPAddress).returns([ipAddress0, ipv6Address0,ipv6Address1]) | |
101 | Facter::Util::WMI.expects(:execquery).returns([nic]) | |
102 | ||
103 | Facter.value(:ipaddress6).should == ipv6Address0 | |
104 | end | |
105 | ||
106 | it "should return return nil if the ipv6 address is link local" do | |
107 | nic = given_a_valid_windows_nic_with_ipv4_and_ipv6 | |
108 | nic.expects(:IPAddress).returns([ipAddress0, ipv6LinkLocal]) | |
109 | Facter::Util::WMI.expects(:execquery).returns([nic]) | |
110 | ||
111 | Facter.value(:ipaddress6).should == nil | |
112 | end | |
113 | end | |
114 | ||
115 | context "when you have more than one network adapter" do | |
116 | it "should return empty if ipv6 is not on" do | |
117 | nics = given_two_valid_windows_nics_with_ipv4_and_ipv6 | |
118 | nics[:nic0].expects(:IPAddress).returns([ipAddress0]) | |
119 | nics[:nic1].expects(:IPAddress).returns([ipAddress1]) | |
120 | Facter::Util::WMI.expects(:execquery).returns(nics.values) | |
121 | ||
122 | Facter.value(:ipaddress6).should == nil | |
123 | end | |
124 | ||
125 | it "should return the ipv6 of the adapter with the lowest IP connection metric (best connection)" do | |
126 | nics = given_two_valid_windows_nics_with_ipv4_and_ipv6 | |
127 | nics[:nic1].expects(:IPConnectionMetric).returns(5) | |
128 | Facter::Util::WMI.expects(:execquery).returns(nics.values) | |
129 | ||
130 | Facter.value(:ipaddress6).should == ipv6Address1 | |
131 | end | |
132 | ||
133 | it "should return the ipv6 of the adapter with the lowest IP connection metric (best connection) that has ipv6 enabled" do | |
134 | nics = given_two_valid_windows_nics_with_ipv4_and_ipv6 | |
135 | nics[:nic1].expects(:IPConnectionMetric).returns(5) | |
136 | nics[:nic1].expects(:IPAddress).returns([ipAddress1]) | |
137 | Facter::Util::WMI.expects(:execquery).returns(nics.values) | |
138 | ||
139 | Facter.value(:ipaddress6).should == ipv6Address0 | |
140 | end | |
141 | ||
142 | context "when the IP connection metric is the same" do | |
143 | it "should return the ipv6 of the adapter with the lowest binding order" do | |
144 | nics = given_two_valid_windows_nics_with_ipv4_and_ipv6 | |
145 | Facter::Util::WMI.expects(:execquery).returns(nics.values) | |
146 | ||
147 | Facter.value(:ipaddress6).should == ipv6Address0 | |
148 | end | |
149 | ||
150 | it "should return the ipv6 of the adapter with the lowest binding order even if the adapter is not first" do | |
151 | nics = given_two_valid_windows_nics_with_ipv4_and_ipv6 | |
152 | Facter::Util::Registry.stubs(:hklm_read).returns(["\\Device\\#{settingId1}", "\\Device\\#{settingId0}" ]) | |
153 | Facter::Util::WMI.expects(:execquery).returns(nics.values) | |
154 | ||
155 | Facter.value(:ipaddress6).should == ipv6Address1 | |
156 | end | |
157 | end | |
158 | end | |
66 | 159 | end |
67 | 160 | end |
2 | 2 | require 'spec_helper' |
3 | 3 | require 'facter/util/ip' |
4 | 4 | |
5 | shared_examples_for "ifconfig output" do |platform, address, fixture| | |
6 | it "correctly on #{platform}" do | |
7 | Facter::Util::IP.stubs(:exec_ifconfig).returns(my_fixture_read(fixture)) | |
8 | subject.value.should == address | |
5 | describe "ipaddress fact" do | |
6 | before do | |
7 | Facter.collection.internal_loader.load(:ipaddress) | |
8 | end | |
9 | ||
10 | context 'using `ifconfig`' do | |
11 | before :each do | |
12 | Facter.fact(:hostname).stubs(:value) | |
13 | end | |
14 | ||
15 | context "on Linux" do | |
16 | before :each do | |
17 | Facter.fact(:kernel).stubs(:value).returns("Linux") | |
18 | end | |
19 | ||
20 | def expect_ifconfig_parse(address, fixture) | |
21 | Facter::Util::IP.stubs(:exec_ifconfig).returns(my_fixture_read(fixture)) | |
22 | Facter.fact(:ipaddress).value.should == address | |
23 | end | |
24 | ||
25 | it "parses correctly on Ubuntu 12.04" do | |
26 | expect_ifconfig_parse "10.87.80.110", "ifconfig_ubuntu_1204.txt" | |
27 | end | |
28 | ||
29 | it "parses correctly on Fedora 17" do | |
30 | expect_ifconfig_parse "131.252.209.153", "ifconfig_net_tools_1.60.txt" | |
31 | end | |
32 | ||
33 | it "parses a real address over multiple loopback addresses" do | |
34 | expect_ifconfig_parse "10.0.222.20", "ifconfig_multiple_127_addresses.txt" | |
35 | end | |
36 | ||
37 | it "parses nothing with a non-english locale" do | |
38 | expect_ifconfig_parse nil, "ifconfig_non_english_locale.txt" | |
39 | end | |
40 | end | |
41 | end | |
42 | ||
43 | context "on Windows" do | |
44 | require 'facter/util/wmi' | |
45 | require 'facter/util/registry' | |
46 | require 'facter/util/ip/windows' | |
47 | require 'facter_spec/windows_network' | |
48 | ||
49 | include FacterSpec::WindowsNetwork | |
50 | ||
51 | before :each do | |
52 | Facter.fact(:kernel).stubs(:value).returns(:windows) | |
53 | Facter.fact(:kernelrelease).stubs(:value).returns('6.1.7601') | |
54 | Facter::Util::Registry.stubs(:hklm_read).returns(nic_bindings) | |
55 | end | |
56 | ||
57 | it "should do what when VPN is turned on?" | |
58 | ||
59 | context "when you have no active network adapter" do | |
60 | it "should return nil if there are no active (or any) network adapters" do | |
61 | Facter::Util::WMI.expects(:execquery).with(Facter::Util::IP::Windows::WMI_IP_INFO_QUERY).returns([]) | |
62 | Facter::Util::Resolution.stubs(:exec) | |
63 | ||
64 | Facter.value(:ipaddress).should == nil | |
65 | end | |
66 | end | |
67 | ||
68 | context "when you have one network adapter" do | |
69 | it "should return the ip address properly" do | |
70 | nic = given_a_valid_windows_nic_with_ipv4_and_ipv6 | |
71 | Facter::Util::WMI.expects(:execquery).returns([nic]) | |
72 | ||
73 | Facter.value(:ipaddress).should == ipAddress0 | |
74 | end | |
75 | end | |
76 | ||
77 | context "when you have more than one network adapter" do | |
78 | it "should return the ip of the adapter with the lowest IP connection metric (best connection)" do | |
79 | nics = given_two_valid_windows_nics_with_ipv4_and_ipv6 | |
80 | nics[:nic1].expects(:IPConnectionMetric).returns(5) | |
81 | Facter::Util::WMI.expects(:execquery).returns(nics.values) | |
82 | ||
83 | Facter.value(:ipaddress).should == ipAddress1 | |
84 | end | |
85 | ||
86 | it "should return the ip of the adapter with the lowest IP connection metric (best connection) that has ipv4 enabled" do | |
87 | nics = given_two_valid_windows_nics_with_ipv4_and_ipv6 | |
88 | nics[:nic1].expects(:IPConnectionMetric).returns(5) | |
89 | nics[:nic1].expects(:IPAddress).returns([ipv6Address1]) | |
90 | Facter::Util::WMI.expects(:execquery).returns(nics.values) | |
91 | ||
92 | Facter.value(:ipaddress).should == ipAddress0 | |
93 | end | |
94 | ||
95 | context "when the IP connection metric is the same" do | |
96 | it "should return the ip of the adapter with the lowest binding order" do | |
97 | nics = given_two_valid_windows_nics_with_ipv4_and_ipv6 | |
98 | Facter::Util::WMI.expects(:execquery).returns(nics.values) | |
99 | ||
100 | Facter.value(:ipaddress).should == ipAddress0 | |
101 | end | |
102 | ||
103 | it "should return the ip of the adapter with the lowest binding order even if the adapter is not first" do | |
104 | nics = given_two_valid_windows_nics_with_ipv4_and_ipv6 | |
105 | Facter::Util::WMI.expects(:execquery).returns(nics.values) | |
106 | Facter::Util::Registry.stubs(:hklm_read).returns(["\\Device\\#{settingId1}", "\\Device\\#{settingId0}" ]) | |
107 | ||
108 | Facter.value(:ipaddress).should == ipAddress1 | |
109 | end | |
110 | end | |
111 | end | |
9 | 112 | end |
10 | 113 | end |
11 | ||
12 | RSpec.configure do |config| | |
13 | config.alias_it_should_behave_like_to :example_behavior_for, "parses" | |
14 | end | |
15 | ||
16 | describe "The ipaddress fact" do | |
17 | subject do | |
18 | Facter.collection.internal_loader.load(:ipaddress) | |
19 | Facter.fact(:ipaddress) | |
20 | end | |
21 | context "on Linux" do | |
22 | before :each do | |
23 | Facter.fact(:kernel).stubs(:value).returns("Linux") | |
24 | end | |
25 | ||
26 | example_behavior_for "ifconfig output", | |
27 | "Ubuntu 12.04", "10.87.80.110", "ifconfig_ubuntu_1204.txt" | |
28 | example_behavior_for "ifconfig output", | |
29 | "Fedora 17", "131.252.209.153", "ifconfig_net_tools_1.60.txt" | |
30 | example_behavior_for "ifconfig output", | |
31 | "Linux with multiple loopback addresses", | |
32 | "10.0.222.20", | |
33 | "ifconfig_multiple_127_addresses.txt" | |
34 | end | |
35 | end |
5 | 5 | |
6 | 6 | def ifconfig_fixture(filename) |
7 | 7 | File.read(fixtures('ifconfig', filename)) |
8 | end | |
9 | ||
10 | def netsh_fixture(filename) | |
11 | File.read(fixtures('netsh', filename)) | |
12 | 8 | end |
13 | 9 | |
14 | 10 | describe "macaddress fact" do |
2 | 2 | require 'spec_helper' |
3 | 3 | |
4 | 4 | describe "Memory facts" do |
5 | after do | |
5 | before(:each) do | |
6 | Facter.collection.internal_loader.load(:memory) | |
7 | end | |
8 | ||
9 | after(:each) do | |
6 | 10 | Facter.clear |
7 | 11 | end |
8 | 12 | |
9 | 13 | describe "when returning scaled sizes" do |
10 | before(:each) do | |
11 | Facter.collection.internal_loader.load(:memory) | |
12 | end | |
13 | ||
14 | 14 | [ "memorysize", |
15 | 15 | "memoryfree", |
16 | 16 | "swapsize", |
45 | 45 | |
46 | 46 | describe "on Darwin" do |
47 | 47 | before(:each) do |
48 | Facter.clear | |
48 | 49 | Facter.fact(:kernel).stubs(:value).returns("Darwin") |
49 | 50 | Facter::Util::Resolution.stubs(:exec).with('sysctl -n hw.memsize').returns('8589934592') |
50 | 51 | sample_vm_stat = <<VMSTAT |
514 | 515 | end |
515 | 516 | |
516 | 517 | it "should use the memorysize fact for the memorytotal fact" do |
517 | Facter.fact("memorysize").expects(:value).once.returns "yay" | |
518 | Facter.fact("memorysize").expects(:value).once.returns "16.00 GB" | |
518 | 519 | Facter::Util::Resolution.expects(:exec).never |
519 | Facter.fact("memorytotal").value.should == "yay" | |
520 | Facter.fact(:memorytotal).value.should == "16.00 GB" | |
520 | 521 | end |
521 | 522 | end |
12 | 12 | end |
13 | 13 | end |
14 | 14 | |
15 | describe "netmask fact" do | |
16 | before :each do | |
17 | Facter.fact(:kernel).stubs(:value).returns("Linux") | |
18 | end | |
15 | describe "The netmask fact" do | |
16 | context "on Linux" do | |
17 | before :each do | |
18 | Facter.fact(:kernel).stubs(:value).returns("Linux") | |
19 | end | |
19 | 20 | |
20 | context "on Linux" do | |
21 | 21 | example_behavior_for "netmask from ifconfig output", |
22 | 22 | "Archlinux (net-tools 1.60)", "255.255.255.0", |
23 | 23 | "ifconfig_net_tools_1.60.txt" |
25 | 25 | "Ubuntu 12.04", "255.255.255.255", |
26 | 26 | "ifconfig_ubuntu_1204.txt" |
27 | 27 | end |
28 | ||
29 | context "on Windows" do | |
30 | require 'facter/util/wmi' | |
31 | require 'facter/util/registry' | |
32 | require 'facter_spec/windows_network' | |
33 | ||
34 | include FacterSpec::WindowsNetwork | |
35 | ||
36 | before :each do | |
37 | Facter.fact(:kernel).stubs(:value).returns(:windows) | |
38 | Facter::Util::Registry.stubs(:hklm_read).returns(nic_bindings) | |
39 | end | |
40 | ||
41 | describe "when you have no active network adapter" do | |
42 | it "should return nil if there are no active (or any) network adapters" do | |
43 | Facter::Util::WMI.expects(:execquery).returns([]) | |
44 | ||
45 | Facter.value(:netmask).should == nil | |
46 | end | |
47 | end | |
48 | ||
49 | describe "when you have one network adapter" do | |
50 | it "should return properly" do | |
51 | nic = given_a_valid_windows_nic_with_ipv4_and_ipv6 | |
52 | Facter::Util::WMI.expects(:execquery).returns([nic]) | |
53 | ||
54 | Facter.value(:netmask).should == subnet0 | |
55 | end | |
56 | end | |
57 | ||
58 | describe "when you have more than one network adapter" do | |
59 | it "should return the netmask of the adapter with the lowest IP connection metric (best connection)" do | |
60 | nics = given_two_valid_windows_nics_with_ipv4_and_ipv6 | |
61 | nics[:nic1].expects(:IPConnectionMetric).returns(5) | |
62 | Facter::Util::WMI.expects(:execquery).returns(nics.values) | |
63 | ||
64 | Facter.value(:netmask).should == subnet1 | |
65 | end | |
66 | ||
67 | context "when the IP connection metric is the same" do | |
68 | it "should return the netmask of the adapter with the lowest binding order" do | |
69 | nics = given_two_valid_windows_nics_with_ipv4_and_ipv6 | |
70 | Facter::Util::WMI.expects(:execquery).returns(nics.values) | |
71 | ||
72 | Facter.value(:netmask).should == subnet0 | |
73 | end | |
74 | ||
75 | it "should return the netmask of the adapter with the lowest binding even if the adapter is not first" do | |
76 | nics = given_two_valid_windows_nics_with_ipv4_and_ipv6 | |
77 | Facter::Util::WMI.expects(:execquery).returns(nics.values) | |
78 | Facter::Util::Registry.stubs(:hklm_read).returns(["\\Device\\#{settingId1}", "\\Device\\#{settingId0}" ]) | |
79 | ||
80 | Facter.value(:netmask).should == subnet1 | |
81 | end | |
82 | end | |
83 | end | |
84 | end | |
28 | 85 | end |
0 | # encoding: UTF-8 | |
1 | ||
2 | require 'spec_helper' | |
3 | require 'facter/util/ip/windows' | |
4 | ||
5 | describe Facter::Util::IP::Windows do | |
6 | before :each do | |
7 | Facter.fact(:kernel).stubs(:value).returns('windows') | |
8 | end | |
9 | ||
10 | describe ".to_s" do | |
11 | let(:to_s) { described_class.to_s } | |
12 | ||
13 | it { to_s.should eq 'windows' } | |
14 | end | |
15 | ||
16 | describe ".convert_netmask_from_hex?" do | |
17 | let :convert_netmask_from_hex? do | |
18 | described_class.convert_netmask_from_hex? | |
19 | end | |
20 | ||
21 | it { convert_netmask_from_hex?.should be false } | |
22 | end | |
23 | ||
24 | describe ".bonding_master" do | |
25 | let(:bonding_master) { described_class.bonding_master('eth0') } | |
26 | ||
27 | pending("porting to Windows") do | |
28 | it { bonding_master.should be_nil } | |
29 | end | |
30 | end | |
31 | ||
32 | describe ".interfaces" do | |
33 | let(:name) { 'Local Area Connection' } | |
34 | let(:index) { 7 } | |
35 | let(:nic_config) { mock('nic_config', :Index => index) } | |
36 | let(:nic) { mock('nic', :NetConnectionId => name ) } | |
37 | ||
38 | it "should return an array of only connected interfaces" do | |
39 | Facter::Util::WMI.expects(:execquery).with(Facter::Util::IP::Windows::WMI_IP_INFO_QUERY). | |
40 | returns([nic_config]) | |
41 | Facter::Util::WMI.expects(:execquery).with("SELECT * FROM Win32_NetworkAdapter WHERE Index = #{index}"). | |
42 | returns([nic]) | |
43 | ||
44 | described_class.interfaces.should == [name] | |
45 | end | |
46 | end | |
47 | end |
51 | 51 | |
52 | 52 | it "should return a list of only connected interfaces on Windows" do |
53 | 53 | Facter.fact(:kernel).stubs(:value).returns("windows") |
54 | windows_netsh = my_fixture_read("windows_netsh_all_interfaces") | |
55 | Facter::Util::IP.stubs(:get_all_interface_output).returns(windows_netsh) | |
54 | ||
55 | Facter::Util::IP::Windows.expects(:interfaces).returns(["Loopback Pseudo-Interface 1", "Local Area Connection", "Teredo Tunneling Pseudo-Interface"]) | |
56 | 56 | Facter::Util::IP.get_interfaces().should == ["Loopback Pseudo-Interface 1", "Local Area Connection", "Teredo Tunneling Pseudo-Interface"] |
57 | 57 | end |
58 | 58 | |
372 | 372 | end |
373 | 373 | |
374 | 374 | describe "on Windows" do |
375 | require 'facter/util/ip/windows' | |
376 | ||
375 | 377 | before :each do |
376 | 378 | Facter.stubs(:value).with(:kernel).returns("windows") |
377 | 379 | end |
378 | 380 | |
379 | 381 | it "should return ipaddress information" do |
380 | windows_netsh = my_fixture_read("windows_netsh_single_interface") | |
381 | ||
382 | Facter::Util::IP.expects(:get_output_for_interface_and_label).with("Local Area Connection", "ipaddress").returns(windows_netsh) | |
382 | Facter::Util::IP::Windows.expects(:value_for_interface_and_label).with("Local Area Connection", "ipaddress").returns('172.16.138.216') | |
383 | 383 | |
384 | 384 | Facter::Util::IP.get_interface_value("Local Area Connection", "ipaddress").should == "172.16.138.216" |
385 | 385 | end |
386 | 386 | |
387 | it "should return a human readable netmask" do | |
388 | windows_netsh = my_fixture_read("windows_netsh_single_interface") | |
389 | ||
390 | Facter::Util::IP.expects(:get_output_for_interface_and_label).with("Local Area Connection", "netmask").returns(windows_netsh) | |
391 | ||
392 | Facter::Util::IP.get_interface_value("Local Area Connection", "netmask").should == "255.255.255.0" | |
393 | end | |
394 | ||
395 | 387 | it "should return network information" do |
396 | windows_netsh = my_fixture_read("windows_netsh_single_interface") | |
397 | ||
398 | Facter::Util::IP.stubs(:get_output_for_interface_and_label).with("Local Area Connection", "ipaddress").returns(windows_netsh) | |
399 | Facter::Util::IP.stubs(:get_output_for_interface_and_label).with("Local Area Connection", "netmask").returns(windows_netsh) | |
388 | Facter::Util::IP::Windows.expects(:value_for_interface_and_label).with("Local Area Connection", "ipaddress").returns('172.16.138.216') | |
389 | Facter::Util::IP::Windows.expects(:value_for_interface_and_label).with("Local Area Connection", "netmask").returns('255.255.255.0') | |
400 | 390 | |
401 | 391 | Facter::Util::IP.get_network_value("Local Area Connection").should == "172.16.138.0" |
402 | 392 | end |
403 | 393 | |
404 | 394 | it "should return ipaddress6 information" do |
405 | windows_netsh = my_fixture_read("windows_netsh_single_interface6") | |
406 | ||
407 | Facter::Util::IP.expects(:get_output_for_interface_and_label).with("Teredo Tunneling Pseudo-Interface", "ipaddress6").returns(windows_netsh) | |
408 | ||
409 | Facter::Util::IP.get_interface_value("Teredo Tunneling Pseudo-Interface", "ipaddress6").should == "2001:0:4137:9e76:2087:77a:53ef:7527" | |
395 | Facter::Util::IP::Windows.expects(:value_for_interface_and_label).with("Local Area Connection", "ipaddress6").returns("2001:0:4137:9e76:2087:77a:53ef:7527") | |
396 | ||
397 | Facter::Util::IP.get_interface_value("Local Area Connection", "ipaddress6").should == "2001:0:4137:9e76:2087:77a:53ef:7527" | |
410 | 398 | end |
411 | 399 | end |
412 | 400 |
80 | 80 | end |
81 | 81 | end |
82 | 82 | |
83 | describe "Windows" do | |
84 | it "should return the first macaddress" do | |
85 | Facter.fact(:kernel).stubs(:value).returns("windows") | |
83 | describe "The macaddress fact" do | |
84 | context "on Windows" do | |
85 | require 'facter/util/wmi' | |
86 | require 'facter/util/registry' | |
87 | require 'facter_spec/windows_network' | |
86 | 88 | |
87 | nic = stubs 'nic' | |
88 | nic.stubs(:MacAddress).returns("00:0C:29:0C:9E:9F") | |
89 | include FacterSpec::WindowsNetwork | |
89 | 90 | |
90 | nic2 = stubs 'nic' | |
91 | nic2.stubs(:MacAddress).returns("00:0C:29:0C:9E:AF") | |
91 | before :each do | |
92 | Facter.fact(:kernel).stubs(:value).returns(:windows) | |
93 | Facter::Util::Registry.stubs(:hklm_read).returns(nic_bindings) | |
94 | end | |
92 | 95 | |
93 | require 'facter/util/wmi' | |
94 | Facter::Util::WMI.stubs(:execquery).with("select MACAddress from Win32_NetworkAdapterConfiguration where IPEnabled = True").returns([nic, nic2]) | |
96 | describe "when you have no active network adapter" do | |
97 | it "should return nil if there are no active (or any) network adapters" do | |
98 | Facter::Util::WMI.expects(:execquery).returns([]) | |
95 | 99 | |
96 | Facter.fact(:macaddress).value.should == "00:0C:29:0C:9E:9F" | |
100 | Facter.value(:macaddress).should == nil | |
101 | end | |
102 | end | |
103 | ||
104 | describe "when you have one network adapter" do | |
105 | it "should return properly" do | |
106 | nic = given_a_valid_windows_nic_with_ipv4_and_ipv6 | |
107 | Facter::Util::WMI.expects(:execquery).returns([nic]) | |
108 | ||
109 | Facter.value(:macaddress).should == macAddress0 | |
110 | end | |
111 | end | |
112 | ||
113 | describe "when you have more than one network adapter" do | |
114 | it "should return the macaddress of the adapter with the lowest IP connection metric (best connection)" do | |
115 | nics = given_two_valid_windows_nics_with_ipv4_and_ipv6 | |
116 | nics[:nic1].expects(:IPConnectionMetric).returns(5) | |
117 | Facter::Util::WMI.expects(:execquery).returns(nics.values) | |
118 | ||
119 | Facter.value(:macaddress).should == macAddress1 | |
120 | end | |
121 | ||
122 | context "when the IP connection metric is the same" do | |
123 | it "should return the macaddress of the adapter with the lowest binding order" do | |
124 | nics = given_two_valid_windows_nics_with_ipv4_and_ipv6 | |
125 | Facter::Util::WMI.expects(:execquery).returns(nics.values) | |
126 | ||
127 | Facter.value(:macaddress).should == macAddress0 | |
128 | end | |
129 | ||
130 | it "should return the macaddress of the adapter with the lowest MACAddress when multiple adapters have the same IP connection metric when the lowest MACAddress is not first" do | |
131 | nics = given_two_valid_windows_nics_with_ipv4_and_ipv6 | |
132 | Facter::Util::WMI.expects(:execquery).returns(nics.values) | |
133 | Facter::Util::Registry.stubs(:hklm_read).returns(["\\Device\\#{settingId1}", "\\Device\\#{settingId0}" ]) | |
134 | ||
135 | Facter.value(:macaddress).should == macAddress1 | |
136 | end | |
137 | end | |
138 | end | |
97 | 139 | end |
98 | 140 | end |
0 | 0 | #!/usr/bin/env ruby |
1 | 1 | |
2 | 2 | require 'spec_helper' |
3 | ||
4 | 3 | require 'facter/util/parser' |
5 | 4 | require 'tempfile' |
6 | 5 | require 'tmpdir.rb' |
120 | 119 | Facter::Util::Parser.parser_for(cmd) |
121 | 120 | end |
122 | 121 | |
123 | it "should return no results" do | |
124 | parser.results.should be_nil | |
122 | it "should not parse a directory" do | |
123 | File.stubs(:file?).with(cmd).returns(false) | |
124 | Facter::Util::Parser.parser_for(cmd).results.should be_nil | |
125 | 125 | end |
126 | ||
127 | it "should return the data properly" do | |
128 | File.stubs(:file?).with(cmd).returns(true) | |
129 | parser.results.should == data | |
130 | end | |
131 | end | |
132 | end | |
133 | ||
134 | describe "powershell parser" do | |
135 | let :ps1 do "/tmp/foo.ps1" end | |
136 | let :data_in_ps1 do "one=two\nthree=four\n" end | |
137 | ||
138 | before :each do | |
139 | Facter::Util::Config.stubs(:is_windows?).returns(true) | |
140 | Facter::Util::Resolution.stubs(:exec).returns(data_in_ps1) | |
141 | end | |
142 | ||
143 | let :parser do | |
144 | Facter::Util::Parser.parser_for(ps1) | |
145 | end | |
146 | ||
147 | it "should not parse a directory" do | |
148 | File.stubs(:file?).with(ps1).returns(false) | |
149 | Facter::Util::Parser.parser_for(ps1).results.should be_nil | |
150 | end | |
151 | ||
152 | it "should return data properly" do | |
153 | File.stubs(:file?).with(ps1).returns(true) | |
154 | parser.results.should == data | |
126 | 155 | end |
127 | 156 | end |
128 | 157 |
260 | 260 | end |
261 | 261 | |
262 | 262 | shared_examples_for "virt-what" do |kernel, path, null_device| |
263 | Facter.fact(:kernel).stubs(:value).returns(kernel) | |
264 | Facter::Util::Resolution.expects(:which).with("virt-what").returns(path) | |
265 | Facter::Util::Resolution.expects(:exec).with("#{path} 2>#{null_device}") | |
266 | Facter::Util::Virtual.virt_what | |
263 | before(:each) do | |
264 | Facter.fact(:kernel).stubs(:value).returns(kernel) | |
265 | Facter::Util::Resolution.expects(:which).with("virt-what").returns(path) | |
266 | Facter::Util::Resolution.expects(:exec).with("#{path} 2>#{null_device}") | |
267 | end | |
268 | ||
269 | it "on #{kernel} virt-what is at #{path} and stderr is sent to #{null_device}" do | |
270 | Facter::Util::Virtual.virt_what | |
271 | end | |
267 | 272 | end |
268 | 273 | |
269 | 274 | context "on linux" do |
55 | 55 | |
56 | 56 | it "handles the zfs command becoming available at a later point in time" do |
57 | 57 | # Simulate Puppet configuring the zfs tools from a persistent daemon by |
58 | # simulating three sequential responses to which('zfs') | |
59 | # (NOTE, each resolution causes which to execute twice. | |
58 | # simulating three sequential responses to which('zfs'). | |
60 | 59 | Facter::Util::Resolution.stubs(:which). |
61 | 60 | with("zfs"). |
62 | returns(nil,nil,nil,nil,"/usr/bin/zfs") | |
61 | returns(nil,nil,"/usr/bin/zfs") | |
63 | 62 | Facter::Util::Resolution.stubs(:exec). |
64 | 63 | with("zfs upgrade -v"). |
65 | 64 | returns(my_fixture_read('linux-fuse_0.6.9')) |
67 | 66 | fact = Facter.fact(:zfs_version) |
68 | 67 | |
69 | 68 | # zfs is not present the first two times the fact is resolved. |
70 | fact.value.should_not == "4" | |
71 | fact.value.should_not == "4" | |
69 | fact.value.should be_nil | |
70 | fact.value.should be_nil | |
72 | 71 | # zfs was configured between the second and third resolutions. |
73 | 72 | fact.value.should == "4" |
74 | 73 | end |
55 | 55 | |
56 | 56 | it "handles the zpool command becoming available" do |
57 | 57 | # Simulate Puppet configuring the zfs tools from a persistent daemon by |
58 | # simulating three sequential responses to which('zpool') | |
59 | # (NOTE, each resolution causes which to execute twice. | |
58 | # simulating three sequential responses to which('zpool'). | |
60 | 59 | Facter::Util::Resolution.stubs(:which). |
61 | 60 | with("zpool"). |
62 | returns(nil,nil,nil,nil,"/usr/bin/zpool") | |
61 | returns(nil,nil,"/usr/bin/zpool") | |
63 | 62 | Facter::Util::Resolution.stubs(:exec). |
64 | 63 | with("zpool upgrade -v"). |
65 | 64 | returns(my_fixture_read('linux-fuse_0.6.9')) |
67 | 66 | fact = Facter.fact(:zpool_version) |
68 | 67 | |
69 | 68 | # zfs is not present the first two times the fact is resolved. |
70 | fact.value.should_not == "23" | |
71 | fact.value.should_not == "23" | |
69 | fact.value.should be_nil | |
70 | fact.value.should be_nil | |
72 | 71 | # zfs was configured between the second and third resolutions. |
73 | 72 | fact.value.should == "23" |
74 | 73 | end |