Skip to content

Commit

Permalink
checking for valid destinations in tool destination config
Browse files Browse the repository at this point in the history
dynamic_tool_destination.py now checks that any job destination referenced
exists in job_conf.xml by matching the name of the destination in
tool_destinations.yml to a destination id in job_conf.xml
  • Loading branch information
Matthew Spelchak committed Feb 1, 2018
1 parent 71460a6 commit 4722c48
Showing 1 changed file with 56 additions and 3 deletions.
59 changes: 56 additions & 3 deletions lib/galaxy/jobs/dynamic_tool_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import collections
import re
from functools import reduce
from xml.etree import ElementTree as ET

# log to galaxy's logger
log = logging.getLogger(__name__)
Expand Down Expand Up @@ -355,8 +356,8 @@ def __validate_destination(cls, valid_rule, return_bool, rule, tool, counter):
@param valid_rule: returns True if everything is valid. False if it encounters any
abnormalities in the config.
@type original_rule: dict
@param original_rule: contains the original received rule
@type rule: dict
@param rule: contains the original received rule
@type counter: int
@param counter: this counter is used to identify what rule # is currently being
Expand Down Expand Up @@ -399,6 +400,8 @@ def __validate_destination(cls, valid_rule, return_bool, rule, tool, counter):
if ("priority" in rule["destination"] and isinstance(rule["destination"]["priority"], dict)):

#### new code
valid_destinations = get_valid_destinations_from_config()

for priority in rule["destination"]["priority"]:
if priority not in priority_list:
error = "Invalid priority classification: "
Expand All @@ -419,6 +422,17 @@ def __validate_destination(cls, valid_rule, return_bool, rule, tool, counter):
log.debug(error)
valid_rule = False

elif rule["destination"]["priority"][priority] not in valid_destinations:
error = "destination for '" + str(tool) + "', rule "
error += str(counter) + ": '"
error += str(rule["destination"]["priority"][priority])
error += "' does not exist in job configuration."
if not return_bool:
error += " Ignoring..."
if verbose:
log.debug(error)
valid_rule = False

#### new code ends here
else:
error = "No destination specified for rule " + str(counter)
Expand Down Expand Up @@ -1391,7 +1405,46 @@ def map_tool_to_destination(
log.debug(output)

return destination


### new method
def get_valid_destinations_from_config(config_location='/config/job_conf.xml'):
"""
returns A list of all destination IDs declared in the job configuration
@type config_location: str
@param config_location: The location of the job config file relative
to the galaxy root directory. Defaults to
galaxy/config/job_conf.xml
@rtype: list
@return: A list of all of the destination IDs declared in the job
configuration file.
"""
valid_destinations = []

# os.path.realpath gets the path of DynamicToolDestination.py
# and then os.path.join is used to go back four directories
config_directory = os.path.join(
os.path.dirname(os.path.realpath(__file__)), '../../..')

job_conf_file = config_directory + config_location
job_conf = ET.parse(job_conf_file)

for destination in job_conf.getroot().iter("destination"):
if isinstance(destination.get("id"), str):
valid_destinations.append(destination.get("id"))

else:
###Not sure what to do here, because we're technically
###only validating the tool destination config, not
###the job configuration
error = "ID for destination " + str(destination)
error += " cannot be parsed."
error += " Ignoring..."
log.debug(error)

return valid_destinations


if __name__ == '__main__':
"""
Expand Down

0 comments on commit 4722c48

Please sign in to comment.