Skip to content

Commit b3d4fd5

Browse files
prilrclaude
authored andcommitted
systemd: keep the unit type when expanding preset template instances
_parse_preset_entry() hardcoded '.service' when expanding a preset entry that names template instances, so "enable backup@.timer daily" yielded backup@daily.service. Harmless while only service presets were consumed; now that presets are read per unit type, such an entry is attributed to the wrong type and dropped by the type filter. Derive the suffix from the matched template unit file instead. No EL8->EL9 preset currently declares template instances for a non-service unit, so this is a latent fix rather than a behavior change on any supported upgrade path. Found in review of PR #69. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 451d923 commit b3d4fd5

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

repos/system_upgrade/common/libraries/systemd.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,13 @@ def _parse_preset_entry(entry, presets, load_path):
200200
# if the entry contains instance names after template unit name
201201
# the entry only applies to the specified instances, not to the
202202
# template itself
203+
# The instance keeps the unit type of the template it comes from,
204+
# which is not necessarily '.service' (e.g. 'backup@.timer').
205+
unit_type = os.path.splitext(unit_file)[1]
203206
for instance in columns[2:]:
204-
service_name = unit_file[:unit_file.index('@') + 1] + instance + '.service'
205-
if service_name not in presets: # first occurrence has priority
206-
presets[service_name] = columns[0]
207+
unit_name = unit_file[:unit_file.index('@') + 1] + instance + unit_type
208+
if unit_name not in presets: # first occurrence has priority
209+
presets[unit_name] = columns[0]
207210

208211
elif unit_file not in presets: # first occurrence has priority
209212
presets[unit_file] = columns[0]

repos/system_upgrade/common/libraries/tests/test_systemd.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,18 @@ def readlink_mocked(path):
132132
'template@instance1.service': 'disable',
133133
'template@instance2.service': 'disable'
134134
}),
135+
# Instances must keep the template's own unit type, not become '.service'
136+
('enable template@.timer daily weekly', {
137+
'template@daily.timer': 'enable',
138+
'template@weekly.timer': 'enable'
139+
}),
135140
('enable globbed*.service', {'globbed-one.service': 'enable', 'globbed-two.service': 'enable'}),
136141
('enable example.*', {'example.service': 'enable', 'example.socket': 'enable'}),
137142
('disable *', {
138143
'example.service': 'disable',
139144
'abc.service': 'disable',
140145
'template@.service': 'disable',
146+
'template@.timer': 'disable',
141147
'template2@.service': 'disable',
142148
'globbed-one.service': 'disable',
143149
'globbed-two.service': 'disable',
@@ -175,6 +181,7 @@ def test_parse_preset_files(monkeypatch):
175181
'example.socket': 'disable',
176182
'abc.service': 'disable',
177183
'template@.service': 'disable',
184+
'template@.timer': 'disable',
178185
'template@instance1.service': 'enable',
179186
'template@instance2.service': 'enable',
180187
'globbed-one.service': 'enable',
@@ -267,7 +274,7 @@ def get_system_preset_files_mocked():
267274
'suffix,expected',
268275
[
269276
('.socket', {'example.socket': 'disable'}),
270-
('.timer', {}),
277+
('.timer', {'template@.timer': 'disable'}),
271278
(
272279
'.service',
273280
{

repos/system_upgrade/common/libraries/tests/test_systemd_files/template@.timer

Whitespace-only changes.

0 commit comments

Comments
 (0)