Skip to content
Snippets Groups Projects
Commit 16edb6ad authored by Sebastian Brommer's avatar Sebastian Brommer :hand_splayed_tone4:
Browse files

fix domain parsing

parent 4f6ff648
Branches
No related tags found
No related merge requests found
......@@ -5,10 +5,6 @@ import sys
def get_job_ad():
instream = sys.stdin
# # dump the input stream to a file for debugging
# with open("/scratch/job_ad.txt", "w") as f:
# for line in instream:
# f.write(line)
job_ad = {}
# format of the job ad is key = value
for line in instream:
......@@ -26,7 +22,7 @@ def sanitize_image_name(image):
if image.startswith("docker://"):
image = image.replace("docker://", "")
# try to identify the domain if there is any
if image.count("/") > 2:
if image.count("/") >= 2:
domain = image.split("/")[0]
image = image.replace(domain + "/", "")
else:
......@@ -55,6 +51,8 @@ def check_image_availability(image_path):
def main():
job_ad = get_job_ad()
status_message = ""
condor_arg = ""
job_ad["WantDocker"] = "false"
# write job_ad to a file for debugging
dumpfilepath = "/scratch/job_ad_initial.json"
with open(dumpfilepath, "w") as f:
......@@ -64,41 +62,33 @@ def main():
docker_image = job_ad.get("DockerImage")
if not container_image and not docker_image:
status_message = "No container image provided, using default container: /cvmfs/unpacked.cern.ch/registry.hub.docker.com/mschnepf/slc7-condocker:latest"
# return the default container image to stdout
print(
'ContainerImage = "/cvmfs/unpacked.cern.ch/registry.hub.docker.com/mschnepf/slc7-condocker:latest"',
file=sys.stdout,
job_ad["status_message"] = (
"No container image provided, using default container: /cvmfs/unpacked.cern.ch/registry.hub.docker.com/mschnepf/slc7-condocker:latest"
)
print("WantDocker = false", file=sys.stdout)
# return the default container image to stdout
job_ad["ContainerImage"] = (
"/cvmfs/unpacked.cern.ch/registry.hub.docker.com/mschnepf/slc7-condocker:latest"
)
job_ad["WantDocker"] = "false"
dumpfilepath = "/scratch/job_ad_updated.json"
with open(dumpfilepath, "w") as f:
for key, value in job_ad.items():
f.write(f"{key} = {value}\n")
return
# pick the args parameter that is not None
image = container_image or docker_image
condor_arg = ""
domain, imagename = sanitize_image_name(image)
image_path = construct_image_path(domain, imagename)
if check_image_availability(image_path):
condor_arg = image_path
else:
condor_arg = f"docker://{domain}/{imagename}"
print(f'ContainerImage = "{condor_arg}"', file=sys.stdout)
print("WantDocker = false", file=sys.stdout)
# pick the args parameter that is not None
image = container_image or docker_image
domain, imagename = sanitize_image_name(image)
image_path = construct_image_path(domain, imagename)
if check_image_availability(image_path):
condor_arg = image_path
else:
condor_arg = f"docker://{domain}/{imagename}"
job_ad["ContainerImage"] = condor_arg
job_ad["status_message"] = f"Container image set to {image_path} via hook"
# return the results via stdout
print(f'ContainerImage = "{job_ad["ContainerImage"]}"', file=sys.stdout)
print(f"WantDocker = {job_ad['WantDocker']}", file=sys.stdout)
print(f'HookStatusMessage = "{job_ad["status_message"]}"', file=sys.stdout)
# dump the updated job ad to a file for debugging
job_ad["ContainerImage"] = condor_arg
job_ad["WantDocker"] = "false"
dumpfilepath = "/scratch/job_ad_updated.json"
with open(dumpfilepath, "w") as f:
for key, value in job_ad.items():
f.write(f"{key} = {value}\n")
status_message = f"Container image {image_path} is available, using it"
print(f"HookStatusMessage = {status_message}", file=sys.stdout)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment