handle multiple tasks in task ls (#645)

This commit is contained in:
tamarrow
2016-06-08 11:44:38 -07:00
parent 9fcbff9446
commit 00406f4a48
2 changed files with 25 additions and 9 deletions

View File

@@ -181,12 +181,20 @@ def _ls(task, path, long_, completed):
path = path[1:]
dcos_client = mesos.DCOSClient()
task_obj = mesos.get_master(dcos_client).task(
fltr=task, completed=completed)
dir_ = posixpath.join(task_obj.directory(), path)
task_objects = mesos.get_master(dcos_client).tasks(
fltr=task,
completed=completed)
if len(task_objects) == 0:
raise DCOSException(
'Cannot find a task with ID containing "{}"'.format(task))
try:
files = dcos_client.browse(task_obj.slave(), dir_)
all_files = []
for task_obj in task_objects:
dir_ = posixpath.join(task_obj.directory(), path)
all_files += [
(task_obj['id'], dcos_client.browse(task_obj.slave(), dir_))]
except DCOSHTTPException as e:
if e.response.status_code == 404:
raise DCOSException(
@@ -194,7 +202,10 @@ def _ls(task, path, long_, completed):
else:
raise
if files:
add_header = len(all_files) > 1
for (task_id, files) in all_files:
if add_header:
emitter.publish('===> {} <==='.format(task_id))
if long_:
emitter.publish(tables.ls_long_table(files))
else:

View File

@@ -233,13 +233,18 @@ def test_ls():
def test_ls_multiple_tasks():
ls_line = 'stderr stderr.logrotate.conf stdout stdout.logrotate.conf'
returncode, stdout, stderr = exec_command(
['dcos', 'task', 'ls', 'test-app'])
lines = stdout.decode('utf-8').split('\n')
assert len(lines) == 5
assert re.match('===>.*<===', lines[0])
assert re.match(ls_line, lines[1])
assert re.match('===>.*<===', lines[2])
assert re.match(ls_line, lines[3])
assert returncode == 1
assert stdout == b''
assert stderr.startswith(b'There are multiple tasks with ID matching '
b'[test-app]. Please choose one:\n\t')
returncode, stdout, stderr = exec_command(
['dcos', 'task', 'ls', 'test-app'])
def test_ls_long():