diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0ee4cd0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,58 @@ +# DO NOT EDIT THIS FILE! +# This file is managed by ModuleSync. + +name: CI + +on: + push: + branches: + - main + - master + pull_request: + branches: + - main + - master + +jobs: + setup_matrix: + name: 'Setup Test Matrix' + runs-on: ubuntu-latest + outputs: + beaker_setfiles: ${{ steps.get-outputs.outputs.beaker_setfiles }} + puppet_major_versions: ${{ steps.get-outputs.outputs.puppet_major_versions }} + puppet_unit_test_matrix: ${{ steps.get-outputs.outputs.puppet_unit_test_matrix }} + env: + BUNDLE_WITHOUT: development:test:release + steps: + - uses: actions/checkout@v2 + - name: Setup ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '2.7' + bundler-cache: true + - name: Run rake validate + run: bundle exec rake validate + - name: Setup Test Matrix + id: get-outputs + run: bundle exec metadata2gha --use-fqdn --pidfile-workaround false + + unit: + needs: setup_matrix + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: ${{fromJson(needs.setup_matrix.outputs.puppet_unit_test_matrix)}} + env: + BUNDLE_WITHOUT: development:system_tests:release + PUPPET_VERSION: "~> ${{ matrix.puppet }}.0" + name: Puppet ${{ matrix.puppet }} (Ruby ${{ matrix.ruby }}) + steps: + - uses: actions/checkout@v2 + - name: Setup ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Run tests + run: bundle exec rake diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..68b8528 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,29 @@ +name: Release + +on: + push: + tags: + - '*' + +env: + BUNDLE_WITHOUT: development:test:system_tests + +jobs: + deploy: + name: 'deploy to forge' + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '2.7' + bundler-cache: true + - name: Build and Deploy + env: + # Configure secrets here: + # https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets + BLACKSMITH_FORGE_USERNAME: '${{ secrets.PUPPET_FORGE_USERNAME }}' + BLACKSMITH_FORGE_API_KEY: '${{ secrets.PUPPET_FORGE_API_KEY }}' + run: bundle exec rake module:push diff --git a/.rspec b/.rspec index 16f9cdb..0b84c1c 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1,4 @@ ---color +# DO NOT EDIT THIS FILE! +# This file is managed by ModuleSync. --format documentation +--color diff --git a/.rubocop.yml b/.rubocop.yml index f5a6c2a..0c53a1e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,122 +1,19 @@ --- -require: rubocop-rspec +# DO NOT EDIT THIS FILE! +# This file is managed by ModuleSync. +inherit_gem: + voxpupuli-test: rubocop.yml AllCops: - DisplayCopNames: true - TargetRubyVersion: '2.1' - Include: - - "./**/*.rb" - Exclude: - - bin/* - - ".vendor/**/*" - - "**/Gemfile" - - "**/Rakefile" - - pkg/**/* - - spec/fixtures/**/* - - vendor/**/* - - "**/Puppetfile" - - "**/Vagrantfile" - - "**/Guardfile" + TargetRubyVersion: "2.4" Metrics/LineLength: Description: People have wide screens, use them. Max: 200 -GetText/DecorateString: - Description: We don't want to decorate test output. - Exclude: - - spec/* -RSpec/BeforeAfterAll: - Description: Beware of using after(:all) as it may cause state to leak between tests. - A necessary evil in acceptance testing. - Exclude: - - spec/acceptance/**/*.rb -RSpec/HookArgument: - Description: Prefer explicit :each argument, matching existing module's style - EnforcedStyle: each -Style/BlockDelimiters: - Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to - be consistent then. - EnforcedStyle: braces_for_chaining -Style/ClassAndModuleChildren: - Description: Compact style reduces the required amount of indentation. - EnforcedStyle: compact -Style/EmptyElse: - Description: Enforce against empty else clauses, but allow `nil` for clarity. - EnforcedStyle: empty -Style/FormatString: - Description: Following the main puppet project's style, prefer the % format format. - EnforcedStyle: percent -Style/FormatStringToken: - Description: Following the main puppet project's style, prefer the simpler template - tokens over annotated ones. - EnforcedStyle: template -Style/Lambda: - Description: Prefer the keyword for easier discoverability. - EnforcedStyle: literal -Style/RegexpLiteral: - Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 - EnforcedStyle: percent_r -Style/TernaryParentheses: - Description: Checks for use of parentheses around ternary conditions. Enforce parentheses - on complex expressions for better readability, but seriously consider breaking - it up. - EnforcedStyle: require_parentheses_when_complex -Style/TrailingCommaInArguments: - Description: Prefer always trailing comma on multiline argument lists. This makes - diffs, and re-ordering nicer. - EnforcedStyleForMultiline: comma -Style/TrailingCommaInLiteral: - Description: Prefer always trailing comma on multiline literals. This makes diffs, - and re-ordering nicer. - EnforcedStyleForMultiline: comma -Style/SymbolArray: - Description: Using percent style obscures symbolic intent of array's contents. - EnforcedStyle: brackets -RSpec/MessageSpies: - EnforcedStyle: receive -Style/Documentation: - Exclude: - - lib/puppet/parser/functions/**/* - - spec/**/* -Style/WordArray: - EnforcedStyle: brackets -Style/CollectionMethods: - Enabled: true -Style/MethodCalledOnDoEndBlock: - Enabled: true -Style/StringMethods: - Enabled: true -Layout/EndOfLine: - Enabled: false -Layout/IndentHeredoc: - Enabled: false -Metrics/AbcSize: - Enabled: false Metrics/BlockLength: Enabled: false -Metrics/ClassLength: - Enabled: false -Metrics/CyclomaticComplexity: - Enabled: false -Metrics/MethodLength: - Enabled: false -Metrics/ModuleLength: - Enabled: false -Metrics/ParameterLists: +Style/FrozenStringLiteralComment: Enabled: false -Metrics/PerceivedComplexity: - Enabled: false -RSpec/DescribeClass: - Enabled: false -RSpec/ExampleLength: - Enabled: false -RSpec/MessageExpectation: - Enabled: false -RSpec/MultipleExpectations: - Enabled: false -RSpec/NestedGroups: - Enabled: false -Style/AsciiComments: - Enabled: false -Style/IfUnlessModifier: - Enabled: false -Style/SymbolProc: +Style/RegexpLiteral: Enabled: false +Style/TrailingCommaInArguments: + Description: Be consistent with Puppet's style + EnforcedStyleForMultiline: comma diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f25ed78..0000000 --- a/.travis.yml +++ /dev/null @@ -1,25 +0,0 @@ -language: ruby -rvm: - - 2.1.9 - - 2.3.4 - - 2.4.1 -before_script: - - bundle install - - bundle exec puppet --version -script: - - bundle exec puppet module build - - bundle exec puppet module install pkg/*.tar.gz - - bundle exec rake spec -env: - matrix: - - PUPPET_GEM_VERSION="~> 4.9.1" FIXTURES_YML=.fixtures-old.yml - - PUPPET_GEM_VERSION="~> 4" FIXTURES_YML=.fixtures-old.yml - - PUPPET_GEM_VERSION="~> 5.4.0" FIXTURES_YML=.fixtures-old.yml - - PUPPET_GEM_VERSION="~> 5" FIXTURES_YML=.fixtures-old.yml - - PUPPET_GEM_VERSION="~> 4.9.1" FIXTURES_YML=.fixtures.yml - - PUPPET_GEM_VERSION="~> 4" FIXTURES_YML=.fixtures.yml - - PUPPET_GEM_VERSION="~> 5.4.0" FIXTURES_YML=.fixtures.yml - - PUPPET_GEM_VERSION="~> 5" FIXTURES_YML=.fixtures.yml -gemfile: Gemfile -notifications: - email: false diff --git a/.yardopts b/.yardopts index 29c933b..f235a7c 100644 --- a/.yardopts +++ b/.yardopts @@ -1 +1,3 @@ ---markup markdown +# DO NOT EDIT THIS FILE! +# This file is managed by ModuleSync. +--fail-on-warning diff --git a/Gemfile b/Gemfile index cf2c387..c8e11d8 100644 --- a/Gemfile +++ b/Gemfile @@ -1,71 +1,29 @@ -source ENV['GEM_SOURCE'] || 'https://rubygems.org' +# DO NOT EDIT THIS FILE! +# This file is managed by ModuleSync. -def location_for(place_or_version, fake_version = nil) - git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} - file_url_regex = %r{\Afile:\/\/(?.*)} +source ENV['GEM_SOURCE'] || "https://rubygems.org" - if place_or_version && (git_url = place_or_version.match(git_url_regex)) - [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact - elsif place_or_version && (file_url = place_or_version.match(file_url_regex)) - ['>= 0', { path: File.expand_path(file_url[:path]), require: false }] - else - [place_or_version, { require: false }] - end +group :test do + gem 'voxpupuli-test', '~> 2.1', :require => false + gem 'simplecov-console', :require => false end - -ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments -minor_version = ruby_version_segments[0..1].join('.') - group :development do - gem "fast_gettext", '1.1.0', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0') - gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0') - gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') - gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9') - gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "puppet-module-posix-default-r#{minor_version}", require: false, platforms: [:ruby] - gem "puppet-module-posix-dev-r#{minor_version}", require: false, platforms: [:ruby] - gem "puppet-module-win-default-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "puppet-module-win-dev-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] end - -puppet_version = ENV['PUPPET_GEM_VERSION'] -facter_version = ENV['FACTER_GEM_VERSION'] -hiera_version = ENV['HIERA_GEM_VERSION'] - -gems = {} - -gems['puppet'] = location_for(puppet_version) - -# If facter or hiera versions have been specified via the environment -# variables - -gems['facter'] = location_for(facter_version) if facter_version -gems['hiera'] = location_for(hiera_version) if hiera_version - -if Gem.win_platform? && puppet_version =~ %r{^(file:///|git://)} - # If we're using a Puppet gem on Windows which handles its own win32-xxx gem - # dependencies (>= 3.5.0), set the maximum versions (see PUP-6445). - gems['win32-dir'] = ['<= 0.4.9', require: false] - gems['win32-eventlog'] = ['<= 0.6.5', require: false] - gems['win32-process'] = ['<= 0.7.5', require: false] - gems['win32-security'] = ['<= 0.2.5', require: false] - gems['win32-service'] = ['0.8.8', require: false] +group :system_tests do + gem 'puppet_metadata', '~> 0.3.0', :require => false + gem 'voxpupuli-acceptance', :require => false end - -gems.each do |gem_name, gem_params| - gem gem_name, *gem_params +group :release do + gem 'github_changelog_generator', :require => false + gem 'puppet-blacksmith', :require => false + gem 'voxpupuli-release', :require => false + gem 'puppet-strings', '>= 2.2', :require => false end +gem 'puppetlabs_spec_helper', '~> 2.0', :require => false +gem 'rake', :require => false +gem 'facter', ENV['FACTER_GEM_VERSION'], :require => false, :groups => [:test] -# Evaluate Gemfile.local and ~/.gemfile if they exist -extra_gemfiles = [ - "#{__FILE__}.local", - File.join(Dir.home, '.gemfile'), -] +puppetversion = ENV['PUPPET_VERSION'] || '~> 6.0' +gem 'puppet', puppetversion, :require => false, :groups => [:test] -extra_gemfiles.each do |gemfile| - if File.file?(gemfile) && File.readable?(gemfile) - eval(File.read(gemfile), binding) - end -end # vim: syntax=ruby diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8dada3e --- /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/README.md b/README.md index 1ba79fb..0069e25 100644 --- a/README.md +++ b/README.md @@ -564,7 +564,7 @@ ihrweinsyslogng_ubuntu1204ruby187_1 rake spec Up ihrweinsyslogng_ubuntu1404ruby193_1 rake spec Up ``` Now, you can check the progress with `make ps`. If they are not -runnnig, you can see the exit codes. 0 mean OK. +runnnig, you can see the exit codes. 0 mean OK. ### Other information diff --git a/Rakefile b/Rakefile index 750ef46..1c37f9d 100644 --- a/Rakefile +++ b/Rakefile @@ -1,76 +1,66 @@ -require 'puppetlabs_spec_helper/rake_tasks' -require 'puppet-syntax/tasks/puppet-syntax' -require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? -require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? -require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? +# DO NOT EDIT THIS FILE! +# This file is managed by ModuleSync. -def changelog_user - return unless Rake.application.top_level_tasks.include? "changelog" - returnVal = nil || JSON.load(File.read('metadata.json'))['author'] - raise "unable to find the changelog_user in .sync.yml, or the author in metadata.json" if returnVal.nil? - puts "GitHubChangelogGenerator user:#{returnVal}" - returnVal -end +# Attempt to load voxupuli-test (which pulls in puppetlabs_spec_helper), +# otherwise attempt to load it directly. +begin + require 'voxpupuli/test/rake' -def changelog_project - return unless Rake.application.top_level_tasks.include? "changelog" - returnVal = nil || JSON.load(File.read('metadata.json'))['name'] - raise "unable to find the changelog_project in .sync.yml or the name in metadata.json" if returnVal.nil? - puts "GitHubChangelogGenerator project:#{returnVal}" - returnVal + task default: :rubocop +rescue LoadError + require 'puppetlabs_spec_helper/rake_tasks' end -def changelog_future_release - return unless Rake.application.top_level_tasks.include? "changelog" - returnVal = "v%s" % JSON.load(File.read('metadata.json'))['version'] - raise "unable to find the future_release (version) in metadata.json" if returnVal.nil? - puts "GitHubChangelogGenerator future_release:#{returnVal}" - returnVal +# load optional tasks for releases +# only available if gem group releases is installed +begin + require 'voxpupuli/release/rake_tasks' +rescue LoadError end -PuppetLint.configuration.send('disable_relative') +desc 'Generate REFERENCE.md' +task :reference, [:debug, :backtrace] do |t, args| + patterns = '' + Rake::Task['strings:generate:reference'].invoke(patterns, args[:debug], args[:backtrace]) +end -if Bundler.rubygems.find_name('github_changelog_generator').any? +begin + require 'github_changelog_generator/task' GitHubChangelogGenerator::RakeTask.new :changelog do |config| - raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include? "changelog" and ENV['CHANGELOG_GITHUB_TOKEN'].nil? - config.user = "#{changelog_user}" - config.project = "#{changelog_project}" - config.future_release = "#{changelog_future_release}" - config.exclude_labels = ['maintenance'] - config.header = "# Change log\n\nAll notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org)." - config.add_pr_wo_labels = true - config.issues = false - config.merge_prefix = "### UNCATEGORIZED PRS; GO LABEL THEM" - config.configure_sections = { - "Changed" => { - "prefix" => "### Changed", - "labels" => ["backwards-incompatible"], - }, - "Added" => { - "prefix" => "### Added", - "labels" => ["feature", "enhancement"], - }, - "Fixed" => { - "prefix" => "### Fixed", - "labels" => ["bugfix"], - }, - } + config.future_release = Blacksmith::Modulefile.new.version + config.header = <<~HEADER.chomp + # Changelog + + All notable changes to this project will be documented in this file. + + The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) + and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + HEADER + config.exclude_labels = %w{duplicate question invalid wontfix wont-fix modulesync skip-changelog ignore} + config.user = 'ccin2p3' + metadata_json = File.join(File.dirname(__FILE__), 'metadata.json') + metadata = JSON.load(File.read(metadata_json)) + config.project = "puppet-#{metadata['name'].split('-').last}" end -else - desc 'Generate a Changelog from GitHub' - task :changelog do - raise <= Gem::Version.new('2.2.2')" -EOM + + require 'puppet_blacksmith' + Blacksmith::RakeTask.new do |t| + t.tag_pattern = '%s' + t.commit_message_pattern = 'Bump version to %s' + end + + # Workaround for https://github.com/github-changelog-generator/github-changelog-generator/issues/715 + require 'rbconfig' + if RbConfig::CONFIG['host_os'] =~ /linux/ + task :changelog do + puts 'Fixing line endings...' + changelog_file = File.join(__dir__, 'CHANGELOG.md') + changelog_txt = File.read(changelog_file) + new_contents = changelog_txt.gsub(%r{\r\n}, "\n") + File.open(changelog_file, "w") {|file| file.puts new_contents } + end end -end +rescue LoadError +end +# vim: syntax=ruby diff --git a/lib/facter/syslog_ng.rb b/lib/facter/syslog_ng.rb index 370ec26..3642bdc 100644 --- a/lib/facter/syslog_ng.rb +++ b/lib/facter/syslog_ng.rb @@ -1,20 +1,16 @@ Facter.add(:syslog_ng) do setcode do if Facter::Util::Resolution.which('syslog-ng') - output = Facter::Util::Resolution.exec("syslog-ng --version").lines + output = Facter::Util::Resolution.exec('syslog-ng --version').lines facts = {} output.each do |e| - if e =~ /^([^:]*):\s*(.*)/ - k = $1 - v = $2 - facts[k] = v - if v =~ /,/ - facts[k] = v.split(',') - end - end + next unless e =~ /^([^:]*):\s*(.*)/ + k = Regexp.last_match(1) + v = Regexp.last_match(2) + facts[k] = v + facts[k] = v.split(',') if v.match?(/,/) end facts end end end - diff --git a/lib/facter/syslog_ng_semantic_version.rb b/lib/facter/syslog_ng_semantic_version.rb index d790fee..577a6f9 100644 --- a/lib/facter/syslog_ng_semantic_version.rb +++ b/lib/facter/syslog_ng_semantic_version.rb @@ -1,6 +1,6 @@ Facter.add(:syslog_ng_semantic_version) do setcode do Facter.value(:syslog_ng_version) =~ /^(\d+\.\d+\.\d+)/ - $1 + Regexp.last_match(1) end end diff --git a/lib/facter/syslog_ng_version.rb b/lib/facter/syslog_ng_version.rb index 4e3f2a1..06523f0 100644 --- a/lib/facter/syslog_ng_version.rb +++ b/lib/facter/syslog_ng_version.rb @@ -10,4 +10,3 @@ end end end - diff --git a/lib/puppet/parser/functions/generate_log.rb b/lib/puppet/parser/functions/generate_log.rb index 36d42bf..080b9b1 100644 --- a/lib/puppet/parser/functions/generate_log.rb +++ b/lib/puppet/parser/functions/generate_log.rb @@ -1,13 +1,13 @@ if RUBY_VERSION >= '1.9.2' - require_relative 'log' + require_relative 'log' else - require File.join(File.expand_path(File.dirname(__FILE__)), './log') + require File.join(File.expand_path(File.dirname(__FILE__)), './log') end module Puppet::Parser::Functions - newfunction(:generate_log, :type => :rvalue) do |args| + newfunction(:generate_log, type: :rvalue) do |args| options = args[0] - - Log.generate_log(options) - end + + Log.generate_log(options) + end end diff --git a/lib/puppet/parser/functions/generate_options.rb b/lib/puppet/parser/functions/generate_options.rb index 8e92e72..5df108d 100644 --- a/lib/puppet/parser/functions/generate_options.rb +++ b/lib/puppet/parser/functions/generate_options.rb @@ -1,15 +1,13 @@ require 'stringio' module Puppet::Parser::Functions - newfunction(:generate_options, :type => :rvalue) do |args| + newfunction(:generate_options, type: :rvalue) do |args| options = args[0] buffer = StringIO.new buffer << "options {\n" indent = ' ' - if options.length == 0 - return "" - end + return '' if options.empty? options.keys.sort.each do |option| value = options[option] diff --git a/lib/puppet/parser/functions/generate_statement.rb b/lib/puppet/parser/functions/generate_statement.rb index 46d4c7e..96aa9b7 100644 --- a/lib/puppet/parser/functions/generate_statement.rb +++ b/lib/puppet/parser/functions/generate_statement.rb @@ -1,15 +1,15 @@ if RUBY_VERSION >= '1.9.2' - require_relative 'statement' + require_relative 'statement' else - require File.join(File.expand_path(File.dirname(__FILE__)), './statement') + require File.join(File.expand_path(File.dirname(__FILE__)), './statement') end module Puppet::Parser::Functions - newfunction(:generate_statement, :type => :rvalue) do |args| - id = args[0] - type = args[1] - params = args[2] + newfunction(:generate_statement, type: :rvalue) do |args| + id = args[0] + type = args[1] + params = args[2] - Statement.generate_statement(id, type, params) - end + Statement.generate_statement(id, type, params) + end end diff --git a/lib/puppet/parser/functions/log.rb b/lib/puppet/parser/functions/log.rb index 969f343..f25ca02 100644 --- a/lib/puppet/parser/functions/log.rb +++ b/lib/puppet/parser/functions/log.rb @@ -1,46 +1,41 @@ require 'stringio' module Log + def self.build_reference(key, value, indent, buffer) + buffer << "#{indent}#{key}(#{value});\n" + end - def self.build_reference(key, value, indent, buffer) - buffer << "#{indent}#{key}(#{value});\n" + def self.build_array(array, indent, buffer) + array.each do |item| + build(item, indent, buffer) if item.is_a? Hash end - - def self.build_array(array, indent, buffer) - array.each do |item| - if item.is_a? Hash - build(item, indent, buffer) - end - end - end - - def self.build(hash, indent, buffer) - indent = indent + ' ' - if hash.keys.length != 1 - return 'Error' - end - - key = hash.keys[0] - - value = hash[key] - - if value.is_a? String - build_reference(key, value, indent, buffer) - elsif value.is_a? Array - buffer << "#{indent}#{key} {\n" - build_array(value, indent, buffer) - buffer << "#{indent}};\n" - elsif value.is_a? Hash - buffer << "#{indent}Build error\n" - end - end - - def self.generate_log(options) - buffer = StringIO.new - indent = '' - buffer << "log {\n" - build_array(options, indent, buffer) - buffer << "};\n" - return buffer.string + end + + def self.build(hash, indent, buffer) + indent += ' ' + return 'Error' if hash.keys.length != 1 + + key = hash.keys[0] + + value = hash[key] + + if value.is_a? String + build_reference(key, value, indent, buffer) + elsif value.is_a? Array + buffer << "#{indent}#{key} {\n" + build_array(value, indent, buffer) + buffer << "#{indent}};\n" + elsif value.is_a? Hash + buffer << "#{indent}Build error\n" end + end + + def self.generate_log(options) + buffer = StringIO.new + indent = '' + buffer << "log {\n" + build_array(options, indent, buffer) + buffer << "};\n" + buffer.string + end end diff --git a/lib/puppet/parser/functions/statement.rb b/lib/puppet/parser/functions/statement.rb index 6b8f17b..2d01af5 100644 --- a/lib/puppet/parser/functions/statement.rb +++ b/lib/puppet/parser/functions/statement.rb @@ -1,310 +1,297 @@ +# rubocop:disable Style/AccessorMethodName, Style/ClassVars, Style/PredicateName module Statement - - # source s_name { .. }; - class Stment - def initialize(type, id, options=[]) - @type = type - @id = id - @options = options - end - - def add_option(option) - @options << option - end - - def build - header = Statement.getln("#{@type} #{@id} {") - Statement.increase_indent - - built_options = @options.map {|item| item.build} - - Statement.decrease_indent - tail = Statement.getln("};") - return header + built_options.join('') + tail - end + # source s_name { .. }; + class Stment + def initialize(type, id, options = []) + @type = type + @id = id + @options = options end - # flags( .. ) - class Parameter - def initialize() - @params = [] - end - - def build - end + def add_option(option) + @options << option end - # like the file name in a file source - class SimpleParameter < Parameter - def initialize(value='') - @value = value - end + def build + header = Statement.getln("#{@type} #{@id} {") + Statement.increase_indent - def value=(value) - @value = value - end + built_options = @options.map(&:build) - def build - return Statement.line(@value) - end + Statement.decrease_indent + tail = Statement.getln('};') + header + built_options.join('') + tail end + end - # like flags in a source - class TypedParameter < Parameter - def initialize(type='') - @type = type - @values = [] - end - - def type=(type) - @type = type - end - - def add_value(value) - @values << value - end + # flags( .. ) + class Parameter + def initialize + @params = [] + end - def build - header = Statement.getln("#{@type}(") - Statement.increase_indent + def build; end + end - built_values = @values.map {|item| item.build} + # like the file name in a file source + class SimpleParameter < Parameter + def initialize(value = '') + @value = value + end - Statement.decrease_indent - tail = Statement.line(")") + attr_writer :value - if @values.length >= 1 - return header + built_values.join(",\n") + "\n" + tail - else - return header + tail - end - end + def build + Statement.line(@value) end + end - class TypedParameterValue - def build - end + # like flags in a source + class TypedParameter < Parameter + def initialize(type = '') + @type = type + @values = [] end - # flags(no-parse): like no-parse - class TypedParameterSimpleValue < TypedParameterValue - def initialize(value=nil) - @value = value - end + attr_writer :type - def build - return Statement.line(@value) - end + def add_value(value) + @values << value end - # like tls in tcp source - class TypedParameterTypedValue < TypedParameterValue - def initialize(type='') - @type = type - @arguments = [] - end + def build + header = Statement.getln("#{@type}(") + Statement.increase_indent - def type=(type) - @type = type - end - - def add_argument(argument) - @arguments << argument - end + built_values = @values.map(&:build) - def build - header = Statement.getln("#{@type}(") - Statement.increase_indent + Statement.decrease_indent + tail = Statement.line(')') - built_args = @arguments.map {|item| item.build } - - Statement.decrease_indent - tail = Statement.line(")") - return header + built_args.join("") + "\n" + tail - end + if @values.length >= 1 + header + built_values.join(",\n") + "\n" + tail + else + header + tail + end end + end - # like a key_file parameter - class Argument - def initialize(value='') - @value = value - end + class TypedParameterValue + def build; end + end - def build - return Statement.line(@value) - end + # flags(no-parse): like no-parse + class TypedParameterSimpleValue < TypedParameterValue + def initialize(value = nil) + @value = value end - # source s { interna(); system(); };: like internal and system - class Option - def initialize(type='') - @type = type - @params = [] - end - - def set_type(type) - @type = type - end - - def add_parameter(parameter) - @params << parameter - end - - def build - header = Statement.getln("#{@type}(") - Statement.increase_indent - - built_params = @params.map {|item| item.build} - - Statement.decrease_indent - tail = Statement.getln(");") - return header + built_params.join(",\n") + "\n" + tail - end + def build + Statement.line(@value) end + end - @@indent = "" - @@indent_step = " " - @@current_statement = nil - @@current_option = nil - @@current_parameter = nil - @@current_parameter_value = nil - - def self.increase_indent() - @@indent += @@indent_step + # like tls in tcp source + class TypedParameterTypedValue < TypedParameterValue + def initialize(type = '') + @type = type + @arguments = [] end - def self.decrease_indent() - @@indent = @@indent[4..-1] - end + attr_writer :type - def self.get_indent() - return @@indent + def add_argument(argument) + @arguments << argument end - def self.getln(line) - return @@indent + "#{line}\n" - end + def build + header = Statement.getln("#{@type}(") + Statement.increase_indent - def self.line(line) - return @@indent + "#{line}" - end + built_args = @arguments.map(&:build) - def self.expand_one_key_hash(hash) - type = hash.keys[0] - value = hash[type] - return type, value + Statement.decrease_indent + tail = Statement.line(')') + header + built_args.join('') + "\n" + tail end + end - def self.parse_typed_parameter_typed_value(values) - type, value = expand_one_key_hash(values) - - # key_file => ... - @@current_parameter_value.type = type - - if is_simple_type?(value) - a = Argument.new(value) - @@current_parameter_value.add_argument(a) - elsif value.is_a? Array - value.each do |item| - # these should be strings or numbers or whatever simple types - a = Argument.new(item) - @@current_parameter_value.add_argument(a) - end - end + # like a key_file parameter + class Argument + def initialize(value = '') + @value = value end - def self.is_simple_type?(value) - return [String, Numeric].any? {|item| value.is_a? item} + def build + Statement.line(@value) end + end - def self.parse_typed_parameter(item) - type, value = expand_one_key_hash(item) - - @@current_parameter.type = type - - ## flags => 'no-parse' - if is_simple_type?(value) and value != '' - @@current_parameter_value = TypedParameterSimpleValue.new(value) - @@current_parameter.add_value(@@current_parameter_value) - # flags => ['something', 'no-parse'] - elsif value.is_a? Array - value.each do |item| - # 'no-parse' - if is_simple_type?(item) - @@current_parameter_value = TypedParameterSimpleValue.new(item) - @@current_parameter.add_value(@@current_parameter_value) - # { ... } - elsif item.is_a? Hash - @@current_parameter_value = TypedParameterTypedValue.new - parse_typed_parameter_typed_value(item) - @@current_parameter.add_value(@@current_parameter_value) - end - end - end + # source s { interna(); system(); };: like internal and system + class Option + def initialize(type = '') + @type = type + @params = [] end - def self.create_and_add_parameters(params) - params.each do |item| - if is_simple_type?(item) - @@current_parameter = SimpleParameter.new(item) - elsif item.is_a? Hash - @@current_parameter = TypedParameter.new - parse_typed_parameter(item) - end + def set_type(type) + @type = type + end - @@current_option.add_parameter(@@current_parameter) - end + def add_parameter(parameter) + @params << parameter end - def self.parse_option(option) - if option.has_key?('type') - type = option['type'] - params = option['options'] - @@current_option.set_type(type) + def build + header = Statement.getln("#{@type}(") + Statement.increase_indent - create_and_add_parameters(params) - else - type, params = expand_one_key_hash(option) - @@current_option.set_type(type) + built_params = @params.map(&:build) - create_and_add_parameters(params) - end + Statement.decrease_indent + tail = Statement.getln(');') + header + built_params.join(",\n") + "\n" + tail end - - def self.create_and_add_option(item) - @@current_option = Option.new() - parse_option(item) - @@current_statement.add_option(@@current_option) + end + + @@indent = '' + @@indent_step = ' ' + @@current_statement = nil + @@current_option = nil + @@current_parameter = nil + @@current_parameter_value = nil + + def self.increase_indent + @@indent += @@indent_step + end + + def self.decrease_indent + @@indent = @@indent[4..-1] + end + + def self.get_indent + @@indent + end + + def self.getln(line) + @@indent + "#{line}\n" + end + + def self.line(line) + @@indent + line.to_s + end + + def self.expand_one_key_hash(hash) + type = hash.keys[0] + value = hash[type] + [type, value] + end + + def self.parse_typed_parameter_typed_value(values) + type, value = expand_one_key_hash(values) + + # key_file => ... + @@current_parameter_value.type = type + + if is_simple_type?(value) + a = Argument.new(value) + @@current_parameter_value.add_argument(a) + elsif value.is_a? Array + value.each do |item| + # these should be strings or numbers or whatever simple types + a = Argument.new(item) + @@current_parameter_value.add_argument(a) + end end - - def self.parse_tree(options) - if options.is_a? Array - options.each do |item| - create_and_add_option(item) - end - elsif options.is_a? Hash - item = options - create_and_add_option(item) - else - raise Puppet::ParseError, "You must use a Hash or an Array as the parameter" + end + + def self.is_simple_type?(value) + [String, Numeric].any? { |item| value.is_a? item } + end + + def self.parse_typed_parameter(item) + type, value = expand_one_key_hash(item) + + @@current_parameter.type = type + + ## flags => 'no-parse' + if is_simple_type?(value) && value != '' + @@current_parameter_value = TypedParameterSimpleValue.new(value) + @@current_parameter.add_value(@@current_parameter_value) + # flags => ['something', 'no-parse'] + elsif value.is_a? Array + value.each do |value_item| + # 'no-parse' + if is_simple_type?(value_item) + @@current_parameter_value = TypedParameterSimpleValue.new(value_item) + @@current_parameter.add_value(@@current_parameter_value) + # { ... } + elsif value_item.is_a? Hash + @@current_parameter_value = TypedParameterTypedValue.new + parse_typed_parameter_typed_value(value_item) + @@current_parameter.add_value(@@current_parameter_value) end + end end - - def self.create_configuration_tree(id, type, options) - @@indent = "" - @@current_statement = Stment.new(type, id) - parse_tree(options) + end + + def self.create_and_add_parameters(params) + params.each do |item| + if is_simple_type?(item) + @@current_parameter = SimpleParameter.new(item) + elsif item.is_a? Hash + @@current_parameter = TypedParameter.new + parse_typed_parameter(item) + end + + @@current_option.add_parameter(@@current_parameter) end - - def self.render_configuration() - text_repr = @@current_statement.build - @@indent = "" - return text_repr + end + + def self.parse_option(option) + if option.key?('type') + type = option['type'] + params = option['options'] + else + type, params = expand_one_key_hash(option) end - - def self.generate_statement(id, type, options) - create_configuration_tree(id, type, options) - render_configuration() + @@current_option.set_type(type) + create_and_add_parameters(params) + end + + def self.create_and_add_option(item) + @@current_option = Option.new + parse_option(item) + @@current_statement.add_option(@@current_option) + end + + def self.parse_tree(options) + if options.is_a? Array + options.each do |item| + create_and_add_option(item) + end + elsif options.is_a? Hash + item = options + create_and_add_option(item) + else + raise Puppet::ParseError, 'You must use a Hash or an Array as the parameter' end + end + + def self.create_configuration_tree(id, type, options) + @@indent = '' + @@current_statement = Stment.new(type, id) + parse_tree(options) + end + + def self.render_configuration + text_repr = @@current_statement.build + @@indent = '' + text_repr + end + + def self.generate_statement(id, type, options) + create_configuration_tree(id, type, options) + render_configuration + end end - diff --git a/manifests/config.pp b/manifests/config.pp index d3d9920..a243b38 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -4,8 +4,8 @@ $order = '5' ) { concat::fragment { "syslog_ng::config ${title}": - target => $::syslog_ng::config_file, + target => $syslog_ng::config_file, content => "${content}\n", - order => $order + order => $order, } } diff --git a/manifests/destination.pp b/manifests/destination.pp index d433c47..1558259 100644 --- a/manifests/destination.pp +++ b/manifests/destination.pp @@ -7,8 +7,8 @@ $order = '70' concat::fragment { "syslog_ng::destination ${title}": - target => $::syslog_ng::config_file, + target => $syslog_ng::config_file, content => generate_statement($id, $type, $params), - order => $order + order => $order, } } diff --git a/manifests/filter.pp b/manifests/filter.pp index 3ddbd00..c98b65b 100644 --- a/manifests/filter.pp +++ b/manifests/filter.pp @@ -7,8 +7,8 @@ $order = '50' concat::fragment { "syslog_ng::filter ${title}": - target => $::syslog_ng::config_file, + target => $syslog_ng::config_file, content => generate_statement($id, $type, $params), - order => $order + order => $order, } } diff --git a/manifests/init.pp b/manifests/init.pp index 57981d4..8b69a16 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -18,7 +18,6 @@ $group = 'root', $syntax_check_before_reloads = true, ) { - validate_bool($syntax_check_before_reloads) validate_bool($manage_package) validate_bool($manage_init_defaults) @@ -32,10 +31,10 @@ ensure => $package_ensure, before => [ Concat[$config_file], - Exec[syslog_ng_reload] - ] + Exec['syslog_ng_reload'], + ], } - syslog_ng::module {$modules:} + syslog_ng::module { $modules: } } @concat { $config_file: @@ -47,30 +46,30 @@ ensure_newline => true, } - class {'syslog_ng::reload': - syntax_check_before_reloads => $syntax_check_before_reloads + class { 'syslog_ng::reload': + syntax_check_before_reloads => $syntax_check_before_reloads, } notice("config_file: ${config_file}") - concat::fragment {'syslog_ng header': + concat::fragment { 'syslog_ng header': target => $config_file, content => $config_file_header, - order => '01' + order => '01', } if $manage_init_defaults { $merged_init_config_hash = merge($init_config_hash,$init_config_hash) - file {$init_config_file: - ensure => present, + file { $init_config_file: + ensure => file, content => template('syslog_ng/init_config_file.erb'), - notify => Exec[syslog_ng_reload] + notify => Exec['syslog_ng_reload'], } } service { $service_name: - ensure => running, - enable => true, - require => Concat[$config_file] + ensure => running, + enable => true, + require => Concat[$config_file], } } diff --git a/manifests/log.pp b/manifests/log.pp index 089bb7c..40b73c4 100644 --- a/manifests/log.pp +++ b/manifests/log.pp @@ -4,8 +4,8 @@ ) { $order = '80' concat::fragment { "syslog_ng::log ${title}": - target => $::syslog_ng::config_file, + target => $syslog_ng::config_file, content => generate_log($params), - order => $order + order => $order, } } diff --git a/manifests/module.pp b/manifests/module.pp index 0a74f03..f8ef9d5 100644 --- a/manifests/module.pp +++ b/manifests/module.pp @@ -1,8 +1,8 @@ # define syslog_ng::module { - include ::syslog_ng - $module_prefix = $::syslog_ng::module_prefix + include syslog_ng + $module_prefix = $syslog_ng::module_prefix package { "${module_prefix}${title}": - ensure => $::syslog_ng::package_ensure + ensure => $syslog_ng::package_ensure, } } diff --git a/manifests/options.pp b/manifests/options.pp index 4015f12..af59732 100644 --- a/manifests/options.pp +++ b/manifests/options.pp @@ -5,8 +5,8 @@ $order = '10' concat::fragment { "syslog_ng::options ${title}": - target => $::syslog_ng::config_file, + target => $syslog_ng::config_file, content => generate_options($options), - order => $order + order => $order, } } diff --git a/manifests/parser.pp b/manifests/parser.pp index c73d6c4..fc7deab 100644 --- a/manifests/parser.pp +++ b/manifests/parser.pp @@ -7,8 +7,8 @@ $order = '40' concat::fragment { "syslog_ng::parser ${title}": - target => $::syslog_ng::config_file, + target => $syslog_ng::config_file, content => generate_statement($id, $type, $params), - order => $order + order => $order, } } diff --git a/manifests/reload.pp b/manifests/reload.pp index 4d4f9ae..b4e08a7 100644 --- a/manifests/reload.pp +++ b/manifests/reload.pp @@ -2,14 +2,13 @@ class syslog_ng::reload ( $syntax_check_before_reloads = true ) { - include syslog_ng - $config_file = $::syslog_ng::config_file + $config_file = $syslog_ng::config_file $exec_path = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:' - $syslog_ng_ctl_full_path = "${::syslog_ng::sbin_path}/syslog-ng-ctl" - $syslog_ng_full_path = "${::syslog_ng::sbin_path}/syslog-ng" + $syslog_ng_ctl_full_path = "${syslog_ng::sbin_path}/syslog-ng-ctl" + $syslog_ng_full_path = "${syslog_ng::sbin_path}/syslog-ng" $syslog_ng_syntax_check_cmd = "${syslog_ng_full_path} --syntax-only --cfgfile %" @@ -21,7 +20,7 @@ refreshonly => true, try_sleep => 1, logoutput => true, - require => Service[$::syslog_ng::service_name], + require => Service[$syslog_ng::service_name], } if $syntax_check_before_reloads { diff --git a/manifests/rewrite.pp b/manifests/rewrite.pp index 80a4d73..c13c00e 100644 --- a/manifests/rewrite.pp +++ b/manifests/rewrite.pp @@ -7,8 +7,8 @@ $order = '30' concat::fragment { "syslog_ng::rewrite ${title}": - target => $::syslog_ng::config_file, + target => $syslog_ng::config_file, content => generate_statement($id, $type, $params), - order => $order + order => $order, } } diff --git a/manifests/source.pp b/manifests/source.pp index dfae75b..bb05aa7 100644 --- a/manifests/source.pp +++ b/manifests/source.pp @@ -9,8 +9,8 @@ $order = '60' concat::fragment { "syslog_ng::source ${title}": - target => $::syslog_ng::config_file, + target => $syslog_ng::config_file, content => generate_statement($id, $type, $params), - order => $order + order => $order, } } diff --git a/manifests/template.pp b/manifests/template.pp index 8934442..035fb55 100644 --- a/manifests/template.pp +++ b/manifests/template.pp @@ -7,8 +7,8 @@ $order = '20' concat::fragment { "syslog_ng::template ${title}": - target => $::syslog_ng::config_file, + target => $syslog_ng::config_file, content => generate_statement($id, $type, $params), - order => $order + order => $order, } } diff --git a/metadata.json b/metadata.json index 048c67c..ee96c66 100644 --- a/metadata.json +++ b/metadata.json @@ -48,7 +48,7 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">=4.9.0 < 6.0.0" + "version_requirement": ">= 5.0.0 < 8.0.0" } ], "pdk-version": "1.10.0", diff --git a/smoke/OK_block.pp b/smoke/OK_block.pp index 5b4570d..8861dcc 100644 --- a/smoke/OK_block.pp +++ b/smoke/OK_block.pp @@ -1,6 +1,6 @@ # -class { 'syslog_ng': +class { 'syslog_ng': config_file => '/tmp/syslog-ng.conf', manage_package => false, syntax_check_before_reloads => false, @@ -11,19 +11,18 @@ syslog_ng::config { 'block foo': content => "block destination coloss(server()) - {network('`server`' transport(udp) port(514) flags(syslog-protocol))};" + {network('`server`' transport(udp) port(514) flags(syslog-protocol))};", } $_coloss_analyzers = ['a','b','c'] -$_coloss_analyzer_destinations = $_coloss_analyzers.map |$host| {{'coloss' => "server(${host})"}} +$_coloss_analyzer_destinations = $_coloss_analyzers.map |$host| { { 'coloss' => "server(${host})" } } puts($_coloss_analyzer_destinations) ::syslog_ng::log { 'd_check_elasticsearch_roundtrip': - params => flatten( - [ - {'source' => 's_check_elasticsearch_roundtrip'}, - {'rewrite' => 'r_sdata_smurf'}, - {'rewrite' => 'r_sdata_facter'}, - {'destination' => $_coloss_analyzer_destinations}, + params => flatten( [ + { 'source' => 's_check_elasticsearch_roundtrip' }, + { 'rewrite' => 'r_sdata_smurf' }, + { 'rewrite' => 'r_sdata_facter' }, + { 'destination' => $_coloss_analyzer_destinations }, #{'destination' => [{'coloss' => 'server(cc1)' }, {'coloss' => 'server(cc1)' }]}, ] ), diff --git a/smoke/OK_complex_destination.pp b/smoke/OK_complex_destination.pp index 67a602e..fcaf36e 100644 --- a/smoke/OK_complex_destination.pp +++ b/smoke/OK_complex_destination.pp @@ -1,4 +1,4 @@ -class { 'syslog_ng': +class { 'syslog_ng': config_file => '/tmp/syslog-ng.conf', manage_package => false, syntax_check_before_reloads => false, @@ -12,15 +12,14 @@ ::syslog_ng::destination { 'd_coloss': params => [ { 'syslog-ng' => flatten([ - { 'server' => "'${coloss_analyzer}'" }, - { 'failover' => [ - { 'servers' => $coloss_analyzers.map |$server| {"\"${server}\""} }, - { 'failback' => [ 'successful-probes-required(3)', 'tcp-probe-interval(5)' ] }, - ], - }, - { 'port' => 514 }, - $options]) + { 'server' => "'${coloss_analyzer}'" }, + { 'failover' => [ + { 'servers' => $coloss_analyzers.map |$server| { "\"${server}\"" } }, + { 'failback' => ['successful-probes-required(3)', 'tcp-probe-interval(5)'] }, + ], + }, + { 'port' => 514 }, + $options]) } - ] + ], } - diff --git a/smoke/OK_config.pp b/smoke/OK_config.pp index dc09bfb..d114b07 100644 --- a/smoke/OK_config.pp +++ b/smoke/OK_config.pp @@ -1,4 +1,4 @@ -class { 'syslog_ng': +class { 'syslog_ng': config_file => '/tmp/syslog-ng.conf', manage_package => false, syntax_check_before_reloads => false, @@ -7,15 +7,15 @@ manage_init_defaults => false, } -syslog_ng::config {'version': - content => '@version: 3.6', - order => '02' +syslog_ng::config { 'version': + content => '@version: 3.6', + order => '02', } $long_comment = '# Comment, # wich spawns over multiple lines # ' -syslog_ng::config {'long_comment': - content => $long_comment +syslog_ng::config { 'long_comment': + content => $long_comment, } diff --git a/smoke/OK_default_config.pp b/smoke/OK_default_config.pp index 975a928..59a56dd 100644 --- a/smoke/OK_default_config.pp +++ b/smoke/OK_default_config.pp @@ -1,4 +1,4 @@ -class { 'syslog_ng': +class { 'syslog_ng': config_file => '/tmp/syslog-ng.conf', manage_package => false, syntax_check_before_reloads => false, @@ -11,53 +11,51 @@ class syslog_ng::default_config { #lint:endignore - syslog_ng::config {'header comment': - content => ' + syslog_ng::config { 'header comment': + content => ' # Default syslog-ng.conf file which collects all local logs into a # single file called /var/log/messages. # - '} + ' } - syslog_ng::config {'version': - content => '@version: 3.6', - order => '03' - } + syslog_ng::config { 'version': + content => '@version: 3.6', + order => '03', + } - syslog_ng::source {'s_local': - params => [ - { - 'type' => 'system', - 'options' => '' - }, - { - 'type' => 'internal', - 'options' => '' - } - ] - } + syslog_ng::source { 's_local': + params => [ + { + 'type' => 'system', + 'options' => '' + }, + { + 'type' => 'internal', + 'options' => '' + }, + ], + } - syslog_ng::source {'s_local': - params => - { - 'type' => 'udp', - 'options' => '' - } - } + syslog_ng::source { 's_local': + params => { + 'type' => 'udp', + 'options' => '', + }, + } - syslog_ng::destination { 'd_local': - params => - { - 'type' => 'file', - 'options' => [ - '/var/log/messages' - ] - } - } + syslog_ng::destination { 'd_local': + params => { + 'type' => 'file', + 'options' => [ + '/var/log/messages', + ], + }, + } - syslog_ng::log { 'l': - params => [ - {'source' => 's_local'}, - {'destination' => 'd_local'} - ] - } + syslog_ng::log { 'l': + params => [ + { 'source' => 's_local' }, + { 'destination' => 'd_local' }, + ], + } } diff --git a/smoke/OK_destination.pp b/smoke/OK_destination.pp index 4ae3a13..95997e1 100644 --- a/smoke/OK_destination.pp +++ b/smoke/OK_destination.pp @@ -1,4 +1,4 @@ -class { 'syslog_ng': +class { 'syslog_ng': config_file => '/tmp/syslog-ng.conf', manage_package => false, syntax_check_before_reloads => false, @@ -8,13 +8,12 @@ } syslog_ng::destination { 'd_udp': - params => { - 'type' => 'udp', - 'options' => [ - "'127.0.0.1'", - {'port' => '1999'}, - {'localport' => '999'} - ] - } + params => { + 'type' => 'udp', + 'options' => [ + "'127.0.0.1'", + { 'port' => '1999' }, + { 'localport' => '999' }, + ], + }, } - diff --git a/smoke/OK_filter.pp b/smoke/OK_filter.pp index c8f93ff..76fb5c0 100644 --- a/smoke/OK_filter.pp +++ b/smoke/OK_filter.pp @@ -1,4 +1,4 @@ -class { 'syslog_ng': +class { 'syslog_ng': config_file => '/tmp/syslog-ng.conf', manage_package => false, syntax_check_before_reloads => false, @@ -7,19 +7,19 @@ manage_init_defaults => false, } -syslog_ng::filter {'f_tag_filter': - params => { - 'type' => 'tags', - 'options' => [ - '".classifier.system"' - ] - } +syslog_ng::filter { 'f_tag_filter': + params => { + 'type' => 'tags', + 'options' => [ + '".classifier.system"', + ], + }, } -syslog_ng::filter {'f_tag_filter_2': - params => { - 'tags' => [ - '".classifier.system"' - ] - } +syslog_ng::filter { 'f_tag_filter_2': + params => { + 'tags' => [ + '".classifier.system"', + ], + }, } diff --git a/smoke/OK_filter_2.pp b/smoke/OK_filter_2.pp index c8f93ff..76fb5c0 100644 --- a/smoke/OK_filter_2.pp +++ b/smoke/OK_filter_2.pp @@ -1,4 +1,4 @@ -class { 'syslog_ng': +class { 'syslog_ng': config_file => '/tmp/syslog-ng.conf', manage_package => false, syntax_check_before_reloads => false, @@ -7,19 +7,19 @@ manage_init_defaults => false, } -syslog_ng::filter {'f_tag_filter': - params => { - 'type' => 'tags', - 'options' => [ - '".classifier.system"' - ] - } +syslog_ng::filter { 'f_tag_filter': + params => { + 'type' => 'tags', + 'options' => [ + '".classifier.system"', + ], + }, } -syslog_ng::filter {'f_tag_filter_2': - params => { - 'tags' => [ - '".classifier.system"' - ] - } +syslog_ng::filter { 'f_tag_filter_2': + params => { + 'tags' => [ + '".classifier.system"', + ], + }, } diff --git a/smoke/OK_init.pp b/smoke/OK_init.pp index f470593..27a1628 100644 --- a/smoke/OK_init.pp +++ b/smoke/OK_init.pp @@ -10,7 +10,7 @@ # http://docs.puppetlabs.com/guides/tests_smoke.html # -class { 'syslog_ng': +class { 'syslog_ng': config_file => '/tmp/syslog-ng.conf', manage_package => false, syntax_check_before_reloads => false, diff --git a/smoke/OK_init_2.pp b/smoke/OK_init_2.pp index 68af4c4..37e5e89 100644 --- a/smoke/OK_init_2.pp +++ b/smoke/OK_init_2.pp @@ -10,12 +10,12 @@ # http://docs.puppetlabs.com/guides/tests_smoke.html # -class { 'syslog_ng': +class { 'syslog_ng': config_file => '/tmp/syslog-ng.conf', manage_package => false, syntax_check_before_reloads => false, user => 'fwernli', group => 'fwernli', manage_init_defaults => false, - package_name => 'syslog-ng' + package_name => 'syslog-ng', } diff --git a/smoke/OK_log.pp b/smoke/OK_log.pp index e6b6f7d..2579e35 100644 --- a/smoke/OK_log.pp +++ b/smoke/OK_log.pp @@ -1,4 +1,4 @@ -class { 'syslog_ng': +class { 'syslog_ng': config_file => '/tmp/syslog-ng.conf', manage_package => false, syntax_check_before_reloads => false, @@ -7,9 +7,9 @@ manage_init_defaults => false, } -syslog_ng::log {'l': - params => [ - {'source' => 's_external'}, - {'destination' => 'd_udp'} - ] +syslog_ng::log { 'l': + params => [ + { 'source' => 's_external' }, + { 'destination' => 'd_udp' }, + ], } diff --git a/smoke/OK_log_02.pp b/smoke/OK_log_02.pp index 791ed74..94c0f3e 100644 --- a/smoke/OK_log_02.pp +++ b/smoke/OK_log_02.pp @@ -1,4 +1,4 @@ -class { 'syslog_ng': +class { 'syslog_ng': config_file => '/tmp/syslog-ng.conf', manage_package => false, syntax_check_before_reloads => false, @@ -7,22 +7,25 @@ manage_init_defaults => false, } -syslog_ng::log {'l2': - params => [ - {'source' => 's_gsoc2014'}, - {'junction' => [ - { - 'channel' => [ - {'filter' => 'f_json'}, - {'parser' => 'p_json'} - ]}, - { - 'channel' => [ - {'filter' => 'f_not_json'}, - {'flags' => 'final'} - ]} - ] +syslog_ng::log { 'l2': + params => [ + { 'source' => 's_gsoc2014' }, + { + 'junction' => [ + { + 'channel' => [ + { 'filter' => 'f_json' }, + { 'parser' => 'p_json' }, + ], }, - {'destination' => 'd_gsoc'} - ] + { + 'channel' => [ + { 'filter' => 'f_not_json' }, + { 'flags' => 'final' }, + ], + }, + ], + }, + { 'destination' => 'd_gsoc' } + ], } diff --git a/smoke/OK_options.pp b/smoke/OK_options.pp index b833b7f..b4e1ed6 100644 --- a/smoke/OK_options.pp +++ b/smoke/OK_options.pp @@ -1,4 +1,4 @@ -class { 'syslog_ng': +class { 'syslog_ng': config_file => '/tmp/syslog-ng.conf', manage_package => false, syntax_check_before_reloads => false, @@ -8,8 +8,8 @@ } syslog_ng::options { 'global_options': - options => { - 'bad_hostname' => "'no'", - 'time_reopen' => 10 - } + options => { + 'bad_hostname' => "'no'", + 'time_reopen' => 10, + }, } diff --git a/smoke/OK_parser.pp b/smoke/OK_parser.pp index be1143c..a745695 100644 --- a/smoke/OK_parser.pp +++ b/smoke/OK_parser.pp @@ -1,4 +1,4 @@ -class { 'syslog_ng': +class { 'syslog_ng': config_file => '/tmp/syslog-ng.conf', manage_package => false, syntax_check_before_reloads => false, @@ -7,20 +7,21 @@ manage_init_defaults => false, } -syslog_ng::parser {'p_hostname_segmentation': - params => { - 'type' => 'csv-parser', - 'options' => [ - {'columns' => [ - '"HOSTNAME.NAME"', - '"HOSTNAME.ID"' - ]}, - {'delimiters' => '"-"'}, - {'flags' => 'escape-none'}, +syslog_ng::parser { 'p_hostname_segmentation': + params => { + 'type' => 'csv-parser', + 'options' => [ + { + 'columns' => [ + '"HOSTNAME.NAME"', + '"HOSTNAME.ID"', + ], + }, + { 'delimiters' => '"-"' }, + { 'flags' => 'escape-none' }, #lint:ignore:single_quote_string_with_variables - {'template' => '"${HOST}"'} + { 'template' => '"${HOST}"' } #lint:endignore - ] - } + ], + }, } - diff --git a/smoke/OK_rewrite.pp b/smoke/OK_rewrite.pp index ca7b6f6..c32e837 100644 --- a/smoke/OK_rewrite.pp +++ b/smoke/OK_rewrite.pp @@ -1,4 +1,4 @@ -class { 'syslog_ng': +class { 'syslog_ng': config_file => '/tmp/syslog-ng.conf', manage_package => false, syntax_check_before_reloads => false, @@ -7,15 +7,14 @@ manage_init_defaults => false, } -syslog_ng::rewrite{'r_rewrite_subst': - params => { - 'type' => 'subst', - 'options' => [ - '"IP"', - '"IP-Address"', - {'value' => '"MESSAGE"'}, - {'flags' => 'global'} - ] - } +syslog_ng::rewrite { 'r_rewrite_subst': + params => { + 'type' => 'subst', + 'options' => [ + '"IP"', + '"IP-Address"', + { 'value' => '"MESSAGE"' }, + { 'flags' => 'global' }, + ], + }, } - diff --git a/smoke/OK_site.pp b/smoke/OK_site.pp index c74725a..8f75279 100644 --- a/smoke/OK_site.pp +++ b/smoke/OK_site.pp @@ -1,4 +1,4 @@ -class { 'syslog_ng': +class { 'syslog_ng': config_file => '/tmp/syslog-ng.conf', manage_package => false, syntax_check_before_reloads => false, @@ -8,15 +8,15 @@ } # the header written by this module has order == 1, so the version must be 02 -syslog_ng::config {'version': - content => '@version: 3.6', - order => '02' +syslog_ng::config { 'version': + content => '@version: 3.6', + order => '02', } syslog_ng::options { 'global_options': options => { - 'bad_hostname' => "'no'" - } + 'bad_hostname' => "'no'", + }, } syslog_ng::source { 's_gsoc': @@ -24,52 +24,52 @@ 'type' => 'tcp', 'options' => { 'ip' => "'127.0.0.1'", - 'port' => 1999 - } - } + 'port' => 1999, + }, + }, } -syslog_ng::source {'s_external': - params => [ - { 'type' => 'udp', - 'options' => [ - {'ip' => ["'127.0.0.1'"]}, - {'port' => [514]} - ] - }, - { 'type' => 'tcp', - 'options' => [ - {'ip' => ["'127.0.0.1'"]}, - {'port' => [514]} - ] - }, - { - 'type' => 'syslog', - 'options' => [ - {'flags' => ['no-multi-line', 'no-parse']}, - {'ip' => ["'127.0.0.1'"]}, - {'keep-alive' => ['yes']}, - {'keep_hostname' => ['yes']}, - {'transport' => ['udp']} - ] - } - ] +syslog_ng::source { 's_external': + params => [ + { 'type' => 'udp', + 'options' => [ + { 'ip' => ["'127.0.0.1'"] }, + { 'port' => [514] } + ] + }, + { 'type' => 'tcp', + 'options' => [ + { 'ip' => ["'127.0.0.1'"] }, + { 'port' => [514] } + ] + }, + { + 'type' => 'syslog', + 'options' => [ + { 'flags' => ['no-multi-line', 'no-parse'] }, + { 'ip' => ["'127.0.0.1'"] }, + { 'keep-alive' => ['yes'] }, + { 'keep_hostname' => ['yes'] }, + { 'transport' => ['udp'] } + ] + } + ], } syslog_ng::destination { 'd_udp': - params => { - 'type' => 'udp', - 'options' => [ - "'127.0.0.1'", - {'port' => '1999'}, - {'localport' => '999'} - ] - } + params => { + 'type' => 'udp', + 'options' => [ + "'127.0.0.1'", + { 'port' => '1999' }, + { 'localport' => '999' }, + ], + }, } -syslog_ng::log {'l': - params => [ - {'source' => 's_external'}, - {'destination' => 'd_udp'} - ] +syslog_ng::log { 'l': + params => [ + { 'source' => 's_external' }, + { 'destination' => 'd_udp' }, + ], } diff --git a/smoke/OK_source.pp b/smoke/OK_source.pp index 79f8895..8ff7619 100644 --- a/smoke/OK_source.pp +++ b/smoke/OK_source.pp @@ -1,4 +1,4 @@ -class { 'syslog_ng': +class { 'syslog_ng': config_file => '/tmp/syslog-ng.conf', manage_package => false, syntax_check_before_reloads => false, @@ -8,50 +8,49 @@ } syslog_ng::source { 's_gsoc': - params => { - 'type' => 'tcp', - 'options' => [ - { 'ip' => "'127.0.0.1'" }, - { 'port' => 1999 } - ] - } + params => { + 'type' => 'tcp', + 'options' => [ + { 'ip' => "'127.0.0.1'" }, + { 'port' => 1999 }, + ], + }, } -syslog_ng::source {'s_external': - params => [ - { 'type' => 'udp', - 'options' => [ - {'ip' => ["'127.0.0.1'"]}, - {'port' => [514]} - ] - }, - { 'type' => 'tcp', - 'options' => [ - {'ip' => ["'127.0.0.1'"]}, - {'port' => [514]} - ] - }, - { - 'type' => 'syslog', - 'options' => [ - {'flags' => ['no-multi-line', 'no-parse']}, - {'ip' => ["'127.0.0.1'"]}, - {'keep-alive' => ['yes']}, - {'keep_hostname' => ['yes']}, - {'transport' => ['udp']} - ] - }, - { - 'tcp' => [ - {'ip' => ["'127.0.0.1'"]}, - {'port' => [514]}, - {'tls' => [ - {'key_file' => ['"/opt/syslog-ng/etc/syslog-ng/key.d/syslog-ng.key"']}, - {'cert_file'=> '"/opt/syslog-ng/etc/syslog-ng/cert.d/syslog-ng.cert"'}, - {'peer_verify' => 'optional-untrusted'} - ]} - ] - } - ] +syslog_ng::source { 's_external': + params => [ + { 'type' => 'udp', + 'options' => [ + { 'ip' => ["'127.0.0.1'"] }, + { 'port' => [514] } + ] + }, + { 'type' => 'tcp', + 'options' => [ + { 'ip' => ["'127.0.0.1'"] }, + { 'port' => [514] } + ] + }, + { + 'type' => 'syslog', + 'options' => [ + { 'flags' => ['no-multi-line', 'no-parse'] }, + { 'ip' => ["'127.0.0.1'"] }, + { 'keep-alive' => ['yes'] }, + { 'keep_hostname' => ['yes'] }, + { 'transport' => ['udp'] } + ] + }, + { + 'tcp' => [ + { 'ip' => ["'127.0.0.1'"] }, + { 'port' => [514] }, + { 'tls' => [ + { 'key_file' => ['"/opt/syslog-ng/etc/syslog-ng/key.d/syslog-ng.key"'] }, + { 'cert_file'=> '"/opt/syslog-ng/etc/syslog-ng/cert.d/syslog-ng.cert"' }, + { 'peer_verify' => 'optional-untrusted' } + ] } + ] + } + ], } - diff --git a/smoke/OK_template.pp b/smoke/OK_template.pp index e75e0aa..ba666ff 100644 --- a/smoke/OK_template.pp +++ b/smoke/OK_template.pp @@ -1,4 +1,4 @@ -class { 'syslog_ng': +class { 'syslog_ng': config_file => '/tmp/syslog-ng.conf', manage_package => false, syntax_check_before_reloads => false, @@ -7,19 +7,19 @@ manage_init_defaults => false, } -syslog_ng::template {'t_demo_filetemplate': - params => [ - { - 'type' => 'template', - 'options' => [ - '"$ISODATE $HOST $MSG\n"' - ] - }, - { - 'type' => 'template_escape', - 'options' => [ - 'no' - ] - } - ] +syslog_ng::template { 't_demo_filetemplate': + params => [ + { + 'type' => 'template', + 'options' => [ + '"$ISODATE $HOST $MSG\n"', + ], + }, + { + 'type' => 'template_escape', + 'options' => [ + 'no', + ] + } + ], } diff --git a/smoke/hpss.pp b/smoke/hpss.pp index 2cb6034..fde1726 100644 --- a/smoke/hpss.pp +++ b/smoke/hpss.pp @@ -1,4 +1,4 @@ -class { 'syslog_ng': +class { 'syslog_ng': config_file => '/tmp/syslog-ng.conf', manage_package => false, syntax_check_before_reloads => false, @@ -9,6 +9,6 @@ syslog_ng::rewrite { 'r_truncate': params => [ - { 'set' => ['"$(substr ${MSG} 0 14400))"'] } - ] + { 'set' => ['"$(substr ${MSG} 0 14400))"'] } + ], } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 243d437..99e8a17 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,25 +1,28 @@ require 'spec_helper' describe 'syslog_ng' do - - let(:facts) {{ concat_basedir: '/dne', - osfamily: 'Debian', - os: { family: 'Debian', name: 'Ubuntu', release: { full: '14.04', major: '14.04' } }, - operatingsystem: 'Ubuntu' - }} + let(:facts) do + { concat_basedir: '/dne', + osfamily: 'Debian', + os: { family: 'Debian', name: 'Ubuntu', release: { full: '14.04', major: '14.04' }, distro: { codename: 'trusty' } }, + operatingsystem: 'Ubuntu' } + end context 'With not default params' do - let(:params) {{ - :config_file => '/tmp/puppet-test/syslog-ng.conf', - :sbin_path => '/home/tibi/install/syslog-ng', - :manage_init_defaults => true - }} + let(:params) do + { + config_file: '/tmp/puppet-test/syslog-ng.conf', + sbin_path: '/home/tibi/install/syslog-ng', + manage_init_defaults: true + } + end + it { - should contain_package('syslog-ng-core') - should contain_service('syslog-ng') + is_expected.to contain_package('syslog-ng-core') + is_expected.to contain_service('syslog-ng') } it { - should contain_file('/etc/default/syslog-ng') + is_expected.to contain_file('/etc/default/syslog-ng') } end @@ -30,27 +33,31 @@ } end - it { should compile } - it { should contain_apt__source('syslog-ng-obs') } + it { is_expected.to compile } + it { is_expected.to contain_apt__source('syslog-ng-obs') } end context 'On RedHat' do - let(:facts) {{ concat_basedir: '/dne', - osfamily: 'RedHat', - os: { family: 'RedHat', name: 'RedHat', release: { major: '7' } }, - operatingsystem: 'RedHat' - }} + let(:facts) do + { concat_basedir: '/dne', + osfamily: 'RedHat', + os: { family: 'RedHat', name: 'RedHat', release: { major: '7' } }, + operatingsystem: 'RedHat' } + end context 'with init_defaults set to true' do - let(:params) {{ - :manage_init_defaults => true - }} + let(:params) do + { + manage_init_defaults: true + } + end + it { - should contain_package('syslog-ng') - should contain_service('syslog-ng') + is_expected.to contain_package('syslog-ng') + is_expected.to contain_service('syslog-ng') } it { - should contain_file('/etc/sysconfig/syslog-ng') + is_expected.to contain_file('/etc/sysconfig/syslog-ng') } end @@ -61,61 +68,77 @@ } end - it { should compile } - it { should contain_yumrepo('czanik-syslog-ng-githead') } + it { is_expected.to compile } + it { is_expected.to contain_yumrepo('czanik-syslog-ng-githead') } end end context 'On SLES with init_defaults set to true' do - let(:params) {{ - :manage_init_defaults => true - }} - let(:facts) {{ concat_basedir: '/dne', - osfamily: 'Suse', - os: { family: 'Suse' }, - operatingsystem: 'SLES' - }} + let(:params) do + { + manage_init_defaults: true + } + end + let(:facts) do + { concat_basedir: '/dne', + osfamily: 'Suse', + os: { family: 'Suse' }, + operatingsystem: 'SLES' } + end + it { - should contain_package('syslog-ng') - should contain_service('syslog-ng') + is_expected.to contain_package('syslog-ng') + is_expected.to contain_service('syslog-ng') } it { - should contain_file('/etc/sysconfig/syslog-ng') + is_expected.to contain_file('/etc/sysconfig/syslog-ng') } end context 'When asked not to manage package' do - let(:params) {{ - :manage_package => false - }} - it { should_not contain_package('syslog-ng-core') } + let(:params) do + { + manage_package: false + } + end + + it { is_expected.not_to contain_package('syslog-ng-core') } end context 'When asked to use additional module' do - let(:params) {{ - :modules => [ 'foo', 'bar', 'baz' ] - }} + let(:params) do + { + modules: %w[foo bar baz] + } + end + it { - should contain_syslog_ng__module('foo') - should contain_syslog_ng__module('bar') - should contain_syslog_ng__module('baz') + is_expected.to contain_syslog_ng__module('foo') + is_expected.to contain_syslog_ng__module('bar') + is_expected.to contain_syslog_ng__module('baz') } end context 'When config changes' do it { - should contain_concat('/etc/syslog-ng/syslog-ng.conf').that_notifies('Exec[syslog_ng_reload]') + is_expected.to contain_concat('/etc/syslog-ng/syslog-ng.conf').that_notifies('Exec[syslog_ng_reload]') } context 'and asked to check syntax before reload' do - let(:params) {{ - :syntax_check_before_reloads => true - }} + let(:params) do + { + syntax_check_before_reloads: true + } + end + it { - should contain_concat('/etc/syslog-ng/syslog-ng.conf').with_validate_cmd(/syntax-only/) + is_expected.to contain_concat('/etc/syslog-ng/syslog-ng.conf').with_validate_cmd(/syntax-only/) } end context 'and asked not to check syntax before reload' do - let(:params) {{ - :syntax_check_before_reloads => false - }} + let(:params) do + { + syntax_check_before_reloads: false + } + end + it { - should contain_concat('/etc/syslog-ng/syslog-ng.conf').without_validate_cmd + is_expected.to contain_concat('/etc/syslog-ng/syslog-ng.conf').without_validate_cmd } end end diff --git a/spec/defines/config_spec.rb b/spec/defines/config_spec.rb index 957086a..04279fa 100644 --- a/spec/defines/config_spec.rb +++ b/spec/defines/config_spec.rb @@ -1,9 +1,9 @@ if RUBY_VERSION >= '1.9.2' - require_relative 'statement' + require_relative 'statement' else - require File.join(File.expand_path(File.dirname(__FILE__)), './statement') + require File.join(File.expand_path(File.dirname(__FILE__)), './statement') end -describe "syslog_ng::destination" do - it_behaves_like "Statement", 'id', 'destination' +describe 'syslog_ng::destination' do + it_behaves_like 'Statement', 'id', 'destination' end diff --git a/spec/defines/destination_spec.rb b/spec/defines/destination_spec.rb index 957086a..04279fa 100644 --- a/spec/defines/destination_spec.rb +++ b/spec/defines/destination_spec.rb @@ -1,9 +1,9 @@ if RUBY_VERSION >= '1.9.2' - require_relative 'statement' + require_relative 'statement' else - require File.join(File.expand_path(File.dirname(__FILE__)), './statement') + require File.join(File.expand_path(File.dirname(__FILE__)), './statement') end -describe "syslog_ng::destination" do - it_behaves_like "Statement", 'id', 'destination' +describe 'syslog_ng::destination' do + it_behaves_like 'Statement', 'id', 'destination' end diff --git a/spec/defines/filter_spec.rb b/spec/defines/filter_spec.rb index df4f1d8..64e423c 100644 --- a/spec/defines/filter_spec.rb +++ b/spec/defines/filter_spec.rb @@ -1,9 +1,9 @@ if RUBY_VERSION >= '1.9.2' - require_relative 'statement' + require_relative 'statement' else - require File.join(File.expand_path(File.dirname(__FILE__)), './statement') + require File.join(File.expand_path(File.dirname(__FILE__)), './statement') end -describe "syslog_ng::filter" do - it_behaves_like "Statement", 'id', 'filter' +describe 'syslog_ng::filter' do + it_behaves_like 'Statement', 'id', 'filter' end diff --git a/spec/defines/log_spec.rb b/spec/defines/log_spec.rb index 633cd62..9530c99 100644 --- a/spec/defines/log_spec.rb +++ b/spec/defines/log_spec.rb @@ -1,9 +1,9 @@ if RUBY_VERSION >= '1.9.2' - require_relative 'statement' + require_relative 'statement' else - require File.join(File.expand_path(File.dirname(__FILE__)), './statement') + require File.join(File.expand_path(File.dirname(__FILE__)), './statement') end -describe "syslog_ng::log" do - it_behaves_like "Statement", 'id', 'log' +describe 'syslog_ng::log' do + it_behaves_like 'Statement', 'id', 'log' end diff --git a/spec/defines/module_spec.rb b/spec/defines/module_spec.rb index 7c9cba7..5901da6 100644 --- a/spec/defines/module_spec.rb +++ b/spec/defines/module_spec.rb @@ -1,56 +1,62 @@ require 'spec_helper' -describe 'syslog_ng::module', :type => 'define' do - let :title do +describe 'syslog_ng::module', type: 'define' do + let :title do 'foo' end - let :default_facts do { - :concat_basedir => '/tmp/concat-basedir' - } end + let :default_facts do + { + concat_basedir: '/tmp/concat-basedir' + } + end let :facts do - default_facts.merge( - { osfamily: 'Debian', os: { family: 'Debian', name: 'Ubuntu', release: { full: '14.4', major: '14.4' } } } - ) + default_facts.merge( + { osfamily: 'Debian', os: { family: 'Debian', name: 'Ubuntu', release: { full: '14.4', major: '14.4' } } }, + ) end - context "When overriding module_prefix" do + + context 'When overriding module_prefix' do let :pre_condition do 'class { syslog_ng: module_prefix => "MODPREFIX_" }' end - it { should compile } - it { should contain_package('MODPREFIX_foo').with_ensure('present') } + + it { is_expected.to compile } + it { is_expected.to contain_package('MODPREFIX_foo').with_ensure('present') } end - context "When osfamily is RedHat" do + context 'When osfamily is RedHat' do let :facts do default_facts.merge( - { osfamily: 'RedHat', os: { family: 'RedHat', release: { major: '7' } } } + { osfamily: 'RedHat', os: { family: 'RedHat', release: { major: '7' } } }, ) end let :pre_condition do 'include syslog_ng' end - it { should compile } - it { should contain_package('syslog-ng-foo').with_ensure('present') } + + it { is_expected.to compile } + it { is_expected.to contain_package('syslog-ng-foo').with_ensure('present') } end - context "When osfamily is Debian" do - context "with defaults" do + context 'When osfamily is Debian' do + context 'with defaults' do let :pre_condition do 'include syslog_ng' end - it { should compile } - it { should contain_package('syslog-ng-mod-foo').with_ensure('present') } + + it { is_expected.to compile } + it { is_expected.to contain_package('syslog-ng-mod-foo').with_ensure('present') } end end - context "When osfamily is Suse" do + context 'When osfamily is Suse' do let :facts do default_facts.merge( - { osfamily: 'Suse', os: { family: 'Suse' } } + { osfamily: 'Suse', os: { family: 'Suse' } }, ) end let :pre_condition do 'include syslog_ng' end - it { should compile } - it { should contain_package('syslog-ng-foo').with_ensure('present') } + + it { is_expected.to compile } + it { is_expected.to contain_package('syslog-ng-foo').with_ensure('present') } end end - diff --git a/spec/defines/options_spec.rb b/spec/defines/options_spec.rb index bd4ccd8..0d60409 100644 --- a/spec/defines/options_spec.rb +++ b/spec/defines/options_spec.rb @@ -1,9 +1,9 @@ if RUBY_VERSION >= '1.9.2' - require_relative 'statement' + require_relative 'statement' else - require File.join(File.expand_path(File.dirname(__FILE__)), './statement') + require File.join(File.expand_path(File.dirname(__FILE__)), './statement') end -describe "syslog_ng::options" do - it_behaves_like "Statement", 'id', 'options' +describe 'syslog_ng::options' do + it_behaves_like 'Statement', 'id', 'options' end diff --git a/spec/defines/parser_spec.rb b/spec/defines/parser_spec.rb index 86fff20..cd91620 100644 --- a/spec/defines/parser_spec.rb +++ b/spec/defines/parser_spec.rb @@ -1,9 +1,9 @@ if RUBY_VERSION >= '1.9.2' - require_relative 'statement' + require_relative 'statement' else - require File.join(File.expand_path(File.dirname(__FILE__)), './statement') + require File.join(File.expand_path(File.dirname(__FILE__)), './statement') end -describe "syslog_ng::parser" do - it_behaves_like "Statement", 'id', 'parser' +describe 'syslog_ng::parser' do + it_behaves_like 'Statement', 'id', 'parser' end diff --git a/spec/defines/rewrite_spec.rb b/spec/defines/rewrite_spec.rb index 3db80da..e36edae 100644 --- a/spec/defines/rewrite_spec.rb +++ b/spec/defines/rewrite_spec.rb @@ -1,9 +1,9 @@ if RUBY_VERSION >= '1.9.2' - require_relative 'statement' + require_relative 'statement' else - require File.join(File.expand_path(File.dirname(__FILE__)), './statement') + require File.join(File.expand_path(File.dirname(__FILE__)), './statement') end -describe "syslog_ng::rewrite" do - it_behaves_like "Statement", 'id', 'rewrite' +describe 'syslog_ng::rewrite' do + it_behaves_like 'Statement', 'id', 'rewrite' end diff --git a/spec/defines/source_spec.rb b/spec/defines/source_spec.rb index fef3cd9..27e15fd 100644 --- a/spec/defines/source_spec.rb +++ b/spec/defines/source_spec.rb @@ -1,9 +1,9 @@ if RUBY_VERSION >= '1.9.2' - require_relative 'statement' + require_relative 'statement' else - require File.join(File.expand_path(File.dirname(__FILE__)), './statement') + require File.join(File.expand_path(File.dirname(__FILE__)), './statement') end -describe "syslog_ng::source" do - it_behaves_like "Statement", 'id', 'source' +describe 'syslog_ng::source' do + it_behaves_like 'Statement', 'id', 'source' end diff --git a/spec/defines/statement.rb b/spec/defines/statement.rb index 70aadb0..b89a43d 100644 --- a/spec/defines/statement.rb +++ b/spec/defines/statement.rb @@ -1,15 +1,17 @@ -shared_examples_for "Statement" do |id, type| - let(:facts) { { concat_basedir: '/dne', - osfamily: 'Debian', - os: { family: 'Debian', name: 'Ubuntu', release: { full: '14.04', major: '14.04' } }, - operatingsystem: 'Ubuntu' } } +shared_examples_for 'Statement' do |id, type| + let(:facts) do + { concat_basedir: '/dne', + osfamily: 'Debian', + os: { family: 'Debian', name: 'Ubuntu', release: { full: '14.04', major: '14.04' } }, + operatingsystem: 'Ubuntu' } + end - let(:pre_condition) { 'include syslog_ng' } - let(:title) { id } - let(:type) { type } - let(:options) {{}} - - it do - should contain_concat__fragment("syslog_ng::"+type+" "+title) - end + let(:pre_condition) { 'include syslog_ng' } + let(:title) { id } + let(:type) { type } + let(:options) { {} } + + it do + is_expected.to contain_concat__fragment('syslog_ng::' + type + ' ' + title) + end end diff --git a/spec/defines/template_spec.rb b/spec/defines/template_spec.rb index f4b993e..eeae0e5 100644 --- a/spec/defines/template_spec.rb +++ b/spec/defines/template_spec.rb @@ -1,9 +1,9 @@ if RUBY_VERSION >= '1.9.2' - require_relative 'statement' + require_relative 'statement' else - require File.join(File.expand_path(File.dirname(__FILE__)), './statement') + require File.join(File.expand_path(File.dirname(__FILE__)), './statement') end -describe "syslog_ng::template" do - it_behaves_like "Statement", 'id', 'template' +describe 'syslog_ng::template' do + it_behaves_like 'Statement', 'id', 'template' end diff --git a/spec/functions/generate_log_spec.rb b/spec/functions/generate_log_spec.rb index 2a41527..df3d433 100644 --- a/spec/functions/generate_log_spec.rb +++ b/spec/functions/generate_log_spec.rb @@ -1,71 +1,75 @@ require 'spec_helper' describe 'generate_log' do - - context "With simple options" do - let(:title) { 's_gsoc' } - let(:options) { [ - {'source' => 's_gsoc2014'}, - {'destination' => 'd_gsoc'} - ] - } - let(:expected) { -'log { - source(s_gsoc2014); - destination(d_gsoc); -}; -' } - it 'Should generate a flat log' do - result = scope.function_generate_log([options]) - expect(result).to be_a String - expect(result).to eq expected - end + context 'With simple options' do + let(:title) { 's_gsoc' } + let(:options) do + [ + { 'source' => 's_gsoc2014' }, + { 'destination' => 'd_gsoc' } + ] end - - context "With simple options" do - let(:title) { 's_gsoc' } - let(:options) { [ - {'source' => 's_gsoc2014'}, - {'junction' => [ - { - 'channel' => [ - {'filter' => 'f_json'}, - {'parser' => 'p_json'} - ] - }, - { - 'channel' => [ - {'filter' => 'f_not_json'}, - {'flags' => 'final'} - ] - } - ] - }, - {'destination' => 'd_gsoc'} - ] } - let(:expected) { -'log { - source(s_gsoc2014); - junction { - channel { - filter(f_json); - parser(p_json); - }; - channel { - filter(f_not_json); - flags(final); - }; - }; - destination(d_gsoc); -}; -' } - it 'Should generate a complex log' do - result = scope.function_generate_log([options]) - expect(result).to be_a String - expect(result).to eq expected - end + let(:expected) do + <<~EOT + log { + source(s_gsoc2014); + destination(d_gsoc); + }; + EOT end + it 'generates a flat log' do + result = scope.function_generate_log([options]) + expect(result).to be_a String + expect(result).to eq expected + end + end + context 'With simple options' do + let(:title) { 's_gsoc' } + let(:options) do + [ + { 'source' => 's_gsoc2014' }, + { 'junction' => [ + { + 'channel' => [ + { 'filter' => 'f_json' }, + { 'parser' => 'p_json' } + ] + }, + { + 'channel' => [ + { 'filter' => 'f_not_json' }, + { 'flags' => 'final' } + ] + } + ] }, + { 'destination' => 'd_gsoc' } + ] + end + let(:expected) do + <<~EOT + log { + source(s_gsoc2014); + junction { + channel { + filter(f_json); + parser(p_json); + }; + channel { + filter(f_not_json); + flags(final); + }; + }; + destination(d_gsoc); + }; + EOT + end + it 'generates a complex log' do + result = scope.function_generate_log([options]) + expect(result).to be_a String + expect(result).to eq expected + end + end end diff --git a/spec/functions/generate_options_spec.rb b/spec/functions/generate_options_spec.rb index 0c0e408..9c537c1 100644 --- a/spec/functions/generate_options_spec.rb +++ b/spec/functions/generate_options_spec.rb @@ -1,34 +1,32 @@ require 'spec_helper' describe 'generate_options' do + context 'With options' do + let(:params) do + { 'log_fifo_size' => 2048, + 'create_dirs' => 'yes' } + end + let(:expected) do + <<~EOT + options { + create_dirs(yes); + log_fifo_size(2048); + }; + EOT + end - context "With options" do - let(:params) {{ 'log_fifo_size' => 2048, - 'create_dirs' => 'yes'}} - let(:expected) { -"options { - create_dirs(yes); - log_fifo_size(2048); -}; -" - - } - - it 'Should fill the options statement' do + it 'fills the options statement' do result = scope.function_generate_options([params]) expect(result).to be_a String expect(result).to eq expected end end - context "Without options" do - - it "Should generate nothing" do + context 'Without options' do + it 'generates nothing' do result = scope.function_generate_options([{}]) expect(result).to be_a String - expect(result).to eq "" + expect(result).to eq '' end - end - end diff --git a/spec/functions/generate_statement_spec.rb b/spec/functions/generate_statement_spec.rb index 6170471..ed27d34 100644 --- a/spec/functions/generate_statement_spec.rb +++ b/spec/functions/generate_statement_spec.rb @@ -1,213 +1,227 @@ require 'spec_helper' describe 'generate_statement' do + let(:title) { 'r_name' } + let(:type) { 'rewrite' } + let(:param1_expected) do + <<~EOT + rewrite r_name { + subst( + 'string', + 'replacement', + value( + field + ), + flags( + ) + ); + }; + EOT + end - let(:title) {'r_name'} - let(:type) {'rewrite'} - let(:param1_expected) { -%q!rewrite r_name { - subst( - 'string', - 'replacement', - value( - field - ), - flags( - ) - ); -}; -!} + context 'Array notation with one item can be omitted' do + let(:param1) do + { + 'type' => 'subst', + 'options' => [ + "'string'", + "'replacement'", + { 'value' => 'field' }, + { 'flags' => '' } + ] + } + end - context "Array notation with one item can be omitted" do - let(:param1) {{ - 'type' => 'subst', - 'options' => [ - %q!'string'!, - %q!'replacement'!, - { 'value' => 'field' }, - { 'flags' => ''} - ] - }} - it 'On parameters of options' do - result = scope.function_generate_statement([title, type, [param1]]) - expect(result).to be_a String - expect(result).to eq param1_expected - end + it 'On parameters of options' do + result = scope.function_generate_statement([title, type, [param1]]) + expect(result).to be_a String + expect(result).to eq param1_expected + end - it 'On options' do - result = scope.function_generate_statement([title, type, param1]) - expect(result).to be_a String - expect(result).to eq param1_expected - end + it 'On options' do + result = scope.function_generate_statement([title, type, param1]) + expect(result).to be_a String + expect(result).to eq param1_expected end + end - context "Type and options key can be reduced to the exact type of statement" do - let(:param1) {{ - 'subst' => [ - %q!'string'!, - %q!'replacement'!, - { 'value' => 'field' }, - { 'flags' => ''} - ] - }} - it 'On parameters of options' do - result = scope.function_generate_statement([title, type, [param1]]) - expect(result).to be_a String - expect(result).to eq param1_expected - end + context 'Type and options key can be reduced to the exact type of statement' do + let(:param1) do + { + 'subst' => [ + "'string'", + "'replacement'", + { 'value' => 'field' }, + { 'flags' => '' } + ] + } + end - it 'On options' do - result = scope.function_generate_statement([title, type, param1]) - expect(result).to be_a String - expect(result).to eq param1_expected - end + it 'On parameters of options' do + result = scope.function_generate_statement([title, type, [param1]]) + expect(result).to be_a String + expect(result).to eq param1_expected + end + it 'On options' do + result = scope.function_generate_statement([title, type, param1]) + expect(result).to be_a String + expect(result).to eq param1_expected end + end - context "Array notation with one item can be omitted" do - let(:param2) {{ - 'type' => 'subst', - 'options' => [ - %q!'string'!, - %q!'replacement'!, - { 'value' => 'field' }, - { 'flags' => 'ignore-case, store-matches'} - ] - }} - let(:param2_expected) { -%q!rewrite r_name { - subst( - 'string', - 'replacement', - value( - field - ), - flags( - ignore-case, store-matches - ) - ); -}; -!} + context 'Array notation with one item can be omitted' do + let(:param2) do + { + 'type' => 'subst', + 'options' => [ + "'string'", + "'replacement'", + { 'value' => 'field' }, + { 'flags' => 'ignore-case, store-matches' } + ] + } + end + let(:param2_expected) do + <<~EOT + rewrite r_name { + subst( + 'string', + 'replacement', + value( + field + ), + flags( + ignore-case, store-matches + ) + ); + }; + EOT + end - it 'On parameters of options' do - result = scope.function_generate_statement([title, type, [param2]]) - expect(result).to be_a String - expect(result).to eq param2_expected - end + it 'On parameters of options' do + result = scope.function_generate_statement([title, type, [param2]]) + expect(result).to be_a String + expect(result).to eq param2_expected + end - it 'On options' do - result = scope.function_generate_statement([title, type, param2]) - expect(result).to be_a String - expect(result).to eq param2_expected - end + it 'On options' do + result = scope.function_generate_statement([title, type, param2]) + expect(result).to be_a String + expect(result).to eq param2_expected + end + end + context 'With simple options' do + let(:param1) do + { + 'type' => 'subst', + 'options' => [ + "'string'", + "'replacement'", + { 'value' => ['field'] }, + { 'flags' => [] } + ] + } end - context "With simple options" do - let(:param1) {{ - 'type' => 'subst', - 'options' => [ - %q!'string'!, - %q!'replacement'!, - { 'value' => ['field'] }, - { 'flags' => [ ]} - ] - }} + let(:params) { [param1] } - let(:params) {[param1]} - it 'Should generate rewrite rule' do - result = scope.function_generate_statement([title, type, params]) - expect(result).to be_a String - expect(result).to eq param1_expected - end + it 'generates rewrite rule' do + result = scope.function_generate_statement([title, type, params]) + expect(result).to be_a String + expect(result).to eq param1_expected end + end - context "Array statement" do - let(:type) { 'source' } - let(:title) { 's_external' } - let(:params) {[ - { 'type' => 'udp', - 'options' => [ - {'ip' => [%q!'192.168.42.2'!]}, - {'port' => [514]}, - {'tls' => [ - {'key_file' => ['"/opt/syslog-ng/etc/syslog-ng/key.d/syslog-ng.key"']}, - {'cert_file'=> '"/opt/syslog-ng/etc/syslog-ng/cert.d/syslog-ng.cert"'}, - {'peer_verify' => 'optional-untrusted'} - ]} - ] - }, - { 'type' => 'tcp', - 'options' => [ - {'ip' => [%q!'192.168.42.2'!]}, - {'port' => [514]} - ] - }, - { - 'type' => 'syslog', - 'options' => [ - {'flags' => ['no-multi-line', 'no-parse']}, - {'ip' => [%q!'10.65.0.5'!]}, - {'keep-alive' => ['yes']}, - {'keep_hostname' => ['yes']}, - {'transport' => ['udp']} - ] - } - ]} - let(:expected) { -%q!source s_external { - udp( - ip( - '192.168.42.2' - ), - port( - 514 - ), - tls( - key_file( - "/opt/syslog-ng/etc/syslog-ng/key.d/syslog-ng.key" - ), - cert_file( - "/opt/syslog-ng/etc/syslog-ng/cert.d/syslog-ng.cert" - ), - peer_verify( - optional-untrusted - ) - ) - ); - tcp( - ip( - '192.168.42.2' - ), - port( - 514 - ) - ); - syslog( - flags( - no-multi-line, - no-parse - ), - ip( - '10.65.0.5' - ), - keep-alive( - yes - ), - keep_hostname( - yes - ), - transport( - udp - ) - ); -}; -!} + context 'Array statement' do + let(:type) { 'source' } + let(:title) { 's_external' } + let(:params) do + [ + { 'type' => 'udp', + 'options' => [ + { 'ip' => ["'192.168.42.2'"] }, + { 'port' => [514] }, + { 'tls' => [ + { 'key_file' => ['"/opt/syslog-ng/etc/syslog-ng/key.d/syslog-ng.key"'] }, + { 'cert_file' => '"/opt/syslog-ng/etc/syslog-ng/cert.d/syslog-ng.cert"' }, + { 'peer_verify' => 'optional-untrusted' } + ] } + ] }, + { 'type' => 'tcp', + 'options' => [ + { 'ip' => ["'192.168.42.2'"] }, + { 'port' => [514] } + ] }, + { + 'type' => 'syslog', + 'options' => [ + { 'flags' => ['no-multi-line', 'no-parse'] }, + { 'ip' => ["'10.65.0.5'"] }, + { 'keep-alive' => ['yes'] }, + { 'keep_hostname' => ['yes'] }, + { 'transport' => ['udp'] } + ] + } + ] + end + let(:expected) do + <<~EOT + source s_external { + udp( + ip( + '192.168.42.2' + ), + port( + 514 + ), + tls( + key_file( + "/opt/syslog-ng/etc/syslog-ng/key.d/syslog-ng.key" + ), + cert_file( + "/opt/syslog-ng/etc/syslog-ng/cert.d/syslog-ng.cert" + ), + peer_verify( + optional-untrusted + ) + ) + ); + tcp( + ip( + '192.168.42.2' + ), + port( + 514 + ) + ); + syslog( + flags( + no-multi-line, + no-parse + ), + ip( + '10.65.0.5' + ), + keep-alive( + yes + ), + keep_hostname( + yes + ), + transport( + udp + ) + ); + }; + EOT + end - it 'Should generate source rule' do - result = scope.function_generate_statement([title, type, params]) - expect(result).to be_a String - expect(result).to eq expected - end + it 'generates source rule' do + result = scope.function_generate_statement([title, type, params]) + expect(result).to be_a String + expect(result).to eq expected end + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 93b25ec..6a41935 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,47 +1,13 @@ -require 'puppetlabs_spec_helper/module_spec_helper' -require 'rspec-puppet-facts' +# DO NOT EDIT THIS FILE! +# This file is managed by ModuleSync. +# +# frozen_string_literal: true -require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) +require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-facts' include RspecPuppetFacts -default_facts = { - puppetversion: Puppet.version, - facterversion: Facter.version, -} - -default_fact_files = [ - File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')), - File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')), -] - -default_fact_files.each do |f| - next unless File.exist?(f) && File.readable?(f) && File.size?(f) - - begin - default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) - rescue => e - RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" - end -end - RSpec.configure do |c| - c.default_facts = default_facts - c.before :each do - # set to strictest setting for testing - # by default Puppet runs at warning level - Puppet.settings[:strict] = :warning - end - c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] - c.after(:suite) do - end + c.hiera_config = 'spec/fixtures/hiera/hiera.yaml' end - -def ensure_module_defined(module_name) - module_name.split('::').reduce(Object) do |last_module, next_module| - last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false) - last_module.const_get(next_module, false) - end -end - -# 'spec_overrides' from sync.yml will appear below this line diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb new file mode 100644 index 0000000..c556c51 --- /dev/null +++ b/spec/spec_helper_acceptance.rb @@ -0,0 +1,10 @@ +# DO NOT EDIT THIS FILE! +# This file is managed by ModuleSync. +# +# frozen_string_literal: true + +require 'voxpupuli/acceptance/spec_helper_acceptance' + +configure_beaker + +Dir['./spec/support/acceptance/**/*.rb'].sort.each { |f| require f } diff --git a/spec/unit/facter/syslog_ng_version_spec.rb b/spec/unit/facter/syslog_ng_version_spec.rb index ba43f37..3b0bca5 100644 --- a/spec/unit/facter/syslog_ng_version_spec.rb +++ b/spec/unit/facter/syslog_ng_version_spec.rb @@ -1,11 +1,11 @@ -require "spec_helper" +require 'spec_helper' describe Facter::Util::Fact do - before { + before do Facter.clear - } + end - describe "syslog_ng" do + describe 'syslog_ng' do context 'fact' do output = <<-EOS syslog-ng 3.7.1 @@ -35,18 +35,18 @@ 'Enable-Linux-Caps' => 'off', } expected_syslog_ng_version = '3.7.1' - it "string" do - Facter::Util::Resolution.expects(:which).with("syslog-ng").returns("/usr/sbin/syslog-ng") - Facter::Util::Resolution.expects(:exec).with("syslog-ng --version").returns(output) + it 'string' do + Facter::Util::Resolution.expects(:which).with('syslog-ng').returns('/usr/sbin/syslog-ng') + Facter::Util::Resolution.expects(:exec).with('syslog-ng --version').returns(output) expect(Facter.value(:syslog_ng_version)).to eq(expected_syslog_ng_version) end - it "structured" do - Facter::Util::Resolution.expects(:which).with("syslog-ng").returns("/usr/sbin/syslog-ng") - Facter::Util::Resolution.expects(:exec).with("syslog-ng --version").returns(output) + it 'structured' do + Facter::Util::Resolution.expects(:which).with('syslog-ng').returns('/usr/sbin/syslog-ng') + Facter::Util::Resolution.expects(:exec).with('syslog-ng --version').returns(output) syslog_ng = Facter.value(:syslog_ng) expect(syslog_ng.keys).to eq(expected_syslog_ng.keys) syslog_ng.keys.each do |k| - expect(syslog_ng[k]).to eq(expected_syslog_ng[k]) + expect(syslog_ng[k]).to eq(expected_syslog_ng[k]) end end end