Skip to content
Permalink
Browse files

increase max priority to 16,000,000 (#1230)

  • Loading branch information...
nsinkov authored and dposada committed Oct 9, 2019
1 parent 2e3d2de commit a158e8bc35d30e7563136d6405f78452012fcb60
@@ -242,15 +242,25 @@ def valid_uuid(s):
else:
raise argparse.ArgumentTypeError('%s is not a valid UUID' % s)

def valid_priority(value):
"""Checks that the given value is a valid priority"""
try:
integer = int(value)
except:
raise argparse.ArgumentTypeError(f'{value} is not an integer')
if integer < 0 or integer > 16000000:
raise argparse.ArgumentTypeError(f'Job priority must be between 0 and 16,000,000 (inclusive)')
return integer

def register(add_parser, add_defaults):
"""Adds this sub-command's parser and returns the action function"""
submit_parser = add_parser('submit', help='create job for command')
submit_parser.add_argument('--uuid', '-u', help='uuid of job', type=valid_uuid)
submit_parser.add_argument('--name', '-n', help='name of job')
submit_parser.add_argument('--priority', '-p', help='priority of job, between 0 and 100 (inclusive), with 100 '
'being highest priority (default = 50)',
type=int, choices=range(0, 101), metavar='')
submit_parser.add_argument('--priority', '-p', help='Per-user job priority. Allows values between 0 and 16,000,000 '
'(inclusive), with higher values having higher priority. '
'Defaults to 50 and typically set between 0 and 100.',
type=valid_priority, metavar='')
submit_parser.add_argument('--max-retries', help='maximum retries for job',
dest='max-retries', type=int, metavar='COUNT')
submit_parser.add_argument('--max-runtime', help='maximum runtime for job',
@@ -2650,3 +2650,21 @@ def test_disallowed_docker_parameters(self):
job_uuid, resp = util.submit_job(self.cook_url, container=container)
self.assertEqual(400, resp.status_code)
self.assertTrue('this_should_not_be_allowed' in resp.text, resp.text)

def test_priority(self):
_, resp = util.submit_job(self.cook_url, priority=0)
self.assertEqual(201, resp.status_code, msg=resp.content)

_, resp = util.submit_job(self.cook_url, priority=100)
self.assertEqual(201, resp.status_code, msg=resp.content)

_, resp = util.submit_job(self.cook_url, priority=16000000)
self.assertEqual(201, resp.status_code, msg=resp.content)

_, resp = util.submit_job(self.cook_url, priority=-1)
self.assertEqual(400, resp.status_code, msg=resp.content)
self.assertTrue(f'priority":"(not (between-0-and-16000000' in str(resp.content))

_, resp = util.submit_job(self.cook_url, priority=16000001)
self.assertEqual(400, resp.status_code, msg=resp.content)
self.assertTrue(f'priority":"(not (between-0-and-16000000' in str(resp.content))
@@ -347,17 +347,26 @@ def test_submit_priority(self):
cp, jobs = cli.show_jobs(uuids, self.cook_url)
self.assertEqual(0, cp.returncode, cp.stderr)
self.assertEqual(0, jobs[0]['priority'])

cp, uuids = cli.submit('ls', self.cook_url, submit_flags='--priority 100')
self.assertEqual(0, cp.returncode, cp.stderr)
cp, jobs = cli.show_jobs(uuids, self.cook_url)
self.assertEqual(0, cp.returncode, cp.stderr)
self.assertEqual(100, jobs[0]['priority'])

cp, uuids = cli.submit('ls', self.cook_url, submit_flags='--priority 16000000')
self.assertEqual(0, cp.returncode, cp.stderr)
cp, jobs = cli.show_jobs(uuids, self.cook_url)
self.assertEqual(0, cp.returncode, cp.stderr)
self.assertEqual(16000000, jobs[0]['priority'])

cp, uuids = cli.submit('ls', self.cook_url, submit_flags='--priority -1')
self.assertEqual(2, cp.returncode, cp.stderr)
self.assertIn('--priority/-p: invalid choice', cli.decode(cp.stderr))
cp, uuids = cli.submit('ls', self.cook_url, submit_flags='--priority 101')
self.assertIn('--priority/-p: Job priority must be between', cli.decode(cp.stderr))

cp, uuids = cli.submit('ls', self.cook_url, submit_flags='--priority 16000001')
self.assertEqual(2, cp.returncode, cp.stderr)
self.assertIn('--priority/-p: invalid choice', cli.decode(cp.stderr))
self.assertIn('--priority/-p: Job priority must be between', cli.decode(cp.stderr))

def test_submit_output_should_explain_what_happened(self):
cp, _ = cli.submit('ls', self.cook_url)
@@ -292,7 +292,7 @@
(re-matches #"[\.a-zA-Z0-9_\-\*]*" s)))))

(s/defschema JobPriority
(s/both s/Int (s/pred #(<= 0 % 100) 'between-0-and-100)))
(s/both s/Int (s/pred #(<= 0 % 16000000) 'between-0-and-16000000)))

(defn valid-runtimes?
"Returns false if the expected-runtime of the given job

0 comments on commit a158e8b

Please sign in to comment.
You can’t perform that action at this time.