Beispiel #1
0
    def test_monitor_job_running(self, retry, get_connection):
        conn = get_connection.return_value.__enter__.return_value
        job_id = 'dummy'
        cluster = {
            '_id': 'jill',
            'type': 'ec2',
            'name': 'dummy',
            'config': {
                '_id': 'dummy',
                'scheduler': {
                    'type': 'sge'
                }
            }
        }
        job_model = {
            '_id': job_id,
            'queueJobId': '1',
            'name': 'dummy',
            'output': []
        }

        conn.execute.return_value = [ 'job-ID  prior   name       user         state submit/start at     queue  slots ja-task-ID',
                             '-----------------------------------------------------------------------------------------',
                             '1 0.00000 hostname   sgeadmin     r     09/09/2009 14:58:14                1']

        def _get_status(url, request):
            content = {
                'status': 'running'
            }
            content = json.dumps(content).encode('utf8')
            headers = {
                'content-length': len(content),
                'content-type': 'application/json'
            }

            self._get_status_called  = True
            return httmock.response(200, content, headers, request=request)

        def _set_status(url, request):
            expected = {'status': 'running', 'timings': {}, 'output': []}
            self._set_status_called = json.loads(request.body) == expected

            if not self._set_status_called:
                six.print_(json.loads(request.body), file=sys.stderr)

            return httmock.response(200, None, {}, request=request)

        status_url = '/api/v1/jobs/%s/status' % job_id
        get_status = httmock.urlmatch(
            path=r'^%s$' % status_url, method='GET')(_get_status)

        status_update_url = '/api/v1/jobs/%s' % job_id
        set_status = httmock.urlmatch(
            path=r'^%s$' % status_update_url, method='PATCH')(_set_status)

        with httmock.HTTMock(get_status, set_status):
            job.monitor_job(cluster, job_model, **{'girder_token': 's', 'log_write_url': 1})

        self.assertTrue(self._get_status_called, 'Expect get status endpoint to be hit')
        self.assertTrue(self._set_status_called, 'Expect set status endpoint to be hit')
Beispiel #2
0
    def test_monitor_job_terminated(self, get_connection):
        conn = get_connection.return_value.__enter__.return_value

        job_id = 'dummy'
        cluster = {
            '_id': 'bob',
            'type': 'ec2',
            'name': 'dummy',
            'config': {
                '_id': 'dummy',
                'scheduler': {
                    'type': 'sge'
                }
            }
        }
        job_model = {
            '_id': job_id,
            'queueJobId': 'dummy',
            'name': 'dummy',
            'output': []
        }

        conn.execute.return_value = 'qstat output'

        def _get_status(url, request):
            content = {
                'status': 'terminating'
            }
            content = json.dumps(content).encode('utf8')
            headers = {
                'content-length': len(content),
                'content-type': 'application/json'
            }

            self._get_status_called  = True
            return httmock.response(200, content, headers, request=request)

        def _set_status(url, request):
            expected = {u'status': u'terminated', u'timings': {}, u'output': []}

            self._set_status_called = json.loads(request.body) == expected

            return httmock.response(200, None, {}, request=request)

        status_url = '/api/v1/jobs/%s/status' % job_id
        get_status = httmock.urlmatch(
            path=r'^%s$' % status_url, method='GET')(_get_status)

        status_update_url = '/api/v1/jobs/%s' % job_id
        set_status = httmock.urlmatch(
            path=r'^%s$' % status_update_url, method='PATCH')(_set_status)

        with httmock.HTTMock(get_status, set_status):
            job.monitor_job(cluster, job_model, **{'girder_token': 's', 'log_write_url': 1})

        self.assertTrue(self._get_status_called, 'Expect get status endpoint to be hit')
        self.assertTrue(self._set_status_called, 'Expect set status endpoint to be hit')
Beispiel #3
0
    def test_monitor_job_complete(self, get_connection):
        conn = get_connection.return_value.__enter__.return_value
        conn.stat.return_value.st_size = 0

        job_id = 'dummy'
        cluster = {
            '_id': 'dummy',
            'type': 'ec2',
            'name': 'dummy',
             'config': {
                '_id': 'dummy',
                'scheduler': {
                    'type': 'sge'
                }
            }
        }
        job_model = {
            '_id': job_id,
            'queueJobId': 'dummy',
            'name': 'dummy',
            'output': [{
                'itemId': 'dummy'
            }],
            'dir': '/home/test/%s' % job_id
        }

        conn.execute.return_value = 'qstat output'

        def _get_status(url, request):
            content = {
                'status': 'running'
            }
            content = json.dumps(content).encode('utf8')
            headers = {
                'content-length': len(content),
                'content-type': 'application/json'
            }

            self._get_status_called  = True
            return httmock.response(200, content, headers, request=request)

        def _set_status(url, request):
            expected = {'status': 'uploading', 'timings': {}, 'output': [{'itemId': u'dummy'}]}
            self._set_status_called = json.loads(request.body) == expected

            return httmock.response(200, None, {}, request=request)

        status_url = '/api/v1/jobs/%s/status' % job_id
        get_status = httmock.urlmatch(
            path=r'^%s$' % status_url, method='GET')(_get_status)

        status_update_url = '/api/v1/jobs/%s' % job_id
        set_status = httmock.urlmatch(
            path=r'^%s$' % status_update_url, method='PATCH')(_set_status)

        with httmock.HTTMock(get_status, set_status):
            job.monitor_job(cluster, job_model, **{'girder_token': 's', 'log_write_url': 1})

        self.assertTrue(self._get_status_called, 'Expect get status endpoint to be hit')
        self.assertTrue(self._set_status_called, 'Expect set status endpoint to be hit')
        expected_calls = [[[{u'config': {u'_id': u'dummy', u'scheduler': {u'type': u'sge'}}, u'name': u'dummy', u'type': u'ec2', u'_id': u'dummy'}, {u'status': u'uploading', u'output': [{u'itemId': u'dummy'}], u'_id': u'dummy', u'queueJobId': u'dummy', u'name': u'dummy', u'dir': u'/home/test/dummy'}], {u'girder_token': u's', u'log_write_url': 1, u'job_dir': u'/home/test/dummy'}]]
        self.assertCalls(self._upload_job_output.call_args_list, expected_calls)
Beispiel #4
0
    def test_monitor_job_terminated(self, get_connection):
        conn = get_connection.return_value.__enter__.return_value

        job_id = 'dummy'
        cluster = {
            '_id': 'bob',
            'type': 'ec2',
            'name': 'dummy',
            'config': {
                '_id': 'dummy',
                'scheduler': {
                    'type': 'sge'
                }
            }
        }
        job_model = {
            '_id': job_id,
            'queueJobId': 'dummy',
            'name': 'dummy',
            'output': []
        }

        conn.execute.return_value = 'qstat output'

        def _get_status(url, request):
            content = {'status': 'terminating'}
            content = json.dumps(content).encode('utf8')
            headers = {
                'content-length': len(content),
                'content-type': 'application/json'
            }

            self._get_status_called = True
            return httmock.response(200, content, headers, request=request)

        def _set_status(url, request):
            expected = {
                u'status': u'terminated',
                u'timings': {},
                u'output': []
            }

            self._set_status_called = json.loads(
                request.body.decode('utf8')) == expected

            return httmock.response(200, None, {}, request=request)

        status_url = '/api/v1/jobs/%s/status' % job_id
        get_status = httmock.urlmatch(path=r'^%s$' % status_url,
                                      method='GET')(_get_status)

        status_update_url = '/api/v1/jobs/%s' % job_id
        set_status = httmock.urlmatch(path=r'^%s$' % status_update_url,
                                      method='PATCH')(_set_status)

        with httmock.HTTMock(get_status, set_status):
            job.monitor_job(cluster, job_model, **{
                'girder_token': 's',
                'log_write_url': 1
            })

        self.assertTrue(self._get_status_called,
                        'Expect get status endpoint to be hit')
        self.assertTrue(self._set_status_called,
                        'Expect set status endpoint to be hit')
Beispiel #5
0
    def test_monitor_job_tail_output(self, get_connection, retry, *args):

        job_id = 'dummy'
        cluster = {
            '_id': 'bill',
            'type': 'ec2',
            'name': 'dummy',
            'config': {
                '_id': 'dummy',
                'scheduler': {
                    'type': 'sge'
                }
            }
        }
        job_model = {
            '_id': job_id,
            'queueJobId': '1',
            'name': 'dummy',
            'output': [{
                'tail': True,
                'path': 'dummy/file/path'
            }],
            'dir': '/home/test'
        }

        conn = get_connection.return_value.__enter__.return_value
        conn.execute.side_effect = [
            'job-ID  prior   name       user         state submit/start at     queue  slots ja-task-ID',
            '-----------------------------------------------------------------------------------------',
            '1 0.00000 hostname   sgeadmin     r     09/09/2009 14:58:14                1'
        ], ['i have a tail', 'asdfas']

        def _get_status(url, request):
            content = {'status': 'running'}
            content = json.dumps(content).encode('utf8')
            headers = {
                'content-length': len(content),
                'content-type': 'application/json'
            }

            self._get_status_called = True
            return httmock.response(200, content, headers, request=request)

        def _set_status(url, request):
            expected = {
                u'status':
                u'running',
                u'output': [{
                    u'content': [u'i have a tail', u'asdfas'],
                    u'path': u'dummy/file/path',
                    u'tail': True
                }],
                u'timings': {}
            }
            self._set_status_called = json.loads(
                request.body.decode('utf8')) == expected

            if not self._set_status_called:
                six.print_(json.loads(request.body.decode('utf8')),
                           file=sys.stderr)

            return httmock.response(200, None, {}, request=request)

        status_url = '/api/v1/jobs/%s/status' % job_id
        get_status = httmock.urlmatch(path=r'^%s$' % status_url,
                                      method='GET')(_get_status)

        status_update_url = '/api/v1/jobs/%s' % job_id
        set_status = httmock.urlmatch(path=r'^%s$' % status_update_url,
                                      method='PATCH')(_set_status)

        with httmock.HTTMock(get_status, set_status):
            job.monitor_job(cluster, job_model, **{
                'girder_token': 's',
                'log_write_url': 1
            })

        self.assertTrue(self._get_status_called,
                        'Expect get status endpoint to be hit')
        self.assertTrue(self._set_status_called,
                        'Expect set status endpoint to be hit')
Beispiel #6
0
    def test_monitor_job_complete(self, get_connection):
        conn = get_connection.return_value.__enter__.return_value
        conn.stat.return_value.st_size = 0

        job_id = 'dummy'
        cluster = {
            '_id': 'dummy',
            'type': 'ec2',
            'name': 'dummy',
            'config': {
                '_id': 'dummy',
                'scheduler': {
                    'type': 'sge'
                }
            }
        }
        job_model = {
            '_id': job_id,
            'queueJobId': 'dummy',
            'name': 'dummy',
            'output': [{
                'itemId': 'dummy'
            }],
            'dir': '/home/test/%s' % job_id
        }

        conn.execute.return_value = 'qstat output'

        def _get_status(url, request):
            content = {'status': 'running'}
            content = json.dumps(content).encode('utf8')
            headers = {
                'content-length': len(content),
                'content-type': 'application/json'
            }

            self._get_status_called = True
            return httmock.response(200, content, headers, request=request)

        def _set_status(url, request):
            expected = {
                'status': 'uploading',
                'timings': {},
                'output': [{
                    'itemId': u'dummy'
                }]
            }
            print('set_status')
            self._set_status_called = json.loads(
                request.body.decode('utf8')) == expected

            return httmock.response(200, None, {}, request=request)

        status_url = '/api/v1/jobs/%s/status' % job_id
        get_status = httmock.urlmatch(path=r'^%s$' % status_url,
                                      method='GET')(_get_status)

        status_update_url = '/api/v1/jobs/%s' % job_id
        set_status = httmock.urlmatch(path=r'^%s$' % status_update_url,
                                      method='PATCH')(_set_status)

        with httmock.HTTMock(get_status, set_status):
            job.monitor_job(cluster, job_model, **{
                'girder_token': 's',
                'log_write_url': 1
            })

        self.assertTrue(self._get_status_called,
                        'Expect get status endpoint to be hit')
        self.assertTrue(self._set_status_called,
                        'Expect set status endpoint to be hit')
        expected_calls = [[[{
            u'config': {
                u'_id': u'dummy',
                u'scheduler': {
                    u'type': u'sge'
                }
            },
            u'name': u'dummy',
            u'type': u'ec2',
            u'_id': u'dummy'
        }, {
            u'status': u'uploading',
            u'output': [{
                u'itemId': u'dummy'
            }],
            u'_id': u'dummy',
            u'queueJobId': u'dummy',
            u'name': u'dummy',
            u'dir': u'/home/test/dummy'
        }], {
            u'girder_token': u's',
            u'log_write_url': 1,
            u'job_dir': u'/home/test/dummy'
        }]]
        self.assertCalls(self._upload_job_output.call_args_list,
                         expected_calls)