Skip to content

Commit 6cfb2b1

Browse files
COMPUTE-1764_no_selector_extra_args
(feat) parsers.py, tests - disallowed instanceTypeSelector to be passed in extra-args.
1 parent 7a2bf0c commit 6cfb2b1

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/python/dxpy/cli/parsers.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,28 @@ def process_extra_args(args):
222222
except:
223223
raise DXParserError('Value given for --extra-args could not be parsed as JSON')
224224

225+
# Validate that instanceTypeSelector is not specified in systemRequirements
226+
def check_system_requirements(sys_reqs, context="systemRequirements"):
227+
if isinstance(sys_reqs, dict):
228+
for entry_point, reqs in sys_reqs.items():
229+
if isinstance(reqs, dict) and 'instanceTypeSelector' in reqs:
230+
raise DXParserError(
231+
'instanceTypeSelector cannot be specified in runtime --extra-args. '
232+
'It must be defined in the dxapp.json at build time.'
233+
)
234+
235+
if 'systemRequirements' in args.extra_args:
236+
check_system_requirements(args.extra_args['systemRequirements'])
237+
238+
# Also check regionalOptions
239+
if 'regionalOptions' in args.extra_args:
240+
regional_opts = args.extra_args['regionalOptions']
241+
if isinstance(regional_opts, dict):
242+
for region, region_spec in regional_opts.items():
243+
if isinstance(region_spec, dict) and 'systemRequirements' in region_spec:
244+
check_system_requirements(region_spec['systemRequirements'],
245+
f"regionalOptions.{region}.systemRequirements")
246+
225247
exec_input_args = argparse.ArgumentParser(add_help=False)
226248
exec_input_args.add_argument('-i', '--input', help=fill('An input to be added using "<input name>[:<class>]=<input value>" (provide "class" if there is no input spec; it can be any job IO class, e.g. "string", "array:string", or "array"; if "class" is "array" or not specified, the value will be attempted to be parsed as JSON and is otherwise treated as a string)', width_adjustment=-24), action='append')
227249
exec_input_args.add_argument('-j', '--input-json', help=fill('The full input JSON (keys=input field names, values=input field values)', width_adjustment=-24))

src/python/test/test_dxclient.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3280,6 +3280,31 @@ def test_dx_run_extra_args(self):
32803280
with self.assertSubprocessFailure(stderr_regexp='JSON', exit_code=3):
32813281
run("dx run " + applet_id + " --extra-args not-a-JSON-string")
32823282

3283+
def test_dx_run_extra_args_instanceTypeSelector_rejected(self):
3284+
# Validate that instanceTypeSelector cannot be specified in runtime extra-args
3285+
applet_id = dxpy.api.applet_new({"project": self.project,
3286+
"dxapi": "1.0.0",
3287+
"runSpec": {"interpreter": "bash",
3288+
"distribution": "Ubuntu",
3289+
"release": "14.04",
3290+
"code": "echo 'hello'"}
3291+
})['id']
3292+
3293+
# Test with wildcard entry point
3294+
with self.assertSubprocessFailure(stderr_regexp='instanceTypeSelector cannot be specified in runtime', exit_code=3):
3295+
run('dx run ' + applet_id + ' --extra-args ' +
3296+
'\'{"systemRequirements": {"*": {"instanceTypeSelector": {"allowedInstanceTypes": ["mem2_ssd1_v2_x2"]}}}}\'')
3297+
3298+
# Test with specific entry point
3299+
with self.assertSubprocessFailure(stderr_regexp='instanceTypeSelector cannot be specified in runtime', exit_code=3):
3300+
run('dx run ' + applet_id + ' --extra-args ' +
3301+
'\'{"systemRequirements": {"main": {"instanceTypeSelector": {"allowedInstanceTypes": ["mem2_ssd1_v2_x2"]}}}}\'')
3302+
3303+
# Test with regionalOptions
3304+
with self.assertSubprocessFailure(stderr_regexp='instanceTypeSelector cannot be specified in runtime', exit_code=3):
3305+
run('dx run ' + applet_id + ' --extra-args ' +
3306+
'\'{"regionalOptions": {"aws:us-east-1": {"systemRequirements": {"*": {"instanceTypeSelector": {"allowedInstanceTypes": ["mem2_ssd1_v2_x2"]}}}}}}\'')
3307+
32833308
def test_dx_run_sys_reqs(self):
32843309
app_spec = {"project": self.project,
32853310
"dxapi": "1.0.0",

0 commit comments

Comments
 (0)