Skip to content

Commit

Permalink
chroot plugin minor touchups:
Browse files Browse the repository at this point in the history
* Disable su as it's not currently working 100% (and was disabled in v1).
* Move BUFSIZE out of the class to match other conenction plugins
* _connect shouldn't return self.
  • Loading branch information
abadger committed Sep 28, 2015
1 parent 7a4266e commit 12a2585
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/ansible/plugins/connection/chroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@
from ansible.utils.unicode import to_bytes


BUFSIZE = 65536


class Connection(ConnectionBase):
''' Local chroot based connections '''

BUFSIZE = 65536
has_pipelining = True
transport = 'chroot'
# su currently has an undiagnosed issue with calculating the file
# checksums (so copy, for instance, doesn't work right)
# Have to look into that before re-enabling this
become_methods = frozenset(C.BECOME_METHODS).difference(('su',))

def __init__(self, play_context, new_stdin, *args, **kwargs):

Expand All @@ -61,13 +67,11 @@ def __init__(self, play_context, new_stdin, *args, **kwargs):
if not self.chroot_cmd:
raise AnsibleError("chroot command not found in PATH")

def _connect(self, port=None):
def _connect(self):
''' connect to the chroot; nothing to do here '''

super(Connection, self)._connect()
self._display.vvv("THIS IS A LOCAL CHROOT DIR", host=self.chroot)

return self

def _generate_cmd(self, cmd, executable):
# subprocess takes byte strings
local_cmd = [self.chroot_cmd, self.chroot, executable, '-c']
Expand Down Expand Up @@ -111,7 +115,7 @@ def put_file(self, in_path, out_path):
try:
with open(in_path, 'rb') as in_file:
try:
p = self._buffered_exec_command('dd of=%s bs=%s' % (out_path, self.BUFSIZE), stdin=in_file)
p = self._buffered_exec_command('dd of=%s bs=%s' % (out_path, BUFSIZE), stdin=in_file)
except OSError:
raise AnsibleError("chroot connection requires dd command in the chroot")
try:
Expand All @@ -131,16 +135,16 @@ def fetch_file(self, in_path, out_path):
self._display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.chroot)

try:
p = self._buffered_exec_command('dd if=%s bs=%s' % (in_path, self.BUFSIZE))
p = self._buffered_exec_command('dd if=%s bs=%s' % (in_path, BUFSIZE))
except OSError:
raise AnsibleError("chroot connection requires dd command in the chroot")

with open(out_path, 'wb+') as out_file:
try:
chunk = p.stdout.read(self.BUFSIZE)
chunk = p.stdout.read(BUFSIZE)
while chunk:
out_file.write(chunk)
chunk = p.stdout.read(self.BUFSIZE)
chunk = p.stdout.read(BUFSIZE)
except:
traceback.print_exc()
raise AnsibleError("failed to transfer file %s to %s" % (in_path, out_path))
Expand Down

0 comments on commit 12a2585

Please sign in to comment.