slapos: allow to use supervisorctl without automatically starting supervisord.

parent 0f8706b4
...@@ -31,7 +31,6 @@ import argparse ...@@ -31,7 +31,6 @@ import argparse
from slapos.cli.command import check_root_user from slapos.cli.command import check_root_user
from slapos.cli.config import ConfigCommand from slapos.cli.config import ConfigCommand
from slapos.grid.svcbackend import (launchSupervisord, _getSupervisordConfigurationFilePath)
import supervisor.supervisorctl import supervisor.supervisorctl
...@@ -54,6 +53,11 @@ class SupervisorctlCommand(ConfigCommand): ...@@ -54,6 +53,11 @@ class SupervisorctlCommand(ConfigCommand):
return True return True
return configp.getboolean('slapos', 'root_check') 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): def take_action(self, args):
configp = self.fetch_config(args) configp = self.fetch_config(args)
...@@ -63,11 +67,19 @@ class SupervisorctlCommand(ConfigCommand): ...@@ -63,11 +67,19 @@ class SupervisorctlCommand(ConfigCommand):
check_root_user(self) check_root_user(self)
instance_root = configp.get('slapos', 'instance_root') instance_root = configp.get('slapos', 'instance_root')
launchSupervisord(instance_root=instance_root, logger=self.app.log) forbid_supervisord_launch = self._should_forbid_supervisord_launch(configp)
supervisor.supervisorctl.main( do_supervisorctl(
args=['-c', _getSupervisordConfigurationFilePath(instance_root)] + args.supervisor_args 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): class SupervisorctlAliasCommand(SupervisorctlCommand):
def take_action(self, args): def take_action(self, args):
......
...@@ -33,10 +33,14 @@ from mock import patch, create_autospec ...@@ -33,10 +33,14 @@ from mock import patch, create_autospec
import slapos.cli.list import slapos.cli.list
import slapos.cli.info import slapos.cli.info
import slapos.cli.supervisorctl
from slapos.client import ClientConfig from slapos.client import ClientConfig
import slapos.grid.svcbackend
import slapos.proxy import slapos.proxy
import slapos.slap import slapos.slap
import supervisor.supervisorctl
def raiseNotFoundError(*args, **kwargs): def raiseNotFoundError(*args, **kwargs):
raise slapos.slap.NotFoundError() raise slapos.slap.NotFoundError()
...@@ -126,3 +130,24 @@ class TestCliInfo(CliMixin): ...@@ -126,3 +130,24 @@ class TestCliInfo(CliMixin):
self.logger.warning.assert_called_once_with('Instance %s does not exist.', self.conf.reference) 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