diff --git a/lib/puppet/provider/a2mod/a2mod.rb b/lib/puppet/provider/a2mod/a2mod.rb deleted file mode 100644 index 3330fd5dcc..0000000000 --- a/lib/puppet/provider/a2mod/a2mod.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -require 'puppet/provider/a2mod' - -Puppet::Type.type(:a2mod).provide(:a2mod, parent: Puppet::Provider::A2mod) do - desc 'Manage Apache 2 modules on Debian and Ubuntu' - - optional_commands encmd: 'a2enmod' - optional_commands discmd: 'a2dismod' - commands apache2ctl: 'apache2ctl' - - confine osfamily: :debian - defaultfor operatingsystem: [:debian, :ubuntu] - - def self.instances - modules = apache2ctl('-M').lines.map { |line| - m = line.match(%r{(\w+)_module \(shared\)$}) - m[1] if m - }.compact - - modules.map do |mod| - new( - name: mod, - ensure: :present, - provider: :a2mod, - ) - end - end - - def create - encmd resource[:name] - end - - def destroy - discmd resource[:name] - end -end diff --git a/lib/puppet/provider/a2mod/gentoo.rb b/lib/puppet/provider/a2mod/gentoo.rb deleted file mode 100644 index c53fbd5b6e..0000000000 --- a/lib/puppet/provider/a2mod/gentoo.rb +++ /dev/null @@ -1,116 +0,0 @@ -# frozen_string_literal: true - -require 'puppet/util/filetype' -Puppet::Type.type(:a2mod).provide(:gentoo, parent: Puppet::Provider) do - desc 'Manage Apache 2 modules on Gentoo' - - confine operatingsystem: :gentoo - defaultfor operatingsystem: :gentoo - - attr_accessor :property_hash - - def create - @property_hash[:ensure] = :present - end - - def exists? - (!@property_hash[:ensure].nil? && @property_hash[:ensure] == :present) - end - - def destroy - @property_hash[:ensure] = :absent - end - - def flush - self.class.flush - end - - class << self - attr_reader :conf_file - end - - def self.clear - @mod_resources = [] - @modules = [] - @other_args = '' - end - - def self.initvars - @conf_file = '/etc/conf.d/apache2' - @filetype = Puppet::Util::FileType.filetype(:flat).new(conf_file) - @mod_resources = [] - @modules = [] - @other_args = '' - end - - initvars - - # Retrieve an array of all existing modules - def self.modules - if @modules.length <= 0 - # Locate the APACHE_OPTS variable - records = filetype.read.split(%r{\n}) - apache2_opts = records.grep(%r{^\s*APACHE2_OPTS=}).first - - # Extract all defines - @modules << Regexp.last_match(1).downcase while apache2_opts.sub!(%r{-D\s+(\w+)}, '') - - # Hang on to any remaining options. - if apache2_opts =~ %r{APACHE2_OPTS="(.+)"} - @other_args = Regexp.last_match(1).strip - end - - @modules.sort!.uniq! - end - - @modules - end - - def self.prefetch(resources = {}) - # Match resources with existing providers - instances.each do |provider| - resource = resources[provider.name] - if resource - resource.provider = provider - end - end - - # Store all resources using this provider for flushing - resources.each do |_name, resource| - @mod_resources << resource - end - end - - def self.instances - modules.map { |mod| new(name: mod, provider: :gentoo, ensure: :present) } - end - - def self.flush - mod_list = modules - mods_to_remove = @mod_resources.select { |mod| mod.should(:ensure) == :absent }.map { |mod| mod[:name] } - mods_to_add = @mod_resources.select { |mod| mod.should(:ensure) == :present }.map { |mod| mod[:name] } - - mod_list -= mods_to_remove - mod_list += mods_to_add - mod_list.sort!.uniq! - - return unless modules != mod_list - - opts = @other_args + ' ' - opts << mod_list.map { |mod| "-D #{mod.upcase}" }.join(' ') - opts.strip! - opts.gsub!(%r{\s+}, ' ') - - apache2_opts = %(APACHE2_OPTS="#{opts}") - Puppet.debug("Writing back \"#{apache2_opts}\" to #{conf_file}") - - records = filetype.read.split(%r{\n}) - - opts_index = records.find_index { |i| i.match(%r{^\s*APACHE2_OPTS}) } - records[opts_index] = apache2_opts - - filetype.backup - filetype.write(records.join("\n")) - @modules = mod_list - end -end diff --git a/lib/puppet/provider/a2mod/modfix.rb b/lib/puppet/provider/a2mod/modfix.rb deleted file mode 100644 index 755c927e45..0000000000 --- a/lib/puppet/provider/a2mod/modfix.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -Puppet::Type.type(:a2mod).provide :modfix do - desc "Dummy provider for A2mod. - Fake nil resources when there is no crontab binary available. Allows - puppetd to run on a bootstrapped machine before a Cron package has been - installed. Workaround for: http://projects.puppetlabs.com/issues/2384 - " - - def self.instances - [] - end -end diff --git a/lib/puppet/provider/a2mod/redhat.rb b/lib/puppet/provider/a2mod/redhat.rb deleted file mode 100644 index 149a7b909b..0000000000 --- a/lib/puppet/provider/a2mod/redhat.rb +++ /dev/null @@ -1,62 +0,0 @@ -# frozen_string_literal: true - -require 'puppet/provider/a2mod' - -Puppet::Type.type(:a2mod).provide(:redhat, parent: Puppet::Provider::A2mod) do - desc 'Manage Apache 2 modules on RedHat family OSs' - - commands apachectl: 'apachectl' - - confine osfamily: :redhat - defaultfor osfamily: :redhat - - require 'pathname' - - # modpath: Path to default apache modules directory /etc/httpd/mod.d - # modfile: Path to module load configuration file; Default: resides under modpath directory - # libfile: Path to actual apache module library. Added in modfile LoadModule - - attr_accessor :modfile, :libfile - class << self - attr_accessor :modpath - def preinit - @modpath = '/etc/httpd/mod.d' - end - end - - preinit - - def create - File.open(modfile, 'w') do |f| - f.puts "LoadModule #{resource[:identifier]} #{libfile}" - end - end - - def destroy - File.delete(modfile) - end - - def self.instances - modules = apachectl('-M').lines.map { |line| - m = line.match(%r{(\w+)_module \(shared\)$}) - m[1] if m - }.compact - - modules.map do |mod| - new( - name: mod, - ensure: :present, - provider: :redhat, - ) - end - end - - def modfile - "#{self.class.modpath}/#{resource[:name]}.load" - end - - # Set libfile path: If absolute path is passed, then maintain it. Else, make it default from 'modules' dir. - def libfile - Pathname.new(resource[:lib]).absolute? ? resource[:lib] : "modules/#{resource[:lib]}" - end -end diff --git a/lib/puppet/type/a2mod.rb b/lib/puppet/type/a2mod.rb deleted file mode 100644 index da04d7f4d8..0000000000 --- a/lib/puppet/type/a2mod.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -Puppet::Type.newtype(:a2mod) do - @doc = 'Manage Apache 2 modules' - - ensurable - - newparam(:name) do - Puppet.warning 'The a2mod provider is deprecated, please use apache::mod instead' - desc 'The name of the module to be managed' - - isnamevar - end - - newparam(:lib) do - desc 'The name of the .so library to be loaded' - - defaultto { "mod_#{@resource[:name]}.so" } - end - - newparam(:identifier) do - desc 'Module identifier string used by LoadModule. Default: module-name_module' - - # http://httpd.apache.org/docs/2.2/mod/module-dict.html#ModuleIdentifier - - defaultto { "#{resource[:name]}_module" } - end - - autorequire(:package) { catalog.resource(:package, 'httpd') } -end diff --git a/spec/unit/provider/a2mod/gentoo_spec.rb b/spec/unit/provider/a2mod/gentoo_spec.rb deleted file mode 100644 index 2fb48f34a1..0000000000 --- a/spec/unit/provider/a2mod/gentoo_spec.rb +++ /dev/null @@ -1,179 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -provider_class = Puppet::Type.type(:a2mod).provider(:gentoo) - -describe provider_class do - before :each do - provider_class.clear - end - - [:conf_file, :instances, :modules, :initvars, :conf_file, :clear].each do |method| - it "responds to the class method #{method}" do - expect(provider_class).to respond_to(method) - end - end - describe 'when fetching modules' do - let(:filetype) do - double - end - - it 'returns a sorted array of the defined parameters' do - expect(filetype).to receive(:read).and_return(%(APACHE2_OPTS="-D FOO -D BAR -D BAZ"\n)) - expect(provider_class).to receive(:filetype) { filetype } - - expect(provider_class.modules).to eq(['bar', 'baz', 'foo']) - end - - it 'caches the module list' do - expect(filetype).to receive(:read).once { %(APACHE2_OPTS="-D FOO -D BAR -D BAZ"\n) } # rubocop:disable Lint/AmbiguousBlockAssociation - expect(provider_class).to receive(:filetype).once { filetype } # rubocop:disable Lint/AmbiguousBlockAssociation - - 2.times { expect(provider_class.modules).to eq(['bar', 'baz', 'foo']) } - end - - it 'normalizes parameters' do - expect(filetype).to receive(:read).and_return(%(APACHE2_OPTS="-D FOO -D BAR -D BAR"\n)) - expect(provider_class).to receive(:filetype) { filetype } - expect(provider_class.modules).to eq(['bar', 'foo']) - end - end - - describe 'when prefetching' do - it 'matches providers to resources' do - provider = instance_double('ssl_provider', name: 'ssl') - resource = instance_double('ssl_resource') - expect(resource).to receive(:provider=).with(provider) - - expect(provider_class).to receive(:instances) { [provider] } - provider_class.prefetch('ssl' => resource) - end - end - describe 'when flushing' do - let(:filetype) { double } - let(:info) { double } - let(:mpm) { double } - let(:ssl) { double } - - before :each do - allow(filetype).to receive(:backup) - allow(provider_class).to receive(:filetype).at_least(:once) { filetype } - - allow(info).to receive(:[]).with(:name) { 'info' } - allow(info).to receive(:provider=) - - allow(mpm).to receive(:[]).with(:name) { 'mpm' } - allow(mpm).to receive(:provider=) - - allow(ssl).to receive(:[]).with(:name) { 'ssl' } - allow(ssl).to receive(:provider=) - end - it 'adds modules whose ensure is present' do - expect(filetype).to receive(:read).at_least(:once) { %(APACHE2_OPTS="") } - expect(filetype).to receive(:write).with(%(APACHE2_OPTS="-D INFO")) - - allow(info).to receive(:should).with(:ensure) { :present } - provider_class.prefetch('info' => info) - - provider_class.flush - end - it 'removes modules whose ensure is present' do - expect(filetype).to receive(:read).at_least(:once) { %(APACHE2_OPTS="-D INFO") } - expect(filetype).to receive(:write).with(%(APACHE2_OPTS="")) - - allow(info).to receive(:should).with(:ensure) { :absent } - allow(info).to receive(:provider=) - provider_class.prefetch('info' => info) - - provider_class.flush - end - - it 'does not modify providers without resources' do - expect(filetype).to receive(:read).at_least(:once) { %(APACHE2_OPTS="-D INFO -D MPM") } - expect(filetype).to receive(:write).with(%(APACHE2_OPTS="-D MPM -D SSL")) - - allow(info).to receive(:should).with(:ensure) { :absent } - provider_class.prefetch('info' => info) - - allow(ssl).to receive(:should).with(:ensure) { :present } - provider_class.prefetch('ssl' => ssl) - - provider_class.flush - end - - it 'writes the modules in sorted order' do - expect(filetype).to receive(:read).at_least(:once) { %(APACHE2_OPTS="") } - expect(filetype).to receive(:write).with(%(APACHE2_OPTS="-D INFO -D MPM -D SSL")) - - allow(mpm).to receive(:should).with(:ensure) { :present } - provider_class.prefetch('mpm' => mpm) - allow(info).to receive(:should).with(:ensure) { :present } - provider_class.prefetch('info' => info) - allow(ssl).to receive(:should).with(:ensure) { :present } - provider_class.prefetch('ssl' => ssl) - - provider_class.flush - end - - it 'writes the records back once' do - expect(filetype).to receive(:read).at_least(:once) { %(APACHE2_OPTS="") } - expect(filetype).to receive(:write).once.with(%(APACHE2_OPTS="-D INFO -D SSL")) - - allow(info).to receive(:should).with(:ensure) { :present } - provider_class.prefetch('info' => info) - - allow(ssl).to receive(:should).with(:ensure) { :present } - provider_class.prefetch('ssl' => ssl) - - provider_class.flush - end - - it 'onlies modify the line containing APACHE2_OPTS' do - expect(filetype).to receive(:read).at_least(:once) { %(# Comment\nAPACHE2_OPTS=""\n# Another comment) } - expect(filetype).to receive(:write).once.with(%(# Comment\nAPACHE2_OPTS="-D INFO"\n# Another comment)) - - allow(info).to receive(:should).with(:ensure) { :present } - provider_class.prefetch('info' => info) - provider_class.flush - end - - it 'restores any arbitrary arguments' do - expect(filetype).to receive(:read).at_least(:once) { %(APACHE2_OPTS="-Y -D MPM -X") } - expect(filetype).to receive(:write).once.with(%(APACHE2_OPTS="-Y -X -D INFO -D MPM")) - - allow(info).to receive(:should).with(:ensure) { :present } - provider_class.prefetch('info' => info) - provider_class.flush - end - - it 'backups the file once if changes were made' do - expect(filetype).to receive(:read).at_least(:once) { %(APACHE2_OPTS="") } - expect(filetype).to receive(:write).once.with(%(APACHE2_OPTS="-D INFO -D SSL")) - - allow(info).to receive(:should).with(:ensure) { :present } - provider_class.prefetch('info' => info) - - allow(ssl).to receive(:should).with(:ensure) { :present } - provider_class.prefetch('ssl' => ssl) - - expect(filetype).to receive(:backup) - - provider_class.flush - end - - it 'does not write the file or run backups if no changes were made' do - expect(filetype).to receive(:read).at_least(:once) { %(APACHE2_OPTS="-X -D INFO -D SSL -Y") } - expect(filetype).to receive(:write).never - - allow(info).to receive(:should).with(:ensure) { :present } - provider_class.prefetch('info' => info) - - allow(ssl).to receive(:should).with(:ensure) { :present } - provider_class.prefetch('ssl' => ssl) - - expect(filetype).to receive(:backup).never - provider_class.flush - end - end -end