Commit 7049d6c8 authored by Jérome Perrin's avatar Jérome Perrin

slapos node prune: write software pid file

slapos node prune already detected the case where software was running
and refused to run while software was runnning, to prevent a case where
software writes files and prune removes them because they are not yet
referenced, but nothing prevented the other way around: slapos node
software should not start while slapos node prune is deleting files. To
prevent this, make slapos node prune actually use software pid file,
then software will refuse to start while prune is running.
parent 261072c7
...@@ -34,6 +34,7 @@ import six.moves.configparser as configparser ...@@ -34,6 +34,7 @@ import six.moves.configparser as configparser
from slapos.cli.config import ConfigCommand from slapos.cli.config import ConfigCommand
from slapos.grid.slapgrid import merged_options from slapos.grid.slapgrid import merged_options
from slapos.grid.utils import setRunning, setFinished
from slapos.util import rmtree from slapos.util import rmtree
...@@ -66,7 +67,13 @@ class PruneCommand(ConfigCommand): ...@@ -66,7 +67,13 @@ class PruneCommand(ConfigCommand):
self.app.log.error('Cannot prune while software is running') self.app.log.error('Cannot prune while software is running')
sys.exit(-1) sys.exit(-1)
sys.exit(do_prune(self.app.log, options, args.dry_run)) if pidfile_software:
setRunning(logger=self.app.log, pidfile=pidfile_software)
try:
do_prune(self.app.log, options, args.dry_run)
finally:
if pidfile_software:
setFinished(pidfile_software)
def _prune( def _prune(
......
...@@ -399,6 +399,25 @@ class TestCliNode(CliMixin): ...@@ -399,6 +399,25 @@ class TestCliNode(CliMixin):
pidfile='/opt/slapos/slapgrid-cp.pid') pidfile='/opt/slapos/slapgrid-cp.pid')
processComputerPartitionList.assert_called_once() processComputerPartitionList.assert_called_once()
def test_node_prune(self):
"""slapos node prune command
"""
app = slapos.cli.entry.SlapOSApp()
with patch('slapos.cli.prune.setRunning') as write_pid_file, \
patch('slapos.cli.prune.merged_options', return_value={
'shared_part_list': 'something',
'pidfile_software': 'pidfile_software.pid',
}), \
patch('slapos.cli.prune.do_prune') as do_prune:
app.run(('node', 'prune'))
write_pid_file.assert_called_once_with(
logger=mock.ANY,
pidfile='pidfile_software.pid')
do_prune.assert_called_once()
class TestCliList(CliMixin): class TestCliList(CliMixin):
def test_list(self): def test_list(self):
......
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