1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
import requests_mock
from marathon import MarathonClient
from marathon import models
def test_get_deployments_pre_1_0():
fake_response = """[
{
"affectedApps": [
"/test"
],
"id": "fakeid",
"steps": [
[
{
"action": "ScaleApplication",
"app": "/test"
}
]
],
"currentActions": [
{
"action": "ScaleApplication",
"app": "/test"
}
],
"version": "fakeversion",
"currentStep": 1,
"totalSteps": 1
}
]"""
with requests_mock.mock() as m:
m.get('http://fake_server/v2/deployments', text=fake_response)
mock_client = MarathonClient(servers='http://fake_server')
actual_deployments = mock_client.list_deployments()
expected_deployments = [models.MarathonDeployment(
id="fakeid",
steps=[
[models.MarathonDeploymentAction(
action="ScaleApplication", app="/test")]],
current_actions=[models.MarathonDeploymentAction(
action="ScaleApplication", app="/test")],
current_step=1,
total_steps=1,
affected_apps=["/test"],
version="fakeversion"
)]
assert expected_deployments == actual_deployments
def test_get_deployments_post_1_0():
fake_response = """[
{
"id": "4d2ff4d8-fbe5-4239-a886-f0831ed68d20",
"version": "2016-04-20T18:00:20.084Z",
"affectedApps": [
"/test-trivial-app"
],
"steps": [
{
"actions": [
{
"type": "StartApplication",
"app": "/test-trivial-app"
}
]
},
{
"actions": [
{
"type": "ScaleApplication",
"app": "/test-trivial-app"
}
]
}
],
"currentActions": [
{
"action": "ScaleApplication",
"app": "/test-trivial-app",
"readinessCheckResults": []
}
],
"currentStep": 2,
"totalSteps": 2
}
]"""
with requests_mock.mock() as m:
m.get('http://fake_server/v2/deployments', text=fake_response)
mock_client = MarathonClient(servers='http://fake_server')
actual_deployments = mock_client.list_deployments()
expected_deployments = [models.MarathonDeployment(
id="4d2ff4d8-fbe5-4239-a886-f0831ed68d20",
steps=[
models.MarathonDeploymentStep(
actions=[models.MarathonDeploymentAction(
type="StartApplication", app="/test-trivial-app")],
),
models.MarathonDeploymentStep(
actions=[models.MarathonDeploymentAction(
type="ScaleApplication", app="/test-trivial-app")],
),
],
current_actions=[models.MarathonDeploymentAction(
action="ScaleApplication", app="/test-trivial-app", readiness_check_results=[])
],
current_step=2,
total_steps=2,
affected_apps=["/test-trivial-app"],
version="2016-04-20T18:00:20.084Z"
)]
# Helpful for tox to see the diff
assert expected_deployments[0].__dict__ == actual_deployments[0].__dict__
assert expected_deployments == actual_deployments
def test_list_tasks_with_app_id():
fake_response = '{ "tasks": [ { "appId": "/anapp", "healthCheckResults": ' \
'[ { "alive": true, "consecutiveFailures": 0, "firstSuccess": "2014-10-03T22:57:02.246Z", ' \
'"lastFailure": null, "lastSuccess": "2014-10-03T22:57:41.643Z", "taskId": "bridged-webapp.eb76c51f-4b4a-11e4-ae49-56847afe9799" } ],' \
' "host": "10.141.141.10", "id": "bridged-webapp.eb76c51f-4b4a-11e4-ae49-56847afe9799", "ports": [ 31000 ], ' \
'"servicePorts": [ 9000 ], "stagedAt": "2014-10-03T22:16:27.811Z", "startedAt": "2014-10-03T22:57:41.587Z", ' \
'"version": "2014-10-03T22:16:23.634Z" }]}'
with requests_mock.mock() as m:
m.get('http://fake_server/v2/apps//anapp/tasks', text=fake_response)
mock_client = MarathonClient(servers='http://fake_server')
actual_deployments = mock_client.list_tasks(app_id='/anapp')
expected_deployments = [models.task.MarathonTask(
app_id="/anapp",
health_check_results=[
models.task.MarathonHealthCheckResult(
alive=True,
consecutive_failures=0,
first_success="2014-10-03T22:57:02.246Z",
last_failure=None,
last_success="2014-10-03T22:57:41.643Z",
task_id="bridged-webapp.eb76c51f-4b4a-11e4-ae49-56847afe9799"
)
],
host="10.141.141.10",
id="bridged-webapp.eb76c51f-4b4a-11e4-ae49-56847afe9799",
ports=[
31000
],
service_ports=[
9000
],
staged_at="2014-10-03T22:16:27.811Z",
started_at="2014-10-03T22:57:41.587Z",
version="2014-10-03T22:16:23.634Z"
)]
assert actual_deployments == expected_deployments
def test_list_tasks_without_app_id():
fake_response = '{ "tasks": [ { "appId": "/anapp", "healthCheckResults": ' \
'[ { "alive": true, "consecutiveFailures": 0, "firstSuccess": "2014-10-03T22:57:02.246Z", "lastFailure": null, ' \
'"lastSuccess": "2014-10-03T22:57:41.643Z", "taskId": "bridged-webapp.eb76c51f-4b4a-11e4-ae49-56847afe9799" } ],' \
' "host": "10.141.141.10", "id": "bridged-webapp.eb76c51f-4b4a-11e4-ae49-56847afe9799", "ports": [ 31000 ], ' \
'"servicePorts": [ 9000 ], "stagedAt": "2014-10-03T22:16:27.811Z", "startedAt": "2014-10-03T22:57:41.587Z", ' \
'"version": "2014-10-03T22:16:23.634Z" }, { "appId": "/anotherapp", ' \
'"healthCheckResults": [ { "alive": true, "consecutiveFailures": 0, "firstSuccess": "2014-10-03T22:57:02.246Z", ' \
'"lastFailure": null, "lastSuccess": "2014-10-03T22:57:41.649Z", "taskId": "bridged-webapp.ef0b5d91-4b4a-11e4-ae49-56847afe9799" } ], ' \
'"host": "10.141.141.10", "id": "bridged-webapp.ef0b5d91-4b4a-11e4-ae49-56847afe9799", "ports": [ 31001 ], "servicePorts": [ 9000 ], ' \
'"stagedAt": "2014-10-03T22:16:33.814Z", "startedAt": "2014-10-03T22:57:41.593Z", "version": "2014-10-03T22:16:23.634Z" } ] }'
with requests_mock.mock() as m:
m.get('http://fake_server/v2/tasks', text=fake_response)
mock_client = MarathonClient(servers='http://fake_server')
actual_deployments = mock_client.list_tasks()
expected_deployments = [
models.task.MarathonTask(
app_id="/anapp",
health_check_results=[
models.task.MarathonHealthCheckResult(
alive=True,
consecutive_failures=0,
first_success="2014-10-03T22:57:02.246Z",
last_failure=None,
last_success="2014-10-03T22:57:41.643Z",
task_id="bridged-webapp.eb76c51f-4b4a-11e4-ae49-56847afe9799"
)
],
host="10.141.141.10",
id="bridged-webapp.eb76c51f-4b4a-11e4-ae49-56847afe9799",
ports=[
31000
],
service_ports=[
9000
],
staged_at="2014-10-03T22:16:27.811Z",
started_at="2014-10-03T22:57:41.587Z",
version="2014-10-03T22:16:23.634Z"
),
models.task.MarathonTask(
app_id="/anotherapp",
health_check_results=[
models.task.MarathonHealthCheckResult(
alive=True,
consecutive_failures=0,
first_success="2014-10-03T22:57:02.246Z",
last_failure=None,
last_success="2014-10-03T22:57:41.649Z",
task_id="bridged-webapp.ef0b5d91-4b4a-11e4-ae49-56847afe9799"
)
],
host="10.141.141.10",
id="bridged-webapp.ef0b5d91-4b4a-11e4-ae49-56847afe9799",
ports=[31001],
service_ports=[9000],
staged_at="2014-10-03T22:16:33.814Z",
started_at="2014-10-03T22:57:41.593Z",
version="2014-10-03T22:16:23.634Z"
)]
assert actual_deployments == expected_deployments
|