8491: Merge branch 'master' into 8491-import-build-tools
authorTom Clegg <tom@curoverse.com>
Fri, 11 Mar 2016 19:16:48 +0000 (14:16 -0500)
committerTom Clegg <tom@curoverse.com>
Fri, 11 Mar 2016 19:16:48 +0000 (14:16 -0500)
sdk/cwl/arvados_cwl/__init__.py
sdk/cwl/setup.py
sdk/cwl/tests/__init__.py [new file with mode: 0644]
sdk/cwl/tests/test_job.py [new file with mode: 0644]

index 7b1c291ef528cf7e0598156399f163d440e5dca4..2e1f75bf351218680280cc5f92aea00b243a7df0 100644 (file)
@@ -152,6 +152,12 @@ class ArvadosJob(object):
         if docker_req and kwargs.get("use_container") is not False:
             runtime_constraints["docker_image"] = arv_docker_get_image(self.arvrunner.api, docker_req, pull_image)
 
+        resources = self.builder.resources
+        if resources is not None:
+            runtime_constraints["min_cores_per_node"] = resources.get("cores", 1)
+            runtime_constraints["min_ram_mb_per_node"] = resources.get("ram")
+            runtime_constraints["min_scratch_mb_per_node"] = resources.get("tmpdirSize", 0) + resources.get("outdirSize", 0)
+
         try:
             response = self.arvrunner.api.jobs().create(body={
                 "script": "crunchrunner",
index cacfc21680eb6bc19ac5fea54aeed084d91442cd..1deb7663d3a2b2f4d415046d1bf72ad1c23eb40e 100644 (file)
@@ -33,6 +33,8 @@ setup(name='arvados-cwl-runner',
           'cwltool>=1.0.20160308152645',
           'arvados-python-client>=0.1.20160219154918'
       ],
+      test_suite='tests',
+      tests_require=['mock>=1.0'],
       zip_safe=True,
       cmdclass={'egg_info': tagger},
       )
diff --git a/sdk/cwl/tests/__init__.py b/sdk/cwl/tests/__init__.py
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
diff --git a/sdk/cwl/tests/test_job.py b/sdk/cwl/tests/test_job.py
new file mode 100644 (file)
index 0000000..0b38db2
--- /dev/null
@@ -0,0 +1,77 @@
+import unittest
+import mock
+import arvados_cwl
+
+class TestJob(unittest.TestCase):
+
+    # The test passes no builder.resources
+    # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
+    def test_run(self):
+        runner = mock.MagicMock()
+        tool = {
+            "inputs": [],
+            "outputs": [],
+            "baseCommand": "ls"
+        }
+        arvtool = arvados_cwl.ArvadosCommandTool(runner, tool)
+        arvtool.formatgraph = None
+        for j in arvtool.job({}, "", mock.MagicMock()):
+            j.run()
+        runner.api.jobs().create.assert_called_with(body={
+            'runtime_constraints': {},
+            'script_parameters': {
+                'tasks': [{
+                    'task.env': {'TMPDIR': '$(task.tmpdir)'},
+                    'command': ['ls']
+                }],
+                'crunchrunner': '83db29f08544e1c319572a6bd971088a+140/crunchrunner'
+            },
+            'script_version': 'master',
+            'minimum_script_version': '9e5b98e8f5f4727856b53447191f9c06e3da2ba6',
+            'repository': 'arvados',
+            'script': 'crunchrunner',
+            'runtime_constraints': {
+                'min_cores_per_node': 1,
+                'min_ram_mb_per_node': 1024,
+                'min_scratch_mb_per_node': 2048 # tmpdirSize + outdirSize
+            }
+        }, find_or_create=True)
+
+    # The test passes some fields in builder.resources
+    # For the remaining fields, the defaults will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
+    def test_resource_requirements(self):
+        runner = mock.MagicMock()
+        tool = {
+            "inputs": [],
+            "outputs": [],
+            "hints": [{
+                "class": "ResourceRequirement",
+                "coresMin": 3,
+                "ramMin": 3000,
+                "tmpdirMin": 4000
+            }],
+            "baseCommand": "ls"
+        }
+        arvtool = arvados_cwl.ArvadosCommandTool(runner, tool)
+        arvtool.formatgraph = None
+        for j in arvtool.job({}, "", mock.MagicMock()):
+            j.run()
+        runner.api.jobs().create.assert_called_with(body={
+            'runtime_constraints': {},
+            'script_parameters': {
+                'tasks': [{
+                    'task.env': {'TMPDIR': '$(task.tmpdir)'},
+                    'command': ['ls']
+                }],
+                'crunchrunner': '83db29f08544e1c319572a6bd971088a+140/crunchrunner'
+            },
+            'script_version': 'master',
+            'minimum_script_version': '9e5b98e8f5f4727856b53447191f9c06e3da2ba6',
+            'repository': 'arvados',
+            'script': 'crunchrunner',
+            'runtime_constraints': {
+                'min_cores_per_node': 3,
+                'min_ram_mb_per_node': 3000,
+                'min_scratch_mb_per_node': 5024 # tmpdirSize + outdirSize
+            }
+        }, find_or_create=True)