Skip to content

Commit 56cd69e

Browse files
committed
Build docker run args the same in distDocker
Make distDocker's runJob similar to localDocker's. Build a list of args instead of assembling nested strings. Make sure to preserve quoting of interior arguments. This has the effect of making the vm core and memory limits effective for distDocker
1 parent ce87fcf commit 56cd69e

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

vmms/distDocker.py

+15-19
Original file line numberDiff line numberDiff line change
@@ -280,24 +280,20 @@ def runJob(self, vm, runTimeout, maxOutputFileSize, disableNetwork):
280280
config.Config.MAX_OUTPUT_FILE_SIZE,
281281
)
282282
)
283-
284-
# IMPORTANT: The single and double quotes are important, since we
285-
# are switching to the autolab user and then running
286-
# bash commands.
287-
setupCmd = (
288-
'cp -r mount/* autolab/; su autolab -c "%s"; \
289-
cp output/feedback mount/feedback'
290-
% autodriverCmd
291-
)
292-
293-
disableNetworkArg = "--network none" if disableNetwork else ""
294-
295-
args = "(docker run --name %s -v %s:/home/mount %s %s sh -c '%s')" % (
296-
instanceName,
297-
volumePath,
298-
disableNetworkArg,
299-
vm.image,
300-
setupCmd,
283+
args = ["docker", "run", "--name", instanceName, "-v"]
284+
args.append("%s:%s" % (volumePath, "/home/mount"))
285+
if vm.cores:
286+
args.append(f"--cpus={vm.cores}")
287+
if vm.memory:
288+
args.extend(("-m", f"{vm.memory}m"))
289+
if disableNetwork:
290+
args.append("--network", "none")
291+
292+
args.append(vm.image)
293+
args.extend(("sh", "-c"))
294+
args.append(
295+
f'"cp -r mount/* autolab/; su autolab -c \'{autodriverCmd}\'; \
296+
cp output/feedback mount/feedback"'
301297
)
302298

303299
self.log.debug("Running job: %s" % args)
@@ -306,7 +302,7 @@ def runJob(self, vm, runTimeout, maxOutputFileSize, disableNetwork):
306302
["ssh"]
307303
+ DistDocker._SSH_FLAGS
308304
+ vm.ssh_flags
309-
+ ["%s@%s" % (self.hostUser, vm.domain_name), args],
305+
+ ["%s@%s" % (self.hostUser, vm.domain_name)] + args,
310306
runTimeout * 2,
311307
)
312308

0 commit comments

Comments
 (0)