mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
dockerio: better error message for native exec driver
This provides a more useful error message when using the native execution driver and nsenter is not available.
This commit is contained in:
parent
1380fec1b9
commit
c375309434
1 changed files with 16 additions and 8 deletions
|
@ -1731,14 +1731,22 @@ def _run_wrapper(status, container, func, cmd, *args, **kwargs):
|
|||
container_id = container_info['Id']
|
||||
if driver.startswith('lxc-'):
|
||||
full_cmd = 'lxc-attach -n {0} -- {1}'.format(container_id, cmd)
|
||||
elif driver.startswith('native-') and HAS_NSENTER:
|
||||
# http://jpetazzo.github.io/2014/03/23/lxc-attach-nsinit-nsenter-docker-0-9/
|
||||
container_pid = container_info['State']['Pid']
|
||||
if container_pid == 0:
|
||||
_invalid(status, id_=container, comment='Container is not running')
|
||||
return status
|
||||
full_cmd = ('nsenter --target {pid} --mount --uts --ipc --net --pid'
|
||||
' {cmd}'.format(pid=container_pid, cmd=cmd))
|
||||
elif driver.startswith('native-'):
|
||||
if HAS_NSENTER:
|
||||
# http://jpetazzo.github.io/2014/03/23/lxc-attach-nsinit-nsenter-docker-0-9/
|
||||
container_pid = container_info['State']['Pid']
|
||||
if container_pid == 0:
|
||||
_invalid(status, id_=container,
|
||||
comment='Container is not running')
|
||||
return status
|
||||
full_cmd = (
|
||||
'nsenter --target {pid} --mount --uts --ipc --net --pid'
|
||||
' {cmd}'.format(pid=container_pid, cmd=cmd)
|
||||
)
|
||||
else:
|
||||
raise CommandExecutionError(
|
||||
'nsenter is not installed on the minion, cannot run command'
|
||||
)
|
||||
else:
|
||||
raise NotImplementedError(
|
||||
'Unknown docker ExecutionDriver {0!r}. Or didn\'t find command'
|
||||
|
|
Loading…
Add table
Reference in a new issue