Skip to content

Commit

Permalink
Fix mkconfig calls (#64)
Browse files Browse the repository at this point in the history
Fixed:
  * Moved the puppetx/augeasproviders_grub/menuentry.rb file to util.rb
    to match the module name
  * Modified all `flush` functions to call the 'global update' mkconfig
    which was added as `PuppetX::AugeasprovidersGrub::Util.mkconfig`
  * Removed EL6 from the beaker tests since the OS is no longer
    supported by the vendor and fails to run

Added:
  * Puppet 7 support
  * EL8.1+ support

Changed:
  * Updated the travis.yml to run faster

Closes #63

fix super calls in flush

try to speed up travis builds

install unbuffer in travis

fix provider inheritance

add augeas tools
  • Loading branch information
trevor-vaughan authored Jan 14, 2021
1 parent 5378c62 commit 63c2c4b
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 165 deletions.
22 changes: 16 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
language: ruby
sudo: required
version: ~> 1.0
os: linux
sudo: false
bundler_args: --without development system_tests --path vendor

addons:
apt:
packages:
# provides unbuffer
- expect-dev
- libaugeas-dev
- augeas-tools

rvm:
- 2.4.4
- 2.5.8
notifications:
email:
- [email protected]
Expand All @@ -11,15 +23,13 @@ env:
- PUPPET=5.5 RUBY_AUGEAS=0.5 FORGE_PUBLISH=true
# Test latest Puppet version
- PUPPET=6 RUBY_AUGEAS=0.5

- PUPPET=7 RUBY_AUGEAS=0.5

matrix:
fast_finish: true

install:
- "travis_retry ./.travis.sh"
script:
- AUGEAS_LENS_LIB=lib/augeas/lenses:augeas/lenses bundle exec rake
- AUGEAS_LENS_LIB=lib/augeas/lenses:augeas/lenses travis_wait 45 unbuffer bundle exec rake
# Do not include the augeas/ directory in the deployed module
- rm -rf augeas/
deploy:
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ normal.

See [Puppet/Augeas pre-requisites](http://docs.puppetlabs.com/guides/augeas.html#pre-requisites).

**WARNING** Your system must be able to run the grub mkconfig scripts with BLS
support if you are on a systen that uses BLS!

## Installing

On Puppet 2.7.14+, the module can be installed easily ([documentation](http://docs.puppetlabs.com/puppet/latest/reference/modules_installing.html)):
Expand Down
26 changes: 3 additions & 23 deletions lib/puppet/provider/grub_config/grub2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,9 @@ def value=(newval)
end

def flush
os_info = Facter.value(:os)
if os_info
os_name = Facter.value(:os)['name']
else
# Support for old versions of Facter
unless os_name
os_name = Facter.value(:operatingsystem)
end
end

cfg = nil
[
"/etc/grub2-efi.cfg",
# Handle the standard EFI naming convention
"/boot/efi/EFI/#{os_name.downcase}/grub.cfg",
"/boot/grub2/grub.cfg",
"/boot/grub/grub.cfg"
].each {|c|
cfg = c if FileTest.file? c
}
fail("Cannot find grub.cfg location to use with grub-mkconfig") unless cfg

super
mkconfig "-o", cfg

require 'puppetx/augeasproviders_grub/util'
PuppetX::AugeasprovidersGrub::Util.grub2_mkconfig(mkconfig)
end
end
4 changes: 2 additions & 2 deletions lib/puppet/provider/grub_menuentry/grub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def self.get_modules(aug, path)
end

def self.instances
require 'puppetx/augeasproviders_grub/menuentry'
require 'puppetx/augeasproviders_grub/util'

resources = []

Expand Down Expand Up @@ -132,7 +132,7 @@ def self.instances


def initialize(*args)
require 'puppetx/augeasproviders_grub/menuentry'
require 'puppetx/augeasproviders_grub/util'

@grubby_info = {}
begin
Expand Down
61 changes: 9 additions & 52 deletions lib/puppet/provider/grub_menuentry/grub2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright (c) 2016 Trevor Vaughan <[email protected]>
# Licensed under the Apache License, Version 2.0

Puppet::Type.type(:grub_menuentry).provide(:grub2) do
Puppet::Type.type(:grub_menuentry).provide(:grub2, :parent => Puppet::Type.type(:augeasprovider).provider(:default)) do
desc "Provides for the manipulation of GRUB2 menuentries"

has_feature :grub2
Expand Down Expand Up @@ -236,7 +236,7 @@ def self.grub2_menuentries(config, current_default)
end

def self.instances
require 'puppetx/augeasproviders_grub/menuentry'
require 'puppetx/augeasproviders_grub/util'

@grubby_default_index ||= (grubby '--default-index').strip

Expand Down Expand Up @@ -269,7 +269,7 @@ def self.prefetch(resources)
def initialize(*args)
super(*args)

require 'puppetx/augeasproviders_grub/menuentry'
require 'puppetx/augeasproviders_grub/util'

@grubby_info = {}
begin
Expand Down Expand Up @@ -490,6 +490,10 @@ def initrd=(newval)
end

def flush
super

require 'puppetx/augeasproviders_grub/util'

@property_hash[:name] = self.name

if @property_hash[:kernel] =~ /(\d.+)/
Expand Down Expand Up @@ -536,7 +540,7 @@ def flush
FileUtils.rm_f(legacy_target)

# Need to rebuild the full grub config if we removed a legacy target
grub2_mkconfig
PuppetX::AugeasprovidersGrub::Util.grub2_mkconfig(mkconfig)
end
end
else
Expand Down Expand Up @@ -568,7 +572,7 @@ def flush
# Need to remove the BLS config if we moved it to be legacy
FileUtils.rm_f(bls_target) if File.exist?(bls_target)

grub2_mkconfig
PuppetX::AugeasprovidersGrub::Util.grub2_mkconfig(mkconfig)
end
end

Expand Down Expand Up @@ -746,51 +750,4 @@ def construct_grub2cfg_entry(property_hash, header_comment='### PUPPET MANAGED #

return output
end

# Run the grub2-mkconfig command on the discovered file paths deconflicting
# across symlinks
def grub2_mkconfig(cfg_paths=[])
tgt_files = []

os_info = Facter.value(:os)
if os_info
os_name = Facter.value(:os)['name']
else
# Support for old versions of Facter
unless os_name
os_name = Facter.value(:operatingsystem)
end
end

cfg_paths = [
"/etc/grub2.cfg",
"/etc/grub2-efi.cfg",
# Handle the standard EFI naming convention
"/boot/efi/EFI/#{os_name.downcase}/grub.cfg",
"/boot/grub2/grub.cfg",
"/boot/grub/grub.cfg"
] if cfg_paths.empty?

cfg_paths.each do |path|
begin
tgt_files << File.realpath(path)
rescue
next
end
end

cfg_paths = cfg_paths.select{|x| FileTest.file?(x)}

fail("Cannot find a grub configuration at any of '#{cfg_paths.join(', ')}' to use with #{command(:mkconfig)}") if cfg_paths.empty?

# This takes a while to run
mkconfig_output = mkconfig

tgt_files.uniq.each do |cfg_path|
File.open(cfg_path, 'w') do |fh|
fh.puts(mkconfig_output)
fh.flush
end
end
end
end
13 changes: 8 additions & 5 deletions lib/puppet/provider/grub_user/grub2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright (c) 2016 Trevor Vaughan <[email protected]>
# Licensed under the Apache License, Version 2.0

Puppet::Type.type(:grub_user).provide(:grub2) do
Puppet::Type.type(:grub_user).provide(:grub2, :parent => Puppet::Type.type(:augeasprovider).provider(:default)) do
desc "Provides for the manipulation of GRUB2 User Entries"

has_feature :grub2
Expand All @@ -21,7 +21,7 @@ def self.mkconfig_path
mk_resource_methods

def self.grub2_cfg
require 'puppetx/augeasproviders_grub/menuentry'
require 'puppetx/augeasproviders_grub/util'

PuppetX::AugeasprovidersGrub::Util.grub2_cfg
end
Expand All @@ -31,7 +31,7 @@ def grub2_cfg
end

def self.grub2_cfg_path
require 'puppetx/augeasproviders_grub/menuentry'
require 'puppetx/augeasproviders_grub/util'

PuppetX::AugeasprovidersGrub::Util.grub2_cfg_path
end
Expand Down Expand Up @@ -223,6 +223,8 @@ def purge
end

def flush
super

# This is to clean up the legacy file that was put in place incorrectly
# prior to the standard 01_users configuration file
legacy_file = '/etc/grub.d/01_puppet_managed_users'
Expand Down Expand Up @@ -275,7 +277,7 @@ def flush
# This really shouldn't happen but could if people start adding users in other files.
if output == @property_hash[:_target_file_content]
err("Please ensure that your *active* GRUB2 configuration is correct. #{self.class} thinks that you need an update, but your file content did not change")
else output == @property_hash[:_target_file_content]
else
fh = File.open(resource[:target], 'w')
fh.puts(output)
fh.flush
Expand All @@ -284,7 +286,8 @@ def flush
FileUtils.chmod(0755, resource[:target])
end

mkconfig "-o", grub2_cfg_path
require 'puppetx/augeasproviders_grub/util'
PuppetX::AugeasprovidersGrub::Util.grub2_mkconfig(mkconfig)
end

private
Expand Down
33 changes: 3 additions & 30 deletions lib/puppet/provider/kernel_parameter/grub2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,36 +154,9 @@ def value=(newval)
end

def flush
os_info = Facter.value(:os)
if os_info
os_name = Facter.value(:os)['name']
else
# Support for old versions of Facter
unless os_name
os_name = Facter.value(:operatingsystem)
end
end

cfg = []
[
"/etc/grub2-efi.cfg",
# Handle the standard EFI naming convention
"/boot/efi/EFI/#{os_name.downcase}/grub.cfg",
"/boot/grub2/grub.cfg",
"/boot/grub/grub.cfg"
].each {|c|
if FileTest.file?(c) || ( FileTest.symlink?(c) &&
FileTest.directory?(File.dirname(File.absolute_path(File.readlink(c)))) )

cfg << c

end
}
fail("Cannot find grub.cfg location to use with grub-mkconfig") unless cfg

super
cfg.each {|c|
mkconfig "-o", c
}

require 'puppetx/augeasproviders_grub/util'
PuppetX::AugeasprovidersGrub::Util.grub2_mkconfig(mkconfig)
end
end
Loading

0 comments on commit 63c2c4b

Please sign in to comment.