slapos: allow to use supervisorctl without automatically starting supervisord.

parent 0f8706b4
......@@ -31,7 +31,6 @@ import argparse
from slapos.cli.command import check_root_user
from slapos.cli.config import ConfigCommand
from slapos.grid.svcbackend import (launchSupervisord, _getSupervisordConfigurationFilePath)
import supervisor.supervisorctl
......@@ -54,6 +53,11 @@ class SupervisorctlCommand(ConfigCommand):
return True
return configp.getboolean('slapos', 'root_check')
def _should_forbid_supervisord_launch(self, configp):
if not configp.has_option('supervisorctl', 'forbid_supervisord_automatic_launch'):
return False
return configp.getboolean('supervisorctl', 'forbid_supervisord_automatic_launch')
def take_action(self, args):
configp = self.fetch_config(args)
......@@ -63,11 +67,19 @@ class SupervisorctlCommand(ConfigCommand):
check_root_user(self)
instance_root = configp.get('slapos', 'instance_root')
launchSupervisord(instance_root=instance_root, logger=self.app.log)
supervisor.supervisorctl.main(
args=['-c', _getSupervisordConfigurationFilePath(instance_root)] + args.supervisor_args
forbid_supervisord_launch = self._should_forbid_supervisord_launch(configp)
do_supervisorctl(
self.app.log, instance_root, args.supervisor_args,
forbid_supervisord_launch
)
def do_supervisorctl(logger, instance_root, supervisor_args, forbid_supervisord_launch=False):
from slapos.grid.svcbackend import (launchSupervisord, _getSupervisordConfigurationFilePath)
if forbid_supervisord_launch is False:
launchSupervisord(instance_root=instance_root, logger=logger)
supervisor.supervisorctl.main(
args=['-c', _getSupervisordConfigurationFilePath(instance_root)] + supervisor_args
)
class SupervisorctlAliasCommand(SupervisorctlCommand):
def take_action(self, args):
......
......@@ -33,10 +33,14 @@ from mock import patch, create_autospec
import slapos.cli.list
import slapos.cli.info
import slapos.cli.supervisorctl
from slapos.client import ClientConfig
import slapos.grid.svcbackend
import slapos.proxy
import slapos.slap
import supervisor.supervisorctl
def raiseNotFoundError(*args, **kwargs):
raise slapos.slap.NotFoundError()
......@@ -126,3 +130,24 @@ class TestCliInfo(CliMixin):
self.logger.warning.assert_called_once_with('Instance %s does not exist.', self.conf.reference)
@patch.object(supervisor.supervisorctl, 'main')
class TestCliSupervisorctl(CliMixin):
def test_allow_supervisord_launch(self, _):
"""
Test that "slapos node supervisorctl" tries to launch supervisord
"""
instance_root = '/foo/bar'
with patch.object(slapos.grid.svcbackend, 'launchSupervisord') as launchSupervisord:
slapos.cli.supervisorctl.do_supervisorctl(self.logger, instance_root, ['status'], False)
launchSupervisord.assert_any_call(instance_root=instance_root, logger=self.logger)
def test_forbid_supervisord_launch(self, _):
"""
Test that "slapos node supervisorctl" does not try to launch supervisord
"""
instance_root = '/foo/bar'
with patch.object(slapos.grid.svcbackend, 'launchSupervisord') as launchSupervisord:
slapos.cli.supervisorctl.do_supervisorctl(self.logger, instance_root, ['status'], True)
self.assertFalse(launchSupervisord.called)
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