Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Bring some missing functions from master to stable.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpereira committed Apr 19, 2018
1 parent 47fc0ee commit c939aab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions testing/sdk_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,24 @@ def task_exec(task_name: str, cmd: str, return_stderr_in_stdout: bool = False) -
return rc, stdout, stderr


def service_task_exec(service_name: str, task_name: str, cmd: str, return_stderr_in_stdout: bool = False) -> tuple:
"""
Invokes the given command on the named SDK service task via `dcos task exec`.
:param service_name: Name of the service running the task.
:param task_name: Name of task to run 'cmd' on.
:param cmd: The command to execute.
:return: a tuple consisting of the task exec's return code, stdout, and stderr
"""

# Contrary to CLI's help text for 'dcos task exec':
# - 'partial task ID' is only prefix/startswith matching, not 'contains' as the wording would imply.
# - Regexes don't work at all.
# Therefore, we need to provide a full TaskID prefix, including "servicename__taskname":
task_id_prefix = '{}__{}__'.format(sdk_utils.get_task_id_service_name(service_name), task_name)

return task_exec(task_id_prefix, cmd, return_stderr_in_stdout)


def resolve_hosts(marathon_task_name: str, hosts: list, bootstrap_cmd: str='./bootstrap') -> bool:
"""
Use bootstrap to resolve the specified list of hosts
Expand Down
7 changes: 7 additions & 0 deletions testing/sdk_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ def get_foldered_name(service_name):
return '/test/integration/' + service_name


def get_task_id_service_name(service_name):
'''Converts the provided service name to a sanitized name as used in task ids.
For example: /test/integration/foo => test.integration.foo'''
return service_name.lstrip('/').replace('/', '.')


def get_zk_path(service_name):
# Foldered services have slashes removed: '/test/integration/foo' => 'test__integration__foo'
return 'dcos-service-{}'.format(service_name.lstrip('/').replace('/', '__'))
Expand Down

0 comments on commit c939aab

Please sign in to comment.