def test_launch_mesos_grace_period(marathon_service_name): """Tests 'taskKillGracePeriodSeconds' option using a Mesos container in a Marathon environment. Read more details about this test in `test_root_marathon.py::test_launch_mesos_root_marathon_grace_period` """ app_def = apps.mesos_app(app_id='mesos-grace-period-app') default_grace_period = 3 grace_period = 20 app_def['fetch'] = [{"uri": "https://downloads.mesosphere.com/testing/test.py"}] app_def['cmd'] = '/opt/mesosphere/bin/python test.py' app_def['taskKillGracePeriodSeconds'] = grace_period app_id = app_def['id'].lstrip('/') client = marathon.create_client() client.add_app(app_def) shakedown.deployment_wait(app_id=app_id) tasks = shakedown.get_service_task(marathon_service_name, app_id) assert tasks is not None client.scale_app(app_id, 0) tasks = shakedown.get_service_task(marathon_service_name, app_id) assert tasks is not None # tasks should still be here after the default_grace_period time.sleep(default_grace_period + 1) tasks = shakedown.get_service_task(marathon_service_name, app_id) assert tasks is not None # but not after the set grace_period time.sleep(grace_period) tasks = shakedown.get_service_task(marathon_service_name, app_id) assert tasks is None
def test_event_channel(): """ Tests the event channel. The way events are verified is by streaming the events to a events.txt file. The fixture ensures the file is removed before and after the test. events checked are connecting, deploying a good task and killing a task. """ app_def = apps.mesos_app() app_id = app_def['id'] client = marathon.create_client() client.add_app(app_def) shakedown.deployment_wait() master_ip = shakedown.master_ip() @retrying.retry(wait_fixed=1000, stop_max_attempt_number=30, retry_on_exception=common.ignore_exception) def check_deployment_message(): status, stdout = shakedown.run_command(master_ip, 'cat events.txt') assert 'event_stream_attached' in stdout, "event_stream_attached event has not been found" assert 'deployment_info' in stdout, "deployment_info event has not been found" assert 'deployment_step_success' in stdout, "deployment_step_success has not been found" check_deployment_message() client.remove_app(app_id, True) shakedown.deployment_wait() @retrying.retry(wait_fixed=1000, stop_max_attempt_number=30, retry_on_exception=common.ignore_exception) def check_kill_message(): status, stdout = shakedown.run_command(master_ip, 'cat events.txt') assert 'KILLED' in stdout, "KILLED event has not been found" check_kill_message()
def test_app_update(): """Tests that an app gets successfully updated.""" app_def = apps.mesos_app(app_id='update-app') client = marathon.create_client() client.add_app(app_def) shakedown.deployment_wait() tasks = client.get_tasks(app_def["id"]) assert len( tasks ) == 1, "The number of tasks is {} after deployment, but 1 was expected".format( len(tasks)) app_def['cpus'] = 1 app_def['instances'] = 2 client.update_app(app_def["id"], app_def) shakedown.deployment_wait() tasks = client.get_tasks(app_def["id"]) assert len( tasks ) == 2, "The number of tasks is {} after deployment, but 2 was expected".format( len(tasks))
def test_launch_mesos_grace_period(marathon_service_name): """Tests 'taskKillGracePeriodSeconds' option using a Mesos container in a Marathon environment. Read more details about this test in `test_root_marathon.py::test_launch_mesos_root_marathon_grace_period` """ app_def = apps.mesos_app() default_grace_period = 3 grace_period = 20 app_def['fetch'] = [{"uri": "https://downloads.mesosphere.com/testing/test.py"}] app_def['cmd'] = '/opt/mesosphere/bin/python test.py' app_def['taskKillGracePeriodSeconds'] = grace_period app_id = app_def['id'].lstrip('/') client = marathon.create_client() client.add_app(app_def) shakedown.deployment_wait(app_id=app_id) tasks = shakedown.get_service_task(marathon_service_name, app_id) assert tasks is not None client.scale_app(app_id, 0) tasks = shakedown.get_service_task(marathon_service_name, app_id) assert tasks is not None # tasks should still be here after the default_grace_period time.sleep(default_grace_period + 1) tasks = shakedown.get_service_task(marathon_service_name, app_id) assert tasks is not None # but not after the set grace_period time.sleep(grace_period) tasks = shakedown.get_service_task(marathon_service_name, app_id) assert tasks is None
def test_launch_app_on_public_agent(): """ Test the successful launch of a mesos container on public agent. MoMs by default do not have slave_public access. """ client = marathon.create_client() app_def = common.add_role_constraint_to_app_def(apps.mesos_app(), ['slave_public']) client.add_app(app_def) shakedown.deployment_wait() tasks = client.get_tasks(app_def["id"]) task_ip = tasks[0]['host'] assert task_ip in shakedown.get_public_agents(), "The application task got started on a private agent"
def test_launch_mesos_container(): """Launches a Mesos container with a simple command.""" app_def = apps.mesos_app(app_id='mesos-container-app') client = marathon.create_client() client.add_app(app_def) shakedown.deployment_wait() tasks = client.get_tasks(app_def["id"]) app = client.get_app(app_def["id"]) assert len(tasks) == 1, "The number of tasks is {} after deployment, but only 1 was expected".format(len(tasks)) assert app['container']['type'] == 'MESOS', "The container type is not MESOS"
def test_launch_mesos_container(): """Launches a Mesos container with a simple command.""" app_def = apps.mesos_app() client = marathon.create_client() client.add_app(app_def) shakedown.deployment_wait() tasks = client.get_tasks(app_def["id"]) app = client.get_app(app_def["id"]) assert len(tasks) == 1, "The number of tasks is {} after deployment, but only 1 was expected".format(len(tasks)) assert app['container']['type'] == 'MESOS', "The container type is not MESOS"
def test_launch_app_timed(): """Most tests wait until a task is launched with no reference to time. This test verifies that if a app is launched on marathon that within 3 secs there is a task spawned. """ app_def = apps.mesos_app(app_id='/timed-launch-app') app_id = app_def["id"] client = marathon.create_client() client.add_app(app_def) # if not launched in 10 sec fail assert_that(lambda: client.get_tasks(app_id), eventually(has_len(equal_to(1)), max_attempts=10))
def test_launch_app_timed(): """Most tests wait until a task is launched with no reference to time. This test verifies that if a app is launched on marathon that within 3 secs there is a task spawned. """ app_def = apps.mesos_app(app_id='/timed-launch-app') client = marathon.create_client() client.add_app(app_def) # if not launched in 3 sec fail time.sleep(3) tasks = client.get_tasks(app_def["id"]) assert len(tasks) == 1, "The number of tasks is {} after deployment, but 1 was expected".format(len(tasks))
def test_launch_app_timed(): """Most tests wait until a task is launched with no reference to time. This test verifies that if a app is launched on marathon that within 3 secs there is a task spawned. """ app_def = apps.mesos_app(app_id='timed-launch-app') client = marathon.create_client() client.add_app(app_def) # if not launched in 3 sec fail time.sleep(3) tasks = client.get_tasks(app_def["id"]) assert len(tasks) == 1, "The number of tasks is {} after deployment, but 1 was expected".format(len(tasks))
def test_app_update(): """Tests that an app gets successfully updated.""" app_def = apps.mesos_app() client = marathon.create_client() client.add_app(app_def) shakedown.deployment_wait() tasks = client.get_tasks(app_def["id"]) assert len(tasks) == 1, "The number of tasks is {} after deployment, but 1 was expected".format(len(tasks)) app_def['cpus'] = 1 app_def['instances'] = 2 client.update_app(app_def["id"], app_def) shakedown.deployment_wait() tasks = client.get_tasks(app_def["id"]) assert len(tasks) == 2, "The number of tasks is {} after deployment, but 2 was expected".format(len(tasks))
async def test_event_channel(sse_events): """ Tests the event channel. The way events are verified is by converting the parsed events to an iterator and asserting the right oder of certain events. Unknown events are skipped. """ await common.assert_event('event_stream_attached', sse_events) app_def = apps.mesos_app() app_id = app_def['id'] client = marathon.create_client() client.add_app(app_def) common.deployment_wait(service_id=app_id) await common.assert_event('deployment_info', sse_events) await common.assert_event('deployment_step_success', sse_events) client.remove_app(app_id, True) common.deployment_wait(service_id=app_id) await common.assert_event('app_terminated_event', sse_events)
async def test_event_channel(sse_events): """ Tests the event channel. The way events are verified is by converting the parsed events to an iterator and asserting the right oder of certain events. Unknown events are skipped. """ await common.assert_event('event_stream_attached', sse_events) app_def = apps.mesos_app() app_id = app_def['id'] client = marathon.create_client() client.add_app(app_def) deployment_wait(service_id=app_id) await common.assert_event('deployment_info', sse_events) await common.assert_event('deployment_step_success', sse_events) client.remove_app(app_id, True) deployment_wait(service_id=app_id) await common.assert_event('app_terminated_event', sse_events)