コード例 #1
0
ファイル: test_jobrunner.py プロジェクト: kbase/JobRunner
    def test_token_lifetime(self, mock_req, mock_auth, mock_njs):
        # Test get token lifetime

        config = NJS_JOB_PARAMS[1]
        resp = AUTH_V2_TOKEN
        mock_req.get.return_value = MockAuth(resp)
        jr = JobRunner(self.config, self.njs_url, self.jobid, self.token,
                       self.admin_token)
        mlog = MockLogger()
        jr.logger = mlog
        exp = jr._get_token_lifetime(config)
        self.assertGreater(exp, 0)

        mock_req.get.side_effect = OSError("bad request")
        with self.assertRaises(OSError):
            jr._get_token_lifetime(config)
コード例 #2
0
ファイル: test_jobrunner.py プロジェクト: kbase/JobRunner
 def test_run_volume(self, mock_njs, mock_auth):
     self._cleanup(self.jobid)
     params = deepcopy(NJS_JOB_PARAMS)
     params[0]['method'] = 'mock_app.voltest'
     params[0]['params'] = {'param1': 'value1'}
     jr = JobRunner(self.config, self.njs_url, self.jobid, self.token,
                    self.admin_token)
     rv = deepcopy(CATALOG_GET_MODULE_VERSION)
     rv['docker_img_name'] = 'mock_app:latest'
     vols = deepcopy(CATALOG_LIST_VOLUME_MOUNTS)
     jr.cc.catalog.get_module_version = MagicMock(return_value=rv)
     jr.cc.catalog.list_volume_mounts = MagicMock(return_value=vols)
     jr.cc.catalog.get_secure_config_params = MagicMock(return_value=None)
     jr.logger.njs.add_job_logs = MagicMock(return_value=rv)
     jr.njs.get_job_params.return_value = params
     jr.njs.check_job_canceled.return_value = {'finished': False}
     jr.auth.get_user.return_value = "bogus"
     jr._get_token_lifetime = MagicMock(return_value=self.future)
     if not os.path.exists('/tmp/bogus'):
         os.mkdir('/tmp/bogus')
     with open('/tmp/bogus/input.fa', 'w') as f:
         f.write('>contig-50_0 length_64486 read_count_327041\n')
         f.write('GTCGTGCTGCTGCCGATCGACCGCGCCTATGCGATGTTGCCGGACGGCATCC\n')
     out = jr.run()
     self.assertIn('result', out)
     self.assertNotIn('error', out)
コード例 #3
0
ファイル: test_jobrunner.py プロジェクト: kbase/JobRunner
 def test_run_online(self, mock_njs):
     self._cleanup(self.jobid)
     params = deepcopy(NJS_JOB_PARAMS)
     jr = JobRunner(self.config, self.njs_url, self.jobid, self.token,
                    self.admin_token)
     rv = deepcopy(CATALOG_GET_MODULE_VERSION)
     rv['docker_img_name'] = 'mock_app:latest'
     jr.logger.njs.add_job_logs = MagicMock(return_value=rv)
     jr.njs.check_job_canceled.return_value = {'finished': False}
     jr.njs.get_job_params.return_value = params
     jr._get_token_lifetime = MagicMock(return_value=self.future)
     out = jr.run()
     self.assertIn('result', out)
     self.assertNotIn('error', out)
コード例 #4
0
ファイル: test_jobrunner.py プロジェクト: kbase/JobRunner
 def test_run(self, mock_njs, mock_auth):
     self._cleanup(self.jobid)
     params = deepcopy(NJS_JOB_PARAMS)
     params[0]['method'] = 'mock_app.bogus'
     params[0]['params'] = {'param1': 'value1'}
     jr = JobRunner(self.config, self.njs_url, self.jobid, self.token,
                    self.admin_token)
     rv = deepcopy(CATALOG_GET_MODULE_VERSION)
     rv['docker_img_name'] = 'mock_app:latest'
     jr.cc.catalog.get_module_version = MagicMock(return_value=rv)
     jr.cc.catalog.list_volume_mounts = MagicMock(return_value=[])
     jr.cc.catalog.get_secure_config_params = MagicMock(return_value=None)
     jr.logger.njs.add_job_logs = MagicMock(return_value=rv)
     jr.njs.get_job_params.return_value = params
     jr.njs.check_job_canceled.return_value = {'finished': False}
     jr.auth.get_user.return_value = "bogus"
     jr._get_token_lifetime = MagicMock(return_value=self.future)
     out = jr.run()
     self.assertIn('result', out)
     self.assertNotIn('error', out)
コード例 #5
0
ファイル: test_jobrunner.py プロジェクト: kbase/JobRunner
 def test_run_slurm(self, mock_njs, mock_auth):
     self._cleanup(self.jobid)
     params = deepcopy(NJS_JOB_PARAMS)
     params[0]['method'] = 'RunTester.run_RunTester'
     params[0]['params'] = [{'do_slurm': 1}]
     params[1]['auth-service-url'] = self.config['auth-service-url']
     params[1]['auth.service.url.v2'] = self.config['auth2-url']
     jr = JobRunner(self.config, self.njs_url, self.jobid, self.token,
                    self.admin_token)
     rv = deepcopy(CATALOG_GET_MODULE_VERSION)
     rv['docker_img_name'] = 'test/runtester:latest'
     jr.cc.catalog.get_module_version = MagicMock(return_value=rv)
     jr.cc.catalog.list_volume_mounts = MagicMock(return_value=[])
     jr.cc.catalog.get_secure_config_params = MagicMock(return_value=None)
     jr.logger.njs.add_job_logs = MagicMock(return_value=rv)
     jr.njs.get_job_params.return_value = params
     jr.njs.check_job_canceled.return_value = {'finished': False}
     jr.auth.get_user.return_value = "bogus"
     jr._get_token_lifetime = MagicMock(return_value=self.future)
     out = jr.run()
     self.assertNotIn('error', out)
コード例 #6
0
ファイル: test_jobrunner.py プロジェクト: kbase/JobRunner
 def test_max_jobs(self, mock_njs, mock_auth):
     self._cleanup(self.jobid)
     params = deepcopy(NJS_JOB_PARAMS)
     params[0]['method'] = 'RunTester.run_RunTester'
     params[0]['params'] = [{'depth': 2, 'size': 1000, 'parallel': 5}]
     config = deepcopy(self.config)
     config['max_tasks'] = 2
     jr = JobRunner(config, self.njs_url, self.jobid, self.token,
                    self.admin_token)
     rv = deepcopy(CATALOG_GET_MODULE_VERSION)
     rv['docker_img_name'] = 'test/runtester:latest'
     jr.cc.catalog.get_module_version = MagicMock(return_value=rv)
     jr.cc.catalog.list_volume_mounts = MagicMock(return_value=[])
     jr.cc.catalog.get_secure_config_params = MagicMock(return_value=None)
     jr.logger.njs.add_job_logs = MagicMock(return_value=rv)
     jr._get_token_lifetime = MagicMock(return_value=self.future)
     jr.njs.get_job_params.return_value = params
     jr.njs.check_job_canceled.return_value = {'finished': False}
     jr.auth.get_user.return_value = "bogus"
     out = jr.run()
     self.assertIn('error', out)