diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000..15cbbfd --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,7 @@ +fixtures: + forge_modules: + stdlib: + repo: 'puppetlabs/stdlib' + ref: '4.5.1' + symlinks: + loggly: "#{source_dir}" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..641e153 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.*.sw? +pkg +spec/fixtures +.rspec_system +.vagrant +.bundle +vendor diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..8c18f1a --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--format documentation +--color diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1e773c2 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,37 @@ +--- +language: ruby +bundler_args: --without development system_tests +before_install: rm Gemfile.lock || true +rvm: + - 1.9.3 + - 2.0.0 + - 2.1.0 +script: bundle exec rake test +env: + - PUPPET_VERSION="~> 3.2.0" + - PUPPET_VERSION="~> 3.3.0" + - PUPPET_VERSION="~> 3.4.0" + - PUPPET_VERSION="~> 3.5.0" STRICT_VARIABLES=yes + - PUPPET_VERSION="~> 3.6.0" STRICT_VARIABLES=yes + - PUPPET_VERSION="~> 3.7.0" STRICT_VARIABLES=yes + - PUPPET_VERSION="~> 3.7.0" STRICT_VARIABLES=yes FUTURE_PARSER=yes + - PUPPET_VERSION="~> 4.0.0" STRICT_VARIABLES=yes +matrix: + exclude: + # Ruby 1.9.3 + - rvm: 1.9.3 + env: PUPPET_VERSION="~> 2.7.0" + + # Ruby 2.0.0 + - rvm: 2.0.0 + env: PUPPET_VERSION="~> 2.7.0" + + # Ruby 2.1.0 + - rvm: 2.1.0 + env: PUPPET_VERSION="~> 2.7.0" + - rvm: 2.1.0 + env: PUPPET_VERSION="~> 3.2.0" + - rvm: 2.1.0 + env: PUPPET_VERSION="~> 3.3.0" + - rvm: 2.1.0 + env: PUPPET_VERSION="~> 3.4.0" diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..5ba4cf7 --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,3 @@ +YYYY-MM-DD Release 0.1.0 +- something you did +- something else you did diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..36d07a8 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,92 @@ +This module has grown over time based on a range of contributions from +people using it. If you follow these contributing guidelines your patch +will likely make it into a release a little quicker. + + +## Contributing + +1. Fork the repo. + +2. Run the tests. We only take pull requests with passing tests, and + it's great to know that you have a clean slate. + +3. Add a test for your change. Only refactoring and documentation + changes require no new tests. If you are adding functionality + or fixing a bug, please add a test. + +4. Make the test pass. + +5. Push to your fork and submit a pull request. + + +## Dependencies + +The testing and development tools have a bunch of dependencies, +all managed by [Bundler](http://bundler.io/) according to the +[Puppet support matrix](http://docs.puppetlabs.com/guides/platforms.html#ruby-versions). + +By default the tests use a baseline version of Puppet. + +If you have Ruby 2.x or want a specific version of Puppet, +you must set an environment variable such as: + + export PUPPET_VERSION="~> 3.2.0" + +Install the dependencies like so... + + bundle install + +## Syntax and style + +The test suite will run [Puppet Lint](http://puppet-lint.com/) and +[Puppet Syntax](https://github.com/gds-operations/puppet-syntax) to +check various syntax and style things. You can run these locally with: + + bundle exec rake lint + bundle exec rake syntax + +## Running the unit tests + +The unit test suite covers most of the code, as mentioned above please +add tests if you're adding new functionality. If you've not used +[rspec-puppet](http://rspec-puppet.com/) before then feel free to ask +about how best to test your new feature. Running the test suite is done +with: + + bundle exec rake spec + +Note also you can run the syntax, style and unit tests in one go with: + + bundle exec rake test + +### Automatically run the tests + +During development of your puppet module you might want to run your unit +tests a couple of times. You can use the following command to automate +running the unit tests on every change made in the manifests folder. + + bundle exec guard + +## Integration tests + +The unit tests just check the code runs, not that it does exactly what +we want on a real machine. For that we're using +[Beaker](https://github.com/puppetlabs/beaker). + +Beaker fires up a new virtual machine (using Vagrant) and runs a series of +simple tests against it after applying the module. You can run our +Beaker tests with: + + bundle exec rake acceptance + +This will use the host described in `spec/acceptance/nodeset/default.yml` +by default. To run against another host, set the `BEAKER_set` environment +variable to the name of a host described by a `.yml` file in the +`nodeset` directory. For example, to run against CentOS 6.4: + + BEAKER_set=centos-64-x64 bundle exec rake acceptance + +If you don't want to have to recreate the virtual machine every time you +can use `BEAKER_destroy=no` and `BEAKER_provision=no`. On the first run you will +at least need `BEAKER_provision` set to yes (the default). The Vagrantfile +for the created virtual machines will be in `.vagrant/beaker_vagrant_files`. diff --git a/CONTRIBUTORS b/CONTRIBUTORS new file mode 100644 index 0000000..c55f0f5 --- /dev/null +++ b/CONTRIBUTORS @@ -0,0 +1,11 @@ +Adam Crews +Jason Skowronski +Joey Moe +Jon Fautley +Jonathan Niesen +Michael Blume +Q +Ryan Coleman +jasons-loggly +maxgutman +psquickitjayant diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..8e87698 --- /dev/null +++ b/Gemfile @@ -0,0 +1,24 @@ +source "https://rubygems.org" + +group :test do + gem "rake" + gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.7.0' + gem "rspec", '< 3.2.0' + gem "rspec-puppet", :git => 'https://github.com/rodjek/rspec-puppet.git' + gem "puppetlabs_spec_helper" + gem "metadata-json-lint" + gem "rspec-puppet-facts" +end + +group :development do + gem "travis" + gem "travis-lint" + gem "vagrant-wrapper" + gem "puppet-blacksmith" + gem "guard-rake" +end + +group :system_tests do + gem "beaker" + gem "beaker-rspec" +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..3ceca1d --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,366 @@ +GIT + remote: https://github.com/rodjek/rspec-puppet.git + revision: a9a837669cf6955279f02d1d9b524dc140b9d3e8 + specs: + rspec-puppet (2.0.1) + rspec + +GEM + remote: https://rubygems.org/ + specs: + CFPropertyList (2.3.1) + activesupport (4.2.1) + i18n (~> 0.7) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + addressable (2.3.8) + autoparse (0.3.3) + addressable (>= 2.3.1) + extlib (>= 0.9.15) + multi_json (>= 1.0.0) + aws-sdk (1.64.0) + aws-sdk-v1 (= 1.64.0) + aws-sdk-v1 (1.64.0) + json (~> 1.4) + nokogiri (>= 1.4.4) + backports (3.6.4) + beaker (2.9.0) + aws-sdk (~> 1.57) + docker-api + fission (~> 0.4) + fog (~> 1.25) + google-api-client (~> 0.8) + hocon (~> 0.0.4) + inifile (~> 2.0) + json (~> 1.8) + minitest (~> 5.4) + net-scp (~> 1.2) + net-ssh (~> 2.9) + rbvmomi (~> 1.8) + rsync (~> 1.0.9) + unf (~> 0.1) + beaker-rspec (5.0.2) + beaker (~> 2.0) + rspec + serverspec (~> 2) + specinfra (~> 2) + builder (3.2.2) + celluloid (0.16.0) + timers (~> 4.0.0) + coderay (1.1.0) + diff-lcs (1.2.5) + docker-api (1.21.0) + excon (>= 0.38.0) + json + domain_name (0.5.24) + unf (>= 0.0.5, < 1.0.0) + ethon (0.7.3) + ffi (>= 1.3.0) + excon (0.45.2) + extlib (0.9.16) + facter (1.7.6) + faraday (0.9.1) + multipart-post (>= 1.2, < 3) + faraday_middleware (0.9.1) + faraday (>= 0.7.4, < 0.10) + ffi (1.9.8) + fission (0.5.0) + CFPropertyList (~> 2.2) + fog (1.29.0) + fog-atmos + fog-aws (~> 0.0) + fog-brightbox (~> 0.4) + fog-core (~> 1.27, >= 1.27.4) + fog-ecloud + fog-json + fog-local + fog-powerdns (>= 0.1.1) + fog-profitbricks + fog-radosgw (>= 0.0.2) + fog-riakcs + fog-sakuracloud (>= 0.0.4) + fog-serverlove + fog-softlayer + fog-storm_on_demand + fog-terremark + fog-vmfusion + fog-voxel + fog-xml (~> 0.1.1) + ipaddress (~> 0.5) + nokogiri (~> 1.5, >= 1.5.11) + fog-atmos (0.1.0) + fog-core + fog-xml + fog-aws (0.1.2) + fog-core (~> 1.27) + fog-json (~> 1.0) + fog-xml (~> 0.1) + ipaddress (~> 0.8) + fog-brightbox (0.7.1) + fog-core (~> 1.22) + fog-json + inflecto (~> 0.0.2) + fog-core (1.30.0) + builder + excon (~> 0.45) + formatador (~> 0.2) + mime-types + net-scp (~> 1.1) + net-ssh (>= 2.1.3) + fog-ecloud (0.1.1) + fog-core + fog-xml + fog-json (1.0.1) + fog-core (~> 1.0) + multi_json (~> 1.0) + fog-local (0.2.1) + fog-core (~> 1.27) + fog-powerdns (0.1.1) + fog-core (~> 1.27) + fog-json (~> 1.0) + fog-xml (~> 0.1) + fog-profitbricks (0.0.2) + fog-core + fog-xml + nokogiri + fog-radosgw (0.0.4) + fog-core (>= 1.21.0) + fog-json + fog-xml (>= 0.0.1) + fog-riakcs (0.1.0) + fog-core + fog-json + fog-xml + fog-sakuracloud (1.0.1) + fog-core + fog-json + fog-serverlove (0.1.2) + fog-core + fog-json + fog-softlayer (0.4.5) + fog-core + fog-json + fog-storm_on_demand (0.1.1) + fog-core + fog-json + fog-terremark (0.1.0) + fog-core + fog-xml + fog-vmfusion (0.1.0) + fission + fog-core + fog-voxel (0.1.0) + fog-core + fog-xml + fog-xml (0.1.2) + fog-core + nokogiri (~> 1.5, >= 1.5.11) + formatador (0.2.5) + gh (0.14.0) + addressable + backports + faraday (~> 0.8) + multi_json (~> 1.0) + net-http-persistent (>= 2.7) + net-http-pipeline + google-api-client (0.8.6) + activesupport (>= 3.2) + addressable (~> 2.3) + autoparse (~> 0.3) + extlib (~> 0.9) + faraday (~> 0.9) + googleauth (~> 0.3) + launchy (~> 2.4) + multi_json (~> 1.10) + retriable (~> 1.4) + signet (~> 0.6) + googleauth (0.4.0) + faraday (~> 0.9) + jwt (~> 1.4) + logging (~> 1.8) + memoist (~> 0.11) + multi_json (= 1.11) + signet (~> 0.6) + guard (2.12.5) + formatador (>= 0.2.4) + listen (~> 2.7) + lumberjack (~> 1.0) + nenv (~> 0.1) + notiffany (~> 0.0) + pry (>= 0.9.12) + shellany (~> 0.0) + thor (>= 0.18.1) + guard-rake (1.0.0) + guard + rake + hiera (1.3.4) + json_pure + highline (1.7.1) + hitimes (1.2.2) + hocon (0.0.7) + http-cookie (1.0.2) + domain_name (~> 0.5) + i18n (0.7.0) + inflecto (0.0.2) + inifile (2.0.2) + ipaddress (0.8.0) + json (1.8.2) + json_pure (1.8.2) + jwt (1.4.1) + launchy (2.4.3) + addressable (~> 2.3) + listen (2.10.0) + celluloid (~> 0.16.0) + rb-fsevent (>= 0.9.3) + rb-inotify (>= 0.9) + little-plugger (1.1.3) + logging (1.8.2) + little-plugger (>= 1.1.3) + multi_json (>= 1.8.4) + lumberjack (1.0.9) + memoist (0.12.0) + metaclass (0.0.4) + metadata-json-lint (0.0.6) + json + spdx-licenses (~> 1.0) + method_source (0.8.2) + mime-types (2.4.3) + mini_portile (0.6.2) + minitest (5.6.0) + mocha (1.1.0) + metaclass (~> 0.0.1) + multi_json (1.11.0) + multipart-post (2.0.0) + nenv (0.2.0) + net-http-persistent (2.9.4) + net-http-pipeline (1.0.1) + net-scp (1.2.1) + net-ssh (>= 2.6.5) + net-ssh (2.9.2) + netrc (0.10.3) + nokogiri (1.6.6.2) + mini_portile (~> 0.6.0) + notiffany (0.0.6) + nenv (~> 0.1) + shellany (~> 0.0) + pry (0.9.12.6) + coderay (~> 1.0) + method_source (~> 0.8) + slop (~> 3.4) + puppet (3.7.5) + facter (> 1.6, < 3) + hiera (~> 1.0) + json_pure + puppet-blacksmith (3.3.1) + puppet (>= 2.7.16) + rest-client + puppet-lint (1.1.0) + puppet-syntax (2.0.0) + rake + puppetlabs_spec_helper (0.10.2) + mocha + puppet-lint + puppet-syntax + rake + rspec-puppet + pusher-client (0.6.0) + json + websocket (~> 1.0) + rake (10.4.2) + rb-fsevent (0.9.4) + rb-inotify (0.9.5) + ffi (>= 0.5.0) + rbvmomi (1.8.2) + builder + nokogiri (>= 1.4.1) + trollop + rest-client (1.8.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 3.0) + netrc (~> 0.7) + retriable (1.4.1) + rspec (3.1.0) + rspec-core (~> 3.1.0) + rspec-expectations (~> 3.1.0) + rspec-mocks (~> 3.1.0) + rspec-core (3.1.7) + rspec-support (~> 3.1.0) + rspec-expectations (3.1.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.1.0) + rspec-its (1.2.0) + rspec-core (>= 3.0.0) + rspec-expectations (>= 3.0.0) + rspec-mocks (3.1.3) + rspec-support (~> 3.1.0) + rspec-puppet-facts (0.6.0) + facter + json + rspec-support (3.1.2) + rsync (1.0.9) + serverspec (2.14.1) + multi_json + rspec (~> 3.0) + rspec-its + specinfra (~> 2.25) + shellany (0.0.1) + signet (0.6.0) + addressable (~> 2.3) + extlib (~> 0.9) + faraday (~> 0.9) + jwt (~> 1.0) + multi_json (~> 1.10) + slop (3.6.0) + spdx-licenses (1.0.0) + json + specinfra (2.28.2) + net-scp + net-ssh + thor (0.19.1) + thread_safe (0.3.5) + timers (4.0.1) + hitimes + travis (1.7.6) + addressable (~> 2.3) + backports + faraday (~> 0.9) + faraday_middleware (~> 0.9, >= 0.9.1) + gh (~> 0.13) + highline (~> 1.6) + launchy (~> 2.1) + pry (~> 0.9, < 0.10) + pusher-client (~> 0.4) + typhoeus (~> 0.6, >= 0.6.8) + travis-lint (2.0.0) + json + trollop (2.1.2) + typhoeus (0.7.1) + ethon (>= 0.7.1) + tzinfo (1.2.2) + thread_safe (~> 0.1) + unf (0.1.4) + unf_ext + unf_ext (0.0.6) + vagrant-wrapper (2.0.2) + websocket (1.2.1) + +PLATFORMS + ruby + +DEPENDENCIES + beaker + beaker-rspec + guard-rake + metadata-json-lint + puppet (~> 3.7.0) + puppet-blacksmith + puppetlabs_spec_helper + rake + rspec (< 3.2.0) + rspec-puppet! + rspec-puppet-facts + travis + travis-lint + vagrant-wrapper diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..fd50602 --- /dev/null +++ b/Guardfile @@ -0,0 +1,5 @@ +notification :off + +guard 'rake', :task => 'test' do + watch(%r{^manifests\/(.+)\.pp$}) +end diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9f71055 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +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 + + 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/Modulefile b/Modulefile deleted file mode 100644 index c02a96f..0000000 --- a/Modulefile +++ /dev/null @@ -1,10 +0,0 @@ -name 'loggly-loggly' -version '1.0.1' -author 'loggly' -license 'Apache License, Version 2.0' -summary 'Configures various data sources for automatic submission to Loggly' -description 'This puppet module allows various data sources to be configured for automatic submission to Loggly, such as rsyslog, sylog-ng, Apache, PHP, Ruby, etc.' -project_page 'https://github.com/loggly/loggly-puppet' - -## Add dependencies, if any: -# dependency 'username/name', '>= 1.2.0' diff --git a/README.md b/README.markdown similarity index 100% rename from README.md rename to README.markdown diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..1778d2a --- /dev/null +++ b/Rakefile @@ -0,0 +1,56 @@ +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet/version' +require 'puppet/vendor/semantic/lib/semantic' unless Puppet.version.to_f < 3.6 +require 'puppet-lint/tasks/puppet-lint' +require 'puppet-syntax/tasks/puppet-syntax' + +# These gems aren't always present, for instance +# on Travis with --without development +begin + require 'puppet_blacksmith/rake_tasks' +rescue LoadError +end + +Rake::Task[:lint].clear + +PuppetLint.configuration.relative = true +PuppetLint.configuration.send("disable_80chars") +PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}" +PuppetLint.configuration.fail_on_warnings = true + +# Forsake support for Puppet 2.6.2 for the benefit of cleaner code. +# http://puppet-lint.com/checks/class_parameter_defaults/ +PuppetLint.configuration.send('disable_class_parameter_defaults') +# http://puppet-lint.com/checks/class_inherits_from_params_class/ +PuppetLint.configuration.send('disable_class_inherits_from_params_class') + +exclude_paths = [ + "bundle/**/*", + "pkg/**/*", + "vendor/**/*", + "spec/**/*", +] +PuppetLint.configuration.ignore_paths = exclude_paths +PuppetSyntax.exclude_paths = exclude_paths + +desc "Run acceptance tests" +RSpec::Core::RakeTask.new(:acceptance) do |t| + t.pattern = 'spec/acceptance' +end + +desc "Populate CONTRIBUTORS file" +task :contributors do + system("git log --format='%aN' | sort -u > CONTRIBUTORS") +end + +task :metadata do + sh "metadata-json-lint metadata.json" +end + +desc "Run syntax, lint, and spec tests." +task :test => [ + :syntax, + :lint, + :spec, + :metadata, +] diff --git a/files/.gitkeep b/files/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/templates/loggly_full.crt.erb b/files/loggly_full.crt similarity index 100% rename from templates/loggly_full.crt.erb rename to files/loggly_full.crt diff --git a/lib/puppet/provider/.gitkeep b/lib/puppet/provider/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/lib/puppet/type/.gitkeep b/lib/puppet/type/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/manifests/init.pp b/manifests/init.pp index 0daeb4c..eec7377 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -13,11 +13,13 @@ # # [*base_dir*] # Base directory to store Loggly support files in. +# # [*enable_tls*] # Enables or disables TLS encryption for shipped log events. +# # [*cert_path*] -# Directory to store the Loggly TLS certs in. Normally this would be relative -# to $base_dir. +# Directory to store the Loggly TLS certs in. Normally this would be +# relative to $base_dir. # # === Authors # @@ -25,37 +27,43 @@ # class loggly ( - $base_dir = $loggly::params::base_dir, - $enable_tls = $loggly::params::enable_tls, - $cert_path = $loggly::params::cert_path + $base_dir = $loggly::params::base_dir, + $enable_tls = $loggly::params::enable_tls, + $cert_path = undef, ) inherits loggly::params { - # create directory for loggly support files - file { $base_dir: - ensure => 'directory', - owner => 'root', - group => 'root', - mode => '0755', - } + $_cert_path = pick($cert_path, "${base_dir}/certs") + + validate_absolute_path($base_dir) + validate_absolute_path($_cert_path) + validate_bool($enable_tls) + + # create directory for loggly support files + file { $base_dir: + ensure => 'directory', + owner => 'root', + group => 'root', + mode => '0755', + } - # create directory for TLS certificates - file { $cert_path: - ensure => 'directory', - owner => 'root', - group => 'root', - mode => '0755', - require => File[$base_dir], - } + # create directory for TLS certificates + file { $_cert_path: + ensure => 'directory', + owner => 'root', + group => 'root', + mode => '0755', + require => File[$base_dir], + } - # store the Loggly TLS cert inside $cert_path - file { "${cert_path}/loggly_full.crt": - ensure => 'file', - owner => 'root', - group => 'root', - mode => '0644', - content => template('loggly/loggly_full.crt.erb'), - require => File[$cert_path], - } + # store the Loggly TLS cert inside $cert_path + file { "${_cert_path}/loggly_full.crt": + ensure => 'file', + owner => 'root', + group => 'root', + mode => '0644', + source => "puppet:///modules/${module_name}/loggly_full.crt", + require => File[$_cert_path], + } } -# vi:syntax=puppet:filetype=puppet:ts=4:et: +# vim: syntax=puppet ft=puppet ts=2 sw=2 nowrap et diff --git a/manifests/params.pp b/manifests/params.pp index 08103fa..86a7329 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -10,14 +10,19 @@ # class loggly::params { - # base directory for loggly support files - $base_dir = '/usr/local/loggly' + case $operatingsystem { + 'RedHat', 'Ubuntu', 'Fedora', 'CentOS', 'Debian': { + # base directory for loggly support files + $base_dir = '/usr/local/loggly' - # directory that shared TLS certificates will be stored in - $cert_path = "${base_dir}/certs" + # TLS support is enabled by default to prevent sniffing of logs + $enable_tls = true + } - # TLS support is enabled by default to prevent sniffing of logs - $enable_tls = true + default: { + fail("$operatingsystem not supported") + } + } } -# vi:syntax=puppet:filetype=puppet:ts=4:et: +# vim: syntax=puppet ft=puppet ts=2 sw=2 nowrap et diff --git a/manifests/rsyslog.pp b/manifests/rsyslog.pp index 89fe9ea..e98841c 100644 --- a/manifests/rsyslog.pp +++ b/manifests/rsyslog.pp @@ -33,19 +33,20 @@ # === Authors # # Colin Moller -# Adam Crews # class loggly::rsyslog ( $customer_token, + $cert_path = $loggly::_cert_path, + $enable_tls = $loggly::enable_tls, ) inherits loggly { - # Bring the TLS and certificate directory configuration into the current - # Puppet scope so that templates have access to it - $enable_tls = $loggly::enable_tls - $cert_path = $loggly::cert_path + validate_string($customer_token) + validate_absolute_path($cert_path) + validate_bool($enable_tls) # Emit a configuration snippet that submits events to Loggly by default file { '/etc/rsyslog.d/22-loggly.conf': + ensure => 'file', owner => 'root', group => 'root', mode => '0644', @@ -78,4 +79,4 @@ } } -# vi:syntax=puppet:filetype=puppet:ts=2:sw=2:et: +# vim: syntax=puppet ft=puppet ts=2 sw=2 nowrap et diff --git a/manifests/rsyslog/logfile.pp b/manifests/rsyslog/logfile.pp index d6c9cab..949505c 100644 --- a/manifests/rsyslog/logfile.pp +++ b/manifests/rsyslog/logfile.pp @@ -46,15 +46,13 @@ validate_absolute_path($filepath) validate_re($severity, $valid_levels, "severity value of ${severity} is not valid") - if ! $logname { - $_t = split($filepath, '/') - $logname = $_t[-1] - } + $_t = split($filepath, '/') + $_logname = pick($logname,$_t[-1]) - validate_string($logname) + validate_string($_logname) # This template uses $logname and $filepath - file { "/etc/rsyslog.d/${logname}.conf": + file { "/etc/rsyslog.d/${_logname}.conf": content => template("${module_name}/log.conf.erb"), notify => Exec['restart_rsyslogd'], } diff --git a/manifests/syslog_ng.pp b/manifests/syslog_ng.pp index b67123a..8c7db47 100644 --- a/manifests/syslog_ng.pp +++ b/manifests/syslog_ng.pp @@ -20,7 +20,7 @@ # This module uses configuration from the base Loggly class to set # the certificate path and TLS status. # -# [*cert_dir*] +# [*cert_path*] # The directory to find the Loggly TLS certs in, as set by the base loggly # class. # @@ -41,77 +41,76 @@ # Colin Moller # class loggly::syslog_ng ( - $customer_token + $customer_token, + $enable_tls = $loggly::enable_tls, + $cert_path = $loggly::_cert_path, ) inherits loggly { - # Bring the Loggly certificate directory configuration into the current - # Puppet scope so templates have access to it - $cert_dir = $loggly::cert_dir + validate_string($customer_token) + validate_bool($enable_tls) + validate_absolute_path($cert_path) - # Ensure our configuration snippet directory exists before putting - # configuration snippets there - if !defined(File['/etc/syslog-ng/conf.d']){ - file { '/etc/syslog-ng/conf.d': - ensure => 'directory', - owner => 'root', - group => 'root', - mode => '0755', - } - } - # Ensure we are using the correct source name on each distro - $syslog_source = $::osfamily ? { - 'RedHat' => 's_sys', - 'Debian' => 's_src', + # Ensure our configuration snippet directory exists before putting + # configuration snippets there + if !defined(File['/etc/syslog-ng/conf.d']){ + file { '/etc/syslog-ng/conf.d': + ensure => 'directory', + owner => 'root', + group => 'root', + mode => '0755', } + } + # Ensure we are using the correct source name on each distro + $syslog_source = $::osfamily ? { + 'RedHat' => 's_sys', + 'Debian' => 's_src', + } - case $::operatingsystem { - centos, redhat: { - # On CentOS/Red Hat, the default syslog-ng configuration does not - # include a configuration snippet directory, so we ensure it - # is present - loggly::utils::line { 'snippet_dir': - ensure => 'present', - line => '@include "/etc/syslog-ng/conf.d/"', - file => '/etc/syslog-ng/syslog-ng.conf', - } - - # Add a dependency on the snippet directory configuration so that - # it will be present before generating the configuration snippet - File['/etc/syslog-ng/conf.d/22-loggly.conf'] -> - Loggly::Utils::Line['snippet_dir'] - - # Packages available from the EPEL repo for syslog-ng on - # CentOS/Red Hat are not compiled with TLS support by default - $enable_tls = false - } + case $::operatingsystem { + centos, redhat: { + # On CentOS/Red Hat, the default syslog-ng configuration does not + # include a configuration snippet directory, so we ensure it is + # present + file_line { 'snippet_dir': + ensure => present, + path => '/etc/syslog-ng/syslog-ng.conf', + line => '@include "/etc/syslog-ng/conf.d/"', + before => File['/etc/syslog-ng/conf.d/22-loggly.conf'], + } - # Respect the default set in the loggly class on other distros - default: { - $enable_tls = $loggly::enable_tls - } + # Packages available from the EPEL repo for syslog-ng on + # CentOS/Red Hat are not compiled with TLS support by default + $_enable_tls = false } - # Emit a configuration snippet that submits events to Loggly by default - file { '/etc/syslog-ng/conf.d/22-loggly.conf': - owner => 'root', - group => 'root', - mode => '0644', - content => template('loggly/syslog-ng/22-loggly.conf.erb'), - require => File['/etc/syslog-ng/conf.d'], - notify => Exec['restart_syslog_ng'], + # Respect the default set in the loggly class on other distros + default: { + $_enable_tls = $enable_tls } + } - # Call an exec to restart the syslog service instead of using a puppet - # managed service to avoid external dependencies or conflicts with modules - # that may already manage the syslog daemon. - # - # Note that this will only be called on configuration changes due to the - # 'refreshonly' parameter. - exec { 'restart_syslog_ng': - command => 'service syslog-ng restart', - path => [ '/usr/sbin', '/sbin', '/usr/bin/', '/bin', ], - refreshonly => true, - } + # Emit a configuration snippet that submits events to Loggly by default + # This template uses $enable_tls, $customer_token, and $cert_path + file { '/etc/syslog-ng/conf.d/22-loggly.conf': + owner => 'root', + group => 'root', + mode => '0644', + content => template("${module_name}/syslog-ng/22-loggly.conf.erb"), + require => File['/etc/syslog-ng/conf.d'], + notify => Exec['restart_syslog_ng'], + } + + # Call an exec to restart the syslog service instead of using a puppet + # managed service to avoid external dependencies or conflicts with + # modules that may already manage the syslog daemon. + # + # Note that this will only be called on configuration changes due to the + # 'refreshonly' parameter. + exec { 'restart_syslog_ng': + command => 'service syslog-ng restart', + path => [ '/usr/sbin', '/sbin', '/usr/bin/', '/bin', ], + refreshonly => true, + } } -# vi:syntax=puppet:filetype=puppet:ts=4:et: +# vim: syntax=puppet ft=puppet ts=2 sw=2 nowrap et diff --git a/manifests/utils/line.pp b/manifests/utils/line.pp deleted file mode 100644 index 56c2dc7..0000000 --- a/manifests/utils/line.pp +++ /dev/null @@ -1,49 +0,0 @@ -# == Define: loggly::utils::line -# -# Ensures a specific line exists in a file, adds it if not already present. -# -# === Parameters -# -# Document parameters here -# -# [*file*] -# namevar of a core resource type. -# -# [*line*] -# slash." -# -# [*ensure*] -# Foo -# -# === Examples -# -# Examples on how to use this type: -# -# loggly::utils::line { 'line_in_motd': -# file => '/etc/motd', -# line => 'hello, world!', -# ensure => 'present', -# } -# -# === Authors -# -# Colin Moller -# - -define loggly::utils::line($file, $line, $ensure = 'present') { - case $ensure { - default : { err ( "unknown ensure value ${ensure}" ) } - present: { - exec { "/bin/echo '${line}' >> '${file}'": - unless => "/bin/grep -qFx '${line}' '${file}'" - } - } - absent: { - exec { "/usr/bin/perl -ni -e 'print unless /^\\Q${line}\\E\$/' '${file}'": - onlyif => "/bin/grep -qFx '${line}' '${file}'" - } - } - } -} - -# vi:syntax=puppet:filetype=puppet:ts=4:et: diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..eacc1a6 --- /dev/null +++ b/metadata.json @@ -0,0 +1,63 @@ +{ + "name": "loggly-loggly", + "version": "2.0.0", + "author": "loggly", + "summary": "Configures various data sources for automatic submission to Loggly", + "description": "Configures various data sources for automatic submission to Loggly", + "license": "Apache-2.0", + "source": "https://github.com/loggly/Loggly-Puppet.git", + "project_page": "https://github.com/loggly/Loggly-Puppet", + "issues_url": "https://github.com/loggly/Loggly-Puppet/issues", + "dependencies": [ + { + "name": "puppetlabs-stdlib", + "version_requirement": ">= 4.2.0 < 5.0.0" + } + ], + "requirements": [ + { + "name": "pe", + "version_requirement": "3.x" + }, + { + "name": "puppet", + "version_requirement": ">=3.0.0 <4.1.0" + } + ], + "operatingsystem_support": [ + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "12.04", + "14.04" + ] + }, + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "6", + "7" + ] + }, + { + "operatingsystem": "CentOS", + "operatingsystemrelease": [ + "6", + "7" + ] + }, + { + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "6", + "7" + ] + }, + { + "operatingsystem": "Fedora", + "operatingsystemrelease": [ + "19" + ] + } + ] +} diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb new file mode 100644 index 0000000..00e841f --- /dev/null +++ b/spec/acceptance/class_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper_acceptance' + +describe 'loggly class' do + + context 'default parameters' do + # Using puppet_apply as a helper + it 'should work idempotently with no errors' do + pp = <<-EOS + class { 'loggly': } + EOS + + # Run it twice and test for idempotency + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + + describe package('loggly') do + it { is_expected.to be_installed } + end + + describe service('loggly') do + it { is_expected.to be_enabled } + it { is_expected.to be_running } + end + end +end diff --git a/spec/acceptance/nodesets/centos-511-x64.yml b/spec/acceptance/nodesets/centos-511-x64.yml new file mode 100644 index 0000000..155926d --- /dev/null +++ b/spec/acceptance/nodesets/centos-511-x64.yml @@ -0,0 +1,12 @@ +HOSTS: + centos-511-x64: + roles: + - master + platform: el-5-x86_64 + box: puppetlabs/centos-5.11-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/boxes/centos-5.11-64-nocm + hypervisor: vagrant + +CONFIG: + log_level: verbose + type: foss diff --git a/spec/acceptance/nodesets/centos-64-x64.yml b/spec/acceptance/nodesets/centos-64-x64.yml new file mode 100644 index 0000000..d19aa69 --- /dev/null +++ b/spec/acceptance/nodesets/centos-64-x64.yml @@ -0,0 +1,11 @@ +HOSTS: + centos-64-x64: + roles: + - master + platform: el-6-x86_64 + box : centos-64-x64-vbox4210-nocm + box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box + hypervisor : vagrant +CONFIG: + log_level: verbose + type: foss diff --git a/spec/acceptance/nodesets/centos-66-x64.yml b/spec/acceptance/nodesets/centos-66-x64.yml new file mode 100644 index 0000000..07843d5 --- /dev/null +++ b/spec/acceptance/nodesets/centos-66-x64.yml @@ -0,0 +1,11 @@ +HOSTS: + centos-66-x64: + roles: + - master + platform: el-6-x86_64 + box: puppetlabs/centos-6.6-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/boxes/centos-6.6-64-nocm + hypervisor: vagrant +CONFIG: + log_level: verbose + type: foss diff --git a/spec/acceptance/nodesets/centos-7-x64.yml b/spec/acceptance/nodesets/centos-7-x64.yml new file mode 100644 index 0000000..8e73537 --- /dev/null +++ b/spec/acceptance/nodesets/centos-7-x64.yml @@ -0,0 +1,12 @@ +HOSTS: + centos-7-x64: + roles: + - master + platform: el-7-x86_64 + box: chef/centos-7.0 + box_url: https://vagrantcloud.com/chef/boxes/centos-7.0 + hypervisor: vagrant + +CONFIG: + log_level: verbose + type: foss diff --git a/spec/acceptance/nodesets/debian-609-x64.yml b/spec/acceptance/nodesets/debian-609-x64.yml new file mode 100644 index 0000000..e2451ea --- /dev/null +++ b/spec/acceptance/nodesets/debian-609-x64.yml @@ -0,0 +1,12 @@ +HOSTS: + debian-609-x64: + roles: + - master + platform: debian-6-amd64 + box: puppetlabs/debian-6.0.9-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/boxes/debian-6.0.9-64-nocm + hypervisor: vagrant + +CONFIG: + log_level: verbose + type: foss diff --git a/spec/acceptance/nodesets/debian-76-x64.yml b/spec/acceptance/nodesets/debian-76-x64.yml new file mode 100644 index 0000000..683e635 --- /dev/null +++ b/spec/acceptance/nodesets/debian-76-x64.yml @@ -0,0 +1,12 @@ +HOSTS: + debian-76-x64: + roles: + - master + platform: debian-7-amd64 + box: puppetlabs/debian-7.6-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/boxes/debian-7.6-64-nocm + hypervisor: vagrant + +CONFIG: + log_level: verbose + type: foss diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml new file mode 100644 index 0000000..3f2dcaa --- /dev/null +++ b/spec/acceptance/nodesets/default.yml @@ -0,0 +1,12 @@ +HOSTS: + ubuntu-server-1204-x64: + roles: + - master + platform: ubuntu-1204-amd64 + box: puppetlabs/ubuntu-12.04-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/boxes/ubuntu-12.04-64-nocm + hypervisor: vagrant + +CONFIG: + log_level: verbose + type: foss diff --git a/spec/acceptance/nodesets/fedora-20-x64.yml b/spec/acceptance/nodesets/fedora-20-x64.yml new file mode 100644 index 0000000..138341f --- /dev/null +++ b/spec/acceptance/nodesets/fedora-20-x64.yml @@ -0,0 +1,12 @@ +HOSTS: + fedora-20-x64: + roles: + - master + platform: el-7-x86_64 + box: chef/fedora-20 + box_url: https://vagrantcloud.com/chef/boxes/fedora-20 + hypervisor: vagrant + +CONFIG: + log_level: verbose + type: foss diff --git a/spec/acceptance/nodesets/ubuntu-server-1204-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1204-x64.yml new file mode 100644 index 0000000..3f2dcaa --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-1204-x64.yml @@ -0,0 +1,12 @@ +HOSTS: + ubuntu-server-1204-x64: + roles: + - master + platform: ubuntu-1204-amd64 + box: puppetlabs/ubuntu-12.04-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/boxes/ubuntu-12.04-64-nocm + hypervisor: vagrant + +CONFIG: + log_level: verbose + type: foss diff --git a/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml b/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml new file mode 100644 index 0000000..b392dab --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml @@ -0,0 +1,12 @@ +HOSTS: + ubuntu-server-12042-x64: + roles: + - master + platform: ubuntu-server-12.04-amd64 + box: ubuntu-server-12042-x64-vbox4210-nocm + box_url: http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box + hypervisor: vagrant + +CONFIG: + log_level: verbose + type: foss diff --git a/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml new file mode 100644 index 0000000..4e33625 --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml @@ -0,0 +1,12 @@ +HOSTS: + ubuntu-server-1404-x64: + roles: + - master + platform: ubuntu-1404-amd64 + box: puppetlabs/ubuntu-14.04-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/boxes/ubuntu-14.04-64-nocm + hypervisor: vagrant + +CONFIG: + log_level: verbose + type: foss diff --git a/spec/classes/coverage_spec.rb b/spec/classes/coverage_spec.rb new file mode 100644 index 0000000..12513b8 --- /dev/null +++ b/spec/classes/coverage_spec.rb @@ -0,0 +1 @@ +at_exit { RSpec::Puppet::Coverage.report! } diff --git a/spec/classes/loggly_spec.rb b/spec/classes/loggly_spec.rb new file mode 100644 index 0000000..76f453c --- /dev/null +++ b/spec/classes/loggly_spec.rb @@ -0,0 +1,101 @@ +require 'spec_helper' + +describe 'loggly' do + + context 'supported operating systems' do + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end + + context "loggly class without any parameters" do + let(:params) {{ }} + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('loggly') } + +# it { is_expected.to contain_class('loggly::params') } +# it { is_expected.to contain_class('loggly::install').that_comes_before('loggly::config') } +# it { is_expected.to contain_class('loggly::config') } +# it { is_expected.to contain_class('loggly::service').that_subscribes_to('loggly::config') } + + it { + is_expected.to contain_file('/usr/local/loggly').with( + 'ensure' => 'directory', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0755' + ) + } + + it { + is_expected.to contain_file('/usr/local/loggly/certs').with( + 'ensure' => 'directory', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0755' + ) + } + + it { + is_expected.to contain_file('/usr/local/loggly/certs/loggly_full.crt').with( + 'ensure' => 'file', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'source' => 'puppet:///modules/loggly/loggly_full.crt' + ) + } + end + + context "loggly class with custom base_dir" do + let(:params) {{ + :base_dir => '/tmp/base_dir' + }} + + it { is_expected.to compile.with_all_deps } + + it { + is_expected.to contain_file('/tmp/base_dir').with( + 'ensure' => 'directory', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0755' + ) + } + + it { + is_expected.to contain_file('/tmp/base_dir/certs').with( + 'ensure' => 'directory', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0755' + ) + } + + it { + is_expected.to contain_file('/tmp/base_dir/certs/loggly_full.crt').with( + 'ensure' => 'file', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'source' => 'puppet:///modules/loggly/loggly_full.crt' + ) + } + end + end + end + end + + context 'unsupported operating system' do + describe 'loggly class without any parameters on Solaris/Nexenta' do + let(:facts) {{ + :osfamily => 'Solaris', + :operatingsystem => 'Nexenta', + }} + + it { expect { is_expected.to contain_package('loggly') }.to raise_error(Puppet::Error, /Nexenta not supported/) } + end + end +end diff --git a/spec/classes/params_spec.rb b/spec/classes/params_spec.rb new file mode 100644 index 0000000..ca4235a --- /dev/null +++ b/spec/classes/params_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +describe 'loggly::params' do #, :type => :class do + context 'supported operating systems' do + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end + + it { is_expected.to contain_class("loggly::params") } + end + end + end + + context 'unsupported operating system' do + describe 'loggly class without any parameters on Solaris/Nexenta' do + let(:facts) {{ + :osfamily => 'Solaris', + :operatingsystem => 'Nexenta', + }} + + it { expect { is_expected.to contain_package('loggly') }.to raise_error(Puppet::Error, /Nexenta not supported/) } + end + end +end diff --git a/spec/classes/rsyslog_spec.rb b/spec/classes/rsyslog_spec.rb new file mode 100644 index 0000000..6aacbde --- /dev/null +++ b/spec/classes/rsyslog_spec.rb @@ -0,0 +1,96 @@ +require 'spec_helper' + +describe 'loggly::rsyslog' do + context 'supported operating systems' do + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end + + context "loggly::rsyslog class without any parameters" do + let(:params) {{ }} + + it { should_not compile } + end + + context "loggly::rsyslog class with invalid customer_token" do + let(:params) {{ + :customer_token => [ 'thing1', 'thing2' ], + }} + it { should_not compile } + end + + context "loggly::rsyslog class with invalid cert_path" do + let(:params) {{ + :customer_token => '0000-0000-0000', + :cert_path => 'relative/path', + }} + it { should_not compile } + end + + context "loggly::rsyslog class with invalid enable_tls" do + let(:params) {{ + :customer_token => '0000-0000-0000', + :enable_tls => 'yes', + }} + it { should_not compile } + end + + context "loggly::rsyslog class with customer_token" do + let(:params) {{ + :customer_token => '0000-0000-0000', + }} + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('loggly::rsyslog') } + + it { + is_expected.to contain_exec('restart_rsyslogd').with( + 'command' => 'service rsyslog restart', + 'refreshonly' => true, + ) + } + end + + context "loggly::rsyslog class with enable_tls" do + context "true" do + let(:params) {{ + :customer_token => '0000-0000-0000', + :enable_tls => true, + }} + + it { + is_expected.to contain_file('/etc/rsyslog.d/22-loggly.conf').with( + 'ensure' => 'file', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'content' => /#RsyslogGnuTLS/, + ) + } + + it { is_expected.to contain_package('rsyslog-gnutls').with_ensure('installed') } + end + + context "false" do + let(:params) {{ + :customer_token => '0000-0000-0000', + :enable_tls => false, + }} + + it { + is_expected.to contain_file('/etc/rsyslog.d/22-loggly.conf').with( + 'ensure' => 'file', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'content' => /logs-01\.loggly\.com:514; LogglyFormat/, + ) + } + end + end + end + end + end +end diff --git a/spec/classes/syslog_ng_spec.rb b/spec/classes/syslog_ng_spec.rb new file mode 100644 index 0000000..3a3faac --- /dev/null +++ b/spec/classes/syslog_ng_spec.rb @@ -0,0 +1,112 @@ +require 'spec_helper' + +describe 'loggly::syslog_ng' do + context 'supported operating systems' do + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end + + context "loggly::syslog_ng class without any parameters" do + let(:params) {{ }} + + it { should_not compile } + end + + context "loggly::syslog_ng class with invalid customer_token" do + let(:params) {{ + :customer_token => [ 'thing1', 'thing2' ], + }} + + it { should_not compile } + end + + context "loggly::syslog_ng class with invalid cert_path" do + let(:params) {{ + :customer_token => '0000-0000-0000', + :cert_path => 'relative/path', + }} + it { should_not compile } + end + + context "loggly::syslog_ng class with invalid enable_tls" do + let(:params) {{ + :customer_token => '0000-0000-0000', + :enable_tls => 'yes', + }} + it { should_not compile } + end + + context "loggly::ssylog_ng class with customer_token" do + let(:params) {{ + :customer_token => '0000-0000-0000', + }} + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('loggly::syslog_ng') } + + + it { + is_expected.to contain_file('/etc/syslog-ng/conf.d').with( + 'ensure' => 'directory', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0755' + ) + } + + case os + when /redhat.*/, /centos.*/ + context "add snippet_dir" do + it { + is_expected.to contain_file_line('snippet_dir').with( + 'ensure' => 'present', + 'path' => '/etc/syslog-ng/syslog-ng.conf', + ) + } + end + + context "default disable tls" do + it { + is_expected.to contain_file('/etc/syslog-ng/conf.d/22-loggly.conf').with( + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'content' => /# Non-encrypted log sink/, + 'require' => 'File[/etc/syslog-ng/conf.d]', + 'notify' => 'Exec[restart_syslog_ng]', + ) + } + end + else + context "should not need snippet_dir" do + it { should_not contain_file_line('snippet_dir') } + end + + context "default enable tls" do + it { + is_expected.to contain_file('/etc/syslog-ng/conf.d/22-loggly.conf').with( + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'content' => /# TLS-enabled log sink/, + 'require' => 'File[/etc/syslog-ng/conf.d]', + 'notify' => 'Exec[restart_syslog_ng]', + ) + } + end + end + + it { + is_expected.to contain_exec('restart_syslog_ng').with( + 'command' => 'service syslog-ng restart', + 'refreshonly' => true, + ) + } + + end + end + end + end +end diff --git a/spec/defines/loggly__rsyslog__logfile_spec.rb b/spec/defines/loggly__rsyslog__logfile_spec.rb new file mode 100644 index 0000000..5c3c034 --- /dev/null +++ b/spec/defines/loggly__rsyslog__logfile_spec.rb @@ -0,0 +1,52 @@ +require 'spec_helper' + +describe 'loggly::rsyslog::logfile', :type => :define do + context 'should require absolute path for $filepath' do + let :title do + 'relative/path.log' + end + + it { should_not compile } + + end + + context 'should reject invalid $severity' do + let :title do + '/tmp/foo_log' + end + + let(:params) {{ + :sevrity => 'invalid' + }} + + it { should_not compile } + end + + context 'should create a config file' do + let :title do + '/tmp/foo_log' + end + + it { is_expected.to contain_loggly__rsyslog__logfile('/tmp/foo_log') } + + describe 'with no parameters' do + it { + is_expected.to contain_file('/etc/rsyslog.d/foo_log.conf').with( + 'content' => /InputFileTag foo_log:/, + ) + } + end + + describe 'with custom tag' do + let(:params) {{ + :logname => 'the_real_foo', + }} + + it { + is_expected.to contain_file('/etc/rsyslog.d/the_real_foo.conf').with( + 'content' => /InputFileTag the_real_foo:/, + ) + } + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..1ffdf17 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,3 @@ +require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-facts' +include RspecPuppetFacts diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb new file mode 100644 index 0000000..563ac68 --- /dev/null +++ b/spec/spec_helper_acceptance.rb @@ -0,0 +1,30 @@ +require 'beaker-rspec/spec_helper' +require 'beaker-rspec/helpers/serverspec' + +unless ENV['BEAKER_provision'] == 'no' + hosts.each do |host| + # Install Puppet + if host.is_pe? + install_pe + else + install_puppet + end + end +end + +RSpec.configure do |c| + # Project root + proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + + # Readable test descriptions + c.formatter = :documentation + + # Configure all nodes in nodeset + c.before :suite do + # Install module and dependencies + puppet_module_install(:source => proj_root, :module_name => 'loggly') + hosts.each do |host| + on host, puppet('module', 'install', 'puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] } + end + end +end diff --git a/templates/log.conf.erb b/templates/log.conf.erb index 5dace6f..4404c36 100644 --- a/templates/log.conf.erb +++ b/templates/log.conf.erb @@ -2,11 +2,11 @@ $ModLoad imfile $InputFilePollInterval 10 -#<%= logname %> -$InputFileName <%= filepath %> -$InputFileTag <%= logname %>: -$InputFileStateFile stat-<%= logname %>-log -$InputFileSeverity <%= severity %> +#<%= @_logname %> +$InputFileName <%= @filepath %> +$InputFileTag <%= @_logname %>: +$InputFileStateFile stat-<%= @_logname %>-log +$InputFileSeverity <%= @severity %> $InputRunFileMonitor diff --git a/templates/syslog-ng/22-loggly.conf.erb b/templates/syslog-ng/22-loggly.conf.erb index 940dc1d..6b2dadf 100644 --- a/templates/syslog-ng/22-loggly.conf.erb +++ b/templates/syslog-ng/22-loggly.conf.erb @@ -8,7 +8,7 @@ template LogglyFormat { }; destination d_loggly { -<% if @enable_tls -%> +<% if @_enable_tls -%> # TLS-enabled log sink tcp("logs-01.loggly.com" port(6514) tls(peer-verify(required-untrusted) ca_dir('<%= @cert_path -%>')) template(LogglyFormat) flush_timeout(1000) frac_digits(3)); <% else -%> diff --git a/tests/init.pp b/tests/init.pp index a4f8806..1e63d44 100644 --- a/tests/init.pp +++ b/tests/init.pp @@ -2,10 +2,11 @@ # should have a corresponding test manifest that declares that class or defined # type. # -# Tests are then run by using puppet apply --noop (to check for compilation errors -# and view a log of events) or by fully applying the test in a virtual environment -# (to compare the resulting system state to the desired state). +# Tests are then run by using puppet apply --noop (to check for compilation +# errors and view a log of events) or by fully applying the test in a virtual +# environment (to compare the resulting system state to the desired state). # -# Learn more about module testing here: http://docs.puppetlabs.com/guides/tests_smoke.html +# Learn more about module testing here: +# http://docs.puppetlabs.com/guides/tests_smoke.html # -include loggly +include ::loggly