marathon: update app and group add to return deployment id (#810)

This commit is contained in:
Ken Sipe
2016-10-14 18:25:40 -05:00
committed by tamarrow
parent 79b72f1f69
commit c9328a448b
5 changed files with 38 additions and 30 deletions

View File

@@ -361,7 +361,8 @@ class MarathonSubcommand(object):
message = "Application '{}' already exists".format(app_id)
raise DCOSException(message)
client.add_app(application_resource)
deployment = client.add_app(application_resource)
emitter.publish('Created deployment {}'.format(deployment))
return 0
@@ -423,7 +424,8 @@ class MarathonSubcommand(object):
else:
raise DCOSException("Group '{}' already exists".format(group_id))
client.create_group(group_resource)
deployment = client.create_group(group_resource)
emitter.publish('Created deployment {}'.format(deployment))
return 0

View File

@@ -3,6 +3,7 @@ import collections
import contextlib
import json
import os
import re
import subprocess
import time
@@ -173,7 +174,12 @@ def add_app(app_path, wait=True):
:rtype: None
"""
assert_command(['dcos', 'marathon', 'app', 'add', app_path])
cmd = ['dcos', 'marathon', 'app', 'add', app_path]
returncode, stdout, stderr = exec_command(cmd)
assert returncode == 0
assert re.fullmatch('Created deployment \S+\n', stdout.decode('utf-8'))
assert stderr == b''
if wait:
watch_all_deployments()
@@ -709,9 +715,7 @@ UNIVERSE_TEST_REPO = "http://universe.marathon.mesos:8085/repo"
def setup_universe_server():
# add universe-server with static packages
assert_command(
['dcos', 'marathon', 'app', 'add', 'tests/data/universe-v3-stub.json'])
watch_all_deployments()
add_app('tests/data/universe-v3-stub.json', True)
assert_command(
['dcos', 'package', 'repo', 'remove', 'Universe'])

View File

@@ -1,5 +1,6 @@
import contextlib
import json
import re
from .common import (assert_command, assert_lines, exec_command, remove_group,
show_app, watch_all_deployments)
@@ -148,9 +149,18 @@ def test_scale_group_when_scale_factor_not_float():
def _deploy_group(file_path, stdin=True):
if stdin:
with open(file_path) as fd:
assert_command(['dcos', 'marathon', 'group', 'add'], stdin=fd)
cmd = ['dcos', 'marathon', 'group', 'add']
returncode, stdout, stderr = exec_command(cmd, stdin=fd)
assert returncode == 0
assert re.fullmatch('Created deployment \S+\n',
stdout.decode('utf-8'))
assert stderr == b''
else:
assert_command(['dcos', 'marathon', 'group', 'add', file_path])
cmd = ['dcos', 'marathon', 'group', 'add', file_path]
returncode, stdout, stderr = exec_command(cmd)
assert returncode == 0
assert re.fullmatch('Created deployment \S+\n', stdout.decode('utf-8'))
assert stderr == b''
# Let's make sure that we don't return until the deployment has finished
watch_all_deployments()

View File

@@ -226,7 +226,7 @@ class Client(object):
# Looks like Marathon return different JSON for versions
if version is None:
return response.json()['app']
return response.json().get('app')
else:
return response.json()
@@ -238,7 +238,7 @@ class Client(object):
"""
response = self._rpc.http_req(http.get, 'v2/groups')
return response.json()['groups']
return response.json().get('groups')
def get_group(self, group_id, version=None):
"""Returns a representation of the requested group version. If
@@ -285,9 +285,9 @@ class Client(object):
response = self._rpc.http_req(http.get, path)
if max_count is None:
return response.json()['versions']
return response.json().get('versions')
else:
return response.json()['versions'][:max_count]
return response.json().get('versions')[:max_count]
def get_apps(self):
"""Get a list of known applications.
@@ -297,7 +297,7 @@ class Client(object):
"""
response = self._rpc.http_req(http.get, 'v2/apps')
return response.json()['apps']
return response.json().get('apps')
def get_apps_for_framework(self, framework_name):
""" Return all apps running the given framework.
@@ -327,8 +327,7 @@ class Client(object):
app_json = app_resource
response = self._rpc.http_req(http.post, 'v2/apps', json=app_json)
return response.json()
return response.json().get('deployments', {})[0].get('id')
def _update_req(
self, resource_type, resource_id, resource_json, force=False):
@@ -374,7 +373,7 @@ class Client(object):
body_json = self._parse_json(response)
try:
return body_json['deploymentId']
return body_json.get('deploymentId')
except KeyError:
template = ('Error: missing "deploymentId" field in the following '
'JSON response from Marathon:\n{}')
@@ -433,7 +432,7 @@ class Client(object):
params=params,
json={'instances': int(instances)})
deployment = response.json()['deploymentId']
deployment = response.json().get('deploymentId')
return deployment
def scale_group(self, group_id, scale_factor, force=False):
@@ -457,7 +456,7 @@ class Client(object):
params=params,
json={'scaleBy': scale_factor})
deployment = response.json()['deploymentId']
deployment = response.json().get('deploymentId')
return deployment
def stop_app(self, app_id, force=False):
@@ -711,7 +710,7 @@ class Client(object):
group_json = group_resource
response = self._rpc.http_req(http.post, 'v2/groups', json=group_json)
return response.json()
return response.json().get("deploymentId")
def get_leader(self):
""" Get the leading marathon instance.
@@ -721,7 +720,7 @@ class Client(object):
"""
response = self._rpc.http_req(http.get, 'v2/leader')
return response.json()['leader']
return response.json().get('leader')
def add_pod(self, pod_json):
"""Add a new pod.
@@ -733,11 +732,7 @@ class Client(object):
"""
response = self._rpc.http_req(http.post, 'v2/pods', json=pod_json)
try:
return response.headers['Marathon-Deployment-Id']
except KeyError:
msg = 'Error: missing "Marathon-Deployment-Id" from header'
raise DCOSException(msg)
return response.headers.get('Marathon-Deployment-Id')
def remove_pod(self, pod_id, force=False):
"""Completely removes the requested pod.

View File

@@ -656,12 +656,9 @@ def _assert_method_raises_dcos_exception_for_json_parse_errors(invoke_method):
def _assert_add_pod_raises_dcos_exception_if_deployment_id_missing(headers):
marathon_client, rpc_client = _create_fixtures()
rpc_client.http_req.return_value = _pod_response_fixture(headers)
result = marathon_client.add_pod({'some': 'json'})
with pytest.raises(DCOSException) as exception_info:
marathon_client.add_pod({'some': 'json'})
expected_error = 'Error: missing "Marathon-Deployment-Id" from header'
assert str(exception_info.value) == expected_error
assert result is None
def _assert_update_pod_raises_dcos_exception_if_deployment_id_missing(headers):