def test_vip_mesos_cmd(marathon_service_name): """ Tests the creation of a VIP from a python command NOT in a docker. the test validates the creation of an app with the VIP label and the accessability of the service via the VIP. """ vip_name = 'vip-service' fqn = '{}.{}.l4lb.thisdcos.directory'.format(vip_name, marathon_service_name) app_def = python_http_app() app_def['portDefinitions'] = [ { "port": 0, "protocol": "tcp", "name": "{}".format(vip_name), "labels": { "VIP_0": "/{}:10000".format(vip_name) } } ] app_def['id'] = vip_name client = marathon.create_client() client.add_app(app_def) shakedown.deployment_wait() @retrying.retry def http_output_check(stop_max_attempt_number=30): common.assert_http_code('{}:{}'.format(fqn, 10000)) http_output_check()
def test_http_health_check_healthy(protocol): """ Test HTTP, MESOS_HTTP, TCP and MESOS_TCP with standard python server """ client = marathon.create_client() app_def = python_http_app() app_def['id'] = 'no-health' client.add_app(app_def) shakedown.deployment_wait() app = client.get_app('/no-health') assert app['tasksRunning'] == 1 assert app['tasksHealthy'] == 0 client.remove_app('/no-health') assert_app_healthy(client, app_def, health_check(protocol=protocol))
def test_health_failed_check(): """ Tests a health check of an app launched by marathon. The health check succeeded, then failed due to a network partition. """ client = marathon.create_client() app_def = python_http_app() health_list = [] health_list.append(health_check()) app_def['id'] = 'healthy' app_def['healthChecks'] = health_list pin_to_host(app_def, ip_other_than_mom()) client.add_app(app_def) shakedown.deployment_wait() # healthy app = client.get_app('/healthy') assert app['tasksRunning'] == 1 assert app['tasksHealthy'] == 1 tasks = client.get_tasks('/healthy') host = tasks[0]['host'] port = tasks[0]['ports'][0] # prefer to break at the agent (having issues) mom_ip = ip_of_mom() shakedown.save_iptables(host) block_port(host, port) time.sleep(7) restore_iptables(host) shakedown.deployment_wait() # after network failure is restored. The task returns and is a new task ID @retrying.retry(wait_fixed=1000, stop_max_delay=3000, retry_on_exception=ignore_on_exception) def check_health_message(): new_tasks = client.get_tasks('/healthy') assert new_tasks[0]['id'] != tasks[0]['id'] app = client.get_app('/healthy') assert app['tasksRunning'] == 1 assert app['tasksHealthy'] == 1 check_health_message()
def test_health_failed_check(): """ Tests a health check of an app launched by marathon. The health check succeeded, then failed due to a network partition. """ client = marathon.create_client() app_def = python_http_app() health_list = [] health_list.append(health_check()) app_def['id'] = 'healthy' app_def['healthChecks'] = health_list pin_to_host(app_def, ip_other_than_mom()) client.add_app(app_def) shakedown.deployment_wait() # healthy app = client.get_app('/healthy') assert app['tasksRunning'] == 1 assert app['tasksHealthy'] == 1 tasks = client.get_tasks('/healthy') host = tasks[0]['host'] port = tasks[0]['ports'][0] # prefer to break at the agent (having issues) mom_ip = ip_of_mom() shakedown.save_iptables(host) block_port(host, port) time.sleep(7) restore_iptables(host) shakedown.deployment_wait() # after network failure is restored. The task returns and is a new task ID @retrying.retry(wait_fixed=1000, stop_max_delay=3000) def check_health_message(): new_tasks = client.get_tasks('/healthy') assert new_tasks[0]['id'] != tasks[0]['id'] app = client.get_app('/healthy') assert app['tasksRunning'] == 1 assert app['tasksHealthy'] == 1 check_health_message()
def test_health_check_unhealthy(): """ Tests failed health checks of an app launched by marathon. This was a health check that never passed. """ client = marathon.create_client() app_def = python_http_app() health_list = [] health_list.append(health_check('/bad-url', failures=0, timeout=0)) app_def['id'] = 'unhealthy' app_def['healthChecks'] = health_list client.add_app(app_def) @retrying.retry(wait_fixed=1000, stop_max_delay=10000) def check_failure_message(): app = client.get_app('/unhealthy') assert app['tasksRunning'] == 1 and app['tasksHealthy'] == 0 and app['tasksUnhealthy'] == 1 check_failure_message()