)
from cephadmlib.locking import FileLock
from cephadmlib.daemon_identity import DaemonIdentity, DaemonSubIdentity
-from cephadmlib.packagers import create_packager, Packager
+from cephadmlib.packagers import create_packager
from cephadmlib.logging import (
cephadm_init_logging,
Highlight,
LogDestination,
)
-from cephadmlib.systemd import check_unit, check_units, terminate_service
+from cephadmlib.systemd import check_unit, check_units, terminate_service, enable_service
from cephadmlib import systemd_unit
from cephadmlib import runscripts
from cephadmlib.container_types import (
if getattr(ctx, 'custom_prometheus_alerts', None):
cli(['orch', 'prometheus', 'set-custom-alerts', '-i', '/etc/ceph/custom_alerts.yml'])
+ # Enable logrotate.timer
+ _, _, installed = check_unit(ctx, 'logrotate')
+ if not installed:
+ logger.warning('Log rotation will not occur because the logrotate service is not installed. Please install it to enable log rotation.')
+ else:
+ logger.info('enable logrotate.timer service')
+ enable_service(ctx, 'logrotate.timer')
return ctx.error_code
##################################
def check_time_sync(
- ctx: CephadmContext, enabler: Optional[Packager] = None
+ ctx: CephadmContext
) -> bool:
units = [
'chrony.service', # 18.04 (at least)
'openntpd.service', # ubuntu / debian
'timemaster.service', # linuxptp on ubuntu/debian
]
- if not check_units(ctx, units, enabler):
+ if not check_units(ctx, units):
logger.warning('No time sync service is running; checked for %s' % units)
return False
return True
pkg.install(['chrony'])
# check again, and this time try to enable
# the service
- check_time_sync(ctx, enabler=pkg)
+ check_time_sync(ctx)
if 'expect_hostname' in ctx and ctx.expect_hostname and ctx.expect_hostname != get_hostname():
logger.warning('Adjusting hostname from %s -> %s...' % (get_hostname(), ctx.expect_hostname))
else:
return 'https://download.ceph.com/keys/autobuild.gpg', 'autobuild'
- def enable_service(self, service: str) -> None:
- """
- Start and enable the service (typically using systemd).
- """
- call_throws(self.ctx, ['systemctl', 'enable', '--now', service])
-
class Apt(Packager):
DISTRO_NAMES = {
import logging
-from typing import Tuple, List, Optional
+from typing import Tuple, List
from .context import CephadmContext
from .call_wrappers import call, CallVerbosity
-from .packagers import Packager
logger = logging.getLogger()
return (enabled, state, installed)
-def check_units(
- ctx: CephadmContext, units: List[str], enabler: Optional[Packager] = None
-) -> bool:
+def check_units(ctx: CephadmContext, units: List[str]) -> bool:
for u in units:
(enabled, state, installed) = check_unit(ctx, u)
if enabled and state == 'running':
logger.info('Unit %s is enabled and running' % u)
return True
- if enabler is not None:
- if installed:
- logger.info('Enabling unit %s' % u)
- enabler.enable_service(u)
+ if installed:
+ logger.info('Enabling unit %s' % u)
+ enable_service(ctx, u)
return False
['systemctl', 'disable', service_name],
verbosity=CallVerbosity.DEBUG,
)
+
+
+def enable_service(ctx: CephadmContext, service_name: str) -> None:
+ """
+ Start and enable the service (typically using systemd).
+ """
+ call(
+ ctx,
+ ['systemctl', 'enable', '--now', service_name],
+ verbosity=CallVerbosity.DEBUG,
+ )
if isinstance(active, Exception):
raise active
return active
+ if "enable" in cmd:
+ return enabled
raise ValueError("should not get here")
return _fake_call
assert (enabled, state, installed) == expected
-class FakeEnabler:
- def __init__(self, should_be_called):
- self._should_be_called = should_be_called
- self._services = []
-
- def enable_service(self, service):
- self._services.append(service)
-
- def check_expected(self):
- if not self._should_be_called:
- assert not self._services
- return
- # there are currently seven chron/chrony type services that
- # cephadm looks for. Make sure it probed for each of them
- # or more in case someone adds to the list.
- assert len(self._services) >= 7
- assert "chrony.service" in self._services
- assert "ntp.service" in self._services
-
-
@pytest.mark.parametrize(
- "call_fn, enabler, expected",
+ "call_fn, expected",
[
# Test that time sync services are not enabled
(
enabled=("", "", 1),
active=("", "", 1),
),
- None,
False,
),
# Test that time sync service is enabled
enabled=("", "", 0),
active=("active", "", 0),
),
- None,
True,
),
# Test that time sync is not enabled, and try to enable them.
enabled=("disabled", "", 1),
active=("", "", 1),
),
- FakeEnabler(True),
False,
),
# Test that time sync is enabled, with an enabler passed which
enabled=("", "", 0),
active=("active", "", 0),
),
- FakeEnabler(False),
True,
),
],
)
-def test_check_time_sync(call_fn, enabler, expected):
+def test_check_time_sync(call_fn, expected):
"""The check_time_sync call actually checks if a time synchronization service
is enabled. It is also the only consumer of check_units.
"""
with with_cephadm_ctx([]) as ctx:
with mock.patch('cephadmlib.systemd.call') as _call:
_call.side_effect = call_fn
- result = _cephadm.check_time_sync(ctx, enabler=enabler)
+ result = _cephadm.check_time_sync(ctx)
assert result == expected
- if enabler is not None:
- enabler.check_expected()
@pytest.mark.parametrize(