From 56cd69ea9cd13e6a73e927a2b4f09bf770b9a452 Mon Sep 17 00:00:00 2001 From: Chaskiel Grundman Date: Thu, 12 Dec 2024 16:43:44 -0500 Subject: [PATCH] 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 --- vmms/distDocker.py | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/vmms/distDocker.py b/vmms/distDocker.py index b6d498e5..c7c7e6af 100644 --- a/vmms/distDocker.py +++ b/vmms/distDocker.py @@ -280,24 +280,20 @@ def runJob(self, vm, runTimeout, maxOutputFileSize, disableNetwork): config.Config.MAX_OUTPUT_FILE_SIZE, ) ) - - # IMPORTANT: The single and double quotes are important, since we - # are switching to the autolab user and then running - # bash commands. - setupCmd = ( - 'cp -r mount/* autolab/; su autolab -c "%s"; \ - cp output/feedback mount/feedback' - % autodriverCmd - ) - - disableNetworkArg = "--network none" if disableNetwork else "" - - args = "(docker run --name %s -v %s:/home/mount %s %s sh -c '%s')" % ( - instanceName, - volumePath, - disableNetworkArg, - vm.image, - setupCmd, + args = ["docker", "run", "--name", instanceName, "-v"] + args.append("%s:%s" % (volumePath, "/home/mount")) + if vm.cores: + args.append(f"--cpus={vm.cores}") + if vm.memory: + args.extend(("-m", f"{vm.memory}m")) + if disableNetwork: + args.append("--network", "none") + + args.append(vm.image) + args.extend(("sh", "-c")) + args.append( + f'"cp -r mount/* autolab/; su autolab -c \'{autodriverCmd}\'; \ + cp output/feedback mount/feedback"' ) self.log.debug("Running job: %s" % args) @@ -306,7 +302,7 @@ def runJob(self, vm, runTimeout, maxOutputFileSize, disableNetwork): ["ssh"] + DistDocker._SSH_FLAGS + vm.ssh_flags - + ["%s@%s" % (self.hostUser, vm.domain_name), args], + + ["%s@%s" % (self.hostUser, vm.domain_name)] + args, runTimeout * 2, )