*: Always pass check= argument to subprocess.run()

- Avoid flake8 warnings.

- Makes the call more explicitly readable in case an exception is expected but
check=True is not passed by mistake.

Tests:

- Many tests are skipped since the changes are considered trivial.
check=False is already the default for subprocess.run() method.

- actions/package: Install an app when it is not installed.

- actions/upgrade: Run manual upgrades.

- actions/users: Change a user password. Login. Create/remove a user.

- actions/zoph: Restore a database.

- container: On a fresh repository, run ./container up,ssh,stop,destroy for a
testing container.

- plinth/action_utils.py: Enable/disable an app that has a running service.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2021-10-11 14:34:40 -04:00
1 parent ebd357476d
commit 9bd1f80d5c
17 files changed
+62 -55

No files matched your search

+2 -1
View File
@@ -226,7 +226,8 @@ def _get_ssh_key_file_for_import(original_key_file, service):
shutil.copy2(original_key_file, key_file)
# Convert OpenSSH format to PEM
subprocess.run(
['ssh-keygen', '-p', '-N', '', '-m', 'PEM', '-f', key_file])
['ssh-keygen', '-p', '-N', '', '-m', 'PEM', '-f', key_file],
check=True)
yield key_file
+1 -1
View File
@@ -96,7 +96,7 @@ def subcommand_install(arguments):
if arguments.force_missing_configuration:
extra_arguments += ['-o', 'Dpkg::Options::=--force-confmiss']
subprocess.run(['dpkg', '--configure', '-a'])
subprocess.run(['dpkg', '--configure', '-a'], check=False)
with apt_hold_freedombox():
run_apt_command(['--fix-broken', 'install'])
returncode = run_apt_command(['install'] + extra_arguments +
+1 -1
View File
@@ -273,7 +273,7 @@ def subcommand_mount(arguments):
process = subprocess.run([
'udisksctl', 'mount', '--block-device', arguments.block_device,
'--no-user-interaction'
])
], check=False)
sys.exit(process.returncode)
+3 -3
View File
@@ -140,7 +140,7 @@ def parse_arguments():
def _run():
"""Run unattended-upgrades"""
subprocess.run(['dpkg', '--configure', '-a'])
subprocess.run(['dpkg', '--configure', '-a'], check=False)
run_apt_command(['--fix-broken', 'install'])
# In case freedombox package was left in held state by an
@@ -453,7 +453,7 @@ def _perform_dist_upgrade():
['grub-pc grub-pc/install_devices_empty boolean true'])
print('Running unattended-upgrade...', flush=True)
subprocess.run(['unattended-upgrade', '--verbose'])
subprocess.run(['unattended-upgrade', '--verbose'], check=False)
# Remove obsolete packages that may prevent other packages from
# upgrading.
@@ -492,7 +492,7 @@ def _perform_dist_upgrade():
# Run unattended-upgrade once more to handle upgrading the
# freedombox package.
print('Running unattended-upgrade...', flush=True)
subprocess.run(['unattended-upgrade', '--verbose'])
subprocess.run(['unattended-upgrade', '--verbose'], check=False)
# Restore original snapshots configuration.
if snapshots_supported and apt_snapshots_enabled:
+3 -4
View File
@@ -373,7 +373,7 @@ def set_samba_user(username, password):
"""
proc = subprocess.run(['smbpasswd', '-a', '-s', username],
input='{0}\n{0}\n'.format(password).encode(),
stderr=subprocess.PIPE)
stderr=subprocess.PIPE, check=False)
if proc.returncode != 0:
raise RuntimeError('Unable to add Samba user: ', proc.stderr)
@@ -580,13 +580,12 @@ def flush_cache():
action_utils.service_reload('apache2')
def _run(arguments, **kwargs):
def _run(arguments, check=True, **kwargs):
"""Run a command. Check return code and suppress output by default."""
env = dict(os.environ, LDAPSCRIPTS_CONF=LDAPSCRIPTS_CONF)
kwargs['stdout'] = kwargs.get('stdout', subprocess.DEVNULL)
kwargs['stderr'] = kwargs.get('stderr', subprocess.DEVNULL)
kwargs['check'] = kwargs.get('check', True)
return subprocess.run(arguments, env=env, **kwargs)
return subprocess.run(arguments, env=env, check=check, **kwargs)
def main():
+1 -1
View File
@@ -128,7 +128,7 @@ def subcommand_dump_database(_):
def subcommand_restore_database(_):
"""Restore database from file."""
db_name = _get_db_name()
subprocess.run(['mysqladmin', '--force', 'drop', db_name])
subprocess.run(['mysqladmin', '--force', 'drop', db_name], check=False)
subprocess.run(['mysqladmin', 'create', db_name], check=True)
with open(DB_BACKUP_FILE, 'r') as db_restore_file:
subprocess.run(['mysql', db_name], stdin=db_restore_file, check=True)