package, email: Move conflicting package removal to framework

- Warning that exim4 will be removed is incorrectly not shown during email app
installation. Fix that.

Tests:

- Unit tests pass.

- On a fresh testing container, trying to install email app shows the warning
message that exim will be removed. Installing the email app succeeds. exim is
removed during installation.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2022-12-15 16:46:18 -08:00 committed by James Valleroy
parent bb527673fb
commit 0b9d567493
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
3 changed files with 39 additions and 12 deletions

View File

@ -15,7 +15,7 @@ from plinth.modules.config import get_domainname
from plinth.modules.firewall.components import (Firewall, from plinth.modules.firewall.components import (Firewall,
FirewallLocalProtection) FirewallLocalProtection)
from plinth.modules.letsencrypt.components import LetsEncrypt from plinth.modules.letsencrypt.components import LetsEncrypt
from plinth.package import Packages, uninstall from plinth.package import Packages
from plinth.privileged import service as service_privileged from plinth.privileged import service as service_privileged
from plinth.signals import domain_added, domain_removed from plinth.signals import domain_added, domain_removed
from plinth.utils import format_lazy from plinth.utils import format_lazy
@ -97,7 +97,7 @@ class EmailApp(plinth.app.App):
'dovecot-lmtpd', 'dovecot-managesieved', 'dovecot-ldap', 'dovecot-lmtpd', 'dovecot-managesieved', 'dovecot-ldap',
'rspamd', 'redis-server', 'openssl' 'rspamd', 'redis-server', 'openssl'
], conflicts=['exim4-base', 'exim4-config', 'exim4-daemon-light'], ], conflicts=['exim4-base', 'exim4-config', 'exim4-daemon-light'],
conflicts_action=Packages.ConflictsAction.IGNORE) conflicts_action=Packages.ConflictsAction.REMOVE)
self.add(packages) self.add(packages)
listen_ports = [(25, 'tcp4'), (25, 'tcp6'), (465, 'tcp4'), listen_ports = [(25, 'tcp4'), (25, 'tcp6'), (465, 'tcp4'),
@ -171,17 +171,7 @@ class EmailApp(plinth.app.App):
def setup(self, old_version): def setup(self, old_version):
"""Install and configure the app.""" """Install and configure the app."""
def _clear_conflicts():
component = self.get_component('packages-email')
packages_to_remove = component.find_conflicts()
if packages_to_remove:
logger.info('Removing conflicting packages: %s',
packages_to_remove)
uninstall(packages_to_remove)
# Install # Install
_clear_conflicts()
super().setup(old_version) super().setup(old_version)
# Setup # Setup

View File

@ -170,6 +170,13 @@ class Packages(app.FollowerComponent):
def setup(self, old_version): def setup(self, old_version):
"""Install the packages.""" """Install the packages."""
packages_to_remove = self.find_conflicts()
if packages_to_remove and \
self.conflicts_action not in (None, self.ConflictsAction.IGNORE):
logger.info('Removing conflicting packages: %s',
packages_to_remove)
uninstall(packages_to_remove)
install(self.get_actual_packages(), install(self.get_actual_packages(),
skip_recommends=self.skip_recommends) skip_recommends=self.skip_recommends)

View File

@ -114,6 +114,36 @@ def test_packages_setup(install):
install.assert_has_calls([call(['python3'], skip_recommends=False)]) install.assert_has_calls([call(['python3'], skip_recommends=False)])
@patch('plinth.package.packages_installed')
@patch('plinth.package.uninstall')
@patch('plinth.package.install')
def test_packages_setup_with_conflicts(install, uninstall, packages_installed):
"""Test setting up packages with conflicts."""
packages_installed.return_value = ['exim4-base']
component = Packages('test-component', ['bash'], conflicts=['exim4-base'],
conflicts_action=Packages.ConflictsAction.REMOVE)
component.setup(old_version=0)
uninstall.assert_has_calls([call(['exim4-base'])])
install.assert_has_calls([call(['bash'], skip_recommends=False)])
uninstall.reset_mock()
install.reset_mock()
component = Packages('test-component', ['bash'], conflicts=['exim4-base'])
component.setup(old_version=0)
uninstall.assert_not_called()
install.assert_has_calls([call(['bash'], skip_recommends=False)])
uninstall.reset_mock()
install.reset_mock()
component = Packages('test-component', ['bash'],
conflicts=['exim4-base', 'not-installed-package'],
conflicts_action=Packages.ConflictsAction.IGNORE)
component.setup(old_version=0)
uninstall.assert_not_called()
install.assert_has_calls([call(['bash'], skip_recommends=False)])
@patch('plinth.package.uninstall') @patch('plinth.package.uninstall')
def test_packages_uninstall(uninstall): def test_packages_uninstall(uninstall):
"""Test uninstalling packages component.""" """Test uninstalling packages component."""