コード例 #1
0
async def test_event_channel_for_pods(sse_events):
    """Tests the Marathon event channel specific to pod events."""

    await common.assert_event('event_stream_attached', sse_events)

    pod_def = pods.simple_pod()
    pod_id = pod_def['id']

    # In strict mode all tasks are started as user `nobody` by default and `nobody`
    # doesn't have permissions to write files.
    if shakedown.ee_version() == 'strict':
        pod_def['user'] = '******'
        common.add_dcos_marathon_user_acls()

    client = marathon.create_client()
    client.add_pod(pod_def)
    common.deployment_wait(service_id=pod_id)

    await common.assert_event('pod_created_event', sse_events)
    await common.assert_event('deployment_step_success', sse_events)

    pod_def["scaling"]["instances"] = 3
    client.update_pod(pod_id, pod_def)
    common.deployment_wait(service_id=pod_id)

    await common.assert_event('pod_updated_event', sse_events)
コード例 #2
0
def test_event_channel_for_pods():
    """Tests the Marathon event channel specific to pod events."""

    pod_def = pods.simple_pod()

    client = marathon.create_client()
    client.add_pod(pod_def)
    shakedown.deployment_wait()

    # look for created
    @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_on_master('cat events.txt')
        assert 'event_stream_attached' in stdout, "event_stream_attached event has not been produced"
        assert 'pod_created_event' in stdout, "pod_created_event event has not been produced"
        assert 'deployment_step_success' in stdout, "deployment_step_success event has not beed produced"

    check_deployment_message()

    pod_def["scaling"]["instances"] = 3
    client.update_pod(pod_def["id"], pod_def)
    shakedown.deployment_wait()

    # look for updated
    @retrying.retry(wait_fixed=1000,
                    stop_max_attempt_number=30,
                    retry_on_exception=common.ignore_exception)
    def check_update_message():
        status, stdout = shakedown.run_command_on_master('cat events.txt')
        assert 'pod_updated_event' in stdout, 'pod_update_event event has not been produced'

    check_update_message()
コード例 #3
0
def test_create_and_update_pod():
    """Versions and reverting with pods"""

    pod_def = pods.simple_pod()
    pod_def["scaling"]["instances"] = 1
    pod_id = pod_def['id']

    client = marathon.create_client()
    client.add_pod(pod_def)
    common.deployment_wait(service_id=pod_id)

    pod_def["scaling"]["instances"] = 3
    client.update_pod(pod_id, pod_def)
    common.deployment_wait(service_id=pod_id)

    versions = get_pod_versions(pod_id)
    assert len(
        versions
    ) == 2, "The number of versions is {}, but 2 was expected".format(
        len(versions))

    version1 = get_pod_version(pod_id, versions[0])
    version2 = get_pod_version(pod_id, versions[1])
    assert version1["scaling"]["instances"] != version2["scaling"]["instances"], \
        "Two pod versions have the same number of instances: {}, but they should not".format(
            version1["scaling"]["instances"])
コード例 #4
0
def test_pod_restarts_on_nonzero_exit_code():
    """Verifies that a pod get restarted in case one of its containers exits with a non-zero code.
       As a result, after restart, there should be two new tasks for different IDs.
    """

    pod_def = pods.simple_pod()
    pod_id = pod_def['id']
    pod_def["scaling"]["instances"] = 1
    pod_def['containers'][0]['exec']['command'][
        'shell'] = 'sleep 5; echo -n leaving; exit 2'

    client = marathon.create_client()
    client.add_pod(pod_def)
    common.deployment_wait(service_id=pod_id)

    tasks = common.get_pod_tasks(pod_id)
    initial_id1 = tasks[0]['id']
    initial_id2 = tasks[1]['id']

    time.sleep(
        6)  # 1 sec past the 5 sec sleep in one of the container's command
    tasks = common.get_pod_tasks(pod_id)
    for task in tasks:
        assert task['id'] != initial_id1, "Got the same task ID"
        assert task['id'] != initial_id2, "Got the same task ID"
コード例 #5
0
async def test_event_channel_for_pods(sse_events):
    """Tests the Marathon event channel specific to pod events."""

    await common.assert_event('event_stream_attached', sse_events)

    pod_def = pods.simple_pod()
    pod_id = pod_def['id']

    # In strict mode all tasks are started as user `nobody` by default and `nobody`
    # doesn't have permissions to write files.
    if shakedown.ee_version() == 'strict':
        pod_def['user'] = '******'
        common.add_dcos_marathon_user_acls()

    client = marathon.create_client()
    client.add_pod(pod_def)
    common.deployment_wait(service_id=pod_id)

    await common.assert_event('pod_created_event', sse_events)
    await common.assert_event('deployment_step_success', sse_events)

    pod_def["scaling"]["instances"] = 3
    client.update_pod(pod_id, pod_def)
    common.deployment_wait(service_id=pod_id)

    await common.assert_event('pod_updated_event', sse_events)
コード例 #6
0
def test_create_pod():
    """Launch simple pod in DC/OS root marathon."""

    pod_def = pods.simple_pod()

    client = marathon.create_client()
    client.add_pod(pod_def)
    shakedown.deployment_wait()

    pod = client.show_pod(pod_def["id"])
    assert pod is not None, "The pod has not been created"
コード例 #7
0
def test_create_pod():
    """Launch simple pod in DC/OS root marathon."""

    pod_def = pods.simple_pod()
    pod_id = pod_def['id']

    client = marathon.create_client()
    client.add_pod(pod_def)
    common.deployment_wait(service_id=pod_id)

    pod = client.show_pod(pod_id)
    assert pod is not None, "The pod has not been created"
コード例 #8
0
def test_create_pod():
    """Launch simple pod in DC/OS root marathon."""

    pod_def = pods.simple_pod()
    pod_id = pod_def['id']

    client = marathon.create_client()
    client.add_pod(pod_def)
    common.deployment_wait(service_id=pod_id)

    pod = client.show_pod(pod_id)
    assert pod is not None, "The pod has not been created"
コード例 #9
0
def test_multi_instance_pod():
    """Launches a pod with multiple instances."""

    pod_def = pods.simple_pod()
    pod_def["scaling"]["instances"] = 10

    client = marathon.create_client()
    client.add_pod(pod_def)
    shakedown.deployment_wait()

    status = get_pod_status(pod_def["id"])
    assert len(status["instances"]) == 10, \
        "The number of instances is {}, but 10 was expected".format(len(status["instances"]))
コード例 #10
0
def test_multi_instance_pod():
    """Launches a pod with multiple instances."""

    pod_def = pods.simple_pod()
    pod_id = pod_def['id']
    pod_def["scaling"]["instances"] = 3

    client = marathon.create_client()
    client.add_pod(pod_def)
    common.deployment_wait(service_id=pod_id)

    status = get_pod_status(pod_id)
    assert len(status["instances"]) == 3, \
        "The number of instances is {}, but 3 was expected".format(len(status["instances"]))
コード例 #11
0
def test_multi_instance_pod():
    """Launches a pod with multiple instances."""

    pod_def = pods.simple_pod()
    pod_id = pod_def['id']
    pod_def["scaling"]["instances"] = 3

    client = marathon.create_client()
    client.add_pod(pod_def)
    common.deployment_wait(service_id=pod_id)

    status = get_pod_status(pod_id)
    assert len(status["instances"]) == 3, \
        "The number of instances is {}, but 3 was expected".format(len(status["instances"]))
コード例 #12
0
def test_event_channel_for_pods():
    """Tests the Marathon event channel specific to pod events."""

    pod_def = pods.simple_pod()
    pod_id = pod_def['id']

    # In strict mode all tasks are started as user `nobody` by default and `nobody`
    # doesn't have permissions to write files.
    if shakedown.ee_version() == 'strict':
        pod_def['user'] = '******'
        common.add_dcos_marathon_user_acls()

    client = marathon.create_client()
    client.add_pod(pod_def)
    common.deployment_wait(service_id=pod_id)

    leader_ip = shakedown.marathon_leader_ip()

    # look for created
    @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(leader_ip,
                                               'cat events.exitcode')
        assert str(stdout).strip(
        ) == '', "SSE stream disconnected (CURL exit code is {})".format(
            stdout.strip())
        status, stdout = shakedown.run_command(leader_ip, 'cat events.txt')
        assert 'event_stream_attached' in stdout, "event_stream_attached event has not been produced"
        assert 'pod_created_event' in stdout, "pod_created_event event has not been produced"
        assert 'deployment_step_success' in stdout, "deployment_step_success event has not beed produced"

    check_deployment_message()

    pod_def["scaling"]["instances"] = 3
    client.update_pod(pod_id, pod_def)
    common.deployment_wait(service_id=pod_id)

    # look for updated
    @retrying.retry(wait_fixed=1000,
                    stop_max_attempt_number=30,
                    retry_on_exception=common.ignore_exception)
    def check_update_message():
        status, stdout = shakedown.run_command(leader_ip, 'cat events.txt')
        assert 'pod_updated_event' in stdout, 'pod_update_event event has not been produced'

    check_update_message()
コード例 #13
0
def test_remove_pod():
    """Launches a pod and then removes it."""

    pod_def = pods.simple_pod()

    client = marathon.create_client()
    client.add_pod(pod_def)
    shakedown.deployment_wait()

    client.remove_pod(pod_def["id"])
    shakedown.deployment_wait()

    try:
        _ = client.show_pod(pod_def["id"])
    except:
        pass
    else:
        assert False, "The pod has not been removed"
コード例 #14
0
def test_remove_pod():
    """Launches a pod and then removes it."""

    pod_def = pods.simple_pod()
    pod_id = pod_def['id']

    client = marathon.create_client()
    client.add_pod(pod_def)
    common.deployment_wait(service_id=pod_id)

    client.remove_pod(pod_id)
    common.deployment_wait(service_id=pod_id)

    try:
        client.show_pod(pod_id)
    except Exception:
        pass
    else:
        assert False, "The pod has not been removed"
コード例 #15
0
def test_remove_pod():
    """Launches a pod and then removes it."""

    pod_def = pods.simple_pod()
    pod_id = pod_def['id']

    client = marathon.create_client()
    client.add_pod(pod_def)
    deployment_wait(service_id=pod_id)

    client.remove_pod(pod_id)
    deployment_wait(service_id=pod_id)

    try:
        client.show_pod(pod_id)
    except requests.HTTPError as e:
        assert e.response.status_code == 404
    else:
        assert False, "The pod has not been removed"
コード例 #16
0
def test_remove_pod():
    """Launches a pod and then removes it."""

    pod_def = pods.simple_pod()
    pod_id = pod_def['id']

    client = marathon.create_client()
    client.add_pod(pod_def)
    common.deployment_wait(service_id=pod_id)

    client.remove_pod(pod_id)
    common.deployment_wait(service_id=pod_id)

    try:
        _ = client.show_pod(pod_id)
    except:
        pass
    else:
        assert False, "The pod has not been removed"
コード例 #17
0
def test_remove_pod():
    """Launches a pod and then removes it."""

    pod_def = pods.simple_pod()
    pod_id = pod_def['id']

    client = marathon.create_client()
    client.add_pod(pod_def)
    deployment_wait(service_id=pod_id)

    client.remove_pod(pod_id)
    deployment_wait(service_id=pod_id)

    try:
        client.show_pod(pod_id)
    except requests.HTTPError as e:
        assert e.response.status_code == 404
    else:
        assert False, "The pod has not been removed"
コード例 #18
0
def test_scale_down_pod():
    """Scales down a pod from 10 to 1 instance."""

    pod_def = pods.simple_pod()
    pod_def["scaling"]["instances"] = 10

    client = marathon.create_client()
    client.add_pod(pod_def)
    shakedown.deployment_wait()

    status = get_pod_status(pod_def["id"])
    assert len(status["instances"]) == 10, \
        "The number of instances is {}, but 10 was expected".format(len(status["instances"]))

    pod_def["scaling"]["instances"] = 1
    client.update_pod(pod_def["id"], pod_def)
    shakedown.deployment_wait()

    status = get_pod_status(pod_def["id"])
    assert len(status["instances"]) == 1, \
        "The number of instances is {}, but 1 was expected".format(len(status["instances"]))
コード例 #19
0
def test_scale_down_pod():
    """Scales down a pod from 3 to 1 instance."""

    pod_def = pods.simple_pod()
    pod_def["scaling"]["instances"] = 3
    pod_id = pod_def['id']

    client = marathon.create_client()
    client.add_pod(pod_def)
    common.deployment_wait(service_id=pod_id)

    status = get_pod_status(pod_id)
    assert len(status["instances"]) == 3, \
        "The number of instances is {}, but 3 was expected".format(len(status["instances"]))

    pod_def["scaling"]["instances"] = 1
    client.update_pod(pod_id, pod_def)
    common.deployment_wait(service_id=pod_id)

    status = get_pod_status(pod_id)
    assert len(status["instances"]) == 1, \
        "The number of instances is {}, but 1 was expected".format(len(status["instances"]))
コード例 #20
0
def test_scale_down_pod():
    """Scales down a pod from 3 to 1 instance."""

    pod_def = pods.simple_pod()
    pod_def["scaling"]["instances"] = 3
    pod_id = pod_def['id']

    client = marathon.create_client()
    client.add_pod(pod_def)
    common.deployment_wait(service_id=pod_id)

    status = get_pod_status(pod_id)
    assert len(status["instances"]) == 3, \
        "The number of instances is {}, but 3 was expected".format(len(status["instances"]))

    pod_def["scaling"]["instances"] = 1
    client.update_pod(pod_id, pod_def)
    common.deployment_wait(service_id=pod_id)

    status = get_pod_status(pod_id)
    assert len(status["instances"]) == 1, \
        "The number of instances is {}, but 1 was expected".format(len(status["instances"]))
コード例 #21
0
def test_create_and_update_pod():
    """Versions and reverting with pods"""

    pod_def = pods.simple_pod()
    pod_def["scaling"]["instances"] = 1
    pod_id = pod_def['id']

    client = marathon.create_client()
    client.add_pod(pod_def)
    common.deployment_wait(service_id=pod_id)

    pod_def["scaling"]["instances"] = 3
    client.update_pod(pod_id, pod_def)
    common.deployment_wait(service_id=pod_id)

    versions = get_pod_versions(pod_id)
    assert len(versions) == 2, "The number of versions is {}, but 2 was expected".format(len(versions))

    version1 = get_pod_version(pod_id, versions[0])
    version2 = get_pod_version(pod_id, versions[1])
    assert version1["scaling"]["instances"] != version2["scaling"]["instances"], \
        "Two pod versions have the same number of instances: {}, but they should not".format(
            version1["scaling"]["instances"])
コード例 #22
0
def test_pod_restarts_on_nonzero_exit_code():
    """Verifies that a pod get restarted in case one of its containers exits with a non-zero code.
       As a result, after restart, there should be two new tasks for different IDs.
    """

    pod_def = pods.simple_pod()
    pod_id = pod_def['id']
    pod_def["scaling"]["instances"] = 1
    pod_def['containers'][0]['exec']['command']['shell'] = 'sleep 5; echo -n leaving; exit 2'

    client = marathon.create_client()
    client.add_pod(pod_def)
    common.deployment_wait(service_id=pod_id)

    tasks = common.get_pod_tasks(pod_id)
    initial_id1 = tasks[0]['id']
    initial_id2 = tasks[1]['id']

    time.sleep(6)  # 1 sec past the 5 sec sleep in one of the container's command
    tasks = common.get_pod_tasks(pod_id)
    for task in tasks:
        assert task['id'] != initial_id1, "Got the same task ID"
        assert task['id'] != initial_id2, "Got the same task ID"