Skip to content

Commit

Permalink
Merge pull request #17 from galaxyproject/add_sample
Browse files Browse the repository at this point in the history
Add sample vortex config and map to first available destination
  • Loading branch information
nuwang authored May 14, 2022
2 parents bf8ec46 + 186a520 commit 272317f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# GalaxyCloudRunner documentation build configuration file, created by
# total-perspective-vortex documentation build configuration file, created by
# sphinx-quickstart on Sat Nov 10 18:16:35 2018.
#
# This file is execfile()d with the current directory set to its
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/mapping-sample.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
global:
default_inherits: default

tools:
default:
cores: 2
mem: cores * 2
params:
local_slots: "{cores}"

destinations:
local:
8 changes: 8 additions & 0 deletions tests/test_mapper_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,11 @@ def test_map_inherit_no_default(self):
self.assertEqual(destination.id, "local")
self.assertFalse([env['value'] for env in destination.env if env['name'] == 'TEST_JOB_SLOTS'])
self.assertEqual(destination.params['another_spec'], '--gpus 4')

def test_map_inherit_no_default_no_tool_def(self):
tool = mock_galaxy.Tool('some_random_tool')
user = mock_galaxy.User('gargravarr', '[email protected]')
vortex_config_path = os.path.join(os.path.dirname(__file__), 'fixtures/mapping-inheritance-no-default.yml')

destination = self._map_to_destination(tool, user, datasets=[], vortex_config_path=vortex_config_path)
self.assertEqual(destination.id, "local")
22 changes: 22 additions & 0 deletions tests/test_mapper_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os
import unittest
from vortex.rules import gateway
from . import mock_galaxy


class TestMapperSample(unittest.TestCase):

@staticmethod
def _map_to_destination(tool):
galaxy_app = mock_galaxy.App()
job = mock_galaxy.Job()
user = mock_galaxy.User('gargravarr', '[email protected]')
vortex_config = os.path.join(os.path.dirname(__file__), 'fixtures/mapping-sample.yml')
gateway.ACTIVE_DESTINATION_MAPPER = None
return gateway.map_tool_to_destination(galaxy_app, job, tool, user, vortex_config_files=[vortex_config])

def test_map_sample_tool(self):
tool = mock_galaxy.Tool('sometool')
destination = self._map_to_destination(tool)
self.assertEqual(destination.id, "local")
self.assertEqual(destination.params['local_slots'], '2')
2 changes: 2 additions & 0 deletions vortex/core/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def validate_entities(self, entity_class: type, entity_list: dict) -> dict:
validated = {}
for entity_id, entity_dict in entity_list.items():
try:
if not entity_dict:
entity_dict = {}
entity_dict['id'] = entity_id
entity_class.from_dict(self, entity_dict)
validated[entity_id] = entity_class.from_dict(self, entity_dict)
Expand Down
6 changes: 5 additions & 1 deletion vortex/core/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import re

from .entities import Tool
from .loader import VortexConfigLoader

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -60,6 +61,8 @@ def find_best_match(self, entity, destinations, context):

def _find_matching_entities(self, tool, user):
tool_entity = self._find_entity_by_id_regex(self.tools, tool.id)
if not tool_entity:
tool_entity = Tool.from_dict(self.loader, {'id': tool.id})

entity_list = [tool_entity]

Expand Down Expand Up @@ -116,7 +119,8 @@ def map_to_destination(self, app, tool, user, job):
# 7. Return destination with params
if destination:
destination = app.job_config.get_destination(destination.id)
destination.env += [dict(name=k, value=v) for (k, v) in evaluated.env.items()]
if evaluated.env:
destination.env += [dict(name=k, value=v) for (k, v) in evaluated.env.items()]
destination.params.update(evaluated.params or {})
return destination
else:
Expand Down

0 comments on commit 272317f

Please sign in to comment.