# Buggy code
def __init__(self, opts):
    pull_sock = os.path.join(opts["sock_dir"], "master_event_pull.ipc")
    if os.path.isfile(pull_sock) and HAS_ZMQ:
        self.event = salt.utils.event.get_event(
            "master", opts["sock_dir"], opts["transport"], opts=opts, listen=False
        )
    else:
        self.event = None
    self.opts = opts
    self.opts["_ssh_version"] = ssh_version()
    self.tgt_type = (
        self.opts["selected_target_option"]
        if self.opts["selected_target_option"]
        else "glob"
    )
    self.roster = salt.roster.Roster(opts, opts.get("roster"))
    self.targets = self.roster.targets(self.opts["tgt"], self.tgt_type)
    priv = self.opts.get(
        "ssh_priv", os.path.join(self.opts["pki_dir"], "ssh", "salt-ssh.rsa")
    )
    if not os.path.isfile(priv):
        try:
            salt.client.ssh.shell.gen_key(priv)
        except OSError:
            raise salt.exceptions.SaltClientError(
                "salt-ssh could not be run because it could not generate keys.\n\nYou can probably resolve this by executing this script with increased permissions via sudo or by running as root.\nYou could also use the '-c' option to supply a configuration directory that you have permissions to read and write to."
            )
    self.defaults = {
        "user": self.opts.get("ssh_user", salt.config.DEFAULT_MASTER_OPTS["ssh_user"]),
        "port": self.opts.get("ssh_port", salt.config.DEFAULT_MASTER_OPTS["ssh_port"]),
        "passwd": self.opts.get(
            "ssh_passwd", salt.config.DEFAULT_MASTER_OPTS["ssh_passwd"]
        ),
        "priv": priv,
        "timeout": self.opts.get(
            "ssh_timeout", salt.config.DEFAULT_MASTER_OPTS["ssh_timeout"]
        )
        + self.opts.get("timeout", salt.config.DEFAULT_MASTER_OPTS["timeout"]),
        "sudo": self.opts.get("ssh_sudo", salt.config.DEFAULT_MASTER_OPTS["ssh_sudo"]),
    }
    if self.opts.get("rand_thin_dir"):
        self.defaults["thin_dir"] = os.path.join(
            "/tmp", ".{0}".format(uuid.uuid4().hex[:6])
        )
        self.opts["wipe_ssh"] = "True"
    self.serial = salt.payload.Serial(opts)
    self.returners = salt.loader.returners(self.opts, {})
    self.fsclient = salt.fileclient.FSClient(self.opts)
    self.mods = mod_data(self.fsclient)


# Traceback (IOError)
Process Process-8:
Traceback (most recent call last):
File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python2.7/dist-packages/salt/client/ssh/__init__.py", line 315, in handle_routine
stdout, stderr, retcode = single.run()
File "/usr/lib/python2.7/dist-packages/salt/client/ssh/__init__.py", line 630, in run
stdout = self.run_wfunc()
File "/usr/lib/python2.7/dist-packages/salt/client/ssh/__init__.py", line 675, in run_wfunc
opts_pkg = pre_wrapper['test.opts_pkg']()
File "/usr/lib/python2.7/dist-packages/salt/client/ssh/wrapper/__init__.py", line 62, in caller
stdout, stderr, _ = single.cmd_block()
File "/usr/lib/python2.7/dist-packages/salt/client/ssh/__init__.py", line 818, in cmd_block
cmd_str = self._cmd_str()
File "/usr/lib/python2.7/dist-packages/salt/client/ssh/__init__.py", line 755, in _cmd_str
thin_sum = salt.utils.thin.thin_sum(cachedir, 'sha1')
File "/usr/lib/python2.7/dist-packages/salt/utils/thin.py", line 182, in thin_sum
thintar = gen_thin(cachedir)
File "/usr/lib/python2.7/dist-packages/salt/utils/thin.py", line 172, in gen_thin
tfp.add('version')
File "/usr/lib/python2.7/tarfile.py", line 1995, in add
self.addfile(tarinfo, f)
File "/usr/lib/python2.7/tarfile.py", line 2024, in addfile
copyfileobj(fileobj, self.fileobj, tarinfo.size)
File "/usr/lib/python2.7/tarfile.py", line 279, in copyfileobj
raise IOError("end of file reached")
IOError: end of file reached

Traceback (most recent call last):
File "./install.py", line 415, in <module>
for output in run():
File "./install.py", line 331, in run
for output in bootstrap('*'):
File "./install.py", line 181, in bootstrap
yield check_output(['salt-ssh', minion_id, 'state.sls', 'bootstrap'])
File "/usr/lib/python2.7/subprocess.py", line 573, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['salt-ssh', '*', 'state.sls', 'bootstrap']' returned non-zero exit status -15

# Fixed code
def __init__(self, opts):
    pull_sock = os.path.join(opts["sock_dir"], "master_event_pull.ipc")
    if os.path.isfile(pull_sock) and HAS_ZMQ:
        self.event = salt.utils.event.get_event(
            "master", opts["sock_dir"], opts["transport"], opts=opts, listen=False
        )
    else:
        self.event = None
    self.opts = opts
    self.opts["_ssh_version"] = ssh_version()
    self.tgt_type = (
        self.opts["selected_target_option"]
        if self.opts["selected_target_option"]
        else "glob"
    )
    self.roster = salt.roster.Roster(opts, opts.get("roster"))
    self.targets = self.roster.targets(self.opts["tgt"], self.tgt_type)
    priv = self.opts.get(
        "ssh_priv", os.path.join(self.opts["pki_dir"], "ssh", "salt-ssh.rsa")
    )
    if not os.path.isfile(priv):
        try:
            salt.client.ssh.shell.gen_key(priv)
        except OSError:
            raise salt.exceptions.SaltClientError(
                "salt-ssh could not be run because it could not generate keys.\n\nYou can probably resolve this by executing this script with increased permissions via sudo or by running as root.\nYou could also use the '-c' option to supply a configuration directory that you have permissions to read and write to."
            )
    self.defaults = {
        "user": self.opts.get("ssh_user", salt.config.DEFAULT_MASTER_OPTS["ssh_user"]),
        "port": self.opts.get("ssh_port", salt.config.DEFAULT_MASTER_OPTS["ssh_port"]),
        "passwd": self.opts.get(
            "ssh_passwd", salt.config.DEFAULT_MASTER_OPTS["ssh_passwd"]
        ),
        "priv": priv,
        "timeout": self.opts.get(
            "ssh_timeout", salt.config.DEFAULT_MASTER_OPTS["ssh_timeout"]
        )
        + self.opts.get("timeout", salt.config.DEFAULT_MASTER_OPTS["timeout"]),
        "sudo": self.opts.get("ssh_sudo", salt.config.DEFAULT_MASTER_OPTS["ssh_sudo"]),
    }
    if self.opts.get("rand_thin_dir"):
        self.defaults["thin_dir"] = os.path.join(
            "/tmp", ".{0}".format(uuid.uuid4().hex[:6])
        )
        self.opts["wipe_ssh"] = "True"
    self.serial = salt.payload.Serial(opts)
    self.returners = salt.loader.returners(self.opts, {})
    self.fsclient = salt.fileclient.FSClient(self.opts)
    self.thin = salt.utils.thin.gen_thin(self.opts["cachedir"])
    self.mods = mod_data(self.fsclient)