Skip to content

Commit d1463bb

Browse files
(maint) Merge up 5e9536c to main
Generated by CI * commit '5e9536c0ce1b31eb6c3740620c49cef33a9ab2b5': (packaging) Updating the puppet.pot file (PUP-11265) Push last used environment and loaders onto the context (PUP-11208) Retry pkg install on Solaris
2 parents 3828aab + 5e9536c commit d1463bb

File tree

4 files changed

+53
-16
lines changed

4 files changed

+53
-16
lines changed

lib/puppet/configurer.rb

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ def run_internal(options)
393393
if last_server_specified_environment
394394
@environment = last_server_specified_environment
395395
report.environment = last_server_specified_environment
396+
397+
push_current_environment_and_loaders
396398
else
397399
Puppet.debug(_("Could not find a usable environment in the lastrunfile. Either the file does not exist, does not have the required keys, or the values of 'initial_environment' and 'converged_environment' are identical."))
398400
end
@@ -403,14 +405,7 @@ def run_internal(options)
403405
# This is to maintain compatibility with anyone using this class
404406
# aside from agent, apply, device.
405407
unless Puppet.lookup(:loaders) { nil }
406-
new_env = Puppet::Node::Environment.remote(@environment)
407-
Puppet.push_context(
408-
{
409-
current_environment: new_env,
410-
loaders: Puppet::Pops::Loaders.new(new_env, true)
411-
},
412-
"Local node environment #{@environment} for configurer transaction"
413-
)
408+
push_current_environment_and_loaders
414409
end
415410

416411
temp_value = options[:pluginsync]
@@ -446,14 +441,7 @@ def run_internal(options)
446441
@environment = catalog.environment
447442
report.environment = @environment
448443

449-
new_env = Puppet::Node::Environment.remote(@environment)
450-
Puppet.push_context(
451-
{
452-
:current_environment => new_env,
453-
:loaders => Puppet::Pops::Loaders.new(new_env, true)
454-
},
455-
"Local node environment #{@environment} for configurer transaction"
456-
)
444+
push_current_environment_and_loaders
457445

458446
query_options, facts = get_facts(options)
459447
query_options[:configured_environment] = configured_environment
@@ -649,6 +637,17 @@ def execute_from_setting(setting)
649637
end
650638
end
651639

640+
def push_current_environment_and_loaders
641+
new_env = Puppet::Node::Environment.remote(@environment)
642+
Puppet.push_context(
643+
{
644+
:current_environment => new_env,
645+
:loaders => Puppet::Pops::Loaders.new(new_env, true)
646+
},
647+
"Local node environment #{@environment} for configurer transaction"
648+
)
649+
end
650+
652651
def retrieve_catalog_from_cache(query_options)
653652
result = nil
654653
@duration = thinmark do

lib/puppet/provider/package/pkg.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,17 @@ def install(nofail = false)
237237
end
238238
self.unhold if self.properties[:mark] == :hold
239239
begin
240+
tries = 1
241+
# pkg install exits with code 7 when the image is currently in use by another process and cannot be modified
240242
r = exec_cmd(command(:pkg), command, *args, name)
243+
while r[:exit] == 7 do
244+
if tries > 4
245+
raise Puppet::Error, _("Pkg could not install %{name} after %{tries} tries. Aborting run") % { name: name, tries: tries }
246+
end
247+
sleep 2 ** tries
248+
tries += 1
249+
r = exec_cmd(command(:pkg), command, *args, name)
250+
end
241251
ensure
242252
self.hold if @resource[:mark] == :hold
243253
end

spec/unit/configurer_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,20 @@ def expects_neither_new_or_cached_catalog
12821282
expect(configurer.environment).to eq(last_server_specified_environment)
12831283
end
12841284

1285+
it "pushes the converged environment found in lastrunfile over the existing context" do
1286+
initial_env = Puppet::Node::Environment.remote('production')
1287+
Puppet.push_context(
1288+
current_environment: initial_env,
1289+
loaders: Puppet::Pops::Loaders.new(initial_env, true))
1290+
1291+
expect(Puppet).to receive(:push_context).with(
1292+
hash_including(:current_environment, :loaders),
1293+
"Local node environment #{last_server_specified_environment} for configurer transaction"
1294+
).once.and_call_original
1295+
1296+
configurer.run
1297+
end
1298+
12851299
it "uses environment from Puppet[:environment] if strict_environment_mode is set" do
12861300
Puppet[:strict_environment_mode] = true
12871301
configurer.run

spec/unit/provider/package/pkg_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,20 @@ def self.it_should_respond_to(*actions)
414414
.and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
415415
provider.insync?(is)
416416
end
417+
418+
it "should try 5 times to install and fail when all tries failed" do
419+
allow_any_instance_of(Kernel).to receive(:sleep)
420+
421+
expect(provider).to receive(:query).and_return({:ensure => :absent})
422+
expect(provider).to receive(:properties).and_return({:mark => :hold})
423+
expect(provider).to receive(:unhold)
424+
expect(Puppet::Util::Execution).to receive(:execute)
425+
.with(['/bin/pkg', 'install', *hash[:flags], 'dummy'], {:failonfail => false, :combine => true}).exactly(5).times
426+
allow($CHILD_STATUS).to receive(:exitstatus).and_return(7)
427+
expect {
428+
provider.update
429+
}.to raise_error(Puppet::Error, /Pkg could not install dummy after 5 tries. Aborting run/)
430+
end
417431
end
418432
end
419433
end

0 commit comments

Comments
 (0)