Skip to content

Commit

Permalink
Land #3, Update healthchecks to handle ldd failures
Browse files Browse the repository at this point in the history
  • Loading branch information
adfoster-r7 authored Apr 19, 2024
2 parents 4a1754f + feb28e3 commit c6dc312
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 17 deletions.
20 changes: 10 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ -->

<!-- latest_release 9.0.23 -->
## [9.0.23](https://github.com/chef/omnibus/tree/9.0.23) (2023-09-22)

#### Merged Pull Requests
- CHEF-5815: Update signing of all msi packages with new cli tool - `smctl` [#1128](https://github.com/chef/omnibus/pull/1128) ([ahasunos](https://github.com/ahasunos))
<!-- latest_release -->
<!-- release_rollup since=9.0.22 -->
<!-- latest_release -->
<!-- release_rollup since=9.0.23 -->
### Changes not yet released to rubygems.org

#### Merged Pull Requests
- CHEF-5815: Update signing of all msi packages with new cli tool - `smctl` [#1128](https://github.com/chef/omnibus/pull/1128) ([ahasunos](https://github.com/ahasunos)) <!-- 9.0.23 -->
<!-- release_rollup -->
<!-- latest_stable_release -->
## [9.0.23](https://github.com/chef/omnibus/tree/9.0.23) (2023-09-25)
<!-- latest_stable_release -->

## [9.0.23](https://github.com/chef/omnibus/tree/9.0.23) (2023-09-25)

#### Merged Pull Requests
- CHEF-5815: Update signing of all msi packages with new cli tool - `smctl` [#1128](https://github.com/chef/omnibus/pull/1128) ([ahasunos](https://github.com/ahasunos))

## [9.0.22](https://github.com/chef/omnibus/tree/9.0.22) (2023-08-18)

#### Merged Pull Requests
Expand All @@ -21,7 +22,6 @@
- Fix Ruby 3.1 deprecation warning with ERB.new [#1108](https://github.com/chef/omnibus/pull/1108) ([stanhu](https://github.com/stanhu))
- Update gpg_name to fix RockyLinux rpm signing issue [#1118](https://github.com/chef/omnibus/pull/1118) ([poorndm](https://github.com/poorndm))
- Update metadata with rocky platform [#1125](https://github.com/chef/omnibus/pull/1125) ([poorndm](https://github.com/poorndm))
<!-- latest_stable_release -->

## [9.0.17](https://github.com/chef/omnibus/tree/9.0.17) (2023-02-20)

Expand Down
38 changes: 31 additions & 7 deletions lib/omnibus/health_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -511,16 +511,40 @@ def read_shared_libs(find_command, ldd_command, &output_proc)
# feed the list of files to the "ldd" command
#

# this command will typically fail if the last file isn't a valid lib/binary which happens often
ldd_output = shellout(ldd_command, input: find_output.join).stdout
# instance Mixlib::ShellOut
ldd_cmd = shellout(ldd_command, input: find_output.join)

# Optimized path: Attempt to run the `ldd` command on all file paths. If it succeeds, then process
# the stdout result in bulk. If the command returned a non-zero exit status code, then something went wrong.
# Each path will have to be manually resolved
unless ldd_cmd.error?
# do the output process to determine if the files are good or bad
ldd_cmd.stdout.each_line do |line|
output_proc.call(line)
end
else
log.debug(log_key) { "Failed running #{ldd_command} with exit status #{ldd_cmd.exitstatus} when resolving individually" }

#
# do the output process to determine if the files are good or bad
#
# Verify each path separately
find_output.each do |path|
ldd_cmd = shellout(ldd_command, input: path)
if ldd_cmd.error?
log.debug(log_key) { "Failed running #{ldd_command} with exit status #{ldd_cmd.exitstatus} against: #{path}" }
end

ldd_output.each_line do |line|
output_proc.call(line)
ldd_output = ldd_cmd.stdout

# Yield the path first
output_proc.call("#{path.rstrip}:")

# do the output process to determine if the files are good or bad
ldd_output.each_line do |line|
output_proc.call(line)
end
end
end

nil
end

#
Expand Down
54 changes: 54 additions & 0 deletions spec/unit/health_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,28 @@ def mkdump(base, size, x64 = false)
let(:file_list) do
double("Mixlib::Shellout",
error!: false,
error?: false,
stdout: <<~EOH
/opt/chefdk/shouldnt/matter
EOH
)
end

let(:file_list_multiple) do
double("Mixlib::Shellout",
error!: false,
error?: false,
stdout: <<~EOH
/opt/chefdk/first
/opt/chefdk/second
EOH
)
end

let(:empty_list) do
double("Mixlib::Shellout",
error!: false,
error?: false,
stdout: <<~EOH
EOH
)
Expand All @@ -238,6 +251,7 @@ def mkdump(base, size, x64 = false)
let(:bad_list) do
double("Mixlib::Shellout",
error!: false,
error?: false,
stdout: <<~EOH
/somewhere/other/than/install/dir
EOH
Expand All @@ -247,6 +261,7 @@ def mkdump(base, size, x64 = false)
let(:bad_healthcheck) do
double("Mixlib::Shellout",
error!: false,
error?: false,
stdout: <<~EOH
/bin/ls:
linux-vdso.so.1 => (0x00007fff583ff000)
Expand All @@ -269,6 +284,7 @@ def mkdump(base, size, x64 = false)
let(:good_healthcheck) do
double("Mixlib::Shellout",
error!: false,
error?: false,
stdout: <<~EOH
/bin/echo:
linux-vdso.so.1 => (0x00007fff8a6ee000)
Expand All @@ -282,6 +298,17 @@ def mkdump(base, size, x64 = false)
)
end

let(:bad_exitstatus_healthcheck) do
double("Mixlib::Shellout",
error!: -> { raise Mixlib::ShellOut::ShellCommandFailed },
error?: true,
exitstatus: 135,
stdout: <<~EOH
/bin/echo:
EOH
)
end

it "raises an exception when there are external dependencies" do
allow(subject).to receive(:shellout)
.with("find /opt/chefdk/ -type f | xargs file | grep \"ELF\" | awk -F: '{print $1}' | sed -e 's/:$//'")
Expand All @@ -306,6 +333,33 @@ def mkdump(base, size, x64 = false)
expect { subject.run! }.to_not raise_error
end

it "does checks lld for each file if the initial bulk ldd command fails" do
allow(subject).to receive(:shellout)
.with("find /opt/chefdk/ -type f | xargs file | grep \"ELF\" | awk -F: '{print $1}' | sed -e 's/:$//'")
.and_return(file_list_multiple)

# Bulk ldd command fails
allow(subject).to receive(:shellout)
.with("xargs ldd", { input: "/opt/chefdk/first\n/opt/chefdk/second\n" })
.and_return(bad_exitstatus_healthcheck)

# First file ldd fails
allow(subject).to receive(:shellout)
.with("xargs ldd", { input: "/opt/chefdk/first\n" })
.and_return(bad_exitstatus_healthcheck)

# Second file lld succeeds
allow(subject).to receive(:shellout)
.with("xargs ldd", { input: "/opt/chefdk/second\n" })
.and_return(good_healthcheck)

output = capture_logging do
expect { subject.run! }.to_not raise_error
end
expect(output).to match(/Failed running xargs ldd with exit status 135 when resolving individually/)
expect(output).to match(%r{Failed running xargs ldd with exit status 135 against: /opt/chefdk/first})
end

it "will not perform dll base relocation checks" do
expect(subject.relocation_checkable?).to be false
end
Expand Down

0 comments on commit c6dc312

Please sign in to comment.