def test_hostname_unique(): install.uninstall(PACKAGE_NAME) options = { "service": { "spec_file": "examples/marathon_constraint.yml" }, "hello": { "count": num_private_agents, "placement": "hostname:UNIQUE" }, "world": { "count": num_private_agents, "placement": "hostname:UNIQUE" } } install.install(PACKAGE_NAME, num_private_agents * 2, additional_options=options) # hello deploys first. One "world" task should end up placed with each "hello" task. plan.get_deployment_plan(PACKAGE_NAME) # ensure "hello" task can still be placed with "world" task cmd.run_cli('hello-world pods replace hello-0') tasks.check_running(PACKAGE_NAME, num_private_agents * 2 - 1, timeout_seconds=10) tasks.check_running(PACKAGE_NAME, num_private_agents * 2) ensure_multiple_per_agent(hello=1, world=1)
def test_joins_overlay_network(): """Verify that the container joined the dcos subnet at 9.0.0.0/24. The logic for this is in the task itself, which will check the container IP address and fail if incorrect, thus preventing the plan from reaching the COMPLETE state.""" spin.time_wait_noisy(lambda: ( plan.get_deployment_plan(PACKAGE_NAME).json()['status'] == 'COMPLETE'))
def test_deploy(): deployment_plan = plan.get_deployment_plan(PACKAGE_NAME).json() sdk_utils.out("deployment_plan: " + str(deployment_plan)) assert (len(deployment_plan['phases']) == 1) assert (deployment_plan['phases'][0]['name'] == 'hello') assert (len(deployment_plan['phases'][0]['steps']) == 1)
def test_joins_overlay_network(): """Verify that the container joined the dcos subnet at 9.0.0.0/24. The logic for this is in the task itself, which will check the container IP address and fail if incorrect, thus preventing the plan from reaching the COMPLETE state.""" spin.time_wait_noisy(lambda: (plan.get_deployment_plan(PACKAGE_NAME).json( )['status'] == 'COMPLETE'))
def test_deploy(): """Verify that the current deploy plan matches the expected plan from the spec.""" deployment_plan = plan.get_deployment_plan(PACKAGE_NAME).json() print("deployment_plan: " + str(deployment_plan)) assert(len(deployment_plan['phases']) == 1) assert(deployment_plan['phases'][0]['name'] == 'all-deploy') assert(len(deployment_plan['phases'][0]['steps']) == 2)
def test_deploy(): sdk_plan.wait_for_completed_deployment(config.SERVICE_NAME) deployment_plan = sdk_plan.get_deployment_plan(config.SERVICE_NAME) log.info(sdk_plan.plan_string("deploy", deployment_plan)) assert len(deployment_plan["phases"]) == 1 assert deployment_plan["phases"][0]["name"] == "hello" assert len(deployment_plan["phases"][0]["steps"]) == 1
def test_deploy(): plan.wait_for_completed_deployment(PACKAGE_NAME) deployment_plan = plan.get_deployment_plan(PACKAGE_NAME) sdk_utils.out("deployment_plan: " + str(deployment_plan)) assert (len(deployment_plan['phases']) == 1) assert (deployment_plan['phases'][0]['name'] == 'hello') assert (len(deployment_plan['phases'][0]['steps']) == 1)
def test_deploy(): """Verify that the current deploy plan matches the expected plan from the spec.""" deployment_plan = plan.get_deployment_plan(PACKAGE_NAME).json() print("deployment_plan: " + str(deployment_plan)) assert (len(deployment_plan['phases']) == 1) assert (deployment_plan['phases'][0]['name'] == 'all-deploy') assert (len(deployment_plan['phases'][0]['steps']) == 2)
def test_deploy(): sdk_plan.wait_for_completed_deployment(config.PACKAGE_NAME) deployment_plan = sdk_plan.get_deployment_plan(config.PACKAGE_NAME) log.info("deployment_plan: " + str(deployment_plan)) assert (len(deployment_plan['phases']) == 1) assert (deployment_plan['phases'][0]['name'] == 'hello') assert (len(deployment_plan['phases'][0]['steps']) == 1)
def test_deploy(): sdk_plan.wait_for_completed_deployment(config.SERVICE_NAME) deployment_plan = sdk_plan.get_deployment_plan(config.SERVICE_NAME) log.info("deployment_plan: " + str(deployment_plan)) assert(len(deployment_plan['phases']) == 1) assert(deployment_plan['phases'][0]['name'] == 'hello') assert(len(deployment_plan['phases'][0]['steps']) == 1)
def test_deploy(): deployment_plan = plan.get_deployment_plan(PACKAGE_NAME).json() print("deployment_plan: " + str(deployment_plan)) assert(len(deployment_plan['phases']) == 2) assert(deployment_plan['phases'][0]['name'] == 'server-deploy') assert(deployment_plan['phases'][1]['name'] == 'once-deploy') assert(len(deployment_plan['phases'][0]['steps']) == 2) assert(len(deployment_plan['phases'][1]['steps']) == 2)
def upgrade_or_downgrade(package_name, running_task_count): task_ids = tasks.get_task_ids(package_name, '') marathon.destroy_app(package_name) install.install(package_name, running_task_count) print('Waiting for upgrade / downgrade deployment to complete') spin.time_wait_noisy(lambda: ( plan.get_deployment_plan(package_name).json()['status'] == 'COMPLETE')) print('Checking that all tasks have restarted') tasks.check_tasks_updated(package_name, '', task_ids)
def test_deploy(): plan.wait_for_completed_deployment(PACKAGE_NAME) deployment_plan = plan.get_deployment_plan(PACKAGE_NAME).json() sdk_utils.out("deployment_plan: " + str(deployment_plan)) assert(len(deployment_plan['phases']) == 2) assert(deployment_plan['phases'][0]['name'] == 'server-deploy') assert(deployment_plan['phases'][1]['name'] == 'once-deploy') assert(len(deployment_plan['phases'][0]['steps']) == 2) assert(len(deployment_plan['phases'][1]['steps']) == 2)
def test_deploy(): sdk_plan.wait_for_completed_deployment(config.SERVICE_NAME) deployment_plan = sdk_plan.get_deployment_plan(config.SERVICE_NAME) log.info("deployment plan: " + str(deployment_plan)) assert (len(deployment_plan['phases']) == 2) assert (deployment_plan['phases'][0]['name'] == 'server-deploy') assert (deployment_plan['phases'][1]['name'] == 'once-deploy') assert (len(deployment_plan['phases'][0]['steps']) == 2) assert (len(deployment_plan['phases'][1]['steps']) == 2)
def test_task_dns_prefix_points_to_all_tasks(): pod_info = dcos.http.get( shakedown.dcos_service_url(PACKAGE_NAME) + "/v1/pods/{}/info".format("hello-0")).json() # Assert that DiscoveryInfo is correctly set on tasks. assert(all(p["info"]["discovery"]["name"] == "hello-0" for p in pod_info)) # Assert that the hello-0.hello-world.mesos DNS entry points to the right IP. spin.time_wait_noisy(lambda: ( plan.get_deployment_plan(PACKAGE_NAME).json()['status'] == 'COMPLETE'))
def test_deploy(): deployment_plan = sdk_plan.get_deployment_plan(config.SERVICE_NAME) log.info(sdk_plan.plan_string("deploy", deployment_plan)) assert len(deployment_plan["phases"]) == 3 assert deployment_plan["phases"][0]["name"] == "hello-deploy" assert deployment_plan["phases"][1]["name"] == "world-server-deploy" assert deployment_plan["phases"][2]["name"] == "world-once-deploy" assert len(deployment_plan["phases"][0]["steps"]) == 2 assert len(deployment_plan["phases"][1]["steps"]) == 1 assert len(deployment_plan["phases"][2]["steps"]) == 1
def test_deploy(): deployment_plan = sdk_plan.get_deployment_plan(config.SERVICE_NAME) log.info("deployment plan: " + str(deployment_plan)) assert (len(deployment_plan['phases']) == 3) assert (deployment_plan['phases'][0]['name'] == 'hello-deploy') assert (deployment_plan['phases'][1]['name'] == 'world-server-deploy') assert (deployment_plan['phases'][2]['name'] == 'world-once-deploy') assert (len(deployment_plan['phases'][0]['steps']) == 2) assert (len(deployment_plan['phases'][1]['steps']) == 1) assert (len(deployment_plan['phases'][2]['steps']) == 1)
def test_deploy(): deployment_plan = plan.get_deployment_plan(PACKAGE_NAME) sdk_utils.out("deployment plan: " + str(deployment_plan)) assert(len(deployment_plan['phases']) == 3) assert(deployment_plan['phases'][0]['name'] == 'hello-deploy') assert(deployment_plan['phases'][1]['name'] == 'world-server-deploy') assert(deployment_plan['phases'][2]['name'] == 'world-once-deploy') assert(len(deployment_plan['phases'][0]['steps']) == 2) assert(len(deployment_plan['phases'][1]['steps']) == 1) assert(len(deployment_plan['phases'][2]['steps']) == 1)
def test_deploy(): deployment_plan = sdk_plan.get_deployment_plan(config.SERVICE_NAME) log.info("deployment plan: " + str(deployment_plan)) assert(len(deployment_plan['phases']) == 3) assert(deployment_plan['phases'][0]['name'] == 'hello-deploy') assert(deployment_plan['phases'][1]['name'] == 'world-server-deploy') assert(deployment_plan['phases'][2]['name'] == 'world-once-deploy') assert(len(deployment_plan['phases'][0]['steps']) == 2) assert(len(deployment_plan['phases'][1]['steps']) == 1) assert(len(deployment_plan['phases'][2]['steps']) == 1)
def test_cluster(): install.uninstall(PACKAGE_NAME) some_agent = shakedown.get_private_agents().pop() options = { "service": { "spec_file": "examples/marathon_constraint.yml" }, "hello": { "count": num_private_agents, "placement": "hostname:CLUSTER:{}".format(some_agent) }, "world": { "count": 0 } } install.install(PACKAGE_NAME, num_private_agents, additional_options=options) plan.get_deployment_plan(PACKAGE_NAME) ensure_multiple_per_agent(hello=num_private_agents, world=0)
def test_overlay_network(): """Verify that the current deploy plan matches the expected plan from the spec.""" def check_task_network(task_name, on_overlay, expected_network_name="dcos"): _task = shakedown.get_task(task_id=task_name, completed=False) for status in _task["statuses"]: if status["state"] == "TASK_RUNNING": for network_info in status["container_status"][ "network_infos"]: if on_overlay: assert "name" in network_info, \ "Didn't find network name in NetworkInfo for task {task} with "\ "status:{status}".format(task=task_name, status=status) assert network_info["name"] == expected_network_name, \ "Expected network name:{expected} found:{observed}"\ .format(expected=expected_network_name, observed=network_info["name"]) else: assert "name" not in network_info, \ "Task {task} has network name when it shouldn't has status:{status}"\ .format(task=task_name, status=status) plan.wait_for_completed_deployment(PACKAGE_NAME) deployment_plan = plan.get_deployment_plan(PACKAGE_NAME).json() utils.out("deployment_plan: " + str(deployment_plan)) # test that the deployment plan is correct assert (len(deployment_plan['phases']) == 3) assert (deployment_plan['phases'][0]['name'] == 'hello-overlay-deploy') assert (deployment_plan['phases'][1]['name'] == 'hello-host-deploy') assert (deployment_plan["phases"][2]["name"] == "getter-deploy") assert (len(deployment_plan['phases'][0]['steps']) == 1) assert (len(deployment_plan["phases"][1]["steps"]) == 1) assert (len(deployment_plan["phases"][2]["steps"]) == 2) # test that the tasks are all up, which tests the overlay DNS framework_tasks = [ task["name"] for task in shakedown.get_service_tasks(PACKAGE_NAME, completed=False) ] expected_tasks = [ 'getter-0-get-host', 'getter-0-get-overlay', 'hello-host-0-server', 'hello-overlay-0-server' ] for expected_task in expected_tasks: assert (expected_task in framework_tasks), "Missing {expected}".format( expected=expected_task) check_task_network("getter-0-get-host", True) check_task_network("getter-0-get-overlay", True) check_task_network("hello-overlay-0-server", True) check_task_network("hello-host-0-server", False)
def test_max_per_hostname(): install.uninstall(PACKAGE_NAME) options = { "service": { "spec_file": "examples/marathon_constraint.yml" }, "hello": { "count": num_private_agents * 2, "placement": "hostname:MAX_PER:2" }, "world": { "count": num_private_agents * 3, "placement": "hostname:MAX_PER:3" } } install.install(PACKAGE_NAME, num_private_agents * 5, additional_options=options) plan.get_deployment_plan(PACKAGE_NAME) ensure_multiple_per_agent(hello=2, world=3)
def test_rr_by_hostname(): install.uninstall(PACKAGE_NAME) options = { "service": { "spec_file": "examples/marathon_constraint.yml" }, "hello": { "count": num_private_agents * 2, "placement": "hostname:GROUP_BY:{}".format(num_private_agents) }, "world": { "count": num_private_agents * 2, "placement": "hostname:GROUP_BY:{}".format(num_private_agents) } } install.install(PACKAGE_NAME, num_private_agents * 4, additional_options=options) plan.get_deployment_plan(PACKAGE_NAME) ensure_multiple_per_agent(hello=2, world=2)
def test_custom_plan(): sdk_install.install( config.PACKAGE_NAME, config.SERVICE_NAME, 3, additional_options={"service": {"scenario": "CUSTOM_PLAN"}}, ) plan = sdk_plan.get_deployment_plan(config.SERVICE_NAME) world_steps = plan["phases"][1]["steps"] assert world_steps[0]["name"] == "world-1:[server]" assert world_steps[1]["name"] == "world-0:[server]"
def test_deploy(): """Verify that the current deploy plan matches the expected plan from the spec.""" deployment_plan = plan.get_deployment_plan(PACKAGE_NAME).json() utils.out("deployment_plan: " + str(deployment_plan)) # deploy two pods serially assert (len(deployment_plan['phases']) == 2) assert (deployment_plan['phases'][0]['name'] == 'hello-deploy') assert (deployment_plan["phases"][1]["name"] == "world-deploy") # they both have two steps, network-task and server assert (len(deployment_plan['phases'][0]['steps']) == 2) assert (len(deployment_plan["phases"][1]["steps"]) == 2)
def test_custom_plan(): sdk_install.install( config.PACKAGE_NAME, config.SERVICE_NAME, 3, additional_options={"service": {"customize_plan": True}}) plan = sdk_plan.get_deployment_plan(config.SERVICE_NAME) world_steps = plan['phases'][1]['steps'] assert world_steps[0]['name'] == 'world-1:[server]' assert world_steps[1]['name'] == 'world-0:[server]' sdk_install.uninstall(config.PACKAGE_NAME, config.SERVICE_NAME)
def test_custom_plan(): sdk_install.install( config.PACKAGE_NAME, config.SERVICE_NAME, 3, additional_options={"service": {"scenario": "CUSTOM_PLAN"}}) plan = sdk_plan.get_deployment_plan(config.SERVICE_NAME) world_steps = plan['phases'][1]['steps'] assert world_steps[0]['name'] == 'world-1:[server]' assert world_steps[1]['name'] == 'world-0:[server]' sdk_install.uninstall(config.PACKAGE_NAME, config.SERVICE_NAME)
def test_canary_second(): sdk_cmd.svc_cli(config.PACKAGE_NAME, config.SERVICE_NAME, "plan continue deploy world-deploy") sdk_plan.wait_for_step_status(config.SERVICE_NAME, "deploy", "world-deploy", "world-0:[server]", "PENDING") # because the plan strategy is serial, the second phase just clears a wait bit without # proceeding to launch anything: expected_tasks = ["hello-0"] try: sdk_tasks.check_running(config.SERVICE_NAME, len(expected_tasks) + 1, timeout_seconds=30) assert False, "Shouldn't have deployed a second task" except AssertionError as arg: raise arg except Exception: pass # expected sdk_tasks.check_running(config.SERVICE_NAME, len(expected_tasks)) rc, stdout, _ = sdk_cmd.svc_cli(config.PACKAGE_NAME, config.SERVICE_NAME, "pod list") assert rc == 0, "Pod list failed" assert json.loads(stdout) == expected_tasks pl = sdk_plan.get_deployment_plan(config.SERVICE_NAME) log.info(pl) assert pl["status"] == "WAITING" assert len(pl["phases"]) == 2 phase = pl["phases"][0] assert phase["status"] == "WAITING" steps = phase["steps"] assert len(steps) == 4 assert steps[0]["status"] == "COMPLETE" assert steps[1]["status"] == "WAITING" assert steps[2]["status"] == "PENDING" assert steps[3]["status"] == "PENDING" phase = pl["phases"][1] assert phase["status"] == "PENDING" steps2 = phase["steps"] assert len(steps) == 4 assert steps2[0]["status"] == "PENDING" assert steps2[1]["status"] == "WAITING" assert steps2[2]["status"] == "PENDING" assert steps2[3]["status"] == "PENDING"
def test_canary_second(): sdk_cmd.svc_cli(config.PACKAGE_NAME, config.SERVICE_NAME, 'plan continue deploy world-deploy') sdk_plan.wait_for_step_status(config.SERVICE_NAME, 'deploy', 'world-deploy', 'world-0:[server]', 'PENDING') # because the plan strategy is serial, the second phase just clears a wait bit without # proceeding to launch anything: expected_tasks = ['hello-0'] try: sdk_tasks.check_running(config.SERVICE_NAME, len(expected_tasks) + 1, timeout_seconds=30) assert False, "Shouldn't have deployed a second task" except AssertionError as arg: raise arg except: pass # expected sdk_tasks.check_running(config.SERVICE_NAME, len(expected_tasks)) assert sdk_cmd.svc_cli(config.PACKAGE_NAME, config.SERVICE_NAME, 'pod list', json=True) == expected_tasks pl = sdk_plan.get_deployment_plan(config.SERVICE_NAME) log.info(pl) assert pl['status'] == 'WAITING' assert len(pl['phases']) == 2 phase = pl['phases'][0] assert phase['status'] == 'WAITING' steps = phase['steps'] assert len(steps) == 4 assert steps[0]['status'] == 'COMPLETE' assert steps[1]['status'] == 'WAITING' assert steps[2]['status'] == 'PENDING' assert steps[3]['status'] == 'PENDING' phase = pl['phases'][1] assert phase['status'] == 'PENDING' steps2 = phase['steps'] assert len(steps) == 4 assert steps2[0]['status'] == 'PENDING' assert steps2[1]['status'] == 'WAITING' assert steps2[2]['status'] == 'PENDING' assert steps2[3]['status'] == 'PENDING'
def test_rack_not_found(): options = _escape_placement_for_1_9({ "service": { "yaml": "marathon_constraint" }, "hello": { "placement": '[["rack_id", "LIKE", "rack-foo-.*"]]' }, "world": { "placement": '[["rack_id", "LIKE", "rack-foo-.*"]]' }, }) # scheduler should fail to deploy, don't wait for it to complete: sdk_install.install( config.PACKAGE_NAME, config.SERVICE_NAME, 0, additional_options=options, wait_for_deployment=False, ) try: sdk_tasks.check_running(config.SERVICE_NAME, 1, timeout_seconds=60) assert False, "Should have failed to deploy anything" except AssertionError as arg: raise arg except Exception: pass # expected to fail pl = sdk_plan.get_deployment_plan(config.SERVICE_NAME) # check that everything is still stuck looking for a match: assert pl["status"] == "IN_PROGRESS" assert len(pl["phases"]) == 2 phase1 = pl["phases"][0] assert phase1["status"] == "IN_PROGRESS" steps1 = phase1["steps"] assert len(steps1) == 1 assert steps1[0]["status"] in ("PREPARED", "PENDING" ) # first step may be PREPARED phase2 = pl["phases"][1] assert phase2["status"] == "PENDING" steps2 = phase2["steps"] assert len(steps2) == 2 assert steps2[0]["status"] == "PENDING" assert steps2[1]["status"] == "PENDING" sdk_install.uninstall(config.PACKAGE_NAME, config.SERVICE_NAME)
def test_custom_plan(): sdk_install.install( config.PACKAGE_NAME, config.SERVICE_NAME, 3, additional_options={"service": { "scenario": "CUSTOM_PLAN" }}, ) plan = sdk_plan.get_deployment_plan(config.SERVICE_NAME) world_steps = plan["phases"][1]["steps"] assert world_steps[0]["name"] == "world-1:[server]" assert world_steps[1]["name"] == "world-0:[server]"
def test_rack_not_found(): options = { 'service': { 'spec_file': 'examples/marathon_constraint.yml' }, 'hello': { 'placement': 'rack_id:LIKE:rack-foo-.*' }, 'world': { 'placement': 'rack_id:LIKE:rack-foo-.*' } } # scheduler should fail to deploy, don't wait for it to complete: sdk_install.install(config.PACKAGE_NAME, config.SERVICE_NAME, 0, additional_options=options, wait_for_deployment=False) try: sdk_tasks.check_running(config.SERVICE_NAME, 1, timeout_seconds=60) assert False, "Should have failed to deploy anything" except AssertionError as arg: raise arg except: pass # expected to fail pl = sdk_plan.get_deployment_plan(config.SERVICE_NAME) # check that everything is still stuck looking for a match: assert pl['status'] == 'IN_PROGRESS' assert len(pl['phases']) == 2 phase1 = pl['phases'][0] assert phase1['status'] == 'IN_PROGRESS' steps1 = phase1['steps'] assert len(steps1) == 1 assert steps1[0]['status'] in ('PREPARED', 'PENDING' ) # first step may be PREPARED phase2 = pl['phases'][1] assert phase2['status'] == 'PENDING' steps2 = phase2['steps'] assert len(steps2) == 2 assert steps2[0]['status'] == 'PENDING' assert steps2[1]['status'] == 'PENDING' sdk_install.uninstall(config.PACKAGE_NAME, config.SERVICE_NAME)
def test_canary_second(): sdk_cmd.svc_cli(config.PACKAGE_NAME, config.SERVICE_NAME, "plan continue deploy world-deploy") sdk_plan.wait_for_step_status( config.SERVICE_NAME, "deploy", "world-deploy", "world-0:[server]", "PENDING" ) # because the plan strategy is serial, the second phase just clears a wait bit without # proceeding to launch anything: expected_tasks = ["hello-0"] try: sdk_tasks.check_running(config.SERVICE_NAME, len(expected_tasks) + 1, timeout_seconds=30) assert False, "Shouldn't have deployed a second task" except AssertionError as arg: raise arg except Exception: pass # expected sdk_tasks.check_running(config.SERVICE_NAME, len(expected_tasks)) rc, stdout, _ = sdk_cmd.svc_cli(config.PACKAGE_NAME, config.SERVICE_NAME, "pod list") assert rc == 0, "Pod list failed" assert json.loads(stdout) == expected_tasks pl = sdk_plan.get_deployment_plan(config.SERVICE_NAME) log.info(pl) assert pl["status"] == "WAITING" assert len(pl["phases"]) == 2 phase = pl["phases"][0] assert phase["status"] == "WAITING" steps = phase["steps"] assert len(steps) == 4 assert steps[0]["status"] == "COMPLETE" assert steps[1]["status"] == "WAITING" assert steps[2]["status"] == "PENDING" assert steps[3]["status"] == "PENDING" phase = pl["phases"][1] assert phase["status"] == "PENDING" steps2 = phase["steps"] assert len(steps) == 4 assert steps2[0]["status"] == "PENDING" assert steps2[1]["status"] == "WAITING" assert steps2[2]["status"] == "PENDING" assert steps2[3]["status"] == "PENDING"
def fail_placement(options): """ This assumes that the DC/OS cluster is reporting that all agents are in a single zone. """ # scheduler should fail to deploy, don't wait for it to complete: sdk_install.install( config.PACKAGE_NAME, config.SERVICE_NAME, 0, additional_options=options, wait_for_deployment=False, ) sdk_plan.wait_for_step_status(config.SERVICE_NAME, "deploy", "world", "world-0:[server]", "COMPLETE") pl = sdk_plan.get_deployment_plan(config.SERVICE_NAME) # check that everything is still stuck looking for a match: assert pl["status"] == "IN_PROGRESS" assert len(pl["phases"]) == 2 phase1 = pl["phases"][0] assert phase1["status"] == "COMPLETE" steps1 = phase1["steps"] assert len(steps1) == 1 phase2 = pl["phases"][1] assert phase2["status"] == "IN_PROGRESS" steps2 = phase2["steps"] assert len(steps2) == 3 assert steps2[0]["status"] == "COMPLETE" assert steps2[1]["status"] in ("COMPLETE", "PREPARED", "PENDING") assert steps2[2]["status"] in ("PREPARED", "PENDING") try: sdk_tasks.check_running(config.SERVICE_NAME, 4, timeout_seconds=30) assert False, "Should have failed to deploy world-2" except AssertionError as arg: raise arg except Exception: pass # expected to fail sdk_install.uninstall(config.PACKAGE_NAME, config.SERVICE_NAME)
def test_rack_not_found(): options = _escape_placement_for_1_9( { "service": {"yaml": "marathon_constraint"}, "hello": {"placement": '[["rack_id", "LIKE", "rack-foo-.*"]]'}, "world": {"placement": '[["rack_id", "LIKE", "rack-foo-.*"]]'}, } ) # scheduler should fail to deploy, don't wait for it to complete: sdk_install.install( config.PACKAGE_NAME, config.SERVICE_NAME, 0, additional_options=options, wait_for_deployment=False, ) try: sdk_tasks.check_running(config.SERVICE_NAME, 1, timeout_seconds=60) assert False, "Should have failed to deploy anything" except AssertionError as arg: raise arg except Exception: pass # expected to fail pl = sdk_plan.get_deployment_plan(config.SERVICE_NAME) # check that everything is still stuck looking for a match: assert pl["status"] == "IN_PROGRESS" assert len(pl["phases"]) == 2 phase1 = pl["phases"][0] assert phase1["status"] == "IN_PROGRESS" steps1 = phase1["steps"] assert len(steps1) == 1 assert steps1[0]["status"] in ("PREPARED", "PENDING") # first step may be PREPARED phase2 = pl["phases"][1] assert phase2["status"] == "PENDING" steps2 = phase2["steps"] assert len(steps2) == 2 assert steps2[0]["status"] == "PENDING" assert steps2[1]["status"] == "PENDING" sdk_install.uninstall(config.PACKAGE_NAME, config.SERVICE_NAME)
def fail_placement(options): """ This assumes that the DC/OS cluster is reporting that all agents are in a single zone. """ # scheduler should fail to deploy, don't wait for it to complete: sdk_install.install( config.PACKAGE_NAME, config.SERVICE_NAME, 0, additional_options=options, wait_for_deployment=False, ) sdk_plan.wait_for_step_status( config.SERVICE_NAME, "deploy", "world", "world-0:[server]", "COMPLETE" ) pl = sdk_plan.get_deployment_plan(config.SERVICE_NAME) # check that everything is still stuck looking for a match: assert pl["status"] == "IN_PROGRESS" assert len(pl["phases"]) == 2 phase1 = pl["phases"][0] assert phase1["status"] == "COMPLETE" steps1 = phase1["steps"] assert len(steps1) == 1 phase2 = pl["phases"][1] assert phase2["status"] == "IN_PROGRESS" steps2 = phase2["steps"] assert len(steps2) == 2 assert steps2[0]["status"] == "COMPLETE" assert steps2[1]["status"] in ("PREPARED", "PENDING") try: sdk_tasks.check_running(config.SERVICE_NAME, 3, timeout_seconds=30) assert False, "Should have failed to deploy world-1" except AssertionError as arg: raise arg except Exception: pass # expected to fail sdk_install.uninstall(config.PACKAGE_NAME, config.SERVICE_NAME)
def test_tmp_directory_created(): sdk_install.install( config.PACKAGE_NAME, config.SERVICE_NAME, 0, additional_options={"service": {"name": config.SERVICE_NAME, "yaml": "isolation"}}, wait_for_deployment=False) pl = sdk_plan.get_deployment_plan(config.SERVICE_NAME) assert pl['status'] != 'COMPLETE' marathon_config = sdk_marathon.get_config(config.SERVICE_NAME) marathon_config['env']['HELLO_ISOLATION'] = 'true' sdk_marathon.update_app(config.SERVICE_NAME, marathon_config) sdk_plan.wait_for_completed_deployment(config.SERVICE_NAME)
def test_rack_not_found(): options = { 'service': { 'spec_file': 'examples/marathon_constraint.yml' }, 'hello': { 'placement': 'rack_id:LIKE:rack-foo-.*' }, 'world': { 'placement': 'rack_id:LIKE:rack-foo-.*' } } # scheduler should fail to deploy, don't wait for it to complete: sdk_install.install(config.PACKAGE_NAME, config.SERVICE_NAME, 0, additional_options=options, wait_for_deployment=False) try: sdk_tasks.check_running(config.SERVICE_NAME, 1, timeout_seconds=60) assert False, "Should have failed to deploy anything" except AssertionError as arg: raise arg except: pass # expected to fail pl = sdk_plan.get_deployment_plan(config.SERVICE_NAME) # check that everything is still stuck looking for a match: assert pl['status'] == 'IN_PROGRESS' assert len(pl['phases']) == 2 phase1 = pl['phases'][0] assert phase1['status'] == 'IN_PROGRESS' steps1 = phase1['steps'] assert len(steps1) == 1 assert steps1[0]['status'] in ('PREPARED', 'PENDING') # first step may be PREPARED phase2 = pl['phases'][1] assert phase2['status'] == 'PENDING' steps2 = phase2['steps'] assert len(steps2) == 2 assert steps2[0]['status'] == 'PENDING' assert steps2[1]['status'] == 'PENDING' sdk_install.uninstall(config.PACKAGE_NAME, config.SERVICE_NAME)
def fail_placement(options): """ This assumes that the DC/OS cluster is reporting that all agents are in a single zone. """ # scheduler should fail to deploy, don't wait for it to complete: sdk_install.install(config.PACKAGE_NAME, config.SERVICE_NAME, 0, additional_options=options, wait_for_deployment=False) sdk_plan.wait_for_step_status(config.SERVICE_NAME, 'deploy', 'world', 'world-0:[server]', 'COMPLETE') pl = sdk_plan.get_deployment_plan(config.SERVICE_NAME) # check that everything is still stuck looking for a match: assert pl['status'] == 'IN_PROGRESS' assert len(pl['phases']) == 2 phase1 = pl['phases'][0] assert phase1['status'] == 'COMPLETE' steps1 = phase1['steps'] assert len(steps1) == 1 phase2 = pl['phases'][1] assert phase2['status'] == 'IN_PROGRESS' steps2 = phase2['steps'] assert len(steps2) == 2 assert steps2[0]['status'] == 'COMPLETE' assert steps2[1]['status'] in ('PREPARED', 'PENDING') try: sdk_tasks.check_running(config.SERVICE_NAME, 3, timeout_seconds=30) assert False, "Should have failed to deploy world-1" except AssertionError as arg: raise arg except: pass # expected to fail sdk_install.uninstall(config.PACKAGE_NAME, config.SERVICE_NAME)
def test_plan(): plan.get_deployment_plan(PACKAGE_NAME)