mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
Introduce uwsgi component to manage uWSGI configuration
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
1 parent
4100d36381
commit
862d87920a
7 files changed
+173
-28
No files matched your search
@@ -58,3 +58,41 @@ class Webserver(app.LeaderComponent):
|
||||
actions.superuser_run(
|
||||
'apache',
|
||||
['disable', '--name', self.web_name, '--kind', self.kind])
|
||||
|
||||
|
||||
class Uwsgi(app.LeaderComponent):
|
||||
"""Component to enable/disable uWSGI configuration."""
|
||||
|
||||
def __init__(self, component_id, uwsgi_name):
|
||||
"""Initialize the uWSGI component.
|
||||
|
||||
component_id should be a unique ID across all components of an app and
|
||||
across all components.
|
||||
|
||||
uwsgi_name is the primary part of the configuration file path which must
|
||||
be enabled/disabled by this component.
|
||||
|
||||
"""
|
||||
super().__init__(component_id)
|
||||
|
||||
self.uwsgi_name = uwsgi_name
|
||||
|
||||
def is_enabled(self):
|
||||
"""Return whether the uWSGI configuration is enabled."""
|
||||
return action_utils.uwsgi_is_enabled(self.uwsgi_name) \
|
||||
and action_utils.service_is_enabled('uwsgi')
|
||||
|
||||
def enable(self):
|
||||
"""Enable the uWSGI configuration."""
|
||||
actions.superuser_run('apache',
|
||||
['uwsgi-enable', '--name', self.uwsgi_name])
|
||||
|
||||
def disable(self):
|
||||
"""Disable the uWSGI configuration."""
|
||||
actions.superuser_run('apache',
|
||||
['uwsgi-disable', '--name', self.uwsgi_name])
|
||||
|
||||
def is_running(self):
|
||||
"""Return whether the uWSGI daemon is running with configuration."""
|
||||
return action_utils.uwsgi_is_enabled(self.uwsgi_name) \
|
||||
and action_utils.service_is_running('uwsgi')
|
||||
@@ -22,7 +22,7 @@ from unittest.mock import call, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from plinth.modules.apache.components import Webserver
|
||||
from plinth.modules.apache.components import Uwsgi, Webserver
|
||||
|
||||
|
||||
def test_webserver_init():
|
||||
@@ -75,3 +75,80 @@ def test_webserver_disable(superuser_run):
|
||||
call('apache',
|
||||
['disable', '--name', 'test-config', '--kind', 'module'])
|
||||
])
|
||||
|
||||
|
||||
def test_uwsgi_init():
|
||||
"""Test that uWSGI component can be initialized."""
|
||||
with pytest.raises(ValueError):
|
||||
Uwsgi(None, None)
|
||||
|
||||
uwsgi = Uwsgi('test-uwsgi', 'test-config')
|
||||
assert uwsgi.component_id == 'test-uwsgi'
|
||||
assert uwsgi.uwsgi_name == 'test-config'
|
||||
|
||||
|
||||
@patch('plinth.action_utils.service_is_enabled')
|
||||
@patch('plinth.action_utils.uwsgi_is_enabled')
|
||||
def test_uwsgi_is_enabled(uwsgi_is_enabled, service_is_enabled):
|
||||
"""Test that checking uwsgi configuration enabled works."""
|
||||
uwsgi = Uwsgi('test-uwsgi', 'test-config')
|
||||
|
||||
uwsgi_is_enabled.return_value = True
|
||||
service_is_enabled.return_value = True
|
||||
assert uwsgi.is_enabled()
|
||||
uwsgi_is_enabled.assert_has_calls([call('test-config')])
|
||||
service_is_enabled.assert_has_calls([call('uwsgi')])
|
||||
|
||||
service_is_enabled.return_value = False
|
||||
assert not uwsgi.is_enabled()
|
||||
|
||||
uwsgi_is_enabled.return_value = False
|
||||
assert not uwsgi.is_enabled()
|
||||
|
||||
service_is_enabled.return_value = False
|
||||
assert not uwsgi.is_enabled()
|
||||
|
||||
|
||||
@patch('plinth.actions.superuser_run')
|
||||
def test_uwsgi_enable(superuser_run):
|
||||
"""Test that enabling uwsgi configuration works."""
|
||||
uwsgi = Uwsgi('test-uwsgi', 'test-config')
|
||||
|
||||
uwsgi.enable()
|
||||
superuser_run.assert_has_calls(
|
||||
[call('apache', ['uwsgi-enable', '--name', 'test-config'])])
|
||||
|
||||
|
||||
@patch('plinth.actions.superuser_run')
|
||||
def test_uwsgi_disable(superuser_run):
|
||||
"""Test that disabling uwsgi configuration works."""
|
||||
uwsgi = Uwsgi('test-uwsgi', 'test-config')
|
||||
|
||||
uwsgi.disable()
|
||||
superuser_run.assert_has_calls(
|
||||
[call('apache', ['uwsgi-disable', '--name', 'test-config'])])
|
||||
|
||||
|
||||
@patch('plinth.action_utils.service_is_running')
|
||||
@patch('plinth.action_utils.uwsgi_is_enabled')
|
||||
def test_uwsgi_is_running(uwsgi_is_enabled, service_is_running):
|
||||
"""Test checking whether uwsgi is running with a configuration."""
|
||||
uwsgi = Uwsgi('test-uwsgi', 'test-config')
|
||||
|
||||
uwsgi_is_enabled.return_value = True
|
||||
service_is_running.return_value = True
|
||||
assert uwsgi.is_running()
|
||||
uwsgi_is_enabled.assert_has_calls([call('test-config')])
|
||||
service_is_running.assert_has_calls([call('uwsgi')])
|
||||
|
||||
uwsgi_is_enabled.return_value = False
|
||||
service_is_running.return_value = True
|
||||
assert not uwsgi.is_running()
|
||||
|
||||
uwsgi_is_enabled.return_value = True
|
||||
service_is_running.return_value = False
|
||||
assert not uwsgi.is_running()
|
||||
|
||||
uwsgi_is_enabled.return_value = False
|
||||
service_is_running.return_value = False
|
||||
assert not uwsgi.is_running()
|
||||
Reference in new issue
Block a user