Skip to content

Commit

Permalink
Add network toggle in job configuration (#249)
Browse files Browse the repository at this point in the history
Linting changes
  • Loading branch information
evanyeyeye authored Feb 20, 2024
1 parent 9dda955 commit a6e6eda
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
8 changes: 7 additions & 1 deletion clients/tango-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,15 @@
"--notifyURL",
help="Complete URL for Tango to give callback to once job is complete.",
)
parser.add_argument(
"--disableNetwork",
action="store_true",
default=False,
help="Disable network access for autograding containers.",
)

# add for aws student accounts
parser.add_argument("--accessKeyId", default="", help="AWS account access key ID")

parser.add_argument("--accessKey", default="", help="AWS account access key content")


Expand Down Expand Up @@ -253,6 +258,7 @@ def tango_addJob():

requestObj["accessKeyId"] = args.accessKeyId
requestObj["accessKey"] = args.accessKey
requestObj["disable_network"] = args.disableNetwork

response = requests.post(
"%s://%s:%d/addJob/%s/%s/"
Expand Down
5 changes: 5 additions & 0 deletions restful_tango/tangoREST.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ def convertJobObj(self, dirName, jobObj):
accessKeyId = jobObj["accessKeyId"]
accessKey = jobObj["accessKey"]

disableNetwork = False
if "disable_network" in jobObj and isinstance(jobObj["disable_network"], bool):
disableNetwork = jobObj["disable_network"]

job = TangoJob(
name=name,
vm=vm,
Expand All @@ -175,6 +179,7 @@ def convertJobObj(self, dirName, jobObj):
maxOutputFileSize=maxOutputFileSize,
accessKey=accessKey,
accessKeyId=accessKeyId,
disableNetwork=disableNetwork,
)

self.log.debug("inputFiles: %s" % [file.localFile for file in input])
Expand Down
2 changes: 2 additions & 0 deletions tangoObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def __init__(
maxOutputFileSize=Config.MAX_OUTPUT_FILE_SIZE,
accessKeyId=None,
accessKey=None,
disableNetwork=None,
):
self.assigned = False
self.retries = 0
Expand All @@ -112,6 +113,7 @@ def __init__(
self._remoteLocation = None
self.accessKeyId = accessKeyId
self.accessKey = accessKey
self.disableNetwork = disableNetwork

def makeAssigned(self):
self.syncRemote()
Expand Down
7 changes: 5 additions & 2 deletions vmms/distDocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def copyIn(self, vm, inputFiles):

return 0

def runJob(self, vm, runTimeout, maxOutputFileSize):
def runJob(self, vm, runTimeout, maxOutputFileSize, disableNetwork):
"""runJob - Run a docker container by doing the follows:
- mount directory corresponding to this job to /home/autolab
in the container
Expand Down Expand Up @@ -290,9 +290,12 @@ def runJob(self, vm, runTimeout, maxOutputFileSize):
% autodriverCmd
)

args = "(docker run --name %s -v %s:/home/mount %s sh -c '%s')" % (
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,
)
Expand Down
4 changes: 3 additions & 1 deletion vmms/localDocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def copyIn(self, vm, inputFiles):
)
return 0

def runJob(self, vm, runTimeout, maxOutputFileSize):
def runJob(self, vm, runTimeout, maxOutputFileSize, disableNetwork):
"""runJob - Run a docker container by doing the follows:
- mount directory corresponding to this job to /home/autolab
in the container
Expand All @@ -161,6 +161,8 @@ def runJob(self, vm, runTimeout, maxOutputFileSize):
args = args + [f"--cpus={vm.cores}"]
if vm.memory:
args = args + ["-m", f"{vm.memory}m"]
if disableNetwork:
args = args + ["--network", "none"]
args = args + [vm.image]
args = args + ["sh", "-c"]

Expand Down
5 changes: 4 additions & 1 deletion worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@ def run(self):

# Run the job on the virtual machine
ret["runjob"] = self.vmms.runJob(
vm, self.job.timeout, self.job.maxOutputFileSize
vm,
self.job.timeout,
self.job.maxOutputFileSize,
self.job.disableNetwork,
)
if ret["runjob"] != 0:
Config.runjob_errors += 1
Expand Down

0 comments on commit a6e6eda

Please sign in to comment.