r10k 3.12.1 → 3.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5500f864c81a0b1ff5f48461bca9de375450f452028a93d381ec65eac3b35865
4
- data.tar.gz: 1d675799b9bf1df2ee328780bc90ed4e79c02bf7706a166dd40f5af952e9610a
3
+ metadata.gz: 13a5d7be1f8e4f5794ad944ef12cfbe32d6a7e704371e8f8137227507857600a
4
+ data.tar.gz: a9060539b639c566371a1c23c28d19910d63649dedeca67ab4b9237d0a43bfab
5
5
  SHA512:
6
- metadata.gz: cc75dcceceb3b368c6ee9dd1773a92530e67a59b1e35b52e3d8205d3dffb6b1b7d4b927edbe58bc828d9a1782d1052254464ca7c0556ea6099c5975811ddad1a
7
- data.tar.gz: 12ecfa266d5c7cafc1a6656bb54d5429ecb030c2b89af8d61a2dcd6587f8bc1ff6f94221a4f185d9e463a96df652d2434adec0c59a78288bc44dda087c67ca12
6
+ metadata.gz: aa2a7a28f9d30468bd17d6e54b4e6202a3290779391efe95409a16648f2eb81a5dd7483964b9c7d3bad8fafbb808fa99a86b6a7c2c0cdac5a5f1d5140e20efd0
7
+ data.tar.gz: 1ee18ff19d30c76a6f00a9650eff77ccf0cae1f60c789a5ae8c90fd725a8c4197f587d4bc1d6a6288b8452ba1c3db07cdfa30030d7fad7e130639283b5f56722
data/CHANGELOG.mkd CHANGED
@@ -4,6 +4,15 @@ CHANGELOG
4
4
  Unreleased
5
5
  ----------
6
6
 
7
+ 3.13.0
8
+ ------
9
+
10
+ - Restore Ruby 3 compatibility [#1234](https://github.com/puppetlabs/r10k/pull/1234)
11
+ - (RK-381) Do not recurse into symlinked dirs when finding files to purge. [#1233](https://github.com/puppetlabs/r10k/pull/1233)
12
+ - Purge should remove unmanaged directories, in addition to unmanaged files. [#1222](https://github.com/puppetlabs/r10k/pull/1222)
13
+ - Rename experimental environment type "bare" to "plain". [#1228](https://github.com/puppetlabs/r10k/pull/1228)
14
+ - Add support for specifying additional logging ouputs. [#1230](https://github.com/puppetlabs/r10k/issues/1230)
15
+
7
16
  3.12.1
8
17
  ------
9
18
 
@@ -760,16 +760,16 @@ modules:
760
760
  version: 62d07f2
761
761
  ```
762
762
 
763
- ### Bare Environment Type
763
+ ### Plain Environment Type
764
764
 
765
765
  A "control repository" typically contains a hiera.yaml, an environment.conf, a manifests/site.pp file, and a few other things. However, none of these are strictly necessary for an environment to be functional if modules can be deployed to it.
766
766
 
767
- The bare environment type allows sources that support environment modules to operate without a control repo being required. Modules can be deployed directly.
767
+ The plain environment type allows sources that support environment modules to operate without a control repo being required. Modules can be deployed directly.
768
768
 
769
769
  ```yaml
770
770
  ---
771
771
  production:
772
- type: bare
772
+ type: plain
773
773
  modules:
774
774
  puppetlabs-stdlib:
775
775
  type: forge
@@ -783,7 +783,7 @@ production:
783
783
  version: 62d07f2
784
784
 
785
785
  development:
786
- type: bare
786
+ type: plain
787
787
  modules:
788
788
  puppetlabs-stdlib:
789
789
  type: forge
@@ -51,6 +51,12 @@ module R10K
51
51
  overrides[:deploy][:generate_types] = @opts[:'generate-types'] if @opts.key?(:'generate-types')
52
52
  overrides[:deploy][:exclude_spec] = @opts[:'exclude-spec'] if @opts.key?(:'exclude-spec')
53
53
  end
54
+ # If the log level has been given as an argument, ensure that output happens on stderr
55
+ if @opts.key?(:loglevel)
56
+ overrides[:logging] = {}
57
+ overrides[:logging][:level] = @opts[:loglevel]
58
+ overrides[:logging][:disable_default_stderr] = false
59
+ end
54
60
 
55
61
  with_overrides = config_settings.merge(overrides) do |key, oldval, newval|
56
62
  newval = oldval.merge(newval) if oldval.is_a? Hash
@@ -1,13 +1,10 @@
1
- class R10K::Environment::Bare < R10K::Environment::WithModules
1
+ class R10K::Environment::Bare < R10K::Environment::Plain
2
2
 
3
3
  R10K::Environment.register(:bare, self)
4
4
 
5
- def sync
6
- path.mkpath
7
- end
8
-
9
- def status
10
- :not_applicable
5
+ def initialize(name, basedir, dirname, options = {})
6
+ logger.warn _('"bare" environment type is deprecated; please use "plain" instead (environment: %{name})') % {name: name}
7
+ super
11
8
  end
12
9
 
13
10
  def signature
@@ -0,0 +1,16 @@
1
+ class R10K::Environment::Plain < R10K::Environment::WithModules
2
+
3
+ R10K::Environment.register(:plain, self)
4
+
5
+ def sync
6
+ path.mkpath
7
+ end
8
+
9
+ def status
10
+ :not_applicable
11
+ end
12
+
13
+ def signature
14
+ 'plain-default'
15
+ end
16
+ end
@@ -30,6 +30,7 @@ module R10K
30
30
 
31
31
  require 'r10k/environment/base'
32
32
  require 'r10k/environment/with_modules'
33
+ require 'r10k/environment/plain'
33
34
  require 'r10k/environment/bare'
34
35
  require 'r10k/environment/git'
35
36
  require 'r10k/environment/svn'
data/lib/r10k/errors.rb CHANGED
@@ -58,4 +58,9 @@ module R10K
58
58
  str.gsub(/^/, prefix)
59
59
  end
60
60
  end
61
+
62
+ # An error class for configuration errors
63
+ #
64
+ class ConfigError < Error
65
+ end
61
66
  end
@@ -30,6 +30,8 @@ module R10K
30
30
  logger.warn(_("the purgedirs key in r10k.yaml is deprecated. it is currently ignored."))
31
31
  end
32
32
 
33
+ with_setting(:logging) { |value| LoggingInitializer.new(value).call }
34
+
33
35
  with_setting(:deploy) { |value| DeployInitializer.new(value).call }
34
36
 
35
37
  with_setting(:cachedir) { |value| R10K::Git::Cache.settings[:cache_root] = value }
@@ -41,6 +43,14 @@ module R10K
41
43
  end
42
44
  end
43
45
 
46
+ class LoggingInitializer < BaseInitializer
47
+ def call
48
+ with_setting(:level) { |value| R10K::Logging.level = value }
49
+ with_setting(:disable_default_stderr) { |value| R10K::Logging.disable_default_stderr = value }
50
+ with_setting(:outputs) { |value| R10K::Logging.add_outputters(value) }
51
+ end
52
+ end
53
+
44
54
  class DeployInitializer < BaseInitializer
45
55
  def call
46
56
  with_setting(:puppet_path) { |value| R10K::Settings.puppet_path = value }
data/lib/r10k/logging.rb CHANGED
@@ -8,6 +8,16 @@ require 'r10k/logging/terminaloutputter'
8
8
  module R10K::Logging
9
9
 
10
10
  LOG_LEVELS = %w{DEBUG2 DEBUG1 DEBUG INFO NOTICE WARN ERROR FATAL}
11
+ SYSLOG_LEVELS_MAP = {
12
+ 'DEBUG2' => 'DEBUG',
13
+ 'DEBUG1' => 'DEBUG',
14
+ 'DEBUG' => 'DEBUG',
15
+ 'INFO' => 'INFO',
16
+ 'NOTICE' => 'INFO',
17
+ 'WARN' => 'WARN',
18
+ 'ERROR' => 'ERROR',
19
+ 'FATAL' => 'FATAL',
20
+ }.freeze
11
21
 
12
22
  def logger_name
13
23
  self.class.to_s
@@ -21,6 +31,9 @@ module R10K::Logging
21
31
  else
22
32
  @logger = Log4r::Logger.new(name)
23
33
  @logger.add(R10K::Logging.outputter)
34
+ R10K::Logging.outputters.each do |output|
35
+ @logger.add(output)
36
+ end
24
37
  end
25
38
  end
26
39
  @logger
@@ -59,7 +72,7 @@ module R10K::Logging
59
72
  if level.nil?
60
73
  raise ArgumentError, _("Invalid log level '%{val}'. Valid levels are %{log_levels}") % {val: val, log_levels: LOG_LEVELS.map(&:downcase).inspect}
61
74
  end
62
- outputter.level = level
75
+ outputter.level = level unless @disable_default_stderr
63
76
  @level = level
64
77
 
65
78
  if level < Log4r::INFO
@@ -69,6 +82,58 @@ module R10K::Logging
69
82
  end
70
83
  end
71
84
 
85
+ def disable_default_stderr=(val)
86
+ @disable_default_stderr = val
87
+ outputter.level = val ? Log4r::OFF : @level
88
+ end
89
+
90
+ def add_outputters(outputs)
91
+ outputs.each do |output|
92
+ type = output.fetch(:type)
93
+ # Support specifying both short as well as full names
94
+ type = type.to_s[0..-10] if type.to_s.downcase.end_with? 'outputter'
95
+
96
+ name = output.fetch(:name, 'r10k')
97
+ if output[:level]
98
+ level = parse_level(output[:level])
99
+ if level.nil?
100
+ raise ArgumentError, _("Invalid log level '%{val}'. Valid levels are %{log_levels}") % { val: output[:level], log_levels: LOG_LEVELS.map(&:downcase).inspect }
101
+ end
102
+ else
103
+ level = self.level
104
+ end
105
+ only_at = output[:only_at]
106
+ only_at&.map! do |val|
107
+ lv = parse_level(val)
108
+ if lv.nil?
109
+ raise ArgumentError, _("Invalid log level '%{val}'. Valid levels are %{log_levels}") % { val: val, log_levels: LOG_LEVELS.map(&:downcase).inspect }
110
+ end
111
+
112
+ lv
113
+ end
114
+ parameters = output.fetch(:parameters, {}).merge({ level: level })
115
+
116
+ begin
117
+ # Try to load the outputter file if possible
118
+ require "log4r/outputter/#{type.to_s.downcase}outputter"
119
+ rescue LoadError
120
+ false
121
+ end
122
+ outputtertype = Log4r.constants
123
+ .select { |klass| klass.to_s.end_with? 'Outputter' }
124
+ .find { |klass| klass.to_s.downcase == "#{type.to_s.downcase}outputter" }
125
+ raise ArgumentError, "Unable to find a #{output[:type]} outputter." unless outputtertype
126
+
127
+ outputter = Log4r.const_get(outputtertype).new(name, parameters)
128
+ outputter.only_at(*only_at) if only_at
129
+ # Handle log4r's syslog mapping correctly
130
+ outputter.map_levels_by_name_to_syslog(SYSLOG_LEVELS_MAP) if outputter.respond_to? :map_levels_by_name_to_syslog
131
+
132
+ @outputters << outputter
133
+ Log4r::Logger.global.add outputter
134
+ end
135
+ end
136
+
72
137
  extend Forwardable
73
138
  def_delegators :@outputter, :use_color, :use_color=
74
139
 
@@ -87,6 +152,16 @@ module R10K::Logging
87
152
  # @return [Log4r::Outputter]
88
153
  attr_reader :outputter
89
154
 
155
+ # @!attribute [r] outputters
156
+ # @api private
157
+ # @return [Array[Log4r::Outputter]]
158
+ attr_reader :outputters
159
+
160
+ # @!attribute [r] disable_default_stderr
161
+ # @api private
162
+ # @return [Boolean]
163
+ attr_reader :disable_default_stderr
164
+
90
165
  def default_formatter
91
166
  Log4r::PatternFormatter.new(:pattern => '%l\t -> %m')
92
167
  end
@@ -106,4 +181,6 @@ module R10K::Logging
106
181
  @level = Log4r::WARN
107
182
  @formatter = default_formatter
108
183
  @outputter = default_outputter
184
+ @outputters = []
185
+ @disable_default_stderr = false
109
186
  end
data/lib/r10k/settings.rb CHANGED
@@ -217,6 +217,39 @@ module R10K
217
217
  })])
218
218
  end
219
219
 
220
+ def self.logging_settings
221
+ R10K::Settings::Collection.new(:logging, [
222
+ Definition.new(:level, {
223
+ desc: 'What logging level should R10k run on if not specified at runtime.',
224
+ validate: lambda do |value|
225
+ if R10K::Logging.parse_level(value).nil?
226
+ raise ArgumentError, "`level` must be a valid log level.
227
+ Valid levels are #{R10K::Logging::LOG_LEVELS.map(&:downcase).inspect}"
228
+ end
229
+ end
230
+ }),
231
+
232
+ Definition.new(:outputs, {
233
+ desc: 'Additional log outputs to use.',
234
+ validate: lambda do |value|
235
+ unless value.is_a?(Array)
236
+ raise ArgumentError, "The `outputs` setting should be an array of outputs, not a #{value.class}"
237
+ end
238
+ end
239
+ }),
240
+
241
+ Definition.new(:disable_default_stderr, {
242
+ desc: 'Disable the default stderr logging output',
243
+ default: false,
244
+ validate: lambda do |value|
245
+ unless !!value == value
246
+ raise ArgumentError, "`disable_default_stderr` can only be a boolean value, not '#{value}'"
247
+ end
248
+ end
249
+ })
250
+ ])
251
+ end
252
+
220
253
  def self.global_settings
221
254
  R10K::Settings::Collection.new(:global, [
222
255
  Definition.new(:sources, {
@@ -271,6 +304,8 @@ module R10K
271
304
  R10K::Settings.git_settings,
272
305
 
273
306
  R10K::Settings.deploy_settings,
307
+
308
+ R10K::Settings.logging_settings
274
309
  ])
275
310
  end
276
311
  end
@@ -7,7 +7,7 @@ class R10K::Source::Yaml < R10K::Source::Hash
7
7
  begin
8
8
  contents = ::YAML.load_file(config)
9
9
  rescue => e
10
- raise ConfigError, _("Couldn't open environments file %{file}: %{err}") % {file: config, err: e.message}
10
+ raise R10K::ConfigError, _("Couldn't open environments file %{file}: %{err}") % {file: config, err: e.message}
11
11
  end
12
12
 
13
13
  # Set the environments key for the parent class to consume
@@ -99,8 +99,8 @@ module R10K
99
99
  end
100
100
 
101
101
  children.flat_map do |child|
102
- if File.directory?(child) && recurse
103
- potentially_purgeable(child, exclusion_globs, allowed_globs, desireds_not_to_recurse_into, recurse)
102
+ if File.directory?(child) && !File.symlink?(child) && recurse
103
+ potentially_purgeable(child, exclusion_globs, allowed_globs, desireds_not_to_recurse_into, recurse) << child.to_s
104
104
  else
105
105
  child.to_s
106
106
  end
data/lib/r10k/version.rb CHANGED
@@ -2,5 +2,5 @@ module R10K
2
2
  # When updating to a new major (X) or minor (Y) version, include `#major` or
3
3
  # `#minor` (respectively) in your commit message to trigger the appropriate
4
4
  # release. Otherwise, a new patch (Z) version will be released.
5
- VERSION = '3.12.1'
5
+ VERSION = '3.13.0'
6
6
  end
data/locales/r10k.pot CHANGED
@@ -6,11 +6,11 @@
6
6
  #, fuzzy
7
7
  msgid ""
8
8
  msgstr ""
9
- "Project-Id-Version: r10k 3.9.3-110-gfe65c736\n"
9
+ "Project-Id-Version: r10k 3.9.3-134-g9f93336f\n"
10
10
  "\n"
11
11
  "Report-Msgid-Bugs-To: docs@puppetlabs.com\n"
12
- "POT-Creation-Date: 2021-09-15 21:23+0000\n"
13
- "PO-Revision-Date: 2021-09-15 21:23+0000\n"
12
+ "POT-Creation-Date: 2021-10-25 18:18+0000\n"
13
+ "PO-Revision-Date: 2021-10-25 18:18+0000\n"
14
14
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
15
15
  "Language-Team: LANGUAGE <LL@li.org>\n"
16
16
  "Language: \n"
@@ -19,55 +19,55 @@ msgstr ""
19
19
  "Content-Transfer-Encoding: 8bit\n"
20
20
  "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
21
21
 
22
- #: ../lib/r10k/action/deploy/deploy_helpers.rb:12 ../lib/r10k/settings/loader.rb:63
22
+ #: ../lib/r10k/action/deploy/deploy_helpers.rb:16 ../lib/r10k/settings/loader.rb:63
23
23
  msgid "No configuration file given, no config file found in current directory, and no global config present"
24
24
  msgstr ""
25
25
 
26
- #: ../lib/r10k/action/deploy/deploy_helpers.rb:26
26
+ #: ../lib/r10k/action/deploy/deploy_helpers.rb:30
27
27
  msgid "Making changes to deployed environments has been administratively disabled."
28
28
  msgstr ""
29
29
 
30
- #: ../lib/r10k/action/deploy/deploy_helpers.rb:27
30
+ #: ../lib/r10k/action/deploy/deploy_helpers.rb:31
31
31
  msgid "Reason: %{write_lock}"
32
32
  msgstr ""
33
33
 
34
- #: ../lib/r10k/action/deploy/environment.rb:118
34
+ #: ../lib/r10k/action/deploy/environment.rb:116
35
35
  msgid "Environment(s) \\'%{environments}\\' cannot be found in any source and will not be deployed."
36
36
  msgstr ""
37
37
 
38
- #: ../lib/r10k/action/deploy/environment.rb:138
38
+ #: ../lib/r10k/action/deploy/environment.rb:136
39
39
  msgid "Executing postrun command."
40
40
  msgstr ""
41
41
 
42
- #: ../lib/r10k/action/deploy/environment.rb:152
42
+ #: ../lib/r10k/action/deploy/environment.rb:150
43
43
  msgid "Environment %{env_dir} does not match environment name filter, skipping"
44
44
  msgstr ""
45
45
 
46
- #: ../lib/r10k/action/deploy/environment.rb:160
46
+ #: ../lib/r10k/action/deploy/environment.rb:158
47
47
  msgid "Deploying environment %{env_path}"
48
48
  msgstr ""
49
49
 
50
- #: ../lib/r10k/action/deploy/environment.rb:163
50
+ #: ../lib/r10k/action/deploy/environment.rb:161
51
51
  msgid "Environment %{env_dir} is now at %{env_signature}"
52
52
  msgstr ""
53
53
 
54
- #: ../lib/r10k/action/deploy/environment.rb:167
54
+ #: ../lib/r10k/action/deploy/environment.rb:165
55
55
  msgid "Environment %{env_dir} is new, updating all modules"
56
56
  msgstr ""
57
57
 
58
- #: ../lib/r10k/action/deploy/module.rb:82
58
+ #: ../lib/r10k/action/deploy/module.rb:81
59
59
  msgid "Running postrun command for environments: %{envs_to_run}."
60
60
  msgstr ""
61
61
 
62
- #: ../lib/r10k/action/deploy/module.rb:92
62
+ #: ../lib/r10k/action/deploy/module.rb:91
63
63
  msgid "No environments were modified, not executing postrun command."
64
64
  msgstr ""
65
65
 
66
- #: ../lib/r10k/action/deploy/module.rb:104
66
+ #: ../lib/r10k/action/deploy/module.rb:103
67
67
  msgid "Only updating modules in environment(s) %{opt_env} skipping environment %{env_path}"
68
68
  msgstr ""
69
69
 
70
- #: ../lib/r10k/action/deploy/module.rb:106
70
+ #: ../lib/r10k/action/deploy/module.rb:105
71
71
  msgid "Updating modules %{modules} in environment %{env_path}"
72
72
  msgstr ""
73
73
 
@@ -107,6 +107,10 @@ msgstr ""
107
107
  msgid "Unable to load sources; the supplied configuration does not define the 'sources' key"
108
108
  msgstr ""
109
109
 
110
+ #: ../lib/r10k/environment/bare.rb:6
111
+ msgid "\"bare\" environment type is deprecated; please use \"plain\" instead (environment: %{name})"
112
+ msgstr ""
113
+
110
114
  #: ../lib/r10k/environment/base.rb:89 ../lib/r10k/environment/base.rb:105 ../lib/r10k/environment/base.rb:114 ../lib/r10k/source/base.rb:83
111
115
  msgid "%{class} has not implemented method %{method}"
112
116
  msgstr ""
@@ -427,7 +431,7 @@ msgstr ""
427
431
  msgid "Cannot track control repo branch for content '%{name}' when not part of a git-backed environment, will use default if available."
428
432
  msgstr ""
429
433
 
430
- #: ../lib/r10k/module/local.rb:33
434
+ #: ../lib/r10k/module/local.rb:37
431
435
  msgid "Module %{title} is a local module, always indicating synced."
432
436
  msgstr ""
433
437
 
@@ -435,39 +439,39 @@ msgstr ""
435
439
  msgid "Could not read metadata.json"
436
440
  msgstr ""
437
441
 
438
- #: ../lib/r10k/module_loader/puppetfile.rb:58
442
+ #: ../lib/r10k/module_loader/puppetfile.rb:62
439
443
  msgid "Using Puppetfile '%{puppetfile}'"
440
444
  msgstr ""
441
445
 
442
- #: ../lib/r10k/module_loader/puppetfile.rb:59
446
+ #: ../lib/r10k/module_loader/puppetfile.rb:63
443
447
  msgid "Using moduledir '%{moduledir}'"
444
448
  msgstr ""
445
449
 
446
- #: ../lib/r10k/module_loader/puppetfile.rb:80
450
+ #: ../lib/r10k/module_loader/puppetfile.rb:84
447
451
  msgid "Failed to evaluate %{path}"
448
452
  msgstr ""
449
453
 
450
- #: ../lib/r10k/module_loader/puppetfile.rb:97
454
+ #: ../lib/r10k/module_loader/puppetfile.rb:101
451
455
  msgid "Unable to preload Puppetfile because of %{msg}"
452
456
  msgstr ""
453
457
 
454
- #: ../lib/r10k/module_loader/puppetfile.rb:115
458
+ #: ../lib/r10k/module_loader/puppetfile.rb:119
455
459
  msgid "Using Forge from Puppetfile: %{forge}"
456
460
  msgstr ""
457
461
 
458
- #: ../lib/r10k/module_loader/puppetfile.rb:118
462
+ #: ../lib/r10k/module_loader/puppetfile.rb:122
459
463
  msgid "Ignoring Forge declaration in Puppetfile, using value from settings: %{forge}."
460
464
  msgstr ""
461
465
 
462
- #: ../lib/r10k/module_loader/puppetfile.rb:179 ../lib/r10k/puppetfile.rb:104
466
+ #: ../lib/r10k/module_loader/puppetfile.rb:183 ../lib/r10k/puppetfile.rb:104
463
467
  msgid "Puppetfile %{path} missing or unreadable"
464
468
  msgstr ""
465
469
 
466
- #: ../lib/r10k/module_loader/puppetfile.rb:215
470
+ #: ../lib/r10k/module_loader/puppetfile.rb:219
467
471
  msgid "Puppetfiles cannot contain duplicate module names."
468
472
  msgstr ""
469
473
 
470
- #: ../lib/r10k/module_loader/puppetfile.rb:217
474
+ #: ../lib/r10k/module_loader/puppetfile.rb:221
471
475
  msgid "Remove the duplicates of the following modules: %{dupes}"
472
476
  msgstr ""
473
477
 
@@ -618,45 +622,45 @@ msgstr ""
618
622
  msgid "pe_license feature is not available, PE only Puppet modules will not be downloadable."
619
623
  msgstr ""
620
624
 
621
- #: ../lib/r10k/util/purgeable.rb:87
625
+ #: ../lib/r10k/util/purgeable.rb:91
622
626
  msgid "Not purging %{path} due to internal exclusion match: %{exclusion_match}"
623
627
  msgstr ""
624
628
 
625
- #: ../lib/r10k/util/purgeable.rb:89
629
+ #: ../lib/r10k/util/purgeable.rb:93
626
630
  msgid "Not purging %{path} due to whitelist match: %{allowlist_match}"
627
631
  msgstr ""
628
632
 
629
- #: ../lib/r10k/util/purgeable.rb:133
633
+ #: ../lib/r10k/util/purgeable.rb:137
630
634
  msgid "No unmanaged contents in %{managed_dirs}, nothing to purge"
631
635
  msgstr ""
632
636
 
633
- #: ../lib/r10k/util/purgeable.rb:138
637
+ #: ../lib/r10k/util/purgeable.rb:142
634
638
  msgid "Removing unmanaged path %{path}"
635
639
  msgstr ""
636
640
 
637
- #: ../lib/r10k/util/purgeable.rb:143
641
+ #: ../lib/r10k/util/purgeable.rb:147
638
642
  msgid "Unable to remove unmanaged path: %{path}"
639
643
  msgstr ""
640
644
 
641
- #: ../lib/r10k/util/setopts.rb:58
645
+ #: ../lib/r10k/util/setopts.rb:60
642
646
  msgid "%{class_name} parameters '%{a}' and '%{b}' conflict. Specify one or the other, but not both"
643
647
  msgstr ""
644
648
 
645
- #: ../lib/r10k/util/setopts.rb:65
649
+ #: ../lib/r10k/util/setopts.rb:67
646
650
  msgid "%{class_name} cannot handle option '%{key}'"
647
651
  msgstr ""
648
652
 
649
- #: ../lib/r10k/util/subprocess.rb:69
653
+ #: ../lib/r10k/util/subprocess.rb:70
650
654
  msgid "Starting process: %{args}"
651
655
  msgstr ""
652
656
 
653
- #: ../lib/r10k/util/subprocess.rb:74
657
+ #: ../lib/r10k/util/subprocess.rb:75
654
658
  msgid ""
655
659
  "Finished process:\n"
656
660
  "%{result}"
657
661
  msgstr ""
658
662
 
659
- #: ../lib/r10k/util/subprocess.rb:77
663
+ #: ../lib/r10k/util/subprocess.rb:78
660
664
  msgid "Command exited with non-zero exit code"
661
665
  msgstr ""
662
666
 
data/r10k.yaml.example CHANGED
@@ -110,3 +110,31 @@ forge:
110
110
  # The 'baseurl' setting indicates where Forge modules should be installed
111
111
  # from. This defaults to 'https://forgeapi.puppetlabs.com'
112
112
  #baseurl: 'https://forgemirror.example.com'
113
+
114
+ # Configuration options on how R10k should log its actions
115
+ logging:
116
+ # The 'level' setting sets the default log level to run R10k actions at.
117
+ # This value will be overridden by any value set through the command line.
118
+ #level: warn
119
+
120
+ # Specify additional log outputs here, any log4r outputter can be used.
121
+ # If no log level is specified then the output will use the global level.
122
+ #outputs:
123
+ # - type: file
124
+ # level: debug
125
+ # parameters:
126
+ # filename: /var/log/r10k.log
127
+ # trunc: true
128
+ # - type: syslog
129
+ # - type: email
130
+ # only_at: [fatal]
131
+ # parameters:
132
+ # from: r10k@example.com
133
+ # to: sysadmins@example.com
134
+ # server: smtp.example.com
135
+ # subject: Fatal R10k error occurred
136
+
137
+ # The 'disable_default_stderr' setting specifies if the default output on
138
+ # stderr should be active or not, in case R10k is to be run entirely
139
+ # through scripts or cronjobs where console output is unwelcome.
140
+ #disable_default_stderr: false
@@ -0,0 +1,12 @@
1
+ ---
2
+ logging:
3
+ level: FATAL
4
+
5
+ outputs:
6
+ - type: file
7
+ parameters:
8
+ filename: r10k.log
9
+
10
+ - type: syslog
11
+
12
+ disable_default_stderr: true
@@ -0,0 +1 @@
1
+ spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1
@@ -0,0 +1 @@
1
+ spec/fixtures/unit/util/purgeable/managed_one/expected_1
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+ require 'r10k/util/purgeable'
3
+ require 'r10k/util/cleaner'
4
+
5
+ require 'tmpdir'
6
+
7
+ RSpec.describe R10K::Util::Purgeable do
8
+ it 'purges only unmanaged files' do
9
+ Dir.mktmpdir do |envdir|
10
+ managed_directory = "#{envdir}/managed_one"
11
+ desired_contents = [
12
+ "#{managed_directory}/expected_1",
13
+ "#{managed_directory}/managed_subdir_1",
14
+ "#{managed_directory}/managed_symlink_dir",
15
+ "#{managed_directory}/managed_subdir_1/subdir_expected_1",
16
+ "#{managed_directory}/managed_subdir_1/managed_symlink_file",
17
+ ]
18
+
19
+ FileUtils.cp_r('spec/fixtures/unit/util/purgeable/managed_one/',
20
+ managed_directory)
21
+
22
+ cleaner = R10K::Util::Cleaner.new([managed_directory], desired_contents)
23
+
24
+ cleaner.purge!({ recurse: true, whitelist: ["**/subdir_allowlisted_2"] })
25
+
26
+ # Files present after purge
27
+ expect(File.exist?("#{managed_directory}/expected_1")).to be true
28
+ expect(File.exist?("#{managed_directory}/managed_subdir_1")).to be true
29
+ expect(File.exist?("#{managed_directory}/managed_symlink_dir")).to be true
30
+ expect(File.exist?("#{managed_directory}/managed_subdir_1/subdir_expected_1")).to be true
31
+ expect(File.exist?("#{managed_directory}/managed_subdir_1/managed_symlink_file")).to be true
32
+ expect(File.exist?("#{managed_directory}/managed_subdir_1/subdir_allowlisted_2")).to be true
33
+
34
+ # Purged files
35
+ expect(File.exist?("#{managed_directory}/unmanaged_1")).to be false
36
+ expect(File.exist?("#{managed_directory}/managed_subdir_1/unmanaged_symlink_dir")).to be false
37
+ expect(File.exist?("#{managed_directory}/unmanaged_symlink_file")).to be false
38
+ expect(File.exist?("#{managed_directory}/managed_subdir_1/subdir_unmanaged_1")).to be false
39
+ end
40
+ end
41
+ end
@@ -4,9 +4,9 @@ require 'r10k/action/puppetfile/install'
4
4
  describe R10K::Action::Puppetfile::Install do
5
5
  let(:default_opts) { { root: "/some/nonexistent/path" } }
6
6
  let(:loader) {
7
- R10K::ModuleLoader::Puppetfile.new({
7
+ R10K::ModuleLoader::Puppetfile.new(
8
8
  basedir: '/some/nonexistent/path',
9
- overrides: {force: false}})
9
+ overrides: {force: false})
10
10
  }
11
11
 
12
12
  def installer(opts = {}, argv = [], settings = {})
@@ -159,10 +159,61 @@ describe R10K::Action::Runner do
159
159
  end
160
160
 
161
161
  describe "configuring logging" do
162
+ before(:each) do
163
+ R10K::Logging.outputters.clear
164
+ end
165
+
162
166
  it "sets the log level if :loglevel is provided" do
163
167
  runner = described_class.new({:opts => :yep, :loglevel => 'FATAL'}, %w[args yes], action_class)
164
- expect(R10K::Logging).to receive(:level=).with('FATAL')
168
+ # The settings/overrides system causes the level to be set twice
169
+ expect(R10K::Logging).to receive(:level=).with('FATAL').twice
170
+ runner.call
171
+ end
172
+
173
+ # The logging fixture tests require a platform with syslog
174
+ if !R10K::Util::Platform.windows?
175
+ it "sets the log level if the logging.level setting is provided" do
176
+ runner = described_class.new({ opts: :yep, config: 'spec/fixtures/unit/action/r10k_logging.yaml'}, %w[args yes], action_class)
177
+ expect(R10K::Logging).to receive(:level=).with('FATAL')
178
+ runner.call
179
+ end
180
+
181
+ it "sets the outputters if logging.outputs is provided" do
182
+ runner = described_class.new({ opts: :yep, config: 'spec/fixtures/unit/action/r10k_logging.yaml' }, %w[args yes], action_class)
183
+ expect(R10K::Logging).to receive(:add_outputters).with([
184
+ { type: 'file', parameters: { filename: 'r10k.log' } },
185
+ { type: 'syslog' }
186
+ ])
187
+ runner.call
188
+ end
189
+
190
+ it "disables the default outputter if the logging.disable_default_stderr setting is provided" do
191
+ runner = described_class.new({ opts: :yep, config: 'spec/fixtures/unit/action/r10k_logging.yaml'}, %w[args yes], action_class)
192
+ expect(R10K::Logging).to receive(:disable_default_stderr=).with(true)
193
+ runner.call
194
+ end
195
+
196
+ it "adds additional log outputs if the logging.outputs setting is provided" do
197
+ runner = described_class.new({ opts: :yep, config: 'spec/fixtures/unit/action/r10k_logging.yaml'}, %w[args yes], action_class)
198
+ runner.call
199
+ expect(R10K::Logging.outputters).to_not be_empty
200
+ end
201
+
202
+ it "disables the default output if the logging.disable_default_stderr setting is provided" do
203
+ runner = described_class.new({ opts: :yep, config: 'spec/fixtures/unit/action/r10k_logging.yaml'}, %w[args yes], action_class)
204
+ runner.call
205
+ expect(runner.logger.outputters).to satisfy { |outputs| outputs.any? { |output| output.is_a?(R10K::Logging::TerminalOutputter) && output.level == Log4r::OFF } }
206
+ end
207
+ end
208
+
209
+ it "doesn't add additional log outputs if the logging.outputs setting is not provided" do
210
+ runner.call
211
+ expect(R10K::Logging.outputters).to be_empty
212
+ end
213
+
214
+ it "includes the default stderr outputter" do
165
215
  runner.call
216
+ expect(runner.logger.outputters).to satisfy { |outputs| outputs.any? { |output| output.is_a? R10K::Logging::TerminalOutputter } }
166
217
  end
167
218
 
168
219
  it "does not modify the loglevel if :loglevel is not provided" do
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'r10k/environment'
3
+
4
+ describe R10K::Environment::Bare do
5
+ it "warns on initialization" do
6
+ logger_spy = spy('logger')
7
+ allow_any_instance_of(described_class).to receive(:logger).and_return(logger_spy)
8
+
9
+ described_class.new('envname', '/basedir', 'dirname', {})
10
+
11
+ expect(logger_spy).to have_received(:warn).with(%r{deprecated.*envname})
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'r10k/environment'
3
+
4
+ describe R10K::Environment::Plain do
5
+ it "initializes successfully" do
6
+ expect(described_class.new('envname', '/basedir', 'dirname', {})).to be_a_kind_of(described_class)
7
+ end
8
+ end
@@ -8,7 +8,7 @@ describe R10K::Environment::WithModules do
8
8
  '/some/nonexistent/environmentdir',
9
9
  'prefix_release42',
10
10
  {
11
- :type => 'bare',
11
+ :type => 'plain',
12
12
  :modules => {
13
13
  'puppetlabs-stdlib' => { local: true },
14
14
  'puppetlabs-concat' => { local: true },
@@ -15,8 +15,10 @@ RSpec.describe R10K::Util::Purgeable do
15
15
  'spec/fixtures/unit/util/purgeable/managed_one/expected_1',
16
16
  'spec/fixtures/unit/util/purgeable/managed_one/new_1',
17
17
  'spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1',
18
+ 'spec/fixtures/unit/util/purgeable/managed_one/managed_symlink_dir',
18
19
  'spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_expected_1',
19
20
  'spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_new_1',
21
+ 'spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/managed_symlink_file',
20
22
  'spec/fixtures/unit/util/purgeable/managed_two/expected_2',
21
23
  'spec/fixtures/unit/util/purgeable/managed_two/new_2',
22
24
  'spec/fixtures/unit/util/purgeable/managed_two/.hidden',
@@ -30,7 +32,8 @@ RSpec.describe R10K::Util::Purgeable do
30
32
 
31
33
  describe '#current_contents' do
32
34
  it 'collects direct contents of all managed directories' do
33
- expect(subject.current_contents(recurse)).to contain_exactly(/\/expected_1/, /\/expected_2/, /\/unmanaged_1/, /\/unmanaged_2/, /\/managed_subdir_1/)
35
+ expect(subject.current_contents(recurse)).to contain_exactly(/\/expected_1/, /\/expected_2/, /\/unmanaged_1/, /\/unmanaged_2/,
36
+ /\/managed_subdir_1/, /\/managed_symlink_dir/, /\/unmanaged_symlink_file/)
34
37
  end
35
38
  end
36
39
 
@@ -46,7 +49,7 @@ RSpec.describe R10K::Util::Purgeable do
46
49
  let(:whitelist) { [] }
47
50
 
48
51
  it 'collects current_contents that should not exist' do
49
- expect(subject.stale_contents(recurse, exclusions, whitelist)).to contain_exactly(/\/unmanaged_1/, /\/unmanaged_2/)
52
+ expect(subject.stale_contents(recurse, exclusions, whitelist)).to contain_exactly(/\/unmanaged_1/, /\/unmanaged_2/, /\/unmanaged_symlink_file/)
50
53
  end
51
54
  end
52
55
 
@@ -56,7 +59,7 @@ RSpec.describe R10K::Util::Purgeable do
56
59
 
57
60
  it 'collects current_contents that should not exist except whitelisted items' do
58
61
  expect(subject.logger).to receive(:debug).with(/unmanaged_1.*whitelist match/i)
59
- expect(subject.stale_contents(recurse, exclusions, whitelist)).to contain_exactly(/\/unmanaged_2/)
62
+ expect(subject.stale_contents(recurse, exclusions, whitelist)).to contain_exactly(/\/unmanaged_2/, /\/unmanaged_symlink_file/)
60
63
  end
61
64
  end
62
65
 
@@ -66,7 +69,7 @@ RSpec.describe R10K::Util::Purgeable do
66
69
 
67
70
  it 'collects current_contents that should not exist except excluded items' do
68
71
  expect(subject.logger).to receive(:debug2).with(/unmanaged_2.*internal exclusion match/i)
69
- expect(subject.stale_contents(recurse, exclusions, whitelist)).to contain_exactly(/\/unmanaged_1/)
72
+ expect(subject.stale_contents(recurse, exclusions, whitelist)).to contain_exactly(/\/unmanaged_1/, /\/unmanaged_symlink_file/)
70
73
  end
71
74
  end
72
75
  end
@@ -102,9 +105,13 @@ RSpec.describe R10K::Util::Purgeable do
102
105
  expect(subject.current_contents(recurse)).
103
106
  to contain_exactly(/\/expected_1/, /\/expected_2/,
104
107
  /\/unmanaged_1/, /\/unmanaged_2/,
108
+ /\/managed_symlink_dir/,
109
+ /\/unmanaged_symlink_file/,
105
110
  /\/managed_subdir_1/,
106
111
  /\/subdir_expected_1/, /\/subdir_unmanaged_1/,
107
- /\/managed_subdir_2/, /\/ignored_1/,
112
+ /\/managed_symlink_file/,
113
+ /\/unmanaged_symlink_dir/,
114
+ /\/subdir_allowlisted_2/, /\/ignored_1/,
108
115
  /\/\.hidden/)
109
116
  end
110
117
  end
@@ -122,7 +129,8 @@ RSpec.describe R10K::Util::Purgeable do
122
129
 
123
130
  it 'collects current_contents that should not exist recursively' do
124
131
  expect(subject.stale_contents(recurse, exclusions, whitelist)).
125
- to contain_exactly(/\/unmanaged_1/, /\/unmanaged_2/, /\/subdir_unmanaged_1/, /\/ignored_1/)
132
+ to contain_exactly(/\/unmanaged_1/, /\/unmanaged_2/, /\/unmanaged_symlink_file/, /\/subdir_unmanaged_1/,
133
+ /\/ignored_1/, /\/subdir_allowlisted_2/, /\/unmanaged_symlink_dir/)
126
134
  end
127
135
  end
128
136
 
@@ -134,7 +142,8 @@ RSpec.describe R10K::Util::Purgeable do
134
142
  expect(subject.logger).to receive(:debug).with(/unmanaged_1.*whitelist match/i)
135
143
 
136
144
  expect(subject.stale_contents(recurse, exclusions, whitelist)).
137
- to contain_exactly(/\/unmanaged_2/, /\/subdir_unmanaged_1/, /\/ignored_1/)
145
+ to contain_exactly(/\/unmanaged_2/, /\/subdir_unmanaged_1/, /\/unmanaged_symlink_file/, /\/ignored_1/,
146
+ /\/subdir_allowlisted_2/, /\/unmanaged_symlink_dir/)
138
147
  end
139
148
 
140
149
  it 'does not collect contents that match recursive globbed whitelist items as intermediate values' do
@@ -142,7 +151,7 @@ RSpec.describe R10K::Util::Purgeable do
142
151
  expect(subject.logger).not_to receive(:debug).with(/ignored_1/)
143
152
 
144
153
  expect(subject.stale_contents(recurse, exclusions, recursive_whitelist)).
145
- to contain_exactly(/\/unmanaged_2/, /\/managed_one\/unmanaged_1/)
154
+ to contain_exactly(/\/unmanaged_2/, /\/managed_one\/unmanaged_1/, /\/managed_one\/unmanaged_symlink_file/)
146
155
  end
147
156
  end
148
157
 
@@ -154,7 +163,8 @@ RSpec.describe R10K::Util::Purgeable do
154
163
  expect(subject.logger).to receive(:debug2).with(/unmanaged_2.*internal exclusion match/i)
155
164
 
156
165
  expect(subject.stale_contents(recurse, exclusions, whitelist)).
157
- to contain_exactly(/\/unmanaged_1/, /\/subdir_unmanaged_1/, /\/ignored_1/)
166
+ to contain_exactly(/\/unmanaged_1/, /\/unmanaged_symlink_file/, /\/subdir_unmanaged_1/, /\/ignored_1/,
167
+ /\/subdir_allowlisted_2/, /\/unmanaged_symlink_dir/)
158
168
  end
159
169
 
160
170
  it 'does not collect contents that match recursive globbed exclusion items as intermediate values' do
@@ -162,7 +172,7 @@ RSpec.describe R10K::Util::Purgeable do
162
172
  expect(subject.logger).not_to receive(:debug).with(/ignored_1/)
163
173
 
164
174
  expect(subject.stale_contents(recurse, recursive_exclusions, whitelist)).
165
- to contain_exactly(/\/unmanaged_2/, /\/managed_one\/unmanaged_1/)
175
+ to contain_exactly(/\/unmanaged_2/, /\/unmanaged_symlink_file/, /\/managed_one\/unmanaged_1/)
166
176
  end
167
177
  end
168
178
  end
@@ -199,6 +209,7 @@ RSpec.describe R10K::Util::Purgeable do
199
209
  it 'does not purge items matching glob at root level' do
200
210
  allow(FileUtils).to receive(:rm_r)
201
211
  expect(FileUtils).to_not receive(:rm_r).with(/\/unmanaged_[12]/, anything)
212
+ expect(FileUtils).to_not receive(:rm_r).with(/\/unmanaged_symlink_file/, anything)
202
213
  expect(subject.logger).to receive(:debug).with(/whitelist match/i).at_least(:once)
203
214
 
204
215
  subject.purge!(purge_opts)
@@ -209,7 +220,7 @@ RSpec.describe R10K::Util::Purgeable do
209
220
  context "recursive whitelist glob" do
210
221
  let(:whitelist) do
211
222
  managed_directories.flat_map do |dir|
212
- [File.join(dir, "**", "*unmanaged*"), File.join(dir, "**", "managed_subdir_2")]
223
+ [File.join(dir, "**", "*unmanaged*"), File.join(dir, "**", "subdir_allowlisted_2")]
213
224
  end
214
225
  end
215
226
  let(:purge_opts) { { recurse: true, whitelist: whitelist } }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r10k
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.12.1
4
+ version: 3.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrien Thebo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-17 00:00:00.000000000 Z
11
+ date: 2021-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored2
@@ -370,6 +370,7 @@ files:
370
370
  - lib/r10k/environment/base.rb
371
371
  - lib/r10k/environment/git.rb
372
372
  - lib/r10k/environment/name.rb
373
+ - lib/r10k/environment/plain.rb
373
374
  - lib/r10k/environment/svn.rb
374
375
  - lib/r10k/environment/with_modules.rb
375
376
  - lib/r10k/errors.rb
@@ -467,6 +468,7 @@ files:
467
468
  - spec/fixtures/unit/action/r10k_forge_auth.yaml
468
469
  - spec/fixtures/unit/action/r10k_forge_auth_no_url.yaml
469
470
  - spec/fixtures/unit/action/r10k_generate_types.yaml
471
+ - spec/fixtures/unit/action/r10k_logging.yaml
470
472
  - spec/fixtures/unit/action/r10k_puppet_path.yaml
471
473
  - spec/fixtures/unit/puppetfile/argument-error/Puppetfile
472
474
  - spec/fixtures/unit/puppetfile/default-branch-override/Puppetfile
@@ -480,10 +482,14 @@ files:
480
482
  - spec/fixtures/unit/puppetfile/various-modules/Puppetfile
481
483
  - spec/fixtures/unit/puppetfile/various-modules/Puppetfile.new
482
484
  - spec/fixtures/unit/util/purgeable/managed_one/expected_1
483
- - spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/managed_subdir_2/ignored_1
485
+ - spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/managed_symlink_file
486
+ - spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_allowlisted_2/ignored_1
484
487
  - spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_expected_1
485
488
  - spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_unmanaged_1
489
+ - spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/unmanaged_symlink_dir
490
+ - spec/fixtures/unit/util/purgeable/managed_one/managed_symlink_dir
486
491
  - spec/fixtures/unit/util/purgeable/managed_one/unmanaged_1
492
+ - spec/fixtures/unit/util/purgeable/managed_one/unmanaged_symlink_file
487
493
  - spec/fixtures/unit/util/purgeable/managed_two/.hidden/unmanaged_3
488
494
  - spec/fixtures/unit/util/purgeable/managed_two/expected_2
489
495
  - spec/fixtures/unit/util/purgeable/managed_two/unmanaged_2
@@ -495,6 +501,7 @@ files:
495
501
  - spec/integration/git/shellgit/thin_repository_spec.rb
496
502
  - spec/integration/git/shellgit/working_repository_spec.rb
497
503
  - spec/integration/git/stateful_repository_spec.rb
504
+ - spec/integration/util/purageable_spec.rb
498
505
  - spec/matchers/exit_with.rb
499
506
  - spec/matchers/match_realpath.rb
500
507
  - spec/r10k-mocks.rb
@@ -525,9 +532,11 @@ files:
525
532
  - spec/unit/cli_spec.rb
526
533
  - spec/unit/deployment/config_spec.rb
527
534
  - spec/unit/deployment_spec.rb
535
+ - spec/unit/environment/bare_spec.rb
528
536
  - spec/unit/environment/base_spec.rb
529
537
  - spec/unit/environment/git_spec.rb
530
538
  - spec/unit/environment/name_spec.rb
539
+ - spec/unit/environment/plain_spec.rb
531
540
  - spec/unit/environment/svn_spec.rb
532
541
  - spec/unit/environment/with_modules_spec.rb
533
542
  - spec/unit/errors/formatting_spec.rb