Skip to content

Commit 3a4b5cb

Browse files
authored
Merge pull request #9157 from mhashizume/maint/main/nov-16-mergeup
(maint) Merge 7.x into main
2 parents 7ca202b + 6eba11d commit 3a4b5cb

File tree

9 files changed

+91
-41
lines changed

9 files changed

+91
-41
lines changed

acceptance/tests/resource/group/should_query_all.rb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,6 @@
88
skip_test('this test fails on windows French due to Cygwin/UTF Issues - PUP-8319,IMAGES-492') if agent['platform'] =~ /windows/ && agent['locale'] == 'fr'
99
step "query natively"
1010

11-
# [PA-4555] Added below code to enable SSH permissions before test starts if they are disabled by default
12-
if (agent['platform'] =~ /osx-12-arm64/ || agent['platform'] =~ /osx-13-arm64/)
13-
on(agent, 'dscl . list /Groups | grep com.apple.access_ssh') do
14-
stdout.each_line do |line|
15-
if line =~ /com.apple.access_ssh-disabled/
16-
on(agent, 'dscl . change /Groups/com.apple.access_ssh-disabled RecordName com.apple.access_ssh-disabled com.apple.access_ssh')
17-
end
18-
end
19-
end
20-
end
21-
2211
groups = agent.group_list
2312

2413
fail_test("No groups found") unless groups

lib/puppet/configurer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ def parse_fact_name_and_value_limits(object, path = [])
195195
path.push(key)
196196
parse_fact_name_and_value_limits(value, path)
197197
path.pop
198-
@number_of_facts += 1
199198
end
200199
when Array
201200
object.each_with_index do |e, idx|
@@ -206,6 +205,7 @@ def parse_fact_name_and_value_limits(object, path = [])
206205
else
207206
check_fact_name_length(path.join(), path.size)
208207
check_fact_values_length(object)
208+
@number_of_facts += 1
209209
end
210210
end
211211

lib/puppet/indirector/catalog/compiler.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,20 @@ def find(request)
5454
node.trusted_data = Puppet.lookup(:trusted_information) { Puppet::Context::TrustedInformation.local(node) }.to_h
5555

5656
if node.environment
57-
# If the requested environment doesn't match the server specified environment,
58-
# as determined by the node terminus, and the request wants us to check for an
57+
# If the requested environment name doesn't match the server specified environment
58+
# name, as determined by the node terminus, and the request wants us to check for an
5959
# environment mismatch, then return an empty catalog with the server-specified
6060
# enviroment.
61-
if request.remote? && request.options[:check_environment] && node.environment != request.environment
62-
return Puppet::Resource::Catalog.new(node.name, node.environment)
61+
if request.remote? && request.options[:check_environment]
62+
# The "environment" may be same while environment objects differ. This
63+
# is most likely because the environment cache was flushed between the request
64+
# processing and node lookup. Environment overrides `==` but requires the
65+
# name and modulepath to be the same. When using versioned environment dirs the
66+
# same "environment" can have different modulepaths so simply compare names here.
67+
if node.environment.name != request.environment.name
68+
Puppet.warning _("Requested environment '%{request_env}' did not match server specified environment '%{server_env}'") % {request_env: request.environment.name, server_env: node.environment.name}
69+
return Puppet::Resource::Catalog.new(node.name, node.environment)
70+
end
6371
end
6472

6573
node.environment.with_text_domain do

lib/puppet/provider/package/dnfmodule.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def install
9494
# module has no default profile and no profile was requested, so just enable the stream
9595
# DNF versions prior to 4.2.8 do not need this workaround
9696
# see https://bugzilla.redhat.com/show_bug.cgi?id=1669527
97-
if @resource[:flavor] == nil && e.message =~ /^(?:missing|broken) groups or modules: #{Regexp.quote(@resource[:name])}$/
97+
if @resource[:flavor] == nil && e.message =~ /^(?:missing|broken) groups or modules: #{Regexp.quote(args)}$/
9898
enable(args)
9999
else
100100
raise

lib/puppet/ssl/ssl_context.rb

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require_relative '../../puppet/ssl'
33

44
module Puppet::SSL
5+
# The `keyword_init: true` option is no longer needed in Ruby >= 3.2
56
SSLContext = Struct.new(
67
:store,
78
:cacerts,
@@ -10,22 +11,16 @@ module Puppet::SSL
1011
:client_cert,
1112
:client_chain,
1213
:revocation,
13-
:verify_peer
14+
:verify_peer,
15+
keyword_init: true
1416
) do
15-
DEFAULTS = {
16-
cacerts: [],
17-
crls: [],
18-
client_chain: [],
19-
revocation: true,
20-
verify_peer: true
21-
}.freeze
22-
23-
# This is an idiom to initialize a Struct from keyword
24-
# arguments. Ruby 2.5 introduced `keyword_init: true` for
25-
# that purpose, but we need to support older versions.
26-
def initialize(kwargs = {})
27-
super({})
28-
DEFAULTS.merge(**kwargs).each { |k,v| self[k] = v }
17+
def initialize(*)
18+
super
19+
self[:cacerts] ||= []
20+
self[:crls] ||= []
21+
self[:client_chain] ||= []
22+
self[:revocation] = true if self[:revocation].nil?
23+
self[:verify_peer] = true if self[:verify_peer].nil?
2924
end
3025
end
3126
end

lib/puppet/type/exec.rb

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -593,13 +593,17 @@ def check(value)
593593
cmd = self[:command]
594594
cmd = cmd[0] if cmd.is_a? Array
595595

596-
cmd.scan(file_regex) { |str|
597-
reqs << str
598-
}
596+
if cmd.is_a?(Puppet::Pops::Evaluator::DeferredValue)
597+
self.debug("The 'command' parameter is deferred and cannot be autorequired")
598+
else
599+
cmd.scan(file_regex) { |str|
600+
reqs << str
601+
}
599602

600-
cmd.scan(/^"([^"]+)"/) { |str|
601-
reqs << str
602-
}
603+
cmd.scan(/^"([^"]+)"/) { |str|
604+
reqs << str
605+
}
606+
end
603607

604608
[:onlyif, :unless].each { |param|
605609
tmp = self[param]
@@ -614,7 +618,11 @@ def check(value)
614618
# unqualified files, but, well, that's a bit more annoying
615619
# to do.
616620
line = line[0] if line.is_a? Array
617-
reqs += line.scan(file_regex)
621+
if line.is_a?(Puppet::Pops::Evaluator::DeferredValue)
622+
self.debug("The '#{param}' parameter is deferred and cannot be autorequired")
623+
else
624+
reqs += line.scan(file_regex)
625+
end
618626
end
619627
}
620628

spec/unit/indirector/catalog/compiler_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,23 @@ def set_facts(fact_hash)
271271
expect(catalog).to have_resource('Stage[main]')
272272
end
273273

274+
# versioned environment directories can cause this
275+
it 'allows environments with the same name but mismatched modulepaths' do
276+
envs = Puppet.lookup(:environments)
277+
env_server = envs.get!(:env_server)
278+
v1_env = env_server.override_with({ modulepath: ['/code-v1/env-v1/'] })
279+
v2_env = env_server.override_with({ modulepath: ['/code-v2/env-v2/'] })
280+
281+
@request.options[:check_environment] = "true"
282+
@request.environment = v1_env
283+
node.environment = v2_env
284+
285+
catalog = compiler.find(@request)
286+
287+
expect(catalog.environment).to eq('env_server')
288+
expect(catalog).to have_resource('Stage[main]')
289+
end
290+
274291
it 'returns an empty catalog if asked to check the environment and they are mismatched' do
275292
@request.options[:check_environment] = "true"
276293
catalog = compiler.find(@request)

spec/unit/provider/package/dnfmodule_spec.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
provider.install
124124
end
125125

126-
it "should just enable the module if it has no default profile(missing groups or modules)" do
126+
it "should just enable the module if it has no default profile (missing groups or modules)" do
127127
dnf_exception = Puppet::ExecutionFailure.new("Error: Problems in request:\nmissing groups or modules: #{resource[:name]}")
128128
allow(provider).to receive(:execute).with(array_including('install')).and_raise(dnf_exception)
129129
resource[:ensure] = :present
@@ -132,7 +132,17 @@
132132
provider.install
133133
end
134134

135-
it "should just enable the module if it has no default profile(broken groups or modules)" do
135+
it "should just enable the module with the right stream if it has no default profile (missing groups or modules)" do
136+
stream = '12.3'
137+
dnf_exception = Puppet::ExecutionFailure.new("Error: Problems in request:\nmissing groups or modules: #{resource[:name]}:#{stream}")
138+
allow(provider).to receive(:execute).with(array_including('install')).and_raise(dnf_exception)
139+
resource[:ensure] = stream
140+
expect(provider).to receive(:execute).with(array_including('install')).ordered
141+
expect(provider).to receive(:execute).with(array_including('enable')).ordered
142+
provider.install
143+
end
144+
145+
it "should just enable the module if it has no default profile (broken groups or modules)" do
136146
dnf_exception = Puppet::ExecutionFailure.new("Error: Problems in request:\nbroken groups or modules: #{resource[:name]}")
137147
allow(provider).to receive(:execute).with(array_including('install')).and_raise(dnf_exception)
138148
resource[:ensure] = :present
@@ -141,6 +151,16 @@
141151
provider.install
142152
end
143153

154+
it "should just enable the module with the right stream if it has no default profile (broken groups or modules)" do
155+
stream = '12.3'
156+
dnf_exception = Puppet::ExecutionFailure.new("Error: Problems in request:\nbroken groups or modules: #{resource[:name]}:#{stream}")
157+
allow(provider).to receive(:execute).with(array_including('install')).and_raise(dnf_exception)
158+
resource[:ensure] = stream
159+
expect(provider).to receive(:execute).with(array_including('install')).ordered
160+
expect(provider).to receive(:execute).with(array_including('enable')).ordered
161+
provider.install
162+
end
163+
144164
it "should just enable the module if enable_only = true" do
145165
resource[:ensure] = :present
146166
resource[:enable_only] = true

spec/unit/type/exec_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,19 @@ def exec_stub(options = {})
252252
expect(dependencies.collect(&:to_s)).to eq([Puppet::Relationship.new(tmp, execer).to_s])
253253
end
254254

255+
it "skips autorequire for deferred commands" do
256+
foo = make_absolute('/bin/foo')
257+
catalog = Puppet::Resource::Catalog.new
258+
tmp = Puppet::Type.type(:file).new(:name => foo)
259+
execer = Puppet::Type.type(:exec).new(:name => 'test array', :command => Puppet::Pops::Evaluator::DeferredValue.new(nil))
260+
261+
catalog.add_resource tmp
262+
catalog.add_resource execer
263+
dependencies = execer.autorequire(catalog)
264+
265+
expect(dependencies.collect(&:to_s)).to eq([])
266+
end
267+
255268
describe "when handling the path parameter" do
256269
expect = %w{one two three four}
257270
{ "an array" => expect,

0 commit comments

Comments
 (0)