From 19f69fa2987b328dcdd8a5db9440fa999a60230d Mon Sep 17 00:00:00 2001 From: Mike Baynton Date: Sat, 1 Jun 2019 22:23:57 -0500 Subject: [PATCH 1/2] Add support for Systemd / Ubuntu 16.04 --- .fixtures.yml | 5 ++++ .gitattributes | 5 ++++ .gitignore | 37 ++++++++++++++++++------- manifests/process.pp | 52 ++++++++++++++++++++++++++---------- metadata.json | 29 +++++++++++++++++--- spec/classes/lsyncd_spec.rb | 11 ++++++++ spec/default_facts.yml | 7 +++++ spec/defines/process_spec.rb | 32 ++++++++++++++++++++++ spec/spec_helper.rb | 48 +++++++++++++++++++++++++++++---- templates/systemd_unit.epp | 16 +++++++++++ 10 files changed, 209 insertions(+), 33 deletions(-) create mode 100644 .fixtures.yml create mode 100644 .gitattributes create mode 100644 spec/classes/lsyncd_spec.rb create mode 100644 spec/default_facts.yml create mode 100644 spec/defines/process_spec.rb create mode 100644 templates/systemd_unit.epp diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000..a7fcf1c --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,5 @@ +--- +fixtures: + forge_modules: + stdlib: "puppetlabs/stdlib" + systemd: "camptocamp/systemd" diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9032a01 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +*.rb eol=lf +*.erb eol=lf +*.pp eol=lf +*.sh eol=lf +*.epp eol=lf diff --git a/.gitignore b/.gitignore index ff69698..2767022 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,27 @@ -.vagrant -*~ -.vagrantuser -*.swp -tags -*.orig -*.rej -Gemfile.lock -log -pkg +.git/ +.*.sw[op] +.metadata +.yardoc +.yardwarns +*.iml +/.bundle/ +/.idea/ +/.vagrant/ +/coverage/ +/bin/ +/doc/ +/Gemfile.local +/Gemfile.lock +/junit/ +/log/ +/pkg/ +/spec/fixtures/manifests/ +/spec/fixtures/modules/ +/tmp/ +/vendor/ +/convert_report.txt +/update_report.txt +.DS_Store +.project +.envrc +/inventory.yaml diff --git a/manifests/process.pp b/manifests/process.pp index 27b110f..0460597 100644 --- a/manifests/process.pp +++ b/manifests/process.pp @@ -20,10 +20,11 @@ # Group of the config file # define lsyncd::process ( - $source = undef, - $content = undef, - $owner = 'root', - $group = 'root', + $source = undef, + $content = undef, + $owner = 'root', + $group = 'root', + $systemd_template = 'lsyncd/systemd_unit.epp', ) { include lsyncd @@ -37,8 +38,6 @@ } $cfgfile = "${lsyncd::confdir}/${name}.lua" - $process = "lsyncd ${cfgfile}" - file { $cfgfile: ensure => file, owner => $owner, @@ -46,14 +45,39 @@ mode => '0644', source => $source, content => $content, - } ~> - - service { "lsyncd-${name}": - ensure => running, - provider => 'debian', - start => "sudo -u ${owner} ${process}", - status => "pgrep -f '^${process}$'", - stop => "pkill --signal KILL -f '^${process}$'", } + if ($facts['systemd']) { + $process = $facts['os']['family'] ? { + 'RedHat' => '/bin/lsyncd', + default => '/usr/local/bin/lsyncd' + } + + $template_hash = { + 'name' => $name, + 'lsyncd_path' => $process, + 'user' => $owner, + 'lua_file' => $cfgfile, + } + systemd::unit_file { "lsyncd-${name}.service": + content => epp($systemd_template, $template_hash) + } + ~> + service { "lsyncd-${name}": + ensure => 'running', + enable => true, + } + } else { + $process = "lsyncd ${cfgfile}" + + service { "lsyncd-${name}": + ensure => running, + provider => 'debian', + start => "sudo -u ${owner} ${process}", + status => "pgrep -f '^${process}$'", + stop => "pkill --signal KILL -f '^${process}$'", + require => File[$cfgfile] + } + + } } diff --git a/metadata.json b/metadata.json index 7dacbd4..aa6ebde 100644 --- a/metadata.json +++ b/metadata.json @@ -2,17 +2,38 @@ "name": "spjmurray-lsyncd", "version": "1.0.1", "author": "Simon Murray", - "license": "GPL-3.0", "summary": "Lsyncd orchestration", + "license": "GPL-3.0", "source": "https://github.com/spjmurray/puppet-lsyncd", "project_page": "https://github.com/spjmurray/puppet-lsyncd", "issues_url": "https://github.com/spjmurray/puppet-lsyncd/issues", - "tags": ["lsyncd"], "operatingsystem_support": [ { "operatingsystem": "Ubuntu", - "operatingsystemrelease": [ "14.04", "14.10", "15.04" ] + "operatingsystemrelease": [ + "14.04", + "14.10", + "15.04", + "16.04" + ] + } + ], + "dependencies": [ + { + "name": "camptocamp/systemd", + "version_requirement": ">= 2.2.0 < 3.0.0" } ], - "dependencies": [] + "requirements": [ + { + "name": "puppet", + "version_requirement": ">= 4.10.0 < 7.0.0" + } + ], + "tags": [ + "lsyncd" + ], + "pdk-version": "1.10.0", + "template-url": "file:///opt/puppetlabs/pdk/share/cache/pdk-templates.git#1.10.0", + "template-ref": "1.10.0-0-gbba9ac3" } diff --git a/spec/classes/lsyncd_spec.rb b/spec/classes/lsyncd_spec.rb new file mode 100644 index 0000000..0fc9d6a --- /dev/null +++ b/spec/classes/lsyncd_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe 'lsyncd' do + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:facts) { os_facts } + + it { is_expected.to compile } + end + end +end diff --git a/spec/default_facts.yml b/spec/default_facts.yml new file mode 100644 index 0000000..ea1e480 --- /dev/null +++ b/spec/default_facts.yml @@ -0,0 +1,7 @@ +# Use default_module_facts.yml for module specific facts. +# +# Facts specified here will override the values provided by rspec-puppet-facts. +--- +ipaddress: "172.16.254.254" +is_pe: false +macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/defines/process_spec.rb b/spec/defines/process_spec.rb new file mode 100644 index 0000000..3f8c11e --- /dev/null +++ b/spec/defines/process_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +describe 'lsyncd::process' do + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:title) { 'test' } + let(:params) { {'content' => 'test'} } + let(:facts) { os_facts } + + it { is_expected.to compile } + end + end + + systemd = { + :supported_os => [ + { + 'operatingsystem' => 'Ubuntu', + 'operatingsystemrelease' => ['16.04'], + } + ], + } + on_supported_os(systemd).each do |os, os_facts| + context "on #{os} (testing systemd)" do + let(:title) { 'test' } + let(:params) { {'content' => 'test'} } + let(:facts) { os_facts.merge({'systemd' => true}) } + + it { is_expected.to compile } + it { is_expected.to contain_systemd__unit_file('lsyncd-test.service') } + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b55ede8..93b25ec 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,9 +1,47 @@ -require 'rspec-puppet' +require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-facts' -fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) +require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) + +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.module_path = File.join(fixture_path, 'modules') - c.manifest_dir = File.join(fixture_path, 'manifests') - c.environmentpath = File.join(Dir.pwd, 'spec') + 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 +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/templates/systemd_unit.epp b/templates/systemd_unit.epp new file mode 100644 index 0000000..ed66c75 --- /dev/null +++ b/templates/systemd_unit.epp @@ -0,0 +1,16 @@ +<%- | String $name, + String $lsyncd_path, + String $user, + String $lua_file +| -%> +[Unit] +Description=Live Syncing (Mirror) Daemon - <%= $name %> +After=network.target + +[Service] +Type=simple +User=<%= $user %> +ExecStart=/usr/bin/lsyncd -nodaemon <%= $lua_file %> + +[Install] +WantedBy=multi-user.target From b88e00dceca0aa10bb0584c9b93eed111a90257a Mon Sep 17 00:00:00 2001 From: Mike Baynton Date: Sat, 1 Jun 2019 22:26:33 -0500 Subject: [PATCH 2/2] Revert pdk-made changes to spec_helper.rb The pdk rewrote this file, but this module uses beaker tests, which pdk doesn't even support currently. --- spec/spec_helper.rb | 48 +++++---------------------------------------- 1 file changed, 5 insertions(+), 43 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 93b25ec..b55ede8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,47 +1,9 @@ -require 'puppetlabs_spec_helper/module_spec_helper' -require 'rspec-puppet-facts' +require 'rspec-puppet' -require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) - -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 +fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) 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 -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 + c.module_path = File.join(fixture_path, 'modules') + c.manifest_dir = File.join(fixture_path, 'manifests') + c.environmentpath = File.join(Dir.pwd, 'spec') end - -# 'spec_overrides' from sync.yml will appear below this line