Commit e64714f6 authored by Jérome Perrin's avatar Jérome Perrin

slapos node prune: check running as root according to config

When config specifies root_check=true, check that user is root instead
of probably failing with error messages because some permissions would
be refused.
parent 7049d6c8
Pipeline #12381 failed with stage
in 0 seconds
......@@ -32,10 +32,11 @@ import glob
import os
import six.moves.configparser as configparser
from slapos.cli.command import check_root_user
from slapos.cli.config import ConfigCommand
from slapos.grid.slapgrid import merged_options
from slapos.grid.utils import setRunning, setFinished
from slapos.util import rmtree
from slapos.util import rmtree, string_to_boolean
class PruneCommand(ConfigCommand):
......@@ -61,6 +62,9 @@ class PruneCommand(ConfigCommand):
self.app.log.error('No shared_part_list options in slapos config')
sys.exit(-1)
if string_to_boolean(options.get('root_check', 'True').lower()):
check_root_user(self)
pidfile_software = options.get('pidfile_software')
if not args.dry_run and pidfile_software and os.path.exists(
pidfile_software):
......
......@@ -404,15 +404,18 @@ class TestCliNode(CliMixin):
"""
app = slapos.cli.entry.SlapOSApp()
with patch('slapos.cli.prune.setRunning') as write_pid_file, \
with patch('slapos.cli.prune.check_root_user', return_value=True) as checked_root_user, \
patch('slapos.cli.prune.setRunning') as write_pid_file, \
patch('slapos.cli.prune.merged_options', return_value={
'shared_part_list': 'something',
'root_check': 'true',
'pidfile_software': 'pidfile_software.pid',
}), \
patch('slapos.cli.prune.do_prune') as do_prune:
app.run(('node', 'prune'))
checked_root_user.assert_called_once()
write_pid_file.assert_called_once_with(
logger=mock.ANY,
pidfile='pidfile_software.pid')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment