예제 #1
0
파일: handlers.py 프로젝트: chjohnst/Tron
 def get_data(self, job, run_id):
     status, data = client.request(trond_url(), 'jobs/%s/%s/' % (job, run_id))
     if status == client.OK:
         run_data=[]
         for run in data['runs']:
             status, run_info = client.request(trond_url(),
                                            'jobs/%s/%s/%s' % (
                                                job, run_id, run["name"]))
             if status == client.OK:
                 run_data.append(run_info)
         return (data, run_data)
     return (None, None)
예제 #2
0
def command_jobs(command, jobs, args, ns=None):
    """ This function run tronctl command for the jobs
    command: the tronctl command it will run
    jobs: a list of jobs
    args: the args for this script
    ns: the namespace to use as the prefix for each job, if None, the scrip would use args.old_ns instead
    """
    data = {'command': command}
    command_flag = True
    for job in jobs:
        if ns is not None:
            job_name = ns + '.' + job['name']
        else:
            job_name = args.old_ns + '.' + job['name']

        if command == 'move':
            data = {'command': command, 'old_name': args.old_ns + '.' + job['name'], 'new_name': args.new_ns + '.' + job['name']}
            uri = urljoin(args.server, 'api/jobs')
            job_name = args.new_ns + '.' + job['name']
        else:
            data = {'command': command}
            uri = urljoin(args.server, 'api/jobs/' + job_name)

        response = client.request(uri, data=data)
        if response.error:
            print(bcolors.FAIL + 'Failed to {} {}'.format(command, job_name) + bcolors.ENDC)
            command_flag = False
        else:
            print(bcolors.OKGREEN + 'Succeed to {} {}'.format(command, job_name) + bcolors.ENDC)
    return command_flag
예제 #3
0
파일: client_test.py 프로젝트: yenNSTH/Tron
 def test_request_http_error(self):
     self.mock_urlopen.side_effect = HTTPError(
         self.url, 500, 'broke', {}, build_file_mock('oops'),
     )
     response = client.request(self.url)
     expected = client.Response(500, 'broke', 'oops')
     assert_equal(response, expected)
예제 #4
0
 def test_request_http_error(self, _):
     self.mock_urlopen.side_effect = HTTPError(
         self.url,
         500,
         'broke',
         mock.Mock(get_content_charset=mock.Mock(return_value='utf-8'), ),
         build_file_mock(b'oops'),
     )
     response = client.request(self.url)
     expected = client.Response(500, 'broke', 'oops')
     assert_equal(response, expected)
예제 #5
0
파일: client_test.py 프로젝트: Yelp/Tron
 def test_request_http_error(self, _):
     self.mock_urlopen.side_effect = HTTPError(
         self.url,
         500,
         'broke',
         mock.Mock(get_content_charset=mock.Mock(return_value='utf-8'), ),
         build_file_mock(b'oops'),
     )
     response = client.request(self.url)
     expected = client.Response(500, 'broke', 'oops')
     assert_equal(response, expected)
예제 #6
0
def command_jobs(command, jobs, args, ns=None):
    """ This function run tronctl command for the jobs
    command: the tronctl command it will run
    jobs: a list of jobs
    args: the args for this script
    ns: the namespace to use as the prefix for each job, if None, the scrip would use args.old_ns instead
    """
    data = {'command': command}
    command_flag = True
    for job in jobs:
        if ns is not None:
            job_name = ns + '.' + job['name']
        else:
            job_name = args.old_ns + '.' + job['name']

        if command == 'move':
            data = {
                'command': command,
                'old_name': args.old_ns + '.' + job['name'],
                'new_name': args.new_ns + '.' + job['name']
            }
            uri = urljoin(args.server, 'api/jobs')
            job_name = args.new_ns + '.' + job['name']
        else:
            data = {'command': command}
            uri = urljoin(args.server, 'api/jobs/' + job_name)

        response = client.request(uri, data=data)
        if response.error:
            print(bcolors.FAIL + 'Failed to {} {}'.format(command, job_name) +
                  bcolors.ENDC)
            command_flag = False
        else:
            print(bcolors.OKGREEN +
                  'Succeed to {} {}'.format(command, job_name) + bcolors.ENDC)
    return command_flag
예제 #7
0
 def test_request_success(self):
     self.mock_urlopen.return_value = build_file_mock('{"ok": "ok"}')
     response = client.request(self.url)
     expected = client.Response(None, None, {'ok': 'ok'})
     assert_equal(response, expected)
예제 #8
0
 def test_request_url_error(self):
     self.mock_urlopen.side_effect = urllib2.URLError('broke')
     response = client.request(self.url)
     expected = client.Response(client.URL_ERROR, 'broke', None)
     assert_equal(response, expected)
예제 #9
0
 def test_request_http_error(self):
     self.mock_urlopen.side_effect = urllib2.HTTPError(
         self.url, 500, 'broke', {}, build_file_mock('oops'))
     response = client.request(self.url)
     expected = client.Response(500, 'broke', 'oops')
     assert_equal(response, expected)
예제 #10
0
 def test_request_success(self):
     self.mock_urlopen.return_value = build_file_mock('{"ok": "ok"}')
     response = client.request(self.url)
     expected = client.Response(None, None, {'ok': 'ok'})
     assert_equal(response, expected)
예제 #11
0
 def test_request_url_error(self):
     self.mock_urlopen.side_effect = urllib2.URLError('broke')
     response = client.request(self.url)
     expected = client.Response(client.URL_ERROR, 'broke', None)
     assert_equal(response, expected)
예제 #12
0
파일: handlers.py 프로젝트: chjohnst/Tron
 def get_data(self, job, run_id, action):
     status, content = client.request(trond_url(),
                                   'jobs/%s/%s/%s/' % (job, run_id, action))
     if status == client.OK:
         return content
     return None
예제 #13
0
파일: handlers.py 프로젝트: chjohnst/Tron
 def get_data(self, job):
     status, content = client.request(trond_url(), 'jobs/%s/' % job)
     if status == client.OK:
         return content
     return None