diff options
| author | Max Martin <max@puppetlabs.com> | 2011-04-13 17:30:44 -0700 |
|---|---|---|
| committer | Max Martin <max@puppetlabs.com> | 2011-04-13 17:30:44 -0700 |
| commit | 3dde838ac992571e13262ea29ba3a0eb8152e753 (patch) | |
| tree | 90520cf62bfa2f1bb9c992bbfe1bc47ae10471f2 | |
| parent | fe45c2417af580597cd39adec96a30a05a7cd66a (diff) | |
| parent | 3ab44c7ce01ab86a995deb66228f5be95239c92a (diff) | |
| download | puppet-3dde838ac992571e13262ea29ba3a0eb8152e753.tar.gz puppet-3dde838ac992571e13262ea29ba3a0eb8152e753.tar.xz puppet-3dde838ac992571e13262ea29ba3a0eb8152e753.zip | |
Merge branch 'next'
* next: (204 commits)
Revert "(#6928) Removed --ignoreimport"
Updated CHANGELOG for 2.6.8rc1
(#6928) Removed --ignoreimport
(#6928) Remove --parseonly
(#6928) Add a Parser face with Validate action
(#6830) Fix sha1 to digest/sha1 require issue for Ruby 1.9
(#6830) Fix UTF-8 encoding issue for Ruby 1.9
(#6830) Fix string method sub call on a symbol for Ruby 1.9
(#2331) Remove darwinports pkg provider, replace with rewritten macports provider
(#7059) handle inherited action binding scope
maint: ensure we handle '-foo=' options correctly in faces.
(#2150) Fix File const lookup when configuring routes
Fixed #7082 - Added system support for groups
maint: install erb templates under lib/
maint: clean up the spec test headers in bulk.
(#7056) Use 'face' rather than 'faces' in the production code.
maint: eliminate deprecated since 2008 code from Puppet.
(#6117) Add POST support to indirector requests
(#6962) Move option handling into #parse_options, not #preinit.
maint: whitespace cleanup for puppet/util/command_line.
...
632 files changed, 7639 insertions, 4534 deletions
@@ -1,3 +1,49 @@ +2.6.8rc1 +==== +8b7444d (#2331) Remove darwinports pkg provider, replace with rewritten macports provider +65c4e14 Fixed #7082 - Added system support for groups +b7f4ff7 (#7018) Give more context on the service type's assumptions. Wording tweaks. +bb19dea (#7018) explain internals better in service provider documentation +23c9663 maint: Fix sqlite3 require to really be optional +4b73d41 maint: Fix sporadic sqlite error +54b9f5d (#6818) Stop from getting Rails 3 named_scope deprecation warning +e493f8a (#6856) Copy dangling symlinks with 'links => manage' File resource. +1e4968e (maint) Indentation fixes +99d78f2 (#6490) Add plugin initialization callback system to core +5d1cb02 Fix #4339 - Locally save the last report to $lastrunreport +306aa30 Fix #4339 - Save a last run report summary to $statedir/last_run_summary.yaml +9bb3018 Fixed #3127 - removed legacy debug code +d2bacd3 Fixed #3127 - Fixed gem selection regex +1b66c28 (#5437) Invalidate cached TypeCollection when there was an error parsing +0675c9a (#6937) Adjust formatting of recurse's desc +2cdadf9 (#6937) Document the recurse parameter of File type. +647a640 (#6893) Document the cron type in the case of specials. +87ca313 (#5670) Don't trigger refresh from a failed resource +f5aabf5 (#5908) Add support for new update-rc.d disable API +37f9ca0 (#6862) Add a default subject for the mail_patches rake task +9a4de12 Fixed #6256 - Creation of rrd directory. +7c60db5 (#5477) Allow watch_file to watch non-existent files, especially site.pp +7761acb (#5221) Add test for fix to fileset with trailing separator +357514c (#5221) Fix fileset path absoluteness checking with trailing slash +f8941b8 (#4769) Fix negative timeout support for newer rubies +a29c7fd Fixed #6562 - Minor kick documentation fix +df20513 (#6658) Propagate ENC connection errors to the agent +08115c0 (#4884) Remove typo from spec test +f2c771b (#4884) Modify tests to pass on non-OS X systems +ec1aa19 (#4884) Revise new exec tests, add a few more +196294a (4576) - if ENC declares invalid class, it is logged at warning. +0d2d6f3 (#4884) Add an shell provider for execs +d2e911a (#4884) Fix Test::Unit exec tests +fa0cfc6 (#4884) Break the exec type out to have a posix provider +c86a980 (#4884) Add consistent path validation and behavior +77fbf7f (#4884) Add expand_path to requiring the spec_helper +7ec9057 (#4884) Autorequire shared behaviors and method to silence warnings +acc99ba (#4884) Fix whitespace +6a4d291 (#4884) Get rid of open3 require since it wasn't being used +3e7ebbb Fixed #6554 - Missing $haveftool if/else conditional in install.rb breaking Ruby 1.9 +fddc165 (#5814) Improved cron type specs +f2dfee6 (#5814) cron_spec shouldn't depend on cron provider + 2.6.7 ===== 17f673d Updated CHANGELOG for 2.6.7rc1 diff --git a/CHANGELOG.old b/CHANGELOG.old deleted file mode 100644 index bb0be94ba..000000000 --- a/CHANGELOG.old +++ /dev/null @@ -1,1705 +0,0 @@ -This is the legacy CHANGELOG. Please see the new ChangeLog file and the ReleaseNotes page at: - -http://reductivelabs.com/trac/puppet/wiki/ReleaseNotes - -0.25.0 - Fixed #2280 - Detailed exit codes fix - - Fixed #198 - Puppet man pages added - - Moved puppetd, puppetmasterd, puppetrun, puppetca from bin to sbin - - Fixed #2071 - Updated LDAP schema - - Fixed #1849 - Ruby 1.9 portability: `when' doesn't like colons, replace with semicolons - - Fixed #1910 - Updated logcheck regex - - Fixed #1879 - Added to tidy documentation - - Fixed #1881 - Added md5lite explanation - - Fixed #1877 - Tidy type reference update for use of 0 - - Fix autotest on win32 - - Doc strings update for REST - - Fixed #1840 - Bug fixes and improvements for Emacs puppet-mode.el - -0.24.8 - Fixed #2077 - ralsh user broken on OSX - - Fixed #2004 - ssh_authorized_key fails if no target is defined - - Fixed #1629 - incorrect permissions on ssh_authorized_keys created files - - Fixed #2000 - No default specified for checksum - - Fixed #2026 - Red Hat ignoring stop method - - Added ext/dbfix.sql script - fixes common errors in stored configuration databases - - Fixed #1963 - Failing to read /proc/mounts for selinux kills file downloads - - Fixed #2025 - gentoo service provider handle only default init level - - Fixed #1910 - updated logcheck - - Fixed #1871 - Sensitive information leaked in log reports - - Fixed #1956 - Cleaned up variable names to be more sane, clarified error messages - and fixed incorrect use of 'value' variable rather than 'member'. - - Fixed #1831 - Added sprintf function - - Fixed #1830 - Added regsubst function - - Updated up2date and service confines to add support for Oracle EL and VM - - Fixing #1948 and #1953 - augeas ins bug: wrong number of arguments (1 for 3) - - Fixing #944 - changing error message from warning to info - connection recycled - - Fixed #961 - puppetd creating too many/not closing TCP connections - - Fixed #1959 - Added column protection for environment schema migration - - Fixing #1869 - autoloaded files should never leak exceptions - - Fixing #1543 - Nagios parse errors no longer kill Puppet - - Fixed #1420 - nagios_serviceescalation not allowing host_name more than one type - - Fixed #1884 - Exported resources are marked as unexported when collected on the exporting host - - Fixed #1922 - Functions squash all arguments into a single hash - - Fixed #1538 - Yumrepo sets permissions wrongly on files in /etc/yum.repos.d - - Fixed #1936 - Added /* */ support to the vim file - - Fixed #1541 - nagios objects write files to clientbucket on every change - - Fixed #1542 - cannot purge nagios objects - - Fixing #1912 - gid still works with no 'should' value fixing ralsh issues - - Fixing the Rakefile to use 'git format-patch' - - Added README.rst file - - Enhancements to Stored Configuration performance - - Added Reductive Labs build library to tasks directory - - Fixed #1852 - Correct behaviour when no SELinux bindings - - Updated Red Hat spec file 0.24.7 - - Fixed #1920 - Shadow password corruption - -0.24.7 - Fixed #1804 - Added VDev and MultiVDev properties to the ZPool type - - Fixed #1496 - nagios_servicedependency needs a unique host_name? - - Fixed #1420 - nagios_serviceescalation not allowing host_name more than one type - - Bug #1803 Zfs should auto require the ancestor file systems - - Refactor #1802 Use 'zfs get -H -o value' instead of parsing output for value - - Fixing #1800 - tidy now correctly ignores missing files and directories - - Fixing #1794 - returning sync when it is already initialized - - Fixing #1750 again - All of the properties and now :ensure check replace? - - Deprecate the NetInfo nameservice provider. Use directoryservice instead - - Add macauthorization type - - Fixing #1703 - using a mutex around the sending of the tagmails - - Fix #1788 - allow rspec rake to run only some tests - - Fixing the AST constant warnings, using a variable instead of a constant - - Feature #1696 Add support for branded zones - - Feature #1783 - Add ZFS support - - type/mcx.rb Feature #1026 - MCX Type - - Fixing #1749 - Splay now hopefully behaves "better" for small values - - Fix #1741 - Add inline_template function - - Slight denormalisation to store a host's environment as a first class - - Added Rake :ci namespace and CI tasks - - Refactoring the thread-safety in Puppet::Util - - Removing the included testing gems; you must now install them yourself - - Refactoring of SELinux functions to use native Ruby SELinux interface - - Removing all mention of EPM, RPM, or Sun packages. - - Fixed #1496 - nagios_servicedependency needs a unique host_name? - - Fixed #1420 - nagios_serviceescalation not allowing host_name more than one type - - Fixed #1695 - Solaris 10 zone provider doesn't properly handle unknown zone attributes in newer releases - - Fixed #1776 - Trivial fix for gentoo service provider - - Fixed #1767 - Minor fix to emacs mode - - Fixed #1711 - fileserver test fails due to incorrect mocking - - Fixed #1751 - Mac OS X DirectoryService nameservice provider support for - plist output and password hash fil - - Fixed #1752 - Add an optional argument to Puppet::Util.execute to determine - whether stderr and stdout are combined in the output - - Added versionable feature to the RPM provider - - Fixed #1668 - puppetca can't clean unsigned certs - - Moved RRD feature from util/metric.rb to feature/base.rb - - Fixed #1735 and #1747 - Fixes to confine system - - Fixed #1681 - Add filesystem type check to test for per-file SELinux context support - - Fixed #1746 - Sync SELinux file attributes after file contents created/modified - - Replaced SELInux calls to binaries with Ruby SELinux bindings - - Fixed #1748 - Include spec directory in packages - - Fixes #1672 - unsafe crontab handling in Solaris - - Fixed #1718 - Added preseed to apt uninstall and purge - - Fixed #1739 - Added uninstall functionality to yum provider - - Fixed #1710 - Spurious output in test run - - Fixed #1667 - Documentation should specify natural language regexs, not Regexp objects - - Fixed #1692 - k5login fails to set mode when file is created - - Fixed #1660 - Added specific recurse values for tidy - - Fixed #1698 - All logs should now show up in the reports - - Fixed #1661 - Type reference: tidy should specify manditory parameters - - Fixed #1104 - Classes and nodes should set $name variables - - Updated Red Hat spec file for 0.24.6 - - Removed conf/debian directory - Debian packaging information - now maintained downstream - - Added augeas type - - Added support for @doc type and manifest documentation support - see: - http://reductivelabs.com/trac/puppet/wiki/PuppetManifestDocumentation - - Added multiline comment support - -0.24.6 - Adding support to the user type for: profiles, auths, project, - key/value pairs (extension to Solaris RBAC support added in - 0.24.6) - - Fixed #1662 - Configuration Reference still references 'section' - - Fixed #1460 - enhance redhat puppetmaster init.d script to easy start puppetmaster as a mongrel cluster - - Fixed #1663 - Regression relating to facter fact naming from 0.24.5 - - Fixed #1655 - Provider::Confine::Variable tests are broken - - Fixed #1646 - service puppet status does not work as non-root - on redhat system - - Fixed #1649 - Updated OSX package cleanup - - Fixed #1647 - puppetdoc -r providers now working again - - Fixed #1639 - uninitialized constant Puppet::Type::User::ProviderUseradd - - Fixed #1637 - With an inexistant (global) templatedir, modules - can't access their templates - - Fixed #1202 - Collection attribute matching doesn't parse arrays - - Fixed #1473 - Puppetd stops with error after puppetmasterd - is unavailable - - Fixed #1354 - yum provider problems with RHEL 3 - - Fixed #1633 - Added support for --detailed-exits to bin/puppet - - Fixed #381 - Allow Allow multiple overrides in one statement - - Fixing #947 - pluginsync no longer fails poorly when no plugins exist - - Fixed #981 - Removed 'Adding aliases' info message - - Fixing #1089 - Log messages are now tagged with the log level, - making it easier to match messages in the 'tagmail' report. - - Fixing #1098 - Multiline strings now correctly increment the line count - - Fixing #1614 - Environments no longer have to be listed out - - Fixed #1628 - Changed node search to use certname rather than Facter - hostname - - Fixed #1613 - The client environment will be substituted when looking - up settings. - - Updated puppet binary documentation - - Feature #1624 - Added RBAC roles to solaris user provider - - Fixed #1586 - Specifying "fully qualified" package names in Gentoo - - Fixed #1620 - Add 'sles' to Puppet confines when 'suse' is used - - Fixed #1585 - Allow complex 'if' and variable expressions - - Fixed #1564 - Saving File#checksum to state.yaml broken - - Fixed #1603 - Added support for running Puppet inside a Rack application - (mod_rails) with Passenger and Apache - - Fixed #1596 - Deploying file resources with ++ generates error - - Modified the group and zone resource types to no longer call - 'currentpropvalues' as a means of setting all values to absent. - There should be no behaviour change from this change. - - Modified the behaviour of resource-level 'retrieve' -- it only - calls 'retrieve' on each property if the resource exists. - - Fixed #1622 - Users and their groups should again add in one transaction - - Fixed #791 - You should now be able to create and find a user/group in one transaction. - - Fixed #1610 - Raise "Filebucketed" messages to Notice priority - - FIxed #1530 - ssh_authorized_keys provider does not crash anymore on SSH type 1 keys - - Added a number of confines to package providers - - Fixed #1609 - Added confines for the Gentoo, FreeBSD and - SMF (Solaris) service providers - - Fixed #1608 - Added ubuntu to defaultfor for apt provider - - Fixed #1607 - Added ubuntu to defaultfor for Debian service - provider - - Fixed #1045 - Multiple metaparams all get added to resources. - - Fixed #1472 -- defined, exported resources in the current compile - now get expanded correctly. - - Fixed #1595 - Internally, Property#retrieve is no longer called - when no 'should' value is available for a resource. - - Fixed #1588 - Fixed puppetca --clean --all - - Fixed #1584 - Added support for appended variables - - Fixed #1554 - Added support for multiple template directories - - Fixed #1500 - puppetrun not working - - Fixed #1579 and #1580 - errors in the Puppet RPM spec file - - Fixed #1572 -- file purging now fails if remote sources do not exist. - - Fixed #1521 -- ldap user and password are now used with the default connection. - - Fixed issues with file descriptors leaking into subprocesses - - Fixed #1568 - createpackage.sh - - Fixed #1571 - Puppet::Util::binary returns incorrect results - - Fixed #1553 - Puppet and Facter cannot both install the plist module into two different locations - - Adjusted hpuxuseradd user provider to confine to HP-UX and fixed HP-UX user provider path regression - - Fixed debug messages in package type - thanks to Todd Zullinger for this fix - - Fixed #1566 - changed password property of the user type - - Fixed debug messages in package type - - Updated Red Hat spec file - - Fixes #1455 - Adds HP-UX support for user type - - Fixes #1551 puppetmaster.freshness xmlrpc call returns incorrect type - - Fixes #1554 - Fix exception for undefined hostname - - Fixed #1533 - changed permissions for man directory - - Added daemontools and runit providers for service type - - Added simple rake task for running unit tests - - Added spec Rake task - - Fixed #1526 - Fixed leak in template - - Fixed #1506 - Removed storeconfig duplicate indexes - - Fixed #1457 - case insensitive match for error - - Fixed #1488 - Moved individual functions out of functions.rb into - lib/puppet/parser/functions directory. New functions should be create in this directory. - - Fixed #1508 - Added HP-UX package provider - - Fixed #1502 - Fixed poor stored configuration performance - - Fixed #1510 - Storeconfiguration fixed for Rails 2.1 - - Add the -P/--ping option to puppetrun, fixes #1501 - - Fixed #1394 - Added stored configuration clearing script to /ext - - Fixed #1442 - replaced use of Facter for report titling with certname - - Fixed $1456 - add proxy configuration capability to yum repo - - Fixed #1457 - removed confine warning - - A working script to create an OS X pkg out of the Puppet repository - - Fixed #1441 - Updated console colours - - Expose all puppet variables as instance member variables of the template wrapper. - This helps resolve redmine #1427, by providing a safe mechanism to access variables. - - * Implement Puppet::Parser::Scope#to_hash, which returns a hash containing all the - variable bindings in the current and, optionally, parent scope. - * Use that to set instance member variables into Puppet::Parser::Templatewrapper - * Report the time taken for variable binding at debug level, to help identify any - performance regression that is encountered in the real world. - * Rename the @scope and @file members of the template wrapper, to avoid clashing - with a scope variable exposed within puppet. - - Ensure that we consistently use either string #{} interpolation or String.% - interpolation, not both, to avoid issues where a #{} interpolated value - contains a % character. - - Feature #1476: Allow specification of --bindir --sbindir --sitelibdir --mandir --destdir - in installation - - Added feature #1241 : Improve performance of group lookups - - Fixed bug #1448: Puppet CA incorrectly writes out all certs to inventory .txt on each - certificate signing - - Fixing puppetlast to make it work with 0.24.5 / 0.25. Made puppetlast work on 0.24.5 - by using the YAML indirector - -0.24.5 - You can now select the encoding format when transferring the catalog, - with 'yaml' still being the default but 'marshal' being an option. - This is because testing has shown drastic performance differences - between the two, with up to 70% of compile time being spent - in YAML code. Use the 'catalog_format' setting to choose your format, - and the setting must be set on the client. - - Fixed #1431 - Provider confines must now specify similar tests in one call. - I.e., you can't do confine :operatingsystem => %w{a b} and then - confine :operatingsystem => %w{b c}; you'd need to do them in one command. - This now-obsolete behaviour does not seem to be used anywhere. - The fix for #1431 is actually just removing the tests that exposed - this change; the change happened when I refactored how confines work. - - Removed faulty interface type - - Updated /spec/unit/rails.rb test - - Fix #1426 - services on redhat are restarted again and status is - called from the Red Hat provider - - Fixed #1414 - Return code from waitpid now right shifted 8 bits - - Fixed #174 - a native type type for managing ssh authorized_keys - files is available. - - Further moves from the examples directory and ext directory - - Fixed #1397 One line fix, fail instead of log - - Moved debian to conf and updated examples directory - - Fixed #1368 - updated Red Hat init scripts - - Added message referencing ReductiveLabs build library - - Fixed #1396 - Added sha1 function from DavidS to core - - Fixed #1399 - the ldap user provider now knows it can manage - passwords. - - Fixed #1272 - if you provide a group name as the gid to an ldap - user, the name will be converted to a gid. Note that this only - looks up ldap groups, at this point; if you want to set an ldap - user's primary group to a local group, you have to specify the GID. - - Fixed #1226 - gems can now specify source repositories. - - Fixed #1232 - the rundir no longer specifies a user/group, - and there are now client- and server-specific yaml directories. - - Fixed 1240 - puppet will function more like puppetd if graphing - or reporting are enabled. - - Fixed #1231 - Exceptions during initialization should now be clearer. - - Fixed #1006 - puppetrun --class works again. I added the class - membership testing to the Ldap node terminus, and added tests, - so it shouldn't break again. - - Fixed #1114 - Facts in plugin directories should now be autoloaded, - as long as you're using Facter 1.5. - - Removed support for the 'node_name' setting in LDAP and external node lookups. - Fixed #1195 - Updated Gentoo init scripts - - Fixed #1367 - Updated Rakefile for new daily builds - - Fixed #1370 - removed test/util/loadedfile.rb tests - - Fixed #1221 - aliases to titles now work for resources. - - Fixed #1012 - templates in the templatedir are preferred to module templates. - - Fixed #707 - special '@reboot'-style cron jobs work again. - - Fixed #1360 - allowdupe works on groups again. - - Fixed #1369 - the init service provider now supports HP-UX. - - Removed support for the 'node_name' setting in LDAP and external node - lookups. - - Also removed support for 'default' nodes in external nodes. - LDAP nodes now use the certificate name, the short name, and 'default', - but external nodes just use the certificate name and any custom terminus - types will use just the certificate name. - - Fixing #1168 (for 0.24.x) -- automatically downcasing the fqdn. - Also requiring that passed in certnames be downcased; the setting - system isn't currently flexible enough to automatically downcase - it for the user. - - Adding a ResourceTemplate class for using templates directly - within resources (i.e., client-side templates). This would really - only be used for composite resources that pass the results of the - template on to generated resources. - - Exporting or collecting resources no longer raises an exception - when no storeconfigs is enabled, it just produces a warning. - - Always using the cert name to store yaml files, which fixes #1178. - The Master handler previously provided the support for the :node_name - setting, and that functionality has now been moved into the Node - class. At the same time, the names to search through have been - changed somewhat: Previously, the certificate name and the - hostname were both used for searching, but now, the cert name - is always searched first (unless node_name == facter), but only - the Facter hostname, domain, and fqdn are used otherwise. We no - longer split the cert name, only the hostname/domain/fqdn. - - Fixing transaction support for prefetching generated resources. - - Adding support for settings within the existing Facter provider confines. - - Moving all confine code out of the Provider class, and fixing #1197. - Created a Confiner module for the Provider class methods, enhanced - the interface between it and the Confine class to make sure binary - paths are searched for fresh each time. - - Modified the 'factpath' setting to automatically configure - Facter to load facts there if a new enough version of - Facter is used. - - Crontab provider: fix a parse error when a line begins with a space - character (fixes #1216) - - Instead of deleting the init scripts (with --del) we should simply - disable it with chkconfig service off, and respectfully do the same - for enable => true; - - Added ldap providers for users and groups. - - Added support for the --all option to puppetca --clean. If - puppetca --clean --all is issued then all client certificates - are removed. - - Resources now return the 'should' value for properties from - the [] accessor method (they previously threw an exception when - this method was used with properties). This shouldn't have any - affect functionally; it just makes the method equivalent to 'should' - for properties, but it works for all attribute types now. - - Modified the 'master' handler to use the Catalog class to - compile node configurations, rather than using the Configuration - handler, which was never used directly. I removed the Configuration - handler as a result. - - Modified the 'master' handler (responsible for sending configurations - to clients) to always return Time.now as its compile date, so - configurations will always get recompiled. - - Fixed #1184 -- definitions now autoload correctly all of the time. - - Removed the code from the client that tries to avoid recompiling - the catalog. The client will now always recompile, assuming it - can reach the server. It will still use the cached config if - there's a failure. - - Fixing #1173 -- classes and definitions can now have the same - name as a directory with no failures. - - Saving new facts now expires any cached node information. - - Switching how caching is handled, so that objects now all - have an expiration date associated with them. This makes it - much easier to know whether a given cached object should be used - or if it should be regenerated. - - Changing the default environment to production. - -0.24.4 - Pass source to pkg_add via the PKG_PATH environment variable if - it ends in a '/' indicating it is a directory. Allows pkg_add - to resolve dependancies, and make it possible to specify packages - without version numbers. - - Fixing #571 -- provider suitability is now checked at resource - evaluation time, rather than resource instantiation time. This - means that you don't catch your "errors" as early, but it also - means you should be able to realistically configure a whole host - in one run. - - Moved the configuration of the Node cache to the puppetmasterd - executable, since it otherwise causes caches to be used in all - cases, which we don't want (e.g., bin/puppet was using them). - - Ported #198 man page creation functionality to 0.24.x branch and - added man pages and man page creation logic to install.rb. The - man pages are stored in man/man8 and will install to config::CONFIG - mandir/man8. - - Fixing #1138 -- the yamldir is automatically created by the - server now that it's in the :puppetmasterd section rather than - a separate :yaml section. - - Disabling http keep-alive as a means of preventing #1010. - There is now a constant in Puppet::Network::HttpPool that will - disable or enable this feature, but note that we determined - that it can cause corruption, especially in file serving (but - it's client-side corruption). - - Applying patch by Ryan McBride to fix OpenBSD package - matching. The actual problem was caused by the fix to #1001. - - Found all instances of methods where split() is used without - any local variables and added a local variable -- see - http://snurl.com/21zf8. My own testing showed that this - caused memory growth to level off at a reasonable level. - Note that the link above says the problem is only with class - methods, but my own testing showed that it's any method that - meets these criteria. This is not a functional change, but - should hopefully be the last nail in the coffin of #1131. - - Found an array that leaked pretty quickly between reparsing - files, thanks to work by Adam Jacob and Arjuna Christenson - (the finding, not the leak). I'm going to act like this - fixes #1131, at least for now, but I doubt it does, - since that shows general memory growth over time, whereas - the leak here should go away as soon as files are reparsed - (because the parser is holding the reference to the leaking - array). - - Fixed #1147: Cached nodes are correctly considered out of - date if the node facts have been updated (thus causing - node facts to again be available in manifests, for those - cases where they were not). - - Fixed #1137: The certificate name is correctly being added - to the facts hash. - - Fixed #1136: Verbose and Debug no longer clobber each other. - - Hopefully *finally* fixed the "already being managed" problem - (#1036). The problem only cropped up if there was a failure - when trying to manage the system -- this would cause the - setting-based resources not to get cleaned up. - -0.24.3 - Modified the ldap node terminus to also use the facts version - as the version for a node, which should similarly encourage the - use of the yaml cache. (Related to #1130) - - Caching node information in yaml (I figured caching in memory will - cause ever-larger memory growth), and changing the external node - terminus to use the version of the facts as their version. This - will usually result in the cached node information being used, - instead of always hitting the external node app during file - serving. Note that if the facts aren't changed by the client, - then this will result in the cached node being used, but at this - point, the client always updates its facts. (#1130) - - Fixing #1132 -- host names can now have dashes anywhere. - (Patch by freiheit.) - - Fixing #1118 -- downloading plugins and facts now ignores noop. - Note that this changes the behaviour a bit -- the resource's - noop setting always beats the global setting (previously, - whichever was true would win). - - The change in checksums from 'timestamp' to 'mtime' no longer - result in updates on every run (#1116). - - Aliases again work in relationships (#1094). - - The CA serial file will no longer ever be owned by - root (#1041). - - Fixing the rest of #1113: External node commands can specify - an environment and Puppet will now use it. - - Partially fixing #1113: LDAP nodes now support environments, - and the schema has been updated accordingly. - - Always duplicating resource defaults in the parser, so that - stacked metaparameter values do not result in all resources - that receive a given default also getting those stacked - values. - -0.24.2 - Fixing #1062 by moving the yamldir setting to its own yaml - section. This should keep the yamldir from being created - on clients. - - Fixed #1047 -- Puppet's parser no longer changes the order - in which statements are evaluated, which means that case - statements can now set variables that are used by other - variables. - - Fixed #1063 -- the master correctly logs syntax errors when - reparsing during a single run. - - Removed the loglevels from the valid values for `logoutput` - in the Exec resource type -- the log levels are specified - using the `loglevel` parameter, not `logoutput`. This never - worked, or at least hasn`t for ages, and now the docs are - just correct. - - Somewhat refactored fileserving so that it no longer caches - any objects, nor does it use Puppet's RAL resources. In the - process, I fixed #894 (you can now copy links) and refactored - other classes as necessary. Mostly it was fixing tests. - - Hopefully partially fixed #1010 -- clients should now fail - to install files whose checksums do not match the checksum - from the server. - - Fixed #1018 -- resources now have their namevars added as - aliases in the resource catalog, just like they were added - in the resource classes. - - Fixed #1037 -- remote unreadable files no longer have the - permission denied exceptions caught, thus forbidding them - from being replaced with 'nil'. - - The environment is now available as a variable in the manifests. - - Fixed #1043 -- autoloading now searches the plugins directory - in each module, in addition to the lib directory. The 'lib' - directory is also deprecated, but supported for now to give - people a chance to convert. - - Fixed #1003 -- Applying DavidS's patch to fix searching for - tags in sql. - - Fixed #992 -- Puppet is now compatible with gems 1.0.1. - - Fixed #968 again, this time with tests -- parseonly works, - including not compiling the configurations, and also storeconfigs - is no longer required during parse-testing. - - Fixed #1021 -- the problem was that my method of determining - the in-degree sometimes resulted in a lower number than the - number of in-edges. - - Fixed #997 -- virtual defined types are no longer evaluated. - NOTE: This introduces a behaviour change, in that you previously - could realize a resource within a virtual defined resource, and now - you must realize the entire defined resource, rather than just - the contained resource. - - Fixed #1030 - class and definition evaluation has been significantly - refactored, fixing this problem and making the whole interplay - between the classes, definitions, and nodes, and the Compile class much - cleaner. - - Exec resources must now have unique names, although the commands can still - be duplicated. This is easily accomplished by just specifying a unique - name with whatever (unique or otherwise) command you need. - - Fixed #989 -- missing CRL files are correctly ignored, and the - value should be set to 'false' to explicitly not look for these - files. - - Fixed #1017 -- environment-specific modulepath is no longer ignored. - - Fixing #794 -- consolidating the gentoo configuration files. - - Fixing #976 -- both the full name of qualified classes and - the class parts are now added as tags. I've also - created a Tagging module that we should push throughout - the rest of the system that uses tags. - - Fixing #995 -- puppetd no longer dies at startup if the server - is not running. - - Fixing #977 -- the rundir is again set to 1777. - - Fixed #971 -- classes can once again be included multiple - times. - - Added builtin support for Nagios types using - Naginator to parse and generate the files. - -0.24.1 - Updated vim filetype detection. (#900 and #963) - - Default resources like schedules no longer conflict with - managed resources. (#965) - - Removing the ability to disable http keep-alive, since - it didn't really work anyway and it should no longer - be necessary. - - Refactored http keep-alive so it actually works again. - This should be sufficient enough that we no longer need the - ability to disable keep-alive. There is now a central - module responsible for managing HTTP instances, along with - all certificates in those instances. - - Fixed a backward compatibility issue when running 0.23.x - clients against 0.24.0 servers -- relationships would - consistently not work. (#967) - - Closing existing http connections when opening a new one, - and closing all connections after each run. (#961) - - Removed warning about deprecated explicit plugins mounts. - -0.24.0 (misspiggy) - Modifying the behaviour of the certdnsnames setting. It now defaults - to an empty string, and will only be used if it is set to something - else. If it is set, then the host's FQDN will also be added as - an alias. The default behaviour is now to add 'puppet' and - 'puppet.$domain' as DNS aliases when the name for the cert being - signed is equal to the signing machine's name, which will only - be the case for CA servers. This should result in servers always - having the alias set up and no one else, but you can still override - the aliases if you want. - - External node support now requires that you set the 'node_terminus' - setting to 'exec'. See the IndirectionReference on the wiki for more - information. - - http_enable_post_connection_check added as a configuration - option for puppetd. This defaults to true, which validates the server - SSL certificate against the requested host name in new versions of ruby. - See #896 for more information. - - Mounts no longer remount swap filesystems. - - Slightly modifying how services manage their list of paths - (and adding documention for it). Services now default - to the paths specified by the provider classes. - - Removed 'type' as a valid attribute for services, since it's been - deprecated since the creation of providers. - - Removed 'running' as a valid attribute for services, since it's - been deprecated since February 2006. - - Added modified patch by Matt Palmer which adds a 'plugins' mount, - fixing #891. See PluginsInModules on the wiki for information on - usage. - - Empty dbserver and dbpassword settings will now be ignored when - initializing Rails connections (patch by womble). - - Configuration settings can now be blank (patch by womble). - - Added calls to endpwent/endgrent when searching for user and group IDs, - which fixes #791. - - Obviated 'target' in interfaces, as all file paths were automatically - calculated anyway. The parameter is still there, but it's - not used and just generates a warning. - - Fixing some of the problems with interface management on Red Hat. - Puppet now uses the :netmask property and does not try to set - the bootproto (#762). - - You now must specify an environment and you are required to specify - the valid environments for your site. (#911) - - Certificates now always specify a subjectAltName, but it defaults - to '*', meaning that it doesn't require DNS names to match. You - can override that behaviour by specifying a value for - 'certdnsnames', which will then require that hostname as a match (#896). - - Relationship metaparams (:notify, :require, :subscribe, and - :before) now stack when they are collecting metaparam values - from their containers (#446). For instance, if a resource - inside a definition has a value set for 'require', and you call - the definition with 'require', the resource gets both requires, - where before it would only retain its initial value. - - Changed the behavior of --debug to include Mongrel client - debugging information. Mongrel output will be written to - the terminal only, not to the puppet debug log. This should - help anyone working with reverse HTTP SSL proxies. (#905) - - Fixed #800 -- invalid configurations are no longer - cached. This was done partially by adding a relationship - validation step once the entire configuration is created, - but it also required the previously-mentioned changes - to how the configuration retrieval process works. - - Removed some functionality from the Master client, - since the local functionality has been replaced - with the Indirector already, and rearranging how configuration - retrieval is done to fix ordering and caching bugs. - - The node scope is now above all other scopes besides - the 'main' scope, which should help make its variables - visible to other classes, assuming those classes were - not included in the node's parent. - - Replaced GRATR::Digraph with Puppet::SimpleGraph as - the base class for Puppet's graphing. Functionality - should be equivalent but with dramatically better - performance. - - The --use-nodes and --no-nodes options are now obsolete. - Puppet automatically detects when nodes are defined, and if - they are defined it will require that a node be found, - else it will not look for a node nor will it fail if it - fails to find one. - - Fixed #832. Added the '--no-daemonize' option to puppetd and - puppetmasterd. NOTE: The default behavior of 'verbose' and - 'debug' no longer cause puppetd and puppetmasterd to not - daemonize. - - Added k5login type. (#759) - - Fixed CA race condition. (#693) - - Added shortname support to config.rb and refactored addargs - -0.23.2 - Fixed the problem in cron jobs where environment settings - tended to multiple. (#749) - - Collection of resources now correctly only collects exported - resources again. This was broken in 0.23.0. (#731) - - 'gen_config' now generates a configuration with - all parameters under a heading that matches the - process name, rather than keeping section headings. - - Refactored how the parser and interpreter relate, - so parsing is now effectively an atomic process (thus - fixing #314 and #729). This makes the interpreter less - prone to error and less prone to show the error to the - clients. Note that this means that if a configuration - fails to parse, then the previous, parseable configuration - will be used instead, so the client will not know that - the configuration failed to parse. - - Added support for managing interfaces, thanks to work - by Paul Rose. - - Fixed #652, thanks to a patch by emerose; --fqdn again - works with puppetd. - - Added an extra check to the Mongrel support so that - Apache can be used with optional cert checking, instead - of mandatory, thus allowing Mongrel to function as the CA. - This is thanks to work done by Marcin Owsiany. - -0.23.1 (beaker) - You can now specify relationships to classes, which work - exactly like relationships to defined types: - require => Class[myclass] - This works with qualified classes, too. - - You can now do simple queries in a collection of - exported resources. You still cannot do multi-condition queries, - though. (#703) - - puppetca now exits with a non-zero code if it cannot - find any host certificates to clean. (Patch by Dean - Wilson.) - - Fully-qualified resources can now have defaults. (#589) - - Resource references can now be fully-qualified names, - meaning you can list definitions with a namespace as - dependencies. (#468) - - Files modified using a FileType instance, as ParsedFile - does, will now automatically get backed up to the filebucket - named "puppet". - - Added a 'maillist' type for managing mailing lists. - - Added a 'mailalias' type for managing mail aliases. - - Added patch by Valentin Vidic that adds the '+>' syntax to - resources, so parameter values can be added to. - - The configuration client now pulls libraries down to $libdir, - and all autoloading is done from there with full support - for any reloadable file, such as types and providers. (#621) - Note that this is not backward compatible -- if you're using - pluginsync right now, you'll need to disable it on your clients - until you can upgrade them. - - The Rails log level can now be set via (shockingly!) the - 'rails_loglevel' parameter (#710). Note that this isn't - exactly the feature asked for, but I could not find a - way to directly copy ActiveRecord's concept of an environment. - - External node sources can now return undefined classes (#687). - - Puppet clients now have http proxy support (#701). - - The parser now throws an error when a resource reference - is created for an unknown type. Also, resource references - look up defined types and translate their type accordingly. (#706) - - Hostnames can now be double quoted. - - Adding module autoloading (#596) -- you can now 'include' classes - from modules without ever needing to specifically load them. - - Class names and node names now conflict (#620). - -0.23.0 - Modified the fileserver to cache file information, so that - each file isn't being read on every connection. Also, - added londo's patch from #678 to avoid reading entire files - into memory. - - Fixed environment handling in the crontab provider (#669). - - Added patch by trombik in #572, supporting old-style - freebsd init scripts with '.sh' endings. - - Added fink package provider (#642), as provided by 'do'. - - Marked the dpkg package provider as versionable (#647). - - Applied patches by trombik to fix FreeBSD ports (#624 and #628). - - Fixed the CA server so that it refuses to send back a certificate - whose public key doesn't match the CSR. Instead, it tells the - user to run 'puppetca --clean'. - - Invalid certificates are no longer written to disk (#578). - - Added a package provider (appdmg) able to install .app packages - on .dmg files on OS X (#641). - - Applied the patch from #667 to hopefully kill the client hanging - problems (permanently, this time). - - Fixed functions so that they accept most other rvalues as valid values - (#548). - - COMPATIBILITY ALERT: - Significantly reworked external node support, in a way that's NOT - backward-compatible: - - Only ONE node source can be used -- you can use LDAP, code, or - an external node program, but not more than one. - - LDAP node support has two changes: First, the "ldapattrs" attribute is - now used for setting the attributes to retrieve from the server (in - addition to required attriutes), and second, all retrieved attributes - are set as variables in the top scope. This means you can set attributes - on your LDAP nodes and they will automatically appear as variables - in your configurations. - - External node support has been completely rewritten. These programs must - now generate a YAML dump of a hash, with "classes" and "parameters" keys. - The classes should be an array, and the parameters should be a hash. The - external node program has no support for parent nodes -- the script must - handle that on its own. - - Reworked the database schema used to store configurations with the - storeconfigs option. - - Replaced the obsolete RRD ruby library with the maintained - RubyRRDtool library (which requires rrdtool2) (#659). - - The Portage package provider now calls eix-update automatically - when eix's database is absent or out of sync (#666). - - Mounts now correctly handle existing fstabs with no pass or dump values - (#550). - - Mounts now default to 0 for pass and dump (#112). - - Added urpmi support (#592). - - Finishing up the type => provider interface work. Basically, package - providers now return lists of provider instances. In the proces, - I rewrote the interface between package types and providers, and also - enabled prefetching on all packages. This should significantly speed - up most package operations. - - Hopefully fixing the file descriptor/open port problems, with patches - from Valentin Vidic. - - Significantly reworked the type => provider interface with respect to - listing existing provider instances. The class method on both - class heirarchies has been renamed to 'instances', to start. Providers - are now expected to return provider instances, instead of creating - resources, and the resource's 'instances' method is expected to - find the matching resource, if any, and set the resource's - provider appropriately. This *significantly* reduces the reliance on - effectively global state (resource references in the resource classes). - This global state will go away soon. - - Along with this change, the 'prefetch' class method on providers now - accepts the list of resources for prefetching. This again reduces - reliance on global state, and makes the execution path much easier - to follow. - - Fixed #532 -- reparsing config files now longer throws an exception. - - Added some warnings and logs to the service type so - users will be encouraged to specify either "ensure" - or "enabled" and added debugging to indicate why - restarting is skipped when it is. - - Changed the location of the classes.txt to the state - directory. - - Added better error reporting on unmatched brackets. - - Moved puppetd and puppetmasterd to sbin in svn and fixed install.rb - to copy them into sbin on the local system appropriately. (#323) - - Added a splay option (#501). It's disabled when running under - --test in puppetd. The value is random but cached. It defaults - to the runinterval but can be tuned with --splaylimit - - Changing the notify type so that it always uses - the loglevel. - - Fixing #568 - nodes can inherit from quoted node names. - - Tags (and thus definitions and classes) can now be a single - character. (#566) - - Added an 'undef' keyword (#629), which will evaluate to "" - within strings but when used as a resource parameter value - will cause that parameter to be evaluated as undefined. - - Changed the topological sort algorithm (#507) so it will always - fail on cycles. - - Added a 'dynamicfacts' configuration option; any facts in that - comma-separated list will be ignored when comparing facts to - see if they have changed and thus whether a recompile is necessary. - - Renamed some poorly named internal variables: - @models in providers are now either @resource or - @resource_type (#605). - - @children is no longer used except by components (#606). - - @parent is now @resource within parameters (#607). - - The old variables are still set for backward compatibility. - - Significantly reworking configuration parsing. Executables all now - look for 'puppet.conf' (#206), although they will parse the old-style - configuration files if they are present, although they throw a deprecation - warning. Also, file parameters (owner, mode, group) are now set on the - same line as the parameter, in brackets. (#422) - - Added transaction summaries (available with the --summarize option), - useful for getting a quick idea of what happened in a transaction. - Currently only useful on the client or with the puppet interpreter. - - Changed the interal workings for retrieve and removed the :is attribute - from Property. The retrieve methods now return the current value of - the property for the system. - - Removed acts_as_taggable from the rails models. - -0.22.4 - Execs now autorequire the user they run as, as long as the user - is specified by name. (#430) - - Files on the local machine but not on the remote server during - a source copy are now purged if purge => true. (#594) - - Providers can now specify that some commands are optional (#585). - Also, the 'command' method returns nil on missing commands, - rather than throwing an error, so the presence of commands - be tested. - - The 'useradd' provider for Users can now manage passwords. - No other providers can, at this point. - - Parameters can now declare a dependency on specific - features, and parameters that require missing features - will not be instantiated. This is most useful for - properties. - - FileParsing classes can now use instance_eval to add - many methods at once to a record type. - - Modules no longer return directories in the list of found - manifests (#588). - - The crontab provider now defaults to root when there is no - USER set in the environment. - - Puppetd once again correctly responds to HUP. - - Added a syntax for referring to variables defined in - other classes (e.g., $puppet::server). - - STDIN, STDOUT, STDERR are now redirected to /dev/null in - service providers descending from base. - - Certificates are now valid starting one day before they are - created, to help handle small amounts of clock skew. - - Files are no longer considered out of sync if some properties - are out of sync but they have no properties that can create - the file. - -0.22.3 - Fixed backward compatibility for logs and metrics from older clients. - - Fixed the location of the authconfig parameters so there aren't - loading order issues. - - Enabling attribute validation on the providers that subclass - 'nameservice', so we can verify that an integer is passed to - UID and GID. - - Added a stand-alone filebucket client, named 'filebucket'. - - Fixed the new nested paths for filebuckets; the entire md5 sum was - not being stored. - - Fixing #553; -M is no longer added when home directories are being - managed on Red Hat. - -0.22.2 (grover) - Users can now manage their home directories, using the managehome - parameter, partially using patches provided by Tim Stoop and - Matt Palmer. (#432) - - Added 'ralsh' (formerly x2puppet) to the svn tree. When possible it - should be added to the packages. - - The 'notify' type now defaults to its message being the same as its name. - - Reopening $stdin to read from /dev/null during execution, in hopes that - init scripts will stop hanging. - - Changed the 'servername' fact set on the server to use the server's fqdn, - instead of the short-name. - - Changing the location of the configuration cache. It now defaults to being - in the state directory, rather than in the configuration directory. - - All parameter instances are stored in a single @parameters instance variable - hash within resource type instances. We used to use separate hashes for - each parameter type. - - Added the concept of provider features. Eventually these should be able - to express the full range of provider functionality, but for now they can - test a provider to see what methods it has set and determine what features it - provides as a result. These features are integrated into the doc generation - system so that you get feature documentation automatically. - - Switched apt/aptitide to using "apt-cache policy" instead of "apt-cache showpkg" - for determining the latest available version. (#487) - - FileBuckets now use a deeply nested structure for storing files, so - you do not end up with hundreds or thousands of files in the same - directory. (#447) - - Facts are now cached in the state file, and when they change the configuration - is always recompiled. (#519) - - Added 'ignoreimport' setting for use in commit hooks. This causes the - parser to ignore import statements so a single file can be parse-checked. (#544) - - Import statements can now specify multiple comma-separated arguments. - - Definitions now support both 'name' and 'title', just like any other - resource type. (#539) - - Added a generate() command, which sets values to the result of an external - command. (#541) - - Added a file() command to read in files with no interpolation. The first - found file has its content returned. - - puppetd now exits if no cert is present in onetime mode. (#533) - - The client configuration cache can be safely removed and the client - will correctly realize the client is not in sync. - - Resources can now be freely deleted, thus fixing many problems introduced - when deletion of required resources was forbidden when purging was introduced. - Only resources being purged will not be deleted. - - Facts and plugins now download even in noop mode (#540). - - Resources in noop mode now log when they would have responded to an event (#542). - - Refactored cron support entirely. Cron now uses providers, and there - is a single 'crontab' provider that handles user crontabs. While this - refactor does not include providers for /etc/crontab or cron.d, it should - now be straightforward to write those providers. - - Changed the parameter sorting so that the provider parameter comes - right after name, so the provider is available when the other parameters - and properties are being created. - - Redid some of the internals of the ParsedFile provider base class. - It now passes a FileRecord around instead of a hash. - - Fixing a bug related to link recursion that caused link directories - to always be considered out of sync. - - The bind address for puppetmasterd can now be specified with - --bindaddress. - - Added (probably experimental) mongrel support. At this point you're - still responsible for starting each individual process, and you have to - set up a proxy in front of it. - - Redesigned the 'network' tree to support multiple web servers, including - refactoring most of the structural code so it's much clearer and more - reusable now. - - Set up the CA client to default to ca_server and ca_port, so you can - easily run a separate CA. - - Supporting hosts with no domain name, thanks to a patch from - Dennis Jacobfeuerborn. - - Added an 'ignorecache' option to tell puppetd to force a recompile, thanks to - a patch by Chris McEniry. - - Made up2date the default for RHEL < 4 and yum the default for the rest. - - The yum provider now supports versions. - - Case statements correctly match when multiple values are provided, - thanks to a patch by David Schmitt. - - Functions can now be called with no arguments. - - String escapes parse correctly in all cases now, thanks to a patch by - cstorey. - - Subclasses again search parent classes for defaults. - - You can now purge apt and dpkg packages. - - When doing file recursion, 'ensure' only affects the top-level directory. - - States have been renamed to Properties. - -0.22.1 (kermit) -- Mostly a bugfix release - Compile times now persist between restarts of puppetd. - - Timeouts have been added to many parts of Puppet, reducing the likelihood - if it hanging forever on broken scripts or servers. - - All of the documentation and recipes have been moved to the wiki by Peter - Abrahamsen and Ben Kite has moved the FAQ to the wiki. - - Explicit relationships now override automatic relationships, allowing you - to manually specify deletion order when removing resources. - - Resources with dependencies can now be deleted as long as all of their - dependencies are also being deleted. - - Namespaces for both classes and definitions now work much more consistently. - You should now be able to specify a class or definition with a namespace - everywhere you would normally expect to be able to specify one without. - - Downcasing of facts can be selectively disabled. - - Cyclic dependency graphs are now checked for and forbidden. - - The netinfo mounts provider was commented out, because it really doesn't - work at all. Stupid NetInfo stores mount information with the device as - the key, which doesn't work with my current NetInfo code. - - Otherwise, lots and lots of bugfixes. Check the tickets associated with the - 'kermit' milestone. - -0.22.0 - Integrated the GRATR graph library into Puppet, for handling resource - relationships. - - Lots of bug-fixes (see bugs tickets associated with the 'minor' milestone). - - Added new 'resources' metatype, which currently only includes the ability - to purge unmanaged resources. - - Added better ability to generate new resource objects during transactions - (using 'generate' and 'eval_generate' methods). - - Rewrote all Rails support with a much better database design. Export/collect - now works, although the database is incompatible with previous versions. - - Removed downcasing of facts and made most of the language case-insensitive. - - Added support for printing the graphs built during transactions. - - Reworked how paths are built for logging. - - Switched all providers to directly executing commands instead of going through - a subshell, which removes the need to quote or escape arguments. - -0.20.1 - Mostly a bug-fix release, with the most important fix being the - multiple-definition error. - - Completely rewrote the ParsedFile system; each provider is now much - shorter and much more maintainable. However, fundamental problems - were found with the 'port' type, so it was disabled. Also, added - a NetInfo provider for 'host' and an experimental NetInfo provider - for 'mount'. - - Made the RRDGraph report *much* better and added reference - generation for reports and functions. - -0.20.0 - Significantly refactored the parser. Resource overrides now consistently - work anywhere in a class hierarchy. - - The language was also modified somewhat. The previous export/collect syntax - is now used for handling virtual objects, and export/collect (which is still - experimental) now uses double sigils (@@ and <<| |>>). - - Resource references (e.g., File["/etc/passwd"]) now have to be capitalized, - in fitting in with capitalizing type operations. - - As usual, lots of other smaller fixes, but most of the work was in the language. - -0.19.3 - Fixing a bug in server/master.rb that causes the hostname - not to be available in locally-executed manifests. - -0.19.2 - Fixing a few smaller bugs, notably in the reports system. - - Refreshed objects now generate an event, which can result in further - refreshes of other objects. - -0.19.1 - Fixing two critical bugs: User management works again and cron jobs are - no longer added to all user accounts. - -0.19.0 - Added provider support. - - Added support for %h, %H, and %d expansion in fileserver.conf. - - Added Certificate Revocation support. - - Made dynamic loading pervasive -- nearly every aspect of Puppet will now - automatically load new instances (e.g., types, providers, and reports). - - Added support for automatic distribution of facts and plugins (custom types). - -0.18.4 - Another bug-fix release. The most import bug fixed is that - cronjobs again work even with initially empty crontabs. - -0.18.3 - Mostly a bug-fix release; fixed small bugs in the functionality added in - 0.18.2. - -0.18.2 - Added templating support. - - Added reporting. - - Added gem and blastwave packaging support. - -0.18.1 - Added signal handlers for HUP, so both client and server deal correctly with it. - - Added signal handler for USR1, which triggers a run on the client. - - As usual, fixed many bugs. - - Significant fixes to puppetrun -- it should behave much more correctly now. - - Added "fail" function which throws a syntax error if it's encountered. - - Added plugin downloading from the central server to the client. It must be - enabled with --pluginsync. - - Added support for FreeBSD's special "@daily" cron schedules. - - Correctly handling spaces in file sources. - - Moved documentation into svn tree. - -0.18.0 - Added support for a "default" node. - - When multiple nodes are specified, they must now be comma-separated (this - introduces a language incompatibility). - - Failed dependencies cause dependent objects within the same transaction - not to run. - - Many updates to puppetrun - - Many bug fixes - - Function names are no longer reserved words. - - Links can now replace files. - -0.17.2 - Added "puppetrun" application and associated runner server and client classes. - - Fixed cron support so it better supports valid values and environment settings. - -0.17.1 - Fixing a bug requiring rails on all Debian boxes - - Fixing a couple of other small bugs - -0.17.0 - Adding ActiveRecord integration on the server - - Adding export/collect functionality - - Fixing many bugs - -0.16.5 - Fixing a critical bug in importing classes from other files - - Fixing nodename handling to actually allow dashes - -0.16.4 - Fixing a critical bug in puppetd when acquiring a certificate for the first - time - -0.16.3 - Some significant bug fixes - - Modified puppetd so that it can now function as an agent independent - of a puppetmasterd process, e.g., using the PuppetShow web application. - -0.16.2 - Modified some of the AST classes so that class names, definition names, and - node names are all set within the code being evaluated, so 'tagged(name)' returns - true while evaluating 'name', for instance. - - Added '--clean' argument to puppetca to remove all traces of a given - client. - -0.16.1 - Added 'tagged' and 'defined' functions. - - Moved all functions to a general framework that makes it very easy to add new - functions. - -0.16.0 - Added 'tag' keyword/function. - - Added FreeBSD Ports support - - Added 'pelement' server for sending or receiving Puppet objects, although - none of the executables use it yet. - -0.15.3 - Fixed many bugs in :exec, including adding support for arrays of checks - - Added autoloading for types and service variants (e.g., you can now - just create a new type in the appropriate location and use it in Puppet, - without modifying the core Puppet libs). - -0.15.2 - Added darwinport, Apple .pkg, and freebsd package types - Added 'mount type - Host facts are now set at the top scope (Bug #103) - Added -e (inline exection) flag to 'puppet' executable - Many small bug fixes - -0.15.1 - Fixed 'yum' installs so that they successfully upgrade packages. - Fixed puppetmasterd.conf file so group settings take. - -0.15.0 - Upped the minor release because the File server is incompatible with 0.14, - because it now handles links. - - The 'symlink' type is deprecated (but still present), in favor of using - files with the 'target' parameter. - - Unset variables no longer throw an error, they just return an empty string - - You can now specify tags to restrict which objects run during a given run. - - You can also specify to skip running against the cached copy when there's - a failure, which is useful for testing new configurations. - - RPMs and Sun packages can now install, as long as they specify a package - location, and they'll automatically upgrade if you point them to a new - file with an upgrade. - Multiple bug fixes. - - -0.14.1 - Fixed a couple of small logging bugs - Fixed a bug with handling group ownership of links - -0.14.0 - Added some ability to selectively manage symlinks when doing file management - Many bug fixes - Variables can now be used as the test values in case statements and selectors - Bumping a minor release number because 0.13.4 introduced a protocol - incompatibility and should have had a minor rev bump - -0.13.6 - Many, many small bug fixes - FreeBSD user/group support has been added - The configuration system has been rewritten so that daemons can now generate - and repair the files and directories they need. (Fixed bug #68.) - Fixed the element override issues; now only subclasses can override values. - -0.13.5 - Fixed packages so types can be specified - Added 'enable' state to services, although it does not work everywhere yet - -0.13.4 - A few important bug fixes, mostly in the parser. - -0.13.3 - Changed transactions to be one-stage instead of two - Changed all types to use self[:name] instead of self.name, to support - the symbolic naming implemented in 0.13.1 - -0.13.2 - Changed package[answerfile] to package[adminfile], and added package[responsefile] - Fixed a bunch of internal functions to behave more consistently and usefully - -0.13.1 - Fixed RPM spec files to create puppet user and group (lutter) - Fixed crontab reading and writing (luke) - Added symbolic naming in the language (luke) - -0.13.0 - Added support for configuration files. - Even more bug fixes, including the infamous 'frozen object' bug, which was a - problem with 'waitforcert'. - David Lutterkort got RPM into good shape. - -0.12.0 - Added Scheduling, and many bug fixes, of course. - -0.11.2 - Fixed bugs related to specifying arrays of requirements - Fixed a key bug in retrieving checksums - Fixed lots of usability bugs - Added 'fail' methods that automatically add file and line info when possible, - and converted many errors to use that method - -0.11.1 - Fixed bug with recursive copying with 'ignore' set. - Added OpenBSD package support. - -0.11.0 - Added 'ensure' state to many elements. - Modified puppetdoc to correctly handle indentation and such. - Significantly rewrote much of the builtin documentation to take advantage - of the new features in puppetdoc, including many examples. - -0.10.2 - Added SMF support - Added autorequire functionality, with specific support for exec and file - Exec elements autorequire any mentioned files, including the scripts, - along with their CWDs. - Files autorequire any parent directories. - Added 'alias' metaparam. - Fixed dependencies so they don't depend on file order. - -0.10.1 - Added Solaris package support and changed puppetmasterd to run as - a non-root user. - -0.10.0 - Significant refactoring of how types, states, and parameters work, including - breaking out parameters into a separate class. This refactoring did not - introduce much new functionality, but made extension of Puppet significantly - easier - - Also, fixed the bug with 'waitforcert' in puppetd. - -0.9.4 - Small fix to wrap the StatusServer class in the checks for required classes. - -0.9.3 - Fixed some significant bugs in cron job management. - -0.9.2 - Second Public Beta - -0.9.0 - First Public Beta diff --git a/COPYING b/COPYING deleted file mode 100644 index 3912109b5..000000000 --- a/COPYING +++ /dev/null @@ -1,340 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 51 Franklin St, 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 Library 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 St, 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 Library General -Public License instead of this License. @@ -1,17 +1,17 @@ -Puppet - Automating Configuration Management. Copyright (C) 2005 Puppet Labs LLC + Puppet - Automating Configuration Management. -Puppet Labs can be contacted at: info@puppetlabs.com + Copyright (C) 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 Version 2 as published by the Free Software -Foundation. + Puppet Labs can be contacted at: info@puppetlabs.com -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. + 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 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 + 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. diff --git a/README b/README deleted file mode 100644 index d6b7d66bc..000000000 --- a/README +++ /dev/null @@ -1,31 +0,0 @@ -Documentation (and detailed install instructions) can be found -online at http://docs.puppetlabs.com/. - -Additional documentation can also be found at the Puppet Wiki: - -http://projects.puppetlabs.com/projects/puppet/wiki/ - -Generally, you need the following things installed: - -* Ruby >= 1.8.1 (earlier releases might work but probably not) - -* The Ruby OpenSSL library. For some reason, this often isn't included - in the main ruby distributions. You can test for it by running - 'ruby -ropenssl -e "puts :yep"'. If that errors out, you're missing the - library. - - If your distribution doesn't come with the necessary library (e.g., on Debian - and Ubuntu you need to install libopenssl-ruby), then you'll probably have to - compile Ruby yourself, since it's part of the standard library and not - available separately. You could probably just compile and install that one - library, though. - -* The Ruby XMLRPC client and server libraries. For some reason, this often - isn't included in the main ruby distributions. You can test for it by - running 'ruby -rxmlrpc/client -e "puts :yep"'. If that errors out, you're missing - the library. - -* Facter => 1.5.1 - You can get this from < http://puppetlabs.com/projects/facter > - -$Id$ @@ -5,10 +5,8 @@ Puppet, an automated administrative engine for your Linux and Unix systems, perf administrative tasks (such as adding users, installing packages, and updating server configurations) based on a centralized specification. -Documentation (and detailed install instructions) can be found online at the -`Puppet Documentation`_ site. - -Additional documentation can also be found at the `Puppet Wiki`_. +Documentation (and detailed installation instructions) can be found online at the +[Puppet Docs site](http://docs.puppetlabs.com). Installation ------------ @@ -28,14 +26,15 @@ Generally, you need the following things installed: available separately. You could probably just compile and install that one library, though. -* The Ruby XMLRPC client and server libraries. For some reason, this often - isn't included in the main ruby distributions. You can test for it by - running 'ruby -rxmlrpc/client -e "puts :yep"'. If that errors out, you're missing - the library. +* Facter => 1.5.1 (available via your package manager or from the [Facter site](http://puppetlabs.com/projects/facter). + +License +------- + +See LICENSE file. + +Support +------- -* Facter => 1.5.1 - You can get this from your package management system or the `Facter site`_ +Please log tickets and issues at our [Projects site](http://projects.puppetlabs.com) -.. _Puppet Documentation: http://docs.puppetlabs.com -.. _Puppet Wiki: http://projects.puppetlabs.com/projects/puppet/wiki/ -.. _Facter site: http://puppetlabs.com/projects/facter diff --git a/README.queueing b/README.queueing deleted file mode 100644 index 83a8e19c0..000000000 --- a/README.queueing +++ /dev/null @@ -1,126 +0,0 @@ -*PUPPET QUEUEING - -Puppet Queueing is a feature which is designed to take some load -off of the PuppetMaster by transferring the task of updating the -database to a separate program which is named puppetqd (Puppet -Queue Daemon). - -Currently this is only supported for "Storeconfigs" which is -documented at: - -http://projects.puppetlabs.com/projects/1/wiki/Using_Stored_Configuration - -In the future this feature can be extended to any new puppet -data which involves storage in a database. - -*OPERATION - -In a nutshell: - - puppetmasterd -> stomp -> service -> stomp -> puppetqd -> database - -At the moment the only messaging protocol supported is "stomp". Although -others could be implemented, stomp is considered by many as the -default queueing mechanism for Ruby and Rails applications. It is -distributed as a Ruby gem and is easily installed. - -(The queueing code inside Puppet has been written so that when other -interfaces and protocols are implemented they will be easy to use by -changing settings in puppet.conf). - -The "service" in the diagram above is any queueing service that supports -the Stomp API. For details refer to: - - http://xircles.codehaus.org/projects/stomp - -Both puppetmasterd and puppetqd subscribe to the same queueing service -using the stomp interface. As puppetmasterd posts data to the queue, -puppetqd receives it and stores it. The details of how to connect to -the service and the name of the queue to use are set in puppet.conf: - - [main] - queue_type = stomp - queue_source = stomp://localhost:61613 - [puppetmasterd] - async_storeconfigs = true - -Note: since puppetmasterd needs to recover the data being stored at a -later time, both puppetmasterd and puppetqd need to work with the same -database as defined in the STORECONFIGS setup. - -*QUEUEING SERVICES - -As mentioned previously any queueing service that supports the Stomp -protocol can be used. Which one you use depends on your needs. We have -tested with two of the most popular services - StompServer and ActiveMQ. - -+ StompServer - - http://rubyforge.org/projects/stompserver/ - -StompServer is a lightweight queueing service written in Ruby which is -suitable for testing or low volume puppet usage. Works well when both -puppetmasterd and puppetd are running on the same machine that it's running -on but we encountered some problems when using it from multiple machines. - -Just install the stompserver gem and run 'stompserver'. - -+ Apache ActiveMQ - - http://activemq.apache.org - -Considered by many to be the most popular message service in use today, -ActiveMQ has hundreds of features for scaling, persistence and so on. - -Although installation is fairly simple, the configuration can seem quite -intimidating, but for our use a one line change to the standard configuration -is all that is required and is explained at: - - http://activemq.apache.org/stomp.html - -Other customization of the internal workings of ActiveMQ, if any, will depend -on your needs and deployment. A quick skimming of the ActiveMQ documentation -will give you enough info to decide. - -Others - -We have looked at but not tried some other queuing services which are -compatible with the Stomp API: - -+ POE Component Message Queue -+ JBoss Messaging (with 3rd party support for Stomp) - -*SCALING - -For StoreConfigs you basically need to have the catalog for a node stored -in the database before the next time the node connects and asks for a -new catalog. - -If the puppetd on your nodes is set to check every 30 minutes, -then it would seem that there is no problem. However if you have 3000 -nodes you have a LOT of catalogs to store and it is possible you will -not get a catalog saved in time. - -Running puppetmaster, your queueing service and puppetqd on the same -machine means that they are all competing for the same CPU cycles. Bumping -up the power of the server they are running on may be enough to handle -even fairly large deployments. - -However since most queueing services (even StompServer) are designed to -deliver messages from a "queue" to whoever asks for the next message you -can split things up between machines: - - puppetmaster1 --\ /-- puppetqd1 -\ - puppetmaster2 ----> ActiveMQ ---> puppetqd2 ---> database - puppetmaster3 --/ \-- puppetqd33 -/ - \- puppetqd4-/ - -This is, of course a totally contrived example, but it gets the point -across. As long as the data gets to the database, it doesn't matter -which machines or services it goes through. - -Although for StoreConfigs absolute reliability is not a requirement as -a new catalog will be sent the next time a node connects, some amount -of persistence should some process crash may be desirable. Both ActiveMQ -and MySQL (and other databases) have these kind of features built in -which can be activated as needed. diff --git a/README.strings b/README.strings new file mode 100644 index 000000000..28289ee10 --- /dev/null +++ b/README.strings @@ -0,0 +1,115 @@ +Puppet Strings +================= +A set of executables that provide complete CLI access to Puppet's +core data types. They also provide String classes for +each of the core data types, which are extensible via plugins. + +For instance, you can create a new action for catalogs at +lib/puppet/string/catalog/$action.rb. + +This is a Puppet module and should work fine if you install it +in Puppet's module path. + +**Note that this only works with Puppet 2.6.next (and thus will work +with 2.6.5), because there is otherwise a bug in finding Puppet applications. +You also have to either install the lib files into your Puppet libdir, or +you need to add this lib directory to your RUBYLIB.** + +This is meant to be tested and iterated upon, with the plan that it will be +merged into Puppet core once we're satisfied with it. + +Usage +----- +The general usage is: + + $ puppet <string> <verb> <name> + +So, e.g.: + + $ puppet facts find myhost.domain.com + $ puppet node destroy myhost + +You can use it to list all known data types and the available terminus classes: + + $ puppet string list + catalog : active_record, compiler, queue, rest, yaml + certificate : ca, file, rest + certificate_request : ca, file, rest + certificate_revocation_list : ca, file, rest + file_bucket_file : file, rest + inventory : yaml + key : ca, file + node : active_record, exec, ldap, memory, plain, rest, yaml + report : processor, rest, yaml + resource : ral, rest + resource_type : parser, rest + status : local, rest + +But most interestingly, you can use it for two main purposes: + +* As a client for any Puppet REST server, such as catalogs, facts, reports, etc. +* As a local CLI for any local Puppet data + +A simple case is looking at the local facts: + + $ puppet facts find localhost + +If you're on the server, you can look in that server's fact collection: + + $ puppet facts --mode master --vardir /tmp/foo --terminus yaml find localhost + +Note that we're setting both the vardir and the 'mode', which switches from the default 'agent' mode to server mode (requires a patch in my branch). + +If you'd prefer the data be outputted in json instead of yaml, well, you can do that, too: + + $ puppet find --mode master facts --vardir /tmp/foo --terminus yaml --format pson localhost + +To test using it as an endpoint for compiling and retrieving catalogs from a remote server, (from my commit), try this: + + # Terminal 1 + $ sbin/puppetmasterd --trace --confdir /tmp/foo --vardir /tmp/foo --debug --manifest ~/bin/test.pp --certname localhost --no-daemonize + + # Terminal 2 + $ sbin/puppetd --trace --debug --confdir /tmp/foo --vardir /tmp/foo --certname localhost --server localhost --test --report + + # Terminal 3, actual testing + $ puppet catalog find localhost --certname localhost --server localhost --mode master --confdir /tmp/foo --vardir /tmp/foo --trace --terminus rest + +This compiles a test catalog (assuming that ~/bin/test.pp exists) and returns it. With the right auth setup, you can also get facts: + + $ puppet facts find localhost --certname localhost --server localhost --mode master --confdir /tmp/foo --vardir /tmp/foo --trace --terminus rest + +Or use IRB to do the same thing: + + $ irb + >> require 'puppet/string' + => true + >> string = Puppet::String[:facts, '1.0.0'] + => #<Puppet::String::Facts:0x1024a1390 @format=:yaml> + >> facts = string.find("myhost") + +Like I said, a prototype, but I'd love it if people would play it with some and make some recommendations. + +Extending +--------- +Like most parts of Puppet, these are easy to extend. Just drop a new action into a given string's directory. E.g.: + + $ cat lib/puppet/string/catalog/select.rb + # Select and show a list of resources of a given type. + Puppet::String.define(:catalog, '1.0.0') do + action :select do + invoke do |host,type| + catalog = Puppet::Resource::Catalog.indirection.find(host) + + catalog.resources.reject { |res| res.type != type }.each { |res| puts res } + end + end + end + $ puppet catalog select localhost Class + Class[main] + Class[Settings] + $ + +Notice that this gets loaded automatically when you try to use it. So, if you have a simple command you've written, such as for cleaning up nodes or diffing catalogs, you an port it to this framework and it should fit cleanly. + +Also note that strings are versioned. These version numbers are interpreted according to Semantic Versioning (http://semver.org). diff --git a/conf/redhat/puppet.spec b/conf/redhat/puppet.spec index e51af0a6b..26b2c9ba0 100644 --- a/conf/redhat/puppet.spec +++ b/conf/redhat/puppet.spec @@ -8,7 +8,7 @@ Name: puppet Version: 2.6.0 Release: 1%{?dist} Summary: A network tool for managing many disparate systems -License: GPLv2+ +License: Apache 2.0 URL: http://puppetlabs.com Source0: http://puppetlabs.com/downloads/%{name}/%{name}-%{version}.tar.gz Source1: http://puppetlabs.com/downloads/%{name}/%{name}-%{version}.tar.gz.sign diff --git a/conf/solaris/pkginfo b/conf/solaris/pkginfo index 7f7bb9736..14a2f0a79 100644 --- a/conf/solaris/pkginfo +++ b/conf/solaris/pkginfo @@ -1,7 +1,6 @@ PKG=CSWpuppet NAME=puppet - System Automation Framework -VERSION=0.23.0 +VERSION=2.7.0 CATEGORY=application -VENDOR=http://reductivelabs.com/projects/puppet -HOTLINE=http://reductivelabs.com/cgi-bin/puppet.cgi -EMAIL=luke@madstop.com +VENDOR=http://projects.puppetlabs.com/projects/puppet +EMAIL=luke@puppetlabs.com diff --git a/conf/suse/puppet.spec b/conf/suse/puppet.spec index 777f6a4b6..2a5b9f4db 100644 --- a/conf/suse/puppet.spec +++ b/conf/suse/puppet.spec @@ -6,7 +6,7 @@ Summary: A network tool for managing many disparate systems Name: puppet Version: 2.6.1 Release: 1%{?dist} -License: GPL +License: Apache 2.0 Group: Productivity/Networking/System URL: http://puppetlabs.com/projects/puppet/ diff --git a/ext/nagios/naggen b/ext/nagios/naggen index c6ca15a55..16dbe6ce4 100755 --- a/ext/nagios/naggen +++ b/ext/nagios/naggen @@ -57,14 +57,21 @@ # # naggen --storeconfigs --confdir /foo --compare # -# = Author # -# Luke Kanies +# = License +# Copyright 2011 Luke Kanies # -# = Copyright +# 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 # -# Copyright (c) 2009 Puppet Labs, LLC -# Licensed under the GPL 2 +# 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. require 'puppet' require 'puppet/rails' diff --git a/ext/puppet-test b/ext/puppet-test index f2648c9ee..affb01249 100755 --- a/ext/puppet-test +++ b/ext/puppet-test @@ -84,14 +84,20 @@ # # puppet-test --retrieve /module/path/to/file # -# = Author +# = License +# Copyright 2011 Luke Kanies # -# Luke Kanies +# 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 # -# = Copyright +# http://www.apache.org/licenses/LICENSE-2.0 # -# Copyright (c) 2005, 2006 Puppet Labs, LLC -# Licensed under the GNU Public License +# 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. # Do an initial trap, so that cancels don't get a stack trace. trap(:INT) do diff --git a/ext/yaml_nodes.rb b/ext/yaml_nodes.rb index 2174da09d..3c7077c13 100755 --- a/ext/yaml_nodes.rb +++ b/ext/yaml_nodes.rb @@ -23,14 +23,20 @@ # yamldir:: # Specify where the yaml is found. Defaults to 'yaml' in the current directory. # -# = Author +# = License +# Copyright 2011 Luke Kanies # -# Luke Kanies +# 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 # -# = Copyright +# http://www.apache.org/licenses/LICENSE-2.0 # -# Copyright (c) 2009 Puppet Labs, Inc. -# Licensed under the GPL2 +# 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. require 'yaml' require 'optparse' diff --git a/install.rb b/install.rb index 6bf4f5587..dcff82403 100755 --- a/install.rb +++ b/install.rb @@ -73,7 +73,7 @@ bins = glob(%w{bin/*}) rdoc = glob(%w{bin/* sbin/* lib/**/*.rb README README-library CHANGELOG TODO Install}).reject { |e| e=~ /\.(bat|cmd)$/ } ri = glob(%w{bin/*.rb sbin/* lib/**/*.rb}).reject { |e| e=~ /\.(bat|cmd)$/ } man = glob(%w{man/man[0-9]/*}) -libs = glob(%w{lib/**/*.rb lib/**/*.py lib/puppet/util/command_line/*}) +libs = glob(%w{lib/**/*.rb lib/**/*.erb lib/**/*.py lib/puppet/util/command_line/*}) tests = glob(%w{test/**/*.rb}) def do_configs(configs, target, strip = 'conf/') diff --git a/lib/puppet.rb b/lib/puppet.rb index ef5fb7f06..64236576a 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -24,7 +24,7 @@ require 'puppet/util/run_mode' # it's also a place to find top-level commands like 'debug' module Puppet - PUPPETVERSION = '2.6.7' + PUPPETVERSION = '2.6.8' def Puppet.version PUPPETVERSION @@ -141,17 +141,12 @@ module Puppet end end - # Create a new type. Just proxy to the Type class. + # Create a new type. Just proxy to the Type class. The mirroring query + # code was deprecated in 2008, but this is still in heavy use. I suppose + # this can count as a soft deprecation for the next dev. --daniel 2011-04-12 def self.newtype(name, options = {}, &block) Puppet::Type.newtype(name, options, &block) end - - # Retrieve a type by name. Just proxy to the Type class. - def self.type(name) - # LAK:DEP Deprecation notice added 12/17/2008 - Puppet.warning "Puppet.type is deprecated; use Puppet::Type.type" - Puppet::Type.type(name) - end end require 'puppet/type' diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb index 57bd88877..374dc850b 100644 --- a/lib/puppet/application.rb +++ b/lib/puppet/application.rb @@ -299,11 +299,12 @@ class Application # This is the main application entry point def run - exit_on_fail("initialize") { hook('preinit') { preinit } } - exit_on_fail("parse options") { hook('parse_options') { parse_options } } - exit_on_fail("parse configuration file") { Puppet.settings.parse } if should_parse_config? - exit_on_fail("prepare for execution") { hook('setup') { setup } } - exit_on_fail("run") { hook('run_command') { run_command } } + exit_on_fail("initialize") { hook('preinit') { preinit } } + exit_on_fail("parse options") { hook('parse_options') { parse_options } } + exit_on_fail("parse configuration file") { Puppet.settings.parse } if should_parse_config? + exit_on_fail("prepare for execution") { hook('setup') { setup } } + exit_on_fail("configure routes from #{Puppet[:route_file]}") { configure_indirector_routes } + exit_on_fail("run") { hook('run_command') { run_command } } end def main @@ -328,6 +329,15 @@ class Application Puppet::Util::Log.newdestination(:syslog) unless options[:setdest] end + def configure_indirector_routes + route_file = Puppet[:route_file] + if ::File.exists?(route_file) + routes = YAML.load_file(route_file) + application_routes = routes[name.to_s] + Puppet::Indirector.configure_routes(application_routes) if application_routes + end + end + def parse_options # Create an option parser option_parser = OptionParser.new(self.class.banner) @@ -349,14 +359,10 @@ class Application end end - # scan command line. - begin - option_parser.parse!(self.command_line.args) - rescue OptionParser::ParseError => detail - $stderr.puts detail - $stderr.puts "Try 'puppet #{command_line.subcommand_name} --help'" - exit(1) - end + # Scan command line. We just hand any exceptions to our upper levels, + # rather than printing help and exiting, so that we can meaningfully + # respond with context-sensitive help if we want to. --daniel 2011-04-12 + option_parser.parse!(self.command_line.args) end def handlearg(opt, arg) @@ -394,7 +400,7 @@ class Application def exit_on_fail(message, code = 1) yield - rescue RuntimeError, NotImplementedError => detail + rescue ArgumentError, RuntimeError, NotImplementedError => detail puts detail.backtrace if Puppet[:trace] $stderr.puts "Could not #{message}: #{detail}" exit(code) diff --git a/lib/puppet/application/agent.rb b/lib/puppet/application/agent.rb index 2ee40227e..fc8616817 100644 --- a/lib/puppet/application/agent.rb +++ b/lib/puppet/application/agent.rb @@ -288,8 +288,7 @@ Luke Kanies COPYRIGHT --------- -Copyright (c) 2005, 2006 Puppet Labs, LLC Licensed under the GNU Public -License +Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License HELP end diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb index 2b7c9f8fb..5779e799c 100644 --- a/lib/puppet/application/apply.rb +++ b/lib/puppet/application/apply.rb @@ -26,6 +26,11 @@ class Puppet::Application::Apply < Puppet::Application end end + option("--parseonly") do + puts "--parseonly has been removed. Please use 'puppet parser validate <manifest>'" + exit 1 + end + def help <<-HELP @@ -117,8 +122,7 @@ Luke Kanies COPYRIGHT --------- -Copyright (c) 2005 Puppet Labs, LLC Licensed under the GNU Public -License +Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License HELP end @@ -126,8 +130,6 @@ License def run_command if options[:catalog] apply - elsif Puppet[:parseonly] - parseonly else main end @@ -154,22 +156,6 @@ License configurer.run :catalog => catalog end - def parseonly - # Set our code or file to use. - if options[:code] or command_line.args.length == 0 - Puppet[:code] = options[:code] || STDIN.read - else - Puppet[:manifest] = command_line.args.shift - end - begin - Puppet::Node::Environment.new(Puppet[:environment]).known_resource_types - rescue => detail - Puppet.err detail - exit 1 - end - exit 0 - end - def main # Set our code or file to use. if options[:code] or command_line.args.length == 0 diff --git a/lib/puppet/application/catalog.rb b/lib/puppet/application/catalog.rb new file mode 100644 index 000000000..10ce05be7 --- /dev/null +++ b/lib/puppet/application/catalog.rb @@ -0,0 +1,4 @@ +require 'puppet/application/indirection_base' + +class Puppet::Application::Catalog < Puppet::Application::IndirectionBase +end diff --git a/lib/puppet/application/cert.rb b/lib/puppet/application/cert.rb index f02fc893c..c08775380 100644 --- a/lib/puppet/application/cert.rb +++ b/lib/puppet/application/cert.rb @@ -48,7 +48,7 @@ class Puppet::Application::Cert < Puppet::Application end def help - puts <<-HELP + <<-HELP puppet-cert(8) -- Manage certificates and requests ======== @@ -163,11 +163,9 @@ Luke Kanies COPYRIGHT --------- -Copyright (c) 2005 Puppet Labs, LLC Licensed under the GNU Public -License +Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License HELP - exit end def main diff --git a/lib/puppet/application/certificate.rb b/lib/puppet/application/certificate.rb new file mode 100644 index 000000000..eacb830b2 --- /dev/null +++ b/lib/puppet/application/certificate.rb @@ -0,0 +1,18 @@ +require 'puppet/application/indirection_base' + +class Puppet::Application::Certificate < Puppet::Application::IndirectionBase + def setup + unless options[:ca_location] + raise ArgumentError, "You must have a CA location specified;\n" + + "use --ca-location to specify the location (remote, local, only)" + end + + location = Puppet::SSL::Host.ca_location + if location == :local && !Puppet::SSL::CertificateAuthority.ca? + self.class.run_mode("master") + self.set_run_mode self.class.run_mode + end + + super + end +end diff --git a/lib/puppet/application/certificate_request.rb b/lib/puppet/application/certificate_request.rb new file mode 100644 index 000000000..1b1b0830c --- /dev/null +++ b/lib/puppet/application/certificate_request.rb @@ -0,0 +1,4 @@ +require 'puppet/application/indirection_base' + +class Puppet::Application::Certificate_request < Puppet::Application::IndirectionBase +end diff --git a/lib/puppet/application/certificate_revocation_list.rb b/lib/puppet/application/certificate_revocation_list.rb new file mode 100644 index 000000000..60b9d97d6 --- /dev/null +++ b/lib/puppet/application/certificate_revocation_list.rb @@ -0,0 +1,4 @@ +require 'puppet/application/indirection_base' + +class Puppet::Application::Certificate_revocation_list < Puppet::Application::IndirectionBase +end diff --git a/lib/puppet/application/config.rb b/lib/puppet/application/config.rb new file mode 100644 index 000000000..a94441e7f --- /dev/null +++ b/lib/puppet/application/config.rb @@ -0,0 +1,4 @@ +require 'puppet/application/face_base' + +class Puppet::Application::Config < Puppet::Application::FaceBase +end diff --git a/lib/puppet/application/configurer.rb b/lib/puppet/application/configurer.rb new file mode 100644 index 000000000..6e86cd2d4 --- /dev/null +++ b/lib/puppet/application/configurer.rb @@ -0,0 +1,23 @@ +require 'puppet/application' +require 'puppet/face' + +class Puppet::Application::Configurer < Puppet::Application + should_parse_config + run_mode :agent + + option("--debug", "-d") + option("--verbose", "-v") + + def setup + if options[:debug] or options[:verbose] + Puppet::Util::Log.level = options[:debug] ? :debug : :info + end + + Puppet::Util::Log.newdestination(:console) + end + + def run_command + report = Puppet::Face[:configurer, '0.0.1'].synchronize(Puppet[:certname]) + Puppet::Face[:report, '0.0.1'].submit(report) + end +end diff --git a/lib/puppet/application/describe.rb b/lib/puppet/application/describe.rb index 79643159e..8ce20b652 100644 --- a/lib/puppet/application/describe.rb +++ b/lib/puppet/application/describe.rb @@ -228,8 +228,7 @@ David Lutterkort COPYRIGHT --------- -Copyright (c) 2005 Puppet Labs, LLC Licensed under the GNU Public -License +Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License HELP end diff --git a/lib/puppet/application/doc.rb b/lib/puppet/application/doc.rb index 74811919e..a88f27c78 100644 --- a/lib/puppet/application/doc.rb +++ b/lib/puppet/application/doc.rb @@ -136,8 +136,7 @@ Luke Kanies COPYRIGHT --------- -Copyright (c) 2005-2007 Puppet Labs, LLC Licensed under the GNU Public -License +Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License HELP end diff --git a/lib/puppet/application/face_base.rb b/lib/puppet/application/face_base.rb new file mode 100644 index 000000000..2a048a532 --- /dev/null +++ b/lib/puppet/application/face_base.rb @@ -0,0 +1,158 @@ +require 'puppet/application' +require 'puppet/face' +require 'optparse' + +class Puppet::Application::FaceBase < Puppet::Application + should_parse_config + run_mode :agent + + option("--debug", "-d") do |arg| + Puppet::Util::Log.level = :debug + end + + option("--verbose", "-v") do + Puppet::Util::Log.level = :info + end + + option("--format FORMAT") do |arg| + @format = arg.to_sym + end + + option("--mode RUNMODE", "-r") do |arg| + raise "Invalid run mode #{arg}; supported modes are user, agent, master" unless %w{user agent master}.include?(arg) + self.class.run_mode(arg.to_sym) + set_run_mode self.class.run_mode + end + + + attr_accessor :face, :action, :type, :arguments, :format + attr_writer :exit_code + + # This allows you to set the exit code if you don't want to just exit + # immediately but you need to indicate a failure. + def exit_code + @exit_code || 0 + end + + # Override this if you need custom rendering. + def render(result) + render_method = Puppet::Network::FormatHandler.format(format).render_method + if render_method == "to_pson" + jj result + exit(0) + else + result.send(render_method) + end + end + + def preinit + super + Signal.trap(:INT) do + $stderr.puts "Cancelling Face" + exit(0) + end + end + + def parse_options + # We need to parse enough of the command line out early, to identify what + # the action is, so that we can obtain the full set of options to parse. + + # REVISIT: These should be configurable versions, through a global + # '--version' option, but we don't implement that yet... --daniel 2011-03-29 + @type = self.class.name.to_s.sub(/.+:/, '').downcase.to_sym + @face = Puppet::Face[@type, :current] + @format = @face.default_format + + # Now, walk the command line and identify the action. We skip over + # arguments based on introspecting the action and all, and find the first + # non-option word to use as the action. + action = nil + index = -1 + until @action or (index += 1) >= command_line.args.length do + item = command_line.args[index] + if item =~ /^-/ then + option = @face.options.find do |name| + item =~ /^-+#{name.to_s.gsub(/[-_]/, '[-_]')}(?:[ =].*)?$/ + end + if option then + option = @face.get_option(option) + # If we have an inline argument, just carry on. We don't need to + # care about optional vs mandatory in that case because we do a real + # parse later, and that will totally take care of raising the error + # when we get there. --daniel 2011-04-04 + if option.takes_argument? and !item.index('=') then + index += 1 unless + (option.optional_argument? and command_line.args[index + 1] =~ /^-/) + end + elsif option = find_global_settings_argument(item) then + unless Puppet.settings.boolean? option.name then + # As far as I can tell, we treat non-bool options as always having + # a mandatory argument. --daniel 2011-04-05 + index += 1 # ...so skip the argument. + end + else + raise OptionParser::InvalidOption.new(item.sub(/=.*$/, '')) + end + else + action = @face.get_action(item.to_sym) + if action.nil? then + raise OptionParser::InvalidArgument.new("#{@face} does not have an #{item} action") + end + @action = action + end + end + + unless @action + raise OptionParser::MissingArgument.new("No action given on the command line") + end + + # Now we can interact with the default option code to build behaviour + # around the full set of options we now know we support. + @action.options.each do |option| + option = @action.get_option(option) # make it the object. + self.class.option(*option.optparse) # ...and make the CLI parse it. + end + + # ...and invoke our parent to parse all the command line options. + super + end + + def find_global_settings_argument(item) + Puppet.settings.each do |name, object| + object.optparse_args.each do |arg| + next unless arg =~ /^-/ + # sadly, we have to emulate some of optparse here... + pattern = /^#{arg.sub('[no-]', '').sub(/[ =].*$/, '')}(?:[ =].*)?$/ + pattern.match item and return object + end + end + return nil # nothing found. + end + + def setup + Puppet::Util::Log.newdestination :console + + @arguments = command_line.args + + # Note: because of our definition of where the action is set, we end up + # with it *always* being the first word of the remaining set of command + # line arguments. So, strip that off when we construct the arguments to + # pass down to the face action. --daniel 2011-04-04 + @arguments.delete_at(0) + + # We copy all of the app options to the end of the call; This allows each + # action to read in the options. This replaces the older model where we + # would invoke the action with options set as global state in the + # interface object. --daniel 2011-03-28 + @arguments << options + end + + + def main + # Call the method associated with the provided action (e.g., 'find'). + if result = @face.send(@action.name, *arguments) + puts render(result) + end + exit(exit_code) + end +end diff --git a/lib/puppet/application/faces.rb b/lib/puppet/application/faces.rb new file mode 100644 index 000000000..3dd3f0312 --- /dev/null +++ b/lib/puppet/application/faces.rb @@ -0,0 +1,88 @@ +require 'puppet/application' +require 'puppet/face' + +class Puppet::Application::Faces < Puppet::Application + + should_parse_config + run_mode :agent + + option("--debug", "-d") do |arg| + Puppet::Util::Log.level = :debug + end + + option("--help", "-h") do |arg| + puts "Usage: puppet faces [actions|terminuses] +Lists all available faces, and by default includes all available terminuses and actions. +" + end + + option("--verbose", "-v") do + Puppet::Util::Log.level = :info + end + + def list(*arguments) + if arguments.empty? + arguments = %w{terminuses actions} + end + faces.each do |name| + str = "#{name}:\n" + if arguments.include?("terminuses") + begin + terms = terminus_classes(name.to_sym) + str << "\tTerminuses: #{terms.join(", ")}\n" + rescue => detail + puts detail.backtrace if Puppet[:trace] + $stderr.puts "Could not load terminuses for #{name}: #{detail}" + end + end + + if arguments.include?("actions") + begin + actions = actions(name.to_sym) + str << "\tActions: #{actions.join(", ")}\n" + rescue => detail + puts detail.backtrace if Puppet[:trace] + $stderr.puts "Could not load actions for #{name}: #{detail}" + end + end + + print str + end + end + + attr_accessor :name, :arguments + + def main + list(*arguments) + end + + def setup + Puppet::Util::Log.newdestination :console + + load_applications # Call this to load all of the apps + + @arguments = command_line.args + @arguments ||= [] + end + + def faces + Puppet::Face.faces + end + + def terminus_classes(indirection) + Puppet::Indirector::Terminus.terminus_classes(indirection).collect { |t| t.to_s }.sort + end + + def actions(indirection) + return [] unless face = Puppet::Face[indirection, '0.0.1'] + face.load_actions + return face.actions.sort { |a, b| a.to_s <=> b.to_s } + end + + def load_applications + command_line.available_subcommands.each do |app| + command_line.require_application app + end + end +end + diff --git a/lib/puppet/application/facts.rb b/lib/puppet/application/facts.rb new file mode 100644 index 000000000..d18b21ea7 --- /dev/null +++ b/lib/puppet/application/facts.rb @@ -0,0 +1,4 @@ +require 'puppet/application/indirection_base' + +class Puppet::Application::Facts < Puppet::Application::IndirectionBase +end diff --git a/lib/puppet/application/file.rb b/lib/puppet/application/file.rb new file mode 100644 index 000000000..32a81c7c6 --- /dev/null +++ b/lib/puppet/application/file.rb @@ -0,0 +1,4 @@ +require 'puppet/application/indirection_base' + +class Puppet::Application::File < Puppet::Application::IndirectionBase +end diff --git a/lib/puppet/application/filebucket.rb b/lib/puppet/application/filebucket.rb index 063d97db8..6d59ae40b 100644 --- a/lib/puppet/application/filebucket.rb +++ b/lib/puppet/application/filebucket.rb @@ -108,8 +108,7 @@ Luke Kanies COPYRIGHT --------- -Copyright (c) 2005 Puppet Labs, LLC Licensed under the GNU Public -License +Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License HELP end diff --git a/lib/puppet/application/help.rb b/lib/puppet/application/help.rb new file mode 100644 index 000000000..0d7767632 --- /dev/null +++ b/lib/puppet/application/help.rb @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +require 'puppet/application/face_base' + +class Puppet::Application::Help < Puppet::Application::FaceBase + # Meh. Disable the default behaviour, which is to inspect the + # string and return that – not so helpful. --daniel 2011-04-11 + def render(result) result end +end diff --git a/lib/puppet/application/indirection_base.rb b/lib/puppet/application/indirection_base.rb new file mode 100644 index 000000000..580a0999a --- /dev/null +++ b/lib/puppet/application/indirection_base.rb @@ -0,0 +1,4 @@ +require 'puppet/application/face_base' + +class Puppet::Application::IndirectionBase < Puppet::Application::FaceBase +end diff --git a/lib/puppet/application/inspect.rb b/lib/puppet/application/inspect.rb index e448cb9e8..30865cfc1 100644 --- a/lib/puppet/application/inspect.rb +++ b/lib/puppet/application/inspect.rb @@ -68,9 +68,7 @@ Puppet Labs COPYRIGHT --------- - -Copyright (c) 2011 Puppet Labs, LLC -Licensed under the GNU General Public License version 2 +Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License HELP end diff --git a/lib/puppet/application/key.rb b/lib/puppet/application/key.rb new file mode 100644 index 000000000..57835b627 --- /dev/null +++ b/lib/puppet/application/key.rb @@ -0,0 +1,4 @@ +require 'puppet/application/indirection_base' + +class Puppet::Application::Key < Puppet::Application::IndirectionBase +end diff --git a/lib/puppet/application/kick.rb b/lib/puppet/application/kick.rb index da93c0182..536699442 100644 --- a/lib/puppet/application/kick.rb +++ b/lib/puppet/application/kick.rb @@ -172,8 +172,7 @@ Luke Kanies COPYRIGHT --------- -Copyright (c) 2005 Puppet Labs, LLC Licensed under the GNU Public -License +Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License HELP end diff --git a/lib/puppet/application/master.rb b/lib/puppet/application/master.rb index 78499a92a..a90829ae0 100644 --- a/lib/puppet/application/master.rb +++ b/lib/puppet/application/master.rb @@ -25,6 +25,11 @@ class Puppet::Application::Master < Puppet::Application end end + option("--parseonly") do + puts "--parseonly has been removed. Please use 'puppet parser validate <manifest>'" + exit 1 + end + def help <<-HELP @@ -105,8 +110,7 @@ Luke Kanies COPYRIGHT --------- -Copyright (c) 2005 Puppet Labs, LLC Licensed under the GNU Public -License +Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License HELP end @@ -126,8 +130,6 @@ License def run_command if options[:node] compile - elsif Puppet[:parseonly] - parseonly else main end @@ -149,16 +151,6 @@ License exit(0) end - def parseonly - begin - Puppet::Node::Environment.new(Puppet[:environment]).known_resource_types - rescue => detail - Puppet.err detail - exit 1 - end - exit(0) - end - def main require 'etc' require 'puppet/file_serving/content' diff --git a/lib/puppet/application/node.rb b/lib/puppet/application/node.rb new file mode 100644 index 000000000..38c1f8610 --- /dev/null +++ b/lib/puppet/application/node.rb @@ -0,0 +1,4 @@ +require 'puppet/application/indirection_base' + +class Puppet::Application::Node < Puppet::Application::IndirectionBase +end diff --git a/lib/puppet/application/parser.rb b/lib/puppet/application/parser.rb new file mode 100644 index 000000000..b6ec3c185 --- /dev/null +++ b/lib/puppet/application/parser.rb @@ -0,0 +1,5 @@ +require 'puppet/application/face_base' +require 'puppet/face' + +class Puppet::Application::Parser < Puppet::Application::FaceBase +end diff --git a/lib/puppet/application/queue.rb b/lib/puppet/application/queue.rb index de8aea32a..e56fde281 100644 --- a/lib/puppet/application/queue.rb +++ b/lib/puppet/application/queue.rb @@ -104,8 +104,7 @@ Luke Kanies COPYRIGHT --------- -Copyright (c) 2009 Puppet Labs, LLC Licensed under the GNU Public -License +Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License HELP end diff --git a/lib/puppet/application/report.rb b/lib/puppet/application/report.rb new file mode 100644 index 000000000..f7f961edd --- /dev/null +++ b/lib/puppet/application/report.rb @@ -0,0 +1,4 @@ +require 'puppet/application/indirection_base' + +class Puppet::Application::Report < Puppet::Application::IndirectionBase +end diff --git a/lib/puppet/application/resource.rb b/lib/puppet/application/resource.rb index 3995c285b..6ef87d68f 100644 --- a/lib/puppet/application/resource.rb +++ b/lib/puppet/application/resource.rb @@ -132,8 +132,7 @@ Luke Kanies COPYRIGHT --------- -Copyright (c) 2005-2007 Puppet Labs, LLC Licensed under the GNU Public -License +Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License HELP end diff --git a/lib/puppet/application/resource_type.rb b/lib/puppet/application/resource_type.rb new file mode 100644 index 000000000..59594262c --- /dev/null +++ b/lib/puppet/application/resource_type.rb @@ -0,0 +1,4 @@ +require 'puppet/application/indirection_base' + +class Puppet::Application::Resource_type < Puppet::Application::IndirectionBase +end diff --git a/lib/puppet/application/status.rb b/lib/puppet/application/status.rb new file mode 100644 index 000000000..1c3ca054e --- /dev/null +++ b/lib/puppet/application/status.rb @@ -0,0 +1,4 @@ +require 'puppet/application/indirection_base' + +class Puppet::Application::Status < Puppet::Application::IndirectionBase +end diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index 989ef3f35..680762b94 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -116,6 +116,7 @@ module Puppet but then ship with tools that do not know how to handle signed ints, so the UIDs show up as huge numbers that can then not be fed back into the system. This is a hackish way to fail in a slightly more useful way when that happens."], + :route_file => ["$confdir/routes.yaml", "The YAML file containing indirector route configuration."], :node_terminus => ["plain", "Where to find information about nodes."], :catalog_terminus => ["compiler", "Where to get node catalogs. This is useful to change if, for instance, you'd like to pre-compile catalogs and store them in memcached or some other easily-accessed store."], @@ -353,6 +354,8 @@ module Puppet autosigns any key request, and is a very bad idea), false (which never autosigns any key request), and the path to a file, which uses that configuration file to determine which keys to sign."}, + :allow_duplicate_certs => [false, "Whether to allow a new certificate + request to overwrite an existing certificate."], :ca_days => ["", "How long a certificate should be valid. This parameter is deprecated, use ca_ttl instead"], :ca_ttl => ["5y", "The default TTL for new certificates; valid values @@ -415,7 +418,6 @@ module Puppet :desc => "Where the puppet master web server logs." }, :masterport => [8140, "Which port puppet master listens on."], - :parseonly => [false, "Just check the syntax of the manifests."], :node_name => ["cert", "How the puppetmaster determines the client's identity and sets the 'hostname', 'fqdn' and 'domain' facts for use in the manifest, in particular for determining which 'node' statement applies to the client. diff --git a/lib/puppet/face.rb b/lib/puppet/face.rb new file mode 100644 index 000000000..f73b2fc3b --- /dev/null +++ b/lib/puppet/face.rb @@ -0,0 +1,12 @@ +# The public name of this feature is 'face', but we have hidden all the +# plumbing over in the 'interfaces' namespace to make clear the distinction +# between the two. +# +# This file exists to ensure that the public name is usable without revealing +# the details of the implementation; you really only need go look at anything +# under Interfaces if you are looking to extend the implementation. +# +# It isn't hidden to gratuitously hide things, just to make it easier to +# separate out the interests people will have. --daniel 2011-04-07 +require 'puppet/interface' +Puppet::Face = Puppet::Interface diff --git a/lib/puppet/face/catalog.rb b/lib/puppet/face/catalog.rb new file mode 100644 index 000000000..0dcde3591 --- /dev/null +++ b/lib/puppet/face/catalog.rb @@ -0,0 +1,40 @@ +require 'puppet/face/indirector' + +Puppet::Face::Indirector.define(:catalog, '0.0.1') do + action(:apply) do + when_invoked do |catalog, options| + report = Puppet::Transaction::Report.new("apply") + report.configuration_version = catalog.version + + Puppet::Util::Log.newdestination(report) + + begin + benchmark(:notice, "Finished catalog run") do + catalog.apply(:report => report) + end + rescue => detail + puts detail.backtrace if Puppet[:trace] + Puppet.err "Failed to apply catalog: #{detail}" + end + + report.finalize_report + report + end + end + + action(:download) do + when_invoked do |certname, facts, options| + Puppet::Resource::Catalog.indirection.terminus_class = :rest + facts_to_upload = {:facts_format => :b64_zlib_yaml, :facts => CGI.escape(facts.render(:b64_zlib_yaml))} + catalog = nil + retrieval_duration = thinmark do + catalog = Puppet::Face[:catalog, '0.0.1'].find(certname, facts_to_upload) + end + catalog = catalog.to_ral + catalog.finalize + catalog.retrieval_duration = retrieval_duration + catalog.write_class_file + catalog + end + end +end diff --git a/lib/puppet/face/catalog/select.rb b/lib/puppet/face/catalog/select.rb new file mode 100644 index 000000000..ba27117bc --- /dev/null +++ b/lib/puppet/face/catalog/select.rb @@ -0,0 +1,10 @@ +# Select and show a list of resources of a given type. +Puppet::Face.define(:catalog, '0.0.1') do + action :select do + when_invoked do |host, type, options| + catalog = Puppet::Resource::Catalog.indirection.find(host) + + catalog.resources.reject { |res| res.type != type }.each { |res| puts res } + end + end +end diff --git a/lib/puppet/face/certificate.rb b/lib/puppet/face/certificate.rb new file mode 100644 index 000000000..77e80f099 --- /dev/null +++ b/lib/puppet/face/certificate.rb @@ -0,0 +1,46 @@ +require 'puppet/face/indirector' +require 'puppet/ssl/host' + +Puppet::Face::Indirector.define(:certificate, '0.0.1') do + # REVISIT: This should use a pre-invoke hook to run the common code that + # needs to happen before we invoke any action; that would be much nicer than + # the "please repeat yourself" stuff found in here right now. + # + # option "--ca-location LOCATION" do + # type [:whatever, :location, :symbols] + # hook :before do |value| + # Puppet::SSL::Host.ca_location = value + # end + # end + # + # ...but should I pass the arguments as well? + # --daniel 2011-04-05 + option "--ca-location LOCATION" + + action :generate do + when_invoked do |name, options| + Puppet::SSL::Host.ca_location = options[:ca_location].to_sym + host = Puppet::SSL::Host.new(name) + host.generate_certificate_request + host.certificate_request.class.indirection.save(host.certificate_request) + end + end + + action :list do + when_invoked do |options| + Puppet::SSL::Host.ca_location = options[:ca_location].to_sym + Puppet::SSL::Host.indirection.search("*", { + :for => :certificate_request, + }).map { |h| h.inspect } + end + end + + action :sign do + when_invoked do |name, options| + Puppet::SSL::Host.ca_location = options[:ca_location].to_sym + host = Puppet::SSL::Host.new(name) + host.desired_state = 'signed' + Puppet::SSL::Host.indirection.save(host) + end + end +end diff --git a/lib/puppet/face/certificate_request.rb b/lib/puppet/face/certificate_request.rb new file mode 100644 index 000000000..1feba25ab --- /dev/null +++ b/lib/puppet/face/certificate_request.rb @@ -0,0 +1,4 @@ +require 'puppet/face/indirector' + +Puppet::Face::Indirector.define(:certificate_request, '0.0.1') do +end diff --git a/lib/puppet/face/certificate_revocation_list.rb b/lib/puppet/face/certificate_revocation_list.rb new file mode 100644 index 000000000..6a75aa578 --- /dev/null +++ b/lib/puppet/face/certificate_revocation_list.rb @@ -0,0 +1,4 @@ +require 'puppet/face/indirector' + +Puppet::Face::Indirector.define(:certificate_revocation_list, '0.0.1') do +end diff --git a/lib/puppet/face/config.rb b/lib/puppet/face/config.rb new file mode 100644 index 000000000..45cb6b156 --- /dev/null +++ b/lib/puppet/face/config.rb @@ -0,0 +1,12 @@ +require 'puppet/face' + +Puppet::Face.define(:config, '0.0.1') do + action(:print) do + when_invoked do |*args| + options = args.pop + Puppet.settings[:configprint] = args.join(",") + Puppet.settings.print_config_options + nil + end + end +end diff --git a/lib/puppet/face/configurer.rb b/lib/puppet/face/configurer.rb new file mode 100644 index 000000000..74dfb854e --- /dev/null +++ b/lib/puppet/face/configurer.rb @@ -0,0 +1,12 @@ +require 'puppet/face' + +Puppet::Face.define(:configurer, '0.0.1') do + action(:synchronize) do + when_invoked do |certname, options| + facts = Puppet::Face[:facts, '0.0.1'].find(certname) + catalog = Puppet::Face[:catalog, '0.0.1'].download(certname, facts) + report = Puppet::Face[:catalog, '0.0.1'].apply(catalog) + report + end + end +end diff --git a/lib/puppet/face/facts.rb b/lib/puppet/face/facts.rb new file mode 100644 index 000000000..8668b2531 --- /dev/null +++ b/lib/puppet/face/facts.rb @@ -0,0 +1,18 @@ +require 'puppet/face/indirector' +require 'puppet/node/facts' + +Puppet::Face::Indirector.define(:facts, '0.0.1') do + set_default_format :yaml + + # Upload our facts to the server + action(:upload) do + when_invoked do |options| + Puppet::Node::Facts.indirection.terminus_class = :facter + facts = Puppet::Node::Facts.indirection.find(Puppet[:certname]) + Puppet::Node::Facts.indirection.terminus_class = :rest + Puppet::Node::Facts.indirection.save(facts) + Puppet.notice "Uploaded facts for '#{Puppet[:certname]}'" + nil + end + end +end diff --git a/lib/puppet/face/file.rb b/lib/puppet/face/file.rb new file mode 100644 index 000000000..1aa9462dd --- /dev/null +++ b/lib/puppet/face/file.rb @@ -0,0 +1,5 @@ +require 'puppet/face/indirector' + +Puppet::Face::Indirector.define(:file, '0.0.1') do + set_indirection_name :file_bucket_file +end diff --git a/lib/puppet/face/help.rb b/lib/puppet/face/help.rb new file mode 100644 index 000000000..1c2da9e83 --- /dev/null +++ b/lib/puppet/face/help.rb @@ -0,0 +1,104 @@ +require 'puppet/face' +require 'puppet/util/command_line' +require 'pathname' +require 'erb' + +Puppet::Face.define(:help, '0.0.1') do + summary "Displays help about puppet subcommands" + + action(:help) do + summary "Display help about faces and their actions." + + option "--version VERSION" do + desc "Which version of the interface to show help for" + end + + when_invoked do |*args| + # Check our invocation, because we want varargs and can't do defaults + # yet. REVISIT: when we do option defaults, and positional options, we + # should rewrite this to use those. --daniel 2011-04-04 + options = args.pop + if options.nil? or args.length > 2 then + raise ArgumentError, "help only takes two (optional) arguments, a face name, and an action" + end + + version = :current + if options.has_key? :version then + if options[:version].to_s !~ /^current$/i then + version = options[:version] + else + if args.length == 0 then + raise ArgumentError, "version only makes sense when a face is given" + end + end + end + + # Name those parameters... + facename, actionname = args + + if facename then + if legacy_applications.include? facename then + actionname and raise ArgumentError, "Legacy subcommands don't take actions" + return Puppet::Application[facename].help + else + face = Puppet::Face[facename.to_sym, version] + actionname and action = face.get_action(actionname.to_sym) + end + end + + case args.length + when 0 then + template = erb 'global.erb' + when 1 then + face or fail ArgumentError, "Unable to load face #{facename}" + template = erb 'face.erb' + when 2 then + face or fail ArgumentError, "Unable to load face #{facename}" + action or fail ArgumentError, "Unable to load action #{actionname} from #{face}" + template = erb 'action.erb' + else + fail ArgumentError, "Too many arguments to help action" + end + + # Run the ERB template in our current binding, including all the local + # variables we established just above. --daniel 2011-04-11 + return template.result(binding) + end + end + + def erb(name) + template = (Pathname(__FILE__).dirname + "help" + name) + erb = ERB.new(template.read, nil, '%') + erb.filename = template.to_s + return erb + end + + def legacy_applications + # The list of applications, less those that are duplicated as a face. + Puppet::Util::CommandLine.available_subcommands.reject do |appname| + Puppet::Face.face? appname.to_sym, :current or + # ...this is a nasty way to exclude non-applications. :( + %w{face_base indirection_base}.include? appname + end.sort + end + + def horribly_extract_summary_from(appname) + begin + require "puppet/application/#{appname}" + help = Puppet::Application[appname].help.split("\n") + # Now we find the line with our summary, extract it, and return it. This + # depends on the implementation coincidence of how our pages are + # formatted. If we can't match the pattern we expect we return the empty + # string to ensure we don't blow up in the summary. --daniel 2011-04-11 + while line = help.shift do + if md = /^puppet-#{appname}\([^\)]+\) -- (.*)$/.match(line) then + return md[1] + end + end + rescue Exception + # Damn, but I hate this: we just ignore errors here, no matter what + # class they are. Meh. + end + return '' + end +end diff --git a/lib/puppet/face/help/action.erb b/lib/puppet/face/help/action.erb new file mode 100644 index 000000000..eaf131464 --- /dev/null +++ b/lib/puppet/face/help/action.erb @@ -0,0 +1,3 @@ +Use: puppet <%= face.name %> [options] <%= action.name %> [options] + +Summary: <%= action.summary %> diff --git a/lib/puppet/face/help/face.erb b/lib/puppet/face/help/face.erb new file mode 100644 index 000000000..efe5fd809 --- /dev/null +++ b/lib/puppet/face/help/face.erb @@ -0,0 +1,7 @@ +Use: puppet <%= face.name %> [options] <action> [options] + +Available actions: +% face.actions.each do |actionname| +% action = face.get_action(actionname) + <%= action.name.to_s.ljust(16) %> <%= action.summary %> +% end diff --git a/lib/puppet/face/help/global.erb b/lib/puppet/face/help/global.erb new file mode 100644 index 000000000..f4c761b2b --- /dev/null +++ b/lib/puppet/face/help/global.erb @@ -0,0 +1,20 @@ +puppet <subcommand> [options] <action> [options] + +Available subcommands, from Puppet Faces: +% Puppet::Face.faces.sort.each do |name| +% face = Puppet::Face[name, :current] + <%= face.name.to_s.ljust(16) %> <%= face.summary %> +% end + +% unless legacy_applications.empty? then # great victory when this is true! +Available applications, soon to be ported to Faces: +% legacy_applications.each do |appname| +% summary = horribly_extract_summary_from appname + <%= appname.to_s.ljust(16) %> <%= summary %> +% end +% end + +See 'puppet help <subcommand> <action>' for help on a specific subcommand action. +See 'puppet help <subcommand>' for help on a specific subcommand. +See 'puppet man <subcommand>' for the full man page. +Puppet v<%= Puppet::PUPPETVERSION %> diff --git a/lib/puppet/face/indirector.rb b/lib/puppet/face/indirector.rb new file mode 100644 index 000000000..f48611e4b --- /dev/null +++ b/lib/puppet/face/indirector.rb @@ -0,0 +1,94 @@ +require 'puppet' +require 'puppet/face' + +class Puppet::Face::Indirector < Puppet::Face + option "--terminus TERMINUS" do + desc "REVISIT: You can select a terminus, which has some bigger effect +that we should describe in this file somehow." + end + + def self.indirections + Puppet::Indirector::Indirection.instances.collect { |t| t.to_s }.sort + end + + def self.terminus_classes(indirection) + Puppet::Indirector::Terminus.terminus_classes(indirection.to_sym).collect { |t| t.to_s }.sort + end + + def call_indirection_method(method, *args) + options = args.last + options.has_key?(:terminus) and set_terminus(options[:terminus]) + + begin + result = indirection.__send__(method, *args) + rescue => detail + puts detail.backtrace if Puppet[:trace] + raise "Could not call '#{method}' on '#{indirection_name}': #{detail}" + end + + indirection.reset_terminus_class + return result + end + + action :destroy do + when_invoked { |*args| call_indirection_method(:destroy, *args) } + end + + action :find do + when_invoked { |*args| call_indirection_method(:find, *args) } + end + + action :save do + when_invoked { |*args| call_indirection_method(:save, *args) } + end + + action :search do + when_invoked { |*args| call_indirection_method(:search, *args) } + end + + # Print the configuration for the current terminus class + action :info do + when_invoked do |*args| + options = args.pop + options.has_key?(:terminus) and set_terminus(options[:terminus]) + + if t = indirection.terminus_class + puts "Run mode '#{Puppet.run_mode.name}': #{t}" + else + $stderr.puts "No default terminus class for run mode '#{Puppet.run_mode.name}'" + end + + indirection.reset_terminus_class + end + end + + attr_accessor :from + + def indirection_name + @indirection_name || name.to_sym + end + + # Here's your opportunity to override the indirection name. By default it + # will be the same name as the face. + def set_indirection_name(name) + @indirection_name = name + end + + # Return an indirection associated with a face, if one exists; + # One usually does. + def indirection + unless @indirection + @indirection = Puppet::Indirector::Indirection.instance(indirection_name) + @indirection or raise "Could not find terminus for #{indirection_name}" + end + @indirection + end + + def set_terminus(from) + begin + indirection.terminus_class = from + rescue => detail + raise "Could not set '#{indirection.name}' terminus to '#{from}' (#{detail}); valid terminus types are #{self.class.terminus_classes(indirection.name).join(", ") }" + end + end +end diff --git a/lib/puppet/face/key.rb b/lib/puppet/face/key.rb new file mode 100644 index 000000000..3a11ddb03 --- /dev/null +++ b/lib/puppet/face/key.rb @@ -0,0 +1,4 @@ +require 'puppet/face/indirector' + +Puppet::Face::Indirector.define(:key, '0.0.1') do +end diff --git a/lib/puppet/face/node.rb b/lib/puppet/face/node.rb new file mode 100644 index 000000000..fd1a548d6 --- /dev/null +++ b/lib/puppet/face/node.rb @@ -0,0 +1,5 @@ +require 'puppet/face/indirector' + +Puppet::Face::Indirector.define(:node, '0.0.1') do + set_default_format :yaml +end diff --git a/lib/puppet/face/parser.rb b/lib/puppet/face/parser.rb new file mode 100644 index 000000000..c44810b99 --- /dev/null +++ b/lib/puppet/face/parser.rb @@ -0,0 +1,17 @@ +require 'puppet/face' +require 'puppet/parser' + +Puppet::Face.define(:parser, '0.0.1') do + action :validate do + when_invoked do |*args| + args.pop + files = args + files << Puppet[:manifest] if files.empty? + files.each do |file| + Puppet[:manifest] = file + Puppet::Node::Environment.new(Puppet[:environment]).known_resource_types.clear + end + nil + end + end +end diff --git a/lib/puppet/face/report.rb b/lib/puppet/face/report.rb new file mode 100644 index 000000000..6e6f0b335 --- /dev/null +++ b/lib/puppet/face/report.rb @@ -0,0 +1,15 @@ +require 'puppet/face/indirector' + +Puppet::Face::Indirector.define(:report, '0.0.1') do + action(:submit) do + when_invoked do |report, options| + begin + Puppet::Transaction::Report.terminus_class = :rest + report.save + rescue => detail + puts detail.backtrace if Puppet[:trace] + Puppet.err "Could not send report: #{detail}" + end + end + end +end diff --git a/lib/puppet/face/resource.rb b/lib/puppet/face/resource.rb new file mode 100644 index 000000000..d162f728a --- /dev/null +++ b/lib/puppet/face/resource.rb @@ -0,0 +1,4 @@ +require 'puppet/face/indirector' + +Puppet::Face::Indirector.define(:resource, '0.0.1') do +end diff --git a/lib/puppet/face/resource_type.rb b/lib/puppet/face/resource_type.rb new file mode 100644 index 000000000..0cdbd719f --- /dev/null +++ b/lib/puppet/face/resource_type.rb @@ -0,0 +1,4 @@ +require 'puppet/face/indirector' + +Puppet::Face::Indirector.define(:resource_type, '0.0.1') do +end diff --git a/lib/puppet/face/status.rb b/lib/puppet/face/status.rb new file mode 100644 index 000000000..7085e7cd7 --- /dev/null +++ b/lib/puppet/face/status.rb @@ -0,0 +1,4 @@ +require 'puppet/face/indirector' + +Puppet::Face::Indirector.define(:status, '0.0.1') do +end diff --git a/lib/puppet/faces/help/action.erb b/lib/puppet/faces/help/action.erb new file mode 100644 index 000000000..eaf131464 --- /dev/null +++ b/lib/puppet/faces/help/action.erb @@ -0,0 +1,3 @@ +Use: puppet <%= face.name %> [options] <%= action.name %> [options] + +Summary: <%= action.summary %> diff --git a/lib/puppet/faces/help/face.erb b/lib/puppet/faces/help/face.erb new file mode 100644 index 000000000..efe5fd809 --- /dev/null +++ b/lib/puppet/faces/help/face.erb @@ -0,0 +1,7 @@ +Use: puppet <%= face.name %> [options] <action> [options] + +Available actions: +% face.actions.each do |actionname| +% action = face.get_action(actionname) + <%= action.name.to_s.ljust(16) %> <%= action.summary %> +% end diff --git a/lib/puppet/faces/help/global.erb b/lib/puppet/faces/help/global.erb new file mode 100644 index 000000000..e123367a2 --- /dev/null +++ b/lib/puppet/faces/help/global.erb @@ -0,0 +1,20 @@ +puppet <subcommand> [options] <action> [options] + +Available subcommands, from Puppet Faces: +% Puppet::Faces.faces.sort.each do |name| +% face = Puppet::Faces[name, :current] + <%= face.name.to_s.ljust(16) %> <%= face.summary %> +% end + +% unless legacy_applications.empty? then # great victory when this is true! +Available applications, soon to be ported to Faces: +% legacy_applications.each do |appname| +% summary = horribly_extract_summary_from appname + <%= appname.to_s.ljust(16) %> <%= summary %> +% end +% end + +See 'puppet help <subcommand> <action>' for help on a specific subcommand action. +See 'puppet help <subcommand>' for help on a specific subcommand. +See 'puppet man <subcommand>' for the full man page. +Puppet v<%= Puppet::PUPPETVERSION %> diff --git a/lib/puppet/feature/ssh.rb b/lib/puppet/feature/ssh.rb new file mode 100644 index 000000000..82fe19882 --- /dev/null +++ b/lib/puppet/feature/ssh.rb @@ -0,0 +1,4 @@ +require 'puppet/util/feature' + +Puppet.features.rubygems? +Puppet.features.add(:ssh, :libs => %{net/ssh}) diff --git a/lib/puppet/indirector.rb b/lib/puppet/indirector.rb index 9effc5cdd..7267ac7f3 100644 --- a/lib/puppet/indirector.rb +++ b/lib/puppet/indirector.rb @@ -12,6 +12,22 @@ module Puppet::Indirector require 'puppet/indirector/envelope' require 'puppet/network/format_handler' + def self.configure_routes(application_routes) + application_routes.each do |indirection_name, termini| + indirection_name = indirection_name.to_sym + terminus_name = termini["terminus"] + cache_name = termini["cache"] + + Puppet::Indirector::Terminus.terminus_classes(indirection_name) + + indirection = Puppet::Indirector::Indirection.instance(indirection_name) + raise "Indirection #{indirection_name} does not exist" unless indirection + + indirection.terminus_class = terminus_name if terminus_name + indirection.cache_class = cache_name if cache_name + end + end + # Declare that the including class indirects its methods to # this terminus. The terminus name must be the name of a Puppet # default, not the value -- if it's the value, then it gets diff --git a/lib/puppet/indirector/certificate_request/ca.rb b/lib/puppet/indirector/certificate_request/ca.rb index f4c924fe1..5d76ee52a 100644 --- a/lib/puppet/indirector/certificate_request/ca.rb +++ b/lib/puppet/indirector/certificate_request/ca.rb @@ -7,6 +7,14 @@ class Puppet::SSL::CertificateRequest::Ca < Puppet::Indirector::SslFile store_in :csrdir def save(request) + if host = Puppet::SSL::Host.indirection.find(request.key) + if Puppet[:allow_duplicate_certs] + Puppet.notice "#{request.key} already has a #{host.state} certificate; new certificate will overwrite it" + else + raise "#{request.key} already has a #{host.state} certificate; ignoring certificate request" + end + end + result = super Puppet.notice "#{request.key} has a waiting certificate request" result diff --git a/lib/puppet/indirector/couch.rb b/lib/puppet/indirector/couch.rb index fae934fd8..243d33dd4 100644 --- a/lib/puppet/indirector/couch.rb +++ b/lib/puppet/indirector/couch.rb @@ -1,6 +1,3 @@ -raise "Couch terminus not supported without couchrest gem" unless Puppet.features.couchdb? - -require 'couchrest' class Puppet::Indirector::Couch < Puppet::Indirector::Terminus # The CouchRest database instance. One database instance per Puppet runtime @@ -13,6 +10,11 @@ class Puppet::Indirector::Couch < Puppet::Indirector::Terminus attributes_of get(request) end + def initialize(*args) + raise "Couch terminus not supported without couchrest gem" unless Puppet.features.couchdb? + super + end + # Create or update the couchdb document with the request's data hash. # def save(request) diff --git a/lib/puppet/indirector/rest.rb b/lib/puppet/indirector/rest.rb index e50dc68ae..0d3997221 100644 --- a/lib/puppet/indirector/rest.rb +++ b/lib/puppet/indirector/rest.rb @@ -72,7 +72,17 @@ class Puppet::Indirector::REST < Puppet::Indirector::Terminus end def find(request) - return nil unless result = deserialize(network(request).get(indirection2uri(request), headers)) + uri, body = request_to_uri_and_body(request) + uri_with_query_string = "#{uri}?#{body}" + http_connection = network(request) + # WEBrick in Ruby 1.9.1 only supports up to 1024 character lines in an HTTP request + # http://redmine.ruby-lang.org/issues/show/3991 + response = if "GET #{uri_with_query_string} HTTP/1.1\r\n".length > 1024 + http_connection.post(uri, body, headers) + else + http_connection.get(uri_with_query_string, headers) + end + result = deserialize response result.name = request.key if result.respond_to?(:name=) result end diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb new file mode 100644 index 000000000..6570ebe46 --- /dev/null +++ b/lib/puppet/interface.rb @@ -0,0 +1,120 @@ +require 'puppet' +require 'puppet/util/autoload' + +class Puppet::Interface + require 'puppet/interface/face_collection' + + require 'puppet/interface/action_manager' + include Puppet::Interface::ActionManager + extend Puppet::Interface::ActionManager + + require 'puppet/interface/option_manager' + include Puppet::Interface::OptionManager + extend Puppet::Interface::OptionManager + + include Puppet::Util + + class << self + # This is just so we can search for actions. We only use its + # list of directories to search. + # Can't we utilize an external autoloader, or simply use the $LOAD_PATH? -pvb + def autoloader + @autoloader ||= Puppet::Util::Autoload.new(:application, "puppet/face") + end + + def faces + Puppet::Interface::FaceCollection.faces + end + + def face?(name, version) + Puppet::Interface::FaceCollection.face?(name, version) + end + + def register(instance) + Puppet::Interface::FaceCollection.register(instance) + end + + def define(name, version, &block) + if face?(name, version) + face = Puppet::Interface::FaceCollection[name, version] + else + face = self.new(name, version) + Puppet::Interface::FaceCollection.register(face) + # REVISIT: Shouldn't this be delayed until *after* we evaluate the + # current block, not done before? --daniel 2011-04-07 + face.load_actions + end + + face.instance_eval(&block) if block_given? + + return face + end + + def [](name, version) + unless face = Puppet::Interface::FaceCollection[name, version] + if current = Puppet::Interface::FaceCollection[name, :current] + raise Puppet::Error, "Could not find version #{version} of #{current}" + else + raise Puppet::Error, "Could not find Puppet Face #{name.inspect}" + end + end + face + end + end + + attr_accessor :default_format + + def set_default_format(format) + self.default_format = format.to_sym + end + + attr_accessor :summary + def summary(value = nil) + @summary = value unless value.nil? + @summary + end + + attr_reader :name, :version + + def initialize(name, version, &block) + unless Puppet::Interface::FaceCollection.validate_version(version) + raise ArgumentError, "Cannot create face #{name.inspect} with invalid version number '#{version}'!" + end + + @name = Puppet::Interface::FaceCollection.underscorize(name) + @version = version + @default_format = :pson + + instance_eval(&block) if block_given? + end + + # Try to find actions defined in other files. + def load_actions + path = "puppet/face/#{name}" + + loaded = [] + [path, "#{name}@#{version}/#{path}"].each do |path| + Puppet::Interface.autoloader.search_directories.each do |dir| + fdir = ::File.join(dir, path) + next unless FileTest.directory?(fdir) + + Dir.chdir(fdir) do + Dir.glob("*.rb").each do |file| + aname = file.sub(/\.rb/, '') + if loaded.include?(aname) + Puppet.debug "Not loading duplicate action '#{aname}' for '#{name}' from '#{fdir}/#{file}'" + next + end + loaded << aname + Puppet.debug "Loading action '#{aname}' for '#{name}' from '#{fdir}/#{file}'" + require "#{Dir.pwd}/#{aname}" + end + end + end + end + end + + def to_s + "Puppet::Face[#{name.inspect}, #{version.inspect}]" + end +end diff --git a/lib/puppet/interface/action.rb b/lib/puppet/interface/action.rb new file mode 100644 index 000000000..db338e39e --- /dev/null +++ b/lib/puppet/interface/action.rb @@ -0,0 +1,129 @@ +# -*- coding: utf-8 -*- +require 'puppet/interface' +require 'puppet/interface/option' + +class Puppet::Interface::Action + def initialize(face, name, attrs = {}) + raise "#{name.inspect} is an invalid action name" unless name.to_s =~ /^[a-z]\w*$/ + @face = face + @name = name.to_sym + @options = {} + attrs.each do |k, v| send("#{k}=", v) end + end + + # This is not nice, but it is the easiest way to make us behave like the + # Ruby Method object rather than UnboundMethod. Duplication is vaguely + # annoying, but at least we are a shallow clone. --daniel 2011-04-12 + def __dup_and_rebind_to(to) + bound_version = self.dup + bound_version.instance_variable_set(:@face, to) + return bound_version + end + + attr_reader :name + def to_s() "#{@face}##{@name}" end + + attr_accessor :summary + + # Initially, this was defined to allow the @action.invoke pattern, which is + # a very natural way to invoke behaviour given our introspection + # capabilities. Heck, our initial plan was to have the faces delegate to + # the action object for invocation and all. + # + # It turns out that we have a binding problem to solve: @face was bound to + # the parent class, not the subclass instance, and we don't pass the + # appropriate context or change the binding enough to make this work. + # + # We could hack around it, by either mandating that you pass the context in + # to invoke, or try to get the binding right, but that has probably got + # subtleties that we don't instantly think of – especially around threads. + # + # So, we are pulling this method for now, and will return it to life when we + # have the time to resolve the problem. For now, you should replace... + # + # @action = @face.get_action(name) + # @action.invoke(arg1, arg2, arg3) + # + # ...with... + # + # @action = @face.get_action(name) + # @face.send(@action.name, arg1, arg2, arg3) + # + # I understand that is somewhat cumbersome, but it functions as desired. + # --daniel 2011-03-31 + # + # PS: This code is left present, but commented, to support this chunk of + # documentation, for the benefit of the reader. + # + # def invoke(*args, &block) + # @face.send(name, *args, &block) + # end + + def when_invoked=(block) + # We need to build an instance method as a wrapper, using normal code, to + # be able to expose argument defaulting between the caller and definer in + # the Ruby API. An extra method is, sadly, required for Ruby 1.8 to work. + # + # In future this also gives us a place to hook in additional behaviour + # such as calling out to the action instance to validate and coerce + # parameters, which avoids any exciting context switching and all. + # + # Hopefully we can improve this when we finally shuffle off the last of + # Ruby 1.8 support, but that looks to be a few "enterprise" release eras + # away, so we are pretty stuck with this for now. + # + # Patches to make this work more nicely with Ruby 1.9 using runtime + # version checking and all are welcome, but they can't actually help if + # the results are not totally hidden away in here. + # + # Incidentally, we though about vendoring evil-ruby and actually adjusting + # the internal C structure implementation details under the hood to make + # this stuff work, because it would have been cleaner. Which gives you an + # idea how motivated we were to make this cleaner. Sorry. --daniel 2011-03-31 + + internal_name = "#{@name} implementation, required on Ruby 1.8".to_sym + file = __FILE__ + "+eval" + line = __LINE__ + 1 + wrapper = "def #{@name}(*args, &block) + args << {} unless args.last.is_a? Hash + args << block if block_given? + self.__send__(#{internal_name.inspect}, *args) + end" + + if @face.is_a?(Class) + @face.class_eval do eval wrapper, nil, file, line end + @face.define_method(internal_name, &block) + else + @face.instance_eval do eval wrapper, nil, file, line end + @face.meta_def(internal_name, &block) + end + end + + def add_option(option) + option.aliases.each do |name| + if conflict = get_option(name) then + raise ArgumentError, "Option #{option} conflicts with existing option #{conflict}" + elsif conflict = @face.get_option(name) then + raise ArgumentError, "Option #{option} conflicts with existing option #{conflict} on #{@face}" + end + end + + option.aliases.each do |name| + @options[name] = option + end + + option + end + + def option?(name) + @options.include? name.to_sym + end + + def options + (@options.keys + @face.options).sort + end + + def get_option(name) + @options[name.to_sym] || @face.get_option(name) + end +end diff --git a/lib/puppet/interface/action_builder.rb b/lib/puppet/interface/action_builder.rb new file mode 100644 index 000000000..34bb3fa44 --- /dev/null +++ b/lib/puppet/interface/action_builder.rb @@ -0,0 +1,35 @@ +require 'puppet/interface' +require 'puppet/interface/action' + +class Puppet::Interface::ActionBuilder + attr_reader :action + + def self.build(face, name, &block) + raise "Action #{name.inspect} must specify a block" unless block + new(face, name, &block).action + end + + private + def initialize(face, name, &block) + @face = face + @action = Puppet::Interface::Action.new(face, name) + instance_eval(&block) + end + + # Ideally the method we're defining here would be added to the action, and a + # method on the face would defer to it, but we can't get scope correct, so + # we stick with this. --daniel 2011-03-24 + def when_invoked(&block) + raise "when_invoked on an ActionBuilder with no corresponding Action" unless @action + @action.when_invoked = block + end + + def option(*declaration, &block) + option = Puppet::Interface::OptionBuilder.build(@action, *declaration, &block) + @action.add_option(option) + end + + def summary(text) + @action.summary = text + end +end diff --git a/lib/puppet/interface/action_manager.rb b/lib/puppet/interface/action_manager.rb new file mode 100644 index 000000000..d75697afa --- /dev/null +++ b/lib/puppet/interface/action_manager.rb @@ -0,0 +1,56 @@ +require 'puppet/interface/action_builder' + +module Puppet::Interface::ActionManager + # Declare that this app can take a specific action, and provide + # the code to do so. + def action(name, &block) + @actions ||= {} + raise "Action #{name} already defined for #{self}" if action?(name) + action = Puppet::Interface::ActionBuilder.build(self, name, &block) + @actions[action.name] = action + end + + # This is the short-form of an action definition; it doesn't use the + # builder, just creates the action directly from the block. + def script(name, &block) + @actions ||= {} + raise "Action #{name} already defined for #{self}" if action?(name) + @actions[name] = Puppet::Interface::Action.new(self, name, :when_invoked => block) + end + + def actions + @actions ||= {} + result = @actions.keys + + if self.is_a?(Class) and superclass.respond_to?(:actions) + result += superclass.actions + elsif self.class.respond_to?(:actions) + result += self.class.actions + end + result.sort + end + + def get_action(name) + @actions ||= {} + result = @actions[name.to_sym] + if result.nil? + if self.is_a?(Class) and superclass.respond_to?(:get_action) + found = superclass.get_action(name) + elsif self.class.respond_to?(:get_action) + found = self.class.get_action(name) + end + + if found then + # This is not the nicest way to make action equivalent to the Ruby + # Method object, rather than UnboundMethod, but it will do for now, + # and we only have to make this change in *one* place. --daniel 2011-04-12 + result = @actions[name.to_sym] = found.__dup_and_rebind_to(self) + end + end + return result + end + + def action?(name) + actions.include?(name.to_sym) + end +end diff --git a/lib/puppet/interface/face_collection.rb b/lib/puppet/interface/face_collection.rb new file mode 100644 index 000000000..591471d4b --- /dev/null +++ b/lib/puppet/interface/face_collection.rb @@ -0,0 +1,131 @@ +# -*- coding: utf-8 -*- +require 'puppet/interface' + +module Puppet::Interface::FaceCollection + SEMVER_VERSION = /^(\d+)\.(\d+)\.(\d+)([A-Za-z][0-9A-Za-z-]*|)$/ + + @faces = Hash.new { |hash, key| hash[key] = {} } + + def self.faces + unless @loaded + @loaded = true + $LOAD_PATH.each do |dir| + next unless FileTest.directory?(dir) + Dir.chdir(dir) do + Dir.glob("puppet/face/*.rb").collect { |f| f.sub(/\.rb/, '') }.each do |file| + iname = file.sub(/\.rb/, '') + begin + require iname + rescue Exception => detail + puts detail.backtrace if Puppet[:trace] + raise "Could not load #{iname} from #{dir}/#{file}: #{detail}" + end + end + end + end + end + return @faces.keys + end + + def self.validate_version(version) + !!(SEMVER_VERSION =~ version.to_s) + end + + def self.cmp_semver(a, b) + a, b = [a, b].map do |x| + parts = SEMVER_VERSION.match(x).to_a[1..4] + parts[0..2] = parts[0..2].map { |e| e.to_i } + parts + end + + cmp = a[0..2] <=> b[0..2] + if cmp == 0 + cmp = a[3] <=> b[3] + cmp = +1 if a[3].empty? && !b[3].empty? + cmp = -1 if b[3].empty? && !a[3].empty? + end + cmp + end + + def self.[](name, version) + @faces[underscorize(name)][version] if face?(name, version) + end + + def self.face?(name, version) + name = underscorize(name) + + # Note: be careful not to accidentally create the top level key, either, + # because it will result in confusion when people try to enumerate the + # list of valid faces later. --daniel 2011-04-11 + return true if @faces.has_key?(name) and @faces[name].has_key?(version) + + # We always load the current version file; the common case is that we have + # the expected version and any compatibility versions in the same file, + # the default. Which means that this is almost always the case. + # + # We use require to avoid executing the code multiple times, like any + # other Ruby library that we might want to use. --daniel 2011-04-06 + begin + require "puppet/face/#{name}" + + # If we wanted :current, we need to index to find that; direct version + # requests just work™ as they go. --daniel 2011-04-06 + if version == :current then + # We need to find current out of this. This is the largest version + # number that doesn't have a dedicated on-disk file present; those + # represent "experimental" versions of faces, which we don't fully + # support yet. + # + # We walk the versions from highest to lowest and take the first version + # that is not defined in an explicitly versioned file on disk as the + # current version. + # + # This constrains us to only ship experimental versions with *one* + # version in the file, not multiple, but given you can't reliably load + # them except by side-effect when you ignore that rule this seems safe + # enough... + # + # Given those constraints, and that we are not going to ship a versioned + # interface that is not :current in this release, we are going to leave + # these thoughts in place, and just punt on the actual versioning. + # + # When we upgrade the core to support multiple versions we can solve the + # problems then; as lazy as possible. + # + # We do support multiple versions in the same file, though, so we sort + # versions here and return the last item in that set. + # + # --daniel 2011-04-06 + latest_ver = @faces[name].keys.sort {|a, b| cmp_semver(a, b) }.last + @faces[name][:current] = @faces[name][latest_ver] + end + rescue LoadError => e + raise unless e.message =~ %r{-- puppet/face/#{name}$} + # ...guess we didn't find the file; return a much better problem. + end + + # Now, either we have the version in our set of faces, or we didn't find + # the version they were looking for. In the future we will support + # loading versioned stuff from some look-aside part of the Ruby load path, + # but we don't need that right now. + # + # So, this comment is a place-holder for that. --daniel 2011-04-06 + # + # Note: be careful not to accidentally create the top level key, either, + # because it will result in confusion when people try to enumerate the + # list of valid faces later. --daniel 2011-04-11 + return !! (@faces.has_key?(name) and @faces[name].has_key?(version)) + end + + def self.register(face) + @faces[underscorize(face.name)][face.version] = face + end + + def self.underscorize(name) + unless name.to_s =~ /^[-_a-z]+$/i then + raise ArgumentError, "#{name.inspect} (#{name.class}) is not a valid face name" + end + + name.to_s.downcase.split(/[-_]/).join('_').to_sym + end +end diff --git a/lib/puppet/interface/option.rb b/lib/puppet/interface/option.rb new file mode 100644 index 000000000..ccc2fbba7 --- /dev/null +++ b/lib/puppet/interface/option.rb @@ -0,0 +1,82 @@ +require 'puppet/interface' + +class Puppet::Interface::Option + attr_reader :parent + attr_reader :name + attr_reader :aliases + attr_reader :optparse + attr_accessor :desc + + def takes_argument? + !!@argument + end + def optional_argument? + !!@optional_argument + end + + def initialize(parent, *declaration, &block) + @parent = parent + @optparse = [] + + # Collect and sort the arguments in the declaration. + dups = {} + declaration.each do |item| + if item.is_a? String and item.to_s =~ /^-/ then + unless item =~ /^-[a-z]\b/ or item =~ /^--[^-]/ then + raise ArgumentError, "#{item.inspect}: long options need two dashes (--)" + end + @optparse << item + + # Duplicate checking... + name = optparse_to_name(item) + if dup = dups[name] then + raise ArgumentError, "#{item.inspect}: duplicates existing alias #{dup.inspect} in #{@parent}" + else + dups[name] = item + end + else + raise ArgumentError, "#{item.inspect} is not valid for an option argument" + end + end + + if @optparse.empty? then + raise ArgumentError, "No option declarations found while building" + end + + # Now, infer the name from the options; we prefer the first long option as + # the name, rather than just the first option. + @name = optparse_to_name(@optparse.find do |a| a =~ /^--/ end || @optparse.first) + @aliases = @optparse.map { |o| optparse_to_name(o) } + + # Do we take an argument? If so, are we consistent about it, because + # incoherence here makes our life super-difficult, and we can more easily + # relax this rule later if we find a valid use case for it. --daniel 2011-03-30 + @argument = @optparse.any? { |o| o =~ /[ =]/ } + if @argument and not @optparse.all? { |o| o =~ /[ =]/ } then + raise ArgumentError, "Option #{@name} is inconsistent about taking an argument" + end + + # Is our argument optional? The rules about consistency apply here, also, + # just like they do to taking arguments at all. --daniel 2011-03-30 + @optional_argument = @optparse.any? { |o| o.include? "[" } + if @optional_argument and not @optparse.all? { |o| o.include? "[" } then + raise ArgumentError, "Option #{@name} is inconsistent about the argument being optional" + end + end + + # to_s and optparse_to_name are roughly mirrored, because they are used to + # transform options to name symbols, and vice-versa. This isn't a full + # bidirectional transformation though. --daniel 2011-04-07 + def to_s + @name.to_s.tr('_', '-') + end + + def optparse_to_name(declaration) + unless found = declaration.match(/^-+(?:\[no-\])?([^ =]+)/) then + raise ArgumentError, "Can't find a name in the declaration #{declaration.inspect}" + end + name = found.captures.first.tr('-', '_') + raise "#{name.inspect} is an invalid option name" unless name.to_s =~ /^[a-z]\w*$/ + name.to_sym + end +end diff --git a/lib/puppet/interface/option_builder.rb b/lib/puppet/interface/option_builder.rb new file mode 100644 index 000000000..2240b3e4a --- /dev/null +++ b/lib/puppet/interface/option_builder.rb @@ -0,0 +1,25 @@ +require 'puppet/interface/option' + +class Puppet::Interface::OptionBuilder + attr_reader :option + + def self.build(face, *declaration, &block) + new(face, *declaration, &block).option + end + + private + def initialize(face, *declaration, &block) + @face = face + @option = Puppet::Interface::Option.new(face, *declaration) + block and instance_eval(&block) + @option + end + + # Metaprogram the simple DSL from the option class. + Puppet::Interface::Option.instance_methods.grep(/=$/).each do |setter| + next if setter =~ /^=/ # special case, darn it... + + dsl = setter.to_s.sub(/=$/, '') + define_method(dsl) do |value| @option.send(setter, value) end + end +end diff --git a/lib/puppet/interface/option_manager.rb b/lib/puppet/interface/option_manager.rb new file mode 100644 index 000000000..56df9760f --- /dev/null +++ b/lib/puppet/interface/option_manager.rb @@ -0,0 +1,56 @@ +require 'puppet/interface/option_builder' + +module Puppet::Interface::OptionManager + # Declare that this app can take a specific option, and provide + # the code to do so. + def option(*declaration, &block) + add_option Puppet::Interface::OptionBuilder.build(self, *declaration, &block) + end + + def add_option(option) + option.aliases.each do |name| + if conflict = get_option(name) then + raise ArgumentError, "Option #{option} conflicts with existing option #{conflict}" + end + + actions.each do |action| + action = get_action(action) + if conflict = action.get_option(name) then + raise ArgumentError, "Option #{option} conflicts with existing option #{conflict} on #{action}" + end + end + end + + option.aliases.each { |name| @options[name] = option } + option + end + + def options + @options ||= {} + result = @options.keys + + if self.is_a?(Class) and superclass.respond_to?(:options) + result += superclass.options + elsif self.class.respond_to?(:options) + result += self.class.options + end + result.sort + end + + def get_option(name) + @options ||= {} + result = @options[name.to_sym] + unless result then + if self.is_a?(Class) and superclass.respond_to?(:get_option) + result = superclass.get_option(name) + elsif self.class.respond_to?(:get_option) + result = self.class.get_option(name) + end + end + return result + end + + def option?(name) + options.include? name.to_sym + end +end diff --git a/lib/puppet/network/http/api/v1.rb b/lib/puppet/network/http/api/v1.rb index 5fe143979..61307f01e 100644 --- a/lib/puppet/network/http/api/v1.rb +++ b/lib/puppet/network/http/api/v1.rb @@ -8,6 +8,9 @@ module Puppet::Network::HTTP::API::V1 :plural => :search, :singular => :find }, + "POST" => { + :singular => :find, + }, "PUT" => { :singular => :save }, @@ -41,6 +44,11 @@ module Puppet::Network::HTTP::API::V1 "/#{request.environment.to_s}/#{indirection}/#{request.escaped_key}#{request.query_string}" end + def request_to_uri_and_body(request) + indirection = request.method == :search ? pluralize(request.indirection_name.to_s) : request.indirection_name.to_s + ["/#{request.environment.to_s}/#{indirection}/#{request.escaped_key}", request.query_string.sub(/^\?/,'')] + end + def indirection_method(http_method, indirection) raise ArgumentError, "No support for http method #{http_method}" unless METHOD_MAP[http_method] diff --git a/lib/puppet/network/http_server/mongrel.rb b/lib/puppet/network/http_server/mongrel.rb index 9bd949a08..ce0401ad2 100644 --- a/lib/puppet/network/http_server/mongrel.rb +++ b/lib/puppet/network/http_server/mongrel.rb @@ -4,26 +4,6 @@ # # Copyright (c) 2006 Manuel Holtgrewe, 2007 Luke Kanies # -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - # This file is based heavily on a file retrieved from # http://ttt.ggnore.net/2006/11/15/xmlrpc-with-mongrel-and-ruby-off-rails/ diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb index 77617e992..c8ebc9483 100644 --- a/lib/puppet/parser/ast/leaf.rb +++ b/lib/puppet/parser/ast/leaf.rb @@ -124,7 +124,7 @@ class Puppet::Parser::AST # not include syntactical constructs, like '$' and '{}'). def evaluate(scope) parsewrap do - if (var = scope.lookupvar(@value, false)) == :undefined + if (var = scope.lookupvar(@value, :file => file, :line => line)) == :undefined var = :undef end var @@ -141,7 +141,7 @@ class Puppet::Parser::AST def evaluate_container(scope) container = variable.respond_to?(:evaluate) ? variable.safeevaluate(scope) : variable - (container.is_a?(Hash) or container.is_a?(Array)) ? container : scope.lookupvar(container) + (container.is_a?(Hash) or container.is_a?(Array)) ? container : scope.lookupvar(container, :file => file, :line => line) end def evaluate_key(scope) diff --git a/lib/puppet/parser/ast/vardef.rb b/lib/puppet/parser/ast/vardef.rb index 6de1860c8..b766311dd 100644 --- a/lib/puppet/parser/ast/vardef.rb +++ b/lib/puppet/parser/ast/vardef.rb @@ -20,7 +20,7 @@ class Puppet::Parser::AST name = @name.safeevaluate(scope) parsewrap do - scope.setvar(name,value, :file => @file, :line => @line, :append => @append) + scope.setvar(name,value, :file => file, :line => line, :append => @append) end end end diff --git a/lib/puppet/parser/functions/extlookup.rb b/lib/puppet/parser/functions/extlookup.rb index bc55410b9..5fbf26cec 100644 --- a/lib/puppet/parser/functions/extlookup.rb +++ b/lib/puppet/parser/functions/extlookup.rb @@ -91,14 +91,9 @@ This is for back compatibility to interpolate variables with %. % interpolation raise Puppet::ParseError, ("extlookup(): wrong number of arguments (#{args.length}; must be <= 3)") if args.length > 3 - extlookup_datadir = lookupvar('extlookup_datadir') - extlookup_precedence = Array.new + extlookup_datadir = undef_as('',lookupvar('::extlookup_datadir')) - extlookup_precedence = lookupvar('extlookup_precedence').collect do |var| - var.gsub(/%\{(.+?)\}/) do |capture| - lookupvar($1) - end - end + extlookup_precedence = undef_as([],lookupvar('::extlookup_precedence')).collect { |var| var.gsub(/%\{(.+?)\}/) { lookupvar("::#{$1}") } } datafiles = Array.new diff --git a/lib/puppet/parser/functions/fqdn_rand.rb b/lib/puppet/parser/functions/fqdn_rand.rb index 91157a148..93ab98bcd 100644 --- a/lib/puppet/parser/functions/fqdn_rand.rb +++ b/lib/puppet/parser/functions/fqdn_rand.rb @@ -7,6 +7,6 @@ Puppet::Parser::Functions::newfunction(:fqdn_rand, :type => :rvalue, :doc => $random_number_seed = fqdn_rand(30,30)") do |args| require 'digest/md5' max = args.shift - srand(Digest::MD5.hexdigest([lookupvar('fqdn'),args].join(':')).hex) + srand(Digest::MD5.hexdigest([lookupvar('::fqdn'),args].join(':')).hex) rand(max).to_s end diff --git a/lib/puppet/parser/functions/sha1.rb b/lib/puppet/parser/functions/sha1.rb index 10cc55cfe..1e7d5abe4 100644 --- a/lib/puppet/parser/functions/sha1.rb +++ b/lib/puppet/parser/functions/sha1.rb @@ -1,5 +1,5 @@ Puppet::Parser::Functions::newfunction(:sha1, :type => :rvalue, :doc => "Returns a SHA1 hash value from a provided string.") do |args| - require 'sha1' + require 'digest/sha1' Digest::SHA1.hexdigest(args[0]) end diff --git a/lib/puppet/parser/grammar.ra b/lib/puppet/parser/grammar.ra index 8339c51b7..d2bd06e94 100644 --- a/lib/puppet/parser/grammar.ra +++ b/lib/puppet/parser/grammar.ra @@ -156,7 +156,7 @@ resourceoverride: resourceref LBRACE anyparams endcomma RBRACE { virtualresource: at resource { type = val[0] - if (type == :exported and ! Puppet[:storeconfigs]) and ! Puppet[:parseonly] + if (type == :exported and ! Puppet[:storeconfigs]) Puppet.warning addcontext("You cannot collect without storeconfigs being set") end @@ -188,7 +188,7 @@ collection: classref collectrhand LBRACE anyparams endcomma RBRACE { else args[:form] = val[1] end - if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] + if args[:form] == :exported and ! Puppet[:storeconfigs] Puppet.warning addcontext("You cannot collect exported resources without storeconfigs being set; the collection will be ignored") end args[:override] = val[3] @@ -208,7 +208,7 @@ collection: classref collectrhand LBRACE anyparams endcomma RBRACE { else args[:form] = val[1] end - if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] + if args[:form] == :exported and ! Puppet[:storeconfigs] Puppet.warning addcontext("You cannot collect exported resources without storeconfigs being set; the collection will be ignored") end result = ast AST::Collection, args diff --git a/lib/puppet/parser/parser.rb b/lib/puppet/parser/parser.rb index 300ddddd6..611398d14 100644 --- a/lib/puppet/parser/parser.rb +++ b/lib/puppet/parser/parser.rb @@ -1366,7 +1366,7 @@ module_eval(<<'.,.,', 'grammar.ra', 156) def _reduce_50(val, _values, result) type = val[0] - if (type == :exported and ! Puppet[:storeconfigs]) and ! Puppet[:parseonly] + if (type == :exported and ! Puppet[:storeconfigs]) Puppet.warning addcontext("You cannot collect without storeconfigs being set") end @@ -1411,7 +1411,7 @@ module_eval(<<'.,.,', 'grammar.ra', 178) else args[:form] = val[1] end - if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] + if args[:form] == :exported and ! Puppet[:storeconfigs] Puppet.warning addcontext("You cannot collect exported resources without storeconfigs being set; the collection will be ignored") end args[:override] = val[3] @@ -1436,7 +1436,7 @@ module_eval(<<'.,.,', 'grammar.ra', 197) else args[:form] = val[1] end - if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] + if args[:form] == :exported and ! Puppet[:storeconfigs] Puppet.warning addcontext("You cannot collect exported resources without storeconfigs being set; the collection will be ignored") end result = ast AST::Collection, args diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index c007d4dbe..ace01bb4b 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -241,7 +241,7 @@ class Puppet::Parser::Resource < Puppet::Resource def add_backward_compatible_relationship_param(name) # Skip metaparams for which we get no value. - return unless val = scope.lookupvar(name.to_s, false) and val != :undefined + return unless val = scope.lookupvar(name.to_s) and val != :undefined # The default case: just set the value set_parameter(name, val) and return unless @parameters[name] diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 24f1d01f7..8de9d60b1 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -18,10 +18,10 @@ class Puppet::Parser::Scope include Enumerable include Puppet::Util::Errors - attr_accessor :level, :source, :resource + attr_accessor :source, :resource attr_accessor :base, :keyword attr_accessor :top, :translated, :compiler - attr_accessor :parent + attr_accessor :parent, :dynamic attr_reader :namespaces # thin wrapper around an ephemeral @@ -104,11 +104,6 @@ class Puppet::Parser::Scope compiler.environment end - # Are we the top scope? - def topscope? - @level == 1 - end - def find_hostclass(name) known_resource_types.find_hostclass(namespaces, name) end @@ -215,45 +210,41 @@ class Puppet::Parser::Scope find_definition(name) || find_hostclass(name) end - def lookup_qualified_var(name, usestring) - parts = name.split(/::/) - shortname = parts.pop - klassname = parts.join("::") - klass = find_hostclass(klassname) - unless klass - warning "Could not look up qualified variable '#{name}'; class #{klassname} could not be found" - return usestring ? "" : :undefined - end - unless kscope = class_scope(klass) - warning "Could not look up qualified variable '#{name}'; class #{klassname} has not been evaluated" - return usestring ? "" : :undefined - end - kscope.lookupvar(shortname, usestring) + def undef_as(x,v) + (v == :undefined) ? x : (v == :undef) ? x : v end - private :lookup_qualified_var + def qualified_scope(classname) + raise "class #{classname} could not be found" unless klass = find_hostclass(classname) + raise "class #{classname} has not been evaluated" unless kscope = class_scope(klass) + kscope + end + + private :qualified_scope - # Look up a variable. The simplest value search we do. Default to returning - # an empty string for missing values, but support returning a constant. - def lookupvar(name, usestring = true) + # Look up a variable. The simplest value search we do. + def lookupvar(name, options = {}) table = ephemeral?(name) ? @ephemeral.last : @symtable # If the variable is qualified, then find the specified scope and look the variable up there instead. - if name =~ /::/ - return lookup_qualified_var(name, usestring) - end - # We can't use "if table[name]" here because the value might be false - if ephemeral_include?(name) or table.include?(name) - if usestring and table[name] == :undef - return "" - else - return table[name] + if name =~ /^(.*)::(.+)$/ + begin + qualified_scope($1).lookupvar($2,options) + rescue RuntimeError => e + location = (options[:file] && options[:line]) ? " at #{options[:file]}:#{options[:line]}" : '' + warning "Could not look up qualified variable '#{name}'; #{e.message}#{location}" + :undefined end - elsif self.parent - return parent.lookupvar(name, usestring) - elsif usestring - return "" + elsif ephemeral_include?(name) or table.include?(name) + # We can't use "if table[name]" here because the value might be false + if options[:dynamic] and self != compiler.topscope + location = (options[:file] && options[:line]) ? " at #{options[:file]}:#{options[:line]}" : '' + Puppet.deprecation_warning "Dynamic lookup of $#{name}#{location} will not be supported in future versions. Use a fully-qualified variable name or parameterized classes." + end + table[name] + elsif parent + parent.lookupvar(name,options.merge(:dynamic => (dynamic || options[:dynamic]))) else - return :undefined + :undefined end end @@ -323,8 +314,6 @@ class Puppet::Parser::Scope # to be reassigned. def setvar(name,value, options = {}) table = options[:ephemeral] ? @ephemeral.last : @symtable - #Puppet.debug "Setting %s to '%s' at level %s mode append %s" % - # [name.inspect,value,self.level, append] if table.include?(name) unless options[:append] error = Puppet::ParseError.new("Cannot reassign variable #{name}") @@ -340,7 +329,7 @@ class Puppet::Parser::Scope table[name] = value else # append case # lookup the value in the scope if it exists and insert the var - table[name] = lookupvar(name) + table[name] = undef_as('',lookupvar(name)) # concatenate if string, append if array, nothing for other types case value when Array @@ -354,65 +343,6 @@ class Puppet::Parser::Scope end end - # Return an interpolated string. - def strinterp(string, file = nil, line = nil) - # Most strings won't have variables in them. - ss = StringScanner.new(string) - out = "" - while not ss.eos? - if ss.scan(/^\$\{((\w*::)*\w+|[0-9]+)\}|^\$([0-9])|^\$((\w*::)*\w+)/) - # If it matches the backslash, then just retun the dollar sign. - if ss.matched == '\\$' - out << '$' - else # look the variable up - # make sure $0-$9 are lookupable only if ephemeral - var = ss[1] || ss[3] || ss[4] - if var and var =~ /^[0-9]+$/ and not ephemeral_include?(var) - next - end - out << lookupvar(var).to_s || "" - end - elsif ss.scan(/^\\(.)/) - # Puppet.debug("Got escape: pos:%d; m:%s" % [ss.pos, ss.matched]) - case ss[1] - when 'n' - out << "\n" - when 't' - out << "\t" - when 's' - out << " " - when '\\' - out << '\\' - when '$' - out << '$' - else - str = "Unrecognised escape sequence '#{ss.matched}'" - str += " in file #{file}" if file - str += " at line #{line}" if line - Puppet.warning str - out << ss.matched - end - elsif ss.scan(/^\$/) - out << '$' - elsif ss.scan(/^\\\n/) # an escaped carriage return - next - else - tmp = ss.scan(/[^\\$]+/) - # Puppet.debug("Got other: pos:%d; m:%s" % [ss.pos, tmp]) - unless tmp - error = Puppet::ParseError.new("Could not parse string #{string.inspect}") - {:file= => file, :line= => line}.each do |m,v| - error.send(m, v) if v - end - raise error - end - out << tmp - end - end - - out - end - # Return the tags associated with this scope. It's basically # just our parents' tags, plus our type. We don't cache this value # because our parent tags might change between calls. diff --git a/lib/puppet/parser/templatewrapper.rb b/lib/puppet/parser/templatewrapper.rb index 6864aa1a9..180a03dc9 100644 --- a/lib/puppet/parser/templatewrapper.rb +++ b/lib/puppet/parser/templatewrapper.rb @@ -18,13 +18,14 @@ class Puppet::Parser::TemplateWrapper @__scope__ end + def script_line + # find which line in the template (if any) we were called from + caller.find { |l| l =~ /#{file}:/ }.first[/:(\d+):/,1] + end + # Should return true if a variable is defined, false if it is not def has_variable?(name) - if scope.lookupvar(name.to_s, false) != :undefined - true - else - false - end + scope.lookupvar(name.to_s, :file => file, :line => script_line) != :undefined end # Allow templates to access the defined classes @@ -55,15 +56,13 @@ class Puppet::Parser::TemplateWrapper # the missing_method definition here until we declare the syntax finally # dead. def method_missing(name, *args) - # We have to tell lookupvar to return :undefined to us when - # appropriate; otherwise it converts to "". - value = scope.lookupvar(name.to_s, false) + value = scope.lookupvar(name.to_s,:file => file,:line => script_line) if value != :undefined return value else # Just throw an error immediately, instead of searching for # other missingmethod things or whatever. - raise Puppet::ParseError, "Could not find value for '#{name}'" + raise Puppet::ParseError.new("Could not find value for '#{name}'",@file,script_line) end end @@ -103,6 +102,7 @@ class Puppet::Parser::TemplateWrapper result = nil benchmark(:debug, "Interpolated template #{template_source}") do template = ERB.new(self.string, 0, "-") + template.filename = file result = template.result(binding) end diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb index 5488c6674..a16f54bd7 100644 --- a/lib/puppet/provider/augeas/augeas.rb +++ b/lib/puppet/provider/augeas/augeas.rb @@ -1,21 +1,17 @@ -#-- -# Copyright (C) 2008 Red Hat Inc. # -# This library 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. +# Copyright 2011 Bryan Kearney <bkearney@redhat.com> # -# 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 -# 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 General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# http://www.apache.org/licenses/LICENSE-2.0 # -# Author: Bryan Kearney <bkearney@redhat.com> +# 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. require 'augeas' if Puppet.features.augeas? require 'strscan' diff --git a/lib/puppet/provider/cron/crontab.rb b/lib/puppet/provider/cron/crontab.rb index 8a347b331..a554363c8 100755 --- a/lib/puppet/provider/cron/crontab.rb +++ b/lib/puppet/provider/cron/crontab.rb @@ -11,13 +11,7 @@ tab = case Facter.value(:operatingsystem) - Puppet::Type.type(:cron).provide( - :crontab, - :parent => Puppet::Provider::ParsedFile, - :default_target => ENV["USER"] || "root", - - :filetype => tab -) do +Puppet::Type.type(:cron).provide(:crontab, :parent => Puppet::Provider::ParsedFile, :default_target => ENV["USER"] || "root", :filetype => tab) do commands :crontab => "crontab" text_line :comment, :match => %r{^#}, :post_parse => proc { |record| diff --git a/lib/puppet/provider/group/directoryservice.rb b/lib/puppet/provider/group/directoryservice.rb index 97fee883d..e11284898 100644 --- a/lib/puppet/provider/group/directoryservice.rb +++ b/lib/puppet/provider/group/directoryservice.rb @@ -1,17 +1,3 @@ -# Created by Jeff McCune on 2007-07-22 -# Copyright (c) 2007. All rights reserved. -# -# 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 - require 'puppet/provider/nameservice/directoryservice' Puppet::Type.type(:group).provide :directoryservice, :parent => Puppet::Provider::NameService::DirectoryService do diff --git a/lib/puppet/provider/group/groupadd.rb b/lib/puppet/provider/group/groupadd.rb index 82ed4c0c7..bcc08d9f7 100644 --- a/lib/puppet/provider/group/groupadd.rb +++ b/lib/puppet/provider/group/groupadd.rb @@ -9,6 +9,8 @@ Puppet::Type.type(:group).provide :groupadd, :parent => Puppet::Provider::NameSe commands :add => "groupadd", :delete => "groupdel", :modify => "groupmod" + has_feature :system_groups + verify :gid, "GID must be an integer" do |value| value.is_a? Integer end @@ -21,6 +23,7 @@ Puppet::Type.type(:group).provide :groupadd, :parent => Puppet::Provider::NameSe end end cmd << "-o" if @resource.allowdupe? + cmd << "-r" if @resource.system? cmd << @resource[:name] cmd diff --git a/lib/puppet/provider/interface/base.rb b/lib/puppet/provider/interface/base.rb new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/lib/puppet/provider/interface/base.rb diff --git a/lib/puppet/provider/interface/cisco.rb b/lib/puppet/provider/interface/cisco.rb new file mode 100644 index 000000000..f3bd202e9 --- /dev/null +++ b/lib/puppet/provider/interface/cisco.rb @@ -0,0 +1,33 @@ +require 'puppet/util/network_device/cisco/device' +require 'puppet/provider/network_device' + +Puppet::Type.type(:interface).provide :cisco, :parent => Puppet::Provider::NetworkDevice do + + desc "Cisco switch/router provider for interface." + + mk_resource_methods + + def self.lookup(url, name) + interface = nil + network_gear = Puppet::Util::NetworkDevice::Cisco::Device.new(url) + network_gear.command do |ng| + interface = network_gear.interface(name) + end + interface + end + + def initialize(*args) + super + end + + def flush + device.command do |device| + device.new_interface(name).update(former_properties, properties) + end + super + end + + def device + @device ||= Puppet::Util::NetworkDevice::Cisco::Device.new(resource[:device_url]) + end +end diff --git a/lib/puppet/provider/mcx/mcxcontent.rb b/lib/puppet/provider/mcx/mcxcontent.rb index 3ad437b53..0c0061278 100644 --- a/lib/puppet/provider/mcx/mcxcontent.rb +++ b/lib/puppet/provider/mcx/mcxcontent.rb @@ -1,22 +1,3 @@ -#-- -# Copyright (C) 2008 Jeffrey J McCune. - -# 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. - -# 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 - -# Author: Jeff McCune <mccune.jeff@gmail.com> - require 'tempfile' Puppet::Type.type(:mcx).provide :mcxcontent, :parent => Puppet::Provider do diff --git a/lib/puppet/provider/nameservice/directoryservice.rb b/lib/puppet/provider/nameservice/directoryservice.rb index 2e3480985..c1139a679 100644 --- a/lib/puppet/provider/nameservice/directoryservice.rb +++ b/lib/puppet/provider/nameservice/directoryservice.rb @@ -1,17 +1,3 @@ -# Created by Jeff McCune on 2007-07-22 -# Copyright (c) 2007. All rights reserved. -# -# 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 - require 'puppet' require 'puppet/provider/nameservice' require 'facter/util/plist' diff --git a/lib/puppet/provider/network_device.rb b/lib/puppet/provider/network_device.rb new file mode 100644 index 000000000..58865fddc --- /dev/null +++ b/lib/puppet/provider/network_device.rb @@ -0,0 +1,59 @@ + +# This is the base class of all prefetched network device provider +class Puppet::Provider::NetworkDevice < Puppet::Provider + + def self.lookup(url, name) + raise "This provider doesn't implement the necessary lookup method" + end + + def self.prefetch(resources) + resources.each do |name, resource| + if result = lookup(resource[:device_url], name) + result[:ensure] = :present + resource.provider = new(result) + else + resource.provider = new(:ensure => :absent) + end + end + end + + def exists? + @property_hash[:ensure] != :absent + end + + def initialize(*args) + super + + # Make a duplicate, so that we have a copy for comparison + # at the end. + @properties = @property_hash.dup + end + + def create + @property_hash[:ensure] = :present + self.class.resource_type.validproperties.each do |property| + if val = resource.should(property) + @property_hash[property] = val + end + end + end + + def destroy + @property_hash[:ensure] = :absent + end + + def flush + @property_hash.clear + end + + def self.instances + end + + def former_properties + @properties.dup + end + + def properties + @property_hash.dup + end +end
\ No newline at end of file diff --git a/lib/puppet/provider/package/darwinport.rb b/lib/puppet/provider/package/darwinport.rb deleted file mode 100755 index c5f9ba28f..000000000 --- a/lib/puppet/provider/package/darwinport.rb +++ /dev/null @@ -1,86 +0,0 @@ -require 'puppet/provider/package' - -Puppet::Type.type(:package).provide :darwinport, :parent => Puppet::Provider::Package do - desc "Package management using DarwinPorts on OS X." - - confine :operatingsystem => :darwin - commands :port => "/opt/local/bin/port" - - def self.eachpkgashash - # list out all of the packages - open("| #{command(:port)} list installed") { |process| - regex = %r{(\S+)\s+@(\S+)\s+(\S+)} - fields = [:name, :ensure, :location] - hash = {} - - # now turn each returned line into a package object - process.each { |line| - hash.clear - - if match = regex.match(line) - fields.zip(match.captures) { |field,value| - hash[field] = value - } - - hash.delete :location - hash[:provider] = self.name - yield hash.dup - else - raise Puppet::DevError, - "Failed to match dpkg line #{line}" - end - } - } - end - - def self.instances - packages = [] - - eachpkgashash do |hash| - packages << new(hash) - end - - packages - end - - def install - should = @resource.should(:ensure) - - # Seems like you can always say 'upgrade' - output = port "upgrade", @resource[:name] - if output =~ /^Error: No port/ - raise Puppet::ExecutionFailure, "Could not find package #{@resource[:name]}" - end - end - - def query - version = nil - self.class.eachpkgashash do |hash| - return hash if hash[:name] == @resource[:name] - end - - nil - end - - def latest - info = port :search, "^#{@resource[:name]}$" - - if $CHILD_STATUS != 0 or info =~ /^Error/ - return nil - end - - ary = info.split(/\s+/) - version = ary[2].sub(/^@/, '') - - version - end - - def uninstall - port :uninstall, @resource[:name] - end - - def update - install - end -end - diff --git a/lib/puppet/provider/package/macports.rb b/lib/puppet/provider/package/macports.rb new file mode 100755 index 000000000..c43eb72f3 --- /dev/null +++ b/lib/puppet/provider/package/macports.rb @@ -0,0 +1,106 @@ +require 'puppet/provider/package' + +Puppet::Type.type(:package).provide :macports, :parent => Puppet::Provider::Package do + desc "Package management using MacPorts on OS X. + + Supports MacPorts versions and revisions, but not variants. + Variant preferences may be specified using the MacPorts variants.conf file + http://guide.macports.org/chunked/internals.configuration-files.html#internals.configuration-files.variants-conf + + When specifying a version in the Puppet DSL, only specify the version, not the revision + Revisions are only used internally for ensuring the latest version/revision of a port. + " + + confine :operatingsystem => :darwin + commands :port => "/opt/local/bin/port" + + has_feature :installable + has_feature :uninstallable + has_feature :upgradeable + has_feature :versionable + + + def self.parse_installed_query_line(line) + regex = /(\S+)\s+@(\S+)_(\S+)\s+\(active\)/ + fields = [:name, :ensure, :revision] + hash_from_line(line, regex, fields) + end + + def self.parse_info_query_line(line) + regex = /(\S+)\s+(\S+)/ + fields = [:version, :revision] + hash_from_line(line, regex, fields) + end + + def self.hash_from_line(line, regex, fields) + hash = {} + if match = regex.match(line) + fields.zip(match.captures) { |field, value| + hash[field] = value + } + hash[:provider] = self.name + return hash + end + nil + end + + def self.instances + packages = [] + port("-q", :installed).each do |line| + if hash = parse_installed_query_line(line) + packages << new(hash) + end + end + packages + end + + def install + should = @resource.should(:ensure) + if [:latest, :installed, :present].include?(should) + output = port("-q", :install, @resource[:name]) + else + output = port("-q", :install, @resource[:name], "@#{should}") + end + # MacPorts now correctly exits non-zero with appropriate errors in + # situations where a port cannot be found or installed. + end + + def query + return self.class.parse_installed_query_line(port("-q", :installed, @resource[:name])) + end + + def latest + # We need both the version and the revision to be confident + # we've got the latest revision of a specific version + # Note we're still not doing anything with variants here. + info_line = port("-q", :info, "--line", "--version", "--revision", @resource[:name]) + return nil if info_line == "" + + if newest = self.class.parse_info_query_line(info_line) + current = query + # We're doing some fiddling behind the scenes here to cope with updated revisions. + # If we're already at the latest version/revision, then just return the version + # so the current and desired values match. Otherwise return version and revision + # to trigger an upgrade to the latest revision. + if newest[:version] == current[:ensure] and newest[:revision] == current[:revision] + return current[:ensure] + else + return "#{newest[:version]}_#{newest[:revision]}" + end + end + nil + end + + def uninstall + port("-q", :uninstall, @resource[:name]) + end + + def update + if query[:name] == @resource[:name] # 'port upgrade' cannot install new ports + port("-q", :upgrade, @resource[:name]) + else + install + end + end +end + diff --git a/lib/puppet/provider/package/pkgdmg.rb b/lib/puppet/provider/package/pkgdmg.rb index 39e377d66..662d05c8f 100644 --- a/lib/puppet/provider/package/pkgdmg.rb +++ b/lib/puppet/provider/package/pkgdmg.rb @@ -1,21 +1,4 @@ # -# pkgdmg.rb -# -# Install Installer.app packages wrapped up inside a DMG image file. -# -# Copyright (C) 2007 Jeff McCune Jeff McCune <jeff@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 -# # Motivation: DMG files provide a true HFS file system # and are easier to manage and .pkg bundles. # diff --git a/lib/puppet/provider/user/directoryservice.rb b/lib/puppet/provider/user/directoryservice.rb index 4b62a6ae7..a2c561039 100644 --- a/lib/puppet/provider/user/directoryservice.rb +++ b/lib/puppet/provider/user/directoryservice.rb @@ -1,17 +1,3 @@ -# Created by Jeff McCune on 2007-07-22 -# Copyright (c) 2007. All rights reserved. -# -# 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 - require 'puppet/provider/nameservice/directoryservice' Puppet::Type.type(:user).provide :directoryservice, :parent => Puppet::Provider::NameService::DirectoryService do diff --git a/lib/puppet/provider/vlan/cisco.rb b/lib/puppet/provider/vlan/cisco.rb new file mode 100644 index 000000000..46e172c73 --- /dev/null +++ b/lib/puppet/provider/vlan/cisco.rb @@ -0,0 +1,34 @@ +require 'puppet/util/network_device/cisco/device' +require 'puppet/provider/network_device' + +Puppet::Type.type(:vlan).provide :cisco, :parent => Puppet::Provider::NetworkDevice do + + desc "Cisco switch/router provider for vlans." + + mk_resource_methods + + def self.lookup(url, id) + vlans = {} + device = Puppet::Util::NetworkDevice::Cisco::Device.new(url) + device.command do |d| + vlans = d.parse_vlans || {} + end + vlans[id] + end + + def initialize(*args) + super + end + + # Clear out the cached values. + def flush + device.command do |device| + device.update_vlan(resource[:name], former_properties, properties) + end + super + end + + def device + @device ||= Puppet::Util::NetworkDevice::Cisco::Device.new(resource[:device_url]) + end +end diff --git a/lib/puppet/rails/fact_name.rb b/lib/puppet/rails/fact_name.rb index 4273399e5..08301d9f0 100644 --- a/lib/puppet/rails/fact_name.rb +++ b/lib/puppet/rails/fact_name.rb @@ -1,3 +1,4 @@ +require 'puppet/rails' require 'puppet/rails/fact_value' class Puppet::Rails::FactName < ActiveRecord::Base diff --git a/lib/puppet/rails/inventory_node.rb b/lib/puppet/rails/inventory_node.rb index 52f8621a4..da7e61040 100644 --- a/lib/puppet/rails/inventory_node.rb +++ b/lib/puppet/rails/inventory_node.rb @@ -3,6 +3,11 @@ require 'puppet/rails/inventory_fact' class Puppet::Rails::InventoryNode < ::ActiveRecord::Base has_many :facts, :class_name => "Puppet::Rails::InventoryFact", :foreign_key => :node_id, :dependent => :delete_all + if Puppet::Util.activerecord_version >= 3.0 + # Prevents "DEPRECATION WARNING: Base.named_scope has been deprecated, please use Base.scope instead" + ActiveRecord::NamedScope::ClassMethods.module_eval { alias :named_scope :scope } + end + named_scope :has_fact_with_value, lambda { |name,value| { :conditions => ["inventory_facts.name = ? AND inventory_facts.value = ?", name, value], diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb index 48d8c1f48..f8d820b77 100644 --- a/lib/puppet/resource/type.rb +++ b/lib/puppet/resource/type.rb @@ -62,13 +62,11 @@ class Puppet::Resource::Type # Now evaluate the code associated with this class or definition. def evaluate_code(resource) - scope = resource.scope - if tmp = evaluate_parent_type(resource) - scope = tmp - end + static_parent = evaluate_parent_type(resource) + scope = static_parent || resource.scope - scope = subscope(scope, resource) unless resource.title == :main + scope = scope.newscope(:namespace => namespace, :source => self, :resource => resource, :dynamic => !static_parent) unless resource.title == :main scope.compiler.add_class(name) unless definition? set_resource_parameters(resource, scope) @@ -263,11 +261,6 @@ class Puppet::Resource::Type end - # Create a new subscope in which to evaluate our code. - def subscope(scope, resource) - scope.newscope :resource => resource, :namespace => self.namespace, :source => self - end - # Check whether a given argument is valid. def valid_parameter?(param) param = param.to_s diff --git a/lib/puppet/resource/type_collection.rb b/lib/puppet/resource/type_collection.rb index 9fe7cdd06..89b0a16ed 100644 --- a/lib/puppet/resource/type_collection.rb +++ b/lib/puppet/resource/type_collection.rb @@ -6,6 +6,7 @@ class Puppet::Resource::TypeCollection @hostclasses.clear @definitions.clear @nodes.clear + @watched_files.clear end def initialize(env) diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index 0533273d9..d7845fbc9 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -4,7 +4,7 @@ require 'puppet' require 'puppet/util/tagging' require 'puppet/application' -require 'sha1' +require 'digest/sha1' class Puppet::Transaction require 'puppet/transaction/event' @@ -255,13 +255,13 @@ class Puppet::Transaction # We want to monitor changes in the relationship graph of our # catalog but this is complicated by the fact that the catalog - # both is_a graph and has_a graph, by the fact that changes to + # both is_a graph and has_a graph, by the fact that changes to # the structure of the object can have adverse serialization # effects, by threading issues, by order-of-initialization issues, - # etc. + # etc. # # Since the proper lifetime/scope of the monitoring is a transaction - # and the transaction is already commiting a mild law-of-demeter + # and the transaction is already commiting a mild law-of-demeter # transgression, we cut the Gordian knot here by simply wrapping the # transaction's view of the resource graph to capture and maintain # the information we need. Nothing outside the transaction needs diff --git a/lib/puppet/transaction/event_manager.rb b/lib/puppet/transaction/event_manager.rb index a21bbf892..f5da870ed 100644 --- a/lib/puppet/transaction/event_manager.rb +++ b/lib/puppet/transaction/event_manager.rb @@ -49,7 +49,7 @@ class Puppet::Transaction::EventManager # since eval_generated children can't have direct relationships. received = (event.name != :restarted) relationship_graph.matching_edges(event, resource).each do |edge| - received ||= true unless edge.target.is_a?(Puppet::Type::Whit) + received ||= true unless edge.target.is_a?(Puppet::Type.type(:whit)) next unless method = edge.callback next unless edge.target.respond_to?(method) diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb index 16fee42ae..652b3874a 100644 --- a/lib/puppet/transaction/report.rb +++ b/lib/puppet/transaction/report.rb @@ -53,7 +53,13 @@ class Puppet::Transaction::Report end end + def prune_internal_data + resource_statuses.delete_if {|name,res| res.resource_type == 'Whit'} + end + def finalize_report + prune_internal_data + resource_metrics = add_metric(:resources, calculate_resource_metrics) add_metric(:time, calculate_time_metrics) change_metric = calculate_change_metric diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 5ecc430d4..c0e5d390b 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -1901,4 +1901,4 @@ end require 'puppet/provider' # Always load these types. -require 'puppet/type/component' +Puppet::Type.type(:component) diff --git a/lib/puppet/type/augeas.rb b/lib/puppet/type/augeas.rb index a8fb1f15f..f4d3c43e1 100644 --- a/lib/puppet/type/augeas.rb +++ b/lib/puppet/type/augeas.rb @@ -1,21 +1,17 @@ -#-- -# Copyright (C) 2008 Red Hat Inc. # -# This library 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. +# Copyright 2011 Bryan Kearney <bkearney@redhat.com> # -# 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 -# 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 General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# http://www.apache.org/licenses/LICENSE-2.0 # -# Author: Bryan Kearney <bkearney@redhat.com> +# 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. Puppet::Type.newtype(:augeas) do include Puppet::Util diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb index 4f6ea733c..5083ca556 100755 --- a/lib/puppet/type/cron.rb +++ b/lib/puppet/type/cron.rb @@ -395,7 +395,7 @@ Puppet::Type.newtype(:cron) do unless ret case name when :command - devfail "No command, somehow" + devfail "No command, somehow" unless @parameters[:ensure].value == :absent when :special # nothing else diff --git a/lib/puppet/type/file/source.rb b/lib/puppet/type/file/source.rb index d3b3a48eb..76c646baf 100755 --- a/lib/puppet/type/file/source.rb +++ b/lib/puppet/type/file/source.rb @@ -114,6 +114,7 @@ module Puppet param_name = (metadata_method == :checksum) ? :content : metadata_method next if metadata_method == :owner and !Puppet.features.root? next if metadata_method == :checksum and metadata.ftype == "directory" + next if metadata_method == :checksum and metadata.ftype == "link" and metadata.links == :manage if resource[param_name].nil? or resource[param_name] == :absent resource[param_name] = metadata.send(metadata_method) diff --git a/lib/puppet/type/group.rb b/lib/puppet/type/group.rb index 2573633f9..b534ef275 100755 --- a/lib/puppet/type/group.rb +++ b/lib/puppet/type/group.rb @@ -1,4 +1,3 @@ - require 'etc' require 'facter' require 'puppet/property/keyvalue' @@ -19,6 +18,9 @@ module Puppet feature :manages_aix_lam, "The provider can manage AIX Loadable Authentication Module (LAM) system." + feature :system_groups, + "The provider allows you to create system groups with lower GIDs." + ensurable do desc "Create or remove the group." @@ -112,7 +114,7 @@ module Puppet def membership :attribute_membership end - + def delimiter " " end @@ -132,5 +134,12 @@ module Puppet defaultto :minimum end + newparam(:system, :boolean => true) do + desc "Whether the group is a system group with lower GID." + + newvalues(:true, :false) + + defaultto false + end end end diff --git a/lib/puppet/type/interface.rb b/lib/puppet/type/interface.rb new file mode 100644 index 000000000..7560a0552 --- /dev/null +++ b/lib/puppet/type/interface.rb @@ -0,0 +1,107 @@ +# +# Manages an interface on a given router or switch +# + +require 'puppet/util/network_device/ipcalc' + +Puppet::Type.newtype(:interface) do + + @doc = "This represents a router or switch interface. It is possible to manage + interface mode (access or trunking, native vlan and encapsulation), + switchport characteristics (speed, duplex)." + + ensurable do + defaultvalues + + aliasvalue :shutdown, :absent + aliasvalue :no_shutdown, :present + + defaultto { :no_shutdown } + end + + newparam(:name) do + desc "Interface name" + end + + newparam(:device_url) do + desc "Url to connect to a router or switch." + end + + newproperty(:description) do + desc "Interface description." + + defaultto { @resource[:name] } + end + + newproperty(:speed) do + desc "Interface speed." + newvalues(:auto, /^\d+/) + end + + newproperty(:duplex) do + desc "Interface duplex." + newvalues(:auto, :full, :half) + end + + newproperty(:native_vlan) do + desc "Interface native vlan (for access mode only)." + newvalues(/^\d+/) + end + + newproperty(:encapsulation) do + desc "Interface switchport encapsulation." + newvalues(:none, :dot1q, :isl ) + end + + newproperty(:mode) do + desc "Interface switchport mode." + newvalues(:access, :trunk) + end + + newproperty(:allowed_trunk_vlans) do + desc "Allowed list of Vlans that this trunk can forward." + newvalues(:all, /./) + end + + newproperty(:etherchannel) do + desc "Channel group this interface is part of." + newvalues(/^\d+/) + end + + newproperty(:ipaddress, :array_matching => :all) do + include Puppet::Util::NetworkDevice::IPCalc + + desc "IP Address of this interface (it might not be possible to set an interface IP address + it depends on the interface type and device type). + Valid format of ip addresses are: + * IPV4, like 127.0.0.1 + * IPV4/prefixlength like 127.0.1.1/24 + * IPV6/prefixlength like FE80::21A:2FFF:FE30:ECF0/128 + * an optional suffix for IPV6 addresses from this list: eui-64, link-local + It is also possible to use an array of values. + " + + validate do |values| + values = [values] unless values.is_a?(Array) + values.each do |value| + self.fail "Invalid interface ip address" unless parse(value.gsub(/\s*(eui-64|link-local)\s*$/,'')) + end + end + + munge do |value| + option = value =~ /eui-64|link-local/i ? value.gsub(/^.*?\s*(eui-64|link-local)\s*$/,'\1') : nil + [parse(value.gsub(/\s*(eui-64|link-local)\s*$/,'')), option].flatten + end + + def value_to_s(value) + value = [value] unless value.is_a?(Array) + value.map{ |v| "#{v[1].to_s}/#{v[0]} #{v[2]}"}.join(",") + end + + def change_to_s(currentvalue, newvalue) + currentvalue = value_to_s(currentvalue) if currentvalue != :absent + newvalue = value_to_s(newvalue) + super(currentvalue, newvalue) + end + end +end diff --git a/lib/puppet/type/mcx.rb b/lib/puppet/type/mcx.rb index 07c9348dd..d0306ca46 100644 --- a/lib/puppet/type/mcx.rb +++ b/lib/puppet/type/mcx.rb @@ -1,22 +1,3 @@ -#-- -# Copyright (C) 2008 Jeffrey J McCune. - -# 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. - -# 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 - -# Author: Jeff McCune <mccune.jeff@gmail.com> - Puppet::Type.newtype(:mcx) do @doc = "MCX object management using DirectoryService on OS X. @@ -81,9 +62,9 @@ MCX settings refer to, the MCX resource will autorequire that user, group, or co newproperty(:content, :required_features => :manages_content) do desc "The XML Plist. The value of MCXSettings in DirectoryService. This is the standard output from the system command: - + dscl localhost -mcxexport /Local/Default/<ds_type>/ds_name - + Note that `ds_type` is capitalized and plural in the dscl command." end diff --git a/lib/puppet/type/router.rb b/lib/puppet/type/router.rb new file mode 100644 index 000000000..648389d39 --- /dev/null +++ b/lib/puppet/type/router.rb @@ -0,0 +1,14 @@ +# +# Manage a router abstraction +# + +module Puppet + newtype(:router) do + @doc = "Manages connected router." + + newparam(:url) do + desc "An URL to access the router of the form (ssh|telnet)://user:pass:enable@host/." + isnamevar + end + end +end diff --git a/lib/puppet/type/service.rb b/lib/puppet/type/service.rb index 3ef044932..5a2c69b87 100644 --- a/lib/puppet/type/service.rb +++ b/lib/puppet/type/service.rb @@ -8,19 +8,24 @@ module Puppet newtype(:service) do @doc = "Manage running services. Service support unfortunately varies - widely by platform -- some platforms have very little if any + widely by platform --- some platforms have very little if any concept of a running service, and some have a very codified and powerful concept. Puppet's service support will generally be able - to make up for any inherent shortcomings (e.g., if there is no + to do the right thing regardless (e.g., if there is no 'status' command, then Puppet will look in the process table for a command matching the service name), but the more information you - can provide the better behaviour you will get. Or, you can just - use a platform that has very good service support. + can provide, the better behaviour you will get. In particular, any + virtual services that don't have a predictable entry in the process table + (for example, `network` on Red Hat/CentOS systems) will manifest odd + behavior on restarts if you don't specify `hasstatus` or a `status` + command. Note that if a `service` receives an event from another resource, the service will get restarted. The actual command to restart the - service depends on the platform. You can provide a special command - for restarting with the `restart` attribute." + service depends on the platform. You can provide an explicit command + for restarting with the `restart` attribute, or use the init script's + restart command with the `hasrestart` attribute; if you do neither, + the service's stop and start commands will be used." feature :refreshable, "The provider can restart the service.", :methods => [:restart] @@ -93,11 +98,14 @@ module Puppet that a large number of init scripts on different platforms do not support any kind of status command; thus, you must specify manually whether the service you are running has such a - command (or you can specify a specific command using the - `status` parameter). - - If you do not specify anything, then the service name will be - looked for in the process table." + command. Alternately, you can provide a specific command using the + `status` attribute. + + If you specify neither of these, then Puppet will look for the + service name in the process table. Be aware that 'virtual' init + scripts such as networking will respond poorly to refresh events + (via notify and subscribe relationships) if you don't override + this default behavior." newvalues(:true, :false) diff --git a/lib/puppet/type/vlan.rb b/lib/puppet/type/vlan.rb new file mode 100644 index 000000000..6708ea4f5 --- /dev/null +++ b/lib/puppet/type/vlan.rb @@ -0,0 +1,24 @@ +# +# Manages a Vlan on a given router or switch +# + +Puppet::Type.newtype(:vlan) do + @doc = "This represents a router or switch vlan." + + ensurable + + newparam(:name) do + desc "Vlan id. It must be a number" + isnamevar + + newvalues(/^\d+/) + end + + newproperty(:description) do + desc "Vlan name" + end + + newparam(:device_url) do + desc "Url to connect to a router or switch." + end +end
\ No newline at end of file diff --git a/lib/puppet/util/command_line.rb b/lib/puppet/util/command_line.rb index 52b5f81ef..a884b8658 100644 --- a/lib/puppet/util/command_line.rb +++ b/lib/puppet/util/command_line.rb @@ -17,12 +17,12 @@ module Puppet 'master' => 'puppetmasterd' ) - def initialize( zero = $0, argv = ARGV, stdin = STDIN ) + def initialize(zero = $0, argv = ARGV, stdin = STDIN) @zero = zero @argv = argv.dup @stdin = stdin - @subcommand_name, @args = subcommand_and_args( @zero, @argv, @stdin ) + @subcommand_name, @args = subcommand_and_args(@zero, @argv, @stdin) Puppet::Plugins.on_commandline_initialization(:command_line_object => self) end @@ -33,19 +33,20 @@ module Puppet File.join('puppet', 'application') end - def available_subcommands - absolute_appdirs = $LOAD_PATH.collect do |x| + def self.available_subcommands + absolute_appdirs = $LOAD_PATH.collect do |x| File.join(x,'puppet','application') end.select{ |x| File.directory?(x) } absolute_appdirs.inject([]) do |commands, dir| commands + Dir[File.join(dir, '*.rb')].map{|fn| File.basename(fn, '.rb')} end.uniq end - - def usage_message - usage = "Usage: puppet command <space separated arguments>" - available = "Available commands are: #{available_subcommands.sort.join(', ')}" - [usage, available].join("\n") + # available_subcommands was previously an instance method, not a class + # method, and we have an unknown number of user-implemented applications + # that depend on that behaviour. Forwarding allows us to preserve a + # backward compatible API. --daniel 2011-04-11 + def available_subcommands + self.class.available_subcommands end def require_application(application) @@ -53,15 +54,24 @@ module Puppet end def execute - if subcommand_name.nil? - puts usage_message - elsif available_subcommands.include?(subcommand_name) #subcommand + if subcommand_name and available_subcommands.include?(subcommand_name) then require_application subcommand_name app = Puppet::Application.find(subcommand_name).new(self) Puppet::Plugins.on_application_initialization(:appliation_object => self) app.run + elsif execute_external_subcommand then + # Logically, we shouldn't get here, but we do, so whatever. We just + # return to the caller. How strange we are. --daniel 2011-04-11 else - abort "Error: Unknown command #{subcommand_name}.\n#{usage_message}" unless execute_external_subcommand + unless subcommand_name.nil? then + puts "Error: Unknown Puppet subcommand #{subcommand_name}.\n" + end + + # Doing this at the top of the file is natural, but causes puppet.rb + # to load too early, which causes things to break. This is a nasty + # thing, found in #7065. --daniel 2011-04-11 + require 'puppet/face' + puts Puppet::Face[:help, :current].help end end @@ -69,10 +79,10 @@ module Puppet external_command = "puppet-#{subcommand_name}" require 'puppet/util' - path_to_subcommand = Puppet::Util.which( external_command ) + path_to_subcommand = Puppet::Util.which(external_command) return false unless path_to_subcommand - system( path_to_subcommand, *args ) + system(path_to_subcommand, *args) true end @@ -82,7 +92,7 @@ module Puppet private - def subcommand_and_args( zero, argv, stdin ) + def subcommand_and_args(zero, argv, stdin) zero = File.basename(zero, '.rb') if zero == 'puppet' diff --git a/lib/puppet/util/logging.rb b/lib/puppet/util/logging.rb index bc52b17f0..4e76ae414 100644 --- a/lib/puppet/util/logging.rb +++ b/lib/puppet/util/logging.rb @@ -15,6 +15,17 @@ module Puppet::Util::Logging end end + def deprecation_warning(message) + $deprecation_warnings ||= Hash.new(0) + if $deprecation_warnings.length < 100 and ($deprecation_warnings[message] += 1) == 1 + warning message + end + end + + def clear_deprecation_warnings + $deprecation_warnings.clear if $deprecation_warnings + end + private def is_resource? diff --git a/lib/puppet/util/monkey_patches.rb b/lib/puppet/util/monkey_patches.rb index a93c66b07..10a268409 100644 --- a/lib/puppet/util/monkey_patches.rb +++ b/lib/puppet/util/monkey_patches.rb @@ -90,3 +90,17 @@ if RUBY_VERSION == '1.8.1' || RUBY_VERSION == '1.8.2' r } end + +class Array + # Ruby < 1.8.7 doesn't have this method but we use it in tests + def combination(num) + return [] if num < 0 || num > size + return [[]] if num == 0 + return map{|e| [e] } if num == 1 + tmp = self.dup + self[0, size - (num - 1)].inject([]) do |ret, e| + tmp.shift + ret += tmp.combination(num - 1).map{|a| a.unshift(e) } + end + end unless method_defined? :combination +end diff --git a/lib/puppet/util/network_device.rb b/lib/puppet/util/network_device.rb new file mode 100644 index 000000000..bca66016b --- /dev/null +++ b/lib/puppet/util/network_device.rb @@ -0,0 +1,2 @@ +module Puppet::Util::NetworkDevice +end
\ No newline at end of file diff --git a/lib/puppet/util/network_device/base.rb b/lib/puppet/util/network_device/base.rb new file mode 100644 index 000000000..ff96c8693 --- /dev/null +++ b/lib/puppet/util/network_device/base.rb @@ -0,0 +1,29 @@ +require 'puppet/util/autoload' +require 'uri' +require 'puppet/util/network_device/transport' +require 'puppet/util/network_device/transport/base' + +module Puppet::Util::NetworkDevice + class Base + + attr_accessor :url, :transport + + def initialize(url) + @url = URI.parse(url) + + @autoloader = Puppet::Util::Autoload.new( + self, + "puppet/util/network_device/transport", + :wrap => false + ) + + if @autoloader.load(@url.scheme) + @transport = Puppet::Util::NetworkDevice::Transport.const_get(@url.scheme.capitalize).new + @transport.host = @url.host + @transport.port = @url.port || case @url.scheme ; when "ssh" ; 22 ; when "telnet" ; 23 ; end + @transport.user = @url.user + @transport.password = @url.password + end + end + end +end
\ No newline at end of file diff --git a/lib/puppet/util/network_device/cisco.rb b/lib/puppet/util/network_device/cisco.rb new file mode 100644 index 000000000..c03a00104 --- /dev/null +++ b/lib/puppet/util/network_device/cisco.rb @@ -0,0 +1,4 @@ + +module Puppet::Util::NetworkDevice::Cisco + +end
\ No newline at end of file diff --git a/lib/puppet/util/network_device/cisco/device.rb b/lib/puppet/util/network_device/cisco/device.rb new file mode 100644 index 000000000..1f350991a --- /dev/null +++ b/lib/puppet/util/network_device/cisco/device.rb @@ -0,0 +1,246 @@ +require 'puppet' +require 'puppet/util' +require 'puppet/util/network_device/base' +require 'puppet/util/network_device/ipcalc' +require 'puppet/util/network_device/cisco/interface' +require 'ipaddr' + +class Puppet::Util::NetworkDevice::Cisco::Device < Puppet::Util::NetworkDevice::Base + + include Puppet::Util::NetworkDevice::IPCalc + + attr_accessor :enable_password + + def initialize(url, options = {}) + super(url) + @enable_password = options[:enable_password] || parse_enable(@url.query) + transport.default_prompt = /[#>]\s?\z/n + end + + def parse_enable(query) + return $1 if query =~ /enable=(.*)/ + end + + def command(cmd=nil) + Puppet.debug("command #{cmd}") + transport.connect + login + transport.command("terminal length 0") do |out| + enable if out =~ />\s?\z/n + end + find_capabilities + out = execute(cmd) if cmd + yield self if block_given? + transport.close + out + end + + def execute(cmd) + transport.command(cmd) + end + + def login + return if transport.handles_login? + if @url.user != '' + transport.command(@url.user, :prompt => /^Password:/) + else + transport.expect(/^Password:/) + end + transport.command(@url.password) + end + + def enable + raise "Can't issue \"enable\" to enter privileged, no enable password set" unless enable_password + transport.command("enable", :prompt => /^Password:/) + transport.command(enable_password) + end + + def support_vlan_brief? + !! @support_vlan_brief + end + + def find_capabilities + out = transport.command("sh vlan brief") + lines = out.split("\n") + lines.shift; lines.pop + + @support_vlan_brief = ! (lines.first =~ /^%/) + end + + IF={ + :FastEthernet => %w{FastEthernet FastEth Fast FE Fa F}, + :GigEthernet => %w{GigabitEthernet GigEthernet GigEth GE Gi G}, + :Ethernet => %w{Ethernet Eth E}, + :Serial => %w{Serial Se S}, + :PortChannel => %w{PortChannel Port-Channel Po}, + :POS => %w{POS P}, + :VLAN => %w{VLAN VL V}, + :Loopback => %w{Loopback Loop Lo}, + :ATM => %w{ATM AT A}, + :Dialer => %w{Dialer Dial Di D}, + :VirtualAccess => %w{Virtual-Access Virtual-A Virtual Virt} + } + + def canonalize_ifname(interface) + IF.each do |k,ifnames| + if found = ifnames.find { |ifname| interface =~ /^#{ifname}\s*\d/i } + interface =~ /^#{found}(.+)\b/i + return "#{k.to_s}#{$1}".gsub(/\s+/,'') + end + end + interface + end + + def interface(name) + ifname = canonalize_ifname(name) + interface = parse_interface(ifname) + return { :ensure => :absent } if interface.empty? + interface.merge!(parse_trunking(ifname)) + interface.merge!(parse_interface_config(ifname)) + end + + def new_interface(name) + Puppet::Util::NetworkDevice::Cisco::Interface.new(canonalize_ifname(name), transport) + end + + def parse_interface(name) + resource = {} + out = transport.command("sh interface #{name}") + lines = out.split("\n") + lines.shift; lines.pop + lines.each do |l| + if l =~ /#{name} is (.+), line protocol is / + resource[:ensure] = ($1 == 'up' ? :present : :absent); + end + if l =~ /Auto Speed \(.+\),/ or l =~ /Auto Speed ,/ or l =~ /Auto-speed/ + resource[:speed] = :auto + end + if l =~ /, (.+)Mb\/s/ + resource[:speed] = $1 + end + if l =~ /\s+Auto-duplex \((.{4})\),/ + resource[:duplex] = :auto + end + if l =~ /\s+(.+)-duplex/ + resource[:duplex] = $1 == "Auto" ? :auto : $1.downcase.to_sym + end + if l =~ /Description: (.+)/ + resource[:description] = $1 + end + end + resource + end + + def parse_interface_config(name) + resource = Hash.new { |hash, key| hash[key] = Array.new ; } + out = transport.command("sh running-config interface #{name} | begin interface") + lines = out.split("\n") + lines.shift; lines.pop + lines.each do |l| + if l =~ /ip address (#{IP}) (#{IP})\s+secondary\s*$/ + resource[:ipaddress] << [prefix_length(IPAddr.new($2)), IPAddr.new($1), 'secondary'] + end + if l =~ /ip address (#{IP}) (#{IP})\s*$/ + resource[:ipaddress] << [prefix_length(IPAddr.new($2)), IPAddr.new($1), nil] + end + if l =~ /ipv6 address (#{IP})\/(\d+) (eui-64|link-local)/ + resource[:ipaddress] << [$2.to_i, IPAddr.new($1), $3] + end + if l =~ /channel-group\s+(\d+)/ + resource[:etherchannel] = $1 + end + end + resource + end + + def parse_vlans + vlans = {} + out = transport.command(support_vlan_brief? ? "sh vlan brief" : "sh vlan-switch brief") + lines = out.split("\n") + lines.shift; lines.shift; lines.shift; lines.pop + vlan = nil + lines.each do |l| + case l + # vlan name status + when /^(\d+)\s+(\w+)\s+(\w+)\s+([a-zA-Z0-9,\/. ]+)\s*$/ + vlan = { :name => $1, :description => $2, :status => $3, :interfaces => [] } + if $4.strip.length > 0 + vlan[:interfaces] = $4.strip.split(/\s*,\s*/).map{ |ifn| canonalize_ifname(ifn) } + end + vlans[vlan[:name]] = vlan + when /^\s+([a-zA-Z0-9,\/. ]+)\s*$/ + raise "invalid sh vlan summary output" unless vlan + if $1.strip.length > 0 + vlan[:interfaces] += $1.strip.split(/\s*,\s*/).map{ |ifn| canonalize_ifname(ifn) } + end + else + end + end + vlans + end + + def update_vlan(id, is = {}, should = {}) + if should[:ensure] == :absent + Puppet.info "Removing #{id} from device vlan" + transport.command("conf t") + transport.command("no vlan #{id}") + transport.command("exit") + return + end + + # We're creating or updating an entry + transport.command("conf t") + transport.command("vlan #{id}") + [is.keys, should.keys].flatten.uniq.each do |property| + Puppet.debug("trying property: #{property}: #{should[property]}") + next if property != :description + transport.command("name #{should[property]}") + end + transport.command("exit") + transport.command("exit") + end + + def parse_trunking(interface) + trunking = {} + out = transport.command("sh interface #{interface} switchport") + lines = out.split("\n") + lines.shift; lines.pop + lines.each do |l| + case l + when /^Administrative mode:\s+(.*)$/i + case $1 + when "trunk" + trunking[:mode] = :trunk + when "static access" + trunking[:mode] = :access + else + raise "Unknown switchport mode: #{$1} for #{interface}" + end + when /^Administrative Trunking Encapsulation:\s+(.*)$/ + case $1 + when "dot1q","isl" + trunking[:encapsulation] = $1.to_sym if trunking[:mode] == :trunk + else + raise "Unknown switchport encapsulation: #{$1} for #{interface}" + end + when /^Access Mode VLAN:\s+(.*) \(\(Inactive\)\)$/ + # nothing + when /^Access Mode VLAN:\s+(.*) \(.*\)$/ + trunking[:native_vlan] = $1 if trunking[:mode] == :access + when /^Trunking VLANs Enabled:\s+(.*)$/ + next if trunking[:mode] == :access + vlans = $1 + trunking[:allowed_trunk_vlans] = case vlans + when /all/i + :all + when /none/i + :none + else + vlans + end + end + end + trunking + end + +end diff --git a/lib/puppet/util/network_device/cisco/interface.rb b/lib/puppet/util/network_device/cisco/interface.rb new file mode 100644 index 000000000..63d5492a7 --- /dev/null +++ b/lib/puppet/util/network_device/cisco/interface.rb @@ -0,0 +1,82 @@ +require 'puppet/util/network_device/cisco' +require 'puppet/util/network_device/ipcalc' + +# this manages setting properties to an interface in a cisco switch or router +class Puppet::Util::NetworkDevice::Cisco::Interface + + include Puppet::Util::NetworkDevice::IPCalc + extend Puppet::Util::NetworkDevice::IPCalc + + attr_reader :transport, :name + + def initialize(name, transport) + @name = name + @transport = transport + end + + COMMANDS = { + # property => order, ios command/block/array + :description => [1, "description %s"], + :speed => [2, "speed %s"], + :duplex => [3, "duplex %s"], + :native_vlan => [4, "switchport access vlan %s"], + :encapsulation => [5, "switchport trunk encapsulation %s"], + :mode => [6, "switchport mode %s"], + :allowed_trunk_vlans => [7, "switchport trunk allowed vlan %s"], + :etherchannel => [8, ["channel-group %s", "port group %s"]], + :ipaddress => [9, + lambda do |prefix,ip,option| + ip.ipv6? ? "ipv6 address #{ip.to_s}/#{prefix} #{option}" : + "ip address #{ip.to_s} #{netmask(Socket::AF_INET,prefix)}" + end], + :ensure => [10, lambda { |value| value == :present ? "no shutdown" : "shutdown" } ] + } + + def update(is={}, should={}) + Puppet.debug("Updating interface #{name}") + command("conf t") + command("interface #{name}") + + # apply changes in a defined orders for cisco IOS devices + [is.keys, should.keys].flatten.uniq.sort {|a,b| COMMANDS[a][0] <=> COMMANDS[b][0] }.each do |property| + # They're equal, so do nothing. + next if is[property] == should[property] + + # We're deleting it + if should[property] == :absent or should[property].nil? + execute(property, is[property], "no ") + next + end + + # We're replacing an existing value or creating a new one + execute(property, should[property]) + end + + command("exit") + command("exit") + end + + def execute(property, value, prefix='') + case COMMANDS[property][1] + when Array + COMMANDS[property][1].each do |command| + transport.command(prefix + command % value) do |out| + break unless out =~ /^%/ + end + end + when String + command(prefix + COMMANDS[property][1] % value) + when Proc + value = [value] unless value.is_a?(Array) + value.each do |value| + command(prefix + COMMANDS[property][1].call(*value)) + end + end + end + + def command(command) + transport.command(command) do |out| + Puppet.err "Error while executing #{command}, device returned #{out}" if out =~ /^%/mo + end + end +end
\ No newline at end of file diff --git a/lib/puppet/util/network_device/ipcalc.rb b/lib/puppet/util/network_device/ipcalc.rb new file mode 100644 index 000000000..2b4f360b7 --- /dev/null +++ b/lib/puppet/util/network_device/ipcalc.rb @@ -0,0 +1,68 @@ + +require 'puppet/util/network_device' +module Puppet::Util::NetworkDevice::IPCalc + + # This is a rip-off of authstore + Octet = '(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])' + IPv4 = "#{Octet}\.#{Octet}\.#{Octet}\.#{Octet}" + IPv6_full = "_:_:_:_:_:_:_:_|_:_:_:_:_:_::_?|_:_:_:_:_::((_:)?_)?|_:_:_:_::((_:){0,2}_)?|_:_:_::((_:){0,3}_)?|_:_::((_:){0,4}_)?|_::((_:){0,5}_)?|::((_:){0,6}_)?" + IPv6_partial = "_:_:_:_:_:_:|_:_:_:_::(_:)?|_:_::(_:){0,2}|_::(_:){0,3}" + IP = "#{IPv4}|#{IPv6_full}".gsub(/_/,'([0-9a-fA-F]{1,4})').gsub(/\(/,'(?:') + + def parse(value) + case value + when /^(#{IP})\/(\d+)$/ # 12.34.56.78/24, a001:b002::efff/120, c444:1000:2000::9:192.168.0.1/112 + [$2.to_i,IPAddr.new($1)] + when /^(#{IP})$/ # 10.20.30.40, + value = IPAddr.new(value) + [bits(value.family),value] + end + end + + def bits(family) + family == Socket::AF_INET6 ? 128 : 32 + end + + def fullmask(family) + (1 << bits(family)) - 1 + end + + def mask(family, length) + (1 << (bits(family) - length)) - 1 + end + + # returns ip address netmask from prefix length + def netmask(family, length) + IPAddr.new(fullmask(family) & ~mask(family, length) , family) + end + + # returns an IOS wildmask + def wildmask(family, length) + IPAddr.new(mask(family, length) , family) + end + + # returns ip address prefix length from netmask + def prefix_length(netmask) + mask_addr = netmask.to_i + return 0 if mask_addr == 0 + length=32 + if (netmask.ipv6?) + length=128 + end + + mask = mask_addr < 2**length ? length : 128 + + mask.times do + if ((mask_addr & 1) == 1) + break + end + mask_addr = mask_addr >> 1 + mask = mask - 1 + end + mask + end + + def linklocal?(ip) + end + +end
\ No newline at end of file diff --git a/lib/puppet/util/network_device/transport.rb b/lib/puppet/util/network_device/transport.rb new file mode 100644 index 000000000..e64fe9b69 --- /dev/null +++ b/lib/puppet/util/network_device/transport.rb @@ -0,0 +1,5 @@ +# stub +module Puppet::Util::NetworkDevice + module Transport + end +end
\ No newline at end of file diff --git a/lib/puppet/util/network_device/transport/base.rb b/lib/puppet/util/network_device/transport/base.rb new file mode 100644 index 000000000..1d62209cb --- /dev/null +++ b/lib/puppet/util/network_device/transport/base.rb @@ -0,0 +1,26 @@ + +require 'puppet/util/network_device' +require 'puppet/util/network_device/transport' + +class Puppet::Util::NetworkDevice::Transport::Base + attr_accessor :user, :password, :host, :port + attr_accessor :default_prompt, :timeout + + def initialize + @timeout = 10 + end + + def send(cmd) + end + + def expect(prompt) + end + + def command(cmd, options = {}) + send(cmd) + expect(options[:prompt] || default_prompt) do |output| + yield output if block_given? + end + end + +end
\ No newline at end of file diff --git a/lib/puppet/util/network_device/transport/ssh.rb b/lib/puppet/util/network_device/transport/ssh.rb new file mode 100644 index 000000000..b3cf51b8a --- /dev/null +++ b/lib/puppet/util/network_device/transport/ssh.rb @@ -0,0 +1,115 @@ + +require 'puppet/util/network_device' +require 'puppet/util/network_device/transport' +require 'puppet/util/network_device/transport/base' +require 'net/ssh' + +# This is an adaptation/simplification of gem net-ssh-telnet, which aims to have +# a sane interface to Net::SSH. Credits goes to net-ssh-telnet authors +class Puppet::Util::NetworkDevice::Transport::Ssh < Puppet::Util::NetworkDevice::Transport::Base + + attr_accessor :buf, :ssh, :channel, :verbose + + def initialize + super + end + + def handles_login? + true + end + + def eof? + !! @eof + end + + def connect(&block) + @output = [] + @channel_data = "" + + begin + Puppet.debug("connecting to #{host} as #{user}") + @ssh = Net::SSH.start(host, user, :port => port, :password => password, :timeout => timeout) + rescue TimeoutError + raise TimeoutError, "timed out while opening an ssh connection to the host" + end + + @buf = "" + @eof = false + @channel = nil + @ssh.open_channel do |channel| + channel.request_pty { |ch,success| raise "failed to open pty" unless success } + + channel.send_channel_request("shell") do |ch, success| + raise "failed to open ssh shell channel" unless success + + ch.on_data { |ch,data| @buf << data } + ch.on_extended_data { |ch,type,data| @buf << data if type == 1 } + ch.on_close { @eof = true } + + @channel = ch + expect(default_prompt, &block) + # this is a little bit unorthodox, we're trying to escape + # the ssh loop there while still having the ssh connection up + # otherwise we wouldn't be able to return ssh stdout/stderr + # for a given call of command. + return + end + + end + @ssh.loop + + end + + def close + @channel.close if @channel + @channel = nil + @ssh.close if @ssh + end + + def expect(prompt) + line = '' + sock = @ssh.transport.socket + + while not @eof + break if line =~ prompt and @buf == '' + break if sock.closed? + + IO::select([sock], [sock], nil, nil) + + process_ssh + + # at this point we have accumulated some data in @buf + # or the channel has been closed + if @buf != "" + line += @buf.gsub(/\r\n/no, "\n") + @buf = '' + yield line if block_given? + elsif @eof + # channel has been closed + break if line =~ prompt + if line == '' + line = nil + yield nil if block_given? + end + break + end + end + Puppet.debug("ssh: expected #{line}") if @verbose + line + end + + def send(line) + Puppet.debug("ssh: send #{line}") if @verbose + @channel.send_data(line + "\n") + end + + def process_ssh + while @buf == "" and not eof? + begin + @channel.connection.process(0.1) + rescue IOError + @eof = true + end + end + end +end
\ No newline at end of file diff --git a/lib/puppet/util/network_device/transport/telnet.rb b/lib/puppet/util/network_device/transport/telnet.rb new file mode 100644 index 000000000..e55079e06 --- /dev/null +++ b/lib/puppet/util/network_device/transport/telnet.rb @@ -0,0 +1,42 @@ +require 'puppet/util/network_device' +require 'puppet/util/network_device/transport' +require 'puppet/util/network_device/transport/base' +require 'net/telnet' + +class Puppet::Util::NetworkDevice::Transport::Telnet < Puppet::Util::NetworkDevice::Transport::Base + def initialize + super + end + + def handles_login? + false + end + + def connect + @telnet = Net::Telnet::new("Host" => host, "Port" => port || 23, + "Timeout" => 10, + "Prompt" => default_prompt, "Output_log" => "/tmp/out.log") + end + + def close + @telnet.close if @telnet + @telnet = nil + end + + def expect(prompt) + @telnet.waitfor(prompt) do |out| + yield out if block_given? + end + end + + def command(cmd, options = {}) + send(cmd) + expect(options[:prompt] || default_prompt) do |output| + yield output if block_given? + end + end + + def send(line) + @telnet.puts(line) + end +end
\ No newline at end of file diff --git a/lib/puppet/util/selinux.rb b/lib/puppet/util/selinux.rb index 9d0e0a715..cec8a57d9 100644 --- a/lib/puppet/util/selinux.rb +++ b/lib/puppet/util/selinux.rb @@ -1,4 +1,4 @@ -# Provides utility functions to help interfaces Puppet to SELinux. +# Provides utility functions to help interface Puppet to SELinux. # # This requires the very new SELinux Ruby bindings. These bindings closely # mirror the SELinux C library interface. diff --git a/man/man5/puppet.conf.5 b/man/man5/puppet.conf.5 index f6c9926c3..930cec533 100644 --- a/man/man5/puppet.conf.5 +++ b/man/man5/puppet.conf.5 @@ -1,8 +1,8 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "PUPPETCONF" "5" "February 2011" "Puppet Labs, LLC" "Puppet manual" -\fBThis page is autogenerated; any changes will get overwritten\fR \fI(last generated on Thu Feb 17 09:56:34 \-0800 2011)\fR +.TH "PUPPETCONF" "5" "April 2011" "Puppet Labs, LLC" "Puppet manual" +\fBThis page is autogenerated; any changes will get overwritten\fR \fI(last generated on Wed Apr 13 14:24:43 \-0700 2011)\fR . .SH "Specifying Configuration Parameters" . @@ -117,7 +117,7 @@ Puppet can also create user and group accounts for itself (one \fBpuppet\fR grou . .nf -$ puppet agent \-\-mkusers +$ puppet master \-\-mkusers . .fi . @@ -132,6 +132,14 @@ Sending the \fBSIGUSR1\fR signal to an instance of \fBpuppet agent\fR will cause .SH "Configuration Parameter Reference" Below is a list of all documented parameters\. Not all of them are valid with all Puppet executables, but the executables will ignore any inappropriate values\. . +.SS "allow_duplicate_certs" +Whether to allow a new certificate request to overwrite an existing certificate\. +. +.IP "\(bu" 4 +\fIDefault\fR: false +. +.IP "" 0 +. .SS "archive_file_server" During an inspect run, the file bucket server to archive files to if archive_files is set\. . @@ -340,7 +348,7 @@ Whether certificate revocation should be supported by downloading a Certificate The name to use when handling certificates\. Defaults to the fully qualified domain name\. . .IP "\(bu" 4 -\fIDefault\fR: magpie\.puppetlabs\.lan +\fIDefault\fR: nick\-lewiss\-macbook\-pro\.local . .IP "" 0 . @@ -522,6 +530,14 @@ Which arguments to pass to the diff command when printing differences between fi . .IP "" 0 . +.SS "document_all" +Document all resources +. +.IP "\(bu" 4 +\fIDefault\fR: false +. +.IP "" 0 +. .SS "downcasefacts" Whether facts should be made all lowercase when sent to the server\. . @@ -1067,14 +1083,6 @@ Run the configuration once, rather than as a long\-running daemon\. This is usef . .IP "" 0 . -.SS "parseonly" -Just check the syntax of the manifests\. -. -.IP "\(bu" 4 -\fIDefault\fR: false -. -.IP "" 0 -. .SS "passfile" Where puppet agent stores the password for its private key\. Generally unused\. . @@ -1261,7 +1269,7 @@ The directory in which to store reports received from the client\. Each client g The \'from\' email address for the reports\. . .IP "\(bu" 4 -\fIDefault\fR: report@magpie\.puppetlabs\.lan +\fIDefault\fR: report@Nick\-Lewiss\-MacBook\-Pro\.local . .IP "" 0 . @@ -1313,6 +1321,14 @@ The configuration file that defines the rights to the different rest indirection . .IP "" 0 . +.SS "route_file" +The YAML file containing indirector route configuration\. +. +.IP "\(bu" 4 +\fIDefault\fR: $confdir/routes\.yaml +. +.IP "" 0 +. .SS "rrddir" The directory where RRD database files are stored\. Directories for each reporting host will be created under this directory\. . @@ -1589,4 +1605,4 @@ Boolean; whether to use the zlib library .IP "" 0 . .P -\fIThis page autogenerated on Thu Feb 17 09:56:34 \-0800 2011\fR +\fIThis page autogenerated on Wed Apr 13 14:24:43 \-0700 2011\fR diff --git a/spec/integration/application/apply_spec.rb b/spec/integration/application/apply_spec.rb index 876f55568..84acc28b2 100755 --- a/spec/integration/application/apply_spec.rb +++ b/spec/integration/application/apply_spec.rb @@ -1,9 +1,6 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') - +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet_spec/files' - require 'puppet/application/apply' describe "apply" do diff --git a/spec/integration/application/doc_spec.rb b/spec/integration/application/doc_spec.rb index f0b9d7db0..df9b91608 100644..100755 --- a/spec/integration/application/doc_spec.rb +++ b/spec/integration/application/doc_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet_spec/files' describe Puppet::Application::Doc do diff --git a/spec/integration/configurer_spec.rb b/spec/integration/configurer_spec.rb index 05b3d6146..f5d8bceb2 100755 --- a/spec/integration/configurer_spec.rb +++ b/spec/integration/configurer_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/configurer' diff --git a/spec/integration/defaults_spec.rb b/spec/integration/defaults_spec.rb index ee0a43d07..8aa59288e 100755 --- a/spec/integration/defaults_spec.rb +++ b/spec/integration/defaults_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/defaults' require 'puppet/rails' diff --git a/spec/integration/file_serving/content_spec.rb b/spec/integration/file_serving/content_spec.rb index 207720d56..a95ddc520 100755 --- a/spec/integration/file_serving/content_spec.rb +++ b/spec/integration/file_serving/content_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-10-18. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/file_serving/content' require 'shared_behaviours/file_serving' diff --git a/spec/integration/file_serving/fileset_spec.rb b/spec/integration/file_serving/fileset_spec.rb index f607aa203..f4b869847 100755 --- a/spec/integration/file_serving/fileset_spec.rb +++ b/spec/integration/file_serving/fileset_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/file_serving/fileset' diff --git a/spec/integration/file_serving/metadata_spec.rb b/spec/integration/file_serving/metadata_spec.rb index 627369ff8..ba7d3311f 100755 --- a/spec/integration/file_serving/metadata_spec.rb +++ b/spec/integration/file_serving/metadata_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-10-18. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/file_serving/metadata' require 'shared_behaviours/file_serving' diff --git a/spec/integration/file_serving/terminus_helper_spec.rb b/spec/integration/file_serving/terminus_helper_spec.rb index 615b24c87..7500b1fc0 100755 --- a/spec/integration/file_serving/terminus_helper_spec.rb +++ b/spec/integration/file_serving/terminus_helper_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/file_serving/terminus_helper' diff --git a/spec/integration/indirector/catalog/compiler_spec.rb b/spec/integration/indirector/catalog/compiler_spec.rb index dafa1af7c..f51a3f24e 100755 --- a/spec/integration/indirector/catalog/compiler_spec.rb +++ b/spec/integration/indirector/catalog/compiler_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/resource/catalog' diff --git a/spec/integration/indirector/catalog/queue_spec.rb b/spec/integration/indirector/catalog/queue_spec.rb index 237e489f9..569f096bf 100755 --- a/spec/integration/indirector/catalog/queue_spec.rb +++ b/spec/integration/indirector/catalog/queue_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/resource/catalog' diff --git a/spec/integration/indirector/direct_file_server_spec.rb b/spec/integration/indirector/direct_file_server_spec.rb index 627733b09..e53b48d69 100755 --- a/spec/integration/indirector/direct_file_server_spec.rb +++ b/spec/integration/indirector/direct_file_server_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-10-19. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/indirector/file_content/file' diff --git a/spec/integration/indirector/file_content/file_server_spec.rb b/spec/integration/indirector/file_content/file_server_spec.rb index 9268ef067..88d2345d8 100755 --- a/spec/integration/indirector/file_content/file_server_spec.rb +++ b/spec/integration/indirector/file_content/file_server_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-10-18. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/indirector/file_content/file_server' require 'shared_behaviours/file_server_terminus' diff --git a/spec/integration/indirector/file_metadata/file_server_spec.rb b/spec/integration/indirector/file_metadata/file_server_spec.rb index 069e7af08..9e84134a6 100755 --- a/spec/integration/indirector/file_metadata/file_server_spec.rb +++ b/spec/integration/indirector/file_metadata/file_server_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-10-18. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/indirector/file_metadata/file_server' require 'shared_behaviours/file_server_terminus' diff --git a/spec/integration/indirector/node/ldap_spec.rb b/spec/integration/indirector/node/ldap_spec.rb index 3da6d0e73..7e53141dc 100755 --- a/spec/integration/indirector/node/ldap_spec.rb +++ b/spec/integration/indirector/node/ldap_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/node/ldap' diff --git a/spec/integration/network/client_spec.rb b/spec/integration/network/client_spec.rb index 07a491b1b..72174c75c 100755 --- a/spec/integration/network/client_spec.rb +++ b/spec/integration/network/client_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/network/client' diff --git a/spec/integration/network/formats_spec.rb b/spec/integration/network/formats_spec.rb index 8eb963e19..af505f267 100755 --- a/spec/integration/network/formats_spec.rb +++ b/spec/integration/network/formats_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/network/formats' diff --git a/spec/integration/network/handler_spec.rb b/spec/integration/network/handler_spec.rb index a3095c125..dc0837c13 100755 --- a/spec/integration/network/handler_spec.rb +++ b/spec/integration/network/handler_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/network/client' diff --git a/spec/integration/network/server/mongrel_spec.rb b/spec/integration/network/server/mongrel_spec.rb index aeaaad6ae..fd5903b9e 100755 --- a/spec/integration/network/server/mongrel_spec.rb +++ b/spec/integration/network/server/mongrel_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/network/server' require 'socket' diff --git a/spec/integration/network/server/webrick_spec.rb b/spec/integration/network/server/webrick_spec.rb index 0e1bb4580..81c35af4f 100755 --- a/spec/integration/network/server/webrick_spec.rb +++ b/spec/integration/network/server/webrick_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/network/server' require 'puppet/ssl/certificate_authority' require 'socket' diff --git a/spec/integration/node/environment_spec.rb b/spec/integration/node/environment_spec.rb index abf0108fa..25a14afd4 100755 --- a/spec/integration/node/environment_spec.rb +++ b/spec/integration/node/environment_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet_spec/files' diff --git a/spec/integration/node/facts_spec.rb b/spec/integration/node/facts_spec.rb index ee956a6b1..f54d7f9aa 100755 --- a/spec/integration/node/facts_spec.rb +++ b/spec/integration/node/facts_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-4-8. # Copyright (c) 2008. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' describe Puppet::Node::Facts do describe "when using the indirector" do diff --git a/spec/integration/node_spec.rb b/spec/integration/node_spec.rb index 4c8a2c2b1..e15ddfc1e 100755 --- a/spec/integration/node_spec.rb +++ b/spec/integration/node_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-9-23. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +require 'spec_helper' require 'puppet/node' diff --git a/spec/integration/parser/collector_spec.rb b/spec/integration/parser/collector_spec.rb index c72e605cf..c14fa4184 100755 --- a/spec/integration/parser/collector_spec.rb +++ b/spec/integration/parser/collector_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/parser/collector' diff --git a/spec/integration/parser/compiler_spec.rb b/spec/integration/parser/compiler_spec.rb index 097e8b03a..9f6aae907 100755 --- a/spec/integration/parser/compiler_spec.rb +++ b/spec/integration/parser/compiler_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::Compiler do before :each do diff --git a/spec/integration/parser/functions/require_spec.rb b/spec/integration/parser/functions/require_spec.rb index 737efcce8..aa15f92be 100755 --- a/spec/integration/parser/functions/require_spec.rb +++ b/spec/integration/parser/functions/require_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe "The require function" do before :each do diff --git a/spec/integration/parser/functions_spec.rb b/spec/integration/parser/functions_spec.rb index 504d1fe5e..6791987d7 100644..100755 --- a/spec/integration/parser/functions_spec.rb +++ b/spec/integration/parser/functions_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::Functions do before :each do @@ -18,4 +17,4 @@ describe Puppet::Parser::Functions do }.should_not raise_error threads.each { |t| t.join } end -end
\ No newline at end of file +end diff --git a/spec/integration/parser/parser_spec.rb b/spec/integration/parser/parser_spec.rb index b7dfcc3e0..65c9ee302 100755 --- a/spec/integration/parser/parser_spec.rb +++ b/spec/integration/parser/parser_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::Parser do module ParseMatcher diff --git a/spec/integration/parser/ruby_manifest_spec.rb b/spec/integration/parser/ruby_manifest_spec.rb index 110898206..7f3bb71e9 100644..100755 --- a/spec/integration/parser/ruby_manifest_spec.rb +++ b/spec/integration/parser/ruby_manifest_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'tempfile' require 'puppet_spec/files' diff --git a/spec/integration/provider/mailalias/aliases_spec.rb b/spec/integration/provider/mailalias/aliases_spec.rb index 19e430ba1..232704e61 100755 --- a/spec/integration/provider/mailalias/aliases_spec.rb +++ b/spec/integration/provider/mailalias/aliases_spec.rb @@ -1,5 +1,5 @@ -#!/usr/bin/env ruby -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'shared_behaviours/all_parsedfile_providers' provider_class = Puppet::Type.type(:mailalias).provider(:aliases) diff --git a/spec/integration/provider/mount_spec.rb b/spec/integration/provider/mount_spec.rb index d6f25fe1d..4af0dca4a 100644..100755 --- a/spec/integration/provider/mount_spec.rb +++ b/spec/integration/provider/mount_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../spec_helper' +require 'spec_helper' require 'puppet/file_bucket/dipper' @@ -56,7 +56,7 @@ describe "mount provider (integration)" do def check_fstab(expected_to_be_present) # Verify that the fake fstab has the expected data in it - fstab_contents = File.read(@fake_fstab).lines.map(&:chomp).reject { |x| x =~ /^#|^$/ } + fstab_contents = File.read(@fake_fstab).split("\n").reject { |x| x =~ /^#|^$/ } if expected_to_be_present fstab_contents.length().should == 1 device, rest_of_line = fstab_contents[0].split(/\t/,2) diff --git a/spec/integration/provider/package_spec.rb b/spec/integration/provider/package_spec.rb index cc03c57a7..2d75826e8 100755 --- a/spec/integration/provider/package_spec.rb +++ b/spec/integration/provider/package_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe "Package Provider" do Puppet::Type.type(:package).providers.each do |name| diff --git a/spec/integration/provider/service/init_spec.rb b/spec/integration/provider/service/init_spec.rb index c74ce29fe..ef7d98b4c 100755 --- a/spec/integration/provider/service/init_spec.rb +++ b/spec/integration/provider/service/init_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider = Puppet::Type.type(:service).provider(:init) diff --git a/spec/integration/reference/providers_spec.rb b/spec/integration/reference/providers_spec.rb index d6e19cb59..6d87ee02e 100755 --- a/spec/integration/reference/providers_spec.rb +++ b/spec/integration/reference/providers_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/reference' diff --git a/spec/integration/reports_spec.rb b/spec/integration/reports_spec.rb index a721d75d8..d5a08d28a 100755 --- a/spec/integration/reports_spec.rb +++ b/spec/integration/reports_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-10-12. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +require 'spec_helper' require 'puppet/reports' diff --git a/spec/integration/resource/catalog_spec.rb b/spec/integration/resource/catalog_spec.rb index 21162655e..41a475d98 100755 --- a/spec/integration/resource/catalog_spec.rb +++ b/spec/integration/resource/catalog_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-4-8. # Copyright (c) 2008. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' describe Puppet::Resource::Catalog do describe "when pson is available", :if => Puppet.features.pson? do diff --git a/spec/integration/resource/type_collection_spec.rb b/spec/integration/resource/type_collection_spec.rb index f6ba9c7af..6ea2e7fe7 100755 --- a/spec/integration/resource/type_collection_spec.rb +++ b/spec/integration/resource/type_collection_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet_spec/files' require 'puppet/resource/type_collection' diff --git a/spec/integration/ssl/certificate_authority_spec.rb b/spec/integration/ssl/certificate_authority_spec.rb index 17b56ea98..c5e145459 100755 --- a/spec/integration/ssl/certificate_authority_spec.rb +++ b/spec/integration/ssl/certificate_authority_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-4-17. # Copyright (c) 2008. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/ssl/certificate_authority' require 'tempfile' diff --git a/spec/integration/ssl/certificate_request_spec.rb b/spec/integration/ssl/certificate_request_spec.rb index f1040055b..688466c37 100755 --- a/spec/integration/ssl/certificate_request_spec.rb +++ b/spec/integration/ssl/certificate_request_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-4-17. # Copyright (c) 2008. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/ssl/certificate_request' require 'tempfile' diff --git a/spec/integration/ssl/certificate_revocation_list_spec.rb b/spec/integration/ssl/certificate_revocation_list_spec.rb index ddf7952f3..051a81569 100755 --- a/spec/integration/ssl/certificate_revocation_list_spec.rb +++ b/spec/integration/ssl/certificate_revocation_list_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-5-5. # Copyright (c) 2008. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/ssl/certificate_revocation_list' require 'tempfile' diff --git a/spec/integration/ssl/host_spec.rb b/spec/integration/ssl/host_spec.rb index 84160b019..e9c37c151 100755 --- a/spec/integration/ssl/host_spec.rb +++ b/spec/integration/ssl/host_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-4-17. # Copyright (c) 2008. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/ssl/host' require 'tempfile' diff --git a/spec/integration/transaction/report_spec.rb b/spec/integration/transaction/report_spec.rb index c38f31081..183d93f76 100755 --- a/spec/integration/transaction/report_spec.rb +++ b/spec/integration/transaction/report_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-4-8. # Copyright (c) 2008. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' describe Puppet::Transaction::Report do describe "when using the indirector" do diff --git a/spec/integration/transaction_spec.rb b/spec/integration/transaction_spec.rb index e608faa27..41a1ebac3 100755 --- a/spec/integration/transaction_spec.rb +++ b/spec/integration/transaction_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet_spec/files' require 'puppet/transaction' diff --git a/spec/integration/type/file_spec.rb b/spec/integration/type/file_spec.rb index 513b96e41..4bed8c6c1 100755 --- a/spec/integration/type/file_spec.rb +++ b/spec/integration/type/file_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet_spec/files' diff --git a/spec/integration/type/package_spec.rb b/spec/integration/type/package_spec.rb index 8e852f261..7d03cb9c0 100755 --- a/spec/integration/type/package_spec.rb +++ b/spec/integration/type/package_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Type.type(:package), "when choosing a default package provider" do before do diff --git a/spec/integration/type/tidy_spec.rb b/spec/integration/type/tidy_spec.rb index 084ebac6d..675aaf4cd 100755 --- a/spec/integration/type/tidy_spec.rb +++ b/spec/integration/type/tidy_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet_spec/files' require 'puppet/file_bucket/dipper' diff --git a/spec/integration/type_spec.rb b/spec/integration/type_spec.rb index 62f8fb7d2..4be01d558 100755 --- a/spec/integration/type_spec.rb +++ b/spec/integration/type_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/type' diff --git a/spec/integration/util/autoload_spec.rb b/spec/integration/util/autoload_spec.rb index f9b913502..92fc6554c 100755 --- a/spec/integration/util/autoload_spec.rb +++ b/spec/integration/util/autoload_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/autoload' require 'fileutils' diff --git a/spec/integration/util/feature_spec.rb b/spec/integration/util/feature_spec.rb index b038cf308..c3c13764d 100755 --- a/spec/integration/util/feature_spec.rb +++ b/spec/integration/util/feature_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/feature' require 'puppet_spec/files' diff --git a/spec/integration/util/file_locking_spec.rb b/spec/integration/util/file_locking_spec.rb index 1914fadf7..9e829df0e 100755 --- a/spec/integration/util/file_locking_spec.rb +++ b/spec/integration/util/file_locking_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/file_locking' diff --git a/spec/integration/util/rdoc/parser_spec.rb b/spec/integration/util/rdoc/parser_spec.rb index 9cb0c9e4a..ce316309b 100755 --- a/spec/integration/util/rdoc/parser_spec.rb +++ b/spec/integration/util/rdoc/parser_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/resource/type_collection' require 'puppet/util/rdoc/parser' diff --git a/spec/integration/util/settings_spec.rb b/spec/integration/util/settings_spec.rb index d3b5ec594..b05c63107 100755 --- a/spec/integration/util/settings_spec.rb +++ b/spec/integration/util/settings_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet_spec/files' diff --git a/spec/lib/puppet/face/basetest.rb b/spec/lib/puppet/face/basetest.rb new file mode 100755 index 000000000..00616f74f --- /dev/null +++ b/spec/lib/puppet/face/basetest.rb @@ -0,0 +1 @@ +Puppet::Face.define(:basetest, '0.0.1') diff --git a/spec/lib/puppet/face/huzzah.rb b/spec/lib/puppet/face/huzzah.rb new file mode 100755 index 000000000..3428c6816 --- /dev/null +++ b/spec/lib/puppet/face/huzzah.rb @@ -0,0 +1,5 @@ +require 'puppet/face' +Puppet::Face.define(:huzzah, '2.0.1') do + summary "life is a thing for celebration" + action :bar do "is where beer comes from" end +end diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb index 38c51a572..30fb4fc42 100644..100755 --- a/spec/lib/puppet_spec/files.rb +++ b/spec/lib/puppet_spec/files.rb @@ -3,41 +3,51 @@ require 'tempfile' # A support module for testing files. module PuppetSpec::Files + # This code exists only to support tests that run as root, pretty much. + # Once they have finally been eliminated this can all go... --daniel 2011-04-08 + if Puppet.features.posix? then + def self.in_tmp(path) + path =~ /^\/tmp/ or path =~ /^\/var\/folders/ + end + elsif Puppet.features.microsoft_windows? + def self.in_tmp(path) + tempdir = File.expand_path(File.join(Dir::LOCAL_APPDATA, "Temp")) + path =~ /^#{tempdir}/ + end + else + fail "Help! Can't find in_tmp for this platform" + end + def self.cleanup - if defined?($tmpfiles) - $tmpfiles.each do |file| - file = File.expand_path(file) - if Puppet.features.posix? and file !~ /^\/tmp/ and file !~ /^\/var\/folders/ - puts "Not deleting tmpfile #{file} outside of /tmp or /var/folders" - next - elsif Puppet.features.microsoft_windows? - tempdir = File.expand_path(File.join(Dir::LOCAL_APPDATA, "Temp")) - if file !~ /^#{tempdir}/ - puts "Not deleting tmpfile #{file} outside of #{tempdir}" - next - end - end - if FileTest.exist?(file) - system("chmod -R 755 '#{file}'") - system("rm -rf '#{file}'") - end + $global_tempfiles ||= [] + while path = $global_tempfiles.pop do + fail "Not deleting tmpfile #{path} outside regular tmpdir" unless in_tmp(path) + + begin + FileUtils.rm_r path, :secure => true + rescue Errno::ENOENT + # nothing to do end - $tmpfiles.clear end end def tmpfile(name) + # Generate a temporary file, just for the name... source = Tempfile.new(name) path = source.path source.close! - $tmpfiles ||= [] - $tmpfiles << path + + # ...record it for cleanup, + $global_tempfiles ||= [] + $global_tempfiles << File.expand_path(path) + + # ...and bam. path end def tmpdir(name) - file = tmpfile(name) - FileUtils.mkdir_p(file) - file + path = tmpfile(name) + FileUtils.mkdir_p(path) + path end end diff --git a/spec/lib/puppet_spec/fixtures.rb b/spec/lib/puppet_spec/fixtures.rb index 7f6bc2a8f..7f6bc2a8f 100644..100755 --- a/spec/lib/puppet_spec/fixtures.rb +++ b/spec/lib/puppet_spec/fixtures.rb diff --git a/spec/lib/puppet_spec/verbose.rb b/spec/lib/puppet_spec/verbose.rb index d9834f2d7..d9834f2d7 100644..100755 --- a/spec/lib/puppet_spec/verbose.rb +++ b/spec/lib/puppet_spec/verbose.rb diff --git a/spec/monkey_patches/alias_should_to_must.rb b/spec/monkey_patches/alias_should_to_must.rb index 1a1111799..1a1111799 100644..100755 --- a/spec/monkey_patches/alias_should_to_must.rb +++ b/spec/monkey_patches/alias_should_to_must.rb diff --git a/spec/monkey_patches/publicize_methods.rb b/spec/monkey_patches/publicize_methods.rb index b39e9c002..b39e9c002 100644..100755 --- a/spec/monkey_patches/publicize_methods.rb +++ b/spec/monkey_patches/publicize_methods.rb diff --git a/spec/shared_behaviours/all_parsedfile_providers.rb b/spec/shared_behaviours/all_parsedfile_providers.rb index 9cb199b5f..9cb199b5f 100644..100755 --- a/spec/shared_behaviours/all_parsedfile_providers.rb +++ b/spec/shared_behaviours/all_parsedfile_providers.rb diff --git a/spec/shared_behaviours/file_server_terminus.rb b/spec/shared_behaviours/file_server_terminus.rb index 94a044d2e..f59169382 100644..100755 --- a/spec/shared_behaviours/file_server_terminus.rb +++ b/spec/shared_behaviours/file_server_terminus.rb @@ -1,4 +1,4 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-10-18. # Copyright (c) 2007. All rights reserved. diff --git a/spec/shared_behaviours/file_serving.rb b/spec/shared_behaviours/file_serving.rb index 84173448a..3afab5b59 100644..100755 --- a/spec/shared_behaviours/file_serving.rb +++ b/spec/shared_behaviours/file_serving.rb @@ -1,4 +1,4 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-10-18. # Copyright (c) 2007. All rights reserved. diff --git a/spec/shared_behaviours/memory_terminus.rb b/spec/shared_behaviours/memory_terminus.rb index f9325a969..f9325a969 100644..100755 --- a/spec/shared_behaviours/memory_terminus.rb +++ b/spec/shared_behaviours/memory_terminus.rb diff --git a/spec/shared_behaviours/path_parameters.rb b/spec/shared_behaviours/path_parameters.rb index b5a907900..b5a907900 100644..100755 --- a/spec/shared_behaviours/path_parameters.rb +++ b/spec/shared_behaviours/path_parameters.rb diff --git a/spec/shared_behaviours/things_that_declare_options.rb b/spec/shared_behaviours/things_that_declare_options.rb new file mode 100755 index 000000000..ac358eacd --- /dev/null +++ b/spec/shared_behaviours/things_that_declare_options.rb @@ -0,0 +1,141 @@ +# encoding: UTF-8 +shared_examples_for "things that declare options" do + it "should support options without arguments" do + subject = add_options_to { option "--bar" } + subject.should be_option :bar + end + + it "should support options with an empty block" do + subject = add_options_to do + option "--foo" do + # this section deliberately left blank + end + end + subject.should be + subject.should be_option :foo + end + + { "--foo=" => :foo }.each do |input, option| + it "should accept #{name.inspect}" do + subject = add_options_to { option input } + subject.should be_option option + end + end + + it "should support option documentation" do + text = "Sturm und Drang (German pronunciation: [ˈʃtʊʁm ʊnt ˈdʁaŋ]) …" + + subject = add_options_to do + option "--foo" do + desc text + end + end + + subject.get_option(:foo).desc.should == text + end + + it "should list all the options" do + subject = add_options_to do + option "--foo" + option "--bar" + end + subject.options.should =~ [:foo, :bar] + end + + it "should detect conflicts in long options" do + expect { + add_options_to do + option "--foo" + option "--foo" + end + }.should raise_error ArgumentError, /Option foo conflicts with existing option foo/i + end + + it "should detect conflicts in short options" do + expect { + add_options_to do + option "-f" + option "-f" + end + }.should raise_error ArgumentError, /Option f conflicts with existing option f/ + end + + ["-f", "--foo"].each do |option| + ["", " FOO", "=FOO", " [FOO]", "=[FOO]"].each do |argument| + input = option + argument + it "should detect conflicts within a single option like #{input.inspect}" do + expect { + add_options_to do + option input, input + end + }.should raise_error ArgumentError, /duplicates existing alias/ + end + end + end + + + # Verify the range of interesting conflicts to check for ordering causing + # the behaviour to change, or anything exciting like that. + [ %w{--foo}, %w{-f}, %w{-f --foo}, %w{--baz -f}, + %w{-f --baz}, %w{-b --foo}, %w{--foo -b} + ].each do |conflict| + base = %w{--foo -f} + it "should detect conflicts between #{base.inspect} and #{conflict.inspect}" do + expect { + add_options_to do + option *base + option *conflict + end + }.should raise_error ArgumentError, /conflicts with existing option/ + end + end + + it "should fail if we are not consistent about taking an argument" do + expect { add_options_to do option "--foo=bar", "--bar" end }. + should raise_error ArgumentError, /inconsistent about taking an argument/ + end + + it "should accept optional arguments" do + subject = add_options_to do option "--foo=[baz]", "--bar=[baz]" end + [:foo, :bar].each do |name| + subject.should be_option name + end + end + + describe "#takes_argument?" do + it "should detect an argument being absent" do + subject = add_options_to do option "--foo" end + subject.get_option(:foo).should_not be_takes_argument + end + ["=FOO", " FOO", "=[FOO]", " [FOO]"].each do |input| + it "should detect an argument given #{input.inspect}" do + subject = add_options_to do option "--foo#{input}" end + subject.get_option(:foo).should be_takes_argument + end + end + end + + describe "#optional_argument?" do + it "should be false if no argument is present" do + option = add_options_to do option "--foo" end.get_option(:foo) + option.should_not be_takes_argument + option.should_not be_optional_argument + end + + ["=FOO", " FOO"].each do |input| + it "should be false if the argument is mandatory (like #{input.inspect})" do + option = add_options_to do option "--foo#{input}" end.get_option(:foo) + option.should be_takes_argument + option.should_not be_optional_argument + end + end + + ["=[FOO]", " [FOO]"].each do |input| + it "should be true if the argument is optional (like #{input.inspect})" do + option = add_options_to do option "--foo#{input}" end.get_option(:foo) + option.should be_takes_argument + option.should be_optional_argument + end + end + end +end diff --git a/spec/spec.opts b/spec/spec.opts index 91cd6427e..425f0edd3 100644 --- a/spec/spec.opts +++ b/spec/spec.opts @@ -1,6 +1,4 @@ --format s --colour ---loadby -mtime --backtrace diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 13470428e..1187c1caf 100644..100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,11 +1,5 @@ -unless defined?(SPEC_HELPER_IS_LOADED) -SPEC_HELPER_IS_LOADED = 1 - dir = File.expand_path(File.dirname(__FILE__)) - -$LOAD_PATH.unshift("#{dir}/") -$LOAD_PATH.unshift("#{dir}/lib") # a spec-specific test lib dir -$LOAD_PATH.unshift("#{dir}/../lib") +$LOAD_PATH.unshift File.join(dir, 'lib') # Don't want puppet getting the command line arguments for rake or autotest ARGV.clear @@ -13,6 +7,7 @@ ARGV.clear require 'puppet' require 'mocha' gem 'rspec', '>=2.0.0' +require 'rspec/expectations' # So everyone else doesn't have to include this base constant. module PuppetSpec @@ -20,6 +15,8 @@ module PuppetSpec end require 'pathname' +require 'tmpdir' + require 'lib/puppet_spec/verbose' require 'lib/puppet_spec/files' require 'lib/puppet_spec/fixtures' @@ -36,6 +33,8 @@ RSpec.configure do |config| config.mock_with :mocha config.before :each do + GC.disable + # these globals are set by Application $puppet_application_mode = nil $puppet_application_name = nil @@ -63,7 +62,13 @@ RSpec.configure do |config| @logs.clear Puppet::Util::Log.close_all + + GC.enable end end +RSpec::Matchers.define :have_matching_element do |expected| + match do |actual| + actual.any? { |item| item =~ expected } + end end diff --git a/spec/unit/agent/locker_spec.rb b/spec/unit/agent/locker_spec.rb index e7c8929c7..341859e3b 100755 --- a/spec/unit/agent/locker_spec.rb +++ b/spec/unit/agent/locker_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/agent' require 'puppet/agent/locker' diff --git a/spec/unit/agent_spec.rb b/spec/unit/agent_spec.rb index a3a54bf7d..bfa44f61c 100755 --- a/spec/unit/agent_spec.rb +++ b/spec/unit/agent_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-11-12. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +require 'spec_helper' require 'puppet/agent' class AgentTestClient diff --git a/spec/unit/application/agent_spec.rb b/spec/unit/application/agent_spec.rb index 804057868..03cf14429 100755 --- a/spec/unit/application/agent_spec.rb +++ b/spec/unit/application/agent_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/agent' require 'puppet/application/agent' diff --git a/spec/unit/application/apply_spec.rb b/spec/unit/application/apply_spec.rb index 0c6df2cf8..dca2a4156 100755 --- a/spec/unit/application/apply_spec.rb +++ b/spec/unit/application/apply_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/application/apply' require 'puppet/file_bucket/dipper' @@ -123,14 +122,6 @@ describe Puppet::Application::Apply do describe "when executing" do - it "should dispatch to parseonly if parseonly is set" do - @apply.stubs(:options).returns({}) - Puppet.stubs(:[]).with(:parseonly).returns(true) - - @apply.expects(:parseonly) - @apply.run_command - end - it "should dispatch to 'apply' if it was called with 'apply'" do @apply.options[:catalog] = "foo" @@ -138,48 +129,13 @@ describe Puppet::Application::Apply do @apply.run_command end - it "should dispatch to main if parseonly is not set" do + it "should dispatch to main otherwise" do @apply.stubs(:options).returns({}) - Puppet.stubs(:[]).with(:parseonly).returns(false) @apply.expects(:main) @apply.run_command end - describe "the parseonly command" do - before :each do - @environment = Puppet::Node::Environment.new("env") - Puppet.stubs(:[]).with(:environment).returns(@environment) - Puppet.stubs(:[]).with(:manifest).returns("site.pp") - Puppet.stubs(:err) - @apply.stubs(:exit) - @apply.options.stubs(:[]).with(:code).returns "some code" - end - - it "should use the environment to parse the file" do - @environment.stubs(:perform_initial_import) - @apply.parseonly - end - - it "should exit with exit code 0 if no error" do - @apply.expects(:exit).with(0) - @apply.parseonly - end - - it "should exit with exit code 1 if error" do - @environment.stubs(:perform_initial_import).raises(Puppet::ParseError) - @apply.expects(:exit).with(1) - @apply.parseonly - end - - it "should exit with exit code 1 if error, even if --noop is set" do - Puppet[:noop] = true - @environment.stubs(:perform_initial_import).raises(Puppet::ParseError) - @apply.expects(:exit).with(1) - @apply.parseonly - end - end - describe "the main command" do before :each do Puppet.stubs(:[]) diff --git a/spec/unit/application/cert_spec.rb b/spec/unit/application/cert_spec.rb index 4315bb8d8..a1b5eb19a 100755 --- a/spec/unit/application/cert_spec.rb +++ b/spec/unit/application/cert_spec.rb @@ -1,7 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') - +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/application/cert' describe Puppet::Application::Cert do @@ -189,16 +187,6 @@ describe Puppet::Application::Cert do @cert_app.ca = @ca end - it "should SystemExit after printing help message" do - # Make the help method silent for testing; this is a bit nasty, but we - # can't identify a cleaner method. Help welcome. --daniel 2011-02-22 - Puppet.features.stubs(:usage?).returns(false) - @cert_app.stubs(:puts) - - @cert_app.command_line.stubs(:args).returns([]) - expect { @cert_app.parse_options }.should raise_error SystemExit - end - %w{list revoke generate sign print verify fingerprint}.each do |cmd| short = cmd[0,1] [cmd, "--#{cmd}", "-#{short}"].each do |option| diff --git a/spec/unit/application/certificate_spec.rb b/spec/unit/application/certificate_spec.rb new file mode 100755 index 000000000..27d6ac81b --- /dev/null +++ b/spec/unit/application/certificate_spec.rb @@ -0,0 +1,20 @@ +require 'puppet/application/certificate' + +describe Puppet::Application::Certificate do + it "should have a 'ca-location' option" do + # REVISIT: This is delegated from the face, and we will have a test there, + # so is this actually a valuable test? --daniel 2011-04-07 + subject.command_line.stubs(:args).returns %w{list} + subject.preinit + subject.parse_options + subject.should respond_to(:handle_ca_location) + end + + it "should accept the ca-location option" do + subject.command_line.stubs(:args).returns %w{--ca-location local list} + subject.preinit + subject.parse_options + subject.setup + subject.arguments.should == [{ :ca_location => "local" }] + end +end diff --git a/spec/unit/application/config_spec.rb b/spec/unit/application/config_spec.rb new file mode 100755 index 000000000..dc2fb5717 --- /dev/null +++ b/spec/unit/application/config_spec.rb @@ -0,0 +1,9 @@ +#!/usr/bin/env rspec +require 'spec_helper' +require 'puppet/application/config' + +describe Puppet::Application::Config do + it "should be a subclass of Puppet::Application::FaceBase" do + Puppet::Application::Config.superclass.should equal(Puppet::Application::FaceBase) + end +end diff --git a/spec/unit/application/configurer_spec.rb b/spec/unit/application/configurer_spec.rb new file mode 100755 index 000000000..791a367ea --- /dev/null +++ b/spec/unit/application/configurer_spec.rb @@ -0,0 +1,32 @@ +#!/usr/bin/env rspec +require 'spec_helper' +require 'puppet/application/configurer' +require 'puppet/indirector/catalog/rest' +require 'puppet/indirector/report/rest' +require 'tempfile' + +describe "Puppet::Application::Configurer" do + it "should retrieve and apply a catalog and submit a report" do + pending "REVISIT: 2.7 changes broke this, and we want the merge published" + + dirname = Dir.mktmpdir("puppetdir") + Puppet[:vardir] = dirname + Puppet[:confdir] = dirname + Puppet[:certname] = "foo" + @catalog = Puppet::Resource::Catalog.new + @file = Puppet::Resource.new(:file, File.join(dirname, "tmp_dir_resource"), :parameters => {:ensure => :present}) + @catalog.add_resource(@file) + + @report = Puppet::Transaction::Report.new("apply") + Puppet::Transaction::Report.stubs(:new).returns(@report) + + Puppet::Resource::Catalog::Rest.any_instance.stubs(:find).returns(@catalog) + @report.expects(:save) + + Puppet::Util::Log.stubs(:newdestination) + + Puppet::Application::Configurer.new.run + + @report.status.should == "changed" + end +end diff --git a/spec/unit/application/describe_spec.rb b/spec/unit/application/describe_spec.rb index 47b98a17b..e79ac21b7 100755 --- a/spec/unit/application/describe_spec.rb +++ b/spec/unit/application/describe_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/application/describe' diff --git a/spec/unit/application/doc_spec.rb b/spec/unit/application/doc_spec.rb index f432184d3..66a833b9d 100755 --- a/spec/unit/application/doc_spec.rb +++ b/spec/unit/application/doc_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/application/doc' require 'puppet/util/reference' diff --git a/spec/unit/application/face_base_spec.rb b/spec/unit/application/face_base_spec.rb new file mode 100755 index 000000000..939712ef8 --- /dev/null +++ b/spec/unit/application/face_base_spec.rb @@ -0,0 +1,187 @@ +#!/usr/bin/env rspec +require 'spec_helper' +require 'puppet/application/face_base' +require 'tmpdir' + +class Puppet::Application::FaceBase::Basetest < Puppet::Application::FaceBase +end + +describe Puppet::Application::FaceBase do + before :all do + Puppet::Face.define(:basetest, '0.0.1') do + option("--[no-]boolean") + option("--mandatory MANDATORY") + option("--optional [OPTIONAL]") + + action :foo do + option("--action") + when_invoked { |*args| args.length } + end + end + end + + let :app do + app = Puppet::Application::FaceBase::Basetest.new + app.command_line.stubs(:subcommand_name).returns('subcommand') + Puppet::Util::Log.stubs(:newdestination) + app + end + + describe "#find_global_settings_argument" do + it "should not match --ca to --ca-location" do + option = mock('ca option', :optparse_args => ["--ca"]) + Puppet.settings.expects(:each).yields(:ca, option) + + app.find_global_settings_argument("--ca-location").should be_nil + end + end + + describe "#parse_options" do + before :each do + app.command_line.stubs(:args).returns %w{} + end + + describe "parsing the command line" do + context "with just an action" do + before :all do + # We have to stub Signal.trap to avoid a crazy mess where we take + # over signal handling and make it impossible to cancel the test + # suite run. + # + # It would be nice to fix this elsewhere, but it is actually hard to + # capture this in rspec 2.5 and all. :( --daniel 2011-04-08 + Signal.stubs(:trap) + app.command_line.stubs(:args).returns %w{foo} + app.preinit + app.parse_options + end + + it "should set the face based on the type" do + app.face.name.should == :basetest + end + + it "should set the format based on the face default" do + app.format.should == :pson + end + + it "should find the action" do + app.action.should be + app.action.name.should == :foo + end + end + + it "should fail if no action is given" do + expect { app.preinit; app.parse_options }. + to raise_error OptionParser::MissingArgument, /No action given/ + end + + it "should report a sensible error when options with = fail" do + app.command_line.stubs(:args).returns %w{--action=bar foo} + expect { app.preinit; app.parse_options }. + to raise_error OptionParser::InvalidOption, /invalid option: --action/ + end + + it "should fail if an action option is before the action" do + app.command_line.stubs(:args).returns %w{--action foo} + expect { app.preinit; app.parse_options }. + to raise_error OptionParser::InvalidOption, /invalid option: --action/ + end + + it "should fail if an unknown option is before the action" do + app.command_line.stubs(:args).returns %w{--bar foo} + expect { app.preinit; app.parse_options }. + to raise_error OptionParser::InvalidOption, /invalid option: --bar/ + end + + it "should fail if an unknown option is after the action" do + app.command_line.stubs(:args).returns %w{foo --bar} + expect { app.preinit; app.parse_options }. + to raise_error OptionParser::InvalidOption, /invalid option: --bar/ + end + + it "should accept --bar as an argument to a mandatory option after action" do + app.command_line.stubs(:args).returns %w{foo --mandatory --bar} + app.preinit + app.parse_options + app.action.name.should == :foo + app.options.should == { :mandatory => "--bar" } + end + + it "should accept --bar as an argument to a mandatory option before action" do + app.command_line.stubs(:args).returns %w{--mandatory --bar foo} + app.preinit + app.parse_options + app.action.name.should == :foo + app.options.should == { :mandatory => "--bar" } + end + + it "should not skip when --foo=bar is given" do + app.command_line.stubs(:args).returns %w{--mandatory=bar --bar foo} + expect { app.preinit; app.parse_options }. + to raise_error OptionParser::InvalidOption, /invalid option: --bar/ + end + + { "boolean options before" => %w{--trace foo}, + "boolean options after" => %w{foo --trace} + }.each do |name, args| + it "should accept global boolean settings #{name} the action" do + app.command_line.stubs(:args).returns args + app.preinit + app.parse_options + Puppet[:trace].should be_true + end + end + + { "before" => %w{--syslogfacility user1 foo}, + " after" => %w{foo --syslogfacility user1} + }.each do |name, args| + it "should accept global settings with arguments #{name} the action" do + app.command_line.stubs(:args).returns args + app.preinit + app.parse_options + Puppet[:syslogfacility].should == "user1" + end + end + end + end + + describe "#setup" do + it "should remove the action name from the arguments" do + app.command_line.stubs(:args).returns %w{--mandatory --bar foo} + app.preinit + app.parse_options + app.setup + app.arguments.should == [{ :mandatory => "--bar" }] + end + + it "should pass positional arguments" do + app.command_line.stubs(:args).returns %w{--mandatory --bar foo bar baz quux} + app.preinit + app.parse_options + app.setup + app.arguments.should == ['bar', 'baz', 'quux', { :mandatory => "--bar" }] + end + end + + describe "#main" do + before :each do + app.expects(:exit).with(0) + + app.face = Puppet::Face[:basetest, '0.0.1'] + app.action = app.face.get_action(:foo) + app.format = :pson + app.arguments = ["myname", "myarg"] + end + + it "should send the specified verb and name to the face" do + app.face.expects(:foo).with(*app.arguments) + app.main + end + + it "should use its render method to render any result" do + app.expects(:render).with(app.arguments.length + 1) + app.stubs(:puts) # meh. Don't print nil, thanks. --daniel 2011-04-12 + app.main + end + end +end diff --git a/spec/unit/application/faces_spec.rb b/spec/unit/application/faces_spec.rb new file mode 100755 index 000000000..cc159b6a5 --- /dev/null +++ b/spec/unit/application/faces_spec.rb @@ -0,0 +1,14 @@ +#!/usr/bin/env rspec +require 'spec_helper' +require 'puppet/application/faces' + +describe Puppet::Application::Faces do + it "should be an application" do + Puppet::Application::Faces.superclass.should equal(Puppet::Application) + end + + it "should always call 'list'" do + subject.expects(:list) + subject.main + end +end diff --git a/spec/unit/application/filebucket_spec.rb b/spec/unit/application/filebucket_spec.rb index 013e358d8..8ba86be9e 100644..100755 --- a/spec/unit/application/filebucket_spec.rb +++ b/spec/unit/application/filebucket_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/application/filebucket' require 'puppet/file_bucket/dipper' diff --git a/spec/unit/application/indirection_base_spec.rb b/spec/unit/application/indirection_base_spec.rb new file mode 100755 index 000000000..63ab11eed --- /dev/null +++ b/spec/unit/application/indirection_base_spec.rb @@ -0,0 +1,38 @@ +#!/usr/bin/env rspec +require 'spec_helper' +require 'puppet/application/indirection_base' +require 'puppet/face/indirector' + +######################################################################## +# Stub for testing; the names are critical, sadly. --daniel 2011-03-30 +class Puppet::Application::TestIndirection < Puppet::Application::IndirectionBase +end + +face = Puppet::Face::Indirector.define(:testindirection, '0.0.1') do +end +# REVISIT: This horror is required because we don't allow anything to be +# :current except for if it lives on, and is loaded from, disk. --daniel 2011-03-29 +face.instance_variable_set('@version', :current) +Puppet::Face.register(face) +######################################################################## + + +describe Puppet::Application::IndirectionBase do + subject { Puppet::Application::TestIndirection.new } + + it "should accept a terminus command line option" do + # It would be nice not to have to stub this, but whatever... writing an + # entire indirection stack would cause us more grief. --daniel 2011-03-31 + terminus = mock("test indirection terminus") + Puppet::Indirector::Indirection.expects(:instance). + with(:testindirection).twice.returns() + + subject.command_line. + instance_variable_set('@args', %w{--terminus foo save}) + + # Not a very nice thing. :( + $stderr.stubs(:puts) + + expect { subject.run }.should raise_error SystemExit + end +end diff --git a/spec/unit/application/inspect_spec.rb b/spec/unit/application/inspect_spec.rb index d334a87ee..fda61c6e4 100755 --- a/spec/unit/application/inspect_spec.rb +++ b/spec/unit/application/inspect_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.dirname(__FILE__) + '/../../spec_helper' +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/application/inspect' require 'puppet/resource/catalog' @@ -246,9 +245,9 @@ describe Puppet::Application::Inspect do @inspect.run_command @report.status.should == "failed" - @report.logs.select{|log| log.message =~ /Could not inspect/}.count.should == 1 - @report.resource_statuses.count.should == 1 - @report.resource_statuses['Stub_type[foo]'].events.count.should == 1 + @report.logs.select{|log| log.message =~ /Could not inspect/}.size.should == 1 + @report.resource_statuses.size.should == 1 + @report.resource_statuses['Stub_type[foo]'].events.size.should == 1 event = @report.resource_statuses['Stub_type[foo]'].events.first event.property.should == "content" @@ -265,7 +264,7 @@ describe Puppet::Application::Inspect do @inspect.run_command - @report.resource_statuses.count.should == 2 + @report.resource_statuses.size.should == 2 @report.resource_statuses.keys.should =~ ['Stub_type[foo]', 'Stub_type[bar]'] end end diff --git a/spec/unit/application/kick_spec.rb b/spec/unit/application/kick_spec.rb index ce0e0c7d0..29e4caea4 100755 --- a/spec/unit/application/kick_spec.rb +++ b/spec/unit/application/kick_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/application/kick' diff --git a/spec/unit/application/master_spec.rb b/spec/unit/application/master_spec.rb index 14478a61a..ea5d3f518 100644..100755 --- a/spec/unit/application/master_spec.rb +++ b/spec/unit/application/master_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/application/master' require 'puppet/daemon' @@ -35,10 +34,6 @@ describe Puppet::Application::Master do @master.should respond_to(:main) end - it "should declare a parseonly command" do - @master.should respond_to(:parseonly) - end - it "should declare a compile command" do @master.should respond_to(:compile) end @@ -233,55 +228,19 @@ describe Puppet::Application::Master do @master.preinit end - it "should dispatch to parseonly if parseonly is set" do - Puppet.stubs(:[]).with(:parseonly).returns(true) - @master.options[:node] = nil - - @master.expects(:parseonly) - @master.run_command - end - it "should dispatch to compile if called with --compile" do @master.options[:node] = "foo" @master.expects(:compile) @master.run_command end - it "should dispatch to main if parseonly is not set" do - Puppet.stubs(:[]).with(:parseonly).returns(false) + it "should dispatch to main otherwise" do @master.options[:node] = nil @master.expects(:main) @master.run_command end - - describe "the parseonly command" do - before :each do - @environment = Puppet::Node::Environment.new("env") - Puppet.stubs(:[]).with(:environment).returns(@environment) - Puppet.stubs(:[]).with(:manifest).returns("site.pp") - Puppet.stubs(:err) - @master.stubs(:exit) - end - - it "should use a Puppet Resource Type Collection to parse the file" do - @environment.expects(:perform_initial_import) - @master.parseonly - end - - it "should exit with exit code 0 if no error" do - @master.expects(:exit).with(0) - @master.parseonly - end - - it "should exit with exit code 1 if error" do - @environment.stubs(:perform_initial_import).raises(Puppet::ParseError) - @master.expects(:exit).with(1) - @master.parseonly - end - end - describe "the compile command" do before do Puppet.stubs(:[]).with(:environment) diff --git a/spec/unit/application/queue_spec.rb b/spec/unit/application/queue_spec.rb index bb485ac3c..87713ca97 100755 --- a/spec/unit/application/queue_spec.rb +++ b/spec/unit/application/queue_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/application/queue' require 'puppet/indirector/catalog/queue' diff --git a/spec/unit/application/resource_spec.rb b/spec/unit/application/resource_spec.rb index 3e3f8296b..673bd65d7 100755 --- a/spec/unit/application/resource_spec.rb +++ b/spec/unit/application/resource_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/application/resource' diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb index befc4f510..f46959092 100755 --- a/spec/unit/application_spec.rb +++ b/spec/unit/application_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/application' require 'puppet' @@ -12,6 +11,7 @@ describe Puppet::Application do @app = Class.new(Puppet::Application).new @appclass = @app.class + @app.stubs(:name).returns("test_app") # avoid actually trying to parse any settings Puppet.settings.stubs(:parse) end @@ -356,16 +356,6 @@ describe Puppet::Application do end end - - it "should exit if OptionParser raises an error" do - $stderr.stubs(:puts) - OptionParser.any_instance.stubs(:parse!).raises(OptionParser::ParseError.new("blah blah")) - - @app.expects(:exit) - - lambda { @app.parse_options }.should_not raise_error - end - end describe "when calling default setup" do @@ -396,6 +386,55 @@ describe Puppet::Application do end + describe "when configuring routes" do + include PuppetSpec::Files + + before :each do + Puppet::Node.indirection.reset_terminus_class + end + + after :each do + Puppet::Node.indirection.reset_terminus_class + end + + it "should use the routes specified for only the active application" do + Puppet[:route_file] = tmpfile('routes') + File.open(Puppet[:route_file], 'w') do |f| + f.print <<-ROUTES + test_app: + node: + terminus: exec + other_app: + node: + terminus: plain + catalog: + terminus: invalid + ROUTES + end + + @app.configure_indirector_routes + + Puppet::Node.indirection.terminus_class.should == 'exec' + end + + it "should not fail if the route file doesn't exist" do + Puppet[:route_file] = "/dev/null/non-existent" + + expect { @app.configure_indirector_routes }.should_not raise_error + end + + it "should raise an error if the routes file is invalid" do + Puppet[:route_file] = tmpfile('routes') + File.open(Puppet[:route_file], 'w') do |f| + f.print <<-ROUTES + invalid : : yaml + ROUTES + end + + expect { @app.configure_indirector_routes }.should raise_error + end + end + describe "when running" do before :each do diff --git a/spec/unit/configurer/downloader_spec.rb b/spec/unit/configurer/downloader_spec.rb index 266a96b03..17b285d53 100755 --- a/spec/unit/configurer/downloader_spec.rb +++ b/spec/unit/configurer/downloader_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/configurer/downloader' diff --git a/spec/unit/configurer/fact_handler_spec.rb b/spec/unit/configurer/fact_handler_spec.rb index 71645225f..70d9b17c0 100755 --- a/spec/unit/configurer/fact_handler_spec.rb +++ b/spec/unit/configurer/fact_handler_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/configurer' require 'puppet/configurer/fact_handler' diff --git a/spec/unit/configurer/plugin_handler_spec.rb b/spec/unit/configurer/plugin_handler_spec.rb index 04a479665..7d99960df 100755 --- a/spec/unit/configurer/plugin_handler_spec.rb +++ b/spec/unit/configurer/plugin_handler_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/configurer' require 'puppet/configurer/plugin_handler' diff --git a/spec/unit/configurer_spec.rb b/spec/unit/configurer_spec.rb index d21d86ecf..7b76c3221 100755 --- a/spec/unit/configurer_spec.rb +++ b/spec/unit/configurer_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-11-12. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +require 'spec_helper' require 'puppet/configurer' describe Puppet::Configurer do diff --git a/spec/unit/daemon_spec.rb b/spec/unit/daemon_spec.rb index 4de76b728..ed8dec2a3 100755 --- a/spec/unit/daemon_spec.rb +++ b/spec/unit/daemon_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/daemon' def without_warnings diff --git a/spec/unit/dsl/resource_api_spec.rb b/spec/unit/dsl/resource_api_spec.rb index 13aa6a437..559a43333 100755 --- a/spec/unit/dsl/resource_api_spec.rb +++ b/spec/unit/dsl/resource_api_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/dsl/resource_api' diff --git a/spec/unit/dsl/resource_type_api_spec.rb b/spec/unit/dsl/resource_type_api_spec.rb index 795ce2868..ea81f7da4 100755 --- a/spec/unit/dsl/resource_type_api_spec.rb +++ b/spec/unit/dsl/resource_type_api_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/dsl/resource_type_api' diff --git a/spec/unit/face/catalog_spec.rb b/spec/unit/face/catalog_spec.rb new file mode 100755 index 000000000..28c2aa9be --- /dev/null +++ b/spec/unit/face/catalog_spec.rb @@ -0,0 +1,4 @@ +require 'puppet/face' +describe Puppet::Face[:catalog, '0.0.1'] do + it "should actually have some testing..." +end diff --git a/spec/unit/face/certificate_request_spec.rb b/spec/unit/face/certificate_request_spec.rb new file mode 100755 index 000000000..a83a92df8 --- /dev/null +++ b/spec/unit/face/certificate_request_spec.rb @@ -0,0 +1,3 @@ +describe Puppet::Face[:certificate_request, '0.0.1'] do + it "should actually have some tests..." +end diff --git a/spec/unit/face/certificate_revocation_list_spec.rb b/spec/unit/face/certificate_revocation_list_spec.rb new file mode 100755 index 000000000..22c0fa2bf --- /dev/null +++ b/spec/unit/face/certificate_revocation_list_spec.rb @@ -0,0 +1,3 @@ +describe Puppet::Face[:certificate_revocation_list, '0.0.1'] do + it "should actually have some tests..." +end diff --git a/spec/unit/face/certificate_spec.rb b/spec/unit/face/certificate_spec.rb new file mode 100755 index 000000000..dbcc888ad --- /dev/null +++ b/spec/unit/face/certificate_spec.rb @@ -0,0 +1,14 @@ +require 'puppet/ssl/host' + +describe Puppet::Face[:certificate, '0.0.1'] do + it "should have a ca-location option" do + subject.should be_option :ca_location + end + + it "should set the ca location when invoked" do + pending "#6983: This is broken in the actual face..." + Puppet::SSL::Host.expects(:ca_location=).with(:foo) + Puppet::SSL::Host.indirection.expects(:save) + subject.sign :ca_location => :foo + end +end diff --git a/spec/unit/face/config_spec.rb b/spec/unit/face/config_spec.rb new file mode 100755 index 000000000..6004d700f --- /dev/null +++ b/spec/unit/face/config_spec.rb @@ -0,0 +1,23 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe Puppet::Face[:config, '0.0.1'] do + it "should use Settings#print_config_options when asked to print" do + Puppet.settings.stubs(:puts) + Puppet.settings.expects(:print_config_options) + subject.print + end + + it "should set 'configprint' to all desired values and call print_config_options when a specific value is provided" do + Puppet.settings.stubs(:puts) + Puppet.settings.expects(:print_config_options) + subject.print("libdir", "ssldir") + Puppet.settings[:configprint].should == "libdir,ssldir" + end + + it "should always return nil" do + Puppet.settings.stubs(:puts) + Puppet.settings.expects(:print_config_options) + subject.print("libdir").should be_nil + end +end diff --git a/spec/unit/face/configurer_spec.rb b/spec/unit/face/configurer_spec.rb new file mode 100755 index 000000000..56b45031f --- /dev/null +++ b/spec/unit/face/configurer_spec.rb @@ -0,0 +1,25 @@ +#!/usr/bin/env rspec +require 'spec_helper' +require 'puppet/indirector/catalog/rest' +require 'tempfile' + +describe Puppet::Face[:configurer, '0.0.1'] do + describe "#synchronize" do + it "should retrieve and apply a catalog and return a report" do + pending "REVISIT: 2.7 changes broke this, and we want the merge published" + + dirname = Dir.mktmpdir("puppetdir") + Puppet[:vardir] = dirname + Puppet[:confdir] = dirname + @catalog = Puppet::Resource::Catalog.new + @file = Puppet::Resource.new(:file, File.join(dirname, "tmp_dir_resource"), :parameters => {:ensure => :present}) + @catalog.add_resource(@file) + Puppet::Resource::Catalog::Rest.any_instance.stubs(:find).returns(@catalog) + + report = subject.synchronize("foo") + + report.kind.should == "apply" + report.status.should == "changed" + end + end +end diff --git a/spec/unit/face/facts_spec.rb b/spec/unit/face/facts_spec.rb new file mode 100755 index 000000000..e6411f836 --- /dev/null +++ b/spec/unit/face/facts_spec.rb @@ -0,0 +1,20 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe Puppet::Face[:facts, '0.0.1'] do + it "should define an 'upload' fact" do + subject.should be_action(:upload) + end + + it "should set its default format to :yaml" do + subject.default_format.should == :yaml + end + + describe "when uploading" do + it "should set the terminus_class to :facter" + + it "should set the cach_eclass to :rest" + + it "should find the current certname" + end +end diff --git a/spec/unit/face/file_spec.rb b/spec/unit/face/file_spec.rb new file mode 100755 index 000000000..97e8bcc08 --- /dev/null +++ b/spec/unit/face/file_spec.rb @@ -0,0 +1,3 @@ +describe Puppet::Face[:file, '0.0.1'] do + it "should actually have some tests..." +end diff --git a/spec/unit/face/help_spec.rb b/spec/unit/face/help_spec.rb new file mode 100755 index 000000000..e67f29e07 --- /dev/null +++ b/spec/unit/face/help_spec.rb @@ -0,0 +1,112 @@ +require 'spec_helper' +require 'puppet/face/help' + +describe Puppet::Face[:help, '0.0.1'] do + it "should have a help action" do + subject.should be_action :help + end + + it "should have a default action of help" do + pending "REVISIT: we don't support default actions yet" + end + + it "should accept a call with no arguments" do + expect { subject.help() }.should_not raise_error + end + + it "should accept a face name" do + expect { subject.help(:help) }.should_not raise_error + end + + it "should accept a face and action name" do + expect { subject.help(:help, :help) }.should_not raise_error + end + + it "should fail if more than a face and action are given" do + expect { subject.help(:help, :help, :for_the_love_of_god) }. + should raise_error ArgumentError + end + + it "should treat :current and 'current' identically" do + subject.help(:help, :version => :current).should == + subject.help(:help, :version => 'current') + end + + it "should complain when the request version of a face is missing" do + expect { subject.help(:huzzah, :bar, :version => '17.0.0') }. + should raise_error Puppet::Error + end + + it "should find a face by version" do + face = Puppet::Face[:huzzah, :current] + subject.help(:huzzah, :version => face.version). + should == subject.help(:huzzah, :version => :current) + end + + context "when listing subcommands" do + subject { Puppet::Face[:help, :current].help } + + # Check a precondition for the next block; if this fails you have + # something odd in your set of face, and we skip testing things that + # matter. --daniel 2011-04-10 + it "should have at least one face with a summary" do + Puppet::Face.faces.should be_any do |name| + Puppet::Face[name, :current].summary + end + end + + Puppet::Face.faces.each do |name| + face = Puppet::Face[name, :current] + summary = face.summary + + it { should =~ %r{ #{name} } } + it { should =~ %r{ #{name} +#{summary}} } if summary + end + + Puppet::Face[:help, :current].legacy_applications.each do |appname| + it { should =~ %r{ #{appname} } } + + summary = Puppet::Face[:help, :current].horribly_extract_summary_from(appname) + summary and it { should =~ %r{ #{summary}\b} } + end + end + + context "#legacy_applications" do + subject { Puppet::Face[:help, :current].legacy_applications } + + # If we don't, these tests are ... less than useful, because they assume + # it. When this breaks you should consider ditching the entire feature + # and tests, but if not work out how to fake one. --daniel 2011-04-11 + it { should have_at_least(1).item } + + # Meh. This is nasty, but we can't control the other list; the specific + # bug that caused these to be listed is annoyingly subtle and has a nasty + # fix, so better to have a "fail if you do something daft" trigger in + # place here, I think. --daniel 2011-04-11 + %w{face_base indirection_base}.each do |name| + it { should_not include name } + end + end + + context "help for legacy applications" do + subject { Puppet::Face[:help, :current] } + let :appname do subject.legacy_applications.first end + + # This test is purposely generic, so that as we eliminate legacy commands + # we don't get into a loop where we either test a face-based replacement + # and fail to notice breakage, or where we have to constantly rewrite this + # test and all. --daniel 2011-04-11 + it "should return the legacy help when given the subcommand" do + help = subject.help(appname) + help.should =~ /puppet-#{appname}/ + %w{SYNOPSIS USAGE DESCRIPTION OPTIONS COPYRIGHT}.each do |heading| + help.should =~ /^#{heading}$/ + end + end + + it "should fail when asked for an action on a legacy command" do + expect { subject.help(appname, :whatever) }. + to raise_error ArgumentError, /Legacy subcommands don't take actions/ + end + end +end diff --git a/spec/unit/face/indirector_spec.rb b/spec/unit/face/indirector_spec.rb new file mode 100755 index 000000000..bb06fcfe2 --- /dev/null +++ b/spec/unit/face/indirector_spec.rb @@ -0,0 +1,59 @@ +#!/usr/bin/env rspec +require 'spec_helper' +require 'puppet/face/indirector' + +describe Puppet::Face::Indirector do + subject do + instance = Puppet::Face::Indirector.new(:test, '0.0.1') + indirection = stub('indirection', + :name => :stub_indirection, + :reset_terminus_class => nil) + instance.stubs(:indirection).returns indirection + instance + end + + it "should be able to return a list of indirections" do + Puppet::Face::Indirector.indirections.should be_include("catalog") + end + + it "should be able to return a list of terminuses for a given indirection" do + Puppet::Face::Indirector.terminus_classes(:catalog).should be_include("compiler") + end + + describe "as an instance" do + it "should be able to determine its indirection" do + # Loading actions here an get, um, complicated + Puppet::Face.stubs(:load_actions) + Puppet::Face::Indirector.new(:catalog, '0.0.1').indirection.should equal(Puppet::Resource::Catalog.indirection) + end + end + + [:find, :search, :save, :destroy].each do |method| + it "should define a '#{method}' action" do + Puppet::Face::Indirector.should be_action(method) + end + + it "should call the indirection method with options when the '#{method}' action is invoked" do + subject.indirection.expects(method).with(:test, "myargs", {}) + subject.send(method, :test, "myargs") + end + it "should forward passed options" do + subject.indirection.expects(method).with(:test, "action", {'one'=>'1'}) + subject.send(method, :test, 'action', {'one'=>'1'}) + end + end + + it "should be able to override its indirection name" do + subject.set_indirection_name :foo + subject.indirection_name.should == :foo + end + + it "should be able to set its terminus class" do + subject.indirection.expects(:terminus_class=).with(:myterm) + subject.set_terminus(:myterm) + end + + it "should define a class-level 'info' action" do + Puppet::Face::Indirector.should be_action(:info) + end +end diff --git a/spec/unit/face/key_spec.rb b/spec/unit/face/key_spec.rb new file mode 100755 index 000000000..10d664790 --- /dev/null +++ b/spec/unit/face/key_spec.rb @@ -0,0 +1,3 @@ +describe Puppet::Face[:key, '0.0.1'] do + it "should actually have some tests..." +end diff --git a/spec/unit/face/node_spec.rb b/spec/unit/face/node_spec.rb new file mode 100755 index 000000000..90d258db9 --- /dev/null +++ b/spec/unit/face/node_spec.rb @@ -0,0 +1,8 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe Puppet::Face[:node, '0.0.1'] do + it "should set its default format to :yaml" do + subject.default_format.should == :yaml + end +end diff --git a/spec/unit/face/report_spec.rb b/spec/unit/face/report_spec.rb new file mode 100755 index 000000000..b1b28167e --- /dev/null +++ b/spec/unit/face/report_spec.rb @@ -0,0 +1,3 @@ +describe Puppet::Face[:report, '0.0.1'] do + it "should actually have some tests..." +end diff --git a/spec/unit/face/resource_spec.rb b/spec/unit/face/resource_spec.rb new file mode 100755 index 000000000..084e2a6a9 --- /dev/null +++ b/spec/unit/face/resource_spec.rb @@ -0,0 +1,3 @@ +describe Puppet::Face[:resource, '0.0.1'] do + it "should actually have some tests..." +end diff --git a/spec/unit/face/resource_type_spec.rb b/spec/unit/face/resource_type_spec.rb new file mode 100755 index 000000000..2adaedca1 --- /dev/null +++ b/spec/unit/face/resource_type_spec.rb @@ -0,0 +1,3 @@ +describe Puppet::Face[:resource_type, '0.0.1'] do + it "should actually have some tests..." +end diff --git a/spec/unit/face_spec.rb b/spec/unit/face_spec.rb new file mode 100755 index 000000000..b6c49d917 --- /dev/null +++ b/spec/unit/face_spec.rb @@ -0,0 +1 @@ +# You should look at interface_spec.rb diff --git a/spec/unit/file_bucket/dipper_spec.rb b/spec/unit/file_bucket/dipper_spec.rb index 4dabb722b..910b2808d 100755 --- a/spec/unit/file_bucket/dipper_spec.rb +++ b/spec/unit/file_bucket/dipper_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'pathname' diff --git a/spec/unit/file_bucket/file_spec.rb b/spec/unit/file_bucket/file_spec.rb index d79345736..c4444ae77 100644..100755 --- a/spec/unit/file_bucket/file_spec.rb +++ b/spec/unit/file_bucket/file_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require ::File.dirname(__FILE__) + '/../../spec_helper' +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/file_bucket/file' require 'digest/md5' diff --git a/spec/unit/file_collection/lookup_spec.rb b/spec/unit/file_collection/lookup_spec.rb index 138949a96..2b0f8bfab 100755 --- a/spec/unit/file_collection/lookup_spec.rb +++ b/spec/unit/file_collection/lookup_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/file_collection/lookup' class LookupTester diff --git a/spec/unit/file_collection_spec.rb b/spec/unit/file_collection_spec.rb index 09888f425..518763629 100755 --- a/spec/unit/file_collection_spec.rb +++ b/spec/unit/file_collection_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/file_collection' diff --git a/spec/unit/file_serving/base_spec.rb b/spec/unit/file_serving/base_spec.rb index 3449c8d0e..17d59460e 100755 --- a/spec/unit/file_serving/base_spec.rb +++ b/spec/unit/file_serving/base_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/file_serving/base' diff --git a/spec/unit/file_serving/configuration/parser_spec.rb b/spec/unit/file_serving/configuration/parser_spec.rb index 46cdc1c45..3d6b3e234 100755 --- a/spec/unit/file_serving/configuration/parser_spec.rb +++ b/spec/unit/file_serving/configuration/parser_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/file_serving/configuration/parser' diff --git a/spec/unit/file_serving/configuration_spec.rb b/spec/unit/file_serving/configuration_spec.rb index 3c6113165..6ee1a4f38 100755 --- a/spec/unit/file_serving/configuration_spec.rb +++ b/spec/unit/file_serving/configuration_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/file_serving/configuration' diff --git a/spec/unit/file_serving/content_spec.rb b/spec/unit/file_serving/content_spec.rb index 576cbde1f..2637ba6ce 100755 --- a/spec/unit/file_serving/content_spec.rb +++ b/spec/unit/file_serving/content_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/file_serving/content' diff --git a/spec/unit/file_serving/fileset_spec.rb b/spec/unit/file_serving/fileset_spec.rb index 3b12c953e..a369ad39c 100755 --- a/spec/unit/file_serving/fileset_spec.rb +++ b/spec/unit/file_serving/fileset_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/file_serving/fileset' diff --git a/spec/unit/file_serving/indirection_hooks_spec.rb b/spec/unit/file_serving/indirection_hooks_spec.rb index 1c7f55da8..4890505ab 100755 --- a/spec/unit/file_serving/indirection_hooks_spec.rb +++ b/spec/unit/file_serving/indirection_hooks_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-10-18. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/file_serving/indirection_hooks' diff --git a/spec/unit/file_serving/metadata_spec.rb b/spec/unit/file_serving/metadata_spec.rb index 34794cca9..39f2a9548 100755 --- a/spec/unit/file_serving/metadata_spec.rb +++ b/spec/unit/file_serving/metadata_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/file_serving/metadata' diff --git a/spec/unit/file_serving/mount/file_spec.rb b/spec/unit/file_serving/mount/file_spec.rb index 792ce951c..70c804abd 100755 --- a/spec/unit/file_serving/mount/file_spec.rb +++ b/spec/unit/file_serving/mount/file_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/file_serving/mount/file' module FileServingMountTesting diff --git a/spec/unit/file_serving/mount/modules_spec.rb b/spec/unit/file_serving/mount/modules_spec.rb index 1213f4fa5..2d582daa2 100755 --- a/spec/unit/file_serving/mount/modules_spec.rb +++ b/spec/unit/file_serving/mount/modules_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/file_serving/mount/modules' describe Puppet::FileServing::Mount::Modules do diff --git a/spec/unit/file_serving/mount/plugins_spec.rb b/spec/unit/file_serving/mount/plugins_spec.rb index 6aa9ae927..b6bed72a0 100755 --- a/spec/unit/file_serving/mount/plugins_spec.rb +++ b/spec/unit/file_serving/mount/plugins_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/file_serving/mount/plugins' describe Puppet::FileServing::Mount::Plugins do diff --git a/spec/unit/file_serving/mount_spec.rb b/spec/unit/file_serving/mount_spec.rb index 2bfe643f6..5d8e64f82 100755 --- a/spec/unit/file_serving/mount_spec.rb +++ b/spec/unit/file_serving/mount_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/file_serving/mount' describe Puppet::FileServing::Mount do diff --git a/spec/unit/file_serving/terminus_helper_spec.rb b/spec/unit/file_serving/terminus_helper_spec.rb index 36cf0daf3..7efe3fb98 100755 --- a/spec/unit/file_serving/terminus_helper_spec.rb +++ b/spec/unit/file_serving/terminus_helper_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-10-22. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/file_serving/terminus_helper' diff --git a/spec/unit/indirector/active_record_spec.rb b/spec/unit/indirector/active_record_spec.rb index 4fab17da2..2baef33fe 100755 --- a/spec/unit/indirector/active_record_spec.rb +++ b/spec/unit/indirector/active_record_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/rails' require 'puppet/indirector/active_record' diff --git a/spec/unit/indirector/catalog/active_record_spec.rb b/spec/unit/indirector/catalog/active_record_spec.rb index da1d77582..35d01179b 100755 --- a/spec/unit/indirector/catalog/active_record_spec.rb +++ b/spec/unit/indirector/catalog/active_record_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe "Puppet::Resource::Catalog::ActiveRecord", :if => Puppet.features.rails? do diff --git a/spec/unit/indirector/catalog/compiler_spec.rb b/spec/unit/indirector/catalog/compiler_spec.rb index a2ab0c6f4..cd84031e5 100755 --- a/spec/unit/indirector/catalog/compiler_spec.rb +++ b/spec/unit/indirector/catalog/compiler_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-9-23. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/indirector/catalog/compiler' require 'puppet/rails' diff --git a/spec/unit/indirector/catalog/queue_spec.rb b/spec/unit/indirector/catalog/queue_spec.rb index 866113631..d396ad897 100755 --- a/spec/unit/indirector/catalog/queue_spec.rb +++ b/spec/unit/indirector/catalog/queue_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/catalog/queue' diff --git a/spec/unit/indirector/catalog/rest_spec.rb b/spec/unit/indirector/catalog/rest_spec.rb index c887504a2..3e674dde9 100755 --- a/spec/unit/indirector/catalog/rest_spec.rb +++ b/spec/unit/indirector/catalog/rest_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/catalog/rest' diff --git a/spec/unit/indirector/catalog/yaml_spec.rb b/spec/unit/indirector/catalog/yaml_spec.rb index 3bf5b4640..ddaa173c6 100755 --- a/spec/unit/indirector/catalog/yaml_spec.rb +++ b/spec/unit/indirector/catalog/yaml_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/resource/catalog' require 'puppet/indirector/catalog/yaml' diff --git a/spec/unit/indirector/certificate/ca_spec.rb b/spec/unit/indirector/certificate/ca_spec.rb index 77384ddb8..277d2209d 100755 --- a/spec/unit/indirector/certificate/ca_spec.rb +++ b/spec/unit/indirector/certificate/ca_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-3-7. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/indirector/certificate/ca' diff --git a/spec/unit/indirector/certificate/file_spec.rb b/spec/unit/indirector/certificate/file_spec.rb index 45dd95cb5..f398e1115 100755 --- a/spec/unit/indirector/certificate/file_spec.rb +++ b/spec/unit/indirector/certificate/file_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-3-7. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/indirector/certificate/file' diff --git a/spec/unit/indirector/certificate/rest_spec.rb b/spec/unit/indirector/certificate/rest_spec.rb index 8fd6bff9a..21e10e316 100755 --- a/spec/unit/indirector/certificate/rest_spec.rb +++ b/spec/unit/indirector/certificate/rest_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/certificate/rest' diff --git a/spec/unit/indirector/certificate_request/ca_spec.rb b/spec/unit/indirector/certificate_request/ca_spec.rb index 8c25e40f7..ebd64a2fb 100755 --- a/spec/unit/indirector/certificate_request/ca_spec.rb +++ b/spec/unit/indirector/certificate_request/ca_spec.rb @@ -1,13 +1,32 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-3-7. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' +require 'puppet/ssl/host' +require 'puppet/sslcertificates' +require 'puppet/sslcertificates/ca' require 'puppet/indirector/certificate_request/ca' describe Puppet::SSL::CertificateRequest::Ca do + include PuppetSpec::Files + + before :each do + Puppet[:ssldir] = tmpdir('ssl') + + Puppet::SSL::Host.ca_location = :local + Puppet[:localcacert] = Puppet[:cacert] + Puppet::SSLCertificates::CA.new.mkrootcert + + @ca = Puppet::SSL::CertificateAuthority.new + end + + after :all do + Puppet::SSL::Host.ca_location = :none + end + it "should have documentation" do Puppet::SSL::CertificateRequest::Ca.doc.should be_instance_of(String) end @@ -16,4 +35,30 @@ describe Puppet::SSL::CertificateRequest::Ca do Puppet.settings.expects(:value).with(:csrdir).returns "/request/dir" Puppet::SSL::CertificateRequest::Ca.collection_directory.should == "/request/dir" end + + it "should overwrite the previous certificate request if allow_duplicate_certs is true" do + Puppet[:allow_duplicate_certs] = true + host = Puppet::SSL::Host.new("foo") + host.generate_certificate_request + @ca.sign(host.name) + + Puppet::SSL::Host.indirection.find("foo").generate_certificate_request + + Puppet::SSL::Certificate.indirection.find("foo").name.should == "foo" + Puppet::SSL::CertificateRequest.indirection.find("foo").name.should == "foo" + Puppet::SSL::Host.indirection.find("foo").state.should == "requested" + end + + it "should reject a new certificate request if allow_duplicate_certs is false" do + Puppet[:allow_duplicate_certs] = false + host = Puppet::SSL::Host.new("bar") + host.generate_certificate_request + @ca.sign(host.name) + + expect { Puppet::SSL::Host.indirection.find("bar").generate_certificate_request }.should raise_error(/ignoring certificate request/) + + Puppet::SSL::Certificate.indirection.find("bar").name.should == "bar" + Puppet::SSL::CertificateRequest.indirection.find("bar").should be_nil + Puppet::SSL::Host.indirection.find("bar").state.should == "signed" + end end diff --git a/spec/unit/indirector/certificate_request/file_spec.rb b/spec/unit/indirector/certificate_request/file_spec.rb index 465d55d3c..69dc5eb9c 100755 --- a/spec/unit/indirector/certificate_request/file_spec.rb +++ b/spec/unit/indirector/certificate_request/file_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-3-7. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/indirector/certificate_request/file' diff --git a/spec/unit/indirector/certificate_request/rest_spec.rb b/spec/unit/indirector/certificate_request/rest_spec.rb index 9a8b87439..398b91b84 100755 --- a/spec/unit/indirector/certificate_request/rest_spec.rb +++ b/spec/unit/indirector/certificate_request/rest_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/certificate_request/rest' diff --git a/spec/unit/indirector/certificate_revocation_list/ca_spec.rb b/spec/unit/indirector/certificate_revocation_list/ca_spec.rb index d72a3bb10..d76373b97 100755 --- a/spec/unit/indirector/certificate_revocation_list/ca_spec.rb +++ b/spec/unit/indirector/certificate_revocation_list/ca_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-3-7. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/indirector/certificate_revocation_list/ca' diff --git a/spec/unit/indirector/certificate_revocation_list/file_spec.rb b/spec/unit/indirector/certificate_revocation_list/file_spec.rb index 3284bee35..f4b8c36d3 100755 --- a/spec/unit/indirector/certificate_revocation_list/file_spec.rb +++ b/spec/unit/indirector/certificate_revocation_list/file_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-3-7. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/indirector/certificate_revocation_list/file' diff --git a/spec/unit/indirector/certificate_revocation_list/rest_spec.rb b/spec/unit/indirector/certificate_revocation_list/rest_spec.rb index e47a0848c..238ba75ff 100755 --- a/spec/unit/indirector/certificate_revocation_list/rest_spec.rb +++ b/spec/unit/indirector/certificate_revocation_list/rest_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/certificate_revocation_list/rest' diff --git a/spec/unit/indirector/certificate_status/file_spec.rb b/spec/unit/indirector/certificate_status/file_spec.rb index 6cc0bb547..ae03aa9cb 100644..100755 --- a/spec/unit/indirector/certificate_status/file_spec.rb +++ b/spec/unit/indirector/certificate_status/file_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/ssl/host' require 'puppet/indirector/certificate_status' require 'tempfile' diff --git a/spec/unit/indirector/certificate_status/rest_spec.rb b/spec/unit/indirector/certificate_status/rest_spec.rb index f44eac671..39fbb7024 100644..100755 --- a/spec/unit/indirector/certificate_status/rest_spec.rb +++ b/spec/unit/indirector/certificate_status/rest_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/ssl/host' require 'puppet/indirector/certificate_status' diff --git a/spec/unit/indirector/code_spec.rb b/spec/unit/indirector/code_spec.rb index 1c9e4d2f1..29369bf5e 100755 --- a/spec/unit/indirector/code_spec.rb +++ b/spec/unit/indirector/code_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/code' describe Puppet::Indirector::Code do diff --git a/spec/unit/indirector/direct_file_server_spec.rb b/spec/unit/indirector/direct_file_server_spec.rb index 5d9af626f..abd7172b7 100755 --- a/spec/unit/indirector/direct_file_server_spec.rb +++ b/spec/unit/indirector/direct_file_server_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-10-24. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/indirector/direct_file_server' diff --git a/spec/unit/indirector/envelope_spec.rb b/spec/unit/indirector/envelope_spec.rb index 2715a2671..e056b768c 100755 --- a/spec/unit/indirector/envelope_spec.rb +++ b/spec/unit/indirector/envelope_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/envelope' describe Puppet::Indirector::Envelope do diff --git a/spec/unit/indirector/exec_spec.rb b/spec/unit/indirector/exec_spec.rb index 5abb00ae9..1050ed4cc 100755 --- a/spec/unit/indirector/exec_spec.rb +++ b/spec/unit/indirector/exec_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/exec' diff --git a/spec/unit/indirector/facts/active_record_spec.rb b/spec/unit/indirector/facts/active_record_spec.rb index 71e19e3ca..01a906716 100755 --- a/spec/unit/indirector/facts/active_record_spec.rb +++ b/spec/unit/indirector/facts/active_record_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/rails' require 'puppet/node/facts' diff --git a/spec/unit/indirector/facts/couch_spec.rb b/spec/unit/indirector/facts/couch_spec.rb index 1f86b56f2..d0862486c 100644..100755 --- a/spec/unit/indirector/facts/couch_spec.rb +++ b/spec/unit/indirector/facts/couch_spec.rb @@ -1,97 +1,102 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/node/facts' +require 'puppet/indirector/facts/couch' -describe "Puppet::Node::Facts::Couch", :if => Puppet.features.couchdb? do - require 'puppet/indirector/facts/couch' if Puppet.features.couchdb? - - before do - @mock_db = mock('couch db') - mock_document = CouchRest::Document.new(:_id => fake_request.key, :facts => fake_request.values) - mock_document.stubs(:database).returns(@mock_db) - @mock_db.stubs(:get).with(fake_request.key).returns(mock_document) - Puppet::Node::Facts::Couch.stubs(:db).returns(@mock_db) +describe "Puppet::Node::Facts::Couch" do + describe "when couchdb is not available", :unless => Puppet.features.couchdb? do + it "should fail to initialize" do + lambda { Puppet::Node::Facts::Couch.new }.should raise_error + end end - subject { Puppet::Node::Facts::Couch } - - describe "#find" do - describe "when the node document exists" do - it "should find the request by key" do - @mock_db.expects(:get).with(fake_request.key).returns({'_id' => fake_request.key, 'facts' => fake_request.instance.values}) - subject.new.find(fake_request).should == fake_request.instance - end + describe "when couchdb is available", :if => Puppet.features.couchdb? do + before do + @mock_db = mock('couch db') + mock_document = CouchRest::Document.new(:_id => fake_request.key, :facts => fake_request.values) + mock_document.stubs(:database).returns(@mock_db) + @mock_db.stubs(:get).with(fake_request.key).returns(mock_document) + Puppet::Node::Facts::Couch.stubs(:db).returns(@mock_db) end - describe "when the node document does not exist" do - before do - @mock_db.expects(:get). - with(fake_request.key). - raises(RestClient::ResourceNotFound) - end + subject { Puppet::Node::Facts::Couch } - it "should return nil" do - subject.new.find(fake_request).should be_nil + describe "#find" do + describe "when the node document exists" do + it "should find the request by key" do + @mock_db.expects(:get).with(fake_request.key).returns({'_id' => fake_request.key, 'facts' => fake_request.instance.values}) + subject.new.find(fake_request).should == fake_request.instance + end end - it "should send Puppet a debug message" do - Puppet.expects(:debug).with("No couchdb document with id: test.local") - subject.new.find(fake_request).should be_nil - end + describe "when the node document does not exist" do + before do + @mock_db.expects(:get). + with(fake_request.key). + raises(RestClient::ResourceNotFound) + end - end - end + it "should return nil" do + subject.new.find(fake_request).should be_nil + end - describe "#save" do - describe "with options" do - subject do - lambda { Puppet::Node::Facts::Couch.new.save(fake_request([1])) } - end + it "should send Puppet a debug message" do + Puppet.expects(:debug).with("No couchdb document with id: test.local") + subject.new.find(fake_request).should be_nil + end - it { should raise_error(ArgumentError, "PUT does not accept options") } + end end - it "should save the json to the CouchDB database" do - @mock_db.expects(:save_doc).at_least_once.returns({'ok' => true }) - subject.new.save(fake_request) - end + describe "#save" do + describe "with options" do + subject do + lambda { Puppet::Node::Facts::Couch.new.save(fake_request([1])) } + end - describe "when the document exists" do - before do - @doc = CouchRest::Document.new(:_id => fake_request.key, :facts => fake_request.instance.values) - @mock_db.expects(:get).with(fake_request.key).returns(@doc) + it { should raise_error(ArgumentError, "PUT does not accept options") } end - it "saves the document" do - @doc.expects(:save) + it "should save the json to the CouchDB database" do + @mock_db.expects(:save_doc).at_least_once.returns({'ok' => true }) subject.new.save(fake_request) end - end + describe "when the document exists" do + before do + @doc = CouchRest::Document.new(:_id => fake_request.key, :facts => fake_request.instance.values) + @mock_db.expects(:get).with(fake_request.key).returns(@doc) + end + + it "saves the document" do + @doc.expects(:save) + subject.new.save(fake_request) + end - describe "when the document does not exist" do - before do - @mock_db.expects(:get). - with(fake_request.key). - raises(RestClient::ResourceNotFound) end - it "saves the document" do - @mock_db.expects(:save_doc) - subject.new.save(fake_request) + describe "when the document does not exist" do + before do + @mock_db.expects(:get). + with(fake_request.key). + raises(RestClient::ResourceNotFound) + end + + it "saves the document" do + @mock_db.expects(:save_doc) + subject.new.save(fake_request) + end + end end + def fake_request(options={}) + facts = YAML.load_file(File.join(PuppetSpec::FIXTURE_DIR, 'yaml', 'test.local.yaml')) + Struct.new(:instance, :key, :options).new(facts, facts.name, options) + end + private :fake_request end - - def fake_request(options={}) - facts = YAML.load_file(File.join(PuppetSpec::FIXTURE_DIR, 'yaml', 'test.local.yaml')) - Struct.new(:instance, :key, :options).new(facts, facts.name, options) - end - private :fake_request - end diff --git a/spec/unit/indirector/facts/facter_spec.rb b/spec/unit/indirector/facts/facter_spec.rb index 3129f5ebf..9f5a0249b 100755 --- a/spec/unit/indirector/facts/facter_spec.rb +++ b/spec/unit/indirector/facts/facter_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-9-23. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/indirector/facts/facter' diff --git a/spec/unit/indirector/facts/inventory_active_record_spec.rb b/spec/unit/indirector/facts/inventory_active_record_spec.rb index 43b9fa397..edd03d8e4 100644..100755 --- a/spec/unit/indirector/facts/inventory_active_record_spec.rb +++ b/spec/unit/indirector/facts/inventory_active_record_spec.rb @@ -1,7 +1,9 @@ -#!/usr/bin/env ruby - -require File.dirname(__FILE__) + '/../../../spec_helper' -require 'sqlite3' rescue nil +#!/usr/bin/env rspec +require 'spec_helper' +begin + require 'sqlite3' +rescue LoadError +end require 'tempfile' require 'puppet/rails' @@ -29,6 +31,7 @@ describe "Puppet::Node::Facts::InventoryActiveRecord", :if => (Puppet.features.r after :each do Puppet::Rails.teardown + ActiveRecord::Base.remove_connection end describe "#save" do diff --git a/spec/unit/indirector/facts/rest_spec.rb b/spec/unit/indirector/facts/rest_spec.rb index 03bef4578..6a2a23f8b 100755 --- a/spec/unit/indirector/facts/rest_spec.rb +++ b/spec/unit/indirector/facts/rest_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/facts/rest' diff --git a/spec/unit/indirector/facts/yaml_spec.rb b/spec/unit/indirector/facts/yaml_spec.rb index c266df18f..a22d690b8 100755 --- a/spec/unit/indirector/facts/yaml_spec.rb +++ b/spec/unit/indirector/facts/yaml_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/node/facts' require 'puppet/indirector/facts/yaml' diff --git a/spec/unit/indirector/file_bucket_file/file_spec.rb b/spec/unit/indirector/file_bucket_file/file_spec.rb index 1423cb2e3..e0612cb21 100755 --- a/spec/unit/indirector/file_bucket_file/file_spec.rb +++ b/spec/unit/indirector/file_bucket_file/file_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require ::File.dirname(__FILE__) + '/../../../spec_helper' +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/file_bucket_file/file' diff --git a/spec/unit/indirector/file_bucket_file/rest_spec.rb b/spec/unit/indirector/file_bucket_file/rest_spec.rb index d0f714751..ae2e033c6 100755 --- a/spec/unit/indirector/file_bucket_file/rest_spec.rb +++ b/spec/unit/indirector/file_bucket_file/rest_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/file_bucket_file/rest' diff --git a/spec/unit/indirector/file_content/file_server_spec.rb b/spec/unit/indirector/file_content/file_server_spec.rb index 5bd88132c..99a535dc3 100755 --- a/spec/unit/indirector/file_content/file_server_spec.rb +++ b/spec/unit/indirector/file_content/file_server_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-10-18. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/indirector/file_content/file_server' diff --git a/spec/unit/indirector/file_content/file_spec.rb b/spec/unit/indirector/file_content/file_spec.rb index edead1c70..b629981c5 100755 --- a/spec/unit/indirector/file_content/file_spec.rb +++ b/spec/unit/indirector/file_content/file_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-10-18. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/indirector/file_content/file' diff --git a/spec/unit/indirector/file_content/rest_spec.rb b/spec/unit/indirector/file_content/rest_spec.rb index cf94d2ffd..06ad16e77 100755 --- a/spec/unit/indirector/file_content/rest_spec.rb +++ b/spec/unit/indirector/file_content/rest_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/file_content' diff --git a/spec/unit/indirector/file_metadata/file_server_spec.rb b/spec/unit/indirector/file_metadata/file_server_spec.rb index 99eb83d7f..e16829035 100755 --- a/spec/unit/indirector/file_metadata/file_server_spec.rb +++ b/spec/unit/indirector/file_metadata/file_server_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-10-18. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/indirector/file_metadata/file_server' diff --git a/spec/unit/indirector/file_metadata/file_spec.rb b/spec/unit/indirector/file_metadata/file_spec.rb index 74eff5b66..28a974290 100755 --- a/spec/unit/indirector/file_metadata/file_spec.rb +++ b/spec/unit/indirector/file_metadata/file_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-10-18. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/indirector/file_metadata/file' diff --git a/spec/unit/indirector/file_metadata/rest_spec.rb b/spec/unit/indirector/file_metadata/rest_spec.rb index 132d90d4f..511f7c758 100755 --- a/spec/unit/indirector/file_metadata/rest_spec.rb +++ b/spec/unit/indirector/file_metadata/rest_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/file_metadata' diff --git a/spec/unit/indirector/file_server_spec.rb b/spec/unit/indirector/file_server_spec.rb index 079eba0ae..6df715fb1 100755 --- a/spec/unit/indirector/file_server_spec.rb +++ b/spec/unit/indirector/file_server_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-10-19. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/indirector/file_server' require 'puppet/file_serving/configuration' diff --git a/spec/unit/indirector/file_spec.rb b/spec/unit/indirector/file_spec.rb index 96d5b2ae7..b72bf4d67 100755 --- a/spec/unit/indirector/file_spec.rb +++ b/spec/unit/indirector/file_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/file' diff --git a/spec/unit/indirector/indirection_spec.rb b/spec/unit/indirector/indirection_spec.rb index 8795ae795..4bbc855b1 100755 --- a/spec/unit/indirector/indirection_spec.rb +++ b/spec/unit/indirector/indirection_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/indirection' diff --git a/spec/unit/indirector/inventory/yaml_spec.rb b/spec/unit/indirector/inventory/yaml_spec.rb index a4eb2ab7a..54ab9c72c 100644..100755 --- a/spec/unit/indirector/inventory/yaml_spec.rb +++ b/spec/unit/indirector/inventory/yaml_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/node/inventory' require 'puppet/indirector/inventory/yaml' diff --git a/spec/unit/indirector/key/ca_spec.rb b/spec/unit/indirector/key/ca_spec.rb index 53bd380a6..ba3d1aae2 100755 --- a/spec/unit/indirector/key/ca_spec.rb +++ b/spec/unit/indirector/key/ca_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-3-7. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/indirector/key/ca' diff --git a/spec/unit/indirector/key/file_spec.rb b/spec/unit/indirector/key/file_spec.rb index 715ceacda..bf9b293d8 100755 --- a/spec/unit/indirector/key/file_spec.rb +++ b/spec/unit/indirector/key/file_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-3-7. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/indirector/key/file' diff --git a/spec/unit/indirector/ldap_spec.rb b/spec/unit/indirector/ldap_spec.rb index ab5dab9ce..2b40325de 100755 --- a/spec/unit/indirector/ldap_spec.rb +++ b/spec/unit/indirector/ldap_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/ldap' diff --git a/spec/unit/indirector/memory_spec.rb b/spec/unit/indirector/memory_spec.rb index 751adb1b6..676acfcca 100755 --- a/spec/unit/indirector/memory_spec.rb +++ b/spec/unit/indirector/memory_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/memory' require 'shared_behaviours/memory_terminus' diff --git a/spec/unit/indirector/node/active_record_spec.rb b/spec/unit/indirector/node/active_record_spec.rb index 65b0e1fc9..6fed940b9 100755 --- a/spec/unit/indirector/node/active_record_spec.rb +++ b/spec/unit/indirector/node/active_record_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/node' diff --git a/spec/unit/indirector/node/exec_spec.rb b/spec/unit/indirector/node/exec_spec.rb index e6d6ccb93..f14990cd5 100755 --- a/spec/unit/indirector/node/exec_spec.rb +++ b/spec/unit/indirector/node/exec_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/node/exec' diff --git a/spec/unit/indirector/node/ldap_spec.rb b/spec/unit/indirector/node/ldap_spec.rb index 5d4086a1a..5e57db3c4 100755 --- a/spec/unit/indirector/node/ldap_spec.rb +++ b/spec/unit/indirector/node/ldap_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/node/ldap' diff --git a/spec/unit/indirector/node/memory_spec.rb b/spec/unit/indirector/node/memory_spec.rb index 904ee1259..8b26a47c1 100755 --- a/spec/unit/indirector/node/memory_spec.rb +++ b/spec/unit/indirector/node/memory_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/node/memory' diff --git a/spec/unit/indirector/node/plain_spec.rb b/spec/unit/indirector/node/plain_spec.rb index 40d5211db..c6ba84e67 100755 --- a/spec/unit/indirector/node/plain_spec.rb +++ b/spec/unit/indirector/node/plain_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/node/plain' diff --git a/spec/unit/indirector/node/rest_spec.rb b/spec/unit/indirector/node/rest_spec.rb index cb3012efa..fa5d1baf7 100755 --- a/spec/unit/indirector/node/rest_spec.rb +++ b/spec/unit/indirector/node/rest_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/node/rest' diff --git a/spec/unit/indirector/node/yaml_spec.rb b/spec/unit/indirector/node/yaml_spec.rb index 649bde06d..db9ffe435 100755 --- a/spec/unit/indirector/node/yaml_spec.rb +++ b/spec/unit/indirector/node/yaml_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/node' require 'puppet/indirector/node/yaml' diff --git a/spec/unit/indirector/plain_spec.rb b/spec/unit/indirector/plain_spec.rb index dfaa701bd..0894f70f0 100755 --- a/spec/unit/indirector/plain_spec.rb +++ b/spec/unit/indirector/plain_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/plain' describe Puppet::Indirector::Plain do diff --git a/spec/unit/indirector/queue_spec.rb b/spec/unit/indirector/queue_spec.rb index 6f5b44b4c..b84ed2aea 100755 --- a/spec/unit/indirector/queue_spec.rb +++ b/spec/unit/indirector/queue_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/queue' class Puppet::Indirector::Queue::TestClient diff --git a/spec/unit/indirector/report/processor_spec.rb b/spec/unit/indirector/report/processor_spec.rb index adc2638fc..bafbe6ee7 100755 --- a/spec/unit/indirector/report/processor_spec.rb +++ b/spec/unit/indirector/report/processor_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-9-23. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/indirector/report/processor' diff --git a/spec/unit/indirector/report/rest_spec.rb b/spec/unit/indirector/report/rest_spec.rb index 67a98e334..806ae6efd 100755 --- a/spec/unit/indirector/report/rest_spec.rb +++ b/spec/unit/indirector/report/rest_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/report/rest' diff --git a/spec/unit/indirector/report/yaml_spec.rb b/spec/unit/indirector/report/yaml_spec.rb index e75fafe5e..7df4bb2e9 100644..100755 --- a/spec/unit/indirector/report/yaml_spec.rb +++ b/spec/unit/indirector/report/yaml_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/transaction/report' require 'puppet/indirector/report/yaml' diff --git a/spec/unit/indirector/request_spec.rb b/spec/unit/indirector/request_spec.rb index bef56b1e1..965d54188 100755 --- a/spec/unit/indirector/request_spec.rb +++ b/spec/unit/indirector/request_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/request' describe Puppet::Indirector::Request do diff --git a/spec/unit/indirector/resource/ral_spec.rb b/spec/unit/indirector/resource/ral_spec.rb index 43deaa8eb..61290f7a7 100644..100755 --- a/spec/unit/indirector/resource/ral_spec.rb +++ b/spec/unit/indirector/resource/ral_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe "Puppet::Resource::Ral" do describe "find" do diff --git a/spec/unit/indirector/resource/rest_spec.rb b/spec/unit/indirector/resource/rest_spec.rb index 1285d338a..70c9a7f11 100755 --- a/spec/unit/indirector/resource/rest_spec.rb +++ b/spec/unit/indirector/resource/rest_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/resource/rest' diff --git a/spec/unit/indirector/resource_type/parser_spec.rb b/spec/unit/indirector/resource_type/parser_spec.rb index f86b319f9..c4fc455a0 100755 --- a/spec/unit/indirector/resource_type/parser_spec.rb +++ b/spec/unit/indirector/resource_type/parser_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/resource_type/parser' require 'puppet_spec/files' diff --git a/spec/unit/indirector/resource_type/rest_spec.rb b/spec/unit/indirector/resource_type/rest_spec.rb index dceb109b2..3d8ddf44c 100755 --- a/spec/unit/indirector/resource_type/rest_spec.rb +++ b/spec/unit/indirector/resource_type/rest_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/resource_type/rest' diff --git a/spec/unit/indirector/rest_spec.rb b/spec/unit/indirector/rest_spec.rb index 326d85f9d..513eb8352 100755 --- a/spec/unit/indirector/rest_spec.rb +++ b/spec/unit/indirector/rest_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/rest' shared_examples_for "a REST http call" do @@ -224,13 +223,32 @@ describe Puppet::Indirector::REST do @searcher.stubs(:network).returns(@connection) # neuter the network connection # Use a key with spaces, so we can test escaping - @request = Puppet::Indirector::Request.new(:foo, :find, "foo bar") + @request = Puppet::Indirector::Request.new(:foo, :find, "foo bar", :environment => "myenv") end - it "should call the GET http method on a network connection" do - @searcher.expects(:network).returns @connection - @connection.expects(:get).returns @response - @searcher.find(@request) + describe "with a large body" do + it "should use the POST http method" do + params = {} + 'aa'.upto('zz') do |s| + params[s] = 'foo' + end + + @request = Puppet::Indirector::Request.new(:foo, :find, "foo bar", params.merge(:environment => "myenv")) + + @connection.expects(:post).with do |uri, body| + uri == "/myenv/foo/foo%20bar" and body.split("&").sort == params.map {|key,value| "#{key}=#{value}"}.sort + end.returns(@response) + + @searcher.find(@request) + end + end + + describe "with a small body" do + it "should use the GET http method" do + @searcher.expects(:network).returns @connection + @connection.expects(:get).returns @response + @searcher.find(@request) + end end it "should deserialize and return the http response, setting name" do @@ -252,10 +270,8 @@ describe Puppet::Indirector::REST do @searcher.find(@request).should == instance end - it "should use the URI generated by the Handler module" do - @searcher.expects(:indirection2uri).with(@request).returns "/my/uri" - @connection.expects(:get).with { |path, args| path == "/my/uri" }.returns(@response) + @connection.expects(:get).with { |path, args| path == "/myenv/foo/foo%20bar?" }.returns(@response) @searcher.find(@request) end diff --git a/spec/unit/indirector/run/local_spec.rb b/spec/unit/indirector/run/local_spec.rb index cb012a0b0..8fb61d962 100644..100755 --- a/spec/unit/indirector/run/local_spec.rb +++ b/spec/unit/indirector/run/local_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/run/local' diff --git a/spec/unit/indirector/run/rest_spec.rb b/spec/unit/indirector/run/rest_spec.rb index cf90caa5b..4b80962d1 100755 --- a/spec/unit/indirector/run/rest_spec.rb +++ b/spec/unit/indirector/run/rest_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/run/rest' diff --git a/spec/unit/indirector/ssl_file_spec.rb b/spec/unit/indirector/ssl_file_spec.rb index ca97cf49e..5d0859598 100755 --- a/spec/unit/indirector/ssl_file_spec.rb +++ b/spec/unit/indirector/ssl_file_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-3-10. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/indirector/ssl_file' diff --git a/spec/unit/indirector/status/rest_spec.rb b/spec/unit/indirector/status/rest_spec.rb index 436c86881..b203e6e20 100755 --- a/spec/unit/indirector/status/rest_spec.rb +++ b/spec/unit/indirector/status/rest_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/status/rest' diff --git a/spec/unit/indirector/terminus_spec.rb b/spec/unit/indirector/terminus_spec.rb index bc255aa5b..41770e1e3 100755 --- a/spec/unit/indirector/terminus_spec.rb +++ b/spec/unit/indirector/terminus_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/defaults' require 'puppet/indirector' require 'puppet/indirector/file' diff --git a/spec/unit/indirector/yaml_spec.rb b/spec/unit/indirector/yaml_spec.rb index 188e300d6..c43dbcaf6 100755 --- a/spec/unit/indirector/yaml_spec.rb +++ b/spec/unit/indirector/yaml_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/indirector/yaml' diff --git a/spec/unit/indirector_spec.rb b/spec/unit/indirector_spec.rb index 7bab426c0..0c09831db 100755 --- a/spec/unit/indirector_spec.rb +++ b/spec/unit/indirector_spec.rb @@ -1,10 +1,68 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/defaults' require 'puppet/indirector' +describe Puppet::Indirector, "when configuring routes" do + before :each do + Puppet::Node.indirection.reset_terminus_class + Puppet::Node.indirection.cache_class = nil + end + + after :each do + Puppet::Node.indirection.reset_terminus_class + Puppet::Node.indirection.cache_class = nil + end + + it "should configure routes as requested" do + routes = { + "node" => { + "terminus" => "exec", + "cache" => "plain" + } + } + + Puppet::Indirector.configure_routes(routes) + + Puppet::Node.indirection.terminus_class.should == "exec" + Puppet::Node.indirection.cache_class.should == "plain" + end + + it "should fail when given an invalid indirection" do + routes = { + "fake_indirection" => { + "terminus" => "exec", + "cache" => "plain" + } + } + + expect { Puppet::Indirector.configure_routes(routes) }.should raise_error(/fake_indirection does not exist/) + end + + it "should fail when given an invalid terminus" do + routes = { + "node" => { + "terminus" => "fake_terminus", + "cache" => "plain" + } + } + + expect { Puppet::Indirector.configure_routes(routes) }.should raise_error(/Could not find terminus fake_terminus/) + end + + it "should fail when given an invalid cache" do + routes = { + "node" => { + "terminus" => "exec", + "cache" => "fake_cache" + } + } + + expect { Puppet::Indirector.configure_routes(routes) }.should raise_error(/Could not find terminus fake_cache/) + end +end + describe Puppet::Indirector, " when available to a model" do before do @thingie = Class.new do diff --git a/spec/unit/interface/action_builder_spec.rb b/spec/unit/interface/action_builder_spec.rb new file mode 100755 index 000000000..5b04df900 --- /dev/null +++ b/spec/unit/interface/action_builder_spec.rb @@ -0,0 +1,69 @@ +#!/usr/bin/env rspec +require 'spec_helper' +require 'puppet/interface/action_builder' + +describe Puppet::Interface::ActionBuilder do + describe "::build" do + it "should build an action" do + action = Puppet::Interface::ActionBuilder.build(nil, :foo) do + end + action.should be_a(Puppet::Interface::Action) + action.name.should == :foo + end + + it "should define a method on the face which invokes the action" do + face = Puppet::Interface.new(:action_builder_test_interface, '0.0.1') + action = Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do + "invoked the method" + end + end + + face.foo.should == "invoked the method" + end + + it "should require a block" do + expect { Puppet::Interface::ActionBuilder.build(nil, :foo) }. + should raise_error("Action :foo must specify a block") + end + + describe "when handling options" do + let :face do Puppet::Interface.new(:option_handling, '0.0.1') end + + it "should have a #option DSL function" do + method = nil + Puppet::Interface::ActionBuilder.build(face, :foo) do + method = self.method(:option) + end + method.should be + end + + it "should define an option without a block" do + action = Puppet::Interface::ActionBuilder.build(face, :foo) do + option "--bar" + end + action.should be_option :bar + end + + it "should accept an empty block" do + action = Puppet::Interface::ActionBuilder.build(face, :foo) do + option "--bar" do + # This space left deliberately blank. + end + end + action.should be_option :bar + end + end + + context "inline documentation" do + let :face do Puppet::Interface.new(:inline_action_docs, '0.0.1') end + + it "should set the summary" do + action = Puppet::Interface::ActionBuilder.build(face, :foo) do + summary "this is some text" + end + action.summary.should == "this is some text" + end + end + end +end diff --git a/spec/unit/interface/action_manager_spec.rb b/spec/unit/interface/action_manager_spec.rb new file mode 100755 index 000000000..c4b21eaac --- /dev/null +++ b/spec/unit/interface/action_manager_spec.rb @@ -0,0 +1,232 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +# This is entirely an internal class for Interface, so we have to load it instead of our class. +require 'puppet/interface' + +class ActionManagerTester + include Puppet::Interface::ActionManager +end + +describe Puppet::Interface::ActionManager do + subject { ActionManagerTester.new } + + describe "when included in a class" do + it "should be able to define an action" do + subject.action(:foo) do + when_invoked { "something "} + end + end + + it "should be able to define a 'script' style action" do + subject.script :bar do + "a bar is where beer is found" + end + end + + it "should be able to list defined actions" do + subject.action(:foo) do + when_invoked { "something" } + end + subject.action(:bar) do + when_invoked { "something" } + end + + subject.actions.should =~ [:foo, :bar] + end + + it "should list 'script' actions" do + subject.script :foo do "foo" end + subject.actions.should =~ [:foo] + end + + it "should list both script and normal actions" do + subject.action :foo do + when_invoked do "foo" end + end + subject.script :bar do "a bar is where beer is found" end + + subject.actions.should =~ [:foo, :bar] + end + + it "should be able to indicate when an action is defined" do + subject.action(:foo) do + when_invoked { "something" } + end + + subject.should be_action(:foo) + end + + it "should indicate an action is defined for script actions" do + subject.script :foo do "foo" end + subject.should be_action :foo + end + + it "should correctly treat action names specified as strings" do + subject.action(:foo) do + when_invoked { "something" } + end + + subject.should be_action("foo") + end + end + + describe "when used to extend a class" do + subject { Class.new.extend(Puppet::Interface::ActionManager) } + + it "should be able to define an action" do + subject.action(:foo) do + when_invoked { "something "} + end + end + + it "should be able to list defined actions" do + subject.action(:foo) do + when_invoked { "something" } + end + subject.action(:bar) do + when_invoked { "something" } + end + + subject.actions.should include(:bar) + subject.actions.should include(:foo) + end + + it "should be able to indicate when an action is defined" do + subject.action(:foo) { "something" } + subject.should be_action(:foo) + end + end + + describe "when used both at the class and instance level" do + before do + @klass = Class.new do + include Puppet::Interface::ActionManager + extend Puppet::Interface::ActionManager + end + @instance = @klass.new + end + + it "should be able to define an action at the class level" do + @klass.action(:foo) do + when_invoked { "something "} + end + end + + it "should create an instance method when an action is defined at the class level" do + @klass.action(:foo) do + when_invoked { "something" } + end + @instance.foo.should == "something" + end + + it "should be able to define an action at the instance level" do + @instance.action(:foo) do + when_invoked { "something "} + end + end + + it "should create an instance method when an action is defined at the instance level" do + @instance.action(:foo) do + when_invoked { "something" } + end + @instance.foo.should == "something" + end + + it "should be able to list actions defined at the class level" do + @klass.action(:foo) do + when_invoked { "something" } + end + @klass.action(:bar) do + when_invoked { "something" } + end + + @klass.actions.should include(:bar) + @klass.actions.should include(:foo) + end + + it "should be able to list actions defined at the instance level" do + @instance.action(:foo) do + when_invoked { "something" } + end + @instance.action(:bar) do + when_invoked { "something" } + end + + @instance.actions.should include(:bar) + @instance.actions.should include(:foo) + end + + it "should be able to list actions defined at both instance and class level" do + @klass.action(:foo) do + when_invoked { "something" } + end + @instance.action(:bar) do + when_invoked { "something" } + end + + @instance.actions.should include(:bar) + @instance.actions.should include(:foo) + end + + it "should be able to indicate when an action is defined at the class level" do + @klass.action(:foo) do + when_invoked { "something" } + end + @instance.should be_action(:foo) + end + + it "should be able to indicate when an action is defined at the instance level" do + @klass.action(:foo) do + when_invoked { "something" } + end + @instance.should be_action(:foo) + end + + it "should list actions defined in superclasses" do + @subclass = Class.new(@klass) + @instance = @subclass.new + + @klass.action(:parent) do + when_invoked { "a" } + end + @subclass.action(:sub) do + when_invoked { "a" } + end + @instance.action(:instance) do + when_invoked { "a" } + end + + @instance.should be_action(:parent) + @instance.should be_action(:sub) + @instance.should be_action(:instance) + end + + it "should create an instance method when an action is defined in a superclass" do + @subclass = Class.new(@klass) + @instance = @subclass.new + + @klass.action(:foo) do + when_invoked { "something" } + end + @instance.foo.should == "something" + end + end + + describe "#get_action" do + let :parent_class do + parent_class = Class.new(Puppet::Interface) + parent_class.action(:foo) {} + parent_class + end + + it "should check that we can find inherited actions when we are a class" do + Class.new(parent_class).get_action(:foo).name.should == :foo + end + + it "should check that we can find inherited actions when we are an instance" do + instance = parent_class.new(:foo, '0.0.0') + instance.get_action(:foo).name.should == :foo + end + end +end diff --git a/spec/unit/interface/action_spec.rb b/spec/unit/interface/action_spec.rb new file mode 100755 index 000000000..8c6782976 --- /dev/null +++ b/spec/unit/interface/action_spec.rb @@ -0,0 +1,172 @@ +#!/usr/bin/env rspec +require 'spec_helper' +require 'puppet/interface/action' + +describe Puppet::Interface::Action do + describe "when validating the action name" do + [nil, '', 'foo bar', '-foobar'].each do |input| + it "should treat #{input.inspect} as an invalid name" do + expect { Puppet::Interface::Action.new(nil, input) }. + should raise_error(/is an invalid action name/) + end + end + end + + describe "when invoking" do + it "should be able to call other actions on the same object" do + face = Puppet::Interface.new(:my_face, '0.0.1') do + action(:foo) do + when_invoked { 25 } + end + + action(:bar) do + when_invoked { "the value of foo is '#{foo}'" } + end + end + face.foo.should == 25 + face.bar.should == "the value of foo is '25'" + end + + # bar is a class action calling a class action + # quux is a class action calling an instance action + # baz is an instance action calling a class action + # qux is an instance action calling an instance action + it "should be able to call other actions on the same object when defined on a class" do + class Puppet::Interface::MyInterfaceBaseClass < Puppet::Interface + action(:foo) do + when_invoked { 25 } + end + + action(:bar) do + when_invoked { "the value of foo is '#{foo}'" } + end + + action(:quux) do + when_invoked { "qux told me #{qux}" } + end + end + + face = Puppet::Interface::MyInterfaceBaseClass.new(:my_inherited_face, '0.0.1') do + action(:baz) do + when_invoked { "the value of foo in baz is '#{foo}'" } + end + + action(:qux) do + when_invoked { baz } + end + end + face.foo.should == 25 + face.bar.should == "the value of foo is '25'" + face.quux.should == "qux told me the value of foo in baz is '25'" + face.baz.should == "the value of foo in baz is '25'" + face.qux.should == "the value of foo in baz is '25'" + end + + context "when calling the Ruby API" do + let :face do + Puppet::Interface.new(:ruby_api, '1.0.0') do + action :bar do + when_invoked do |options| + options + end + end + end + end + + it "should work when no options are supplied" do + options = face.bar + options.should == {} + end + + it "should work when options are supplied" do + options = face.bar :bar => "beer" + options.should == { :bar => "beer" } + end + end + end + + describe "with action-level options" do + it "should support options with an empty block" do + face = Puppet::Interface.new(:action_level_options, '0.0.1') do + action :foo do + option "--bar" do + # this line left deliberately blank + end + end + end + + face.should_not be_option :bar + face.get_action(:foo).should be_option :bar + end + + it "should return only action level options when there are no face options" do + face = Puppet::Interface.new(:action_level_options, '0.0.1') do + action :foo do option "--bar" end + end + + face.get_action(:foo).options.should =~ [:bar] + end + + describe "with both face and action options" do + let :face do + Puppet::Interface.new(:action_level_options, '0.0.1') do + action :foo do option "--bar" end + action :baz do option "--bim" end + option "--quux" + end + end + + it "should return combined face and action options" do + face.get_action(:foo).options.should =~ [:bar, :quux] + end + + it "should fetch options that the face inherited" do + parent = Class.new(Puppet::Interface) + parent.option "--foo" + child = parent.new(:inherited_options, '0.0.1') do + option "--bar" + action :action do option "--baz" end + end + + action = child.get_action(:action) + action.should be + + [:baz, :bar, :foo].each do |name| + action.get_option(name).should be_an_instance_of Puppet::Interface::Option + end + end + + it "should get an action option when asked" do + face.get_action(:foo).get_option(:bar). + should be_an_instance_of Puppet::Interface::Option + end + + it "should get a face option when asked" do + face.get_action(:foo).get_option(:quux). + should be_an_instance_of Puppet::Interface::Option + end + + it "should return options only for this action" do + face.get_action(:baz).options.should =~ [:bim, :quux] + end + end + + it_should_behave_like "things that declare options" do + def add_options_to(&block) + face = Puppet::Interface.new(:with_options, '0.0.1') do + action(:foo, &block) + end + face.get_action(:foo) + end + end + + it "should fail when a face option duplicates an action option" do + expect { + Puppet::Interface.new(:action_level_options, '0.0.1') do + option "--foo" + action :bar do option "--foo" end + end + }.should raise_error ArgumentError, /Option foo conflicts with existing option foo/i + end + end +end diff --git a/spec/unit/interface/face_collection_spec.rb b/spec/unit/interface/face_collection_spec.rb new file mode 100755 index 000000000..d1114dde7 --- /dev/null +++ b/spec/unit/interface/face_collection_spec.rb @@ -0,0 +1,170 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +require 'tmpdir' +require 'puppet/interface/face_collection' + +describe Puppet::Interface::FaceCollection do + # To avoid cross-pollution we have to save and restore both the hash + # containing all the interface data, and the array used by require. Restoring + # both means that we don't leak side-effects across the code. --daniel 2011-04-06 + # + # Worse luck, we *also* need to flush $" of anything defining a face, + # because otherwise we can cross-pollute from other test files and end up + # with no faces loaded, but the require value set true. --daniel 2011-04-10 + before :each do + @original_faces = subject.instance_variable_get("@faces").dup + @original_required = $".dup + $".delete_if do |path| path =~ %r{/face/.*\.rb$} end + subject.instance_variable_get("@faces").clear + end + + after :each do + subject.instance_variable_set("@faces", @original_faces) + $".clear ; @original_required.each do |item| $" << item end + end + + describe "::faces" do + it "REVISIT: should have some tests here, if we describe it" + end + + describe "::validate_version" do + it 'should permit three number versions' do + subject.validate_version('10.10.10').should == true + end + + it 'should permit versions with appended descriptions' do + subject.validate_version('10.10.10beta').should == true + end + + it 'should not permit versions with more than three numbers' do + subject.validate_version('1.2.3.4').should == false + end + + it 'should not permit versions with only two numbers' do + subject.validate_version('10.10').should == false + end + + it 'should not permit versions with only one number' do + subject.validate_version('123').should == false + end + + it 'should not permit versions with text in any position but at the end' do + subject.validate_version('v1.1.1').should == false + end + end + + describe "::[]" do + before :each do + subject.instance_variable_get("@faces")[:foo]['0.0.1'] = 10 + end + + it "should return the face with the given name" do + subject["foo", '0.0.1'].should == 10 + end + + it "should attempt to load the face if it isn't found" do + subject.expects(:require).with('puppet/face/bar') + subject["bar", '0.0.1'] + end + + it "should attempt to load the default face for the specified version :current" do + subject.expects(:require).with('puppet/face/fozzie') + subject['fozzie', :current] + end + end + + describe "::face?" do + it "should return true if the face specified is registered" do + subject.instance_variable_get("@faces")[:foo]['0.0.1'] = 10 + subject.face?("foo", '0.0.1').should == true + end + + it "should attempt to require the face if it is not registered" do + subject.expects(:require).with do |file| + subject.instance_variable_get("@faces")[:bar]['0.0.1'] = true + file == 'puppet/face/bar' + end + subject.face?("bar", '0.0.1').should == true + end + + it "should return true if requiring the face registered it" do + subject.stubs(:require).with do + subject.instance_variable_get("@faces")[:bar]['0.0.1'] = 20 + end + end + + it "should return false if the face is not registered" do + subject.stubs(:require).returns(true) + subject.face?("bar", '0.0.1').should be_false + end + + it "should return false if the face file itself is missing" do + subject.stubs(:require). + raises(LoadError, 'no such file to load -- puppet/face/bar') + subject.face?("bar", '0.0.1').should be_false + end + + it "should register the version loaded by `:current` as `:current`" do + subject.expects(:require).with do |file| + subject.instance_variable_get("@faces")[:huzzah]['2.0.1'] = :huzzah_face + file == 'puppet/face/huzzah' + end + subject.face?("huzzah", :current) + subject.instance_variable_get("@faces")[:huzzah][:current].should == :huzzah_face + end + + context "with something on disk" do + it "should register the version loaded from `puppet/face/{name}` as `:current`" do + subject.should be_face "huzzah", '2.0.1' + subject.should be_face "huzzah", :current + Puppet::Face[:huzzah, '2.0.1'].should == Puppet::Face[:huzzah, :current] + end + + it "should index :current when the code was pre-required" do + subject.instance_variable_get("@faces")[:huzzah].should_not be_key :current + require 'puppet/face/huzzah' + subject.face?(:huzzah, :current).should be_true + end + end + + it "should not cause an invalid face to be enumerated later" do + subject.face?(:there_is_no_face, :current).should be_false + subject.faces.should_not include :there_is_no_face + end + end + + describe "::register" do + it "should store the face by name" do + face = Puppet::Face.new(:my_face, '0.0.1') + subject.register(face) + subject.instance_variable_get("@faces").should == {:my_face => {'0.0.1' => face}} + end + end + + describe "::underscorize" do + faulty = [1, "#foo", "$bar", "sturm und drang", :"sturm und drang"] + valid = { + "Foo" => :foo, + :Foo => :foo, + "foo_bar" => :foo_bar, + :foo_bar => :foo_bar, + "foo-bar" => :foo_bar, + :"foo-bar" => :foo_bar, + } + + valid.each do |input, expect| + it "should map #{input.inspect} to #{expect.inspect}" do + result = subject.underscorize(input) + result.should == expect + end + end + + faulty.each do |input| + it "should fail when presented with #{input.inspect} (#{input.class})" do + expect { subject.underscorize(input) }. + should raise_error ArgumentError, /not a valid face name/ + end + end + end +end diff --git a/spec/unit/interface/option_builder_spec.rb b/spec/unit/interface/option_builder_spec.rb new file mode 100755 index 000000000..fae48324e --- /dev/null +++ b/spec/unit/interface/option_builder_spec.rb @@ -0,0 +1,29 @@ +require 'puppet/interface/option_builder' + +describe Puppet::Interface::OptionBuilder do + let :face do Puppet::Interface.new(:option_builder_testing, '0.0.1') end + + it "should be able to construct an option without a block" do + Puppet::Interface::OptionBuilder.build(face, "--foo"). + should be_an_instance_of Puppet::Interface::Option + end + + describe "when using the DSL block" do + it "should work with an empty block" do + option = Puppet::Interface::OptionBuilder.build(face, "--foo") do + # This block deliberately left blank. + end + + option.should be_an_instance_of Puppet::Interface::Option + end + + it "should support documentation declarations" do + text = "this is the description" + option = Puppet::Interface::OptionBuilder.build(face, "--foo") do + desc text + end + option.should be_an_instance_of Puppet::Interface::Option + option.desc.should == text + end + end +end diff --git a/spec/unit/interface/option_spec.rb b/spec/unit/interface/option_spec.rb new file mode 100755 index 000000000..3bcd121e2 --- /dev/null +++ b/spec/unit/interface/option_spec.rb @@ -0,0 +1,75 @@ +require 'puppet/interface/option' + +describe Puppet::Interface::Option do + let :face do Puppet::Interface.new(:option_testing, '0.0.1') end + + describe "#optparse_to_name" do + ["", "=BAR", " BAR", "=bar", " bar"].each do |postfix| + { "--foo" => :foo, "-f" => :f }.each do |base, expect| + input = base + postfix + it "should map #{input.inspect} to #{expect.inspect}" do + option = Puppet::Interface::Option.new(face, input) + option.name.should == expect + end + end + end + + [:foo, 12, nil, {}, []].each do |input| + it "should fail sensible when given #{input.inspect}" do + expect { Puppet::Interface::Option.new(face, input) }. + should raise_error ArgumentError, /is not valid for an option argument/ + end + end + + ["-foo", "-foo=BAR", "-foo BAR"].each do |input| + it "should fail with a single dash for long option #{input.inspect}" do + expect { Puppet::Interface::Option.new(face, input) }. + should raise_error ArgumentError, /long options need two dashes \(--\)/ + end + end + end + + it "requires a face when created" do + expect { Puppet::Interface::Option.new }. + should raise_error ArgumentError, /wrong number of arguments/ + end + + it "also requires some declaration arguments when created" do + expect { Puppet::Interface::Option.new(face) }. + should raise_error ArgumentError, /No option declarations found/ + end + + it "should infer the name from an optparse string" do + option = Puppet::Interface::Option.new(face, "--foo") + option.name.should == :foo + end + + it "should infer the name when multiple optparse string are given" do + option = Puppet::Interface::Option.new(face, "--foo", "-f") + option.name.should == :foo + end + + it "should prefer the first long option name over a short option name" do + option = Puppet::Interface::Option.new(face, "-f", "--foo") + option.name.should == :foo + end + + it "should create an instance when given a face and name" do + Puppet::Interface::Option.new(face, "--foo"). + should be_instance_of Puppet::Interface::Option + end + + describe "#to_s" do + it "should transform a symbol into a string" do + option = Puppet::Interface::Option.new(face, "--foo") + option.name.should == :foo + option.to_s.should == "foo" + end + + it "should use - rather than _ to separate words in strings but not symbols" do + option = Puppet::Interface::Option.new(face, "--foo-bar") + option.name.should == :foo_bar + option.to_s.should == "foo-bar" + end + end +end diff --git a/spec/unit/interface_spec.rb b/spec/unit/interface_spec.rb new file mode 100755 index 000000000..e52b45d8a --- /dev/null +++ b/spec/unit/interface_spec.rb @@ -0,0 +1,207 @@ +require 'spec_helper' +require 'puppet/face' +require 'puppet/interface' + +describe Puppet::Interface do + subject { Puppet::Interface } + + before :all do + @faces = Puppet::Interface::FaceCollection.instance_variable_get("@faces").dup + end + + before :each do + Puppet::Interface::FaceCollection.instance_variable_get("@faces").clear + end + + after :all do + Puppet::Interface::FaceCollection.instance_variable_set("@faces", @faces) + end + + describe "#[]" do + it "should fail when no version is requested" do + expect { subject[:huzzah] }.should raise_error ArgumentError + end + + it "should raise an exception when the requested version is unavailable" do + expect { subject[:huzzah, '17.0.0'] }.should raise_error, Puppet::Error + end + + it "should raise an exception when the requested face doesn't exist" do + expect { subject[:burrble_toot, :current] }.should raise_error, Puppet::Error + end + end + + describe "#define" do + it "should register the face" do + face = subject.define(:face_test_register, '0.0.1') + face.should == subject[:face_test_register, '0.0.1'] + end + + it "should load actions" do + subject.any_instance.expects(:load_actions) + subject.define(:face_test_load_actions, '0.0.1') + end + + it "should require a version number" do + expect { subject.define(:no_version) }.to raise_error ArgumentError + end + + it "should support summary builder and accessor methods" do + subject.new(:foo, '1.0.0').should respond_to(:summary).with(0).arguments + subject.new(:foo, '1.0.0').should respond_to(:summary=).with(1).arguments + end + + it "should set the summary text" do + text = "hello, freddy, my little pal" + subject.define(:face_test_summary, '1.0.0') do + summary text + end + subject[:face_test_summary, '1.0.0'].summary.should == text + end + + it "should support mutating the summary" do + text = "hello, freddy, my little pal" + subject.define(:face_test_summary, '1.0.0') do + summary text + end + subject[:face_test_summary, '1.0.0'].summary.should == text + subject[:face_test_summary, '1.0.0'].summary = text + text + subject[:face_test_summary, '1.0.0'].summary.should == text + text + end + end + + describe "#initialize" do + it "should require a version number" do + expect { subject.new(:no_version) }.to raise_error ArgumentError + end + + it "should require a valid version number" do + expect { subject.new(:bad_version, 'Rasins') }. + should raise_error ArgumentError + end + + it "should instance-eval any provided block" do + face = subject.new(:face_test_block, '0.0.1') do + action(:something) do + when_invoked { "foo" } + end + end + + face.something.should == "foo" + end + end + + it "should have a name" do + subject.new(:me, '0.0.1').name.should == :me + end + + it "should stringify with its own name" do + subject.new(:me, '0.0.1').to_s.should =~ /\bme\b/ + end + + it "should allow overriding of the default format" do + face = subject.new(:me, '0.0.1') + face.set_default_format :foo + face.default_format.should == :foo + end + + it "should default to :pson for its format" do + subject.new(:me, '0.0.1').default_format.should == :pson + end + + # Why? + it "should create a class-level autoloader" do + subject.autoloader.should be_instance_of(Puppet::Util::Autoload) + end + + it "should try to require faces that are not known" do + pending "mocking require causes random stack overflow" + subject::FaceCollection.expects(:require).with "puppet/face/foo" + subject[:foo, '0.0.1'] + end + + it "should be able to load all actions in all search paths" + + + it_should_behave_like "things that declare options" do + def add_options_to(&block) + subject.new(:with_options, '0.0.1', &block) + end + end + + describe "with face-level options" do + it "should not return any action-level options" do + face = subject.new(:with_options, '0.0.1') do + option "--foo" + option "--bar" + action :baz do + option "--quux" + end + end + face.options.should =~ [:foo, :bar] + end + + it "should fail when a face option duplicates an action option" do + expect { + subject.new(:action_level_options, '0.0.1') do + action :bar do option "--foo" end + option "--foo" + end + }.should raise_error ArgumentError, /Option foo conflicts with existing option foo on/i + end + + it "should work when two actions have the same option" do + face = subject.new(:with_options, '0.0.1') do + action :foo do option "--quux" end + action :bar do option "--quux" end + end + + face.get_action(:foo).options.should =~ [:quux] + face.get_action(:bar).options.should =~ [:quux] + end + end + + describe "with inherited options" do + let :parent do + parent = Class.new(subject) + parent.option("--inherited") + parent.action(:parent_action) do end + parent + end + + let :face do + face = parent.new(:example, '0.2.1') + face.option("--local") + face.action(:face_action) do end + face + end + + describe "#options" do + it "should list inherited options" do + face.options.should =~ [:inherited, :local] + end + + it "should see all options on face actions" do + face.get_action(:face_action).options.should =~ [:inherited, :local] + end + + it "should see all options on inherited actions accessed on the subclass" do + face.get_action(:parent_action).options.should =~ [:inherited, :local] + end + + it "should not see subclass actions on the parent class" do + parent.options.should =~ [:inherited] + end + + it "should not see subclass actions on actions accessed on the parent class" do + parent.get_action(:parent_action).options.should =~ [:inherited] + end + end + + describe "#get_option" do + it "should return an inherited option object" do + face.get_option(:inherited).should be_an_instance_of subject::Option + end + end + end +end diff --git a/spec/unit/module_spec.rb b/spec/unit/module_spec.rb index f3120e16b..8d38657f9 100755 --- a/spec/unit/module_spec.rb +++ b/spec/unit/module_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet_spec/files' describe Puppet::Module do diff --git a/spec/unit/network/authconfig_spec.rb b/spec/unit/network/authconfig_spec.rb index 9d69e99ac..c47b2e0c5 100755 --- a/spec/unit/network/authconfig_spec.rb +++ b/spec/unit/network/authconfig_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/network/authconfig' diff --git a/spec/unit/network/authstore_spec.rb b/spec/unit/network/authstore_spec.rb index d477ee301..d62c8abaa 100644..100755 --- a/spec/unit/network/authstore_spec.rb +++ b/spec/unit/network/authstore_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/network/authconfig' diff --git a/spec/unit/network/client_spec.rb b/spec/unit/network/client_spec.rb index 820f10f12..102a053c0 100755 --- a/spec/unit/network/client_spec.rb +++ b/spec/unit/network/client_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-3-24. # Copyright (c) 2008. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/network/client' diff --git a/spec/unit/network/format_handler_spec.rb b/spec/unit/network/format_handler_spec.rb index 556fada80..8b535c3ab 100755 --- a/spec/unit/network/format_handler_spec.rb +++ b/spec/unit/network/format_handler_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/network/format_handler' diff --git a/spec/unit/network/format_spec.rb b/spec/unit/network/format_spec.rb index 658729e4c..f59593479 100755 --- a/spec/unit/network/format_spec.rb +++ b/spec/unit/network/format_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/network/format' diff --git a/spec/unit/network/formats_spec.rb b/spec/unit/network/formats_spec.rb index 30e88c578..72d355192 100755 --- a/spec/unit/network/formats_spec.rb +++ b/spec/unit/network/formats_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/network/formats' diff --git a/spec/unit/network/handler/fileserver_spec.rb b/spec/unit/network/handler/fileserver_spec.rb index 014b82e69..52c4a71f5 100644..100755 --- a/spec/unit/network/handler/fileserver_spec.rb +++ b/spec/unit/network/handler/fileserver_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/network/handler/fileserver' diff --git a/spec/unit/network/http/api/v1_spec.rb b/spec/unit/network/http/api/v1_spec.rb index 257eec5de..bd95071c1 100644..100755 --- a/spec/unit/network/http/api/v1_spec.rb +++ b/spec/unit/network/http/api/v1_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/network/http/api/v1' @@ -68,6 +67,10 @@ describe Puppet::Network::HTTP::API::V1 do @tester.uri2indirection("GET", "/env/foo/bar", {})[1].should == :find end + it "should choose 'find' as the indirection method if the http method is a POST and the indirection name is singular" do + @tester.uri2indirection("POST", "/env/foo/bar", {})[1].should == :find + end + it "should choose 'head' as the indirection method if the http method is a HEAD and the indirection name is singular" do @tester.uri2indirection("HEAD", "/env/foo/bar", {})[1].should == :head end @@ -164,4 +167,26 @@ describe Puppet::Network::HTTP::API::V1 do end end + describe "when converting a request into a URI with body" do + before :each do + @request = Puppet::Indirector::Request.new(:foo, :find, "with spaces", :foo => :bar, :environment => "myenv") + end + + it "should use the environment as the first field of the URI" do + @tester.request_to_uri_and_body(@request).first.split("/")[1].should == "myenv" + end + + it "should use the indirection as the second field of the URI" do + @tester.request_to_uri_and_body(@request).first.split("/")[2].should == "foo" + end + + it "should use the escaped key as the remainder of the URI" do + escaped = URI.escape("with spaces") + @tester.request_to_uri_and_body(@request).first.split("/")[3].sub(/\?.+/, '').should == escaped + end + + it "should return the URI and body separately" do + @tester.request_to_uri_and_body(@request).should == ["/myenv/foo/with%20spaces", "foo=bar"] + end + end end diff --git a/spec/unit/network/http/compression_spec.rb b/spec/unit/network/http/compression_spec.rb index 85c62f358..5c919c6c5 100755 --- a/spec/unit/network/http/compression_spec.rb +++ b/spec/unit/network/http/compression_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe "http compression" do diff --git a/spec/unit/network/http/handler_spec.rb b/spec/unit/network/http/handler_spec.rb index 97d17fcf8..83969c504 100755 --- a/spec/unit/network/http/handler_spec.rb +++ b/spec/unit/network/http/handler_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/network/http/handler' require 'puppet/network/rest_authorization' diff --git a/spec/unit/network/http/mongrel/rest_spec.rb b/spec/unit/network/http/mongrel/rest_spec.rb index 086fec522..3e454cf8f 100755 --- a/spec/unit/network/http/mongrel/rest_spec.rb +++ b/spec/unit/network/http/mongrel/rest_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/network/http' diff --git a/spec/unit/network/http/mongrel_spec.rb b/spec/unit/network/http/mongrel_spec.rb index 5a67a3fae..56d0afbed 100755 --- a/spec/unit/network/http/mongrel_spec.rb +++ b/spec/unit/network/http/mongrel_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Rick Bradley on 2007-10-15. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/network/http' describe "Puppet::Network::HTTP::Mongrel", "after initializing", :if => Puppet.features.mongrel? do diff --git a/spec/unit/network/http/rack/rest_spec.rb b/spec/unit/network/http/rack/rest_spec.rb index dd49fa057..8a5666f56 100755 --- a/spec/unit/network/http/rack/rest_spec.rb +++ b/spec/unit/network/http/rack/rest_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/network/http/rack' if Puppet.features.rack? require 'puppet/network/http/rack/rest' diff --git a/spec/unit/network/http/rack/xmlrpc_spec.rb b/spec/unit/network/http/rack/xmlrpc_spec.rb index e8ae47bf7..9173438a6 100755 --- a/spec/unit/network/http/rack/xmlrpc_spec.rb +++ b/spec/unit/network/http/rack/xmlrpc_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/network/handler' require 'puppet/network/http/rack' if Puppet.features.rack? require 'puppet/network/http/rack/xmlrpc' if Puppet.features.rack? diff --git a/spec/unit/network/http/rack_spec.rb b/spec/unit/network/http/rack_spec.rb index 75d3fdb90..9e1ee3d1e 100755 --- a/spec/unit/network/http/rack_spec.rb +++ b/spec/unit/network/http/rack_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/network/handler' require 'puppet/network/http/rack' if Puppet.features.rack? diff --git a/spec/unit/network/http/webrick/rest_spec.rb b/spec/unit/network/http/webrick/rest_spec.rb index b1491e32e..267ddcc72 100755 --- a/spec/unit/network/http/webrick/rest_spec.rb +++ b/spec/unit/network/http/webrick/rest_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/network/http' require 'webrick' require 'puppet/network/http/webrick/rest' diff --git a/spec/unit/network/http/webrick_spec.rb b/spec/unit/network/http/webrick_spec.rb index b27a941ea..be74a1052 100755 --- a/spec/unit/network/http/webrick_spec.rb +++ b/spec/unit/network/http/webrick_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Rick Bradley on 2007-10-15. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/network/handler' require 'puppet/network/http' require 'puppet/network/http/webrick' diff --git a/spec/unit/network/http_pool_spec.rb b/spec/unit/network/http_pool_spec.rb index 2cd96cea4..c5d3e0470 100755 --- a/spec/unit/network/http_pool_spec.rb +++ b/spec/unit/network/http_pool_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-11-26. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/network/http_pool' describe Puppet::Network::HttpPool do diff --git a/spec/unit/network/http_spec.rb b/spec/unit/network/http_spec.rb index 8422e2113..550c15bf7 100755 --- a/spec/unit/network/http_spec.rb +++ b/spec/unit/network/http_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Rick Bradley on 2007-10-03. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/network/http' diff --git a/spec/unit/network/rest_authconfig_spec.rb b/spec/unit/network/rest_authconfig_spec.rb index e0bcb5af0..499a14b78 100755 --- a/spec/unit/network/rest_authconfig_spec.rb +++ b/spec/unit/network/rest_authconfig_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/network/rest_authconfig' diff --git a/spec/unit/network/rights_spec.rb b/spec/unit/network/rights_spec.rb index 8ae03c56d..b709f10fa 100755 --- a/spec/unit/network/rights_spec.rb +++ b/spec/unit/network/rights_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/network/rights' diff --git a/spec/unit/network/server_spec.rb b/spec/unit/network/server_spec.rb index 2a63cd4ec..912275a20 100755 --- a/spec/unit/network/server_spec.rb +++ b/spec/unit/network/server_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Rick Bradley on 2007-10-03. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/network/server' require 'puppet/network/handler' diff --git a/spec/unit/network/xmlrpc/client_spec.rb b/spec/unit/network/xmlrpc/client_spec.rb index 7498ca4cf..b9be0a906 100755 --- a/spec/unit/network/xmlrpc/client_spec.rb +++ b/spec/unit/network/xmlrpc/client_spec.rb @@ -1,7 +1,7 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec require 'puppet/network/client' -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' describe Puppet::Network::XMLRPCClient do describe "when performing the rpc call" do diff --git a/spec/unit/node/environment_spec.rb b/spec/unit/node/environment_spec.rb index d34bdb000..d1badfa3a 100755 --- a/spec/unit/node/environment_spec.rb +++ b/spec/unit/node/environment_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/node/environment' require 'puppet/util/execution' diff --git a/spec/unit/node/facts_spec.rb b/spec/unit/node/facts_spec.rb index 797009ae4..a130ae3f8 100755 --- a/spec/unit/node/facts_spec.rb +++ b/spec/unit/node/facts_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/node/facts' diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index ec1b65ee1..7d813ba30 100755 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Node do describe "when managing its environment" do diff --git a/spec/unit/other/selinux_spec.rb b/spec/unit/other/selinux_spec.rb index 7f908885f..216feaf1f 100644..100755 --- a/spec/unit/other/selinux_spec.rb +++ b/spec/unit/other/selinux_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/type/selboolean' require 'puppet/type/selmodule' diff --git a/spec/unit/other/transbucket_spec.rb b/spec/unit/other/transbucket_spec.rb index 6bc257897..b95a4abca 100755 --- a/spec/unit/other/transbucket_spec.rb +++ b/spec/unit/other/transbucket_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::TransBucket do before do diff --git a/spec/unit/other/transobject_spec.rb b/spec/unit/other/transobject_spec.rb index c2652a386..4715e2fa1 100755 --- a/spec/unit/other/transobject_spec.rb +++ b/spec/unit/other/transobject_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/transportable' diff --git a/spec/unit/parameter/path_spec.rb b/spec/unit/parameter/path_spec.rb index 08a26de33..d113a1581 100644..100755 --- a/spec/unit/parameter/path_spec.rb +++ b/spec/unit/parameter/path_spec.rb @@ -1,5 +1,5 @@ -#!/usr/bin/env ruby -require File.expand_path(File.join(File.dirname(__FILE__), '../../spec_helper')) +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/parameter/path' diff --git a/spec/unit/parameter/value_collection_spec.rb b/spec/unit/parameter/value_collection_spec.rb index 99e4302bc..af70160c1 100755 --- a/spec/unit/parameter/value_collection_spec.rb +++ b/spec/unit/parameter/value_collection_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/parameter' diff --git a/spec/unit/parameter/value_spec.rb b/spec/unit/parameter/value_spec.rb index cb44770b4..f3414e4e0 100755 --- a/spec/unit/parameter/value_spec.rb +++ b/spec/unit/parameter/value_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/parameter' diff --git a/spec/unit/parameter_spec.rb b/spec/unit/parameter_spec.rb index c9ef32faf..04556c013 100755 --- a/spec/unit/parameter_spec.rb +++ b/spec/unit/parameter_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/parameter' diff --git a/spec/unit/parser/ast/arithmetic_operator_spec.rb b/spec/unit/parser/ast/arithmetic_operator_spec.rb index 381c5c629..144ebd78c 100755 --- a/spec/unit/parser/ast/arithmetic_operator_spec.rb +++ b/spec/unit/parser/ast/arithmetic_operator_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::ArithmeticOperator do @@ -60,14 +59,4 @@ describe Puppet::Parser::AST::ArithmeticOperator do operator.evaluate(@scope).should == 4.33 end - it "should work for variables too" do - @scope.expects(:lookupvar).with("one", false).returns(1) - @scope.expects(:lookupvar).with("two", false).returns(2) - one = ast::Variable.new( :value => "one" ) - two = ast::Variable.new( :value => "two" ) - - operator = ast::ArithmeticOperator.new :lval => one, :operator => "+", :rval => two - operator.evaluate(@scope).should == 3 - end - end diff --git a/spec/unit/parser/ast/astarray_spec.rb b/spec/unit/parser/ast/astarray_spec.rb index 01082b3f0..a3f56052a 100755 --- a/spec/unit/parser/ast/astarray_spec.rb +++ b/spec/unit/parser/ast/astarray_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::ASTArray do before :each do diff --git a/spec/unit/parser/ast/asthash_spec.rb b/spec/unit/parser/ast/asthash_spec.rb index 83f604545..d7fbbfae9 100644..100755 --- a/spec/unit/parser/ast/asthash_spec.rb +++ b/spec/unit/parser/ast/asthash_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::ASTHash do before :each do diff --git a/spec/unit/parser/ast/boolean_operator_spec.rb b/spec/unit/parser/ast/boolean_operator_spec.rb index 529946694..287f466a7 100755 --- a/spec/unit/parser/ast/boolean_operator_spec.rb +++ b/spec/unit/parser/ast/boolean_operator_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::BooleanOperator do diff --git a/spec/unit/parser/ast/casestatement_spec.rb b/spec/unit/parser/ast/casestatement_spec.rb index bce3ad801..e21190706 100755 --- a/spec/unit/parser/ast/casestatement_spec.rb +++ b/spec/unit/parser/ast/casestatement_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::CaseStatement do before :each do diff --git a/spec/unit/parser/ast/collection_spec.rb b/spec/unit/parser/ast/collection_spec.rb index 99abc998d..78094e68d 100755 --- a/spec/unit/parser/ast/collection_spec.rb +++ b/spec/unit/parser/ast/collection_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::Collection do before :each do diff --git a/spec/unit/parser/ast/collexpr_spec.rb b/spec/unit/parser/ast/collexpr_spec.rb index 04ce69cd3..454e7481b 100755 --- a/spec/unit/parser/ast/collexpr_spec.rb +++ b/spec/unit/parser/ast/collexpr_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::CollExpr do diff --git a/spec/unit/parser/ast/comparison_operator_spec.rb b/spec/unit/parser/ast/comparison_operator_spec.rb index 03c9069cb..96f4562e9 100755 --- a/spec/unit/parser/ast/comparison_operator_spec.rb +++ b/spec/unit/parser/ast/comparison_operator_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::ComparisonOperator do before :each do @@ -95,8 +94,8 @@ describe Puppet::Parser::AST::ComparisonOperator do one = Puppet::Parser::AST::Variable.new( :value => "one" ) two = Puppet::Parser::AST::Variable.new( :value => "two" ) - @scope.expects(:lookupvar).with("one", false).returns(1) - @scope.expects(:lookupvar).with("two", false).returns(2) + one.expects(:safeevaluate).with(@scope).returns(1) + two.expects(:safeevaluate).with(@scope).returns(2) operator = Puppet::Parser::AST::ComparisonOperator.new :lval => one, :operator => "<", :rval => two operator.evaluate(@scope).should == true diff --git a/spec/unit/parser/ast/definition_spec.rb b/spec/unit/parser/ast/definition_spec.rb index e7f55d258..8b2f7f26f 100644..100755 --- a/spec/unit/parser/ast/definition_spec.rb +++ b/spec/unit/parser/ast/definition_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::Definition do it "should make its context available through an accessor" do diff --git a/spec/unit/parser/ast/function_spec.rb b/spec/unit/parser/ast/function_spec.rb index cd4b0f94e..c52e806e9 100644..100755 --- a/spec/unit/parser/ast/function_spec.rb +++ b/spec/unit/parser/ast/function_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::Function do before :each do diff --git a/spec/unit/parser/ast/hostclass_spec.rb b/spec/unit/parser/ast/hostclass_spec.rb index 390490788..ee154fac8 100644..100755 --- a/spec/unit/parser/ast/hostclass_spec.rb +++ b/spec/unit/parser/ast/hostclass_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::Hostclass do def ast diff --git a/spec/unit/parser/ast/ifstatement_spec.rb b/spec/unit/parser/ast/ifstatement_spec.rb index 6a2fed22c..4b6e0b8e5 100755 --- a/spec/unit/parser/ast/ifstatement_spec.rb +++ b/spec/unit/parser/ast/ifstatement_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::IfStatement do before :each do diff --git a/spec/unit/parser/ast/in_operator_spec.rb b/spec/unit/parser/ast/in_operator_spec.rb index 08c01582e..b6b6fbb89 100644..100755 --- a/spec/unit/parser/ast/in_operator_spec.rb +++ b/spec/unit/parser/ast/in_operator_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/parser/ast/in_operator' diff --git a/spec/unit/parser/ast/leaf_spec.rb b/spec/unit/parser/ast/leaf_spec.rb index 2119a27a8..ff3fed5e9 100755 --- a/spec/unit/parser/ast/leaf_spec.rb +++ b/spec/unit/parser/ast/leaf_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::Leaf do before :each do @@ -107,7 +106,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do describe "when evaluating" do it "should evaluate the variable part if necessary" do - @scope.stubs(:lookupvar).with("a").returns(["b"]) + @scope.stubs(:lookupvar).with { |name,options| name == 'a'}.returns(["b"]) variable = stub 'variable', :evaluate => "a" access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => variable, :key => 0 ) @@ -118,7 +117,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do end it "should evaluate the access key part if necessary" do - @scope.stubs(:lookupvar).with("a").returns(["b"]) + @scope.stubs(:lookupvar).with { |name,options| name == 'a'}.returns(["b"]) index = stub 'index', :evaluate => 0 access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => index ) @@ -129,7 +128,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do end it "should be able to return an array member" do - @scope.stubs(:lookupvar).with("a").returns(["val1", "val2", "val3"]) + @scope.stubs(:lookupvar).with { |name,options| name == 'a'}.returns(["val1", "val2", "val3"]) access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => 1 ) @@ -137,7 +136,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do end it "should be able to return an array member when index is a stringified number" do - @scope.stubs(:lookupvar).with("a").returns(["val1", "val2", "val3"]) + @scope.stubs(:lookupvar).with { |name,options| name == "a" }.returns(["val1", "val2", "val3"]) access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "1" ) @@ -145,7 +144,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do end it "should raise an error when accessing an array with a key" do - @scope.stubs(:lookupvar).with("a").returns(["val1", "val2", "val3"]) + @scope.stubs(:lookupvar).with { |name,options| name == "a"}.returns(["val1", "val2", "val3"]) access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "get_me_the_second_element_please" ) @@ -153,7 +152,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do end it "should be able to return an hash value" do - @scope.stubs(:lookupvar).with("a").returns({ "key1" => "val1", "key2" => "val2", "key3" => "val3" }) + @scope.stubs(:lookupvar).with { |name,options| name == 'a'}.returns({ "key1" => "val1", "key2" => "val2", "key3" => "val3" }) access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "key2" ) @@ -161,7 +160,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do end it "should be able to return an hash value with a numerical key" do - @scope.stubs(:lookupvar).with("a").returns({ "key1" => "val1", "key2" => "val2", "45" => "45", "key3" => "val3" }) + @scope.stubs(:lookupvar).with { |name,options| name == "a"}.returns({ "key1" => "val1", "key2" => "val2", "45" => "45", "key3" => "val3" }) access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "45" ) @@ -169,7 +168,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do end it "should raise an error if the variable lookup didn't return an hash or an array" do - @scope.stubs(:lookupvar).with("a").returns("I'm a string") + @scope.stubs(:lookupvar).with { |name,options| name == "a"}.returns("I'm a string") access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "key2" ) @@ -177,7 +176,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do end it "should raise an error if the variable wasn't in the scope" do - @scope.stubs(:lookupvar).with("a").returns(nil) + @scope.stubs(:lookupvar).with { |name,options| name == 'a'}.returns(nil) access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "key2" ) @@ -190,7 +189,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do end it "should work with recursive hash access" do - @scope.stubs(:lookupvar).with("a").returns({ "key" => { "subkey" => "b" }}) + @scope.stubs(:lookupvar).with { |name,options| name == 'a'}.returns({ "key" => { "subkey" => "b" }}) access1 = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "key") access2 = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => access1, :key => "subkey") @@ -199,7 +198,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do end it "should work with interleaved array and hash access" do - @scope.stubs(:lookupvar).with("a").returns({ "key" => [ "a" , "b" ]}) + @scope.stubs(:lookupvar).with { |name,options| name == 'a'}.returns({ "key" => [ "a" , "b" ]}) access1 = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "key") access2 = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => access1, :key => 1) @@ -220,7 +219,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do end it "should raise an error when assigning an array element with a key" do - @scope.stubs(:lookupvar).with("a").returns([]) + @scope.stubs(:lookupvar).with { |name,options| name == "a"}.returns([]) access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "get_me_the_second_element_please" ) @@ -238,7 +237,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do end it "should raise an error when trying to overwrite an hash value" do - @scope.stubs(:lookupvar).with("a").returns({ "key" => [ "a" , "b" ]}) + @scope.stubs(:lookupvar).with { |name,options| name == "a" }.returns({ "key" => [ "a" , "b" ]}) access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "key") lambda { access.assign(@scope, "test") }.should raise_error @@ -332,16 +331,21 @@ end describe Puppet::Parser::AST::Variable do before :each do @scope = stub 'scope' - @var = Puppet::Parser::AST::Variable.new(:value => "myvar") + @var = Puppet::Parser::AST::Variable.new(:value => "myvar", :file => 'my.pp', :line => 222) end it "should lookup the variable in scope" do - @scope.expects(:lookupvar).with("myvar", false).returns(:myvalue) + @scope.expects(:lookupvar).with { |name,options| name == "myvar" }.returns(:myvalue) + @var.safeevaluate(@scope).should == :myvalue + end + + it "should pass the source location to lookupvar" do + @scope.expects(:lookupvar).with { |name,options| name == "myvar" and options[:file] == 'my.pp' and options[:line] == 222 }.returns(:myvalue) @var.safeevaluate(@scope).should == :myvalue end it "should return undef if the variable wasn't set" do - @scope.expects(:lookupvar).with("myvar", false).returns(:undefined) + @scope.expects(:lookupvar).with { |name,options| name == "myvar" }.returns(:undefined) @var.safeevaluate(@scope).should == :undef end diff --git a/spec/unit/parser/ast/match_operator_spec.rb b/spec/unit/parser/ast/match_operator_spec.rb index f2a68b676..0f9235aeb 100755 --- a/spec/unit/parser/ast/match_operator_spec.rb +++ b/spec/unit/parser/ast/match_operator_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::MatchOperator do before :each do diff --git a/spec/unit/parser/ast/minus_spec.rb b/spec/unit/parser/ast/minus_spec.rb index 339087e80..8ebd14e80 100755 --- a/spec/unit/parser/ast/minus_spec.rb +++ b/spec/unit/parser/ast/minus_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::Minus do before :each do diff --git a/spec/unit/parser/ast/node_spec.rb b/spec/unit/parser/ast/node_spec.rb index c4e20ca67..c2e187184 100644..100755 --- a/spec/unit/parser/ast/node_spec.rb +++ b/spec/unit/parser/ast/node_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::Node do describe "when instantiated" do diff --git a/spec/unit/parser/ast/nop_spec.rb b/spec/unit/parser/ast/nop_spec.rb index 3fa2fc0ee..81302fa55 100755 --- a/spec/unit/parser/ast/nop_spec.rb +++ b/spec/unit/parser/ast/nop_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::Nop do diff --git a/spec/unit/parser/ast/not_spec.rb b/spec/unit/parser/ast/not_spec.rb index 31a425132..6569af699 100755 --- a/spec/unit/parser/ast/not_spec.rb +++ b/spec/unit/parser/ast/not_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::Not do before :each do diff --git a/spec/unit/parser/ast/relationship_spec.rb b/spec/unit/parser/ast/relationship_spec.rb index d8bc3a535..441ac45b1 100644..100755 --- a/spec/unit/parser/ast/relationship_spec.rb +++ b/spec/unit/parser/ast/relationship_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::Relationship do before do diff --git a/spec/unit/parser/ast/resource_defaults_spec.rb b/spec/unit/parser/ast/resource_defaults_spec.rb index 36eb8df5f..8164828e1 100755 --- a/spec/unit/parser/ast/resource_defaults_spec.rb +++ b/spec/unit/parser/ast/resource_defaults_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::ResourceDefaults do diff --git a/spec/unit/parser/ast/resource_override_spec.rb b/spec/unit/parser/ast/resource_override_spec.rb index 7ca3a7e8c..458d9a4bf 100755 --- a/spec/unit/parser/ast/resource_override_spec.rb +++ b/spec/unit/parser/ast/resource_override_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::ResourceOverride do diff --git a/spec/unit/parser/ast/resource_reference_spec.rb b/spec/unit/parser/ast/resource_reference_spec.rb index 492c25490..627754dd1 100755 --- a/spec/unit/parser/ast/resource_reference_spec.rb +++ b/spec/unit/parser/ast/resource_reference_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::ResourceReference do diff --git a/spec/unit/parser/ast/resource_spec.rb b/spec/unit/parser/ast/resource_spec.rb index b00fee587..68ad9c229 100755 --- a/spec/unit/parser/ast/resource_spec.rb +++ b/spec/unit/parser/ast/resource_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::Resource do ast = Puppet::Parser::AST diff --git a/spec/unit/parser/ast/selector_spec.rb b/spec/unit/parser/ast/selector_spec.rb index 4c13aa7ba..1bf5f6757 100755 --- a/spec/unit/parser/ast/selector_spec.rb +++ b/spec/unit/parser/ast/selector_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::Selector do before :each do diff --git a/spec/unit/parser/ast/vardef_spec.rb b/spec/unit/parser/ast/vardef_spec.rb index 9c8b77905..7dd2b31e7 100755 --- a/spec/unit/parser/ast/vardef_spec.rb +++ b/spec/unit/parser/ast/vardef_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::AST::VarDef do before :each do @@ -16,8 +15,7 @@ describe Puppet::Parser::AST::VarDef do name.expects(:safeevaluate).with(@scope) value.expects(:safeevaluate).with(@scope) - vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil, - :line => nil + vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil, :line => nil vardef.evaluate(@scope) end @@ -27,8 +25,7 @@ describe Puppet::Parser::AST::VarDef do @scope.expects(:setvar).with { |name,value,options| options[:append] == nil } - vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil, - :line => nil + vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil, :line => nil vardef.evaluate(@scope) end @@ -38,8 +35,17 @@ describe Puppet::Parser::AST::VarDef do @scope.expects(:setvar).with { |name,value,options| options[:append] == true } - vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil, - :line => nil, :append => true + vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil, :line => nil, :append => true + vardef.evaluate(@scope) + end + + it "should call pass the source location to setvar" do + name = stub 'name', :safeevaluate => "var" + value = stub 'value', :safeevaluate => "1" + + @scope.expects(:setvar).with { |name,value,options| options[:file] == 'setvar.pp' and options[:line] == 917 } + + vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => 'setvar.pp', :line => 917 vardef.evaluate(@scope) end diff --git a/spec/unit/parser/ast_spec.rb b/spec/unit/parser/ast_spec.rb index cdfb51869..4d4871219 100644..100755 --- a/spec/unit/parser/ast_spec.rb +++ b/spec/unit/parser/ast_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/parser/ast' diff --git a/spec/unit/parser/collector_spec.rb b/spec/unit/parser/collector_spec.rb index 100a04daf..01918d2a0 100755 --- a/spec/unit/parser/collector_spec.rb +++ b/spec/unit/parser/collector_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/rails' require 'puppet/parser/collector' diff --git a/spec/unit/parser/compiler_spec.rb b/spec/unit/parser/compiler_spec.rb index e4b18e14b..ced760b76 100755 --- a/spec/unit/parser/compiler_spec.rb +++ b/spec/unit/parser/compiler_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' class CompilerTestResource attr_accessor :builtin, :virtual, :evaluated, :type, :title @@ -131,10 +130,6 @@ describe Puppet::Parser::Compiler do @compiler.newscope(@compiler.topscope).should be_instance_of(Puppet::Parser::Scope) end - it "should correctly set the level of newly created scopes" do - @compiler.newscope(@compiler.topscope, :level => 5).level.should == 5 - end - it "should set the parent scope of the new scope to be the passed-in parent" do scope = mock 'scope' newscope = @compiler.newscope(scope) diff --git a/spec/unit/parser/files_spec.rb b/spec/unit/parser/files_spec.rb index 525c83697..04777f0ec 100644..100755 --- a/spec/unit/parser/files_spec.rb +++ b/spec/unit/parser/files_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/parser/files' diff --git a/spec/unit/parser/functions/create_resources_spec.rb b/spec/unit/parser/functions/create_resources_spec.rb index 366fb536c..88a67e369 100755 --- a/spec/unit/parser/functions/create_resources_spec.rb +++ b/spec/unit/parser/functions/create_resources_spec.rb @@ -1,5 +1,5 @@ require 'puppet' -require File.dirname(__FILE__) + '/../../../spec_helper' +require 'spec_helper' describe 'function for dynamically creating resources' do diff --git a/spec/unit/parser/functions/defined_spec.rb b/spec/unit/parser/functions/defined_spec.rb index 0113c3233..0651864fb 100755 --- a/spec/unit/parser/functions/defined_spec.rb +++ b/spec/unit/parser/functions/defined_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe "the 'defined' function" do before :all do diff --git a/spec/unit/parser/functions/extlookup_spec.rb b/spec/unit/parser/functions/extlookup_spec.rb index 46cd3cc27..f68daaf3f 100755 --- a/spec/unit/parser/functions/extlookup_spec.rb +++ b/spec/unit/parser/functions/extlookup_spec.rb @@ -1,6 +1,5 @@ -#! /usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'tempfile' describe "the extlookup function" do @@ -65,7 +64,7 @@ describe "the extlookup function" do describe "should look in $extlookup_datadir for data files listed by $extlookup_precedence" do before do - @scope.stubs(:lookupvar).with('extlookup_datadir').returns("/tmp") + @scope.stubs(:lookupvar).with('::extlookup_datadir').returns("/tmp") File.open("/tmp/one.csv","w"){|one| one.puts "key,value1" } File.open("/tmp/two.csv","w") do |two| two.puts "key,value2" @@ -74,21 +73,21 @@ describe "the extlookup function" do end it "when the key is in the first file" do - @scope.stubs(:lookupvar).with('extlookup_precedence').returns(["one","two"]) + @scope.stubs(:lookupvar).with('::extlookup_precedence').returns(["one","two"]) result = @scope.function_extlookup([ "key" ]) result.should == "value1" end it "when the key is in the second file" do - @scope.stubs(:lookupvar).with('extlookup_precedence').returns(["one","two"]) + @scope.stubs(:lookupvar).with('::extlookup_precedence').returns(["one","two"]) result = @scope.function_extlookup([ "key2" ]) result.should == "value_two" end it "should not modify extlookup_precedence data" do variable = '%{fqdn}' - @scope.stubs(:lookupvar).with('extlookup_precedence').returns([variable,"one"]) - @scope.stubs(:lookupvar).with('fqdn').returns('myfqdn') + @scope.stubs(:lookupvar).with('::extlookup_precedence').returns([variable,"one"]) + @scope.stubs(:lookupvar).with('::fqdn').returns('myfqdn') result = @scope.function_extlookup([ "key" ]) variable.should == '%{fqdn}' end diff --git a/spec/unit/parser/functions/fqdn_rand_spec.rb b/spec/unit/parser/functions/fqdn_rand_spec.rb index be2e6fa76..90fc0ef41 100755 --- a/spec/unit/parser/functions/fqdn_rand_spec.rb +++ b/spec/unit/parser/functions/fqdn_rand_spec.rb @@ -1,6 +1,5 @@ -#! /usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe "the fqdn_rand function" do before :all do @@ -16,49 +15,49 @@ describe "the fqdn_rand function" do end it "should handle 0 arguments" do - @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1") + @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1") lambda { @scope.function_fqdn_rand([]) }.should_not raise_error(Puppet::ParseError) end it "should handle 1 argument'}" do - @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1") + @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1") lambda { @scope.function_fqdn_rand([3]) }.should_not raise_error(Puppet::ParseError) end (1..10).each { |n| it "should handle #{n} additional arguments" do - @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1") + @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1") lambda { @scope.function_fqdn_rand([3,1,2,3,4,5,6,7,8,9,10][0..n]) }.should_not raise_error(Puppet::ParseError) end it "should handle #{n} additional string arguments" do - @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1") + @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1") lambda { @scope.function_fqdn_rand([3,%w{ 1 2 3 4 5 6 7 8 9 10}].flatten[0..n]) }.should_not raise_error(Puppet::ParseError) end } it "should return a value less than max" do - @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1") + @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1") @scope.function_fqdn_rand([3]).should satisfy {|n| n.to_i < 3 } end it "should return the same values on subsequent invocations for the same host" do - @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1").twice + @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1").twice @scope.function_fqdn_rand([3,4]).should eql(@scope.function_fqdn_rand([3, 4])) end it "should return different sequences of value for different hosts" do - @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1") + @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1") val1 = @scope.function_fqdn_rand([10000000,4]) - @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.2") + @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.2") val2 = @scope.function_fqdn_rand([10000000,4]) val1.should_not eql(val2) end it "should return different values for the same hosts with different seeds" do - @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1") + @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1") val1 = @scope.function_fqdn_rand([10000000,4]) - @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1") + @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1") val2 = @scope.function_fqdn_rand([10000000,42]) val1.should_not eql(val2) end diff --git a/spec/unit/parser/functions/generate_spec.rb b/spec/unit/parser/functions/generate_spec.rb index d25015b56..6c90ae531 100755 --- a/spec/unit/parser/functions/generate_spec.rb +++ b/spec/unit/parser/functions/generate_spec.rb @@ -1,6 +1,5 @@ -#! /usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe "the generate function" do before :all do diff --git a/spec/unit/parser/functions/include_spec.rb b/spec/unit/parser/functions/include_spec.rb index cfaadfbb6..15206cd7c 100755 --- a/spec/unit/parser/functions/include_spec.rb +++ b/spec/unit/parser/functions/include_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe "the 'include' function" do before :all do diff --git a/spec/unit/parser/functions/inline_template_spec.rb b/spec/unit/parser/functions/inline_template_spec.rb index 712c68c69..a9ac0c2d0 100755 --- a/spec/unit/parser/functions/inline_template_spec.rb +++ b/spec/unit/parser/functions/inline_template_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe "the inline_template function" do before :all do diff --git a/spec/unit/parser/functions/realize_spec.rb b/spec/unit/parser/functions/realize_spec.rb index 3106c42b6..159805cbd 100755 --- a/spec/unit/parser/functions/realize_spec.rb +++ b/spec/unit/parser/functions/realize_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe "the realize function" do before :all do diff --git a/spec/unit/parser/functions/regsubst_spec.rb b/spec/unit/parser/functions/regsubst_spec.rb index 1fb8e410c..4ed3bcf68 100755 --- a/spec/unit/parser/functions/regsubst_spec.rb +++ b/spec/unit/parser/functions/regsubst_spec.rb @@ -1,6 +1,5 @@ -#! /usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe "the regsubst function" do before :all do diff --git a/spec/unit/parser/functions/require_spec.rb b/spec/unit/parser/functions/require_spec.rb index edcbc4ae6..692b35305 100755 --- a/spec/unit/parser/functions/require_spec.rb +++ b/spec/unit/parser/functions/require_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe "the require function" do before :all do diff --git a/spec/unit/parser/functions/shellquote_spec.rb b/spec/unit/parser/functions/shellquote_spec.rb index 55302b97b..b100b4913 100755 --- a/spec/unit/parser/functions/shellquote_spec.rb +++ b/spec/unit/parser/functions/shellquote_spec.rb @@ -1,6 +1,5 @@ -#! /usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe "the shellquote function" do before :all do diff --git a/spec/unit/parser/functions/split_spec.rb b/spec/unit/parser/functions/split_spec.rb index b892a5c2a..18a21a0cf 100755 --- a/spec/unit/parser/functions/split_spec.rb +++ b/spec/unit/parser/functions/split_spec.rb @@ -1,6 +1,5 @@ -#! /usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe "the split function" do before :all do diff --git a/spec/unit/parser/functions/sprintf_spec.rb b/spec/unit/parser/functions/sprintf_spec.rb index 69fbb5e97..bd4863f23 100755 --- a/spec/unit/parser/functions/sprintf_spec.rb +++ b/spec/unit/parser/functions/sprintf_spec.rb @@ -1,6 +1,5 @@ -#! /usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe "the sprintf function" do before :all do diff --git a/spec/unit/parser/functions/tag_spec.rb b/spec/unit/parser/functions/tag_spec.rb index b6bb45252..e8a07e1bb 100755 --- a/spec/unit/parser/functions/tag_spec.rb +++ b/spec/unit/parser/functions/tag_spec.rb @@ -1,6 +1,5 @@ -#! /usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe "the 'tag' function" do before :all do diff --git a/spec/unit/parser/functions/template_spec.rb b/spec/unit/parser/functions/template_spec.rb index 7eaf3554d..e7ee974d3 100755 --- a/spec/unit/parser/functions/template_spec.rb +++ b/spec/unit/parser/functions/template_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe "the template function" do before :all do diff --git a/spec/unit/parser/functions/versioncmp_spec.rb b/spec/unit/parser/functions/versioncmp_spec.rb index ddc79cd85..6fc724c38 100755 --- a/spec/unit/parser/functions/versioncmp_spec.rb +++ b/spec/unit/parser/functions/versioncmp_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe "the versioncmp function" do before :all do diff --git a/spec/unit/parser/functions_spec.rb b/spec/unit/parser/functions_spec.rb index 51e52faee..8240a184c 100644..100755 --- a/spec/unit/parser/functions_spec.rb +++ b/spec/unit/parser/functions_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::Functions do diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb index bc9e22e48..6cdb0553a 100755 --- a/spec/unit/parser/lexer_spec.rb +++ b/spec/unit/parser/lexer_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/parser/lexer' diff --git a/spec/unit/parser/parser_spec.rb b/spec/unit/parser/parser_spec.rb index 01cdcb976..78adc30ee 100755 --- a/spec/unit/parser/parser_spec.rb +++ b/spec/unit/parser/parser_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser do diff --git a/spec/unit/parser/relationship_spec.rb b/spec/unit/parser/relationship_spec.rb index 883a38d11..5a49831e1 100644..100755 --- a/spec/unit/parser/relationship_spec.rb +++ b/spec/unit/parser/relationship_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/parser/relationship' diff --git a/spec/unit/parser/resource_spec.rb b/spec/unit/parser/resource_spec.rb index 73c4412dd..b03c18e5f 100755 --- a/spec/unit/parser/resource_spec.rb +++ b/spec/unit/parser/resource_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' # LAK: FIXME This is just new tests for resources; I have # not moved all tests over yet. diff --git a/spec/unit/parser/scope_spec.rb b/spec/unit/parser/scope_spec.rb index 32a87f1f4..bf4d1e29e 100755 --- a/spec/unit/parser/scope_spec.rb +++ b/spec/unit/parser/scope_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Parser::Scope do before :each do @@ -73,19 +72,19 @@ describe Puppet::Parser::Scope do Puppet::Parser::Scope.new.singleton_class.ancestors.should be_include(mod) end - end - describe "when looking up a variable" do - it "should default to an empty string" do - @scope.lookupvar("var").should == "" + it "should remember if it is dynamic" do + (!!Puppet::Parser::Scope.new(:dynamic => true).dynamic).should == true end - it "should return an string when asked for a string" do - @scope.lookupvar("var", true).should == "" + it "should assume it is not dynamic" do + (!Puppet::Parser::Scope.new.dynamic).should == true end + end - it "should return ':undefined' for unset variables when asked not to return a string" do - @scope.lookupvar("var", false).should == :undefined + describe "when looking up a variable" do + it "should return ':undefined' for unset variables" do + @scope.lookupvar("var").should == :undefined end it "should be able to look up values" do @@ -151,32 +150,32 @@ describe Puppet::Parser::Scope do @scope.lookupvar("other::deep::klass::var").should == "otherval" end - it "should return an empty string for qualified variables that cannot be found in other classes" do + it "should return ':undefined' for qualified variables that cannot be found in other classes" do other_scope = create_class_scope("other::deep::klass") - @scope.lookupvar("other::deep::klass::var").should == "" + @scope.lookupvar("other::deep::klass::var").should == :undefined end - it "should warn and return an empty string for qualified variables whose classes have not been evaluated" do + it "should warn and return ':undefined' for qualified variables whose classes have not been evaluated" do klass = newclass("other::deep::klass") @scope.expects(:warning) - @scope.lookupvar("other::deep::klass::var").should == "" + @scope.lookupvar("other::deep::klass::var").should == :undefined end - it "should warn and return an empty string for qualified variables whose classes do not exist" do + it "should warn and return ':undefined' for qualified variables whose classes do not exist" do @scope.expects(:warning) - @scope.lookupvar("other::deep::klass::var").should == "" + @scope.lookupvar("other::deep::klass::var").should == :undefined end it "should return ':undefined' when asked for a non-string qualified variable from a class that does not exist" do @scope.stubs(:warning) - @scope.lookupvar("other::deep::klass::var", false).should == :undefined + @scope.lookupvar("other::deep::klass::var").should == :undefined end it "should return ':undefined' when asked for a non-string qualified variable from a class that has not been evaluated" do @scope.stubs(:warning) klass = newclass("other::deep::klass") - @scope.lookupvar("other::deep::klass::var", false).should == :undefined + @scope.lookupvar("other::deep::klass::var").should == :undefined end end end @@ -291,7 +290,7 @@ describe Puppet::Parser::Scope do @scope.unset_ephemeral_var - @scope.lookupvar("1", false).should == :undefined + @scope.lookupvar("1").should == :undefined end it "should not remove classic variables when unset_ephemeral_var is called" do @@ -301,7 +300,7 @@ describe Puppet::Parser::Scope do @scope.unset_ephemeral_var - @scope.lookupvar("myvar", false).should == :value1 + @scope.lookupvar("myvar").should == :value1 end it "should raise an error when setting it again" do @@ -322,7 +321,7 @@ describe Puppet::Parser::Scope do @scope.setvar("0", :earliest, :ephemeral => true) @scope.new_ephemeral @scope.setvar("0", :latest, :ephemeral => true) - @scope.lookupvar("0", false).should == :latest + @scope.lookupvar("0").should == :latest end it "should be able to report the current level" do @@ -353,7 +352,7 @@ describe Puppet::Parser::Scope do @scope.setvar("1", :value1, :ephemeral => true) @scope.new_ephemeral @scope.setvar("0", :value2, :ephemeral => true) - @scope.lookupvar("1", false).should == :value1 + @scope.lookupvar("1").should == :value1 end describe "when calling unset_ephemeral_var without a level" do @@ -364,7 +363,7 @@ describe Puppet::Parser::Scope do @scope.unset_ephemeral_var - @scope.lookupvar("1", false).should == :undefined + @scope.lookupvar("1").should == :undefined end end @@ -378,152 +377,9 @@ describe Puppet::Parser::Scope do @scope.unset_ephemeral_var(2) - @scope.lookupvar("1", false).should == :value2 - end - end - end - end - - describe "when interpolating string" do - (0..9).each do |n| - it "should allow $#{n} to match" do - @scope.setvar(n.to_s, "value", :ephemeral => true) - - @scope.strinterp("$#{n}").should == "value" - end - end - - (0..9).each do |n| - it "should not allow $#{n} to match if not ephemeral" do - @scope.setvar(n.to_s, "value", :ephemeral => false) - - @scope.strinterp("$#{n}").should_not == "value" - end - end - - it "should not allow $10 to match" do - @scope.setvar("10", "value", :ephemeral => true) - - @scope.strinterp('==$10==').should_not == "==value==" - end - - it "should not allow ${10} to match" do - @scope.setvar("10", "value", :ephemeral => true) - - @scope.strinterp('==${10}==').should == "==value==" - end - - describe "with qualified variables" do - before do - @scopes = {} - klass = @scope.known_resource_types.add(Puppet::Resource::Type.new(:hostclass, "")) - Puppet::Parser::Resource.new("class", :main, :scope => @scope, :source => mock('source')).evaluate - @scopes[""] = @scope.class_scope(klass) - @scopes[""].setvar("test", "value") - - %w{one one::two one::two::three}.each do |name| - klass = @scope.known_resource_types.add(Puppet::Resource::Type.new(:hostclass, name)) - Puppet::Parser::Resource.new("class", name, :scope => @scope, :source => mock('source')).evaluate - @scopes[name] = @scope.class_scope(klass) - @scopes[name].setvar("test", "value-#{name.sub(/.+::/,'')}") + @scope.lookupvar("1").should == :value2 end end - { - "===${one::two::three::test}===" => "===value-three===", - "===$one::two::three::test===" => "===value-three===", - "===${one::two::test}===" => "===value-two===", - "===$one::two::test===" => "===value-two===", - "===${one::test}===" => "===value-one===", - "===$one::test===" => "===value-one===", - "===${::test}===" => "===value===", - "===$::test===" => "===value===" - }.each do |input, output| - it "should parse '#{input}' correctly" do - @scope.strinterp(input).should == output - end - end - end - - tests = { - "===${test}===" => "===value===", - "===${test} ${test} ${test}===" => "===value value value===", - "===$test ${test} $test===" => "===value value value===", - "===\\$test===" => "===$test===", - '===\\$test string===' => "===$test string===", - '===$test string===' => "===value string===", - '===a testing $===' => "===a testing $===", - '===a testing \$===' => "===a testing $===", - "===an escaped \\\n carriage return===" => "===an escaped carriage return===", - '\$' => "$", - '\s' => "\s", - '\t' => "\t", - '\n' => "\n" - } - - tests.each do |input, output| - it "should parse '#{input}' correctly" do - @scope.setvar("test", "value") - @scope.strinterp(input).should == output - end - end - - # #523 - %w{d f h l w z}.each do |l| - it "should parse '#{l}' when escaped" do - string = "\\#{l}" - @scope.strinterp(string).should == string - end - end - end - - def test_strinterp - # Make and evaluate our classes so the qualified lookups work - parser = mkparser - klass = parser.newclass("") - scope = mkscope(:parser => parser) - Puppet::Parser::Resource.new(:type => "class", :title => :main, :scope => scope, :source => mock('source')).evaluate - - assert_nothing_raised { - scope.setvar("test","value") - } - - scopes = {"" => scope} - - %w{one one::two one::two::three}.each do |name| - klass = parser.newclass(name) - Puppet::Parser::Resource.new(:type => "class", :title => name, :scope => scope, :source => mock('source')).evaluate - scopes[name] = scope.class_scope(klass) - scopes[name].setvar("test", "value-#{name.sub(/.+::/,'')}") - end - - assert_equal("value", scope.lookupvar("::test"), "did not look up qualified value correctly") - tests.each do |input, output| - assert_nothing_raised("Failed to scan #{input.inspect}") do - assert_equal(output, scope.strinterp(input), 'did not parserret %s correctly' % input.inspect) - end - end - - logs = [] - Puppet::Util::Log.close - Puppet::Util::Log.newdestination(logs) - - # #523 - %w{d f h l w z}.each do |l| - string = "\\#{l}" - assert_nothing_raised do - - assert_equal( - string, scope.strinterp(string), - - 'did not parserret %s correctly' % string) - end - - - assert( - logs.detect { |m| m.message =~ /Unrecognised escape/ }, - - "Did not get warning about escape sequence with #{string}") - logs.clear end end @@ -563,13 +419,13 @@ describe Puppet::Parser::Scope do it "should be able to unset normal variables" do @scope.setvar("foo", "bar") @scope.unsetvar("foo") - @scope.lookupvar("foo").should == "" + @scope.lookupvar("foo").should == :undefined end it "should be able to unset ephemeral variables" do @scope.setvar("0", "bar", :ephemeral => true) @scope.unsetvar("0") - @scope.lookupvar("0").should == "" + @scope.lookupvar("0").should == :undefined end it "should not unset ephemeral variables in previous ephemeral scope" do diff --git a/spec/unit/parser/templatewrapper_spec.rb b/spec/unit/parser/templatewrapper_spec.rb index aab169348..600293bbf 100755 --- a/spec/unit/parser/templatewrapper_spec.rb +++ b/spec/unit/parser/templatewrapper_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/parser/templatewrapper' describe Puppet::Parser::TemplateWrapper do @@ -17,6 +16,12 @@ describe Puppet::Parser::TemplateWrapper do @tw = Puppet::Parser::TemplateWrapper.new(@scope) end + def mock_template(source=nil) + template_mock = mock("template", :result => "woot!") + ERB.expects(:new).with("template contents", 0, "-").returns(template_mock) + template_mock.expects(:filename=).with(source) + end + it "should create a new object TemplateWrapper from a scope" do tw = Puppet::Parser::TemplateWrapper.new(@scope) @@ -54,41 +59,38 @@ describe Puppet::Parser::TemplateWrapper do end it "should return the processed template contents with a call to result" do - template_mock = mock("template", :result => "woot!") + mock_template("/tmp/fake_template") File.expects(:read).with("/tmp/fake_template").returns("template contents") - ERB.expects(:new).with("template contents", 0, "-").returns(template_mock) @tw.file = @file @tw.result.should eql("woot!") end it "should return the processed template contents with a call to result and a string" do - template_mock = mock("template", :result => "woot!") - ERB.expects(:new).with("template contents", 0, "-").returns(template_mock) - + mock_template @tw.result("template contents").should eql("woot!") end it "should return the contents of a variable if called via method_missing" do - @scope.expects(:lookupvar).with("chicken", false).returns("is good") + @scope.expects(:lookupvar).with { |name,options| name == "chicken"}.returns("is good") tw = Puppet::Parser::TemplateWrapper.new(@scope) tw.chicken.should eql("is good") end it "should throw an exception if a variable is called via method_missing and it does not exist" do - @scope.expects(:lookupvar).with("chicken", false).returns(:undefined) + @scope.expects(:lookupvar).with { |name,options| name == "chicken"}.returns(:undefined) tw = Puppet::Parser::TemplateWrapper.new(@scope) lambda { tw.chicken }.should raise_error(Puppet::ParseError) end it "should allow you to check whether a variable is defined with has_variable?" do - @scope.expects(:lookupvar).with("chicken", false).returns("is good") + @scope.expects(:lookupvar).with { |name,options| name == "chicken"}.returns("is good") tw = Puppet::Parser::TemplateWrapper.new(@scope) tw.has_variable?("chicken").should eql(true) end it "should allow you to check whether a variable is not defined with has_variable?" do - @scope.expects(:lookupvar).with("chicken", false).returns(:undefined) + @scope.expects(:lookupvar).with { |name,options| name == "chicken"}.returns(:undefined) tw = Puppet::Parser::TemplateWrapper.new(@scope) tw.has_variable?("chicken").should eql(false) end @@ -114,9 +116,7 @@ describe Puppet::Parser::TemplateWrapper do end it "should set all of the scope's variables as instance variables" do - template_mock = mock("template", :result => "woot!") - ERB.expects(:new).with("template contents", 0, "-").returns(template_mock) - + mock_template @scope.expects(:to_hash).returns("one" => "foo") @tw.result("template contents") @@ -124,8 +124,7 @@ describe Puppet::Parser::TemplateWrapper do end it "should not error out if one of the variables is a symbol" do - template_mock = mock("template", :result => "woot!") - ERB.expects(:new).with("template contents", 0, "-").returns(template_mock) + mock_template @scope.expects(:to_hash).returns(:_timestamp => "1234") @tw.result("template contents") @@ -133,13 +132,11 @@ describe Puppet::Parser::TemplateWrapper do %w{! . ; :}.each do |badchar| it "should translate #{badchar} to _ when setting the instance variables" do - template_mock = mock("template", :result => "woot!") - ERB.expects(:new).with("template contents", 0, "-").returns(template_mock) + mock_template + @scope.expects(:to_hash).returns("one#{badchar}" => "foo") + @tw.result("template contents") - @scope.expects(:to_hash).returns("one#{badchar}" => "foo") - @tw.result("template contents") - - @tw.instance_variable_get("@one_").should == "foo" - end + @tw.instance_variable_get("@one_").should == "foo" + end end end diff --git a/spec/unit/parser/type_loader_spec.rb b/spec/unit/parser/type_loader_spec.rb index 12bc1ccd6..9367b61c8 100644..100755 --- a/spec/unit/parser/type_loader_spec.rb +++ b/spec/unit/parser/type_loader_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/parser/type_loader' require 'puppet_spec/files' diff --git a/spec/unit/property/ensure_spec.rb b/spec/unit/property/ensure_spec.rb index d3029c658..35151553b 100644..100755 --- a/spec/unit/property/ensure_spec.rb +++ b/spec/unit/property/ensure_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/property/ensure' diff --git a/spec/unit/property/keyvalue_spec.rb b/spec/unit/property/keyvalue_spec.rb index a0175cfa3..821c61799 100644..100755 --- a/spec/unit/property/keyvalue_spec.rb +++ b/spec/unit/property/keyvalue_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/property/keyvalue' diff --git a/spec/unit/property/list_spec.rb b/spec/unit/property/list_spec.rb index 704fbe3d9..a29d65751 100644..100755 --- a/spec/unit/property/list_spec.rb +++ b/spec/unit/property/list_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/property/list' diff --git a/spec/unit/property/ordered_list_spec.rb b/spec/unit/property/ordered_list_spec.rb index 460bec79d..2ad05367c 100644..100755 --- a/spec/unit/property/ordered_list_spec.rb +++ b/spec/unit/property/ordered_list_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/property/ordered_list' diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb index 602d3c66b..7728b5d40 100755 --- a/spec/unit/property_spec.rb +++ b/spec/unit/property_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/property' describe Puppet::Property do diff --git a/spec/unit/provider/augeas/augeas_spec.rb b/spec/unit/provider/augeas/augeas_spec.rb index c65f39097..5bb98eadf 100644..100755 --- a/spec/unit/provider/augeas/augeas_spec.rb +++ b/spec/unit/provider/augeas/augeas_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:augeas).provider(:augeas) diff --git a/spec/unit/provider/confine/exists_spec.rb b/spec/unit/provider/confine/exists_spec.rb index 1dabafb19..1e2d7f86f 100755 --- a/spec/unit/provider/confine/exists_spec.rb +++ b/spec/unit/provider/confine/exists_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/provider/confine/exists' diff --git a/spec/unit/provider/confine/false_spec.rb b/spec/unit/provider/confine/false_spec.rb index 8ea4bf740..1afa57cbc 100755 --- a/spec/unit/provider/confine/false_spec.rb +++ b/spec/unit/provider/confine/false_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/provider/confine/false' diff --git a/spec/unit/provider/confine/feature_spec.rb b/spec/unit/provider/confine/feature_spec.rb index 534c8c14a..959c7a3bb 100755 --- a/spec/unit/provider/confine/feature_spec.rb +++ b/spec/unit/provider/confine/feature_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/provider/confine/feature' diff --git a/spec/unit/provider/confine/true_spec.rb b/spec/unit/provider/confine/true_spec.rb index b23373b87..795819bd3 100755 --- a/spec/unit/provider/confine/true_spec.rb +++ b/spec/unit/provider/confine/true_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/provider/confine/true' diff --git a/spec/unit/provider/confine/variable_spec.rb b/spec/unit/provider/confine/variable_spec.rb index 083573c3a..7b9f53c3d 100755 --- a/spec/unit/provider/confine/variable_spec.rb +++ b/spec/unit/provider/confine/variable_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/provider/confine/variable' diff --git a/spec/unit/provider/confine_collection_spec.rb b/spec/unit/provider/confine_collection_spec.rb index fc68ef7f6..f1dbaf35d 100755 --- a/spec/unit/provider/confine_collection_spec.rb +++ b/spec/unit/provider/confine_collection_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/provider/confine_collection' diff --git a/spec/unit/provider/confine_spec.rb b/spec/unit/provider/confine_spec.rb index ce969eded..ade444276 100755 --- a/spec/unit/provider/confine_spec.rb +++ b/spec/unit/provider/confine_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/provider/confine' diff --git a/spec/unit/provider/confiner_spec.rb b/spec/unit/provider/confiner_spec.rb index 15e2e6129..23ec162a5 100755 --- a/spec/unit/provider/confiner_spec.rb +++ b/spec/unit/provider/confiner_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/provider/confiner' diff --git a/spec/unit/provider/exec/posix_spec.rb b/spec/unit/provider/exec/posix_spec.rb index d02099250..50697d826 100755 --- a/spec/unit/provider/exec/posix_spec.rb +++ b/spec/unit/provider/exec/posix_spec.rb @@ -1,5 +1,5 @@ -#!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../../spec_helper' +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:exec).provider(:posix) diff --git a/spec/unit/provider/exec/shell_spec.rb b/spec/unit/provider/exec/shell_spec.rb index 4bae354c9..90047b9d6 100644..100755 --- a/spec/unit/provider/exec/shell_spec.rb +++ b/spec/unit/provider/exec/shell_spec.rb @@ -1,5 +1,5 @@ -#!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../../spec_helper' +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:exec).provider(:shell) diff --git a/spec/unit/provider/group/groupadd_spec.rb b/spec/unit/provider/group/groupadd_spec.rb index 41431fb59..585eb02af 100755 --- a/spec/unit/provider/group/groupadd_spec.rb +++ b/spec/unit/provider/group/groupadd_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:group).provider(:groupadd) @@ -10,10 +9,10 @@ describe provider_class do @provider = provider_class.new(@resource) end - # #1360 it "should add -o when allowdupe is enabled and the group is being created" do @resource.stubs(:should).returns "fakeval" @resource.stubs(:[]).returns "fakeval" + @resource.stubs(:system?).returns true @resource.expects(:allowdupe?).returns true @provider.expects(:execute).with { |args| args.include?("-o") } @@ -28,4 +27,14 @@ describe provider_class do @provider.gid = 150 end + + it "should add -r when system is enabled and the group is being created" do + @resource.stubs(:should).returns "fakeval" + @resource.stubs(:[]).returns "fakeval" + @resource.expects(:system?).returns true + @resource.stubs(:allowdupe?).returns true + @provider.expects(:execute).with { |args| args.include?("-r") } + + @provider.create + end end diff --git a/spec/unit/provider/group/ldap_spec.rb b/spec/unit/provider/group/ldap_spec.rb index 8454b9604..947007f10 100755 --- a/spec/unit/provider/group/ldap_spec.rb +++ b/spec/unit/provider/group/ldap_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-3-10. # Copyright (c) 2006. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' provider_class = Puppet::Type.type(:group).provider(:ldap) diff --git a/spec/unit/provider/host/parsed_spec.rb b/spec/unit/provider/host/parsed_spec.rb index 048d77ba2..9cb5890cc 100755 --- a/spec/unit/provider/host/parsed_spec.rb +++ b/spec/unit/provider/host/parsed_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'shared_behaviours/all_parsedfile_providers' require 'puppet_spec/files' diff --git a/spec/unit/provider/interface/cisco_spec.rb b/spec/unit/provider/interface/cisco_spec.rb new file mode 100755 index 000000000..d1f70609f --- /dev/null +++ b/spec/unit/provider/interface/cisco_spec.rb @@ -0,0 +1,64 @@ +#!/usr/bin/env rspec + +require File.dirname(__FILE__) + '/../../../spec_helper' + +require 'puppet/provider/interface/cisco' + +provider_class = Puppet::Type.type(:interface).provider(:cisco) + +describe provider_class do + before do + @resource = stub("resource", :name => "Fa0/1") + @provider = provider_class.new(@resource) + end + + it "should have a parent of Puppet::Provider::NetworkDevice" do + provider_class.should < Puppet::Provider::NetworkDevice + end + + it "should have an instances method" do + provider_class.should respond_to(:instances) + end + + describe "when looking up instances at prefetch" do + before do + @device = stub_everything 'device' + Puppet::Util::NetworkDevice::Cisco::Device.stubs(:new).returns(@device) + @device.stubs(:command).yields(@device) + end + + it "should initialize the network device with the given url" do + Puppet::Util::NetworkDevice::Cisco::Device.expects(:new).with(:url).returns(@device) + provider_class.lookup(:url, "Fa0/1") + end + + it "should delegate to the device interface fetcher" do + @device.expects(:interface) + provider_class.lookup("", "Fa0/1") + end + + it "should return the given interface data" do + @device.expects(:interface).returns({ :description => "thisone", :mode => :access}) + provider_class.lookup("", "Fa0").should == {:description => "thisone", :mode => :access } + end + + end + + describe "when an instance is being flushed" do + it "should call the device interface update method with current and past properties" do + @instance = provider_class.new(:ensure => :present, :name => "Fa0/1", :description => "myinterface") + @instance.description = "newdesc" + @instance.resource = @resource + @resource.stubs(:[]).with(:name).returns("Fa0/1") + device = stub_everything 'device' + @instance.stubs(:device).returns(device) + device.expects(:command).yields(device) + interface = stub 'interface' + device.expects(:new_interface).with("Fa0/1").returns(interface) + interface.expects(:update).with( {:ensure => :present, :name => "Fa0/1", :description => "myinterface"}, + {:ensure => :present, :name => "Fa0/1", :description => "newdesc"}) + + @instance.flush + end + end +end diff --git a/spec/unit/provider/ldap_spec.rb b/spec/unit/provider/ldap_spec.rb index 7ed289c62..012a22b99 100755 --- a/spec/unit/provider/ldap_spec.rb +++ b/spec/unit/provider/ldap_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-3-21. # Copyright (c) 2006. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/provider/ldap' diff --git a/spec/unit/provider/macauthorization_spec.rb b/spec/unit/provider/macauthorization_spec.rb index 3c74334ba..a76f917f7 100755 --- a/spec/unit/provider/macauthorization_spec.rb +++ b/spec/unit/provider/macauthorization_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Unit testing for the macauthorization provider # -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet' require 'facter/util/plist' diff --git a/spec/unit/provider/mcx/mcxcontent_spec.rb b/spec/unit/provider/mcx/mcxcontent_spec.rb index 82dbf9ac7..4676575be 100755 --- a/spec/unit/provider/mcx/mcxcontent_spec.rb +++ b/spec/unit/provider/mcx/mcxcontent_spec.rb @@ -1,24 +1,5 @@ -#! /usr/bin/env ruby -#-- -# Copyright (C) 2008 Jeffrey J McCune. - -# 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. - -# 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 - -# Author: Jeff McCune <mccune.jeff@gmail.com> - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:mcx).provider(:mcxcontent) diff --git a/spec/unit/provider/mount/parsed_spec.rb b/spec/unit/provider/mount/parsed_spec.rb index b63c0751f..0293e0758 100755 --- a/spec/unit/provider/mount/parsed_spec.rb +++ b/spec/unit/provider/mount/parsed_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-9-12. # Copyright (c) 2006. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'shared_behaviours/all_parsedfile_providers' provider_class = Puppet::Type.type(:mount).provider(:parsed) diff --git a/spec/unit/provider/mount_spec.rb b/spec/unit/provider/mount_spec.rb index 9cadfc403..963bfba7c 100755 --- a/spec/unit/provider/mount_spec.rb +++ b/spec/unit/provider/mount_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/provider/mount' diff --git a/spec/unit/provider/naginator_spec.rb b/spec/unit/provider/naginator_spec.rb index 8ae1895cc..1d8e78015 100755 --- a/spec/unit/provider/naginator_spec.rb +++ b/spec/unit/provider/naginator_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/provider/naginator' diff --git a/spec/unit/provider/nameservice/directoryservice_spec.rb b/spec/unit/provider/nameservice/directoryservice_spec.rb index 661899db9..47f2ad0cd 100755 --- a/spec/unit/provider/nameservice/directoryservice_spec.rb +++ b/spec/unit/provider/nameservice/directoryservice_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.dirname(__FILE__) + '/../../../spec_helper' +#!/usr/bin/env rspec +require 'spec_helper' # We use this as a reasonable way to obtain all the support infrastructure. [:user, :group].each do |type_for_this_round| diff --git a/spec/unit/provider/network_device_spec.rb b/spec/unit/provider/network_device_spec.rb new file mode 100755 index 000000000..83d2bdc01 --- /dev/null +++ b/spec/unit/provider/network_device_spec.rb @@ -0,0 +1,148 @@ +#!/usr/bin/env rspec + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/provider/network_device' + +Puppet::Type.type(:vlan).provide :test, :parent => Puppet::Provider::NetworkDevice do + mk_resource_methods + def self.lookup(device_url, name) + end +end + +provider_class = Puppet::Type.type(:vlan).provider(:test) + +describe provider_class do + before do + @resource = stub("resource", :name => "test") + @provider = provider_class.new(@resource) + end + + it "should be able to prefetch instances from the device" do + provider_class.should respond_to(:prefetch) + end + + it "should have an instances method" do + provider_class.should respond_to(:instances) + end + + describe "when prefetching" do + before do + @resource = stub_everything 'resource' + @resources = {"200" => @resource} + provider_class.stubs(:lookup) + end + + it "should lookup an entry for each passed resource" do + provider_class.expects(:lookup).with(nil, "200").returns nil + + provider_class.stubs(:new) + @resource.stubs(:provider=) + provider_class.prefetch(@resources) + end + + describe "resources that do not exist" do + it "should create a provider with :ensure => :absent" do + provider_class.stubs(:lookup).returns(nil) + provider_class.expects(:new).with(:ensure => :absent).returns "myprovider" + @resource.expects(:provider=).with("myprovider") + provider_class.prefetch(@resources) + end + end + + describe "resources that exist" do + it "should create a provider with the results of the find and ensure at present" do + provider_class.stubs(:lookup).returns({ :name => "200", :description => "myvlan"}) + + provider_class.expects(:new).with(:name => "200", :description => "myvlan", :ensure => :present).returns "myprovider" + @resource.expects(:provider=).with("myprovider") + + provider_class.prefetch(@resources) + end + end + end + + describe "when being initialized" do + describe "with a hash" do + before do + @resource_class = mock 'resource_class' + provider_class.stubs(:resource_type).returns @resource_class + + @property_class = stub 'property_class', :array_matching => :all, :superclass => Puppet::Property + @resource_class.stubs(:attrclass).with(:one).returns(@property_class) + @resource_class.stubs(:valid_parameter?).returns true + end + + it "should store a copy of the hash as its vlan_properties" do + instance = provider_class.new(:one => :two) + instance.former_properties.should == {:one => :two} + end + end + end + + describe "when an instance" do + before do + @instance = provider_class.new + + @property_class = stub 'property_class', :array_matching => :all, :superclass => Puppet::Property + @resource_class = stub 'resource_class', :attrclass => @property_class, :valid_parameter? => true, :validproperties => [:description] + provider_class.stubs(:resource_type).returns @resource_class + end + + it "should have a method for creating the instance" do + @instance.should respond_to(:create) + end + + it "should have a method for removing the instance" do + @instance.should respond_to(:destroy) + end + + it "should indicate when the instance already exists" do + @instance = provider_class.new(:ensure => :present) + @instance.exists?.should be_true + end + + it "should indicate when the instance does not exist" do + @instance = provider_class.new(:ensure => :absent) + @instance.exists?.should be_false + end + + describe "is being flushed" do + it "should flush properties" do + @instance = provider_class.new(:ensure => :present, :name => "200", :description => "myvlan") + @instance.flush + @instance.properties.should be_empty + end + end + + describe "is being created" do + before do + @rclass = mock 'resource_class' + @rclass.stubs(:validproperties).returns([:description]) + @resource = stub_everything 'resource' + @resource.stubs(:class).returns @rclass + @resource.stubs(:should).returns nil + @instance.stubs(:resource).returns @resource + end + + it "should set its :ensure value to :present" do + @instance.create + @instance.properties[:ensure].should == :present + end + + it "should set all of the other attributes from the resource" do + @resource.expects(:should).with(:description).returns "myvlan" + + @instance.create + @instance.properties[:description].should == "myvlan" + end + end + + describe "is being destroyed" do + it "should set its :ensure value to :absent" do + @instance.destroy + @instance.properties[:ensure].should == :absent + end + end + end +end diff --git a/spec/unit/provider/package/aix_spec.rb b/spec/unit/provider/package/aix_spec.rb index 40e497c27..fba29d7a7 100755 --- a/spec/unit/provider/package/aix_spec.rb +++ b/spec/unit/provider/package/aix_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:package).provider(:aix) diff --git a/spec/unit/provider/package/apt_spec.rb b/spec/unit/provider/package/apt_spec.rb index b0ce4f799..b020b0f4f 100755 --- a/spec/unit/provider/package/apt_spec.rb +++ b/spec/unit/provider/package/apt_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider = Puppet::Type.type(:package).provider(:apt) diff --git a/spec/unit/provider/package/dpkg_spec.rb b/spec/unit/provider/package/dpkg_spec.rb index 444fb31c1..e64146056 100755 --- a/spec/unit/provider/package/dpkg_spec.rb +++ b/spec/unit/provider/package/dpkg_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider = Puppet::Type.type(:package).provider(:dpkg) diff --git a/spec/unit/provider/package/freebsd_spec.rb b/spec/unit/provider/package/freebsd_spec.rb index 0d38a16cf..9c8038791 100755 --- a/spec/unit/provider/package/freebsd_spec.rb +++ b/spec/unit/provider/package/freebsd_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.dirname(__FILE__) + '/../../../spec_helper' +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:package).provider(:freebsd) diff --git a/spec/unit/provider/package/gem_spec.rb b/spec/unit/provider/package/gem_spec.rb index c2bd3cc90..284e63c23 100644..100755 --- a/spec/unit/provider/package/gem_spec.rb +++ b/spec/unit/provider/package/gem_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:package).provider(:gem) diff --git a/spec/unit/provider/package/hpux_spec.rb b/spec/unit/provider/package/hpux_spec.rb index e75ae0822..b781f6540 100644..100755 --- a/spec/unit/provider/package/hpux_spec.rb +++ b/spec/unit/provider/package/hpux_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:package).provider(:hpux) diff --git a/spec/unit/provider/package/macports_spec.rb b/spec/unit/provider/package/macports_spec.rb new file mode 100755 index 000000000..7d1acd537 --- /dev/null +++ b/spec/unit/provider/package/macports_spec.rb @@ -0,0 +1,122 @@ +require 'spec_helper' + +provider_class = Puppet::Type.type(:package).provider(:macports) + +describe provider_class do + let :resource_name do + "foo" + end + + let :resource do + Puppet::Type.type(:package).new(:name => resource_name, :provider => :macports) + end + + let :provider do + prov = resource.provider + prov.expects(:execute).never + prov + end + + let :current_hash do + {:name => resource_name, :ensure => "1.2.3", :revision => "1", :provider => :macports} + end + + describe "provider features" do + subject { provider } + + it { should be_installable } + it { should be_uninstallable } + it { should be_upgradeable } + it { should be_versionable } + end + + describe "when listing all instances" do + it "should call port -q installed" do + provider_class.expects(:port).with("-q", :installed).returns("") + provider_class.instances + end + + it "should create instances from active ports" do + provider_class.expects(:port).returns("foo @1.234.5_2 (active)") + provider_class.instances.size.should == 1 + end + + it "should ignore ports that aren't activated" do + provider_class.expects(:port).returns("foo @1.234.5_2") + provider_class.instances.size.should == 0 + end + end + + describe "when installing" do + it "should not specify a version when ensure is set to latest" do + resource[:ensure] = :latest + provider.expects(:port).with { |flag, method, name, version| + version.should be_nil + } + provider.install + end + + it "should not specify a version when ensure is set to present" do + resource[:ensure] = :present + provider.expects(:port).with { |flag, method, name, version| + version.should be_nil + } + provider.install + end + + it "should specify a version when ensure is set to a version" do + resource[:ensure] = "1.2.3" + provider.expects(:port).with { |flag, method, name, version| + version.should be + } + provider.install + end + end + + describe "when querying for the latest version" do + let :new_info_line do + "1.2.3 2" + end + let :infoargs do + ["-q", :info, "--line", "--version", "--revision", resource_name] + end + + it "should return nil when the package cannot be found" do + resource[:name] = resource_name + provider.expects(:port).returns("") + provider.latest.should == nil + end + + it "should return the current version if the installed port has the same revision" do + current_hash[:revision] = "2" + provider.expects(:port).with(*infoargs).returns(new_info_line) + provider.expects(:query).returns(current_hash) + provider.latest.should == current_hash[:ensure] + end + + it "should return the new version_revision if the installed port has a lower revision" do + current_hash[:revision] = "1" + provider.expects(:port).with(*infoargs).returns(new_info_line) + provider.expects(:query).returns(current_hash) + provider.latest.should == "1.2.3_2" + end + end + + describe "when updating a port" do + it "should execute port upgrade if the port is installed" do + resource[:name] = resource_name + resource[:ensure] = :present + provider.expects(:query).returns(current_hash) + provider.expects(:port).with("-q", :upgrade, resource_name) + provider.update + end + + it "should execute port install if the port is not installed" do + resource[:name] = resource_name + resource[:ensure] = :present + provider.expects(:query).returns("") + provider.expects(:port).with("-q", :install, resource_name) + provider.update + end + end +end diff --git a/spec/unit/provider/package/nim_spec.rb b/spec/unit/provider/package/nim_spec.rb index 74f903813..0fa9f580d 100755 --- a/spec/unit/provider/package/nim_spec.rb +++ b/spec/unit/provider/package/nim_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:package).provider(:nim) diff --git a/spec/unit/provider/package/pip_spec.rb b/spec/unit/provider/package/pip_spec.rb index 8953b4b2c..b56271029 100644..100755 --- a/spec/unit/provider/package/pip_spec.rb +++ b/spec/unit/provider/package/pip_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:package).provider(:pip) diff --git a/spec/unit/provider/package/pkg_spec.rb b/spec/unit/provider/package/pkg_spec.rb index 3455c4c40..04a4ae607 100644..100755 --- a/spec/unit/provider/package/pkg_spec.rb +++ b/spec/unit/provider/package/pkg_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider = Puppet::Type.type(:package).provider(:pkg) diff --git a/spec/unit/provider/package/pkgdmg_spec.rb b/spec/unit/provider/package/pkgdmg_spec.rb index 86631e596..155f12e7b 100755 --- a/spec/unit/provider/package/pkgdmg_spec.rb +++ b/spec/unit/provider/package/pkgdmg_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider = Puppet::Type.type(:package).provider(:pkgdmg) diff --git a/spec/unit/provider/package/yum_spec.rb b/spec/unit/provider/package/yum_spec.rb index 4e2294a77..601c24009 100644..100755 --- a/spec/unit/provider/package/yum_spec.rb +++ b/spec/unit/provider/package/yum_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider = Puppet::Type.type(:package).provider(:yum) diff --git a/spec/unit/provider/package/zypper_spec.rb b/spec/unit/provider/package/zypper_spec.rb index 1bf27ad97..4218b14c7 100644..100755 --- a/spec/unit/provider/package/zypper_spec.rb +++ b/spec/unit/provider/package/zypper_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:package).provider(:zypper) diff --git a/spec/unit/provider/parsedfile_spec.rb b/spec/unit/provider/parsedfile_spec.rb index 7d95ef1d0..2ff904b7f 100755 --- a/spec/unit/provider/parsedfile_spec.rb +++ b/spec/unit/provider/parsedfile_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/provider/parsedfile' diff --git a/spec/unit/provider/selboolean_spec.rb b/spec/unit/provider/selboolean_spec.rb index 02a39f2a7..64f925e1e 100755 --- a/spec/unit/provider/selboolean_spec.rb +++ b/spec/unit/provider/selboolean_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:selboolean).provider(:getsetsebool) diff --git a/spec/unit/provider/selmodule_spec.rb b/spec/unit/provider/selmodule_spec.rb index cb143e993..67196667f 100755 --- a/spec/unit/provider/selmodule_spec.rb +++ b/spec/unit/provider/selmodule_spec.rb @@ -1,11 +1,11 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # Note: This unit test depends on having a sample SELinux policy file # in the same directory as this test called selmodule-example.pp # with version 1.5.0. The provided selmodule-example.pp is the first # 256 bytes taken from /usr/share/selinux/targeted/nagios.pp on Fedora 9 -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' provider_class = Puppet::Type.type(:selmodule).provider(:semodule) diff --git a/spec/unit/provider/service/daemontools_spec.rb b/spec/unit/provider/service/daemontools_spec.rb index 0bdb0a85d..64eeb9fa4 100755 --- a/spec/unit/provider/service/daemontools_spec.rb +++ b/spec/unit/provider/service/daemontools_spec.rb @@ -1,10 +1,10 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Unit testing for the Daemontools service Provider # # author Brice Figureau # -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' provider_class = Puppet::Type.type(:service).provider(:daemontools) diff --git a/spec/unit/provider/service/debian_spec.rb b/spec/unit/provider/service/debian_spec.rb index b5edf6882..4e3d30d61 100755 --- a/spec/unit/provider/service/debian_spec.rb +++ b/spec/unit/provider/service/debian_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Unit testing for the debian service provider # -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' provider_class = Puppet::Type.type(:service).provider(:debian) diff --git a/spec/unit/provider/service/freebsd_spec.rb b/spec/unit/provider/service/freebsd_spec.rb index d8b751108..c1a6d26f7 100644..100755 --- a/spec/unit/provider/service/freebsd_spec.rb +++ b/spec/unit/provider/service/freebsd_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:service).provider(:freebsd) diff --git a/spec/unit/provider/service/init_spec.rb b/spec/unit/provider/service/init_spec.rb index b54c27e8e..d64e0fc5d 100755 --- a/spec/unit/provider/service/init_spec.rb +++ b/spec/unit/provider/service/init_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Unit testing for the Init service Provider # -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' provider_class = Puppet::Type.type(:service).provider(:init) diff --git a/spec/unit/provider/service/launchd_spec.rb b/spec/unit/provider/service/launchd_spec.rb index dfcb58fdc..8ae7f003d 100755 --- a/spec/unit/provider/service/launchd_spec.rb +++ b/spec/unit/provider/service/launchd_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Unit testing for the launchd service provider # -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet' diff --git a/spec/unit/provider/service/redhat_spec.rb b/spec/unit/provider/service/redhat_spec.rb index a3c6247dd..b7f56e089 100755 --- a/spec/unit/provider/service/redhat_spec.rb +++ b/spec/unit/provider/service/redhat_spec.rb @@ -1,8 +1,8 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Unit testing for the RedHat service Provider # -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' provider_class = Puppet::Type.type(:service).provider(:redhat) diff --git a/spec/unit/provider/service/runit_spec.rb b/spec/unit/provider/service/runit_spec.rb index 12dfeeb35..38855a451 100755 --- a/spec/unit/provider/service/runit_spec.rb +++ b/spec/unit/provider/service/runit_spec.rb @@ -1,10 +1,10 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Unit testing for the Runit service Provider # # author Brice Figureau # -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' provider_class = Puppet::Type.type(:service).provider(:runit) diff --git a/spec/unit/provider/service/smf_spec.rb b/spec/unit/provider/service/smf_spec.rb index 40e96ab23..5212d540a 100755 --- a/spec/unit/provider/service/smf_spec.rb +++ b/spec/unit/provider/service/smf_spec.rb @@ -1,10 +1,10 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Unit testing for the SMF service Provider # # author Dominic Cleal # -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' provider_class = Puppet::Type.type(:service).provider(:smf) diff --git a/spec/unit/provider/service/src_spec.rb b/spec/unit/provider/service/src_spec.rb index dbe073513..17f49994e 100755 --- a/spec/unit/provider/service/src_spec.rb +++ b/spec/unit/provider/service/src_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Unit testing for the AIX System Resource Controller (src) provider # -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' provider_class = Puppet::Type.type(:service).provider(:src) diff --git a/spec/unit/provider/service/upstart.rb b/spec/unit/provider/service/upstart.rb index 22cf2bdeb..0febc939d 100644..100755 --- a/spec/unit/provider/service/upstart.rb +++ b/spec/unit/provider/service/upstart.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:service).provider(:upstart) diff --git a/spec/unit/provider/ssh_authorized_key/parsed_spec.rb b/spec/unit/provider/ssh_authorized_key/parsed_spec.rb index 3ac57facc..69d29c674 100755 --- a/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +++ b/spec/unit/provider/ssh_authorized_key/parsed_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'shared_behaviours/all_parsedfile_providers' require 'puppet_spec/files' diff --git a/spec/unit/provider/sshkey/parsed_spec.rb b/spec/unit/provider/sshkey/parsed_spec.rb index 7a76b02d6..e66032bc4 100755 --- a/spec/unit/provider/sshkey/parsed_spec.rb +++ b/spec/unit/provider/sshkey/parsed_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:sshkey).provider(:parsed) diff --git a/spec/unit/provider/user/hpux_spec.rb b/spec/unit/provider/user/hpux_spec.rb index b10f2847c..f7779a98d 100755 --- a/spec/unit/provider/user/hpux_spec.rb +++ b/spec/unit/provider/user/hpux_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:user).provider(:hpuxuseradd) diff --git a/spec/unit/provider/user/ldap_spec.rb b/spec/unit/provider/user/ldap_spec.rb index 5b2dc98b5..065b3b423 100755 --- a/spec/unit/provider/user/ldap_spec.rb +++ b/spec/unit/provider/user/ldap_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-3-10. # Copyright (c) 2006. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' provider_class = Puppet::Type.type(:user).provider(:ldap) diff --git a/spec/unit/provider/user/user_role_add_spec.rb b/spec/unit/provider/user/user_role_add_spec.rb index 12a71d25a..b17ba68c8 100644..100755 --- a/spec/unit/provider/user/user_role_add_spec.rb +++ b/spec/unit/provider/user/user_role_add_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:user).provider(:user_role_add) diff --git a/spec/unit/provider/user/useradd_spec.rb b/spec/unit/provider/user/useradd_spec.rb index b1719eeaf..724fc12c0 100755 --- a/spec/unit/provider/user/useradd_spec.rb +++ b/spec/unit/provider/user/useradd_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:user).provider(:useradd) diff --git a/spec/unit/provider/vlan/cisco_spec.rb b/spec/unit/provider/vlan/cisco_spec.rb new file mode 100755 index 000000000..bb243a75e --- /dev/null +++ b/spec/unit/provider/vlan/cisco_spec.rb @@ -0,0 +1,62 @@ +#!/usr/bin/env rspec + +require File.dirname(__FILE__) + '/../../../spec_helper' + +require 'puppet/provider/vlan/cisco' + +provider_class = Puppet::Type.type(:vlan).provider(:cisco) + +describe provider_class do + before do + @resource = stub("resource", :name => "200") + @provider = provider_class.new(@resource) + end + + it "should have a parent of Puppet::Provider::NetworkDevice" do + provider_class.should < Puppet::Provider::NetworkDevice + end + + it "should have an instances method" do + provider_class.should respond_to(:instances) + end + + describe "when looking up instances at prefetch" do + before do + @device = stub_everything 'device' + Puppet::Util::NetworkDevice::Cisco::Device.stubs(:new).returns(@device) + @device.stubs(:command).yields(@device) + end + + it "should initialize the network device with the given url" do + Puppet::Util::NetworkDevice::Cisco::Device.expects(:new).with(:url).returns(@device) + provider_class.lookup(:url, "200") + end + + it "should delegate to the device vlans" do + @device.expects(:parse_vlans) + provider_class.lookup("", "200") + end + + it "should return only the given vlan" do + @device.expects(:parse_vlans).returns({"200" => { :description => "thisone" }, "1" => { :description => "nothisone" }}) + provider_class.lookup("", "200").should == {:description => "thisone" } + end + + end + + describe "when an instance is being flushed" do + it "should call the device update_vlan method with its vlan id, current attributes, and desired attributes" do + @instance = provider_class.new(:ensure => :present, :name => "200", :description => "myvlan") + @instance.description = "myvlan2" + @instance.resource = @resource + @resource.stubs(:[]).with(:name).returns("200") + device = stub_everything 'device' + @instance.stubs(:device).returns(device) + device.expects(:command).yields(device) + device.expects(:update_vlan).with(@instance.name, {:ensure => :present, :name => "200", :description => "myvlan"}, + {:ensure => :present, :name => "200", :description => "myvlan2"}) + + @instance.flush + end + end +end diff --git a/spec/unit/provider/zfs/solaris_spec.rb b/spec/unit/provider/zfs/solaris_spec.rb index 84a2be9f6..8a0cd23b1 100755 --- a/spec/unit/provider/zfs/solaris_spec.rb +++ b/spec/unit/provider/zfs/solaris_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:zfs).provider(:solaris) diff --git a/spec/unit/provider/zone/solaris_spec.rb b/spec/unit/provider/zone/solaris_spec.rb index 4a1d03272..17ec8f68f 100755 --- a/spec/unit/provider/zone/solaris_spec.rb +++ b/spec/unit/provider/zone/solaris_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:zone).provider(:solaris) diff --git a/spec/unit/provider/zpool/solaris_spec.rb b/spec/unit/provider/zpool/solaris_spec.rb index e2a0e16c8..7e3048a7a 100755 --- a/spec/unit/provider/zpool/solaris_spec.rb +++ b/spec/unit/provider/zpool/solaris_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' provider_class = Puppet::Type.type(:zpool).provider(:solaris) diff --git a/spec/unit/provider_spec.rb b/spec/unit/provider_spec.rb index 24f5216fe..4eb5e12de 100755 --- a/spec/unit/provider_spec.rb +++ b/spec/unit/provider_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Provider do it "should have a specifity class method" do diff --git a/spec/unit/puppet/provider/README.markdown b/spec/unit/puppet/provider/README.markdown new file mode 100644 index 000000000..702585021 --- /dev/null +++ b/spec/unit/puppet/provider/README.markdown @@ -0,0 +1,4 @@ +Provider Specs +============== + +Define specs for your providers under this directory. diff --git a/spec/unit/puppet/type/README.markdown b/spec/unit/puppet/type/README.markdown new file mode 100644 index 000000000..1ee19ac84 --- /dev/null +++ b/spec/unit/puppet/type/README.markdown @@ -0,0 +1,4 @@ +Resource Type Specs +=================== + +Define specs for your resource types in this directory. diff --git a/spec/unit/puppet_spec.rb b/spec/unit/puppet_spec.rb index 28dbd5104..50d3a4718 100755 --- a/spec/unit/puppet_spec.rb +++ b/spec/unit/puppet_spec.rb @@ -1,6 +1,6 @@ -#!/usr/bin/env ruby" +#!/usr/bin/env rspec" -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +require 'spec_helper' require 'puppet' describe Puppet do diff --git a/spec/unit/rails/host_spec.rb b/spec/unit/rails/host_spec.rb index e83135c91..df0b2fa1d 100755 --- a/spec/unit/rails/host_spec.rb +++ b/spec/unit/rails/host_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe "Puppet::Rails::Host", :if => Puppet.features.rails? do def column(name, type) diff --git a/spec/unit/rails/param_value_spec.rb b/spec/unit/rails/param_value_spec.rb index 9a725cfc8..7f0086252 100755 --- a/spec/unit/rails/param_value_spec.rb +++ b/spec/unit/rails/param_value_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/rails' describe "Puppet::Rails::ParamValue", :if => Puppet.features.rails? do diff --git a/spec/unit/rails/resource_spec.rb b/spec/unit/rails/resource_spec.rb index 3fbbbc7b7..22e5267f4 100755 --- a/spec/unit/rails/resource_spec.rb +++ b/spec/unit/rails/resource_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/rails' describe "Puppet::Rails::Resource", :if => Puppet.features.rails? do diff --git a/spec/unit/rails_spec.rb b/spec/unit/rails_spec.rb index a08485e4c..fe7fd8e29 100755 --- a/spec/unit/rails_spec.rb +++ b/spec/unit/rails_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/rails' describe Puppet::Rails, "when initializing any connection", :if => Puppet.features.rails? do diff --git a/spec/unit/relationship_spec.rb b/spec/unit/relationship_spec.rb index 362d74c74..a7e787b46 100755 --- a/spec/unit/relationship_spec.rb +++ b/spec/unit/relationship_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-11-1. # Copyright (c) 2006. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +require 'spec_helper' require 'puppet/relationship' describe Puppet::Relationship do diff --git a/spec/unit/reports/http_spec.rb b/spec/unit/reports/http_spec.rb index a62793ed5..d7c37bfdd 100644..100755 --- a/spec/unit/reports/http_spec.rb +++ b/spec/unit/reports/http_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/reports' diff --git a/spec/unit/reports/rrdgraph_spec.rb b/spec/unit/reports/rrdgraph_spec.rb index 5215f1dcc..3c2704a7a 100644..100755 --- a/spec/unit/reports/rrdgraph_spec.rb +++ b/spec/unit/reports/rrdgraph_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/reports' diff --git a/spec/unit/reports/store_spec.rb b/spec/unit/reports/store_spec.rb index d48f6a846..73a7e353f 100644..100755 --- a/spec/unit/reports/store_spec.rb +++ b/spec/unit/reports/store_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/reports' require 'time' diff --git a/spec/unit/reports/tagmail_spec.rb b/spec/unit/reports/tagmail_spec.rb index 716bcbc04..a53d11978 100755 --- a/spec/unit/reports/tagmail_spec.rb +++ b/spec/unit/reports/tagmail_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/reports' diff --git a/spec/unit/reports_spec.rb b/spec/unit/reports_spec.rb index a9d10be17..a4b2e04a9 100755 --- a/spec/unit/reports_spec.rb +++ b/spec/unit/reports_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/reports' diff --git a/spec/unit/resource/catalog_spec.rb b/spec/unit/resource/catalog_spec.rb index 78d1b3223..ae65aa91a 100755 --- a/spec/unit/resource/catalog_spec.rb +++ b/spec/unit/resource/catalog_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Resource::Catalog, "when compiling" do diff --git a/spec/unit/resource/status_spec.rb b/spec/unit/resource/status_spec.rb index 343b8d318..bb88518c0 100755 --- a/spec/unit/resource/status_spec.rb +++ b/spec/unit/resource/status_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/resource/status' diff --git a/spec/unit/resource/type_collection_helper_spec.rb b/spec/unit/resource/type_collection_helper_spec.rb index 442cfd076..ad8d75271 100644..100755 --- a/spec/unit/resource/type_collection_helper_spec.rb +++ b/spec/unit/resource/type_collection_helper_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/resource/type_collection_helper' diff --git a/spec/unit/resource/type_collection_spec.rb b/spec/unit/resource/type_collection_spec.rb index 278e629bd..0c997c2ad 100644..100755 --- a/spec/unit/resource/type_collection_spec.rb +++ b/spec/unit/resource/type_collection_spec.rb @@ -1,11 +1,12 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/resource/type_collection' require 'puppet/resource/type' describe Puppet::Resource::TypeCollection do + include PuppetSpec::Files + before do @instance = Puppet::Resource::Type.new(:hostclass, "foo") @code = Puppet::Resource::TypeCollection.new("env") @@ -82,11 +83,14 @@ describe Puppet::Resource::TypeCollection do loader.add Puppet::Resource::Type.new(:hostclass, "class") loader.add Puppet::Resource::Type.new(:definition, "define") loader.add Puppet::Resource::Type.new(:node, "node") + watched_file = tmpfile('watched_file') + loader.watch_file(watched_file) loader.clear loader.hostclass("class").should be_nil loader.definition("define").should be_nil loader.node("node").should be_nil + loader.should_not be_watching_file(watched_file) end describe "when resolving namespaces" do diff --git a/spec/unit/resource/type_spec.rb b/spec/unit/resource/type_spec.rb index 41b5554d9..352f767e4 100755 --- a/spec/unit/resource/type_spec.rb +++ b/spec/unit/resource/type_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/resource/type' @@ -237,35 +236,6 @@ describe Puppet::Resource::Type do end end - describe "when creating a subscope" do - before do - @scope = stub 'scope', :newscope => nil - @resource = stub 'resource' - @type = Puppet::Resource::Type.new(:hostclass, "foo") - end - - it "should return a new scope created with the provided scope as the parent" do - @scope.expects(:newscope).returns "foo" - @type.subscope(@scope, @resource).should == "foo" - end - - it "should set the source as itself" do - @scope.expects(:newscope).with { |args| args[:source] == @type } - @type.subscope(@scope, @resource) - end - - it "should set the scope's namespace to its namespace" do - @type.expects(:namespace).returns "yayness" - @scope.expects(:newscope).with { |args| args[:namespace] == "yayness" } - @type.subscope(@scope, @resource) - end - - it "should set the scope's resource to the provided resource" do - @scope.expects(:newscope).with { |args| args[:resource] == @resource } - @type.subscope(@scope, @resource) - end - end - describe "when setting its parameters in the scope" do before do @scope = Puppet::Parser::Scope.new(:compiler => stub("compiler", :environment => Puppet::Node::Environment.new), :source => stub("source")) @@ -465,7 +435,7 @@ describe Puppet::Resource::Type do it "should set all of its parameters in a subscope" do subscope = stub 'subscope', :compiler => @compiler - @type.expects(:subscope).with(@scope, @resource).returns subscope + @scope.expects(:newscope).with(:source => @type, :dynamic => true, :namespace => 'foo', :resource => @resource).returns subscope @type.expects(:set_resource_parameters).with(@resource, subscope) @type.evaluate_code(@resource) @@ -493,8 +463,9 @@ describe Puppet::Resource::Type do it "should evaluate the AST code if any is provided" do code = stub 'code' @type.stubs(:code).returns code - @type.stubs(:subscope).returns stub_everything("subscope", :compiler => @compiler) - code.expects(:safeevaluate).with @type.subscope + subscope = stub_everything("subscope", :compiler => @compiler) + @scope.stubs(:newscope).returns subscope + code.expects(:safeevaluate).with subscope @type.evaluate_code(@resource) end diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index 916741d1a..79ea69e9c 100755 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/resource' describe Puppet::Resource do diff --git a/spec/unit/run_spec.rb b/spec/unit/run_spec.rb index 6c5ecde65..ea6ec74b1 100755 --- a/spec/unit/run_spec.rb +++ b/spec/unit/run_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/agent' require 'puppet/run' diff --git a/spec/unit/simple_graph_spec.rb b/spec/unit/simple_graph_spec.rb index 99db2a55c..c8fea3b58 100755 --- a/spec/unit/simple_graph_spec.rb +++ b/spec/unit/simple_graph_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-11-1. # Copyright (c) 2006. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +require 'spec_helper' require 'puppet/simple_graph' describe Puppet::SimpleGraph do diff --git a/spec/unit/ssl/base_spec.rb b/spec/unit/ssl/base_spec.rb index 99038391f..125623b70 100755 --- a/spec/unit/ssl/base_spec.rb +++ b/spec/unit/ssl/base_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/ssl/certificate' @@ -40,4 +39,4 @@ describe Puppet::SSL::Certificate do @base.fingerprint(:digest).should == "DI:GE:ST" end end -end
\ No newline at end of file +end diff --git a/spec/unit/ssl/certificate_authority/interface_spec.rb b/spec/unit/ssl/certificate_authority/interface_spec.rb index 2e4a3fc77..9e858dd54 100755 --- a/spec/unit/ssl/certificate_authority/interface_spec.rb +++ b/spec/unit/ssl/certificate_authority/interface_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/ssl/certificate_authority' diff --git a/spec/unit/ssl/certificate_authority_spec.rb b/spec/unit/ssl/certificate_authority_spec.rb index 76633b48f..3aedfdc25 100755 --- a/spec/unit/ssl/certificate_authority_spec.rb +++ b/spec/unit/ssl/certificate_authority_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/ssl/certificate_authority' diff --git a/spec/unit/ssl/certificate_factory_spec.rb b/spec/unit/ssl/certificate_factory_spec.rb index c2bcb19ce..f34dafe43 100755 --- a/spec/unit/ssl/certificate_factory_spec.rb +++ b/spec/unit/ssl/certificate_factory_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/ssl/certificate_factory' diff --git a/spec/unit/ssl/certificate_request_spec.rb b/spec/unit/ssl/certificate_request_spec.rb index 32c9cb51d..e45f0130b 100755 --- a/spec/unit/ssl/certificate_request_spec.rb +++ b/spec/unit/ssl/certificate_request_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/ssl/certificate_request' require 'puppet/ssl/key' diff --git a/spec/unit/ssl/certificate_revocation_list_spec.rb b/spec/unit/ssl/certificate_revocation_list_spec.rb index e83ad9cc5..99058b353 100755 --- a/spec/unit/ssl/certificate_revocation_list_spec.rb +++ b/spec/unit/ssl/certificate_revocation_list_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/ssl/certificate_revocation_list' diff --git a/spec/unit/ssl/certificate_spec.rb b/spec/unit/ssl/certificate_spec.rb index b3af9f236..0b635f2bc 100755 --- a/spec/unit/ssl/certificate_spec.rb +++ b/spec/unit/ssl/certificate_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/ssl/certificate' diff --git a/spec/unit/ssl/host_spec.rb b/spec/unit/ssl/host_spec.rb index 885bd45e2..2624c2234 100755 --- a/spec/unit/ssl/host_spec.rb +++ b/spec/unit/ssl/host_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/ssl/host' require 'puppet/sslcertificates' diff --git a/spec/unit/ssl/inventory_spec.rb b/spec/unit/ssl/inventory_spec.rb index 4d47a37c6..d8606b1b4 100755 --- a/spec/unit/ssl/inventory_spec.rb +++ b/spec/unit/ssl/inventory_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/ssl/inventory' diff --git a/spec/unit/ssl/key_spec.rb b/spec/unit/ssl/key_spec.rb index e0667a5cc..cddf9f8ea 100755 --- a/spec/unit/ssl/key_spec.rb +++ b/spec/unit/ssl/key_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/ssl/key' diff --git a/spec/unit/sslcertificates/ca_spec.rb b/spec/unit/sslcertificates/ca_spec.rb index 4e44f2d90..eea246ba1 100644..100755 --- a/spec/unit/sslcertificates/ca_spec.rb +++ b/spec/unit/sslcertificates/ca_spec.rb @@ -1,5 +1,5 @@ -#!/usr/bin/env ruby -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet' require 'puppet/sslcertificates' diff --git a/spec/unit/status_spec.rb b/spec/unit/status_spec.rb index 3a9c805b3..820807638 100644..100755 --- a/spec/unit/status_spec.rb +++ b/spec/unit/status_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Status do it "should implement find" do diff --git a/spec/unit/transaction/event_manager_spec.rb b/spec/unit/transaction/event_manager_spec.rb index e45fbdf78..d127d0391 100755 --- a/spec/unit/transaction/event_manager_spec.rb +++ b/spec/unit/transaction/event_manager_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/transaction/event_manager' diff --git a/spec/unit/transaction/event_spec.rb b/spec/unit/transaction/event_spec.rb index c77716cd6..1227802a7 100755 --- a/spec/unit/transaction/event_spec.rb +++ b/spec/unit/transaction/event_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/transaction/event' diff --git a/spec/unit/transaction/report_spec.rb b/spec/unit/transaction/report_spec.rb index a3bfe1e82..191a30eb7 100755 --- a/spec/unit/transaction/report_spec.rb +++ b/spec/unit/transaction/report_spec.rb @@ -1,10 +1,10 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/transaction/report' describe Puppet::Transaction::Report do + include PuppetSpec::Files before do Puppet::Util::Storage.stubs(:store) end @@ -38,6 +38,24 @@ describe Puppet::Transaction::Report do report.configuration_version.should == "some version" end + it "should not include whits" do + Puppet::FileBucket::File.indirection.stubs(:save) + + filename = tmpfile('whit_test') + file = Puppet::Type.type(:file).new(:path => filename) + + catalog = Puppet::Resource::Catalog.new + catalog.add_resource(file) + + report = Puppet::Transaction::Report.new("apply") + + catalog.apply(:report => report) + report.finalize_report + + report.resource_statuses.values.any? {|res| res.resource_type =~ /whit/i}.should be_false + report.metrics['time'].values.any? {|metric| metric.first =~ /whit/i}.should be_false + end + describe "when accepting logs" do before do @report = Puppet::Transaction::Report.new("apply") diff --git a/spec/unit/transaction/resource_harness_spec.rb b/spec/unit/transaction/resource_harness_spec.rb index 168b50287..20a42d27b 100755 --- a/spec/unit/transaction/resource_harness_spec.rb +++ b/spec/unit/transaction/resource_harness_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/transaction/resource_harness' diff --git a/spec/unit/transaction_spec.rb b/spec/unit/transaction_spec.rb index ab76130e3..4157e58ac 100755 --- a/spec/unit/transaction_spec.rb +++ b/spec/unit/transaction_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/transaction' diff --git a/spec/unit/transportable_spec.rb b/spec/unit/transportable_spec.rb index e69de29bb..e69de29bb 100644..100755 --- a/spec/unit/transportable_spec.rb +++ b/spec/unit/transportable_spec.rb diff --git a/spec/unit/type/augeas_spec.rb b/spec/unit/type/augeas_spec.rb index dece395e1..c8dc207f9 100644..100755 --- a/spec/unit/type/augeas_spec.rb +++ b/spec/unit/type/augeas_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' augeas = Puppet::Type.type(:augeas) diff --git a/spec/unit/type/component_spec.rb b/spec/unit/type/component_spec.rb index 60abfafbf..9d6d71926 100755 --- a/spec/unit/type/component_spec.rb +++ b/spec/unit/type/component_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' component = Puppet::Type.type(:component) diff --git a/spec/unit/type/computer_spec.rb b/spec/unit/type/computer_spec.rb index 3177884f7..1e15d7a4f 100755 --- a/spec/unit/type/computer_spec.rb +++ b/spec/unit/type/computer_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' computer = Puppet::Type.type(:computer) diff --git a/spec/unit/type/cron_spec.rb b/spec/unit/type/cron_spec.rb index 5466b4d58..7bf92eb02 100755 --- a/spec/unit/type/cron_spec.rb +++ b/spec/unit/type/cron_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Type.type(:cron) do before do @@ -478,4 +477,14 @@ describe Puppet::Type.type(:cron) do end end + + it "should require a command when adding an entry" do + entry = @class.new(:name => "test_entry", :ensure => :present) + expect { entry.value(:command) }.should raise_error(/No command/) + end + + it "should not require a command when removing an entry" do + entry = @class.new(:name => "test_entry", :ensure => :absent) + entry.value(:command).should == nil + end end diff --git a/spec/unit/type/exec_spec.rb b/spec/unit/type/exec_spec.rb index 86b824423..47d1b8523 100755 --- a/spec/unit/type/exec_spec.rb +++ b/spec/unit/type/exec_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Type.type(:exec) do def exec_tester(command, exitstatus = 0, rest = {}) diff --git a/spec/unit/type/file/checksum_spec.rb b/spec/unit/type/file/checksum_spec.rb index 16e8e99e1..b47f617cc 100644..100755 --- a/spec/unit/type/file/checksum_spec.rb +++ b/spec/unit/type/file/checksum_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' checksum = Puppet::Type.type(:file).attrclass(:checksum) describe checksum do diff --git a/spec/unit/type/file/content_spec.rb b/spec/unit/type/file/content_spec.rb index 7abc7c433..7af5f9d83 100755 --- a/spec/unit/type/file/content_spec.rb +++ b/spec/unit/type/file/content_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' content = Puppet::Type.type(:file).attrclass(:content) describe content do diff --git a/spec/unit/type/file/ctime.rb b/spec/unit/type/file/ctime.rb index 9fb892aed..1700d4928 100644..100755 --- a/spec/unit/type/file/ctime.rb +++ b/spec/unit/type/file/ctime.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Type.type(:file).attrclass(:ctime) do require 'puppet_spec/files' diff --git a/spec/unit/type/file/ensure_spec.rb b/spec/unit/type/file/ensure_spec.rb index c5351309e..8555ef035 100755 --- a/spec/unit/type/file/ensure_spec.rb +++ b/spec/unit/type/file/ensure_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' property = Puppet::Type.type(:file).attrclass(:ensure) diff --git a/spec/unit/type/file/group_spec.rb b/spec/unit/type/file/group_spec.rb index 37a6872bd..707a37cd6 100755 --- a/spec/unit/type/file/group_spec.rb +++ b/spec/unit/type/file/group_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' property = Puppet::Type.type(:file).attrclass(:group) diff --git a/spec/unit/type/file/mtime.rb b/spec/unit/type/file/mtime.rb index fa61bc343..3222df095 100644..100755 --- a/spec/unit/type/file/mtime.rb +++ b/spec/unit/type/file/mtime.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Type.type(:file).attrclass(:mtime) do require 'puppet_spec/files' diff --git a/spec/unit/type/file/owner_spec.rb b/spec/unit/type/file/owner_spec.rb index 375faa237..ed3bef1fe 100755 --- a/spec/unit/type/file/owner_spec.rb +++ b/spec/unit/type/file/owner_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' property = Puppet::Type.type(:file).attrclass(:owner) diff --git a/spec/unit/type/file/selinux_spec.rb b/spec/unit/type/file/selinux_spec.rb index 45e8b3b14..2622948d0 100644..100755 --- a/spec/unit/type/file/selinux_spec.rb +++ b/spec/unit/type/file/selinux_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' [:seluser, :selrole, :seltype, :selrange].each do |param| diff --git a/spec/unit/type/file/source_spec.rb b/spec/unit/type/file/source_spec.rb index bb83e7531..5665d323d 100755 --- a/spec/unit/type/file/source_spec.rb +++ b/spec/unit/type/file/source_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' source = Puppet::Type.type(:file).attrclass(:source) describe Puppet::Type.type(:file).attrclass(:source) do @@ -187,6 +186,7 @@ describe Puppet::Type.type(:file).attrclass(:source) do describe "and the source is a link" do it "should set the target to the link destination" do @metadata.stubs(:ftype).returns "link" + @metadata.stubs(:links).returns "manage" @resource.stubs(:[]) @resource.stubs(:[]=) diff --git a/spec/unit/type/file/type.rb b/spec/unit/type/file/type.rb index 0d38b64cd..7d4af0e16 100644..100755 --- a/spec/unit/type/file/type.rb +++ b/spec/unit/type/file/type.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Type.type(:file).attrclass(:type) do require 'puppet_spec/files' diff --git a/spec/unit/type/file_spec.rb b/spec/unit/type/file_spec.rb index b15d41d4b..683c3654b 100755 --- a/spec/unit/type/file_spec.rb +++ b/spec/unit/type/file_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Type.type(:file) do before do diff --git a/spec/unit/type/filebucket_spec.rb b/spec/unit/type/filebucket_spec.rb index 7fcbacc4f..3c5311184 100644..100755 --- a/spec/unit/type/filebucket_spec.rb +++ b/spec/unit/type/filebucket_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Type.type(:filebucket) do describe "when validating attributes" do diff --git a/spec/unit/type/group_spec.rb b/spec/unit/type/group_spec.rb index 43fdfcd4d..42fd3fb7b 100755 --- a/spec/unit/type/group_spec.rb +++ b/spec/unit/type/group_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Type.type(:group) do before do @@ -16,6 +15,10 @@ describe Puppet::Type.type(:group) do @class.defaultprovider.ancestors.should be_include(Puppet::Provider) end + it "should have a system_groups feature" do + @class.provider_feature(:system_groups).should_not be_nil + end + describe "when validating attributes" do [:name, :allowdupe].each do |param| it "should have a #{param} parameter" do @@ -38,11 +41,14 @@ describe Puppet::Type.type(:group) do end end - # #1407 - we need to declare the allowdupe param as boolean. it "should have a boolean method for determining if duplicates are allowed" do @class.new(:name => "foo").methods.should be_include("allowdupe?") end + it "should have a boolean method for determining if system groups are allowed" do + @class.new(:name => "foo").methods.should be_include("system?") + end + it "should call 'create' to create the group" do group = @class.new(:name => "foo", :ensure => :present) group.provider.expects(:create) diff --git a/spec/unit/type/host_spec.rb b/spec/unit/type/host_spec.rb index 60ce73c6d..602c428af 100755 --- a/spec/unit/type/host_spec.rb +++ b/spec/unit/type/host_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' host = Puppet::Type.type(:host) diff --git a/spec/unit/type/interface_spec.rb b/spec/unit/type/interface_spec.rb new file mode 100755 index 000000000..68f4c765f --- /dev/null +++ b/spec/unit/type/interface_spec.rb @@ -0,0 +1,93 @@ +#!/usr/bin/env rspec + +require File.dirname(__FILE__) + '/../../spec_helper' + +describe Puppet::Type.type(:interface) do + it "should have a 'name' parameter'" do + Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1")[:name].should == "FastEthernet 0/1" + end + + it "should have a 'device_url' parameter'" do + Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :device_url => :device)[:device_url].should == :device + end + + it "should have an ensure property" do + Puppet::Type.type(:interface).attrtype(:ensure).should == :property + end + + [:description, :speed, :duplex, :native_vlan, :encapsulation, :mode, :allowed_trunk_vlans, :etherchannel, :ipaddress].each do |p| + it "should have a #{p} property" do + Puppet::Type.type(:interface).attrtype(p).should == :property + end + end + + describe "when validating attribute values" do + before do + @provider = stub 'provider', :class => Puppet::Type.type(:interface).defaultprovider, :clear => nil + Puppet::Type.type(:interface).defaultprovider.stubs(:new).returns(@provider) + end + + it "should support :present as a value to :ensure" do + Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :ensure => :present) + end + + it "should support :shutdown as a value to :ensure" do + Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :ensure => :shutdown) + end + + it "should support :no_shutdown as a value to :ensure" do + Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :ensure => :no_shutdown) + end + + describe "especially speed" do + it "should allow a number" do + Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :speed => "100") + end + + it "should allow :auto" do + Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :speed => :auto) + end + end + + describe "especially duplex" do + it "should allow :half" do + Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :duplex => :half) + end + + it "should allow :full" do + Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :duplex => :full) + end + + it "should allow :auto" do + Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :duplex => :auto) + end + end + + describe "especially ipaddress" do + it "should allow ipv4 addresses" do + Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :ipaddress => "192.168.0.1/24") + end + + it "should allow arrays of ipv4 addresses" do + Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :ipaddress => ["192.168.0.1/24", "192.168.1.0/24"]) + end + + it "should allow ipv6 addresses" do + Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :ipaddress => "f0e9::/64") + end + + it "should allow ipv6 options" do + Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :ipaddress => "f0e9::/64 link-local") + Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :ipaddress => "f0e9::/64 eui-64") + end + + it "should allow a mix of ipv4 and ipv6" do + Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :ipaddress => ["192.168.0.1/24", "f0e9::/64 link-local"]) + end + + it "should munge ip addresses to a computer format" do + Puppet::Type.type(:interface).new(:name => "FastEthernet 0/1", :ipaddress => "192.168.0.1/24")[:ipaddress].should == [[24, IPAddr.new('192.168.0.1'), nil]] + end + end + end +end diff --git a/spec/unit/type/macauthorization_spec.rb b/spec/unit/type/macauthorization_spec.rb index e0d3b9433..8ab30834b 100755 --- a/spec/unit/type/macauthorization_spec.rb +++ b/spec/unit/type/macauthorization_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' macauth_type = Puppet::Type.type(:macauthorization) diff --git a/spec/unit/type/maillist_spec.rb b/spec/unit/type/maillist_spec.rb index 7e96b4760..ae5fcd5b3 100755 --- a/spec/unit/type/maillist_spec.rb +++ b/spec/unit/type/maillist_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' maillist = Puppet::Type.type(:maillist) diff --git a/spec/unit/type/mcx_spec.rb b/spec/unit/type/mcx_spec.rb index 4b60a5c96..02f691a52 100755 --- a/spec/unit/type/mcx_spec.rb +++ b/spec/unit/type/mcx_spec.rb @@ -1,26 +1,5 @@ -#!/usr/bin/env ruby -#-- -# Copyright (C) 2008 Jeffrey J McCune. - -# 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. - -# 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 - -# Author: Jeff McCune <mccune.jeff@gmail.com> - -# Most of this code copied from /spec/type/service.rb - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/type/mcx' diff --git a/spec/unit/type/mount_spec.rb b/spec/unit/type/mount_spec.rb index 4638e9a2e..9ef76992a 100755 --- a/spec/unit/type/mount_spec.rb +++ b/spec/unit/type/mount_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Type.type(:mount) do it "should have a :refreshable feature that requires the :remount method" do diff --git a/spec/unit/type/nagios_spec.rb b/spec/unit/type/nagios_spec.rb index 1515c2ae9..d650723c8 100755 --- a/spec/unit/type/nagios_spec.rb +++ b/spec/unit/type/nagios_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/external/nagios' diff --git a/spec/unit/type/noop_metaparam_spec.rb b/spec/unit/type/noop_metaparam_spec.rb index 6f8f87e6c..f4241d417 100755 --- a/spec/unit/type/noop_metaparam_spec.rb +++ b/spec/unit/type/noop_metaparam_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/type' diff --git a/spec/unit/type/package_spec.rb b/spec/unit/type/package_spec.rb index 3db9c77be..e75f7d290 100755 --- a/spec/unit/type/package_spec.rb +++ b/spec/unit/type/package_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Type.type(:package) do before do diff --git a/spec/unit/type/resources_spec.rb b/spec/unit/type/resources_spec.rb index 020ab9b81..aedc58c7c 100644..100755 --- a/spec/unit/type/resources_spec.rb +++ b/spec/unit/type/resources_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' resources = Puppet::Type.type(:resources) diff --git a/spec/unit/type/schedule_spec.rb b/spec/unit/type/schedule_spec.rb index 59d199812..7599411e4 100755 --- a/spec/unit/type/schedule_spec.rb +++ b/spec/unit/type/schedule_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' module ScheduleTesting diff --git a/spec/unit/type/selboolean_spec.rb b/spec/unit/type/selboolean_spec.rb index 41b254f25..aa495af4a 100755 --- a/spec/unit/type/selboolean_spec.rb +++ b/spec/unit/type/selboolean_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Type.type(:selboolean), "when validating attributes" do [:name, :persistent].each do |param| diff --git a/spec/unit/type/selmodule_spec.rb b/spec/unit/type/selmodule_spec.rb index 37453d8ed..c067de01d 100755 --- a/spec/unit/type/selmodule_spec.rb +++ b/spec/unit/type/selmodule_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Type.type(:selmodule), "when validating attributes" do [:name, :selmoduledir, :selmodulepath].each do |param| diff --git a/spec/unit/type/service_spec.rb b/spec/unit/type/service_spec.rb index b11c4d7e7..40270e7c8 100755 --- a/spec/unit/type/service_spec.rb +++ b/spec/unit/type/service_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Type.type(:service) do it "should have an :enableable feature that requires the :enable, :disable, and :enabled? methods" do diff --git a/spec/unit/type/ssh_authorized_key_spec.rb b/spec/unit/type/ssh_authorized_key_spec.rb index 287fca3ab..a5f167165 100755 --- a/spec/unit/type/ssh_authorized_key_spec.rb +++ b/spec/unit/type/ssh_authorized_key_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' ssh_authorized_key = Puppet::Type.type(:ssh_authorized_key) diff --git a/spec/unit/type/sshkey_spec.rb b/spec/unit/type/sshkey_spec.rb index 8315d7ba9..ba3406976 100644..100755 --- a/spec/unit/type/sshkey_spec.rb +++ b/spec/unit/type/sshkey_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' sshkey = Puppet::Type.type(:sshkey) diff --git a/spec/unit/type/stage_spec.rb b/spec/unit/type/stage_spec.rb index 19922f112..f5fed6c3c 100644..100755 --- a/spec/unit/type/stage_spec.rb +++ b/spec/unit/type/stage_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Type.type(:stage) do it "should have a 'name' parameter'" do diff --git a/spec/unit/type/tidy_spec.rb b/spec/unit/type/tidy_spec.rb index 56bdf6c19..cb030634b 100755 --- a/spec/unit/type/tidy_spec.rb +++ b/spec/unit/type/tidy_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/file_bucket/dipper' tidy = Puppet::Type.type(:tidy) diff --git a/spec/unit/type/user_spec.rb b/spec/unit/type/user_spec.rb index 6421e6049..71c9e1857 100755 --- a/spec/unit/type/user_spec.rb +++ b/spec/unit/type/user_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' user = Puppet::Type.type(:user) diff --git a/spec/unit/type/vlan_spec.rb b/spec/unit/type/vlan_spec.rb new file mode 100755 index 000000000..2983a58e9 --- /dev/null +++ b/spec/unit/type/vlan_spec.rb @@ -0,0 +1,40 @@ +#!/usr/bin/env rspec + +require File.dirname(__FILE__) + '/../../spec_helper' + +describe Puppet::Type.type(:vlan) do + it "should have a 'name' parameter'" do + Puppet::Type.type(:vlan).new(:name => "200")[:name].should == "200" + end + + it "should have a 'device_url' parameter'" do + Puppet::Type.type(:vlan).new(:name => "200", :device_url => :device)[:device_url].should == :device + end + + it "should have an ensure property" do + Puppet::Type.type(:vlan).attrtype(:ensure).should == :property + end + + it "should have a description property" do + Puppet::Type.type(:vlan).attrtype(:description).should == :property + end + + describe "when validating attribute values" do + before do + @provider = stub 'provider', :class => Puppet::Type.type(:vlan).defaultprovider, :clear => nil + Puppet::Type.type(:vlan).defaultprovider.stubs(:new).returns(@provider) + end + + it "should support :present as a value to :ensure" do + Puppet::Type.type(:vlan).new(:name => "200", :ensure => :present) + end + + it "should support :absent as a value to :ensure" do + Puppet::Type.type(:vlan).new(:name => "200", :ensure => :absent) + end + + it "should fail if vlan name is not a number" do + lambda { Puppet::Type.type(:vlan).new(:name => "notanumber", :ensure => :present) }.should raise_error + end + end +end diff --git a/spec/unit/type/whit_spec.rb b/spec/unit/type/whit_spec.rb index 0a3324afa..4d0949900 100644..100755 --- a/spec/unit/type/whit_spec.rb +++ b/spec/unit/type/whit_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' whit = Puppet::Type.type(:whit).new(:name => "Foo::Bar") diff --git a/spec/unit/type/zfs_spec.rb b/spec/unit/type/zfs_spec.rb index 88193fca3..e53c25e02 100755 --- a/spec/unit/type/zfs_spec.rb +++ b/spec/unit/type/zfs_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' zfs = Puppet::Type.type(:zfs) diff --git a/spec/unit/type/zone_spec.rb b/spec/unit/type/zone_spec.rb index e479fb1e9..eb3d33bb0 100755 --- a/spec/unit/type/zone_spec.rb +++ b/spec/unit/type/zone_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' zone = Puppet::Type.type(:zone) diff --git a/spec/unit/type/zpool_spec.rb b/spec/unit/type/zpool_spec.rb index 96e7d548c..9f1800073 100755 --- a/spec/unit/type/zpool_spec.rb +++ b/spec/unit/type/zpool_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' zpool = Puppet::Type.type(:zpool) diff --git a/spec/unit/type_spec.rb b/spec/unit/type_spec.rb index f9372fced..ca291c4fa 100755 --- a/spec/unit/type_spec.rb +++ b/spec/unit/type_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Type do it "should include the Cacher module" do diff --git a/spec/unit/util/autoload/file_cache_spec.rb b/spec/unit/util/autoload/file_cache_spec.rb index 5ad820e4c..cdde9bb48 100755 --- a/spec/unit/util/autoload/file_cache_spec.rb +++ b/spec/unit/util/autoload/file_cache_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/autoload/file_cache' class FileCacheTester diff --git a/spec/unit/util/autoload_spec.rb b/spec/unit/util/autoload_spec.rb index 808885dd7..6d49b57dc 100755 --- a/spec/unit/util/autoload_spec.rb +++ b/spec/unit/util/autoload_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/autoload' diff --git a/spec/unit/util/backups_spec.rb b/spec/unit/util/backups_spec.rb index 3d707a58c..611c19304 100755 --- a/spec/unit/util/backups_spec.rb +++ b/spec/unit/util/backups_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/backups' diff --git a/spec/unit/util/cache_accumulator_spec.rb b/spec/unit/util/cache_accumulator_spec.rb index 4ed9abf5c..9c35cc353 100644..100755 --- a/spec/unit/util/cache_accumulator_spec.rb +++ b/spec/unit/util/cache_accumulator_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/rails/cache_accumulator' describe Puppet::Util::CacheAccumulator do diff --git a/spec/unit/util/cacher_spec.rb b/spec/unit/util/cacher_spec.rb index 125382e84..2e43b4e20 100755 --- a/spec/unit/util/cacher_spec.rb +++ b/spec/unit/util/cacher_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/cacher' diff --git a/spec/unit/util/checksums_spec.rb b/spec/unit/util/checksums_spec.rb index 954dc650b..146544201 100755 --- a/spec/unit/util/checksums_spec.rb +++ b/spec/unit/util/checksums_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-9-22. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/util/checksums' diff --git a/spec/unit/util/command_line_spec.rb b/spec/unit/util/command_line_spec.rb index a7d261dcf..81612ee5c 100755 --- a/spec/unit/util/command_line_spec.rb +++ b/spec/unit/util/command_line_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/command_line' @@ -99,10 +98,11 @@ describe Puppet::Util::CommandLine do Puppet::Util.expects(:which).with('puppet-whatever').returns(nil) commandline.expects(:system).never - commandline.expects(:usage_message).returns("the usage message") - commandline.expects(:abort).with{|x| x =~ /the usage message/}.raises("stubbed abort") + text = Puppet::Face[:help, :current].help + commandline.expects(:puts).with { |x| x =~ /Unknown Puppet subcommand/ } + commandline.expects(:puts).with text - lambda{ commandline.execute }.should raise_error('stubbed abort') + commandline.execute end end end @@ -111,6 +111,11 @@ describe Puppet::Util::CommandLine do @core_apps = %w{describe filebucket kick queue resource agent cert apply doc master} @command_line = Puppet::Util::CommandLine.new("foo", %w{ client --help whatever.pp }, @tty ) end + it "should expose available_subcommands as a class method" do + @core_apps.each do |command| + @command_line.available_subcommands.should include command + end + end it 'should be able to find all existing commands' do @core_apps.each do |command| @command_line.available_subcommands.should include command diff --git a/spec/unit/util/constant_inflector_spec.rb b/spec/unit/util/constant_inflector_spec.rb index 29574fd5b..cf2e8f892 100755 --- a/spec/unit/util/constant_inflector_spec.rb +++ b/spec/unit/util/constant_inflector_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-02-12. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/util/constant_inflector' diff --git a/spec/unit/util/errors_spec.rb b/spec/unit/util/errors_spec.rb index da1b8b0bd..d51a15ef4 100755 --- a/spec/unit/util/errors_spec.rb +++ b/spec/unit/util/errors_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/errors' diff --git a/spec/unit/util/execution_spec.rb b/spec/unit/util/execution_spec.rb index 312dd3b8e..5b8b8a527 100644..100755 --- a/spec/unit/util/execution_spec.rb +++ b/spec/unit/util/execution_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.dirname(__FILE__) + '/../../spec_helper' +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Util::Execution do include Puppet::Util::Execution diff --git a/spec/unit/util/execution_stub_spec.rb b/spec/unit/util/execution_stub_spec.rb index 14cf9c67a..34987689c 100644..100755 --- a/spec/unit/util/execution_stub_spec.rb +++ b/spec/unit/util/execution_stub_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.dirname(__FILE__) + '/../../spec_helper' +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Util::ExecutionStub do it "should use the provided stub code when 'set' is called" do diff --git a/spec/unit/util/feature_spec.rb b/spec/unit/util/feature_spec.rb index 365428752..15375e0b1 100755 --- a/spec/unit/util/feature_spec.rb +++ b/spec/unit/util/feature_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/feature' diff --git a/spec/unit/util/file_locking_spec.rb b/spec/unit/util/file_locking_spec.rb index e9dbe9d7b..261474263 100755 --- a/spec/unit/util/file_locking_spec.rb +++ b/spec/unit/util/file_locking_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/file_locking' diff --git a/spec/unit/util/filetype_spec.rb b/spec/unit/util/filetype_spec.rb index 012631b91..a2c0da660 100644..100755 --- a/spec/unit/util/filetype_spec.rb +++ b/spec/unit/util/filetype_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/filetype' diff --git a/spec/unit/util/inline_docs_spec.rb b/spec/unit/util/inline_docs_spec.rb index 75afb57cb..1d88180b3 100755 --- a/spec/unit/util/inline_docs_spec.rb +++ b/spec/unit/util/inline_docs_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/inline_docs' diff --git a/spec/unit/util/ldap/connection_spec.rb b/spec/unit/util/ldap/connection_spec.rb index 91f008a2e..f97c72d77 100755 --- a/spec/unit/util/ldap/connection_spec.rb +++ b/spec/unit/util/ldap/connection_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-3-19. # Copyright (c) 2006. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/util/ldap/connection' diff --git a/spec/unit/util/ldap/generator_spec.rb b/spec/unit/util/ldap/generator_spec.rb index 59c05b7c7..b3e664d6b 100755 --- a/spec/unit/util/ldap/generator_spec.rb +++ b/spec/unit/util/ldap/generator_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-3-28. # Copyright (c) 2008. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/util/ldap/generator' diff --git a/spec/unit/util/ldap/manager_spec.rb b/spec/unit/util/ldap/manager_spec.rb index e91582c8d..5cce626b5 100755 --- a/spec/unit/util/ldap/manager_spec.rb +++ b/spec/unit/util/ldap/manager_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-3-19. # Copyright (c) 2006. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'spec_helper' require 'puppet/util/ldap/manager' diff --git a/spec/unit/util/loadedfile_spec.rb b/spec/unit/util/loadedfile_spec.rb index 92daeb953..dcea53e45 100755 --- a/spec/unit/util/loadedfile_spec.rb +++ b/spec/unit/util/loadedfile_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'tempfile' require 'puppet/util/loadedfile' diff --git a/spec/unit/util/log/destinations_spec.rb b/spec/unit/util/log/destinations_spec.rb index b84c2ab44..873c5f0c7 100755 --- a/spec/unit/util/log/destinations_spec.rb +++ b/spec/unit/util/log/destinations_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/log' diff --git a/spec/unit/util/log_spec.rb b/spec/unit/util/log_spec.rb index 3c8577493..78411d187 100755 --- a/spec/unit/util/log_spec.rb +++ b/spec/unit/util/log_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/log' diff --git a/spec/unit/util/logging_spec.rb b/spec/unit/util/logging_spec.rb index 97ffc0b25..6a77e70ef 100755 --- a/spec/unit/util/logging_spec.rb +++ b/spec/unit/util/logging_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/logging' @@ -92,4 +91,29 @@ describe Puppet::Util::Logging do end end end + + describe "when sending a deprecation warning" do + before do + @logger.clear_deprecation_warnings + end + + it "should the message with warn" do + @logger.expects(:warning).with('foo') + @logger.deprecation_warning 'foo' + end + + it "should only log each unique message once" do + @logger.expects(:warning).with('foo').once + 5.times { @logger.deprecation_warning 'foo' } + end + + it "should only log the first 100 messages" do + (1..100).each { |i| + @logger.expects(:warning).with(i).once + @logger.deprecation_warning i + } + @logger.expects(:warning).with(101).never + @logger.deprecation_warning 101 + end + end end diff --git a/spec/unit/util/metric_spec.rb b/spec/unit/util/metric_spec.rb index 425812297..07a9e4945 100755 --- a/spec/unit/util/metric_spec.rb +++ b/spec/unit/util/metric_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/metric' diff --git a/spec/unit/util/monkey_patches_spec.rb b/spec/unit/util/monkey_patches_spec.rb index 8bfcd900e..4b609ad09 100644..100755 --- a/spec/unit/util/monkey_patches_spec.rb +++ b/spec/unit/util/monkey_patches_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/monkey_patches' @@ -31,3 +30,26 @@ describe "yaml deserialization" do obj.foo.should == 100 end end + +# In Ruby > 1.8.7 this is a builtin, otherwise we monkey patch the method in +describe "Array#combination" do + it "should fail if wrong number of arguments given" do + lambda { [1,2,3].combination() }.should raise_error(ArgumentError, /wrong number/) + lambda { [1,2,3].combination(1,2) }.should raise_error(ArgumentError, /wrong number/) + end + + it "should return an empty array if combo size than array size or negative" do + [1,2,3].combination(4).to_a.should == [] + [1,2,3].combination(-1).to_a.should == [] + end + + it "should return an empty array with an empty array if combo size == 0" do + [1,2,3].combination(0).to_a.should == [[]] + end + + it "should all provide all combinations of size passed in" do + [1,2,3,4].combination(1).to_a.should == [[1], [2], [3], [4]] + [1,2,3,4].combination(2).to_a.should == [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]] + [1,2,3,4].combination(3).to_a.should == [[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]] + end +end diff --git a/spec/unit/util/nagios_maker_spec.rb b/spec/unit/util/nagios_maker_spec.rb index 20582525d..b61f4fe9d 100755 --- a/spec/unit/util/nagios_maker_spec.rb +++ b/spec/unit/util/nagios_maker_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2007-11-18. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/util/nagios_maker' diff --git a/spec/unit/util/network_device/cisco/device_spec.rb b/spec/unit/util/network_device/cisco/device_spec.rb new file mode 100755 index 000000000..82b0666e6 --- /dev/null +++ b/spec/unit/util/network_device/cisco/device_spec.rb @@ -0,0 +1,521 @@ +#!/usr/bin/env rspec + +require File.dirname(__FILE__) + '/../../../../spec_helper' + +require 'puppet/util/network_device/cisco/device' + +describe Puppet::Util::NetworkDevice::Cisco::Device do + before(:each) do + @transport = stub_everything 'transport', :is_a? => true, :command => "" + @cisco = Puppet::Util::NetworkDevice::Cisco::Device.new("telnet://user:password@localhost:23/") + @cisco.transport = @transport + end + + describe "when creating the device" do + it "should find the enable password from the url" do + cisco = Puppet::Util::NetworkDevice::Cisco::Device.new("telnet://user:password@localhost:23/?enable=enable_password") + cisco.enable_password.should == "enable_password" + end + + it "should find the enable password from the options" do + cisco = Puppet::Util::NetworkDevice::Cisco::Device.new("telnet://user:password@localhost:23/?enable=enable_password", :enable_password => "mypass") + cisco.enable_password.should == "mypass" + end + end + + describe "when connecting to the physical device" do + it "should connect to the transport" do + @transport.expects(:connect) + @cisco.command + end + + it "should attempt to login" do + @cisco.expects(:login) + @cisco.command + end + + it "should tell the device to not page" do + @transport.expects(:command).with("terminal length 0") + @cisco.command + end + + it "should enter the enable password if returned prompt is not privileged" do + @transport.stubs(:command).yields("Switch>").returns("") + @cisco.expects(:enable) + @cisco.command + end + + it "should find device capabilities" do + @cisco.expects(:find_capabilities) + @cisco.command + end + + it "should execute given command" do + @transport.expects(:command).with("mycommand") + @cisco.command("mycommand") + end + + it "should yield to the command block if one is provided" do + @transport.expects(:command).with("mycommand") + @cisco.command do |c| + c.command("mycommand") + end + end + + it "should close the device transport" do + @transport.expects(:close) + @cisco.command + end + + describe "when login in" do + it "should not login if transport handles login" do + @transport.expects(:handles_login?).returns(true) + @transport.expects(:command).never + @transport.expects(:expect).never + @cisco.login + end + + it "should send username if one has been provided" do + @transport.expects(:command).with("user", :prompt => /^Password:/) + @cisco.login + end + + it "should send password after the username" do + @transport.expects(:command).with("user", :prompt => /^Password:/) + @transport.expects(:command).with("password") + @cisco.login + end + + it "should expect the Password: prompt if no user was sent" do + @cisco.url.user = '' + @transport.expects(:expect).with(/^Password:/) + @transport.expects(:command).with("password") + @cisco.login + end + end + + describe "when entering enable password" do + it "should raise an error if no enable password has been set" do + @cisco.enable_password = nil + lambda{ @cisco.enable }.should raise_error + end + + it "should send the enable command and expect an enable prompt" do + @cisco.enable_password = 'mypass' + @transport.expects(:command).with("enable", :prompt => /^Password:/) + @cisco.enable + end + + it "should send the enable password" do + @cisco.enable_password = 'mypass' + @transport.stubs(:command).with("enable", :prompt => /^Password:/) + @transport.expects(:command).with("mypass") + @cisco.enable + end + end + end + + describe "when finding network device capabilities" do + it "should try to execute sh vlan brief" do + @transport.expects(:command).with("sh vlan brief").returns("") + @cisco.find_capabilities + end + + it "should detect errors" do + @transport.stubs(:command).with("sh vlan brief").returns(<<eos) +Switch#sh vlan brief +% Ambiguous command: "sh vlan brief" +Switch# +eos + + @cisco.find_capabilities + @cisco.should_not be_support_vlan_brief + end + end + + + { + "Fa 0/1" => "FastEthernet0/1", + "Fa0/1" => "FastEthernet0/1", + "FastEth 0/1" => "FastEthernet0/1", + "Gi1" => "GigEthernet1", + "Di9" => "Dialer9", + "Ethernet 0/0/1" => "Ethernet0/0/1", + "E0" => "Ethernet0", + "ATM 0/1.1" => "ATM0/1.1", + "VLAN99" => "VLAN99" + }.each do |input,expected| + it "should canonicalize #{input} to #{expected}" do + @cisco.canonalize_ifname(input).should == expected + end + end + + describe "when updating device vlans" do + describe "when removing a vlan" do + it "should issue the no vlan command" do + @transport.expects(:command).with("no vlan 200") + @cisco.update_vlan("200", {:ensure => :present, :name => "200"}, { :ensure=> :absent}) + end + end + + describe "when updating a vlan" do + it "should issue the vlan command to enter global vlan modifications" do + @transport.expects(:command).with("vlan 200") + @cisco.update_vlan("200", {:ensure => :present, :name => "200"}, { :ensure=> :present, :name => "200"}) + end + + it "should issue the name command to modify the vlan description" do + @transport.expects(:command).with("name myvlan") + @cisco.update_vlan("200", {:ensure => :present, :name => "200"}, { :ensure=> :present, :name => "200", :description => "myvlan"}) + end + end + end + + describe "when parsing interface" do + + it "should parse interface output" do + @cisco.expects(:parse_interface).returns({ :ensure => :present }) + + @cisco.interface("FastEthernet0/1").should == { :ensure => :present } + end + + it "should parse trunking and merge results" do + @cisco.stubs(:parse_interface).returns({ :ensure => :present }) + @cisco.expects(:parse_trunking).returns({ :native_vlan => "100" }) + + @cisco.interface("FastEthernet0/1").should == { :ensure => :present, :native_vlan => "100" } + end + + it "should return an absent interface if parse_interface returns nothing" do + @cisco.stubs(:parse_interface).returns({}) + + @cisco.interface("FastEthernet0/1").should == { :ensure => :absent } + end + + it "should parse ip address information and merge results" do + @cisco.stubs(:parse_interface).returns({ :ensure => :present }) + @cisco.expects(:parse_interface_config).returns({ :ipaddress => [24,IPAddr.new('192.168.0.24'), nil] }) + + @cisco.interface("FastEthernet0/1").should == { :ensure => :present, :ipaddress => [24,IPAddr.new('192.168.0.24'), nil] } + end + + it "should parse the sh interface command" do + @transport.stubs(:command).with("sh interface FastEthernet0/1").returns(<<eos) +Switch#sh interfaces FastEthernet 0/1 +FastEthernet0/1 is down, line protocol is down + Hardware is Fast Ethernet, address is 00d0.bbe2.19c1 (bia 00d0.bbe2.19c1) + MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec, + reliability 255/255, txload 1/255, rxload 1/255 + Encapsulation ARPA, loopback not set + Keepalive not set + Auto-duplex , Auto Speed , 100BaseTX/FX + ARP type: ARPA, ARP Timeout 04:00:00 + Last input never, output 5d04h, output hang never + Last clearing of "show interface" counters never + Queueing strategy: fifo + Output queue 0/40, 0 drops; input queue 0/75, 0 drops + 5 minute input rate 0 bits/sec, 0 packets/sec + 5 minute output rate 0 bits/sec, 0 packets/sec + 580 packets input, 54861 bytes + Received 6 broadcasts, 0 runts, 0 giants, 0 throttles + 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored + 0 watchdog, 1 multicast + 0 input packets with dribble condition detected + 845 packets output, 80359 bytes, 0 underruns + 0 output errors, 0 collisions, 1 interface resets + 0 babbles, 0 late collision, 0 deferred + 0 lost carrier, 0 no carrier + 0 output buffer failures, 0 output buffers swapped out +Switch# +eos + + @cisco.parse_interface("FastEthernet0/1").should == { :ensure => :absent, :duplex => :auto, :speed => :auto } + end + + it "should be able to parse the sh vlan brief command output" do + @cisco.stubs(:support_vlan_brief?).returns(true) + @transport.stubs(:command).with("sh vlan brief").returns(<<eos) +Switch#sh vlan brief +VLAN Name Status Ports +---- -------------------------------- --------- ------------------------------- +1 default active Fa0/3, Fa0/4, Fa0/5, Fa0/6, + Fa0/7, Fa0/8, Fa0/9, Fa0/10, + Fa0/11, Fa0/12, Fa0/13, Fa0/14, + Fa0/15, Fa0/16, Fa0/17, Fa0/18, + Fa0/23, Fa0/24 +10 VLAN0010 active +100 management active Fa0/1, Fa0/2 +Switch# +eos + + @cisco.parse_vlans.should == {"100"=>{:status=>"active", :interfaces=>["FastEthernet0/1", "FastEthernet0/2"], :description=>"management", :name=>"100"}, "1"=>{:status=>"active", :interfaces=>["FastEthernet0/3", "FastEthernet0/4", "FastEthernet0/5", "FastEthernet0/6", "FastEthernet0/7", "FastEthernet0/8", "FastEthernet0/9", "FastEthernet0/10", "FastEthernet0/11", "FastEthernet0/12", "FastEthernet0/13", "FastEthernet0/14", "FastEthernet0/15", "FastEthernet0/16", "FastEthernet0/17", "FastEthernet0/18", "FastEthernet0/23", "FastEthernet0/24"], :description=>"default", :name=>"1"}, "10"=>{:status=>"active", :interfaces=>[], :description=>"VLAN0010", :name=>"10"}} + end + + it "should parse trunk switchport information" do + @transport.stubs(:command).with("sh interface FastEthernet0/21 switchport").returns(<<eos) +Switch#sh interfaces FastEthernet 0/21 switchport +Name: Fa0/21 +Switchport: Enabled +Administrative mode: trunk +Operational Mode: trunk +Administrative Trunking Encapsulation: dot1q +Operational Trunking Encapsulation: dot1q +Negotiation of Trunking: Disabled +Access Mode VLAN: 0 ((Inactive)) +Trunking Native Mode VLAN: 1 (default) +Trunking VLANs Enabled: ALL +Trunking VLANs Active: 1,10,100 +Pruning VLANs Enabled: 2-1001 + +Priority for untagged frames: 0 +Override vlan tag priority: FALSE +Voice VLAN: none +Appliance trust: none +Self Loopback: No +Switch# +eos + + @cisco.parse_trunking("FastEthernet0/21").should == { :mode => :trunk, :encapsulation => :dot1q, :allowed_trunk_vlans=>:all, } + end + + it "should parse trunk switchport information with allowed vlans" do + @transport.stubs(:command).with("sh interface GigabitEthernet 0/1 switchport").returns(<<eos) +c2960#sh interfaces GigabitEthernet 0/1 switchport +Name: Gi0/1 +Switchport: Enabled +Administrative Mode: trunk +Operational Mode: trunk +Administrative Trunking Encapsulation: dot1q +Operational Trunking Encapsulation: dot1q +Negotiation of Trunking: On +Access Mode VLAN: 1 (default) +Trunking Native Mode VLAN: 1 (default) +Administrative Native VLAN tagging: enabled +Voice VLAN: none +Administrative private-vlan host-association: none +Administrative private-vlan mapping: none +Administrative private-vlan trunk native VLAN: none +Administrative private-vlan trunk Native VLAN tagging: enabled +Administrative private-vlan trunk encapsulation: dot1q +Administrative private-vlan trunk normal VLANs: none +Administrative private-vlan trunk associations: none +Administrative private-vlan trunk mappings: none +Operational private-vlan: none +Trunking VLANs Enabled: 1,99 +Pruning VLANs Enabled: 2-1001 +Capture Mode Disabled +Capture VLANs Allowed: ALL + +Protected: false +Unknown unicast blocked: disabled +Unknown multicast blocked: disabled +Appliance trust: none +c2960# +eos + + @cisco.parse_trunking("GigabitEthernet 0/1").should == { :mode => :trunk, :encapsulation => :dot1q, :allowed_trunk_vlans=>"1,99", } + end + + it "should parse access switchport information" do + @transport.stubs(:command).with("sh interface FastEthernet0/1 switchport").returns(<<eos) +Switch#sh interfaces FastEthernet 0/1 switchport +Name: Fa0/1 +Switchport: Enabled +Administrative mode: static access +Operational Mode: static access +Administrative Trunking Encapsulation: isl +Operational Trunking Encapsulation: isl +Negotiation of Trunking: Disabled +Access Mode VLAN: 100 (SHDSL) +Trunking Native Mode VLAN: 1 (default) +Trunking VLANs Enabled: NONE +Pruning VLANs Enabled: NONE + +Priority for untagged frames: 0 +Override vlan tag priority: FALSE +Voice VLAN: none +Appliance trust: none +Self Loopback: No +Switch# +eos + + @cisco.parse_trunking("FastEthernet0/1").should == { :mode => :access, :native_vlan => "100" } + end + + it "should parse ip addresses" do + @transport.stubs(:command).with("sh running-config interface Vlan 1 | begin interface").returns(<<eos) +router#sh running-config interface Vlan 1 | begin interface +interface Vlan1 + description $ETH-SW-LAUNCH$$INTF-INFO-HWIC 4ESW$$FW_INSIDE$ + ip address 192.168.0.24 255.255.255.0 secondary + ip address 192.168.0.1 255.255.255.0 + ip access-group 100 in + no ip redirects + no ip proxy-arp + ip nbar protocol-discovery + ip dns view-group dow + ip nat inside + ip virtual-reassembly + ip route-cache flow + ipv6 address 2001:7A8:71C1::/64 eui-64 + ipv6 enable + ipv6 traffic-filter DENY-ACL6 out + ipv6 mtu 1280 + ipv6 nd prefix 2001:7A8:71C1::/64 + ipv6 nd ra interval 60 + ipv6 nd ra lifetime 180 + ipv6 verify unicast reverse-path + ipv6 inspect STD6 out +end + +router# +eos + @cisco.parse_interface_config("Vlan 1").should == {:ipaddress=>[[24, IPAddr.new('192.168.0.24'), 'secondary'], + [24, IPAddr.new('192.168.0.1'), nil], + [64, IPAddr.new('2001:07a8:71c1::'), "eui-64"]]} + end + + it "should parse etherchannel membership" do + @transport.stubs(:command).with("sh running-config interface Gi0/17 | begin interface").returns(<<eos) +c2960#sh running-config interface Gi0/17 | begin interface +interface GigabitEthernet0/17 + description member of Po1 + switchport mode access + channel-protocol lacp + channel-group 1 mode passive + spanning-tree portfast + spanning-tree bpduguard enable +end + +c2960# +eos + @cisco.parse_interface_config("Gi0/17").should == {:etherchannel=>"1"} + end + end +end + +# static access +# Switch#sh interfaces FastEthernet 0/1 switchport +# Name: Fa0/1 +# Switchport: Enabled +# Administrative mode: static access +# Operational Mode: static access +# Administrative Trunking Encapsulation: isl +# Operational Trunking Encapsulation: isl +# Negotiation of Trunking: Disabled +# Access Mode VLAN: 100 (SHDSL) +# Trunking Native Mode VLAN: 1 (default) +# Trunking VLANs Enabled: NONE +# Pruning VLANs Enabled: NONE +# +# Priority for untagged frames: 0 +# Override vlan tag priority: FALSE +# Voice VLAN: none +# Appliance trust: none +# Self Loopback: No +# Switch# + +# c2960#sh interfaces GigabitEthernet 0/1 switchport +# Name: Gi0/1 +# Switchport: Enabled +# Administrative Mode: trunk +# Operational Mode: trunk +# Administrative Trunking Encapsulation: dot1q +# Operational Trunking Encapsulation: dot1q +# Negotiation of Trunking: On +# Access Mode VLAN: 1 (default) +# Trunking Native Mode VLAN: 1 (default) +# Administrative Native VLAN tagging: enabled +# Voice VLAN: none +# Administrative private-vlan host-association: none +# Administrative private-vlan mapping: none +# Administrative private-vlan trunk native VLAN: none +# Administrative private-vlan trunk Native VLAN tagging: enabled +# Administrative private-vlan trunk encapsulation: dot1q +# Administrative private-vlan trunk normal VLANs: none +# Administrative private-vlan trunk associations: none +# Administrative private-vlan trunk mappings: none +# Operational private-vlan: none +# Trunking VLANs Enabled: 1,99 +# Pruning VLANs Enabled: 2-1001 +# Capture Mode Disabled +# Capture VLANs Allowed: ALL +# +# Protected: false +# Unknown unicast blocked: disabled +# Unknown multicast blocked: disabled +# Appliance trust: none +# c2960# + +# c2960#sh interfaces GigabitEthernet 0/2 switchport +# Name: Gi0/2 +# Switchport: Enabled +# Administrative Mode: static access +# Operational Mode: static access +# Administrative Trunking Encapsulation: dot1q +# Operational Trunking Encapsulation: native +# Negotiation of Trunking: Off +# Access Mode VLAN: 99 (MGMT) +# Trunking Native Mode VLAN: 1 (default) +# Administrative Native VLAN tagging: enabled +# Voice VLAN: none +# Administrative private-vlan host-association: none +# Administrative private-vlan mapping: none +# Administrative private-vlan trunk native VLAN: none +# Administrative private-vlan trunk Native VLAN tagging: enabled +# Administrative private-vlan trunk encapsulation: dot1q +# Administrative private-vlan trunk normal VLANs: none +# Administrative private-vlan trunk associations: none +# Administrative private-vlan trunk mappings: none +# Operational private-vlan: none +# Trunking VLANs Enabled: ALL +# Pruning VLANs Enabled: 2-1001 +# Capture Mode Disabled +# Capture VLANs Allowed: ALL +# +# Protected: false +# Unknown unicast blocked: disabled +# Unknown multicast blocked: disabled +# Appliance trust: none +# c2960# + +# c877#sh interfaces FastEthernet 1 switchport +# Name: Fa1 +# Switchport: Enabled +# Administrative Mode: trunk +# Operational Mode: trunk +# Administrative Trunking Encapsulation: dot1q +# Operational Trunking Encapsulation: dot1q +# Negotiation of Trunking: Disabled +# Access Mode VLAN: 0 ((Inactive)) +# Trunking Native Mode VLAN: 1 (default) +# Trunking VLANs Enabled: ALL +# Trunking VLANs Active: 1 +# Protected: false +# Priority for untagged frames: 0 +# Override vlan tag priority: FALSE +# Voice VLAN: none +# Appliance trust: none + + +# c2960#sh etherchannel summary +# Flags: D - down P - bundled in port-channel +# I - stand-alone s - suspended +# H - Hot-standby (LACP only) +# R - Layer3 S - Layer2 +# U - in use f - failed to allocate aggregator +# +# M - not in use, minimum links not met +# u - unsuitable for bundling +# w - waiting to be aggregated +# d - default port +# +# +# Number of channel-groups in use: 1 +# Number of aggregators: 1 +# +# Group Port-channel Protocol Ports +# ------+-------------+-----------+----------------------------------------------- +# 1 Po1(SU) LACP Gi0/17(P) Gi0/18(P) +# +# c2960# diff --git a/spec/unit/util/network_device/cisco/interface_spec.rb b/spec/unit/util/network_device/cisco/interface_spec.rb new file mode 100755 index 000000000..24217750c --- /dev/null +++ b/spec/unit/util/network_device/cisco/interface_spec.rb @@ -0,0 +1,89 @@ +#!/usr/bin/env rspec + +require File.dirname(__FILE__) + '/../../../../spec_helper' + +require 'puppet/util/network_device' +require 'puppet/util/network_device/cisco/interface' + +describe Puppet::Util::NetworkDevice::Cisco::Interface do + before(:each) do + @transport = stub_everything 'transport' + @interface = Puppet::Util::NetworkDevice::Cisco::Interface.new("FastEthernet0/1",@transport) + end + + it "should include IPCalc" do + @interface.class.include?(Puppet::Util::NetworkDevice::IPCalc) + end + + describe "when updating the physical device" do + it "should enter global configuration mode" do + @transport.expects(:command).with("conf t") + @interface.update + end + + it "should enter interface configuration mode" do + @transport.expects(:command).with("interface FastEthernet0/1") + @interface.update + end + + it "should 'execute' all differing properties" do + @interface.expects(:execute).with(:description, "b") + @interface.expects(:execute).with(:mode, :access).never + @interface.update({ :description => "a", :mode => :access }, { :description => "b", :mode => :access }) + end + + it "should execute in cisco ios defined order" do + speed = states('speed').starts_as('notset') + @interface.expects(:execute).with(:speed, :auto).then(speed.is('set')) + @interface.expects(:execute).with(:duplex, :auto).when(speed.is('set')) + @interface.update({ :duplex => :half, :speed => "10" }, { :duplex => :auto, :speed => :auto }) + end + + it "should execute absent properties with a no prefix" do + @interface.expects(:execute).with(:description, "a", "no ") + @interface.update({ :description => "a"}, { }) + end + + it "should exit twice" do + @transport.expects(:command).with("exit").twice + @interface.update + end + end + + describe "when executing commands" do + it "should execute string commands directly" do + @transport.expects(:command).with("speed auto") + @interface.execute(:speed, :auto) + end + + it "should execute string commands with the given prefix" do + @transport.expects(:command).with("no speed auto") + @interface.execute(:speed, :auto, "no ") + end + + it "should stop at executing the first command that works for array" do + @transport.expects(:command).with("channel-group 1").yields("% Invalid command") + @transport.expects(:command).with("port group 1") + @interface.execute(:etherchannel, "1") + end + + it "should execute the block for block commands" do + @transport.expects(:command).with("ip address 192.168.0.1 255.255.255.0") + @interface.execute(:ipaddress, [[24, IPAddr.new('192.168.0.1'), nil]]) + end + + it "should execute the block for block commands" do + @transport.expects(:command).with("ipv6 address fe08::/76 link-local") + @interface.execute(:ipaddress, [[76, IPAddr.new('fe08::'), 'link-local']]) + end + + end + + describe "when sending commands to the device" do + it "should detect errors" do + Puppet.expects(:err) + @transport.stubs(:command).yields("% Invalid Command") + @interface.command("sh ver") + end + end +end diff --git a/spec/unit/util/network_device/ipcalc_spec.rb b/spec/unit/util/network_device/ipcalc_spec.rb new file mode 100755 index 000000000..0418c6a84 --- /dev/null +++ b/spec/unit/util/network_device/ipcalc_spec.rb @@ -0,0 +1,63 @@ +#!/usr/bin/env rspec + +require File.dirname(__FILE__) + '/../../../spec_helper' + +require 'puppet/util/network_device/ipcalc' + +describe Puppet::Util::NetworkDevice::IPCalc do + class TestIPCalc + include Puppet::Util::NetworkDevice::IPCalc + end + + before(:each) do + @ipcalc = TestIPCalc.new + end + + describe "when parsing ip/prefix" do + it "should parse ipv4 without prefixes" do + @ipcalc.parse('127.0.0.1').should == [32,IPAddr.new('127.0.0.1')] + end + + it "should parse ipv4 with prefixes" do + @ipcalc.parse('127.0.1.2/8').should == [8,IPAddr.new('127.0.1.2')] + end + + it "should parse ipv6 without prefixes" do + @ipcalc.parse('FE80::21A:2FFF:FE30:ECF0').should == [128,IPAddr.new('FE80::21A:2FFF:FE30:ECF0')] + end + + it "should parse ipv6 with prefixes" do + @ipcalc.parse('FE80::21A:2FFF:FE30:ECF0/56').should == [56,IPAddr.new('FE80::21A:2FFF:FE30:ECF0')] + end + end + + describe "when building netmask" do + it "should produce the correct ipv4 netmask from prefix length" do + @ipcalc.netmask(Socket::AF_INET, 27).should == IPAddr.new('255.255.255.224') + end + + it "should produce the correct ipv6 netmask from prefix length" do + @ipcalc.netmask(Socket::AF_INET6, 56).should == IPAddr.new('ffff:ffff:ffff:ff00::0') + end + end + + describe "when building wildmask" do + it "should produce the correct ipv4 wildmask from prefix length" do + @ipcalc.wildmask(Socket::AF_INET, 27).should == IPAddr.new('0.0.0.31') + end + + it "should produce the correct ipv6 wildmask from prefix length" do + @ipcalc.wildmask(Socket::AF_INET6, 126).should == IPAddr.new('::3') + end + end + + describe "when computing prefix length from netmask" do + it "should produce the correct ipv4 prefix length" do + @ipcalc.prefix_length(IPAddr.new('255.255.255.224')).should == 27 + end + + it "should produce the correct ipv6 prefix length" do + @ipcalc.prefix_length(IPAddr.new('fffe::0')).should == 15 + end + end +end diff --git a/spec/unit/util/network_device/transport/base_spec.rb b/spec/unit/util/network_device/transport/base_spec.rb new file mode 100755 index 000000000..c186d72e5 --- /dev/null +++ b/spec/unit/util/network_device/transport/base_spec.rb @@ -0,0 +1,42 @@ +#!/usr/bin/env rspec + +require File.dirname(__FILE__) + '/../../../../spec_helper' + +require 'puppet/util/network_device/transport/base' + +describe Puppet::Util::NetworkDevice::Transport::Base do + class TestTransport < Puppet::Util::NetworkDevice::Transport::Base + end + + before(:each) do + @transport = TestTransport.new + end + + describe "when sending commands" do + it "should send the command to the telnet session" do + @transport.expects(:send).with("line") + @transport.command("line") + end + + it "should expect an output matching the given prompt" do + @transport.expects(:expect).with(/prompt/) + @transport.command("line", :prompt => /prompt/) + end + + it "should expect an output matching the default prompt" do + @transport.default_prompt = /defprompt/ + @transport.expects(:expect).with(/defprompt/) + @transport.command("line") + end + + it "should yield telnet output to the given block" do + @transport.expects(:expect).yields("output") + @transport.command("line") { |out| out.should == "output" } + end + + it "should return telnet output to the caller" do + @transport.expects(:expect).returns("output") + @transport.command("line").should == "output" + end + end +end diff --git a/spec/unit/util/network_device/transport/ssh_spec.rb b/spec/unit/util/network_device/transport/ssh_spec.rb new file mode 100755 index 000000000..0e91ed9f9 --- /dev/null +++ b/spec/unit/util/network_device/transport/ssh_spec.rb @@ -0,0 +1,211 @@ +#!/usr/bin/env rspec + +require File.dirname(__FILE__) + '/../../../../spec_helper' + +require 'puppet/util/network_device/transport/ssh' + +describe Puppet::Util::NetworkDevice::Transport::Ssh, :if => Puppet.features.ssh? do + + before(:each) do + @transport = Puppet::Util::NetworkDevice::Transport::Ssh.new() + end + + it "should handle login through the transport" do + @transport.should be_handles_login + end + + it "should connect to the given host and port" do + Net::SSH.expects(:start).with { |host, user, args| host == "localhost" && args[:port] == 22 }.returns stub_everything + @transport.host = "localhost" + @transport.port = 22 + + @transport.connect + end + + it "should connect using the given username and password" do + Net::SSH.expects(:start).with { |host, user, args| user == "user" && args[:password] == "pass" }.returns stub_everything + @transport.user = "user" + @transport.password = "pass" + + @transport.connect + end + + describe "when connected" do + before(:each) do + @ssh = stub_everything 'ssh' + @channel = stub_everything 'channel' + Net::SSH.stubs(:start).returns @ssh + @ssh.stubs(:open_channel).yields(@channel) + @transport.stubs(:expect) + end + + it "should open a channel" do + @ssh.expects(:open_channel) + + @transport.connect + end + + it "should request a pty" do + @channel.expects(:request_pty) + + @transport.connect + end + + it "should create a shell channel" do + @channel.expects(:send_channel_request).with("shell") + @transport.connect + end + + it "should raise an error if shell channel creation fails" do + @channel.expects(:send_channel_request).with("shell").yields(@channel, false) + lambda { @transport.connect }.should raise_error + end + + it "should register an on_data and on_extended_data callback" do + @channel.expects(:send_channel_request).with("shell").yields(@channel, true) + @channel.expects(:on_data) + @channel.expects(:on_extended_data) + @transport.connect + end + + it "should accumulate data to the buffer on data" do + @channel.expects(:send_channel_request).with("shell").yields(@channel, true) + @channel.expects(:on_data).yields(@channel, "data") + + @transport.connect + @transport.buf.should == "data" + end + + it "should accumulate data to the buffer on extended data" do + @channel.expects(:send_channel_request).with("shell").yields(@channel, true) + @channel.expects(:on_extended_data).yields(@channel, 1, "data") + + @transport.connect + @transport.buf.should == "data" + end + + it "should mark eof on close" do + @channel.expects(:send_channel_request).with("shell").yields(@channel, true) + @channel.expects(:on_close).yields(@channel) + + @transport.connect + @transport.should be_eof + end + + it "should expect output to conform to the default prompt" do + @channel.expects(:send_channel_request).with("shell").yields(@channel, true) + @transport.expects(:default_prompt).returns("prompt") + @transport.expects(:expect).with("prompt") + @transport.connect + end + + it "should start the ssh loop" do + @ssh.expects(:loop) + @transport.connect + end + end + + describe "when closing" do + before(:each) do + @ssh = stub_everything 'ssh' + @channel = stub_everything 'channel' + Net::SSH.stubs(:start).returns @ssh + @ssh.stubs(:open_channel).yields(@channel) + @channel.stubs(:send_channel_request).with("shell").yields(@channel, true) + @transport.stubs(:expect) + @transport.connect + end + + it "should close the channel" do + @channel.expects(:close) + @transport.close + end + + it "should close the ssh session" do + @ssh.expects(:close) + @transport.close + end + end + + describe "when sending commands" do + before(:each) do + @ssh = stub_everything 'ssh' + @channel = stub_everything 'channel' + Net::SSH.stubs(:start).returns @ssh + @ssh.stubs(:open_channel).yields(@channel) + @channel.stubs(:send_channel_request).with("shell").yields(@channel, true) + @transport.stubs(:expect) + @transport.connect + end + + it "should send data to the ssh channel" do + @channel.expects(:send_data).with("data\n") + @transport.command("data") + end + + it "should expect the default prompt afterward" do + @transport.expects(:default_prompt).returns("prompt") + @transport.expects(:expect).with("prompt") + @transport.command("data") + end + + it "should expect the given prompt" do + @transport.expects(:expect).with("myprompt") + @transport.command("data", :prompt => "myprompt") + end + + it "should yield the buffer output to given block" do + @transport.expects(:expect).yields("output") + @transport.command("data") do |out| + out.should == "output" + end + end + + it "should return buffer output" do + @transport.expects(:expect).returns("output") + @transport.command("data").should == "output" + end + end + + describe "when expecting output" do + before(:each) do + @connection = stub_everything 'connection' + @socket = stub_everything 'socket' + transport = stub 'transport', :socket => @socket + @ssh = stub_everything 'ssh', :transport => transport + @channel = stub_everything 'channel', :connection => @connection + @transport.ssh = @ssh + @transport.channel = @channel + end + + it "should process the ssh event loop" do + IO.stubs(:select) + @transport.buf = "output" + @transport.expects(:process_ssh) + @transport.expect(/output/) + end + + it "should return the output" do + IO.stubs(:select) + @transport.buf = "output" + @transport.stubs(:process_ssh) + @transport.expect(/output/).should == "output" + end + + it "should return the output" do + IO.stubs(:select) + @transport.buf = "output" + @transport.stubs(:process_ssh) + @transport.expect(/output/).should == "output" + end + + describe "when processing the ssh loop" do + it "should advance one tick in the ssh event loop and exit on eof" do + @transport.buf = '' + @connection.expects(:process).then.raises(EOFError) + @transport.process_ssh + end + end + end + +end diff --git a/spec/unit/util/network_device/transport/telnet_spec.rb b/spec/unit/util/network_device/transport/telnet_spec.rb new file mode 100755 index 000000000..7528e0740 --- /dev/null +++ b/spec/unit/util/network_device/transport/telnet_spec.rb @@ -0,0 +1,76 @@ +#!/usr/bin/env rspec + +require File.dirname(__FILE__) + '/../../../../spec_helper' + +require 'puppet/util/network_device/transport/telnet' + +describe Puppet::Util::NetworkDevice::Transport::Telnet do + + before(:each) do + @transport = Puppet::Util::NetworkDevice::Transport::Telnet.new() + end + + it "should not handle login through the transport" do + @transport.should_not be_handles_login + end + + it "should connect to the given host and port" do + Net::Telnet.expects(:new).with { |args| args["Host"] == "localhost" && args["Port"] == 23 }.returns stub_everything + @transport.host = "localhost" + @transport.port = 23 + + @transport.connect + end + + it "should connect and specify the default prompt" do + @transport.default_prompt = "prompt" + Net::Telnet.expects(:new).with { |args| args["Prompt"] == "prompt" }.returns stub_everything + @transport.host = "localhost" + @transport.port = 23 + + @transport.connect + end + + describe "when connected" do + before(:each) do + @telnet = stub_everything 'telnet' + Net::Telnet.stubs(:new).returns(@telnet) + @transport.connect + end + + it "should send line to the telnet session" do + @telnet.expects(:puts).with("line") + @transport.send("line") + end + + describe "when expecting output" do + it "should waitfor output on the telnet session" do + @telnet.expects(:waitfor).with(/regex/) + @transport.expect(/regex/) + end + + it "should return telnet session output" do + @telnet.expects(:waitfor).returns("output") + @transport.expect(/regex/).should == "output" + end + + it "should yield telnet session output to the given block" do + @telnet.expects(:waitfor).yields("output") + @transport.expect(/regex/) { |out| out.should == "output" } + end + end + end + + describe "when closing" do + before(:each) do + @telnet = stub_everything 'telnet' + Net::Telnet.stubs(:new).returns(@telnet) + @transport.connect + end + + it "should close the telnet session" do + @telnet.expects(:close) + @transport.close + end + end +end diff --git a/spec/unit/util/package_spec.rb b/spec/unit/util/package_spec.rb index e72a7ae91..78c114afc 100644..100755 --- a/spec/unit/util/package_spec.rb +++ b/spec/unit/util/package_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/package' diff --git a/spec/unit/util/posix_spec.rb b/spec/unit/util/posix_spec.rb index 6d7351220..db7c5c3a7 100755 --- a/spec/unit/util/posix_spec.rb +++ b/spec/unit/util/posix_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/posix' diff --git a/spec/unit/util/pson_spec.rb b/spec/unit/util/pson_spec.rb index 08758ee38..63d085a66 100755 --- a/spec/unit/util/pson_spec.rb +++ b/spec/unit/util/pson_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/pson' diff --git a/spec/unit/util/queue/stomp_spec.rb b/spec/unit/util/queue/stomp_spec.rb index a11d5324e..f67189cf5 100755 --- a/spec/unit/util/queue/stomp_spec.rb +++ b/spec/unit/util/queue/stomp_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/queue' describe Puppet::Util::Queue, :if => Puppet.features.stomp? do diff --git a/spec/unit/util/queue_spec.rb b/spec/unit/util/queue_spec.rb index d356fd7bb..59ea57d9b 100755 --- a/spec/unit/util/queue_spec.rb +++ b/spec/unit/util/queue_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/queue' require 'spec/mocks' diff --git a/spec/unit/util/rdoc/parser_spec.rb b/spec/unit/util/rdoc/parser_spec.rb index f118dc99b..c7f99051f 100755 --- a/spec/unit/util/rdoc/parser_spec.rb +++ b/spec/unit/util/rdoc/parser_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/resource/type_collection' require 'puppet/util/rdoc/parser' diff --git a/spec/unit/util/rdoc_spec.rb b/spec/unit/util/rdoc_spec.rb index 3b5248528..067b5b8a7 100755 --- a/spec/unit/util/rdoc_spec.rb +++ b/spec/unit/util/rdoc_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/rdoc' require 'rdoc/rdoc' diff --git a/spec/unit/util/reference_serializer_spec.rb b/spec/unit/util/reference_serializer_spec.rb index f72715ed6..de53ab9bb 100644..100755 --- a/spec/unit/util/reference_serializer_spec.rb +++ b/spec/unit/util/reference_serializer_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/rails/reference_serializer' class SerializeTester diff --git a/spec/unit/util/resource_template_spec.rb b/spec/unit/util/resource_template_spec.rb index e823a9ff4..4f7cafdb7 100755 --- a/spec/unit/util/resource_template_spec.rb +++ b/spec/unit/util/resource_template_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/resource_template' diff --git a/spec/unit/util/run_mode_spec.rb b/spec/unit/util/run_mode_spec.rb index 1956973ea..c8d2b31f6 100644..100755 --- a/spec/unit/util/run_mode_spec.rb +++ b/spec/unit/util/run_mode_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Util::RunMode do before do diff --git a/spec/unit/util/selinux_spec.rb b/spec/unit/util/selinux_spec.rb index c18be0c2f..0eaf43cbb 100755 --- a/spec/unit/util/selinux_spec.rb +++ b/spec/unit/util/selinux_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/selinux' include Puppet::Util::SELinux diff --git a/spec/unit/util/settings/file_setting_spec.rb b/spec/unit/util/settings/file_setting_spec.rb index a2049e2ad..734b41f3a 100755 --- a/spec/unit/util/settings/file_setting_spec.rb +++ b/spec/unit/util/settings/file_setting_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/settings' require 'puppet/util/settings/file_setting' diff --git a/spec/unit/util/settings_spec.rb b/spec/unit/util/settings_spec.rb index 2ab31c294..aa50c8f3a 100755 --- a/spec/unit/util/settings_spec.rb +++ b/spec/unit/util/settings_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Util::Settings do describe "when specifying defaults" do diff --git a/spec/unit/util/storage_spec.rb b/spec/unit/util/storage_spec.rb index 5359f746f..90c11aa69 100755 --- a/spec/unit/util/storage_spec.rb +++ b/spec/unit/util/storage_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'yaml' require 'puppet/util/storage' diff --git a/spec/unit/util/tagging_spec.rb b/spec/unit/util/tagging_spec.rb index 5231be2eb..018871bef 100755 --- a/spec/unit/util/tagging_spec.rb +++ b/spec/unit/util/tagging_spec.rb @@ -1,9 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env rspec # # Created by Luke Kanies on 2008-01-19. # Copyright (c) 2007. All rights reserved. -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require 'spec_helper' require 'puppet/util/tagging' diff --git a/spec/unit/util/user_attr_spec.rb b/spec/unit/util/user_attr_spec.rb index 5acdaee58..2d6ba8b5a 100644..100755 --- a/spec/unit/util/user_attr_spec.rb +++ b/spec/unit/util/user_attr_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/user_attr' diff --git a/spec/unit/util/warnings_spec.rb b/spec/unit/util/warnings_spec.rb index a3460bccf..cc2c44711 100755 --- a/spec/unit/util/warnings_spec.rb +++ b/spec/unit/util/warnings_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' describe Puppet::Util::Warnings do before(:all) do diff --git a/spec/unit/util/zaml_spec.rb b/spec/unit/util/zaml_spec.rb index 804aa8e58..d77cf99d2 100755 --- a/spec/unit/util/zaml_spec.rb +++ b/spec/unit/util/zaml_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +#!/usr/bin/env rspec +require 'spec_helper' require 'puppet/util/monkey_patches' diff --git a/autotest/watcher.rb b/spec/watchr.rb index 9f89a448c..26919d1a1 100644..100755 --- a/autotest/watcher.rb +++ b/spec/watchr.rb @@ -15,10 +15,10 @@ def run_comp(cmd) line << c if c == ?\n results << if RUBY_VERSION >= "1.9" then - line.join - else - line.pack "c*" - end + line.join + else + line.pack "c*" + end line.clear end end @@ -47,7 +47,7 @@ end def file2specs(file) %w{spec/unit spec/integration}.collect { |d| - file.sub('lib/puppet', d) + file.sub('lib/puppet', d).sub(".rb", "_spec.rb") }.find_all { |f| File.exist?(f) } @@ -80,8 +80,12 @@ end def run_spec_files(files) files = Array(files) return if files.empty? - opts = File.readlines('spec/spec.opts').collect { |l| l.chomp }.join(" ") - run_spec("spec #{files.join(' ')}") + if File.exist?(File.expand_path("~/.rspec")) then + opts = '' # use the user defaults + else + opts = File.readlines('spec/spec.opts').collect { |l| l.chomp }.join(" ") + end + run_spec("rspec #{opts} --tty #{files.join(' ')}") end def run_all_tests @@ -89,12 +93,12 @@ def run_all_tests end def run_all_specs - run_test("rake spec") + run_spec_files "spec" end def run_suite - run_all_tests run_all_specs + run_all_tests end watch('spec/spec_helper.rb') { run_all_specs } diff --git a/test/language/functions.rb b/test/language/functions.rb index e882b68f3..84b1b3861 100755 --- a/test/language/functions.rb +++ b/test/language/functions.rb @@ -382,17 +382,15 @@ class TestLangFunctions < Test::Unit::TestCase }.each do |string, value| scope = mkscope scope.setvar("yayness", string) - assert_equal(string, scope.lookupvar("yayness", false)) + assert_equal(string, scope.lookupvar("yayness")) assert_nothing_raised("An empty string was not a valid variable value") do ast.evaluate(scope) end - - assert_equal( - "template #{value}\n", scope.lookupvar("output"), - - "#{string.inspect} did not get evaluated correctly") + assert_equal( + "template #{value}\n", scope.lookupvar("output"), + "#{string.inspect} did not get evaluated correctly") end end diff --git a/test/language/parser.rb b/test/language/parser.rb index 36a9c4787..f7e636add 100755 --- a/test/language/parser.rb +++ b/test/language/parser.rb @@ -14,7 +14,6 @@ class TestParser < Test::Unit::TestCase include PuppetTest::Support::Utils def setup super - Puppet[:parseonly] = true #@lexer = Puppet::Parser::Lexer.new end diff --git a/test/language/scope.rb b/test/language/scope.rb index c4154dc27..ccc359651 100755 --- a/test/language/scope.rb +++ b/test/language/scope.rb @@ -42,22 +42,22 @@ class TestScope < Test::Unit::TestCase # Set a variable in the top and make sure all three can get it topscope.setvar("first", "topval") scopes.each do |name, scope| - assert_equal("topval", scope.lookupvar("first", false), "Could not find var in #{name}") + assert_equal("topval", scope.lookupvar("first"), "Could not find var in #{name}") end # Now set a var in the midscope and make sure the mid and bottom can see it but not the top midscope.setvar("second", "midval") - assert_equal(:undefined, scopes[:top].lookupvar("second", false), "Found child var in top scope") + assert_equal(:undefined, scopes[:top].lookupvar("second"), "Found child var in top scope") [:mid, :bot].each do |name| - assert_equal("midval", scopes[name].lookupvar("second", false), "Could not find var in #{name}") + assert_equal("midval", scopes[name].lookupvar("second"), "Could not find var in #{name}") end # And set something in the bottom, and make sure we only find it there. botscope.setvar("third", "botval") [:top, :mid].each do |name| - assert_equal(:undefined, scopes[name].lookupvar("third", false), "Found child var in top scope") + assert_equal(:undefined, scopes[name].lookupvar("third"), "Found child var in top scope") end - assert_equal("botval", scopes[:bot].lookupvar("third", false), "Could not find var in bottom scope") + assert_equal("botval", scopes[:bot].lookupvar("third"), "Could not find var in bottom scope") # Test that the scopes convert to hash structures correctly. @@ -260,18 +260,7 @@ Host <<||>>" scope = mkscope scope.setvar("testing", :undef) - - - assert_equal( - :undef, scope.lookupvar("testing", false), - - "undef was not returned as :undef when not string") - - - assert_equal( - "", scope.lookupvar("testing", true), - - "undef was not returned as '' when string") + assert_equal(:undef, scope.lookupvar("testing"), "undef was not returned as :undef") end end @@ -68,8 +68,8 @@ # # = Copyright # -# Copyright (c) 2005 Puppet Labs, LLC -# Licensed under the GNU Public License +# Copyright (c) 2005-2011 Puppet Labs, LLC +# Licensed under the Apache 2.0 License require 'find' require 'getoptlong' |
