def test_dispatcher_role_propagated(setup_spark, role, enforce_role): dispatcher_framework = dcos_utils.get_framework_json(SERVICE_NAME, completed=False) log.info("Dispatcher framework:\n{}".format(dispatcher_framework)) assert role == dispatcher_framework["role"] _submit_job_and_verify_role(role)
def test_dispatcher_role_enforced(setup_spark, service_name, role, enforce_role): dispatcher_framework = dcos_utils.get_framework_json(service_name, completed=False) log.info("Dispatcher framework:\n{}".format(dispatcher_framework)) assert role == dispatcher_framework["role"] _submit_job_and_verify_role(service_name, role) _verify_submission_rejected(service_name=service_name, driver_role="custom_role")
def test_marathon_group_enforced(create_group, setup_spark, group, enforce_group, role, enforce_role): log.info( "Running test: group='{}', enforce_group='{}', service_name='{}', role='{}', enforce_role='{}'" .format(group, enforce_group, SERVICE_NAME, role, enforce_role)) dispatcher_framework = dcos_utils.get_framework_json(SERVICE_NAME, completed=False) log.info("Dispatcher framework:\n{}".format(dispatcher_framework)) assert group == dispatcher_framework["role"] # verifying submissions without role _submit_job_and_verify_role(expected_role=group) # verifying submissions with role equal to group role _submit_job_and_verify_role(expected_role=group, driver_role=group) # submissions with role different from group should be rejected _verify_submission_rejected(driver_role="{}/spark".format(group))
def _submit_job_and_verify_role(service_name, expected_role, driver_role=None): app_name = "MockTaskRunner" submit_args = ["--conf spark.cores.max=1", "--class {}".format(app_name)] submission_id = utils.submit_job(service_name=service_name, app_url=utils.dcos_test_jar_url(), app_args="1 300", driver_role=driver_role, args=submit_args) try: sdk_tasks.check_running(app_name, 1, timeout_seconds=300) driver_framework = dcos_utils.get_framework_json(app_name, completed=False) log.info("Driver framework:\n{}".format(driver_framework)) assert expected_role == driver_framework["role"], \ "Expected role '{}' but got '{}'".format(expected_role, driver_framework["role"]) except Exception: log.info(f"Cleaning up. Attempting to kill driver: {submission_id}") utils.kill_driver(submission_id, service_name=service_name)