Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix InvalidJobNameError in marathon_services_running_here #119

Merged
merged 1 commit into from
Dec 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions paasta_itests/marathon.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ Feature: paasta_tools can create marathon apps
When we create a trivial marathon app
Then we should see it running in marathon

Scenario: get_marathon_services_running_here_for_nerve works
Given a working paasta cluster
When we create a trivial marathon app
Then we should see it running in marathon
When the task has started
Then it should show up in marathon_services_running_here

# vim: set ts=2 sw=2
35 changes: 31 additions & 4 deletions paasta_itests/steps/marathon_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,52 @@
# limitations under the License.

import sys
import time

from behave import when, then
import mock

sys.path.append('../')
import paasta_tools

APP_ID = 'test--marathon--app.instance.git01234567.configabcdef01'


@when(u'we create a trivial marathon app')
def create_trivial_marathon_app(context):
app_config = {
'id': 'test--marathon--app',
'cmd': '/bin/true',
'id': APP_ID,
'cmd': '/bin/sleep 30',
'instances': 1,
}
with mock.patch('paasta_tools.bounce_lib.create_app_lock'):
paasta_tools.bounce_lib.create_marathon_app(app_config['id'], app_config, context.marathon_client)


@then(u'we should see it running in marathon')
def list_marathon_apps_has_trivial_app(context):
assert 'test--marathon--app' in paasta_tools.marathon_tools.list_all_marathon_app_ids(context.marathon_client)
assert context.marathon_client.get_app('/test--marathon--app')
actual = paasta_tools.marathon_tools.list_all_marathon_app_ids(context.marathon_client)
assert APP_ID in actual
assert context.marathon_client.get_app('/%s' % APP_ID)


@then(u'it should show up in marathon_services_running_here')
def marathon_services_running_here_works(context):
with mock.patch('paasta_tools.mesos_tools.socket.getfqdn', return_value='mesosslave'):
(discovered,) = paasta_tools.marathon_tools.marathon_services_running_here()

assert discovered[0] == u'test_marathon_app', repr(discovered)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I didn't know about this comma thing with assert...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I wish that behave had the magical assertion stuff that pytest has. Without this you just get AssertionError.

assert discovered[1] == 'instance'


@when(u'the task has started')
def when_the_task_has_started(context):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about reusing the when_there_are_num_which_tasks function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seemed too complicated. Also can you share steps between features like that?

# 120 * 0.5 = 60 seconds
for _ in xrange(120):
app = context.marathon_client.get_app(APP_ID, embed_tasks=True)
happy_count = len(app.tasks)
if happy_count >= 1:
return
time.sleep(0.5)

raise Exception("timed out waiting for task to start")
8 changes: 7 additions & 1 deletion paasta_tools/marathon_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,11 @@ def get_all_namespaces(soa_dir=DEFAULT_SOA_DIR):
return namespace_list


def get_app_id_and_task_uuid_from_executor_id(executor_id):
"""Parse the marathon executor ID and return the (app id, task uuid)"""
return executor_id.rsplit('.', 1)


def marathon_services_running_here():
"""See what marathon services are being run by a mesos-slave on this host.
:returns: A list of triples of (service, instance, port)"""
Expand All @@ -653,7 +658,8 @@ def marathon_services_running_here():
if u'TASK_RUNNING' in [t[u'state'] for t in ex.get('tasks', [])]]
srv_list = []
for executor in executors:
(srv_name, srv_instance, _, __) = deformat_job_id(executor['id'])
app_id, task_uuid = get_app_id_and_task_uuid_from_executor_id(executor['id'])
(srv_name, srv_instance, _, __) = deformat_job_id(app_id)
srv_port = int(re.findall('[0-9]+', executor['resources']['ports'])[0])
srv_list.append((srv_name, srv_instance, srv_port))
return srv_list
Expand Down
10 changes: 5 additions & 5 deletions tests/test_marathon_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,11 @@ def test_read_namespace_for_service_instance_no_value(self, read_info_patch):

@mock.patch('marathon_tools.get_local_slave_state', autospec=True)
def test_marathon_services_running_here(self, mock_get_local_slave_state):
id_1 = 'klingon.ships.detected.249qwiomelht4jioewglkemr'
id_2 = 'fire.photon.torpedos.jtgriemot5yhtwe94'
id_3 = 'dota.axe.cleave.482u9jyoi4wed'
id_4 = 'mesos.deployment.is.hard'
id_5 = 'how.to.fake.data'
id_1 = 'klingon.ships.detected.249qwiomelht4jioewglkemr.someuuid'
id_2 = 'fire.photon.torpedos.jtgriemot5yhtwe94.someuuid'
id_3 = 'dota.axe.cleave.482u9jyoi4wed.someuuid'
id_4 = 'mesos.deployment.is.hard.someuuid'
id_5 = 'how.to.fake.data.someuuid'
ports_1 = '[111-111]'
ports_2 = '[222-222]'
ports_3 = '[333-333]'
Expand Down