1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# Tests for various assorted utility functions found within cephadm
#
from unittest import mock
import functools
import io
import os
import sys
import pytest
from tests.fixtures import (
import_cephadm,
mock_docker,
mock_podman,
with_cephadm_ctx,
)
from cephadmlib import context
from cephadmlib import systemd_unit
from cephadmlib.constants import CGROUPS_SPLIT_PODMAN_VERSION
_cephadm = import_cephadm()
def _get_unit_file(ctx, fsid):
return str(systemd_unit._get_unit_file(ctx, fsid))
def test_docker_engine_wants_docker():
ctx = context.CephadmContext()
ctx.container_engine = mock_docker()
r = _get_unit_file(ctx, '9b9d7609-f4d5-4aba-94c8-effa764d96c9')
assert 'Wants=docker.service' in r
def test_podman_engine_does_not_req_docker():
ctx = context.CephadmContext()
ctx.container_engine = mock_podman()
r = _get_unit_file(ctx, '9b9d7609-f4d5-4aba-94c8-effa764d96c9')
assert 'Requires=docker.service' not in r
def test_podman_engine_forking_service():
# verity that the podman service uses the forking service type
# and related parameters
ctx = context.CephadmContext()
ctx.container_engine = mock_podman()
r = _get_unit_file(ctx, '9b9d7609-f4d5-4aba-94c8-effa764d96c9')
assert 'Type=forking' in r
assert 'PIDFile=' in r
assert 'ExecStartPre' in r
assert 'ExecStopPost' in r
def test_podman_with_split_cgroups_sets_delegate():
ctx = context.CephadmContext()
ctx.container_engine = mock_podman()
ctx.container_engine.version = CGROUPS_SPLIT_PODMAN_VERSION
r = _get_unit_file(ctx, '9b9d7609-f4d5-4aba-94c8-effa764d96c9')
assert 'Type=forking' in r
assert 'Delegate=yes' in r
def _ignore_blank_lines(value):
return [v for v in value.splitlines() if v]
def test_new_docker():
ctx = context.CephadmContext()
ctx.container_engine = mock_docker()
ru = _get_unit_file(ctx, '9b9d7609-f4d5-4aba-94c8-effa764d96c9')
assert _ignore_blank_lines(ru) == [
'# generated by cephadm',
'[Unit]',
'Description=Ceph %i for 9b9d7609-f4d5-4aba-94c8-effa764d96c9',
'# According to:',
'# http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget',
'# these can be removed once ceph-mon will dynamically change network',
'# configuration.',
'After=network-online.target local-fs.target time-sync.target docker.service',
'Wants=network-online.target local-fs.target time-sync.target',
'Wants=docker.service',
'PartOf=ceph-9b9d7609-f4d5-4aba-94c8-effa764d96c9.target',
'Before=ceph-9b9d7609-f4d5-4aba-94c8-effa764d96c9.target',
'[Service]',
'LimitNOFILE=1048576',
'LimitNPROC=1048576',
'EnvironmentFile=-/etc/environment',
'ExecStart=/bin/bash '
'/var/lib/ceph/9b9d7609-f4d5-4aba-94c8-effa764d96c9/%i/unit.run',
"ExecStop=-/bin/bash -c 'bash "
"/var/lib/ceph/9b9d7609-f4d5-4aba-94c8-effa764d96c9/%i/unit.stop'",
'ExecStopPost=-/bin/bash '
'/var/lib/ceph/9b9d7609-f4d5-4aba-94c8-effa764d96c9/%i/unit.poststop',
'KillMode=none',
'Restart=on-failure',
'RestartSec=10s',
'TimeoutStartSec=200',
'TimeoutStopSec=120',
'StartLimitInterval=30min',
'StartLimitBurst=5',
'[Install]',
'WantedBy=ceph-9b9d7609-f4d5-4aba-94c8-effa764d96c9.target',
]
def test_new_podman():
ctx = context.CephadmContext()
ctx.container_engine = mock_podman()
ctx.container_engine.version = CGROUPS_SPLIT_PODMAN_VERSION
ru = _get_unit_file(ctx, '9b9d7609-f4d5-4aba-94c8-effa764d96c9')
assert _ignore_blank_lines(ru) == [
'# generated by cephadm',
'[Unit]',
'Description=Ceph %i for 9b9d7609-f4d5-4aba-94c8-effa764d96c9',
'# According to:',
'# http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget',
'# these can be removed once ceph-mon will dynamically change network',
'# configuration.',
'After=network-online.target local-fs.target time-sync.target',
'Wants=network-online.target local-fs.target time-sync.target',
'PartOf=ceph-9b9d7609-f4d5-4aba-94c8-effa764d96c9.target',
'Before=ceph-9b9d7609-f4d5-4aba-94c8-effa764d96c9.target',
'[Service]',
'LimitNOFILE=1048576',
'LimitNPROC=1048576',
'EnvironmentFile=-/etc/environment',
'ExecStart=/bin/bash '
'/var/lib/ceph/9b9d7609-f4d5-4aba-94c8-effa764d96c9/%i/unit.run',
"ExecStop=-/bin/bash -c 'bash "
"/var/lib/ceph/9b9d7609-f4d5-4aba-94c8-effa764d96c9/%i/unit.stop'",
'ExecStopPost=-/bin/bash '
'/var/lib/ceph/9b9d7609-f4d5-4aba-94c8-effa764d96c9/%i/unit.poststop',
'KillMode=none',
'Restart=on-failure',
'RestartSec=10s',
'TimeoutStartSec=200',
'TimeoutStopSec=120',
'StartLimitInterval=30min',
'StartLimitBurst=5',
'ExecStartPre=-/bin/rm -f %t/%n-pid %t/%n-cid',
'ExecStopPost=-/bin/rm -f %t/%n-pid %t/%n-cid',
'Type=forking',
'PIDFile=%t/%n-pid',
'Delegate=yes',
'[Install]',
'WantedBy=ceph-9b9d7609-f4d5-4aba-94c8-effa764d96c9.target',
]
|