Skip to content

Commit

Permalink
Merge pull request #70 from universalcore/feature/issue-68-tasks-404-12x
Browse files Browse the repository at this point in the history
Check for 404 during task syncing
  • Loading branch information
JayH5 committed May 10, 2016
2 parents 5a07002 + 9e1f9b6 commit 6f28ed2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
10 changes: 9 additions & 1 deletion consular/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,15 @@ def _consul_key_to_marathon_label_key(self, consul_key):

@inlineCallbacks
def sync_app_tasks(self, app):
tasks = yield self.marathon_client.get_app_tasks(app['id'])
tasks = yield handle_not_found_error(
self.marathon_client.get_app_tasks, app['id'])
if tasks is None:
# Certain versions of Marathon may return 404 when an app has no
# tasks. Other versions return an empty list.
# https://github.com/mesosphere/marathon/issues/3881
log.msg('No tasks found in Marathon for app ID "%s"' % app['id'])
return

for task in tasks:
yield self.register_task_service(
app['id'], task['id'], task['host'], task['ports'])
Expand Down
25 changes: 25 additions & 0 deletions consular/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,31 @@ def test_sync_app_tasks_multiple_ports(self):
FakeResponse(200, [], json.dumps({})))
yield d

@inlineCallbacks
def test_sync_app_tasks_not_found(self):
"""
When syncing an app with a task, and Marathon has no tasks for the app,
Consular should handle a 404 response from Marathon gracefully.
"""
d = self.consular.sync_app_tasks({'id': '/my-app'})

# First Consular fetches the tasks for the app
marathon_request = yield self.requests.get()
self.assertEqual(marathon_request['method'], 'GET')
self.assertEqual(
marathon_request['url'],
'http://localhost:8080/v2/apps/my-app/tasks')

# Respond with a 404
marathon_request['deferred'].callback(
FakeResponse(404, [], json.dumps(
{"message": "App '/my-app' does not exist"}))
)

# Nothing much should happen -- there are no tasks

yield d

@inlineCallbacks
def test_sync_app_labels(self):
app = {
Expand Down

0 comments on commit 6f28ed2

Please sign in to comment.