Skip to content

Commit

Permalink
fix: better exception handling for checking sudoers set
Browse files Browse the repository at this point in the history
  • Loading branch information
gavindsouza committed Mar 19, 2020
1 parent 6bb30e3 commit d51311b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion bench/patches/v5/fix_user_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,19 @@

def is_sudoers_set():
cmd = ["sudo", "-n", "bench"]
return (not subprocess.call(cmd)) or (change_uid_msg in get_cmd_output(cmd, _raise=False))

with open(os.devnull, "wb") as f:
return_code_check = not subprocess.call(cmd, stdout=f)

if return_code_check:
try:
bench_warn = change_uid_msg in get_cmd_output(cmd, _raise=False)
except Exception:
bench_warn = False
finally:
return_code_check = return_code_check and bench_warn

return return_code_check


def is_production_set(bench_path):
Expand Down
1 change: 1 addition & 0 deletions bench/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ def check_git_for_shallow_clone():


def get_cmd_output(cmd, cwd='.', _raise=True):
output = ""
try:
output = subprocess.check_output(cmd, cwd=cwd, shell=True, stderr=subprocess.PIPE).strip()
except subprocess.CalledProcessError as e:
Expand Down

0 comments on commit d51311b

Please sign in to comment.