8000 Fixed pattern matching for task IDs in 'task exec'. by klueska · Pull Request #1189 · dcos/dcos-cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fixed pattern matching for task IDs in 'task exec'. #1189

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

Merged
merged 1 commit into from
Mar 28, 2018
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
38 changes: 9 additions & 29 deletions python/lib/dcos/dcos/mesos.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -493,33 +493,17 @@ def tasks(self, fltr=None, completed=False, all_=False):

return tasks

def get_container_id(self, task_id):
"""Returns the container ID for a task ID matching `task_id`
def get_container_id(self, task_obj):
"""Returns the container ID for a task.

:param task_id: The task ID which will be mapped to container ID
:type task_id: str
:returns: The container ID associated with 'task_id'
:param task__obj: The task which will be mapped to container ID
:type task_obj: Task()
:returns: The container ID associated with 'task_obj'
:rtype: str
"""

def _get_task(task_id):
candidates = []
if 'frameworks' in self.state():
for framework in self.state()['frameworks']:
if 'tasks' in framework:
for task in framework['tasks']:
if 'id' in task:
if task['id'].startswith(task_id):
candidates.append(task)

if len(candidates) == 1:
return candidates[0]

raise DCOSException(
"More than one task matching '{}' found: {}"
.format(task_id, candidates))

def _get_container_status(task):
def _get_container_status(task_obj):
task = task_obj.dict()
if 'statuses' in task:
if len(task['statuses']) > 0:
if 'container_status' in task['statuses'][0]:
Expand All @@ -539,11 +523,7 @@ def _get_container_id(container_status):
" It might still be spinning up."
" Please try again.")

if not task_id:
raise DCOSException("Invalid task ID")

task = _get_task(task_id)
container_status = _get_container_status(task)
container_status = _get_container_status(task_obj)
return _get_container_id(container_status)

def frameworks(self, inactive=False, completed=False):
Expand Down Expand Up @@ -1136,7 +1116,7 @@ def __init__(self, task_id, cmd=None, args=None,
path="api/v1")

# Grab a reference to the container ID for the task.
self.parent_id = master.get_container_id(task_id)
self.parent_id = master.get_container_id(task_obj)

# Generate a new UUID for the nested container
# used to run commands passed to `task exec`.
Expand Down
2 changes: 1 addition & 1 deletion 2 python/lib/dcoscli/dcoscli/task/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def _metrics(summary, task_id, json_):
'Error finding agent associated with task: {}'.format(task_id))

slave_id = task['slave_id']
container_id = master.get_container_id(task_id)["value"]
container_id = master.get_container_id(task)["value"]

endpoint = '/system/v1/agent/{}/metrics/v0/containers/{}'.format(
slave_id, container_id
Expand Down
7 changes: 7 additions & 0 deletions python/lib/dcoscli/tests/integrations/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,13 @@ def test_exec_interactive():
stdout=content, stdin=text)


def test_exec_match_id_pattern():
assert_command(['dcos', 'task', 'exec', 'app1', 'true'])
assert_command(['dcos', 'task', 'exec', 'app2', 'true'])
returncode, _, _ = exec_command(['dcos', 'task', 'exec', 'app', 'true'])
assert returncode != 0


def _mark_non_blocking(file_):
import fcntl
fcntl.fcntl(file_.fileno(), fcntl.F_SETFL, os.O_NONBLOCK)
Expand Down
0