diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 048d2b55..6aaa603f 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -124,7 +124,7 @@ If you have Ruby 2.x or want a specific version of Puppet, you must set an environment variable such as: ```sh -export PUPPET_VERSION="~> 5.5.6" +export PUPPET_GEM_VERSION="~> 6.1.0" ``` You can install all needed gems for spec tests into the modules directory by @@ -232,19 +232,21 @@ simple tests against it after applying the module. You can run this with: ```sh -BEAKER_setfile=debian10-x64 bundle exec rake beaker +BEAKER_PUPPET_COLLECTION=puppet7 BEAKER_setfile=debian11-64 bundle exec rake beaker ``` -You can replace the string `debian10` with any common operating system. +You can replace the string `debian11` with any common operating system. The following strings are known to work: -* ubuntu1604 -* ubuntu1804 * ubuntu2004 -* debian9 -* debian10 +* ubuntu2204 +* debian11 * centos7 * centos8 +* centos9 +* almalinux8 +* almalinux9 +* fedora36 For more information and tips & tricks, see [voxpupuli-acceptance's documentation](https://github.com/voxpupuli/voxpupuli-acceptance#running-tests). diff --git a/.github/SECURITY.md b/.github/SECURITY.md deleted file mode 100644 index cacadf22..00000000 --- a/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Vox Pupuli Security Policy - -Our vulnerabilities reporting process is at https://voxpupuli.org/security/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d08d05e8..7216724f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,87 +4,20 @@ name: CI -on: pull_request +on: + pull_request: {} + push: + branches: + - main + - master concurrency: - group: ${{ github.head_ref }} + group: ${{ github.ref_name }} cancel-in-progress: true jobs: - setup_matrix: - name: 'Setup Test Matrix' - runs-on: ubuntu-latest - timeout-minutes: 40 - outputs: - puppet_unit_test_matrix: ${{ steps.get-outputs.outputs.puppet_unit_test_matrix }} - github_action_test_matrix: ${{ steps.get-outputs.outputs.github_action_test_matrix }} - env: - BUNDLE_WITHOUT: development:system_tests:release - steps: - - uses: actions/checkout@v2 - - name: Setup ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.0' - bundler-cache: true - - name: Run static validations - run: bundle exec rake validate lint check - - name: Run rake rubocop - run: bundle exec rake rubocop - - name: Setup Test Matrix - id: get-outputs - run: bundle exec metadata2gha --use-fqdn --pidfile-workaround false - - unit: - needs: setup_matrix - runs-on: ubuntu-latest - timeout-minutes: 40 - 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 parallel_spec - - acceptance: - needs: setup_matrix - runs-on: ubuntu-latest - env: - BUNDLE_WITHOUT: development:test:release - strategy: - fail-fast: false - matrix: - include: ${{fromJson(needs.setup_matrix.outputs.github_action_test_matrix)}} - name: ${{ matrix.puppet.name }} - ${{ matrix.setfile.name }} - steps: - - uses: actions/checkout@v2 - - name: Setup ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.0' - bundler-cache: true - - name: Run tests - run: bundle exec rake beaker - env: - BEAKER_PUPPET_COLLECTION: ${{ matrix.puppet.collection }} - BEAKER_setfile: ${{ matrix.setfile.value }} - - tests: - needs: - - unit - - acceptance - runs-on: ubuntu-latest - name: Test suite - steps: - - run: echo Test suite completed + puppet: + name: Puppet + uses: voxpupuli/gha-puppet/.github/workflows/beaker.yml@v2 + with: + pidfile_workaround: 'false' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 664ba694..55324aa6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,26 +9,14 @@ on: tags: - '*' -env: - BUNDLE_WITHOUT: development:test:system_tests - jobs: - deploy: - name: 'deploy to forge' - runs-on: ubuntu-latest - if: github.repository_owner == 'voxpupuli' - 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 + release: + name: Release + uses: voxpupuli/gha-puppet/.github/workflows/release.yml@v2 + with: + allowed_owner: 'voxpupuli' + secrets: + # Configure secrets here: + # https://docs.github.com/en/actions/security-guides/encrypted-secrets + username: ${{ secrets.PUPPET_FORGE_USERNAME }} + api_key: ${{ secrets.PUPPET_FORGE_API_KEY }} diff --git a/.gitignore b/.gitignore index 9b95224c..84fd904c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,23 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -pkg/ -Gemfile.lock -Gemfile.local -vendor/ -.vendor/ -spec/fixtures/manifests/ -spec/fixtures/modules/ -.vagrant/ -.bundle/ -.ruby-version -coverage/ -log/ -.idea/ -.dependencies/ -.librarian/ -Puppetfile.lock +/pkg/ +/Gemfile.lock +/Gemfile.local +/vendor/ +/.vendor/ +/spec/fixtures/manifests/ +/spec/fixtures/modules/ +/.vagrant/ +/.bundle/ +/.ruby-version +/coverage/ +/log/ +/.idea/ +/.dependencies/ +/.librarian/ +/Puppetfile.lock *.iml .*.sw? -.yardoc/ -Guardfile +/.yardoc/ +/Guardfile diff --git a/.msync.yml b/.msync.yml index 43966c2f..f46ee025 100644 --- a/.msync.yml +++ b/.msync.yml @@ -2,4 +2,4 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -modulesync_config_version: '4.2.0' +modulesync_config_version: '7.3.0' diff --git a/.pmtignore b/.pmtignore index 65f50514..10b98306 100644 --- a/.pmtignore +++ b/.pmtignore @@ -1,37 +1,38 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -docs/ -pkg/ -Gemfile -Gemfile.lock -Gemfile.local -vendor/ -.vendor/ -spec/ -Rakefile -.vagrant/ -.bundle/ -.ruby-version -coverage/ -log/ -.idea/ -.dependencies/ -.github/ -.librarian/ -Puppetfile.lock +/docs/ +/pkg/ +/Gemfile +/Gemfile.lock +/Gemfile.local +/vendor/ +/.vendor/ +/spec/ +/Rakefile +/.vagrant/ +/.bundle/ +/.ruby-version +/coverage/ +/log/ +/.idea/ +/.dependencies/ +/.github/ +/.librarian/ +/Puppetfile.lock *.iml -.editorconfig -.fixtures.yml -.gitignore -.msync.yml -.overcommit.yml -.pmtignore -.rspec -.rspec_parallel -.rubocop.yml -.sync.yml +/.editorconfig +/.fixtures.yml +/.gitignore +/.msync.yml +/.overcommit.yml +/.pmtignore +/.rspec +/.rspec_parallel +/.rubocop.yml +/.sync.yml .*.sw? -.yardoc/ -.yardopts -Dockerfile +/.yardoc/ +/.yardopts +/Dockerfile +/HISTORY.md diff --git a/.puppet-lint.rc b/.puppet-lint.rc new file mode 100644 index 00000000..dd8272c7 --- /dev/null +++ b/.puppet-lint.rc @@ -0,0 +1,3 @@ +--fail-on-warnings +--no-parameter_documentation-check +--no-parameter_types-check diff --git a/.rubocop.yml b/.rubocop.yml index 53ac1898..fded90cf 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,5 +2,6 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ +inherit_from: .rubocop_todo.yml inherit_gem: voxpupuli-test: rubocop.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 00000000..72452a28 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,13 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2023-08-17 21:32:49 UTC using RuboCop version 1.50.2. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 12 +# This cop supports unsafe autocorrection (--autocorrect-all). +RSpec/BeEq: + Exclude: + - 'spec/unit/lib/facter/gluster_spec.rb' diff --git a/CHANGELOG.md b/CHANGELOG.md index e4d5e3e9..f31dee5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,7 +46,7 @@ These should not affect the functionality of the module. **Breaking changes:** - modulesync 2.7.0 and drop puppet 4 [\#193](https://github.com/voxpupuli/puppet-gluster/pull/193) ([bastelfreak](https://github.com/bastelfreak)) -- Add arm64, remove i386 compatibility from ::gluster::repo:apt [\#189](https://github.com/voxpupuli/puppet-gluster/pull/189) ([jacksgt](https://github.com/jacksgt)) +- Add arm64, remove i386 compatibility from gluster::repo:apt [\#189](https://github.com/voxpupuli/puppet-gluster/pull/189) ([jacksgt](https://github.com/jacksgt)) - Remove 3.8 repo, use pl-apt 4.4 https support, clean coding [\#170](https://github.com/voxpupuli/puppet-gluster/pull/170) ([ekohl](https://github.com/ekohl)) **Implemented enhancements:** @@ -246,7 +246,7 @@ These should not affect the functionality of the module. - Mounts can be defined but mount point will not be created [\#16](https://github.com/voxpupuli/puppet-gluster/issues/16) - refreshes to gluster::mount fail to remount the volume [\#10](https://github.com/voxpupuli/puppet-gluster/issues/10) - Support yum priorities [\#4](https://github.com/voxpupuli/puppet-gluster/issues/4) -- ::gluster::volume doesn't create volumes from hosts included in the volume [\#3](https://github.com/voxpupuli/puppet-gluster/issues/3) +- gluster::volume doesn't create volumes from hosts included in the volume [\#3](https://github.com/voxpupuli/puppet-gluster/issues/3) - A stopped volume aborts a Puppet run [\#1](https://github.com/voxpupuli/puppet-gluster/issues/1) **Merged pull requests:** diff --git a/Dockerfile b/Dockerfile index e3cf307f..8dd82d63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ WORKDIR /opt/puppet # https://github.com/puppetlabs/puppet/blob/06ad255754a38f22fb3a22c7c4f1e2ce453d01cb/lib/puppet/provider/service/runit.rb#L39 RUN mkdir -p /etc/sv -ARG PUPPET_VERSION="~> 6.0" +ARG PUPPET_GEM_VERSION="~> 6.0" ARG PARALLEL_TEST_PROCESSORS=4 # Cache gems diff --git a/Gemfile b/Gemfile index a39114ce..a4a3b204 100644 --- a/Gemfile +++ b/Gemfile @@ -1,13 +1,13 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -source ENV['GEM_SOURCE'] || "https://rubygems.org" +source ENV['GEM_SOURCE'] || 'https://rubygems.org' group :test do - gem 'voxpupuli-test', '~> 2.5', :require => false + gem 'voxpupuli-test', '~> 7.0', :require => false gem 'coveralls', :require => false gem 'simplecov-console', :require => false - gem 'puppet_metadata', '~> 1.0', :require => false + gem 'puppet_metadata', '~> 3.5', :require => false end group :development do @@ -16,19 +16,17 @@ group :development do end group :system_tests do - gem 'voxpupuli-acceptance', '~> 1.0', :require => false + gem 'voxpupuli-acceptance', '~> 3.0', :require => false end group :release do - gem 'github_changelog_generator', '>= 1.16.1', :require => false if RUBY_VERSION >= '2.5' - gem 'voxpupuli-release', '>= 1.0.2', :require => false - gem 'puppet-strings', '>= 2.2', :require => false + gem 'voxpupuli-release', '~> 3.0', :require => false end gem 'rake', :require => false gem 'facter', ENV['FACTER_GEM_VERSION'], :require => false, :groups => [:test] -puppetversion = ENV['PUPPET_VERSION'] || '>= 6.0' +puppetversion = ENV['PUPPET_GEM_VERSION'] || '~> 7.24' gem 'puppet', puppetversion, :require => false, :groups => [:test] # vim: syntax=ruby diff --git a/README.md b/README.md index f008bb00..b21c4999 100644 --- a/README.md +++ b/README.md @@ -55,21 +55,31 @@ Fedora users can get GlusterFS packages directly from Fedora's repository. Red H gluster::repo => false ``` -For systems using APT, the latest packages of the latest release will be installed by default. Otherwise, specify a version: +For Debian, the latest packages of the latest release will be installed by default. Otherwise, specify a version: ```puppet -class { ::gluster::repo: +class { gluster::repo: version => '3.5.2', } ``` +For Ubuntu, the [Gluster PPA](https://launchpad.net/~gluster) repositories only contain the latest version of each release. +Therefore specify the release to install: + +```puppet +class { gluster::repo: + release => '10', +} +``` + + For systems using YUM, the latest package from the 3.8 release branch will be installed. You can specify a specific version and release: ```puppet -class { ::gluster::repo: +class { gluster::repo: release => '3.7', } -class { ::gluster: +class { gluster: version => '3.7.12', } ``` @@ -103,7 +113,7 @@ On Debian-based systems, only the first two version places are significant ("x.y ### client.pp This class installs **only** the Gluster client package(s). If you need to install both the server and client, please use the `install.pp` (or `init.pp`) classes. - class { ::gluster::client: + class { gluster::client: repo => true, version => '3.5.2', } @@ -113,7 +123,7 @@ Use of `gluster::client` is not supported with either `gluster::install` or `glu ### service.pp This class manages the `glusterd` service. - class { ::gluster::service: + class { gluster::service: ensure => running, } @@ -128,7 +138,7 @@ The use of exported resources assume you're using PuppetDB, or some other backin If a `volumes` parameter is passed, the defined Gluster volume(s) can be created at the same time as the storage pool. See the volume defined type below for more details. - class { ::gluster: + class { gluster: repo => true, client => false, pool => 'production', diff --git a/Rakefile b/Rakefile index 80b799d6..ebf49eb4 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,7 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -# Attempt to load voxupuli-test (which pulls in puppetlabs_spec_helper), +# Attempt to load voxpupuli-test (which pulls in puppetlabs_spec_helper), # otherwise attempt to load it directly. begin require 'voxpupuli/test/rake' @@ -24,6 +24,10 @@ end begin require 'voxpupuli/release/rake_tasks' rescue LoadError + # voxpupuli-release not present +else + GCGConfig.user = 'voxpupuli' + GCGConfig.project = 'puppet-gluster' end desc "Run main 'test' task and report merged results to coveralls" @@ -37,36 +41,4 @@ task test_with_coveralls: [:test] do end end -desc 'Generate REFERENCE.md' -task :reference, [:debug, :backtrace] do |t, args| - patterns = '' - Rake::Task['strings:generate:reference'].invoke(patterns, args[:debug], args[:backtrace]) -end - -begin - require 'github_changelog_generator/task' - require 'puppet_blacksmith' - GitHubChangelogGenerator::RakeTask.new :changelog do |config| - metadata = Blacksmith::Modulefile.new - config.future_release = "v#{metadata.version}" if metadata.version =~ /^\d+\.\d+.\d+$/ - config.header = "# Changelog\n\nAll notable changes to this project will be documented in this file.\nEach new release typically also includes the latest modulesync defaults.\nThese should not affect the functionality of the module." - config.exclude_labels = %w{duplicate question invalid wontfix wont-fix modulesync skip-changelog} - config.user = 'voxpupuli' - config.project = metadata.metadata['name'] - 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 - -rescue LoadError -end # vim: syntax=ruby diff --git a/examples/01_simple.md b/examples/01_simple.md index fe556b58..70855918 100644 --- a/examples/01_simple.md +++ b/examples/01_simple.md @@ -9,7 +9,7 @@ To create a simple two-node replicated Gluster volume, you could use the followi node /srv[1-2].local/ { # first, install Gluster using upstream packages - class { ::gluster: + class { gluster: server => true, client => true, repo => true, diff --git a/examples/02_simple.md b/examples/02_simple.md index e3b740b8..832806b0 100644 --- a/examples/02_simple.md +++ b/examples/02_simple.md @@ -10,7 +10,7 @@ To create a simple two-node replicated Gluster volume, you could use the followi node /srv[1-2].local/ { # first, install the upstream Gluster packages - class { ::gluster::install: + class { gluster::install: server => true, client => true, repo => true, @@ -18,7 +18,7 @@ To create a simple two-node replicated Gluster volume, you could use the followi } # make sure the service is started - class { ::gluster::service: + class { gluster::service: ensure => running, require => Class[::gluster::install], } diff --git a/examples/04_hiera.md b/examples/04_hiera.md index 1fafe741..622ca289 100644 --- a/examples/04_hiera.md +++ b/examples/04_hiera.md @@ -22,7 +22,7 @@ Your `/etc/puppet/hieradata/common.yaml` file could then contain: gluster::repo: true gluster::version: '3.5.2-1.el6' -You can then simply apply `class { ::gluster: }` to any hosts and they will use the upstream Gluster repo, install version 3.5.2-1.el6 of both the server and client, and join the `production` pool. +You can then simply apply `class { gluster: }` to any hosts and they will use the upstream Gluster repo, install version 3.5.2-1.el6 of both the server and client, and join the `production` pool. In this way, you could have two servers (srv1.local and srv2.local) operating in a different pool, with a different version of Gluster, and without the client packages installed, while all your other servers use the values from common.yaml. diff --git a/examples/05_client.md b/examples/05_client.md index efb9e5cc..f2072d33 100644 --- a/examples/05_client.md +++ b/examples/05_client.md @@ -19,7 +19,7 @@ define gluster_mount ( $options = undef, ) { if ! defined ( Class[::gluster::client] ) { - include ::gluster::client + include gluster::client } if ! defined ( File['/gluster'] ) { @@ -49,7 +49,7 @@ define gluster_mount ( if ! defined ( Gluster::Mount["/gluster/${title}"] ) and has_key( $gluster_mounts, $title ) { - ::gluster::mount { "/gluster/${title}": + gluster::mount { "/gluster/${title}": ensure => 'mounted', volume => $gluster_mounts[$title], options => $_options, diff --git a/lib/facter/gluster.rb b/lib/facter/gluster.rb index 0bd30207..5019adcc 100644 --- a/lib/facter/gluster.rb +++ b/lib/facter/gluster.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # vim: syntax=ruby tabstop=2 softtabstop=2 shiftwidth=2 require 'rexml/document' @@ -136,29 +138,25 @@ gluster_volumes.keys.join(',') end end - gluster_volumes.keys.each do |volume| + gluster_volumes.each_key do |volume| Facter.add("gluster_volume_#{volume}_bricks".to_sym) do setcode do gluster_volumes[volume]['bricks'].join(',') end end end - if volume_options - volume_options.each do |vol, opts| - # Create flat facts for each volume - Facter.add("gluster_volume_#{vol}_options".to_sym) do - setcode do - opts.join(',') - end + volume_options&.each do |vol, opts| + # Create flat facts for each volume + Facter.add("gluster_volume_#{vol}_options".to_sym) do + setcode do + opts.join(',') end end end - if volume_ports - volume_ports.each do |vol, ports| - Facter.add("gluster_volume_#{vol}_ports".to_sym) do - setcode do - ports.join(',') - end + volume_ports&.each do |vol, ports| + Facter.add("gluster_volume_#{vol}_ports".to_sym) do + setcode do + ports.join(',') end end end diff --git a/manifests/init.pp b/manifests/init.pp index 19a1197d..4538ea6b 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -17,7 +17,7 @@ # optional list of volumes (and their properties) to create # # @example -# class { ::gluster: +# class { gluster: # client => false, # server => true, # pool => 'production', diff --git a/manifests/install.pp b/manifests/install.pp index dc18f54d..ec49cda8 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -49,44 +49,29 @@ default => $version, } - if $client_package == $server_package { - if $server { - # we use ensure_packages here because on some distributions the client and server package have different names - ensure_packages($server_package, - { - ensure => $_version, - tag => 'gluster-packages', - notify => Class['gluster::service'], - } - ) - } elsif $client { - ensure_packages($client_package, - { - ensure => $_version, - tag => 'gluster-packages', - } - ) - } - } else { - if $client { - # we use ensure_packages here because on some distributions the client and server package have different names - ensure_packages($client_package, - { - ensure => $_version, - tag => 'gluster-packages', - } - ) - } + $packages = ( + ( + if $server { + [$server_package] + } else { + [] + } + ) + + ( + if $client { + [$client_package] + } else { + [] + } + ) + ).unique - if $server { - # we use ensure_packages here because on some distributions the client and server package have different names - ensure_packages($server_package, - { - ensure => $_version, - notify => Class['gluster::service'], - tag => 'gluster-packages', - } - ) - } + package { $packages: + ensure => $_version, + tag => 'gluster-packages', + } + + if $server { + Package[$server_package] ~> Class['gluster::service'] } } diff --git a/manifests/params.pp b/manifests/params.pp index 058a4215..55312e95 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -35,7 +35,11 @@ $service_name = 'glusterd' } 'Debian': { - $repo = true + # Ubuntu 22.04 includes GlusterFS in the base repositories + $repo = "${facts['os']['name']}_${facts['os']['release']['major']}" ? { + 'Ubuntu_22.04' => false, + default => true + } $server_package = 'glusterfs-server' $client_package = 'glusterfs-client' $service_name = 'glusterd' diff --git a/manifests/peer.pp b/manifests/peer.pp index 387f0f27..8a42dafc 100644 --- a/manifests/peer.pp +++ b/manifests/peer.pp @@ -41,7 +41,7 @@ # we can't do much without the Gluster binary # but we don't necessarily want the Puppet run to fail if the # gluster_binary fact is absent! - if getvar('::gluster_binary') { + if getvar('gluster_binary') { # we can't join to ourselves, so it only makes sense to operate # on other gluster servers in the same pool if $fqdn != $facts['networking']['fqdn'] { diff --git a/manifests/repo.pp b/manifests/repo.pp index f42085f3..9043f649 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -27,7 +27,8 @@ } 'Debian': { class { 'gluster::repo::apt': - version => $version, + version => $version, + release => $release, } } default: { fail("${facts['os']['family']} not yet supported!") } diff --git a/manifests/repo/apt.pp b/manifests/repo/apt.pp index f7830df3..02ab2d5b 100644 --- a/manifests/repo/apt.pp +++ b/manifests/repo/apt.pp @@ -30,33 +30,38 @@ ) { include 'apt' - $repo_key_name = $release ? { - '3.9' => '849512C2CA648EF425048F55C883F50CB2289A17', - '3.10' => 'C784DD0FD61E38B8B1F65E10DAD761554A72C1DF', - '3.11' => 'DE82F0BACC4DB70DBEF95CA65EC2255642304A6E', - '3.12' => '8B7C364430B66F0B084C0B0C55339A4C6A7BD8D4', - '3.13' => '9B5AE8E6FD2581F293104ACC38675E5F30F779AF', - '4.0' => '55F839E173AC06F364120D46FA86EEACB306CEE1', - '4.1' => 'EED3351AFD72E5437C050F0388F6CDEE78FA6D97', - default => 'F9C958A3AEE0D2184FAD1CBD43607F0DC2F8238C', - } - - $repo_key_source = "https://download.gluster.org/pub/gluster/glusterfs/${release}/rsa.pub" - - # basic sanity check - if $version == 'LATEST' { - $repo_ver = $version - } elsif $version =~ /^\d\.\d+$/ { - $repo_ver = "${version}/LATEST" - } elsif $version =~ /^(\d)\.(\d+)\.(\d+).*$/ { - $repo_ver = "${1}.${2}/${1}.${2}.${3}" - } else { - fail("${version} doesn't make sense for ${facts['os']['name']}!") + $_release = versioncmp($release, '4.1') ? { + 1 => $release.match(/\A[^.]*/)[0], + default => $release, } # the Gluster repo only supports x86_64 (amd64) and arm64. The Ubuntu PPA also supports armhf and arm64. case $facts['os']['name'] { 'Debian': { + $repo_key_name = $release ? { + '3.9' => '849512C2CA648EF425048F55C883F50CB2289A17', + '3.10' => 'C784DD0FD61E38B8B1F65E10DAD761554A72C1DF', + '3.11' => 'DE82F0BACC4DB70DBEF95CA65EC2255642304A6E', + '3.12' => '8B7C364430B66F0B084C0B0C55339A4C6A7BD8D4', + '3.13' => '9B5AE8E6FD2581F293104ACC38675E5F30F779AF', + '4.0' => '55F839E173AC06F364120D46FA86EEACB306CEE1', + '4.1' => 'EED3351AFD72E5437C050F0388F6CDEE78FA6D97', + default => 'F9C958A3AEE0D2184FAD1CBD43607F0DC2F8238C', + } + + $repo_key_source = "https://download.gluster.org/pub/gluster/glusterfs/${_release}/rsa.pub" + + # basic sanity check + if $version == 'LATEST' { + $repo_ver = $version + } elsif $version =~ /^\d\.\d+$/ { + $repo_ver = "${version}/LATEST" + } elsif $version =~ /^(\d)\.(\d+)\.(\d+).*$/ { + $repo_ver = "${1}.${2}/${1}.${2}.${3}" + } else { + fail("${version} doesn't make sense for ${facts['os']['name']}!") + } + case $facts['os']['distro']['codename'] { 'jessie', 'stretch': { $arch = $facts['os']['architecture'] ? { @@ -69,11 +74,6 @@ $repo_url = if versioncmp($release, '4.1') < 0 { "${_repo_base}/01.old-releases/${release}/LATEST/Debian/${facts['os']['distro']['codename']}/${arch}/apt/" } else { - $_release = if $release == '4.1' { - $release - } else { - $release[0] - } "${_repo_base}/${_release}/LATEST/Debian/${facts['os']['distro']['codename']}/${arch}/apt/" } } @@ -82,8 +82,27 @@ } } } + 'Ubuntu': { + $repo_key_name = 'F7C73FCC930AC9F83B387A5613E01B7B3FE869A9' + $repo_key_source = undef + + unless $version == 'LATEST' { + fail("Specifying version other than LATEST doesn't make sense for Ubuntu PPA!") + } + $repo_ver = $version + + $arch = $facts['os']['architecture'] ? { + 'amd64' => 'amd64', + 'arm64' => 'arm64', + 'armhf' => 'armhf', + 'i386' => 'i386', + default => false, + } + + $repo_url = "http://ppa.launchpad.net/gluster/glusterfs-${_release}/ubuntu" + } default: { - fail('gluster::repo::apt currently only works on Debian') + fail('gluster::repo::apt currently only works on Debian and Ubuntu') } } @@ -99,7 +118,7 @@ repos => 'main', key => { id => $repo_key_name, - key_source => $repo_key_source, + source => $repo_key_source, }, pin => $priority, architecture => $arch, diff --git a/manifests/volume.pp b/manifests/volume.pp index 2c9605d0..d09e83c6 100644 --- a/manifests/volume.pp +++ b/manifests/volume.pp @@ -121,7 +121,7 @@ $args = join(delete($cmd_args, ''), ' ') - if getvar('::gluster_binary') { + if getvar('gluster_binary') { # we need the Gluster binary to do anything! if $facts['gluster_volume_list'] and member( split( $facts['gluster_volume_list'], ',' ), $title ) { @@ -254,14 +254,14 @@ # either of $current_options or $_options may be empty. # we need to account for this situation # - if is_array($_current) and is_array($_options) { + if $_current =~ Array and $_options =~ Array { $to_remove = difference($_current, $_options) $to_add = difference($_options, $_current) } else { - if is_array($_current) { + if $_current =~ Array { # $_options is not an array, so remove all currently set options $to_remove = $_current - } elsif is_array($_options) { + } elsif $_options =~ Array { # $current_options is not an array, so add all our defined options $to_add = $_options } @@ -269,14 +269,14 @@ if ! empty($to_remove) { # we have some options active that are not defined here. Remove them # - # the syntax to remove ::gluster::volume::options is a little different + # the syntax to remove gluster::volume::options is a little different # so build up the hash correctly # $remove_opts = prefix( $to_remove, "${title}:" ) $remove_yaml = join( regsubst( $remove_opts, ': .+$', ":\n ensure: absent", 'G' ), "\n" ) $remove = parseyaml($remove_yaml) if $remove_options { - create_resources( ::gluster::volume::option, $remove ) + create_resources( gluster::volume::option, $remove ) } else { $remove_str = join( keys($remove), ', ' ) notice("NOT REMOVING the following options for volume ${title}: ${remove_str}.") @@ -287,7 +287,7 @@ $add_opts = prefix( $to_add, "${title}:" ) $add_yaml = join( regsubst( $add_opts, ': ', ":\n value: ", 'G' ), "\n" ) $add = parseyaml($add_yaml) - create_resources( ::gluster::volume::option, $add ) + create_resources( gluster::volume::option, $add ) } } } else { diff --git a/metadata.json b/metadata.json index 5e0e43d0..69146ce6 100644 --- a/metadata.json +++ b/metadata.json @@ -28,7 +28,6 @@ { "operatingsystem": "Debian", "operatingsystemrelease": [ - "9" ] }, { @@ -40,22 +39,29 @@ "11", "12" ] + }, + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "20.04", + "22.04" + ] } ], "dependencies": [ { "name": "puppetlabs/apt", - "version_requirement": ">= 4.4.0 < 9.0.0" + "version_requirement": ">= 4.4.0 < 10.0.0" }, { "name": "puppetlabs/stdlib", - "version_requirement": ">= 4.6.0 < 9.0.0" + "version_requirement": ">= 4.6.0 < 10.0.0" } ], "requirements": [ { "name": "puppet", - "version_requirement": ">= 6.1.0 < 8.0.0" + "version_requirement": ">= 7.0.0 < 9.0.0" } ] } diff --git a/spec/acceptance/client_spec.rb b/spec/acceptance/client_spec.rb index 83dc903f..da6f23a1 100644 --- a/spec/acceptance/client_spec.rb +++ b/spec/acceptance/client_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'gluster client' do @@ -18,13 +20,14 @@ class { 'gluster': end context 'packages installed' do - if os[:family] == 'debian' + case os[:family] + when 'debian' describe package('glusterfs-client') do it { is_expected.to be_installed } end - elsif os[:family] == 'redhat' + when 'redhat' describe package('glusterfs') do it { is_expected.to be_installed } diff --git a/spec/acceptance/server_spec.rb b/spec/acceptance/server_spec.rb index a992ae04..942faea3 100644 --- a/spec/acceptance/server_spec.rb +++ b/spec/acceptance/server_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'gluster server' do @@ -18,13 +20,14 @@ class { 'gluster': end context 'packages installed' do - if os[:family] == 'debian' + case os[:family] + when 'debian' describe package('glusterfs-server') do it { is_expected.to be_installed } end - elsif os[:family] == 'redhat' + when 'redhat' describe package('glusterfs') do it { is_expected.to be_installed } diff --git a/spec/classes/client_spec.rb b/spec/classes/client_spec.rb index 7da22534..53f1efd7 100644 --- a/spec/classes/client_spec.rb +++ b/spec/classes/client_spec.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'gluster::client', type: :class do on_supported_os.each do |os, facts| - context "on #{os} " do + context "on #{os}" do let(:facts) do facts end @@ -12,6 +14,7 @@ context 'with all defaults' do it { is_expected.to contain_class('gluster::client') } it { is_expected.to compile.with_all_deps } + it 'includes gluster::install' do is_expected.to create_class('gluster::install').with( repo: true, @@ -20,6 +23,7 @@ ) end end + context 'when a version number is specified' do let :params do { @@ -35,6 +39,7 @@ ) end end + context 'when repo is false' do let :params do { @@ -54,14 +59,18 @@ context 'with all defaults' do it { is_expected.to contain_class('gluster::client') } it { is_expected.to compile.with_all_deps } + + repo_params = { + client_package: 'glusterfs-client', + version: 'LATEST' + } + repo_params[:repo] = !'ubuntu-22.04-x86_64'.eql?(os) + it 'includes gluster::install' do - is_expected.to create_class('gluster::install').with( - repo: true, - client_package: 'glusterfs-client', - version: 'LATEST' - ) + is_expected.to create_class('gluster::install').with(repo_params) end end + context 'when a version number is specified' do let :params do { @@ -69,14 +78,22 @@ } end - it 'includes gluster::install with version 3.6.1' do - is_expected.to create_class('gluster::install').with( - repo: true, - client_package: 'glusterfs-client', - version: '3.6.1' - ) + case facts[:os][:name] + when 'Debian' + it 'includes gluster::install with version 3.6.1' do + is_expected.to create_class('gluster::install').with( + repo: true, + client_package: 'glusterfs-client', + version: '3.6.1' + ) + end + when 'Ubuntu' + it 'does not install' do + is_expected.to compile.and_raise_error(%r{Specifying version other than LATEST doesn't make sense for Ubuntu PPA!}) + end end end + context 'when repo is false' do let :params do { diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 6a4650fb..f3f55ae7 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'gluster', type: :class do @@ -10,14 +12,15 @@ context 'with all defaults' do it { is_expected.to contain_class('gluster') } it { is_expected.to contain_class('gluster::params') } - unless facts[:os]['family'] == 'Archlinux' || facts[:os]['family'] == 'Suse' - it { is_expected.to contain_class('gluster::repo') } - end + + it { is_expected.to contain_class('gluster::repo') } unless facts[:os]['family'] == 'Archlinux' || facts[:os]['family'] == 'Suse' || os == 'ubuntu-22.04-x86_64' it { is_expected.to compile.with_all_deps } + it 'includes classes' do is_expected.to contain_class('gluster::install') is_expected.to contain_class('gluster::service') end + it 'manages the Gluster service' do is_expected.to create_class('gluster::service').with(ensure: true) end @@ -29,6 +32,7 @@ it { is_expected.to contain_service('glusterd') } it { is_expected.to contain_class('gluster::repo::yum') } it { is_expected.to contain_yumrepo('glusterfs-x86_64') } + it 'creates gluster::install' do is_expected.to create_class('gluster::install').with( server: true, @@ -40,6 +44,7 @@ ) end end + context 'specific version and package names defined' do let :params do { @@ -60,6 +65,7 @@ repo: false ) end + it 'installs custom-gluster-client and custom-gluster-server' do is_expected.to create_package('custom-gluster-client') is_expected.to create_package('custom-gluster-server') @@ -67,19 +73,23 @@ end when 'Debian' context 'Debian specific stuff' do - it { is_expected.to contain_class('gluster::repo::apt') } - it { is_expected.to contain_apt__source('glusterfs-LATEST') } + it { is_expected.to contain_class('gluster::repo::apt') } unless os == 'ubuntu-22.04-x86_64' + it { is_expected.to contain_apt__source('glusterfs-LATEST') } unless os == 'ubuntu-22.04-x86_64' + + repo_params = { + server: true, + server_package: 'glusterfs-server', + client: true, + client_package: 'glusterfs-client', + version: 'LATEST', + } + repo_params[:repo] = !'ubuntu-22.04-x86_64'.eql?(os) + it 'creates gluster::install' do - is_expected.to create_class('gluster::install').with( - server: true, - server_package: 'glusterfs-server', - client: true, - client_package: 'glusterfs-client', - version: 'LATEST', - repo: true - ) + is_expected.to create_class('gluster::install').with(repo_params) end end + context 'specific version and package names defined' do let :params do { @@ -100,6 +110,7 @@ repo: false ) end + it 'installs custom-gluster-client and custom-gluster-server' do is_expected.to create_package('custom-gluster-client') is_expected.to create_package('custom-gluster-server') @@ -151,7 +162,7 @@ volumes: { 'data1' => { - 'bricks' => ['srv1.local:/brick1/brick', 'srv2.local:/brick1/brick'] + 'bricks' => ['srv1.local:/brick1/brick', 'srv2.local:/brick1/brick'] } } } @@ -164,6 +175,7 @@ bricks: ['srv1.local:/brick1/brick', 'srv2.local:/brick1/brick'] ) end + it 'executes command without replica' do is_expected.not_to contain_exec('gluster create volume data1').with( command: %r{.* replica .*} diff --git a/spec/classes/install_spec.rb b/spec/classes/install_spec.rb index f44c250a..7289169b 100644 --- a/spec/classes/install_spec.rb +++ b/spec/classes/install_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'gluster::install', type: :class do @@ -7,11 +9,12 @@ facts end let :pre_condition do - 'require ::gluster::service' + 'require gluster::service' end context 'with defaults' do it { is_expected.to compile.with_all_deps } + case facts[:osfamily] when 'Redhat' # rubocop:disable RSpec/RepeatedExample @@ -21,10 +24,12 @@ when 'Debian' it { is_expected.to create_package('glusterfs-server') } it { is_expected.to create_package('glusterfs-client') } - it { is_expected.to create_class('gluster::repo').with(version: 'LATEST') } + + it { is_expected.to create_class('gluster::repo').with(version: 'LATEST') } unless os == 'ubuntu-22.04-x86_64' # rubocop:enable RSpec/RepeatedExample end end + context 'when repo is false' do let :params do { repo: false } @@ -32,6 +37,7 @@ it { is_expected.not_to create_class('gluster::repo') } end + context 'when client is false' do let :params do { client: false } @@ -44,6 +50,7 @@ it { is_expected.not_to create_package('glusterfs-client') } end end + context 'when server is false' do let :params do { server: false } @@ -54,6 +61,7 @@ it { is_expected.not_to create_package('glusterfs-server') } end end + context 'installing on an unsupported architecture' do let :facts do # deep_merge modifies facts in place @@ -66,7 +74,7 @@ when 'Archlinux', 'Suse' it { is_expected.not_to create_class('gluster::repo') } else - it { is_expected.to compile.and_raise_error(%r{not yet supported}) } + it { is_expected.to compile.and_raise_error(%r{not yet supported}) } unless os == 'ubuntu-22.04-x86_64' end end end diff --git a/spec/classes/repo_apt_spec.rb b/spec/classes/repo_apt_spec.rb index 82b8d8e2..f7cbbb81 100644 --- a/spec/classes/repo_apt_spec.rb +++ b/spec/classes/repo_apt_spec.rb @@ -1,19 +1,27 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'gluster::repo::apt', type: :class do on_supported_os.each do |os, os_facts| - context "on #{os}", if: os_facts[:os]['family'] == 'Debian' do + # Ubuntu 22.04 does not require a repo + context "on #{os}", if: os_facts[:os]['family'] == 'Debian' && os_facts[:os]['release']['major'] != '22.04' do let(:facts) { os_facts } let(:pre_condition) { 'require gluster::params' } context 'with all defaults' do it { is_expected.to contain_class('gluster::repo::apt') } it { is_expected.to compile.with_all_deps } + it 'installs' do + location = { + 'Debian' => "https://download.gluster.org/pub/gluster/glusterfs/7/LATEST/Debian/#{facts[:lsbdistcodename]}/#{facts[:architecture]}/apt/", + 'Ubuntu' => 'http://ppa.launchpad.net/gluster/glusterfs-7/ubuntu', + } is_expected.to contain_apt__source('glusterfs-LATEST').with( repos: 'main', release: facts[:lsbdistcodename].to_s, - location: "https://download.gluster.org/pub/gluster/glusterfs/7/LATEST/Debian/#{facts[:lsbdistcodename]}/#{facts[:architecture]}/apt/" + location: location[facts[:os]['name']] ) end end @@ -39,10 +47,14 @@ end it 'installs' do + location = { + 'Debian' => "https://download.gluster.org/pub/gluster/glusterfs/7/LATEST/Debian/#{facts[:lsbdistcodename]}/#{facts[:architecture]}/apt/", + 'Ubuntu' => 'http://ppa.launchpad.net/gluster/glusterfs-7/ubuntu', + } is_expected.to contain_apt__source('glusterfs-LATEST').with( repos: 'main', release: facts[:lsbdistcodename].to_s, - location: "https://download.gluster.org/pub/gluster/glusterfs/7/LATEST/Debian/#{facts[:lsbdistcodename]}/#{facts[:architecture]}/apt/", + location: location[facts[:os]['name']], pin: '700' ) end @@ -56,14 +68,25 @@ end it 'installs' do + location = { + 'Debian' => "https://download.gluster.org/pub/gluster/glusterfs/4.1/LATEST/Debian/#{facts[:lsbdistcodename]}/amd64/apt/", + 'Ubuntu' => 'http://ppa.launchpad.net/gluster/glusterfs-4.1/ubuntu', + } + key = { + 'Debian' => { + 'id' => 'EED3351AFD72E5437C050F0388F6CDEE78FA6D97', + 'source' => 'https://download.gluster.org/pub/gluster/glusterfs/4.1/rsa.pub', + }, + 'Ubuntu' => { + 'id' => 'F7C73FCC930AC9F83B387A5613E01B7B3FE869A9', + 'source' => nil, + }, + } is_expected.to contain_apt__source('glusterfs-LATEST').with( repos: 'main', release: facts[:lsbdistcodename].to_s, - key: { - 'id' => 'EED3351AFD72E5437C050F0388F6CDEE78FA6D97', - 'key_source' => 'https://download.gluster.org/pub/gluster/glusterfs/4.1/rsa.pub' - }, - location: "https://download.gluster.org/pub/gluster/glusterfs/4.1/LATEST/Debian/#{facts[:lsbdistcodename]}/amd64/apt/" + key: key[facts[:os]['name']], + location: location[facts[:os]['name']] ) end end @@ -76,14 +99,25 @@ end it 'installs' do + location = { + 'Debian' => "https://download.gluster.org/pub/gluster/glusterfs/01.old-releases/3.12/LATEST/Debian/#{facts[:lsbdistcodename]}/amd64/apt/", + 'Ubuntu' => 'http://ppa.launchpad.net/gluster/glusterfs-3.12/ubuntu', + } + key = { + 'Debian' => { + 'id' => '8B7C364430B66F0B084C0B0C55339A4C6A7BD8D4', + 'source' => 'https://download.gluster.org/pub/gluster/glusterfs/3.12/rsa.pub', + }, + 'Ubuntu' => { + 'id' => 'F7C73FCC930AC9F83B387A5613E01B7B3FE869A9', + 'source' => nil, + }, + } is_expected.to contain_apt__source('glusterfs-LATEST').with( repos: 'main', release: facts[:lsbdistcodename].to_s, - key: { - 'id' => '8B7C364430B66F0B084C0B0C55339A4C6A7BD8D4', - 'key_source' => 'https://download.gluster.org/pub/gluster/glusterfs/3.12/rsa.pub' - }, - location: "https://download.gluster.org/pub/gluster/glusterfs/01.old-releases/3.12/LATEST/Debian/#{facts[:lsbdistcodename]}/amd64/apt/" + key: key[facts[:os]['name']], + location: location[facts[:os]['name']] ) end end diff --git a/spec/classes/repo_yum_spec.rb b/spec/classes/repo_yum_spec.rb index 795baaa2..5a894b63 100644 --- a/spec/classes/repo_yum_spec.rb +++ b/spec/classes/repo_yum_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'gluster::repo::yum', type: :class do @@ -12,6 +14,7 @@ context 'with all defaults' do it { is_expected.to contain_class('gluster::repo::yum') } it { is_expected.to compile.with_all_deps } + it 'installs' do is_expected.not_to create_package('yum-plugin-priorities') is_expected.to create_yumrepo('glusterfs-x86_64').with( @@ -22,6 +25,7 @@ ) end end + context 'bogus version' do let :params do { @@ -33,6 +37,7 @@ is_expected.to compile.and_raise_error(%r{doesn't make sense!}) end end + context 'unsupported architecture' do let :facts do super().merge( @@ -44,6 +49,7 @@ is_expected.to compile.and_raise_error(%r{not yet supported}) end end + context 'latest Gluster with priority' do let :params do { diff --git a/spec/classes/service_spec.rb b/spec/classes/service_spec.rb index e00e69e5..2b470a1c 100644 --- a/spec/classes/service_spec.rb +++ b/spec/classes/service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'gluster::service', type: :class do @@ -9,13 +11,10 @@ context 'with all defaults' do it { is_expected.to compile.with_all_deps } + it 'starts the service' do case facts[:osfamily] - when 'Redhat' - is_expected.to create_service('glusterd') - when 'Debian' - is_expected.to create_service('glusterd') - when 'Archlinux' + when 'Archlinux', 'Debian', 'Redhat' is_expected.to create_service('glusterd') end end diff --git a/spec/defines/peer_spec.rb b/spec/defines/peer_spec.rb index db22f619..05ea734d 100644 --- a/spec/defines/peer_spec.rb +++ b/spec/defines/peer_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'gluster::peer', type: :define do @@ -37,6 +39,7 @@ it { is_expected.to compile } it { is_expected.not_to contain_exec('gluster peer probe peer1.example.com') } end + describe '2 peers' do let(:facts) do { @@ -65,6 +68,7 @@ it { is_expected.to compile } it { is_expected.to contain_exec('gluster peer probe peer1.example.com') } end + describe '1 peer' do let(:facts) do { @@ -78,6 +82,7 @@ it { is_expected.to compile } it { is_expected.to contain_exec('gluster peer probe peer1.example.com') } end + describe '2 peers' do let(:facts) do { @@ -106,6 +111,7 @@ end it { is_expected.to compile } + it 'we don\'t try to join with ourselves' do is_expected.not_to contain_exec('gluster peer probe peer1.example.com') end diff --git a/spec/defines/volume_spec.rb b/spec/defines/volume_spec.rb index f85c451d..da638266 100644 --- a/spec/defines/volume_spec.rb +++ b/spec/defines/volume_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'gluster::volume', type: :define do @@ -56,6 +58,7 @@ it { is_expected.to compile.with_all_deps } end end + describe 'with nonexistent volume' do let(:facts) do { @@ -71,6 +74,7 @@ end it { is_expected.to compile.with_all_deps } + it do is_expected.to contain_exec("gluster create volume #{title}").with( command: "/usr/sbin/gluster volume create #{title} #{args}" @@ -87,6 +91,7 @@ end it { is_expected.to compile.with_all_deps } + it do is_expected.to contain_exec("gluster create volume #{title}").with( command: "/usr/sbin/gluster volume create #{title} #{args}" @@ -107,6 +112,7 @@ it { is_expected.to compile.with_all_deps } it { is_expected.to contain_exec("gluster create volume #{title}") } end + describe 'with empty options' do let(:facts) do { diff --git a/spec/setup_acceptance_node.pp b/spec/setup_acceptance_node.pp new file mode 100644 index 00000000..dd504d99 --- /dev/null +++ b/spec/setup_acceptance_node.pp @@ -0,0 +1,8 @@ +if $facts['os']['name'] == 'Ubuntu' { + # Needed for facter to fetch facts used by the postgresql module + if versioncmp($facts['facterversion'], '4.0.0') <= 0 { + package{ 'lsb-release': + ensure => present, + } + } +} diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fb5f0cbe..9efb4ae6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,17 +1,20 @@ +# frozen_string_literal: true + # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ # puppetlabs_spec_helper will set up coverage if the env variable is set. # We want to do this if lib exists and it hasn't been explicitly set. -ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../../lib', __FILE__)) +ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../lib', __dir__)) require 'voxpupuli/test/spec_helper' +add_mocked_facts! + if File.exist?(File.join(__dir__, 'default_module_facts.yml')) facts = YAML.safe_load(File.read(File.join(__dir__, 'default_module_facts.yml'))) - if facts - facts.each do |name, value| - add_custom_fact name.to_sym, value - end + facts&.each do |name, value| + add_custom_fact name.to_sym, value end end +Dir['./spec/support/spec/**/*.rb'].sort.each { |f| require f } diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index d3b906bf..2681792e 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ require 'voxpupuli/acceptance/spec_helper_acceptance' -configure_beaker +configure_beaker(modules: :metadata) Dir['./spec/support/acceptance/**/*.rb'].sort.each { |f| require f } diff --git a/spec/unit/lib/facter/gluster_spec.rb b/spec/unit/lib/facter/gluster_spec.rb index 3d5a825a..c4b285c2 100644 --- a/spec/unit/lib/facter/gluster_spec.rb +++ b/spec/unit/lib/facter/gluster_spec.rb @@ -1,7 +1,10 @@ +# frozen_string_literal: true + # vim: syntax=ruby tabstop=2 softtabstop=2 shiftwidth=2 fdm=marker require 'spec_helper' +# rubocop:disable RSpec/MultipleMemoizedHelpers describe Facter::Util::Fact do before do Facter.clear @@ -345,37 +348,42 @@ allow(Facter).to receive(:value) # Stub all other calls allow(Facter).to receive(:value).with('gluster_custom_binary').and_return(gluster_binary) allow(File).to receive(:executable?).with(gluster_binary).and_return(true) - allow(Facter::Util::Resolution).to receive(:exec).with("#{gluster_binary} peer status --xml") { - 'Connection failed. Please check if gluster daemon is operational.' - } - allow(Facter::Util::Resolution).to receive(:exec).with("#{gluster_binary} volume info --xml") { - 'Connection failed. Please check if gluster daemon is operational.' - } + allow(Facter::Util::Resolution).to receive(:exec).with("#{gluster_binary} peer status --xml").and_return('Connection failed. Please check if gluster daemon is operational.') + allow(Facter::Util::Resolution).to receive(:exec).with("#{gluster_binary} volume info --xml").and_return('Connection failed. Please check if gluster daemon is operational.') end + it 'detect gluster binary' do expect(Facter.fact(:gluster_binary).value).to eq(gluster_binary) end + it 'null peer count' do expect(Facter.fact(:gluster_peer_count).value).to eq(0) end + it 'empty peer list' do expect(Facter.fact(:gluster_peer_list).value).to eq('') end + it 'empty peers hash' do expect(Facter.fact(:gluster_peers).value).to eq({}) end + it 'empty volumes hash' do expect(Facter.fact(:gluster_volumes).value).to eq({}) end + it 'nil gluster_volume_list' do expect(Facter.fact(:gluster_volume_list)).to eq(nil) end + it 'nil gluster_volume_volume_bricks' do expect(Facter.fact(:"gluster_volume_#{gluster_volume_one}_bricks")).to eq(nil) end + it 'nil gluster_volume_volume_options' do expect(Facter.fact(:"gluster_volume_#{gluster_volume_one}_options")).to eq(nil) end + it 'nil gluster_volume_volume_ports' do expect(Facter.fact(:"gluster_volume_#{gluster_volume_one}_ports")).to eq(nil) end @@ -392,30 +400,39 @@ allow(Facter::Util::Resolution).to receive(:exec).with("#{gluster_binary} peer status --xml") { gluster_no_peer } allow(Facter::Util::Resolution).to receive(:exec).with("#{gluster_binary} volume info --xml") { gluster_no_volume } end + it 'detect gluster binary' do expect(Facter.fact(:gluster_binary).value).to eq(gluster_binary) end + it 'null peer count' do expect(Facter.fact(:gluster_peer_count).value).to eq(0) end + it 'empty peer list' do expect(Facter.fact(:gluster_peer_list).value).to eq('') end + it 'empty peers hash' do expect(Facter.fact(:gluster_peers).value).to eq({}) end + it 'empty volumes hash' do expect(Facter.fact(:gluster_volumes).value).to eq({}) end + it 'nil gluster_volume_list' do expect(Facter.fact(:gluster_volume_list)).to eq(nil) end + it 'nil gluster_volume_volume_bricks' do expect(Facter.fact(:"gluster_volume_#{gluster_volume_one}_bricks")).to eq(nil) end + it 'nil gluster_volume_volume_options' do expect(Facter.fact(:"gluster_volume_#{gluster_volume_one}_options")).to eq(nil) end + it 'nil gluster_volume_volume_ports' do expect(Facter.fact(:"gluster_volume_#{gluster_volume_one}_ports")).to eq(nil) end @@ -432,30 +449,39 @@ allow(Facter::Util::Resolution).to receive(:exec).with("#{gluster_binary} peer status --xml") { gluster_peer_status_xml } allow(Facter::Util::Resolution).to receive(:exec).with("#{gluster_binary} volume info --xml") { gluster_no_volume } end + it 'detect gluster binary' do expect(Facter.fact(:gluster_binary).value).to eq(gluster_binary) end + it 'check gluster_peer_count integer' do expect(Facter.fact(:gluster_peer_count).value).to eq(gluster_peer_count) end + it 'check gluster_peer_list string' do expect(Facter.fact(:gluster_peer_list).value).to eq(gluster_peer_list) end + it 'check gluster_peers hash' do expect(Facter.fact(:gluster_peers).value).to eq(gluster_peers) end + it 'empty volumes hash' do expect(Facter.fact(:gluster_volumes).value).to eq({}) end + it 'nil gluster_volume_list' do expect(Facter.fact(:gluster_volume_list)).to eq(nil) end + it 'nil gluster_volume_volume_bricks' do expect(Facter.fact(:"gluster_volume_#{gluster_volume_one}_bricks")).to eq(nil) end + it 'nil gluster_volume_volume_options' do expect(Facter.fact(:"gluster_volume_#{gluster_volume_one}_options")).to eq(nil) end + it 'nil gluster_volume_volume_ports' do expect(Facter.fact(:"gluster_volume_#{gluster_volume_one}_ports")).to eq(nil) end @@ -473,30 +499,39 @@ allow(Facter::Util::Resolution).to receive(:exec).with("#{gluster_binary} volume info --xml") { gluster_volume_info_xml } allow(Facter::Util::Resolution).to receive(:exec).with("#{gluster_binary} volume status #{gluster_volume_one} --xml") { gluster_volume_one_status_xml } end + it 'detect gluster binary' do expect(Facter.fact(:gluster_binary).value).to eq(gluster_binary) end + it 'check gluster_peer_count integer' do expect(Facter.fact(:gluster_peer_count).value).to eq(gluster_peer_count) end + it 'check gluster_peer_list string' do expect(Facter.fact(:gluster_peer_list).value).to eq(gluster_peer_list) end + it 'check gluster_peers hash' do expect(Facter.fact(:gluster_peers).value).to eq(gluster_peers) end + it 'check gluster_volumes hash' do expect(Facter.fact(:gluster_volumes).value).to eq(gluster_volumes) end + it 'check gluster_volume_list string' do expect(Facter.fact(:gluster_volume_list).value).to eq(gluster_volume_list) end + it 'check gluster_volume_volume_bricks (comma separated string)' do expect(Facter.fact(:"gluster_volume_#{gluster_volume_one}_bricks").value).to eq(gluster_volumes[gluster_volume_one]['bricks'].join(',')) end + it 'check gluster_volume_volume_options (comma separated string)' do expect(Facter.fact(:"gluster_volume_#{gluster_volume_one}_options").value).to eq(gluster_volume_options[gluster_volume_one].join(',')) end + it 'check gluster_volume_volume_ports (comma separated string)' do expect(Facter.fact(:"gluster_volume_#{gluster_volume_one}_ports").value).to eq(gluster_volume_ports[gluster_volume_one]['ports'].join(',')) end @@ -504,3 +539,4 @@ # }}} end +# rubocop:enable RSpec/MultipleMemoizedHelpers