diff options
author | Matt Robinson <matt@puppetlabs.com> | 2011-05-20 16:17:37 -0700 |
---|---|---|
committer | Matt Robinson <matt@puppetlabs.com> | 2011-05-20 16:17:37 -0700 |
commit | 59173268a5c6525a4a5df55b362775d07bc6b52d (patch) | |
tree | fbba104c5d714156b3dc872b9e006107ee2a4618 | |
parent | 024f7c99543e58ec00bb8f755a1d89d01fd5174c (diff) | |
parent | 2c5effffa0558f0cec4e84d07ee80ffa27db9a2f (diff) | |
download | facter-59173268a5c6525a4a5df55b362775d07bc6b52d.tar.gz facter-59173268a5c6525a4a5df55b362775d07bc6b52d.tar.xz facter-59173268a5c6525a4a5df55b362775d07bc6b52d.zip |
Merge branch 'next'
* next: (32 commits)
(#7507) Fix 1.9.2 test failure
Removed inappropriately uncredited Ohai method from ec2 fact
(#6614) Update ipaddress6 fact to work with Ruby 1.9
(#6612) Changed uptime spec to be endian agnostic
(#6728) Facter improperly detects openvzve on CloudLinux systems
(#5135) Fix faulty logic in physicalprocessorcount
Ensures that ARP facts are returned only on EC2 hosts
Fixed #6974 - Moved to Apache 2.0 license
refactor the mechanism for allowing for resolution ordering to be influenced
(#6740) facter doesn't always respect facts in environment variables
Partial fix for #6971 - Fix for virtual tests
(#2714) Fixed faulty test
(#2714) Added timeout to prtdiag resulution
(#5135) Refactored physicalprocessorcount
Re-factor. Do not use pure-Ruby file reading against "/proc/cpuinfo" and possibly any entry under "/sys" from the sysfs file system.
Fix. Using sysfs file system entries to count the number of physical CPUs. Fall-back to "/proc/cpuinfo" included for backward-compatibility with legacy systems.
(#3856) Add virtualbox detection via lspci (graphics card), dmidecode, and prtdiag for Solaris and corresponding tests. Darwin case is not handled yet.
(#6883) Update Facter install.rb to be slightly more informative.
(#5394) Document each Facter fact.
(#6862) Add a default subject for the mail_patches rake task
...
69 files changed, 836 insertions, 569 deletions
diff --git a/COPYING b/COPYING deleted file mode 100644 index d511905..0000000 --- a/COPYING +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - <one line to give the program's name and a brief idea of what it does.> - Copyright (C) <year> <name of author> - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - <signature of Ty Coon>, 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. @@ -1,17 +1,15 @@ -Facter - Host Fact Detection and Reporting. Copyright (C) 2005 Reductive Labs LLC +Facter - Host Fact Detection and Reporting -Reductive Labs can be contacted at: info@reductivelabs.com +Copyright 2011 Puppet Labs Inc -This program and entire repository is free software; you can -redistribute it and/or modify it under the terms of the GNU -General Public License as published by the Free Software -Foundation; either version 2 of the License, or any later version. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. +http://www.apache.org/licenses/LICENSE-2.0 -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. @@ -1,8 +0,0 @@ -This package is largely meant to be a library for collecting facts about your -system. These facts are mostly strings (i.e., not numbers), and are things -like the output of 'uname', public ssh and cfengine keys, the number of -processors, etc. - -See bin/facter for an example of the interface. - -See http://www.puppetlabs.com/puppet/related-projects/facter for more details. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e5a5453 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +Facter +====== + +This package is largely meant to be a library for collecting facts about your +system. These facts are mostly strings (i.e., not numbers), and are things +like the output of `uname`, public ssh and cfengine keys, the number of +processors, etc. + +See `bin/facter` for an example of the interface. + +Running Facter +-------------- + +Run the `facter` binary on the command for a full list of facts supported on your host. + +Adding your own facts +--------------------- + +See the [Adding Facts](http://docs.puppetlabs.com/guides/custom_facts.html) page for details of how to add your own custom facts to Facter. + +Further Information +------------------- + +See http://www.puppetlabs.com/puppet/related-projects/facter for more details. diff --git a/README.rst b/README.rst deleted file mode 100644 index 2b71136..0000000 --- a/README.rst +++ /dev/null @@ -1,26 +0,0 @@ -Facter -====== - -This package is largely meant to be a library for collecting facts about your -system. These facts are mostly strings (i.e., not numbers), and are things -like the output of ``uname``, public ssh and cfengine keys, the number of -processors, etc. - -See ``bin/facter`` for an example of the interface. - -Running Facter -++++++++++++++ - -Run the ``facter`` binary on the command for a full list of facts supported on your host. - -Adding your own facts -+++++++++++++++++++++ - -See the `Adding Facts`_ page for details of how to add your own custom facts to Facter. - -Further Information -+++++++++++++++++++ - -See http://www.puppetlabs.com/puppet/related-projects/facter for more details. - -.. _Adding Facts: http://docs.puppetlabs.com/guides/custom_facts.html @@ -1,4 +0,0 @@ -More documentation. - -The ability to specify fact names with strings or symbols; right now, only -strings are supported @@ -52,8 +52,8 @@ # # = Copyright # -# Copyright (c) 2006 Reductive Labs, LLC -# Licensed under the GNU Public License +# Copyright (c) 2011 Puppet Labs, Inc +# Licensed under the Apache 2.0 license require 'facter/application' diff --git a/conf/redhat/facter.spec b/conf/redhat/facter.spec index 1148fd3..99a6505 100644 --- a/conf/redhat/facter.spec +++ b/conf/redhat/facter.spec @@ -7,7 +7,7 @@ Summary: Ruby module for collecting simple facts about a host operating system Name: facter Version: 1.5.8 Release: 1%{?dist} -License: GPLv2+ +License: Apache 2.0 Group: System Environment/Base URL: http://www.puppetlabs.com/puppet/related-projects/%{name}/ Source0: http://puppetlabs.com/downloads/%{name}/%{name}-%{version}.tar.gz @@ -119,7 +119,7 @@ def check_prereqs begin require pre rescue LoadError - puts "Could not load %s; cannot install" % pre + puts "Could not load #{pre} Ruby library; cannot install" exit -1 end } diff --git a/lib/facter.rb b/lib/facter.rb index 63eea37..2073b84 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -1,21 +1,18 @@ -#-- -# Copyright 2006 Luke Kanies <luke@madstop.com> +# Facter - Host Fact Detection and Reporting # -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. +# Copyright 2011 Puppet Labs Inc # -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# http://www.apache.org/licenses/LICENSE-2.0 # -#-- +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. module Facter # This is just so the other classes have the constant. diff --git a/lib/facter/Cfkey.rb b/lib/facter/Cfkey.rb index a4e0c11..e54aeb0 100644 --- a/lib/facter/Cfkey.rb +++ b/lib/facter/Cfkey.rb @@ -1,17 +1,17 @@ +# Fact: Cfkey +# +# Purpose: Return the public key(s) for CFengine. +# +# Resolution: +# Tries each file of standard localhost.pub & cfkey.pub locations, +# checks if they appear to be a public key, and then join them all together. +# +# Caveats: +# + ## Cfkey.rb ## Facts related to cfengine ## -## This program is free software; you can redistribute it and/or -## modify it under the terms of the GNU General Public License -## as published by the Free Software Foundation (version 2 of the License) -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA -## Facter.add(:Cfkey) do setcode do diff --git a/lib/facter/architecture.rb b/lib/facter/architecture.rb index e4aaeba..cd606a2 100644 --- a/lib/facter/architecture.rb +++ b/lib/facter/architecture.rb @@ -1,3 +1,16 @@ +# Fact: architecture +# +# Purpose: +# Return the CPU hardware architecture. +# +# Resolution: +# On OpenBSD, Linux and Debian's kfreebsd, use the hardwaremodel fact. +# Gentoo and Debian call "x86_86" "amd64". +# Gentoo also calls "i386" "x86". +# +# Caveats: +# + Facter.add(:architecture) do confine :kernel => [:linux, :"gnu/kfreebsd"] setcode do diff --git a/lib/facter/domain.rb b/lib/facter/domain.rb index 29bb204..2a79754 100644 --- a/lib/facter/domain.rb +++ b/lib/facter/domain.rb @@ -1,3 +1,23 @@ +# Fact: domain +# +# Purpose: +# Return the host's primary DNS domain name. +# +# Resolution: +# On UNIX (excluding Darwin), first try and use the hostname fact, +# which uses the hostname system command, and then parse the output +# of that. +# Failing that it tries the dnsdomainname system command. +# Failing that it uses /etc/resolv.conf and takes the domain from that, or as +# a final resort, the search from that. +# Otherwise returns nil. +# +# On Windows uses the win32ole gem and winmgmts to get the DNSDomain value +# from the Win32 networking stack. +# +# Caveats: +# + Facter.add(:domain) do setcode do # Get the domain from various sources; the order of these diff --git a/lib/facter/facterversion.rb b/lib/facter/facterversion.rb index 0b1cfda..574da99 100644 --- a/lib/facter/facterversion.rb +++ b/lib/facter/facterversion.rb @@ -1,3 +1,12 @@ +# Fact: facterversion +# +# Purpose: returns the version of the facter module. +# +# Resolution: Uses the version constant. +# +# Caveats: +# + Facter.add(:facterversion) do setcode { Facter::FACTERVERSION.to_s } end diff --git a/lib/facter/fqdn.rb b/lib/facter/fqdn.rb index 5ebc5f5..090ca63 100644 --- a/lib/facter/fqdn.rb +++ b/lib/facter/fqdn.rb @@ -1,3 +1,14 @@ +# Fact: fqdn +# +# Purpose: Returns the fully qualified domain name of the host. +# +# Resolution: Simply joins the hostname fact with the domain name fact. +# +# Caveats: No attempt is made to check that the two facts are accurate or that +# the two facts go together. At no point is there any DNS resolution made +# either. +# + Facter.add(:fqdn) do setcode do host = Facter.value(:hostname) diff --git a/lib/facter/hardwareisa.rb b/lib/facter/hardwareisa.rb index 23f7d08..9d0830e 100644 --- a/lib/facter/hardwareisa.rb +++ b/lib/facter/hardwareisa.rb @@ -1,3 +1,15 @@ +# Fact: hardwareisa +# +# Purpose: +# Returns hardware processor type. +# +# Resolution: +# On Solaris, Linux and the BSDs simply uses the output of "uname -p" +# +# Caveats: +# Some linuxes return unknown to uname -p with relative ease. +# + Facter.add(:hardwareisa) do setcode 'uname -p', '/bin/sh' confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo FreeBSD OpenBSD NetBSD OEL OVS GNU/kFreeBSD} diff --git a/lib/facter/hardwaremodel.rb b/lib/facter/hardwaremodel.rb index 6201bdd..8f52fef 100644 --- a/lib/facter/hardwaremodel.rb +++ b/lib/facter/hardwaremodel.rb @@ -1,3 +1,16 @@ +# Fact: hardwaremodel +# +# Purpose: +# Returns the hardware model of the system. +# +# Resolution: +# Uses purely "uname -m" on all platforms other than AIX and Windows. +# On AIX uses the parsed "modelname" output of "lsattr -El sys0 -a modelname". +# On Windows uses the 'host_cpu' pulled out of Ruby's config. +# +# Caveats: +# + Facter.add(:hardwaremodel) do setcode 'uname -m' end diff --git a/lib/facter/hostname.rb b/lib/facter/hostname.rb index 188efa4..0dcd01c 100644 --- a/lib/facter/hostname.rb +++ b/lib/facter/hostname.rb @@ -1,3 +1,16 @@ +# Fact: hostname +# +# Purpose: Return the system's short hostname. +# +# Resolution: +# On all system bar Darwin, parses the output of the "hostname" system command +# to everything before the first period. +# On Darwin, uses the system configuration util to get the LocalHostName +# variable. +# +# Caveats: +# + Facter.add(:hostname, :ldapname => "cn") do setcode do hostname = nil diff --git a/lib/facter/id.rb b/lib/facter/id.rb index 1c42284..cc0a0a6 100644 --- a/lib/facter/id.rb +++ b/lib/facter/id.rb @@ -1,3 +1,16 @@ +# Fact: id +# +# Purpose: Internal fact used to specity the program to return the currently +# running user id. +# +# Resolution: +# On all Unixes bar Solaris, just returns "whoami". +# On Solaris, parses the output of the "id" command to grab the username, as +# Solaris doesn't have the whoami command. +# +# Caveats: +# + Facter.add(:id) do setcode "whoami" end diff --git a/lib/facter/interfaces.rb b/lib/facter/interfaces.rb index 4fbaef1..04b1c19 100644 --- a/lib/facter/interfaces.rb +++ b/lib/facter/interfaces.rb @@ -1,3 +1,12 @@ +# Fact: interfaces +# +# Purpose: +# +# Resolution: +# +# Caveats: +# + # interfaces.rb # Try to get additional Facts about the machine's network interfaces # diff --git a/lib/facter/ipaddress.rb b/lib/facter/ipaddress.rb index d563408..5260504 100644 --- a/lib/facter/ipaddress.rb +++ b/lib/facter/ipaddress.rb @@ -1,3 +1,27 @@ +# Fact: ipaddress +# +# Purpose: Return the main IP address for a host. +# +# Resolution: +# On the Unixes does an ifconfig, and returns the first non 127.0.0.0/8 +# subnetted IP it finds. +# On Windows, it attempts to use the socket library and resolve the machine's +# hostname via DNS. +# +# On LDAP based hosts it tries to use either the win32/resolv library to +# resolve the hostname to an IP address, or on Unix, it uses the resolv +# library. +# +# As a fall back for undefined systems, it tries to run the "host" command to +# resolve the machine's hostname using the system DNS. +# +# Caveats: +# DNS resolution relies on working DNS infrastructure and resolvers on the +# host system. +# The ifconfig parsing purely takes the first IP address it finds without any +# checking this is a useful IP address. +# + Facter.add(:ipaddress) do confine :kernel => :linux setcode do diff --git a/lib/facter/ipaddress6.rb b/lib/facter/ipaddress6.rb index 547d636..db3805b 100644 --- a/lib/facter/ipaddress6.rb +++ b/lib/facter/ipaddress6.rb @@ -1,32 +1,46 @@ +# Fact: ipaddress6 +# +# Purpose: Returns the "main" IPv6 IP address of a system. +# +# Resolution: +# OS dependant code that parses the output of various networking +# tools and currently not very intelligent. Returns the first +# non-loopback and non-linklocal address found in the ouput unless +# a default route can be mapped to a routeable interface. Guessing +# an interface is currently only possible with BSD type systems +# to many assumptions have to be made on other platforms to make +# this work with the current code. Most code ported or modeled +# after the ipaddress fact for the sake of similar functionality +# and familiar mechanics. +# +# Caveats: +# + # Cody Herriges <c.a.herriges@gmail.com> # # Used the ipaddress fact that is already part of # Facter as a template. -# OS dependant code that parses the output of various networking -# tools and currently not very intelligent. Returns the first -# non-loopback and non-linklocal address found in the ouput unless -# a default route can be mapped to a routeable interface. Guessing -# an interface is currently only possible with BSD type systems -# to many assumptions have to be made on other platforms to make -# this work with the current code. Most code ported or modeled -# after the ipaddress fact for the sake of similar functionality -# and familiar mechanics. +def get_address_after_token(output, token, return_first=false) + ip = nil + + output.scan(/#{token} ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each do |match| + match = match.first + unless match =~ /fe80.*/ or match == "::1" + ip = match + break if return_first + end + end + + ip +end + Facter.add(:ipaddress6) do confine :kernel => :linux setcode do - ip = nil output = Facter::Util::Resolution.exec('/sbin/ifconfig') - output.scan(/inet6 addr: ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each { |str| - str = str.to_s - unless str =~ /fe80.*/ or str == "::1" - ip = str - end - } - - ip - + get_address_after_token(output, 'inet6 addr:') end end @@ -34,17 +48,8 @@ Facter.add(:ipaddress6) do confine :kernel => %w{SunOS} setcode do output = Facter::Util::Resolution.exec('/usr/sbin/ifconfig -a') - ip = nil - - output.scan(/inet6 ((?>[0-9,a-f,A-F]*\:{0,2})+[0-9,a-f,A-F]{0,4})/).each { |str| - str = str.to_s - unless str =~ /fe80.*/ or str == "::1" - ip = str - end - } - - ip + get_address_after_token(output, 'inet6') end end @@ -52,17 +57,7 @@ Facter.add(:ipaddress6) do confine :kernel => %w{Darwin FreeBSD OpenBSD} setcode do output = Facter::Util::Resolution.exec('/sbin/ifconfig -a') - ip = nil - - output.scan(/inet6 ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each do |str| - str = str.to_s - unless str =~ /fe80.*/ or str == "::1" - ip = str - break - end - end - ip + get_address_after_token(output, 'inet6', true) end end - diff --git a/lib/facter/iphostnumber.rb b/lib/facter/iphostnumber.rb index bc38432..cddaadd 100644 --- a/lib/facter/iphostnumber.rb +++ b/lib/facter/iphostnumber.rb @@ -1,3 +1,14 @@ +# Fact: iphostnumber +# +# Purpose: On selected versions of Darwin, returns the host's IP address. +# +# Resolution: +# Uses either the scutil program to get the localhost name, or parses output +# of ifconfig for a MAC address. +# +# Caveats: +# + Facter.add(:iphostnumber) do confine :kernel => :darwin, :kernelrelease => "R6" setcode do diff --git a/lib/facter/kernel.rb b/lib/facter/kernel.rb index 66f21ce..f457e01 100644 --- a/lib/facter/kernel.rb +++ b/lib/facter/kernel.rb @@ -1,3 +1,14 @@ +# Fact: kernel +# +# Purpose: Returns the operating system's name. +# +# Resolution: +# Uses Ruby's rbconfig to find host_os, if that is a Windows derivative, the +# returns 'windows', otherwise returns "uname -s" verbatim. +# +# Caveats: +# + Facter.add(:kernel) do setcode do require 'rbconfig' diff --git a/lib/facter/kernelmajversion.rb b/lib/facter/kernelmajversion.rb index 32fd7aa..84f71d4 100644 --- a/lib/facter/kernelmajversion.rb +++ b/lib/facter/kernelmajversion.rb @@ -1,3 +1,13 @@ +# Fact: kernelmajversion +# +# Purpose: Return the operating system's release number's major value. +# +# Resolution: +# Takes the first 2 elements of the kernel version as delimited by periods. +# +# Caveats: +# + Facter.add("kernelmajversion") do setcode do Facter.value(:kernelversion).split('.')[0..1].join('.') diff --git a/lib/facter/kernelrelease.rb b/lib/facter/kernelrelease.rb index 2f6ae45..a6f9c2c 100644 --- a/lib/facter/kernelrelease.rb +++ b/lib/facter/kernelrelease.rb @@ -1,3 +1,16 @@ +# Fact: kernelrelease +# +# Purpose: Return the operating system's release number. +# +# Resolution: +# On AIX returns the output from the "oslevel -s" system command. +# On Windows based systems, uses the win32ole gem to query Windows Management +# for the 'Win32_OperatingSystem' value. +# Otherwise uses the output of "uname -r" system command. +# +# Caveats: +# + Facter.add(:kernelrelease) do setcode 'uname -r' end diff --git a/lib/facter/kernelversion.rb b/lib/facter/kernelversion.rb index cac6c14..7e0d95c 100644 --- a/lib/facter/kernelversion.rb +++ b/lib/facter/kernelversion.rb @@ -1,3 +1,15 @@ +# Fact: kernelversion +# +# Purpose: Return the operating system's kernel version. +# +# Resolution: +# On Solaris and SunOS based machines, returns the output of "uname -v". +# Otherwise returns the 'kernerlversion' fact up to the first '-'. This may be +# the entire 'kernelversion' fact in many cases. +# +# Caveats: +# + Facter.add("kernelversion") do setcode do Facter['kernelrelease'].value.split('-')[0] diff --git a/lib/facter/lsb.rb b/lib/facter/lsb.rb index bf4b9db..7beb41d 100644 --- a/lib/facter/lsb.rb +++ b/lib/facter/lsb.rb @@ -1,17 +1,18 @@ +# Fact: lsb +# +# Purpose: Return Linux Standard Base information for the host. +# +# Resolution: +# Uses the lsb_release system command and parses the output with a series of +# regular expressions. +# +# Caveats: +# Only works on Linux (and the kfreebsd derivative) systems. +# Requires the lsb_release program, which may not be installed by default. +# Also is as only as accurate as that program outputs. + ## lsb.rb ## Facts related to Linux Standard Base (LSB) -## -## This program is free software; you can redistribute it and/or -## modify it under the terms of the GNU General Public License -## as published by the Free Software Foundation (version 2 of the License) -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA -## { "LSBRelease" => %r{^LSB Version:\t(.*)$}, "LSBDistId" => %r{^Distributor ID:\t(.*)$}, diff --git a/lib/facter/lsbmajdistrelease.rb b/lib/facter/lsbmajdistrelease.rb index 34a2f1e..3659541 100644 --- a/lib/facter/lsbmajdistrelease.rb +++ b/lib/facter/lsbmajdistrelease.rb @@ -1,3 +1,15 @@ +# Fact: lsbmajdistrelease +# +# Purpose: Returns the major version of the operation system version as gleaned +# from the lsbdistrelease fact. +# +# Resolution: +# Parses the lsbdistrelease fact for numbers followed by a period and +# returns those, or just the lsbdistrelease fact if none were found. +# +# Caveats: +# + # lsbmajdistrelease.rb # require 'facter' diff --git a/lib/facter/macaddress.rb b/lib/facter/macaddress.rb index 4a12384..54c3c84 100644 --- a/lib/facter/macaddress.rb +++ b/lib/facter/macaddress.rb @@ -1,3 +1,12 @@ +# Fact: macaddress +# +# Purpose: +# +# Resolution: +# +# Caveats: +# + require 'facter/util/macaddress' Facter.add(:macaddress) do @@ -13,6 +22,18 @@ Facter.add(:macaddress) do end Facter.add(:macaddress) do + confine :operatingsystem => "Solaris" + setcode do + ether = [] + output = Facter::Util::Resolution.exec("/usr/bin/netstat -np") + output.each_line do |s| + ether.push($1) if s =~ /(?:SPLA)\s+(\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2})/ + end + ether[0] + end +end + +Facter.add(:macaddress) do confine :operatingsystem => %w{FreeBSD OpenBSD} setcode do ether = [] diff --git a/lib/facter/macosx.rb b/lib/facter/macosx.rb index 3841c50..7c8562d 100644 --- a/lib/facter/macosx.rb +++ b/lib/facter/macosx.rb @@ -1,3 +1,16 @@ +# Fact: macosx +# +# Purpose: +# Returns a number of Mac specific facts, from system profiler and +# sw_vers. +# +# Resolution: +# Uses util/macosx.rb to do the fact reconnaissance, then outputs them +# preceded by 'sp_' +# +# Caveats: +# + # # macosx.rb # Additional Facts coming from Mac OS X system_profiler command @@ -5,17 +18,6 @@ # Copyright (C) 2007 Jeff McCune # Author: Jeff McCune <jeff.mccune@northstarlabs.net> # -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation (version 2 of the License) -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA - # Jeff McCune # There's a lot more information coming out of system_profiler -xml # We could add quite a bit more, but I didn't want to overload facter diff --git a/lib/facter/manufacturer.rb b/lib/facter/manufacturer.rb index 4f2df98..26aef5f 100644 --- a/lib/facter/manufacturer.rb +++ b/lib/facter/manufacturer.rb @@ -1,3 +1,16 @@ +# Fact: manufacturer +# +# Purpose: Return the hardware manufacturer information about the hardware. +# +# Resolution: +# On OpenBSD, queries sysctl values, via a util class. +# On SunOS Sparc, uses prtdiag via a util class. +# On Windows, queries the system via a util class. +# Uses the 'util/manufacturer.rb' for fallback parsing. +# +# Caveats: +# + # manufacturer.rb # Facts related to hardware manufacturer # diff --git a/lib/facter/memory.rb b/lib/facter/memory.rb index 9dd2e29..992f2ad 100644 --- a/lib/facter/memory.rb +++ b/lib/facter/memory.rb @@ -1,3 +1,20 @@ +# Fact: memory +# +# Purpose: Return information about memory and swap usage. +# +# Resolution: +# On Linuxes, uses Facter::Memory.meminfo_number from +# 'facter/util/memory.rb' +# On AIX, parses "swap -l" for swap values only. +# On OpenBSD, it parses "swapctl -l" for swap values, vmstat via a module for +# free memory, and "sysctl hw.physmem" for maximum memory. +# On Solaris, use "swap -l" for swap values, and parsing prtconf for maximum +# memory, and again, the vmstat module for free memory. +# +# Caveats: +# Some BSD platforms aren't covered at all. AIX is missing memory values. +# + # memory.rb # Additional Facts for memory/swap usage # @@ -23,30 +40,30 @@ end Facter.add("SwapSize") do confine :kernel => :Darwin setcode do - swap = Facter::Util::Resolution.exec('sysctl vm.swapusage') - swaptotal = 0 - if swap =~ /total = (\S+)/ then swaptotal = $1; end - swaptotal + swap = Facter::Util::Resolution.exec('sysctl vm.swapusage') + swaptotal = 0 + if swap =~ /total = (\S+)/ then swaptotal = $1; end + swaptotal end end Facter.add("SwapFree") do confine :kernel => :Darwin setcode do - swap = Facter::Util::Resolution.exec('sysctl vm.swapusage') - swapfree = 0 - if swap =~ /free = (\S+)/ then swapfree = $1; end - swapfree + swap = Facter::Util::Resolution.exec('sysctl vm.swapusage') + swapfree = 0 + if swap =~ /free = (\S+)/ then swapfree = $1; end + swapfree end end Facter.add("SwapEncrypted") do confine :kernel => :Darwin setcode do - swap = Facter::Util::Resolution.exec('sysctl vm.swapusage') - encrypted = false - if swap =~ /\(encrypted\)/ then encrypted = true; end - encrypted + swap = Facter::Util::Resolution.exec('sysctl vm.swapusage') + encrypted = false + if swap =~ /\(encrypted\)/ then encrypted = true; end + encrypted end end @@ -57,9 +74,9 @@ if Facter.value(:kernel) == "AIX" and Facter.value(:id) == "root" if dev =~ /^\/\S+\s.*\s+(\S+)MB\s+(\S+)MB/ swaptotal += $1.to_i swapfree += $2.to_i - end - end - + end + end + Facter.add("SwapSize") do confine :kernel => :aix setcode do @@ -154,9 +171,9 @@ if Facter.value(:kernel) == "SunOS" if dev =~ /^\/\S+\s.*\s+(\d+)\s+(\d+)$/ swaptotal += $1.to_i / 2 swapfree += $2.to_i / 2 - end - end - + end + end + Facter.add("SwapSize") do confine :kernel => :sunos setcode do diff --git a/lib/facter/netmask.rb b/lib/facter/netmask.rb index d6d125e..fbb84f5 100644 --- a/lib/facter/netmask.rb +++ b/lib/facter/netmask.rb @@ -1,3 +1,12 @@ +# Fact: netmask +# +# Purpose: Returns the netmask for the main interfaces. +# +# Resolution: Uses the facter/util/netmask library routines. +# +# Caveats: +# + # netmask.rb # Find the netmask of the primary ipaddress # Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at> diff --git a/lib/facter/network.rb b/lib/facter/network.rb index df53ce4..d4faaac 100644 --- a/lib/facter/network.rb +++ b/lib/facter/network.rb @@ -1,3 +1,15 @@ +# Fact: network +# +# Purpose: +# Get IP, network and netmask information for available network +# interfacs. +# +# Resolution: +# Uses 'facter/util/ip' to enumerate interfaces and return their information. +# +# Caveats: +# + require 'facter/util/ip' Facter::Util::IP.get_interfaces.each do |interface| diff --git a/lib/facter/operatingsystem.rb b/lib/facter/operatingsystem.rb index 25eeb00..a90c283 100644 --- a/lib/facter/operatingsystem.rb +++ b/lib/facter/operatingsystem.rb @@ -1,3 +1,16 @@ +# Fact: operatingsystem +# +# Purpose: Return the name of the operating system. +# +# Resolution: +# If the kernel is a Linux kernel, check for the existence of a selection of +# files in /etc/ to find the specific flavour. +# On SunOS based kernels, return Solaris. +# On systems other than Linux, use the kernel value. +# +# Caveats: +# + require 'facter/lsb' Facter.add(:operatingsystem) do diff --git a/lib/facter/operatingsystemrelease.rb b/lib/facter/operatingsystemrelease.rb index da1b76a..347fe7f 100644 --- a/lib/facter/operatingsystemrelease.rb +++ b/lib/facter/operatingsystemrelease.rb @@ -1,3 +1,20 @@ +# Fact: operatingsystemrelease +# +# Purpose: Returns the release of the operating system. +# +# Resolution: +# On RedHat derivatives, returns their '/etc/<variant>-release' file. +# On Debian, returns '/etc/debian_version'. +# On Ubuntu, parses '/etc/issue' for the release version. +# On Suse, derivatives, parses '/etc/SuSE-release' for a selection of version +# information. +# On Slackware, parses '/etc/slackware-version'. +# +# On all remaining systems, returns the 'kernelrelease' value. +# +# Caveats: +# + Facter.add(:operatingsystemrelease) do confine :operatingsystem => %w{CentOS Fedora oel ovs RedHat MeeGo} setcode do diff --git a/lib/facter/path.rb b/lib/facter/path.rb index 03907c0..71df6cd 100644 --- a/lib/facter/path.rb +++ b/lib/facter/path.rb @@ -1,3 +1,12 @@ +# Fact: path +# +# Purpose: Returns the $PATH variable. +# +# Resolution: Gets $PATH from the environment. +# +# Caveats: +# + Facter.add(:path) do setcode do ENV['PATH'] diff --git a/lib/facter/physicalprocessorcount.rb b/lib/facter/physicalprocessorcount.rb index 8fe643e..22c00c1 100644 --- a/lib/facter/physicalprocessorcount.rb +++ b/lib/facter/physicalprocessorcount.rb @@ -1,7 +1,56 @@ -Facter.add("physicalprocessorcount") do - confine :kernel => :linux +# Fact: physicalprocessorcount +# +# Purpose: Return the number of physical processors. +# +# Resolution: +# +# Attempts to use sysfs to get the physical IDs of the processors. Falls +# back to /proc/cpuinfo and "physical id" if sysfs is not available. +# +# Caveats: +# +Facter.add('physicalprocessorcount') do + confine :kernel => :linux - setcode do - ppcount = Facter::Util::Resolution.exec('grep "physical id" /proc/cpuinfo|cut -d: -f 2|sort -u|wc -l') + setcode do + sysfs_cpu_directory = '/sys/devices/system/cpu' # This should always be there ... + + if File.exists?(sysfs_cpu_directory) + # + # We assume that the sysfs file system has the correct number of entries + # under the "/sys/device/system/cpu" directory and if so then we process + # content of the file "physical_package_id" located inside the "topology" + # directory in each of the per-CPU sub-directories. + # + # As per Linux Kernel documentation and the file "cputopology.txt" located + # inside the "/usr/src/linux/Documentation" directory we can find following + # short explanation: + # + # (...) + # + # 1) /sys/devices/system/cpu/cpuX/topology/physical_package_id: + # + # physical package id of cpuX. Typically corresponds to a physical + # socket number, but the actual value is architecture and platform + # dependent. + # + # (...) + # + lookup_pattern = "#{sysfs_cpu_directory}" + + "/cpu*/topology/physical_package_id" + + Dir.glob(lookup_pattern).collect { |f| Facter::Util::Resolution.exec("cat #{f}")}.uniq.size + + else + # + # Try to count number of CPUs using the proc file system next ... + # + # We assume that /proc/cpuinfo has what we need and is so then we need + # to make sure that we only count unique entries ... + # + str = Facter::Util::Resolution.exec("grep 'physical.\\+:' /proc/cpuinfo") + + if str then str.scan(/\d+/).uniq.size; end end + end end diff --git a/lib/facter/processor.rb b/lib/facter/processor.rb index c71bad4..ec196b2 100644 --- a/lib/facter/processor.rb +++ b/lib/facter/processor.rb @@ -1,5 +1,18 @@ +# Fact: processor +# +# Purpose: +# Additional Facts about the machine's CPUs. +# +# Resolution: +# On Linux and kFreeBSD, parse '/proc/cpuinfo' for each processor. +# On AIX, parse the output of 'lsdev' for it's processor section. +# On OpenBSD, use 'uname -p' and the sysctl variable for 'hw.ncpu' for CPU +# count. +# +# Caveats: +# + # processor.rb -# Additional Facts about the machine's CPUs # # Copyright (C) 2006 Mooter Media Ltd # Author: Matthew Palmer <matt@solutionsfirst.com.au> diff --git a/lib/facter/ps.rb b/lib/facter/ps.rb index e7bcdae..ef803fb 100644 --- a/lib/facter/ps.rb +++ b/lib/facter/ps.rb @@ -1,3 +1,15 @@ +# Fact: ps +# +# Purpose: Internal fact for what to use to list all processes. Used by +# Service{} type in Puppet. +# +# Resolution: +# Assumes "ps -ef" for all operating systems other than BSD derivatives, where +# it uses "ps auxwww" +# +# Caveats: +# + Facter.add(:ps) do setcode do 'ps -ef' end end diff --git a/lib/facter/puppetversion.rb b/lib/facter/puppetversion.rb index d2eb1f3..01422f0 100644 --- a/lib/facter/puppetversion.rb +++ b/lib/facter/puppetversion.rb @@ -1,3 +1,13 @@ +# Fact: puppetversion +# +# Purpose: Return the version of puppet installed. +# +# Resolution: +# Requres puppet via Ruby and returns it's version constant. +# +# Caveats: +# + Facter.add(:puppetversion) do setcode do begin diff --git a/lib/facter/rubysitedir.rb b/lib/facter/rubysitedir.rb index c205322..9973329 100644 --- a/lib/facter/rubysitedir.rb +++ b/lib/facter/rubysitedir.rb @@ -1,3 +1,13 @@ +# Fact: rubysitedir +# +# Purpose: Returns Ruby's site library directory. +# +# Resolution: Works out the version to major/minor (1.8, 1.9, etc), then joins +# that with all the $: library paths. +# +# Caveats: +# + Facter.add :rubysitedir do setcode do version = RUBY_VERSION.to_s.sub(/\.\d+$/, '') diff --git a/lib/facter/rubyversion.rb b/lib/facter/rubyversion.rb index 48f5cc8..e578400 100644 --- a/lib/facter/rubyversion.rb +++ b/lib/facter/rubyversion.rb @@ -1,3 +1,12 @@ +# Fact: rubyversion +# +# Purpose: Returns the version of Ruby facter is running under. +# +# Resolution: Returns RUBY_VERSION. +# +# Caveats: +# + Facter.add(:rubyversion) do setcode { RUBY_VERSION.to_s } end diff --git a/lib/facter/selinux.rb b/lib/facter/selinux.rb index 9fab427..1555da0 100644 --- a/lib/facter/selinux.rb +++ b/lib/facter/selinux.rb @@ -1,3 +1,12 @@ +# Fact: selinux +# +# Purpose: +# +# Resolution: +# +# Caveats: +# + # Fact for SElinux # Written by immerda admin team (admin(at)immerda.ch) diff --git a/lib/facter/ssh.rb b/lib/facter/ssh.rb index 318e9d4..5ae68ed 100644 --- a/lib/facter/ssh.rb +++ b/lib/facter/ssh.rb @@ -1,17 +1,15 @@ +# Fact: ssh +# +# Purpose: +# +# Resolution: +# +# Caveats: +# + ## ssh.rb ## Facts related to SSH ## -## This program is free software; you can redistribute it and/or -## modify it under the terms of the GNU General Public License -## as published by the Free Software Foundation (version 2 of the License) -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA -## ["/etc/ssh","/usr/local/etc/ssh","/etc","/usr/local/etc"].each do |dir| {"SSHDSAKey" => "ssh_host_dsa_key.pub", "SSHRSAKey" => "ssh_host_rsa_key.pub"}.each do |name,file| diff --git a/lib/facter/timezone.rb b/lib/facter/timezone.rb index 744e06a..462c9ba 100644 --- a/lib/facter/timezone.rb +++ b/lib/facter/timezone.rb @@ -1,3 +1,12 @@ +# Fact: timezone +# +# Purpose: Return the machine's time zone. +# +# Resolution: Uses's Ruby's Time module's Time.new call. +# +# Caveats: +# + Facter.add("timezone") do setcode do Time.new.zone diff --git a/lib/facter/uptime.rb b/lib/facter/uptime.rb index 56a959b..7aeeb39 100644 --- a/lib/facter/uptime.rb +++ b/lib/facter/uptime.rb @@ -1,3 +1,14 @@ +# Fact: uptime +# +# Purpose: return the system uptime in a human readable format. +# +# Resolution: +# Does basic maths on the "uptime_seconds" fact to return a count of +# days, hours and minutes of uptime +# +# Caveats: +# + require 'facter/util/uptime' Facter.add(:uptime) do diff --git a/lib/facter/uptime_days.rb b/lib/facter/uptime_days.rb index add305c..25af966 100644 --- a/lib/facter/uptime_days.rb +++ b/lib/facter/uptime_days.rb @@ -1,3 +1,12 @@ +# Fact: uptime_days +# +# Purpose: Return purely number of days of uptime. +# +# Resolution: Divides uptime_hours fact by 24. +# +# Caveats: +# + Facter.add(:uptime_days) do setcode do hours = Facter.value(:uptime_hours) diff --git a/lib/facter/uptime_hours.rb b/lib/facter/uptime_hours.rb index ce691d2..d02ac32 100644 --- a/lib/facter/uptime_hours.rb +++ b/lib/facter/uptime_hours.rb @@ -1,3 +1,12 @@ +# Fact: uptime_hours +# +# Purpose: Return purely number of hours of uptime. +# +# Resolution: Divides uptime_seconds fact by 3600. +# +# Caveats: +# + Facter.add(:uptime_hours) do setcode do seconds = Facter.value(:uptime_seconds) diff --git a/lib/facter/uptime_seconds.rb b/lib/facter/uptime_seconds.rb index 14bb573..9793e41 100644 --- a/lib/facter/uptime_seconds.rb +++ b/lib/facter/uptime_seconds.rb @@ -1,3 +1,17 @@ +# Fact: uptime_seconds +# +# Purpose: Return purely number of seconds of uptime. +# +# Resolution: +# Using the 'facter/util/uptime.rb' module, try a verity of methods to acquire +# the uptime on Unix. +# +# On Windows, the module calculates the uptime by the "LastBootupTime" Windows +# management value. +# +# Caveats: +# + require 'facter/util/uptime' Facter.add(:uptime_seconds) do diff --git a/lib/facter/util/fact.rb b/lib/facter/util/fact.rb index e78ed97..935b3c1 100644 --- a/lib/facter/util/fact.rb +++ b/lib/facter/util/fact.rb @@ -41,9 +41,7 @@ class Facter::Util::Fact # Immediately sort the resolutions, so that we always have # a sorted list for looking up values. - # We always want to look them up in the order of number of - # confines, so the most restricted resolution always wins. - @resolves.sort! { |a, b| b.length <=> a.length } + @resolves.sort! { |a, b| b.weight <=> a.weight } return resolve end diff --git a/lib/facter/util/loader.rb b/lib/facter/util/loader.rb index 2d2d9e8..a52012c 100644 --- a/lib/facter/util/loader.rb +++ b/lib/facter/util/loader.rb @@ -90,6 +90,7 @@ class Facter::Util::Loader next if fact and env_name != fact Facter.add($1) do + has_weight 1_000_000 setcode { value } end diff --git a/lib/facter/util/macosx.rb b/lib/facter/util/macosx.rb index 6754f18..cc9b2df 100644 --- a/lib/facter/util/macosx.rb +++ b/lib/facter/util/macosx.rb @@ -4,17 +4,6 @@ ## Copyright (C) 2007 Jeff McCune ## Author: Jeff McCune <jeff.mccune@northstarlabs.net> ## -## This program is free software; you can redistribute it and/or -## modify it under the terms of the GNU General Public License -## as published by the Free Software Foundation (version 2 of the License) -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA -## module Facter::Util::Macosx require 'thread' diff --git a/lib/facter/util/memory.rb b/lib/facter/util/memory.rb index 029b117..d49079d 100644 --- a/lib/facter/util/memory.rb +++ b/lib/facter/util/memory.rb @@ -1,17 +1,6 @@ ## memory.rb ## Support module for memory related facts ## -## This program is free software; you can redistribute it and/or -## modify it under the terms of the GNU General Public License -## as published by the Free Software Foundation (version 2 of the License) -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA -## module Facter::Memory require 'thread' @@ -75,7 +64,7 @@ module Facter::Memory memspecfree = 0 vmstats = Facter::Util::Resolution.exec('vm_stat') - vmstats.each do |vmline| + vmstats.each_line do |vmline| case when vmline =~ /page\ssize\sof\s(\d+)\sbytes/ pagesize = $1.to_i @@ -94,4 +83,3 @@ module Facter::Memory end end end - diff --git a/lib/facter/util/resolution.rb b/lib/facter/util/resolution.rb index 4a99c35..d82fab2 100644 --- a/lib/facter/util/resolution.rb +++ b/lib/facter/util/resolution.rb @@ -85,17 +85,26 @@ class Facter::Util::Resolution end end + def has_weight(weight) + @weight = weight + end + # Create a new resolution mechanism. def initialize(name) @name = name @confines = [] @value = nil @timeout = 0 + @weight = nil end - # Return the number of confines. - def length - @confines.length + # Return the importance of this resolution. + def weight + if @weight + @weight + else + @confines.length + end end # We need this as a getter for 'timeout', because some versions diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb index 4355451..8bdde16 100644 --- a/lib/facter/util/virtual.rb +++ b/lib/facter/util/virtual.rb @@ -1,6 +1,6 @@ module Facter::Util::Virtual def self.openvz? - FileTest.directory?("/proc/vz") + FileTest.directory?("/proc/vz") and FileTest.exists?( '/proc/vz/veinfo' ) end def self.openvz_type diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb index 468ab77..a583995 100644 --- a/lib/facter/virtual.rb +++ b/lib/facter/virtual.rb @@ -1,3 +1,30 @@ +# Fact: virtual +# +# Purpose: Determine if the system's hardware is real or virtualised. +# +# Resolution: +# Assumes physical unless proven otherwise. +# +# On Darwin, use the macosx util module to acquire the SPDisplaysDataType, +# from that parse it to see if it's VMWare or Parallels pretending to be the +# display. +# +# On Linux, BSD, Solaris and HPUX: +# Much of the logic here is obscured behind util/virtual.rb, which rather +# than document here, which would encourage drift, just refer to it. +# The Xen tests in here rely on /sys and /proc, and check for the presence and +# contents of files in there. +# If after all the other tests, it's still seen as physical, then it tries to +# parse the output of the "lspci", "dmidecode" and "prtdiag" and parses them +# for obvious signs of being under VMWare or Parallels. +# Finally it checks for the existence of vmware-vmx, which would hint it's +# VMWare. +# +# Caveats: +# Virtualbox detection isn't implemented. +# Many checks rely purely on existence of files. +# + require 'facter/util/virtual' Facter.add("virtual") do @@ -25,7 +52,7 @@ Facter.add("virtual") do setcode do - if Facter::Util::Virtual.zone? and Facter.value(:operatingsystem) == "Solaris" + if Facter.value(:operatingsystem) == "Solaris" and Facter::Util::Virtual.zone? result = "zone" end @@ -77,6 +104,9 @@ Facter.add("virtual") do # --- look for the vmware video card to determine if it is virtual => vmware. # --- 00:0f.0 VGA compatible controller: VMware Inc [VMware SVGA II] PCI Display Adapter result = "vmware" if p =~ /VM[wW]are/ + # --- look for virtualbox video card to determine if it is virtual => virtualbox. + # --- 00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter + result = "virtualbox" if p =~ /VirtualBox/ # --- look for pci vendor id used by Parallels video card # --- 01:00.0 VGA compatible controller: Unknown device 1ab8:4005 result = "parallels" if p =~ /1ab8:|[Pp]arallels/ @@ -87,13 +117,18 @@ Facter.add("virtual") do output.each_line do |pd| result = "parallels" if pd =~ /Parallels/ result = "vmware" if pd =~ /VMware/ + result = "virtualbox" if pd =~ /VirtualBox/ end - else - output = Facter::Util::Resolution.exec('prtdiag') + elsif Facter.value(:kernel) == 'SunOS' + res = Facter::Util::Resolution.new('prtdiag') + res.timeout = 6 + res.setcode('prtdiag') + output = res.value if not output.nil? output.each_line do |pd| result = "parallels" if pd =~ /Parallels/ result = "vmware" if pd =~ /VMware/ + result = "virtualbox" if pd =~ /VirtualBox/ end end end @@ -108,6 +143,17 @@ Facter.add("virtual") do end end +# Fact: is_virtual +# +# Purpose: returning true or false for if a machine is virtualised or not. +# +# Resolution: The Xen domain 0 machine is virtualised to a degree, but is generally +# not viewed as being a virtual machine. This checks that the machine is not +# physical nor xen0, if that is the case, it is virtual. +# +# Caveats: +# + Facter.add("is_virtual") do confine :kernel => %w{Linux FreeBSD OpenBSD SunOS HP-UX Darwin GNU/kFreeBSD} diff --git a/lib/facter/vlans.rb b/lib/facter/vlans.rb index d65bdd8..8c485a4 100644 --- a/lib/facter/vlans.rb +++ b/lib/facter/vlans.rb @@ -1,3 +1,13 @@ +# Fact: vlans +# +# Purpose: On Linux, return a list of all the VLANs on the system. +# +# Resolution: On Linux only, checks for and reads /proc/net/vlan/config and +# parses it. +# +# Caveats: +# + require 'facter/util/vlans' Facter.add("vlans") do diff --git a/lib/facter/xendomains.rb b/lib/facter/xendomains.rb index 972ac90..5bcde05 100644 --- a/lib/facter/xendomains.rb +++ b/lib/facter/xendomains.rb @@ -1,3 +1,14 @@ +# Fact: xendomains +# +# Purpose: Return the list of Xen domains on the Dom0. +# +# Resolution: +# On a Xen Dom0 host, return a list of Xen domains using the 'util/xendomains' +# library. +# +# Caveats: +# + require 'facter/util/xendomains' Facter.add("xendomains") do diff --git a/spec/fixtures/uptime/sysctl_kern_boottime_big_endian b/spec/fixtures/uptime/sysctl_kern_boottime_big_endian Binary files differnew file mode 100644 index 0000000..6b7be22 --- /dev/null +++ b/spec/fixtures/uptime/sysctl_kern_boottime_big_endian diff --git a/spec/fixtures/uptime/sysctl_kern_boottime b/spec/fixtures/uptime/sysctl_kern_boottime_little_endian Binary files differindex 0c54fe4..0c54fe4 100644 --- a/spec/fixtures/uptime/sysctl_kern_boottime +++ b/spec/fixtures/uptime/sysctl_kern_boottime_little_endian diff --git a/spec/unit/physicalprocessorcount_spec.rb b/spec/unit/physicalprocessorcount_spec.rb new file mode 100644 index 0000000..e1f7c60 --- /dev/null +++ b/spec/unit/physicalprocessorcount_spec.rb @@ -0,0 +1,40 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +require 'facter' + +describe "Physical processor count facts" do + before do + Facter.loadfacts + end + before do + Facter.clear + end + it "should return one physical CPU" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true) + Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu*/topology/physical_package_id").returns(["/sys/devices/system/cpu/cpu0/topology/physical_package_id"]) + Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu0/topology/physical_package_id").returns("0") + + Facter.fact(:physicalprocessorcount).value.should == 1 + end + + it "should return four physical CPUs" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true) + Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu*/topology/physical_package_id").returns(%w{ + /sys/devices/system/cpu/cpu0/topology/physical_package_id + /sys/devices/system/cpu/cpu1/topology/physical_package_id + /sys/devices/system/cpu/cpu2/topology/physical_package_id + /sys/devices/system/cpu/cpu3/topology/physical_package_id + }) + + Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu0/topology/physical_package_id").returns("0") + Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu1/topology/physical_package_id").returns("1") + Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu2/topology/physical_package_id").returns("2") + Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu3/topology/physical_package_id").returns("3") + + Facter.fact(:physicalprocessorcount).value.should == 4 + end +end diff --git a/spec/unit/util/fact_spec.rb b/spec/unit/util/fact_spec.rb index db08670..523c855 100755 --- a/spec/unit/util/fact_spec.rb +++ b/spec/unit/util/fact_spec.rb @@ -56,10 +56,10 @@ describe Facter::Util::Fact do @fact.add { } end - it "should re-sort the resolutions by length, so the most restricted resolutions are first" do - r1 = stub 'r1', :length => 1 - r2 = stub 'r2', :length => 2 - r3 = stub 'r3', :length => 0 + it "should re-sort the resolutions by weight, so the most restricted resolutions are first" do + r1 = stub 'r1', :weight => 1 + r2 = stub 'r2', :weight => 2 + r3 = stub 'r3', :weight => 0 Facter::Util::Resolution.expects(:new).times(3).returns(r1).returns(r2).returns(r3) @fact.add { } @fact.add { } @@ -83,9 +83,9 @@ describe Facter::Util::Fact do end it "should return the first value returned by a resolution" do - r1 = stub 'r1', :length => 2, :value => nil, :suitable? => true - r2 = stub 'r2', :length => 1, :value => "yay", :suitable? => true - r3 = stub 'r3', :length => 0, :value => "foo", :suitable? => true + r1 = stub 'r1', :weight => 2, :value => nil, :suitable? => true + r2 = stub 'r2', :weight => 1, :value => "yay", :suitable? => true + r3 = stub 'r3', :weight => 0, :value => "foo", :suitable? => true Facter::Util::Resolution.expects(:new).times(3).returns(r1).returns(r2).returns(r3) @fact.add { } @fact.add { } @@ -95,8 +95,8 @@ describe Facter::Util::Fact do end it "should short-cut returning the value once one is found" do - r1 = stub 'r1', :length => 2, :value => "foo", :suitable? => true - r2 = stub 'r2', :length => 1, :suitable? => true # would fail if 'value' were asked for + r1 = stub 'r1', :weight => 2, :value => "foo", :suitable? => true + r2 = stub 'r2', :weight => 1, :suitable? => true # would fail if 'value' were asked for Facter::Util::Resolution.expects(:new).times(2).returns(r1).returns(r2) @fact.add { } @fact.add { } @@ -105,8 +105,8 @@ describe Facter::Util::Fact do end it "should skip unsuitable resolutions" do - r1 = stub 'r1', :length => 2, :suitable? => false # would fail if 'value' were asked for' - r2 = stub 'r2', :length => 1, :value => "yay", :suitable? => true + r1 = stub 'r1', :weight => 2, :suitable? => false # would fail if 'value' were asked for' + r2 = stub 'r2', :weight => 1, :value => "yay", :suitable? => true Facter::Util::Resolution.expects(:new).times(2).returns(r1).returns(r2) @fact.add { } @fact.add { } diff --git a/spec/unit/util/resolution_spec.rb b/spec/unit/util/resolution_spec.rb index 581d0e1..3e13cdc 100755 --- a/spec/unit/util/resolution_spec.rb +++ b/spec/unit/util/resolution_spec.rb @@ -13,6 +13,10 @@ describe Facter::Util::Resolution do Facter::Util::Resolution.new("yay").name.should == "yay" end + it "should have a method for setting the weight" do + Facter::Util::Resolution.new("yay").should respond_to(:has_weight) + end + it "should have a method for setting the code" do Facter::Util::Resolution.new("yay").should respond_to(:setcode) end @@ -195,11 +199,25 @@ describe Facter::Util::Resolution do it "should provide a method for returning the number of confines" do @resolve = Facter::Util::Resolution.new("yay") @resolve.confine "one" => "foo", "two" => "fee" - @resolve.length.should == 2 + @resolve.weight.should == 2 end it "should return 0 confines when no confines have been added" do - Facter::Util::Resolution.new("yay").length.should == 0 + Facter::Util::Resolution.new("yay").weight.should == 0 + end + + it "should provide a way to set the weight" do + @resolve = Facter::Util::Resolution.new("yay") + @resolve.has_weight(45) + @resolve.weight.should == 45 + end + + it "should allow the weight to override the number of confines" do + @resolve = Facter::Util::Resolution.new("yay") + @resolve.confine "one" => "foo", "two" => "fee" + @resolve.weight.should == 2 + @resolve.has_weight(45) + @resolve.weight.should == 45 end it "should have a method for determining if it is suitable" do diff --git a/spec/unit/util/uptime_spec.rb b/spec/unit/util/uptime_spec.rb index 8d3980c..98a1a1b 100755 --- a/spec/unit/util/uptime_spec.rb +++ b/spec/unit/util/uptime_spec.rb @@ -27,7 +27,12 @@ describe Facter::Util::Uptime do end it "should use 'sysctl kern.boottime'" do - sysctl_output_file = File.join(SPECDIR, 'fixtures', 'uptime', 'sysctl_kern_boottime') # Aug 01 14:13:47 -0700 2010 + if [1].pack("L") == [1].pack("V") # Determine endianness + sysctl_output_filename = 'sysctl_kern_boottime_little_endian' + else + sysctl_output_filename = 'sysctl_kern_boottime_big_endian' + end + sysctl_output_file = File.join(SPECDIR, 'fixtures', 'uptime', sysctl_output_filename) # Aug 01 14:13:47 -0700 2010 Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat \"#{sysctl_output_file}\"") Time.stubs(:now).returns Time.parse("Aug 01 15:13:47 -0700 2010") # one hour later Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60 diff --git a/spec/unit/util/virtual_spec.rb b/spec/unit/util/virtual_spec.rb index aa2de5a..36e1bf1 100644 --- a/spec/unit/util/virtual_spec.rb +++ b/spec/unit/util/virtual_spec.rb @@ -9,6 +9,7 @@ describe Facter::Util::Virtual do end it "should detect openvz" do FileTest.stubs(:directory?).with("/proc/vz").returns(true) + FileTest.stubs(:exists?).with("/proc/vz/veinfo").returns(true) Facter::Util::Virtual.should be_openvz end diff --git a/spec/unit/virtual_spec.rb b/spec/unit/virtual_spec.rb index 7e50847..f69c898 100644 --- a/spec/unit/virtual_spec.rb +++ b/spec/unit/virtual_spec.rb @@ -73,6 +73,7 @@ describe "Virtual fact" do before do FileTest.expects(:exists?).with("/usr/lib/vmware/bin/vmware-vmx").returns false + Facter.fact(:operatingsystem).stubs(:value).returns(true) Facter.fact(:architecture).stubs(:value).returns(true) end @@ -94,6 +95,12 @@ describe "Virtual fact" do Facter.fact(:virtual).value.should == "vmware" end + it "should be virtualbox with VirtualBox vendor name from lspci" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns("00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter") + Facter.fact(:virtual).value.should == "virtualbox" + end + it "should be vmware with VMWare vendor name from dmidecode" do Facter.fact(:kernel).stubs(:value).returns("Linux") Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) @@ -108,21 +115,38 @@ describe "Virtual fact" do Facter.fact(:virtual).value.should == "parallels" end - it "should be vmware with VMWare vendor name from prtdiag" do + it "should be virtualbox with VirtualBox vendor name from dmidecode" do Facter.fact(:kernel).stubs(:value).returns("Linux") Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("BIOS Information\nVendor: innotek GmbH\nVersion: VirtualBox\n\nSystem Information\nManufacturer: innotek GmbH\nProduct Name: VirtualBox\nFamily: Virtual Machine") + Facter.fact(:virtual).value.should == "virtualbox" + end + + end + describe "on Solaris" do + it "should be vmware with VMWare vendor name from prtdiag" do + Facter.fact(:kernel).stubs(:value).returns("SunOS") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil) - Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: VMware, Inc. VMware Virtual Platform") + Facter::Util::Resolution.stubs(:exec).with('prtdiag', '/bin/sh').returns("System Configuration: VMware, Inc. VMware Virtual Platform") Facter.fact(:virtual).value.should == "vmware" end it "should be parallels with Parallels vendor name from prtdiag" do - Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:kernel).stubs(:value).returns("SunOS") Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil) - Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: Parallels Virtual Platform") + Facter::Util::Resolution.stubs(:exec).with('prtdiag', '/bin/sh').returns("System Configuration: Parallels Virtual Platform") Facter.fact(:virtual).value.should == "parallels" end + + it "should be virtualbox with VirtualBox vendor name from prtdiag" do + Facter.fact(:kernel).stubs(:value).returns("SunOS") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('prtdiag', '/bin/sh').returns("System Configuration: innotek GmbH VirtualBox") + Facter.fact(:virtual).value.should == "virtualbox" + end end end @@ -152,6 +176,12 @@ describe "is_virtual fact" do Facter.fact(:is_virtual).value.should == "true" end + it "should be true when running on virtualbox" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:virtual).stubs(:value).returns("virtualbox") + Facter.fact(:is_virtual).value.should == "true" + end + it "should be true when running on openvz" do Facter.fact(:kernel).stubs(:value).returns("Linux") Facter.fact(:virtual).stubs(:value).returns("openvzve") diff --git a/tasks/rake/mail_patches.rake b/tasks/rake/mail_patches.rake index be8dda1..1346faa 100644 --- a/tasks/rake/mail_patches.rake +++ b/tasks/rake/mail_patches.rake @@ -34,12 +34,14 @@ task :mail_patches do # If we've got more than one patch, add --compose if files.length > 1 compose = "--compose" + subject = %Q{--subject "#{type} #{name} against #{parent}"} else compose = "" + subject = "" end # Now send the mail. - sh "git send-email #{compose} --no-signed-off-by-cc --suppress-from --to puppet-dev@googlegroups.com 00*.patch" + sh "git send-email #{compose} #{subject} --no-signed-off-by-cc --suppress-from --to puppet-dev@googlegroups.com 00*.patch" # Finally, clean up the patches sh "rm 00*.patch" |