def test_launch_container_with_persistent_volume(): """ Tests launching a task with PV. It will write to a file in the PV. The app is killed and restarted and we can still read from the PV. """ app_def = persistent_volume_app() app_id = app_def['id'] client = marathon.create_client() client.add_app(app_def) shakedown.deployment_wait() tasks = client.get_tasks(app_id) assert len(tasks) == 1 port = tasks[0]['ports'][0] host = tasks[0]['host'] cmd = "curl {}:{}/data/foo".format(host, port) run, data = shakedown.run_command_on_master(cmd) assert run, "{} did not succeed".format(cmd) assert data == 'hello\n', "'{}' was not equal to hello\\n".format(data) client.restart_app(app_id) shakedown.deployment_wait() tasks = client.get_tasks(app_id) assert len(tasks) == 1 port = tasks[0]['ports'][0] host = tasks[0]['host'] cmd = "curl {}:{}/data/foo".format(host, port) run, data = shakedown.run_command_on_master(cmd) assert run, "{} did not succeed".format(cmd) assert data == 'hello\nhello\n', "'{}' was not equal to hello\\nhello\\n".format(data)
def test_launch_container_with_persistent_volume(): """ Tests launching a task with PV. It will write to a file in the PV. The app is killed and restarted and we can still read from the PV. """ with marathon_on_marathon(): app_def = persistent_volume_app() app_id = app_def['id'] client = marathon.create_client() client.add_app(app_def) shakedown.deployment_wait() tasks = client.get_tasks(app_id) assert len(tasks) == 1 port = tasks[0]['ports'][0] host = tasks[0]['host'] cmd = "curl {}:{}/data/foo".format(host, port) run, data = shakedown.run_command_on_master(cmd) assert run, "{} did not succeed".format(cmd) assert data == 'hello\n', "'{}' was not equal to hello\\n".format(data) client.restart_app(app_id) shakedown.deployment_wait() tasks = client.get_tasks(app_id) assert len(tasks) == 1 port = tasks[0]['ports'][0] host = tasks[0]['host'] cmd = "curl {}:{}/data/foo".format(host, port) run, data = shakedown.run_command_on_master(cmd) assert run, "{} did not succeed".format(cmd) assert data == 'hello\nhello\n', "'{}' was not equal to hello\\nhello\\n".format(data)
def test_launch_container_with_persistent_volume(): """ Tests launching a task with PV. It will write to a file in the PV. The app is killed and restarted and we can still read from the PV. """ app_def = persistent_volume_app() app_id = app_def['id'] client = marathon.create_client() client.add_app(app_def) shakedown.deployment_wait() tasks = client.get_tasks(app_id) assert len(tasks) == 1, "Num of tasks: {} is not 1 after deployment".format(len(tasks)) port = tasks[0]['ports'][0] host = tasks[0]['host'] cmd = "curl {}:{}/data/foo".format(host, port) run, data = shakedown.run_command_on_master(cmd) assert run, "{} did not succeed".format(cmd) assert data == 'hello\n', "'{}' was not equal to hello\\n".format(data) client.restart_app(app_id) shakedown.deployment_wait() @retrying.retry(wait_fixed=1000, stop_max_delay=10000, retry_on_exception=common.ignore_exception) def check_task_recovery(): tasks = client.get_tasks(app_id) assert len(tasks) == 1, "Num of tasks: {} is not 1 after recovery".format(len(tasks)) check_task_recovery() port = tasks[0]['ports'][0] host = tasks[0]['host'] cmd = "curl {}:{}/data/foo".format(host, port) run, data = shakedown.run_command_on_master(cmd) assert run, "{} did not succeed".format(cmd) assert data == 'hello\nhello\n', "'{}' was not equal to hello\\nhello\\n".format(data)