Skip to content

Commit

Permalink
(maint) Pass the appropriate Puppetfile path to module loader
Browse files Browse the repository at this point in the history
Previously, we always passed the `puppetfile_name` from the `R10K::Puppetfile`
class to `R10K::ModuleLoader::Puppetfile`. That was an attempt to fix a bug
where relative Puppetfile paths were not getting resolved correctly by the
module loader (9082511).
That, however, unearthed another bug: when instantiating a new instance of
`R10K::Puppetfile` with the `puppetfile_path` option, that path would get
completely ignored in favor of the default `puppetfile_name` value. This broke
usage of the `r10k puppetfile purge` command.

This commit ensures that we pass the appropriate Puppetfile path to the module
loader - we pass the `puppetfile_path` if it exists, otherwise we pass the
`puppetfile_name`. In order to maintain the fix for the original bug around
relative Puppetfile paths, we no longer attempt to resolve the `puppetfile_path`
in the `R10K::Puppetfile` class, since `R10K::ModuleLoader::Puppetfile` already
handles that resolution.
  • Loading branch information
mwaggett committed Aug 13, 2021
1 parent 7880c0c commit 8d37831
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/r10k/module_loader/puppetfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Puppetfile
DEFAULT_FORGE_API = 'forgeapi.puppetlabs.com'

attr_accessor :default_branch_override, :environment
attr_reader :modules, :moduledir,
attr_reader :modules, :moduledir, :puppetfile_path,
:managed_directories, :desired_contents, :purge_exclusions

# @param basedir [String] The path that contains the moduledir &
Expand Down
19 changes: 10 additions & 9 deletions lib/r10k/puppetfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ class Puppetfile
# @return [String] The base directory that contains the Puppetfile
attr_reader :basedir

# @!attrbute [r] puppetfile_path
# @return [String] The path to the Puppetfile
attr_reader :puppetfile_path

# @!attribute [r] environment
# @return [R10K::Environment] Optional R10K::Environment that this Puppetfile belongs to.
attr_reader :environment
Expand Down Expand Up @@ -68,8 +64,9 @@ def initialize(basedir, options_or_moduledir = nil, deprecated_path_arg = nil, d

@force = deprecated_force_arg || options.delete(:force) || false
@moduledir = deprecated_moduledir_arg || options.delete(:moduledir) || File.join(basedir, 'modules')
@puppetfile_name = deprecated_name_arg || options.delete(:puppetfile_name) || 'Puppetfile'
@puppetfile_path = deprecated_path_arg || options.delete(:puppetfile_path) || File.join(basedir, @puppetfile_name)
puppetfile_name = deprecated_name_arg || options.delete(:puppetfile_name) || 'Puppetfile'
puppetfile_path = deprecated_path_arg || options.delete(:puppetfile_path)
@puppetfile = puppetfile_path || puppetfile_name
@environment = options.delete(:environment)

@overrides = options.delete(:overrides) || {}
Expand All @@ -80,7 +77,7 @@ def initialize(basedir, options_or_moduledir = nil, deprecated_path_arg = nil, d
@loader = ::R10K::ModuleLoader::Puppetfile.new(
basedir: @basedir,
moduledir: @moduledir,
puppetfile: @puppetfile_name,
puppetfile: @puppetfile,
forge: @forge,
overrides: @overrides,
environment: @environment
Expand All @@ -104,8 +101,8 @@ def load(default_branch_override = nil)
if self.loaded?
return @loaded_content
else
if !File.readable?(@puppetfile_path)
logger.debug _("Puppetfile %{path} missing or unreadable") % {path: @puppetfile_path.inspect}
if !File.readable?(puppetfile_path)
logger.debug _("Puppetfile %{path} missing or unreadable") % {path: puppetfile_path.inspect}
else
self.load!(default_branch_override)
end
Expand Down Expand Up @@ -154,6 +151,10 @@ def moduledir
@loader.moduledir
end

def puppetfile_path
@loader.puppetfile_path
end

def environment=(env)
@loader.environment = env
@environment = env
Expand Down

0 comments on commit 8d37831

Please sign in to comment.