Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test to ensure default inheritance can be overridden #132

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions tests/fixtures/mapping-inheritance-override-default-inherits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
global:
default_inherits: _default

tools:
_default:
abstract: true
cores: 1
mem: cores * 2.7
context:
roundup_large_partition: multi
time: "36:00:00"
hisat:
cores: 4
scheduling:
require:
- hisat

destinations:
_roundup_common:
abstract: true
runner: slurm
params:
tmp_dir: true
roundup:
inherits: _roundup_common
min_accepted_cores: 2
min_accepted_mem: 8
max_accepted_cores: 16
max_accepted_mem: 64
params:
native_spec: "--nodes=1 --ntasks={cores} --mem={round(mem*1024)} --time={time} --partition={roundup_large_partition}"
scheduling:
prefer:
- hisat
13 changes: 13 additions & 0 deletions tests/test_mapper_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,16 @@ def test_general_destination_inheritance(self):
self.assertTrue('ABC' in [e.get('name') for e in destination.env])
self.assertEqual('extra-args', destination.params.get('docker_extra'))
self.assertEqual('k8s', destination.runner)

def test_override_default_inherits(self):
user = mock_galaxy.User('majikthise', 'majikthise@vortex.org')
tool = mock_galaxy.Tool('hisat')
tpv_config_files = [
os.path.join(os.path.dirname(__file__), 'fixtures/mapping-inheritance.yml'),
os.path.join(os.path.dirname(__file__), 'fixtures/mapping-inheritance-override-default-inherits.yml'),
]
destination = self._map_to_destination(tool, user, datasets=[], tpv_config_files=tpv_config_files)
self.assertEqual('roundup', destination.id)
self.assertEqual('--nodes=1 --ntasks=4 --mem=16384 --time=36:00:00 --partition=multi', destination.params.get('native_spec'))
# Job slots should not be in env since default inheritance was overridden
self.assertTrue('TEST_JOB_SLOTS' not in [e['name'] for e in destination.env])
3 changes: 2 additions & 1 deletion tpv/core/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ def rank(self, entity, destinations, context):
def match_and_rank_destinations(self, entity, destinations, context):
# At this point, the resource requirements (cores, mem, gpus) are unevaluated.
# So temporarily evaluate them so we can match up with a destination.
evaluated_entity = entity.evaluate_resources(context)
matches = [dest for dest in self.__apply_default_destination_inheritance(destinations)
if dest.matches(entity.evaluate_resources(context), context)]
if dest.matches(evaluated_entity, context)]
return self.rank(entity, matches, context)

def to_galaxy_destination(self, destination):
Expand Down
2 changes: 1 addition & 1 deletion tpv/rules/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def setup_destination_mapper(app, tpv_config_files):
mapper = load_destination_mapper(tpv_config_files)

def reload_destination_mapper(path=None):
# reload all config files when one file changes to preserve order of loading the files
# reload all config files when one file changes to preserve the order of loading files
global ACTIVE_DESTINATION_MAPPER
ACTIVE_DESTINATION_MAPPER = load_destination_mapper(tpv_config_files, reload=True)

Expand Down
Loading