Skip to content

Commit

Permalink
Integration Tests: Check for exceptions at build time (#10789)
Browse files Browse the repository at this point in the history
* Integration Tests: Check for exceptions at build time

* Update install_chrome_dependencies.py

* Reintroduce automatic chrome revs + fail gracefully

* Correct formatting

* Do not get latest version of chrome driver
  • Loading branch information
Maffooch authored Oct 3, 2024
1 parent fbe0855 commit f383947
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions docker/install_chrome_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,47 @@


def find_packages(library_name):
stdout = run_command(["apt-file", "search", library_name])
stdout, stderr, status_code = run_command(["apt-file", "search", library_name])
# Check if ldd has failed for a good reason, or if there are no results
if status_code != 0:
# Any other case should be be caught
msg = f"apt-file search (exit code {status_code}): {stderr}"
raise ValueError(msg)

if not stdout.strip():
return []
libs = [line.split(":")[0] for line in stdout.strip().split("\n")]
return list(set(libs))


def run_command(cmd, cwd=None, env=None):
# Do not raise exception here because some commands are too loose with negative exit codes
result = subprocess.run(cmd, cwd=cwd, env=env, capture_output=True, text=True, check=False)
return result.stdout
return result.stdout.strip(), result.stderr.strip(), result.returncode


def ldd(file_path):
stdout = run_command(["ldd", file_path])
# For simplicity, I'm assuming if we get an error, the code is non-zero.
try:
result = subprocess.run(
["ldd", file_path], capture_output=True, text=True, check=False,
)
stdout = result.stdout
code = result.returncode
except subprocess.CalledProcessError:
stdout = ""
code = 1
return stdout, code
stdout, stderr, status_code = run_command(["ldd", file_path])
# Check if ldd has failed for a good reason, or if there are no results
if status_code != 0:
# It is often the case when stdout will be empty. This is not an error
if not stdout:
return stdout, status_code
# Any other case should be be caught
msg = f"ldd (exit code {status_code}): {stderr}"
raise ValueError(msg)

return stdout, status_code


raw_deps = ldd("/opt/chrome/chrome")
dependencies = raw_deps[0].splitlines()

missing_deps = {
r[0].strip()
for d in dependencies
for r in [d.split("=>")]
if len(r) == 2 and r[1].strip() == "not found"
}

missing_packages = []
for d in missing_deps:
all_packages = find_packages(d)
Expand All @@ -59,5 +63,4 @@ def ldd(file_path):
]
for p in packages:
missing_packages.append(p)

logger.info("missing_packages: " + (" ".join(missing_packages)))

0 comments on commit f383947

Please sign in to comment.