From 17c4be00a42b48b1d75de53d0fffcfdf005f0461 Mon Sep 17 00:00:00 2001 From: Jens Lehme Date: Tue, 9 Jun 2015 15:27:01 +0200 Subject: [PATCH 1/2] Refactoring, make puppet 4 conform, add some tests --- .fixtures.yml | 5 ++ Rakefile | 12 +-- manifests/config.pp | 46 ++++++++++ manifests/init.pp | 97 +++++----------------- manifests/install.pp | 9 ++ manifests/params.pp | 48 +++++++++++ spec/classes/cpan_spec.rb | 71 ++++++++++++++++ spec/spec_helper.rb | 31 +++++-- spec/type/cpan_spec.rb | 17 ---- templates/{Config.pm.erb => cpan.conf.erb} | 0 10 files changed, 231 insertions(+), 105 deletions(-) create mode 100644 .fixtures.yml create mode 100644 manifests/config.pp create mode 100644 manifests/install.pp create mode 100644 manifests/params.pp create mode 100644 spec/classes/cpan_spec.rb delete mode 100644 spec/type/cpan_spec.rb rename templates/{Config.pm.erb => cpan.conf.erb} (100%) diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000..344ac89 --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,5 @@ +fixtures: + repositories: + stdlib: git://github.com/puppetlabs/puppetlabs-stdlib + symlinks: + cpan: "#{source_dir}" diff --git a/Rakefile b/Rakefile index e6443dc..74446c5 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,7 @@ -require 'rake' +require 'rubygems' +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' -require 'rspec/core/rake_task' - -RSpec::Core::RakeTask.new(:spec) do |t| - t.pattern = 'spec/*/*_spec.rb' -end +PuppetLint.configuration.fail_on_warnings = true +PuppetLint.configuration.send('relative') +PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] diff --git a/manifests/config.pp b/manifests/config.pp new file mode 100644 index 0000000..f991fa6 --- /dev/null +++ b/manifests/config.pp @@ -0,0 +1,46 @@ +# +class cpan::config inherits cpan { + if $cpan::manage_config { + case $::osfamily { + 'Debian': { + file { [ '/etc/perl', '/etc/perl/CPAN' ]: + ensure => directory, + owner => root, + group => root, + mode => '0755', + } + file { '/etc/perl/CPAN/Config.pm': + ensure => present, + owner => root, + group => root, + mode => '0644', + content => template($cpan::config_template), + require => File['/etc/perl/CPAN'], + } + } + 'RedHat': { + if versioncmp($::operatingsystemmajrelease, '6') >= 0 { + file { '/usr/share/perl5/CPAN/Config.pm': + ensure => present, + owner => root, + group => root, + mode => '0644', + content => template($cpan::config_template), + } + } else { + file { '/usr/lib/perl5/5.8.8/CPAN/Config.pm': + ensure => present, + owner => root, + group => root, + mode => '0644', + source => 'puppet:///modules/cpan/Config.pm', + content => template($cpan::config_template), + } + } + } + default: { + fail("Module ${module_name} is not supported on ${::osfamily} os.") + } + } + } +} diff --git a/manifests/init.pp b/manifests/init.pp index d2e9a16..4095223 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,81 +1,24 @@ # Class cpan class cpan ( - $manage_config = true, - $manage_package = true, - $installdirs = 'site', - $local_lib = false, - $config_hash = { 'build_requires_install_policy' => 'no' }, -) { - unless $installdirs =~ /^(perl|site|vendor)$/ { - fail("installdirs must be one of {perl,site,vendor}") - } - case $::osfamily { - 'Debian': { - if $manage_package { - package { 'perl-modules': ensure => installed } - package { 'gcc': ensure => installed } - package { 'make': ensure => installed } - if $local_lib { - package {'liblocal-lib-perl': ensure => installed } - } - } - if $manage_config { - file { [ '/etc/perl', '/etc/perl/CPAN' ]: - ensure => directory, - owner => root, - group => root, - mode => '0755', - } - file { '/etc/perl/CPAN/Config.pm': - ensure => present, - owner => root, - group => root, - mode => '0644', - content => template('cpan/Config.pm.erb'), - require => File['/etc/perl/CPAN'] - } - } - } - 'Redhat': { - if versioncmp($::operatingsystemmajrelease, '6') >= 0 { - if $manage_package { - package { 'perl-CPAN': ensure => installed } - package { 'gcc': ensure => installed } - package { 'make': ensure => installed } - if $local_lib { - package {'perl-local-lib': ensure => installed } - } - } - if $manage_config { - file { '/usr/share/perl5/CPAN/Config.pm': - ensure => present, - owner => root, - group => root, - mode => '0644', - content => template('cpan/Config.pm.erb'), - } - } - } else { - if $local_lib { - fail('local::lib is not supported on redhat < 6') - } - if $manage_config { - file { '/usr/lib/perl5/5.8.8/CPAN/Config.pm': - ensure => present, - owner => root, - group => root, - mode => '0644', - source => 'puppet:///modules/cpan/Config.pm', - content => template('cpan/Config.pm.erb'), - } - } - } - } - Windows: { + $manage_config = $cpan::params::manage_config, + $manage_package = $cpan::params::manage_package, + $installdirs = $cpan::params::installdirs, + $local_lib = $cpan::params::local_lib, + $config_template = $cpan::params::config_template, + $config_hash = $cpan::params::config_hash, + $package_ensure = $cpan::params::package_ensure, +) inherits cpan::params { + + validate_bool($manage_config) + validate_bool($manage_package) + validate_string($installdirs) + validate_bool($local_lib) + validate_string($config_template) + validate_string($package_ensure) + + anchor { 'cpan::begin': } -> + class { '::cpan::install': } -> + class { '::cpan::config': } -> + anchor { 'cpan::end': } - } - default: { - fail("Module ${module_name} is not supported on ${::osfamily}") - } - } } diff --git a/manifests/install.pp b/manifests/install.pp new file mode 100644 index 0000000..ab9a45c --- /dev/null +++ b/manifests/install.pp @@ -0,0 +1,9 @@ +# +class cpan::install inherits cpan { + + if $cpan::manage_package { + package { $cpan::package_name: + ensure => $cpan::package_ensure, + } + } +} diff --git a/manifests/params.pp b/manifests/params.pp new file mode 100644 index 0000000..0f86222 --- /dev/null +++ b/manifests/params.pp @@ -0,0 +1,48 @@ +# Class: cpan::params +class cpan::params { + + $manage_config = true + $installdirs = 'site' + $local_lib = false + $config_template = 'cpan/cpan.conf.erb' + $config_hash = { 'build_requires_install_policy' => 'no' } + $package_ensure = 'present' + $common_package = ['gcc','make'] + + unless $installdirs =~ /^(perl|site|vendor)$/ { + fail('installdirs must be one of {perl,site,vendor}') + } + + $manage_package = $::osfamily ? { + 'Debian' => true, + 'Redhat' => true, + default => false, + } + case $::osfamily { + 'Debian': { + $common_os_package = ['perl-modules'] + if $local_lib { + $local_lib_package = ['liblocal-lib-perl'] + } else { + $local_lib_package = [] + } + } + 'RedHat': { + $common_os_package = ['perl-CPAN'] + + if $local_lib { + if ($::operatingsystem == 'RedHat' and versioncmp($::operatingsystemmajrelease, '6') >= 0) { + $local_lib_package = ['perl-local-lib'] + } elsif ($::operatingsystem == 'Fedora' and versioncmp($::operatingsystemmajrelease, '16') >=0) { + $local_lib_package = ['perl-local-lib'] + } + } else { + $local_lib_package = [] + } + } + default: { + fail("Module ${module_name} is not supported on ${::osfamily}") + } + } + $package_name = concat($common_package,$common_os_package,$local_lib_package ) +} diff --git a/spec/classes/cpan_spec.rb b/spec/classes/cpan_spec.rb new file mode 100644 index 0000000..7eddda8 --- /dev/null +++ b/spec/classes/cpan_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper' + +describe 'cpan' do + let(:facts) { {} } + ['Debian','RedHat'].each do |system| + context "On a #{system} OS ..." do + let(:facts) { super().merge( :osfamily => system ) } + + it { should contain_class('cpan::install') } + it { should contain_class('cpan::config') } + + describe "cpan::install" do + let(:params) { {:package_ensure => 'present', :manage_package => true, :local_lib => false} } + + it { should contain_package('gcc').with(:ensure => 'present') } + it { should contain_package('make').with(:ensure => 'present') } + + if system == 'Debian' + it { should contain_package('perl-modules').with(:ensure => 'present') } + end + + if system == 'RedHat' + it { should contain_package('perl-CPAN').with(:ensure => 'present') } + end + + describe 'should allow package ensure to be overridden' do + let(:params) { {:package_ensure => 'latest', :manage_package => true} } + it { should contain_package('gcc').with_ensure('latest') } + it { should contain_package('make').with_ensure('latest') } + if system == 'Debian' + it { should contain_package('perl-modules').with(:ensure => 'latest') } + end + if system == 'RedHat' + it { should contain_package('perl-CPAN').with(:ensure => 'latest') } + end + end + end + end + + context 'cpan::config' do + + describe "cpan::config on Debian" do + let(:facts) { super().merge(:osfamily => 'Debian') } + it { should contain_file('/etc/perl/CPAN/Config.pm').with_owner('root') } + it { should contain_file('/etc/perl/CPAN/Config.pm').with_group('root') } + it { should contain_file('/etc/perl/CPAN/Config.pm').with_mode('0644') } + end + + describe 'cpan::config on RedHat and operatingsystemrelease 6' do + let(:facts) { super().merge(:osfamily => 'RedHat', :operatingsystemmajrelease => '6') } + it { should contain_file('/usr/share/perl5/CPAN/Config.pm').with_owner('root') } + it { should contain_file('/usr/share/perl5/CPAN/Config.pm').with_group('root') } + it { should contain_file('/usr/share/perl5/CPAN/Config.pm').with_mode('0644') } + end + + describe 'cpan::config on RedHat and operatingsystemrelease 5' do + let(:facts) { super().merge(:osfamily => 'RedHat', :operatingsystemmajrelease => '5') } + it { should contain_file('/usr/lib/perl5/5.8.8/CPAN/Config.pm').with_owner('root') } + it { should contain_file('/usr/lib/perl5/5.8.8/CPAN/Config.pm').with_group('root') } + it { should contain_file('/usr/lib/perl5/5.8.8/CPAN/Config.pm').with_mode('0644') } + end + + describe "for operating system family unsupported" do + let(:facts) { super().merge(:osfamily => 'unsupported') } + it { expect {catalogue}.to raise_error( + /Module cpan is not supported/ + ) } + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d3923f8..ba15afe 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,8 +1,29 @@ -require 'rspec-puppet' - -fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) +require 'rubygems' +require 'puppetlabs_spec_helper/module_spec_helper' RSpec.configure do |c| - c.module_path = File.join(fixture_path, 'modules') - c.manifest_dir = File.join(fixture_path, 'manifests') + c.include PuppetlabsSpec::Files + + c.before :each do + # Ensure that we don't accidentally cache facts and environment + # between test cases. + Facter::Util::Loader.any_instance.stubs(:load_all) + Facter.clear + Facter.clear_messages + + # Store any environment variables away to be restored later + @old_env = {} + ENV.each_key {|k| @old_env[k] = ENV[k]} + + if Gem::Version.new(`puppet --version`) >= Gem::Version.new('3.5') + Puppet.settings[:strict_variables]=true + end + if ENV['PARSER'] + Puppet.settings[:parser]=ENV['PARSER'] + end + end + + c.after :each do + PuppetlabsSpec::Files.cleanup + end end diff --git a/spec/type/cpan_spec.rb b/spec/type/cpan_spec.rb deleted file mode 100644 index 776fa97..0000000 --- a/spec/type/cpan_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'spec_helper' - -describe Puppet::Type.type(:cpan) do - before :each do - @provider_class = described_class.provide(:simple) do - mk_resource_methods - def create; end - def delete; end - def exists?; get(:ensure) != :absent; end - end - described_class.stub(:defaultprovider).and_return @provider_class - end - - it "should be able to create an instance" do - described_class.new(:name => 'LWP').should_not be_nil - end -end diff --git a/templates/Config.pm.erb b/templates/cpan.conf.erb similarity index 100% rename from templates/Config.pm.erb rename to templates/cpan.conf.erb From 3086dd7b160a2bd3f144d4830cc9a55d4adf94ac Mon Sep 17 00:00:00 2001 From: Salimane Adjao Moustapha Date: Fri, 12 Aug 2016 13:35:38 +0200 Subject: [PATCH 2/2] Update the CI setup with travisci - Update Readme - Add travisci config file and badges - Restructure rspec test cases - bump version for new release Signed-off-by: Salimane Adjao Moustapha --- .fixtures.yml | 2 +- .gitignore | 5 + .rspec | 2 + .travis.yml | 30 ++++++ Gemfile | 16 +++ LICENSE | 201 ++++++++++++++++++++++++++++++++++++++ Modulefile | 3 - README.md | 147 ++++++++++++++++++++++------ Rakefile | 49 +++++++++- manifests/config.pp | 22 +++-- manifests/init.pp | 32 +++++- manifests/install.pp | 9 +- manifests/params.pp | 5 +- metadata.json | 66 ++++--------- spec/classes/cpan_spec.rb | 31 +++++- spec/spec_helper.rb | 29 +----- test/local_lib.pp | 5 +- test/local_lib_default.pp | 5 +- test/no_local_lib.pp | 5 +- 19 files changed, 528 insertions(+), 136 deletions(-) create mode 100644 .gitignore create mode 100644 .rspec create mode 100644 .travis.yml create mode 100644 Gemfile create mode 100644 LICENSE delete mode 100644 Modulefile diff --git a/.fixtures.yml b/.fixtures.yml index 344ac89..d4e209c 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,5 +1,5 @@ fixtures: repositories: - stdlib: git://github.com/puppetlabs/puppetlabs-stdlib + stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git" symlinks: cpan: "#{source_dir}" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..18384b8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.*.sw? +pkg +.rspec_system/ +spec/fixtures +Gemfile.lock 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..1aa2874 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,30 @@ +--- +language: ruby +cache: bundler +sudo: false +bundler_args: --without development +before_install: rm Gemfile.lock || true +script: bundle exec rake test +matrix: + fast_finish: true + include: + - rvm: 2.0.0 + env: PUPPET_VERSION="~> 3.0" FUTURE_PARSER="yes" + - rvm: 2.0.0 + env: PUPPET_VERSION="~> 3.3.0" + - rvm: 2.0.0 + env: PUPPET_VERSION="~> 3.7" + - rvm: 2.1.0 + env: PUPPET_VERSION="~> 3" FUTURE_PARSER="yes" + - rvm: 2.1.8 + env: PUPPET_VERSION="~> 4.0" + - rvm: 2.1.8 + env: PUPPET_VERSION="~> 4" + - rvm: 2.2.4 + env: PUPPET_VERSION="~> 4.0" + - rvm: 2.2.4 + env: PUPPET_VERSION="~> 4" + - rvm: 2.3.0 + env: PUPPET_VERSION="~> 4.0" + - rvm: 2.3.0 + env: PUPPET_VERSION="~> 4" diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..a6a75ec --- /dev/null +++ b/Gemfile @@ -0,0 +1,16 @@ +source "https://rubygems.org" + +group :test do + gem "rake", '~> 11.2.2' + gem "puppet", ENV['PUPPET_VERSION'] || '~> 4.5.3' + gem "puppet-lint", '~> 2.0.0' + gem "rspec-puppet", '~> 2.4.0' + gem "puppetlabs_spec_helper", '~> 1.1.1' + gem "metadata-json-lint", '~> 0.0.11' +end + +group :development do + gem "travis", '~> 1.8.2' + gem "travis-lint", '~> 2.0.0' + gem "guard-rake", '~> 1.0.0' +end diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..11069ed --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + 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 e3aba7f..0000000 --- a/Modulefile +++ /dev/null @@ -1,3 +0,0 @@ -name 'meltwater-cpan' -version '1.0.1' -description "Provides a puppet type to easily install perl CPAN modules" diff --git a/README.md b/README.md index a22e0a4..9553df9 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,139 @@ -puppet-cpan -=========== +# puppet-cpan -Handle installations of cpan modules via puppet. -The force parameter will allow stubborn modules to be installed unattended. +[![Puppet Forge Version](http://img.shields.io/puppetforge/v/meltwater/cpan.svg)](https://forge.puppetlabs.com/meltwater/cpan) +[![Puppet Forge Downloads](http://img.shields.io/puppetforge/dt/meltwater/cpan.svg)](https://forge.puppetlabs.com/meltwater/cpan) +[![Travis branch](https://img.shields.io/travis/meltwater/puppet-cpan/master.svg)](https://travis-ci.org/meltwater/puppet-cpan) +[![By Meltwater](https://img.shields.io/badge/by-meltwater-28bbbb.svg)](http://underthehood.meltwater.com/) +[![Maintenance](https://img.shields.io/maintenance/yes/2016.svg)](https://github.com/meltwater/puppet-cpan/commits/master) +[![license](https://img.shields.io/github/license/meltwater/puppet-cpan.svg)](https://github.com/meltwater/puppet-cpan/blob/master/LICENSE) -Usage Example -------------- +#### Table of Contents - include cpan - cpan { "Clone::Closure": - ensure => present, - require => Class['::cpan'], - force => true, - } +1. [Overview](#overview) +2. [Module Description - What the module does and why it is useful](#module-description) +3. [Setup - The basics of getting started with cpan](#setup) + * [What cpan affects](#what-cpan-affects) + * [Beginning with cpan](#beginning-with-cpan) +4. [Usage - Configuration options and additional functionality](#usage) +5. [Reference - An under-the-hood peek at what the module is doing and how](#reference) -Package Management ------------------- -To avoid conflicts with inhouse package management, use: +## Overview - class {'cpan': - manage_package => false, - } +Handle installations of [cpan modules](http://www.cpan.org/modules/) via puppet. + +## Module Description +The cpan module sets up capn on a server + +## Setup + +### What puppet-cpan affects + +* cpan package. +* cpan configuration file. + +## Usage + +All options and configuration can be done through interacting with the parameters +on the cpan class and the cpan resource type. These are documented below. + +## cpan class + +```puppet +class {'::cpan': + manage_config => true, + manage_package => true, + package_ensure => 'present', + installdirs => 'site', + local_lib => false, + config_hash => { 'build_requires_install_policy' => 'no' }, +} +``` + +### Beginning with cpan + +```puppet +include '::cpan' +cpan { "Clone::Closure": + ensure => present, + require => Class['::cpan'], + force => true, +} +``` + +### Package Management + +To avoid conflicts with in house package management, use: + +```puppet +class {'::cpan': + manage_package => false, +} +``` + +### Install Destination -Install Destination -------------------- To control target installation path, use: - class {'cpan': - installdirs => 'vendor' - } +```puppet +class {'::cpan': + installdirs => 'vendor', +} +``` Any of `site` (default), `perl` and `vendor` are accepted. To further control the location of installed modules, you can use [local::lib](http://search.cpan.org/perldoc?local::lib): - cpan { 'Foo::Bar': - ensure => present, - local_lib => '/opt', - } +```puppet +cpan { 'Foo::Bar': + ensure => present, + local_lib => '/opt', +} +``` This will install the module into `/opt`. Of course you need to adjust `@INC` of your code in order to use that new location, *e.g.* by using `perl -Mlocal::lib=/opt myapp.pl`. You can also define the default value of `local_lib` for all `cpan` resources: - Cpan { local_lib => '/opt' } +```puppet +Cpan { local_lib => '/opt' } +``` + + +## Reference + +## Classes + +* cpan: Main class for installation and service management. +* cpan::install: Handles package installation. +* cpan::params: Different configuration data for different systems. +* cpan::config: Handles the cpan service. + +### Parameters + +#### `manage_config` + +#### `manage_package` + +#### `installdirs` + +#### `local_lib` + +#### `config_template` + +#### `config_hash` + +#### `package_ensure` + +## Limitations + +This module has been built on and tested against Puppet 3.x and Puppet 4.x + +The module has been tested on: + +* RedHat Enterprise Linux 6/7 +* Debian 6/7 +* CentOS 6/7 +Testing on other platforms has been light and cannot be guaranteed. diff --git a/Rakefile b/Rakefile index 74446c5..0143c93 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,48 @@ -require 'rubygems' require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-lint/tasks/puppet-lint' +require 'puppet-syntax/tasks/puppet-syntax' -PuppetLint.configuration.fail_on_warnings = true -PuppetLint.configuration.send('relative') -PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] +exclude_paths = [ + "pkg/**/*", + "vendor/**/*", + "spec/**/*", +] +PuppetLint.configuration.ignore_paths = exclude_paths +PuppetSyntax.exclude_paths = exclude_paths + +Rake::Task[:lint].clear +PuppetLint::RakeTask.new :lint do |config| + config.ignore_paths = exclude_paths + config.log_format = '%{path}:%{linenumber}:%{check}:%{KIND}:%{message}' + + # Forsake support for Puppet 2.6.2 for the benefit of cleaner code. + # http://puppet-lint.com/checks/class_parameter_defaults/ + # http://puppet-lint.com/checks/class_inherits_from_params_class/ + config.disable_checks = [ + "class_inherits_from_params_class", + "80chars", + "puppet_url_without_modules", + "inherits_across_namespaces", + "class_parameter_defaults" + ] + config.fail_on_warnings = true + config.relative = true +end + +PuppetSyntax.exclude_paths = exclude_paths + +task :metadata do + sh "bundle exec metadata-json-lint metadata.json" +end + +Rake::Task[:default].clear +desc 'Run test by default' +task :default => [:test] + +desc "Run syntax, lint, and spec tests." +task :test => [ + :syntax, + :lint, + :spec, + :metadata_lint, +] diff --git a/manifests/config.pp b/manifests/config.pp index f991fa6..fb327c6 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -1,6 +1,9 @@ +# == Class: cpan::config +# +# Private class. Should not be called directly. # class cpan::config inherits cpan { - if $cpan::manage_config { + if $::cpan::manage_config { case $::osfamily { 'Debian': { file { [ '/etc/perl', '/etc/perl/CPAN' ]: @@ -14,27 +17,26 @@ owner => root, group => root, mode => '0644', - content => template($cpan::config_template), + content => template($::cpan::config_template), require => File['/etc/perl/CPAN'], } } 'RedHat': { - if versioncmp($::operatingsystemmajrelease, '6') >= 0 { + if versioncmp($::operatingsystemmajrelease, '6') >= 0 and $::operatingsystem != 'Fedora' { file { '/usr/share/perl5/CPAN/Config.pm': ensure => present, - owner => root, - group => root, + owner => 'root', + group => 'root', mode => '0644', - content => template($cpan::config_template), + content => template($::cpan::config_template), } } else { file { '/usr/lib/perl5/5.8.8/CPAN/Config.pm': ensure => present, - owner => root, - group => root, + owner => 'root', + group => 'root', mode => '0644', - source => 'puppet:///modules/cpan/Config.pm', - content => template($cpan::config_template), + content => template($::cpan::config_template), } } } diff --git a/manifests/init.pp b/manifests/init.pp index 4095223..ffe2c4a 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,4 +1,34 @@ -# Class cpan +# == Class: cpan +# +# Installs cpan +# +# === Parameters +# +# [*manage_config*] +# +# [*manage_package*] +# +# [*installdirs*] +# +# [*local_lib*] +# +# [*config_template*] +# +# [*config_hash*] +# +# [*package_ensure*] +# +# === Examples +# +# class {'::cpan': +# manage_config => true, +# manage_package => true, +# package_ensure => 'present', +# installdirs => 'site', +# local_lib => false, +# config_hash => { 'build_requires_install_policy' => 'no' }, +# } +# class cpan ( $manage_config = $cpan::params::manage_config, $manage_package = $cpan::params::manage_package, diff --git a/manifests/install.pp b/manifests/install.pp index ab9a45c..700db57 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -1,9 +1,12 @@ +# == Class cpan::install +# +# Installs cpan. # class cpan::install inherits cpan { - if $cpan::manage_package { - package { $cpan::package_name: - ensure => $cpan::package_ensure, + if $::cpan::manage_package { + package { $::cpan::package_name : + ensure => $::cpan::package_ensure, } } } diff --git a/manifests/params.pp b/manifests/params.pp index 0f86222..bc95fd6 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,4 +1,7 @@ -# Class: cpan::params +# == Class: cpan::params +# +# Parameters for cpan class +# class cpan::params { $manage_config = true diff --git a/metadata.json b/metadata.json index e4548f5..ab93426 100644 --- a/metadata.json +++ b/metadata.json @@ -1,52 +1,28 @@ { "name": "meltwater-cpan", - "version": "1.0.0", - "source": "UNKNOWN", + "version": "2.0.0", "author": "meltwater", - "license": "Apache License, Version 2.0", - "summary": "UNKNOWN", - "description": "Provides a puppet type to easily install perl CPAN modules", - "project_page": "UNKNOWN", - "dependencies": [ - - ], - "types": [ + "summary": "Provides a puppet type to easily install Perl CPAN modules.", + "description": "Puppet module for installing and configuring the Marathon framework for Mesos.", + "license": "Apache-2.0", + "source": "https://github.com/meltwater/puppet-cpan", + "project_page": "https://github.com/meltwater/puppet-cpan", + "issues_url": "https://github.com/meltwater/puppet-cpan/issues", + "operatingsystem_support": [ + { + "operatingsystem": "RedHat", + "operatingsystemrelease":[ "5.0", "6.0", "7.0" ] + }, { - "name": "cpan", - "doc": "Install cpan modules", - "properties": [ - { - "name": "ensure", - "doc": "The basic property that the resource should be in.\n\nValid values are `present`, `absent`, `latest`. " - }, - { - "name": "force", - "doc":"Enable/Disable the installation of the module. Disabled by default.\n\nValid values are `true`, `false`" - } - ], - "parameters": [ - { - "name": "name", - "doc": "The name of the module.\n\n" - } - ], - "providers": [ - { - "name": "default", - "doc": "Manages cpan modules\n\n* Required binaries: `cpan`, `perl`." - } - ] + "operatingsystem": "Debian", + "operatingsystemrelease": [ "6", "7" ] } ], - "checksums": { - "Modulefile": "92c74701a5bdc136413278666a1e0106", - "README.md": "97f5e14f20694b55eeea4e00cae89fd4", - "Rakefile": "f39450f89f23380c06f6d6a36d0ec017", - "files/Config.pm": "8275e4cc16586abfa7d92ba92c3886ac", - "lib/puppet/provider/cpan/default.rb": "2a5c700c99147aaa1e33452e33503c88", - "lib/puppet/type/cpan.rb": "6c82dc9d17b00c60547811a3bb6f793d", - "manifests/init.pp": "a44a15d63438a60bd52b2a4722bc3194", - "spec/spec_helper.rb": "792eeb7aa7edafb93e2bc1d27c5e75c5", - "spec/type/cpan_spec.rb": "3e9398882212cd92645e12ca98f1a058" - } + "tags": [ "cpan", "perl", "metacpan", "module", "lib" ], + "dependencies": [ + { + "name":"puppetlabs-stdlib", + "version_requirement":">= 2.2.0" + } + ] } diff --git a/spec/classes/cpan_spec.rb b/spec/classes/cpan_spec.rb index 7eddda8..45a5c9b 100644 --- a/spec/classes/cpan_spec.rb +++ b/spec/classes/cpan_spec.rb @@ -1,10 +1,28 @@ require 'spec_helper' -describe 'cpan' do +describe 'cpan', :type => 'class' do let(:facts) { {} } - ['Debian','RedHat'].each do |system| + ['Debian', 'RedHat'].each do |system| context "On a #{system} OS ..." do - let(:facts) { super().merge( :osfamily => system ) } + if system == 'Debian' + let(:facts) { super().merge( + :operatingsystem => system, + :osfamily => system, + :operatingsystemmajrelease => '6', + :path => '/usr/local/bin:/usr/bin:/bin', + ) + } + end + + if system == 'RedHat' + let(:facts) { super().merge( + :osfamily => system, + :operatingsystem => system, + :operatingsystemmajrelease => '6', + :path => '/usr/local/bin:/usr/bin:/bin', + ) + } + end it { should contain_class('cpan::install') } it { should contain_class('cpan::config') } @@ -53,6 +71,13 @@ it { should contain_file('/usr/share/perl5/CPAN/Config.pm').with_mode('0644') } end + describe 'cpan::config on RedHat and operatingsystemrelease 7' do + let(:facts) { super().merge(:osfamily => 'RedHat', :operatingsystemmajrelease => '7') } + it { should contain_file('/usr/share/perl5/CPAN/Config.pm').with_owner('root') } + it { should contain_file('/usr/share/perl5/CPAN/Config.pm').with_group('root') } + it { should contain_file('/usr/share/perl5/CPAN/Config.pm').with_mode('0644') } + end + describe 'cpan::config on RedHat and operatingsystemrelease 5' do let(:facts) { super().merge(:osfamily => 'RedHat', :operatingsystemmajrelease => '5') } it { should contain_file('/usr/lib/perl5/5.8.8/CPAN/Config.pm').with_owner('root') } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ba15afe..b57d07b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,29 +1,2 @@ -require 'rubygems' -require 'puppetlabs_spec_helper/module_spec_helper' - -RSpec.configure do |c| - c.include PuppetlabsSpec::Files - - c.before :each do - # Ensure that we don't accidentally cache facts and environment - # between test cases. - Facter::Util::Loader.any_instance.stubs(:load_all) - Facter.clear - Facter.clear_messages - # Store any environment variables away to be restored later - @old_env = {} - ENV.each_key {|k| @old_env[k] = ENV[k]} - - if Gem::Version.new(`puppet --version`) >= Gem::Version.new('3.5') - Puppet.settings[:strict_variables]=true - end - if ENV['PARSER'] - Puppet.settings[:parser]=ENV['PARSER'] - end - end - - c.after :each do - PuppetlabsSpec::Files.cleanup - end -end +require 'puppetlabs_spec_helper/module_spec_helper' diff --git a/test/local_lib.pp b/test/local_lib.pp index ec3edee..f65e125 100644 --- a/test/local_lib.pp +++ b/test/local_lib.pp @@ -1,11 +1,10 @@ # -class { 'cpan': +class { '::cpan': manage_package => false, - manage_config => false, + manage_config => false, } cpan { 'Riemann::Client': ensure => present, local_lib => '/tmp/cpan' } - diff --git a/test/local_lib_default.pp b/test/local_lib_default.pp index 8bbf808..8b0a716 100644 --- a/test/local_lib_default.pp +++ b/test/local_lib_default.pp @@ -1,7 +1,7 @@ # -class { 'cpan': +class { '::cpan': manage_package => false, - manage_config => false, + manage_config => false, } Cpan { @@ -11,4 +11,3 @@ cpan { 'Riemann::Client': ensure => present, } - diff --git a/test/no_local_lib.pp b/test/no_local_lib.pp index bb1211e..7e670b5 100644 --- a/test/no_local_lib.pp +++ b/test/no_local_lib.pp @@ -1,11 +1,10 @@ # -class { 'cpan': +class { '::cpan': manage_package => false, - manage_config => false, + manage_config => false, } cpan { 'Riemann::Client': ensure => present, local_lib => false } -