Skip to content

Commit ec24edb

Browse files
committed
Implement idempotency for server.modprobe & server.mount operations.
1 parent 9cb25ba commit ec24edb

File tree

10 files changed

+16
-18
lines changed

10 files changed

+16
-18
lines changed

pyinfra/operations/server.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,14 @@ def partition(predicate, iterable):
249249
# Module is loaded and we don't want it?
250250
if not present and present_mods:
251251
yield 'modprobe{0} -r -a {1}'.format(args, ' '.join(present_mods))
252+
for mod in present_mods:
253+
modules.pop(mod)
252254

253255
# Module isn't loaded and we want it?
254256
elif present and missing_mods:
255257
yield 'modprobe{0} -a {1}'.format(args, ' '.join(missing_mods))
258+
for mod in missing_mods:
259+
modules[mod] = {}
256260

257261
else:
258262
host.noop('{0} {1} {2} {3}'.format(
@@ -299,17 +303,20 @@ def mount(
299303
' -o {0}'.format(options_string) if options_string else '',
300304
path,
301305
)
306+
mounts[path] = {'options': options}
302307

303308
# Want no mount but mounted?
304309
elif mounted is False and is_mounted:
305310
yield 'umount {0}'.format(path)
311+
mounts.pop(path)
306312

307313
# Want mount and is mounted! Check the options
308314
elif is_mounted and mounted and options:
309315
mounted_options = mounts[path]['options']
310316
needed_options = set(options) - set(mounted_options)
311317
if needed_options:
312318
yield 'mount -o remount,{0} {1}'.format(options_string, path)
319+
mounts[path]['options'] = options
313320

314321
else:
315322
host.noop('filesystem {0} is {1}'.format(

tests/operations/server.modprobe/add-list.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@
77
},
88
"commands": [
99
"modprobe -a mod1 mod3"
10-
],
11-
"idempotent": false
10+
]
1211
}

tests/operations/server.modprobe/add.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@
55
},
66
"commands": [
77
"modprobe -a somemodule"
8-
],
9-
"idempotent": false
8+
]
109
}

tests/operations/server.modprobe/add_force.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@
88
},
99
"commands": [
1010
"modprobe -f -a somemodule"
11-
],
12-
"idempotent": false
11+
]
1312
}

tests/operations/server.modprobe/remove-list.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@
1010
},
1111
"commands": [
1212
"modprobe -r -a mod1"
13-
],
14-
"idempotent": false
13+
]
1514
}

tests/operations/server.modprobe/remove.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@
1010
},
1111
"commands": [
1212
"modprobe -r -a somemodule"
13-
],
14-
"idempotent": false
13+
]
1514
}

tests/operations/server.mount/mount.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@
55
},
66
"commands": [
77
"mount /data"
8-
],
9-
"idempotent": false
8+
]
109
}

tests/operations/server.mount/mount_options.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@
88
},
99
"commands": [
1010
"mount -o rw /data"
11-
],
12-
"idempotent": false
11+
]
1312
}

tests/operations/server.mount/remount_options.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@
1212
},
1313
"commands": [
1414
"mount -o remount,rw,noatime /data"
15-
],
16-
"idempotent": false
15+
]
1716
}

tests/operations/server.mount/unmount.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@
1010
},
1111
"commands": [
1212
"umount /data"
13-
],
14-
"idempotent": false
13+
]
1514
}

0 commit comments

Comments
 (0)