gurudesh/pytracebugs huggingface dataset:
# Buggy code
def symlink_list(self, load):
    """
    Return a list of symlinked files and dirs
    """
    if "env" in load:
        salt.utils.warn_until(
            "Boron",
            "Passing a salt environment should be done using 'saltenv' "
            "not 'env'. This functionality will be removed in Salt "
            "Boron.",
        )
        load["saltenv"] = load.pop("env")

    ret = {}
    if "saltenv" not in load:
        return {}
    for fsb in self._gen_back(None):
        symlstr = "{0}.symlink_list".format(fsb)
        if symlstr in self.servers:
            ret = self.servers[symlstr](load)
    # some *fs do not handle prefix. Ensure it is filtered
    prefix = load.get("prefix", "").strip("/")
    if prefix != "":
        ret = dict([(x, y) for x, y in ret.items() if x.startswith(prefix)])
    return ret


# Traceback (UnicodeDecodeError)
2015-02-07 21:51:36,769 [salt.master      ][ERROR   ] Error in function _file_list:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/master.py", line 1336, in run_func
ret = getattr(self, func)(load)
File "/usr/lib/python2.7/dist-packages/salt/fileserver/__init__.py", line 455, in file_list
return sorted(ret)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 64: ordinal not in range(128)

# Fixed code
def symlink_list(self, load):
    """
    Return a list of symlinked files and dirs
    """
    if "env" in load:
        salt.utils.warn_until(
            "Boron",
            "Passing a salt environment should be done using 'saltenv' "
            "not 'env'. This functionality will be removed in Salt "
            "Boron.",
        )
        load["saltenv"] = load.pop("env")

    ret = {}
    if "saltenv" not in load:
        return {}
    for fsb in self._gen_back(None):
        symlstr = "{0}.symlink_list".format(fsb)
        if symlstr in self.servers:
            ret = self.servers[symlstr](load)
    # upgrade all set elements to a common encoding
    ret = dict([(salt.utils.sdecode(x), salt.utils.sdecode(y)) for x, y in ret.items()])
    # some *fs do not handle prefix. Ensure it is filtered
    prefix = load.get("prefix", "").strip("/")
    if prefix != "":
        ret = dict([(x, y) for x, y in ret.items() if x.startswith(prefix)])
    return ret
# Buggy code
def _run_svn(cmd, cwd, user, username, password, opts, **kwargs):
    """
    Execute svn
    return the output of the command

    cmd
        The command to run.

    cwd
        The path to the Subversion repository

    user
        Run svn as a user other than what the minion runs as

    username
        Connect to the Subversion server as another user

    password
        Connect to the Subversion server with this password

        .. versionadded:: 0.17.0

    opts
        Any additional options to add to the command line

    kwargs
        Additional options to pass to the run-cmd
    """
    cmd = ["svn", "--non-interactive", cmd]
    if username:
        opts.extend(["--username", username])
    if password:
        opts.extend(["--password", password])
    if opts:
        cmd.extend(opts)

    result = __salt__["cmd.run_all"](
        cmd, python_shell=False, cwd=cwd, runas=user, **kwargs
    )

    retcode = result["retcode"]

    if retcode == 0:
        return result["stdout"]
    raise exceptions.CommandExecutionError(result["stderr"] + "\n\n" + " ".join(cmd))


# Traceback (AttributeError)
----------
ID: https://**.**.**.**/svn/System-Shellscripts/trunk/andros/scripts
Function: svn.latest
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1529, in call
**cdata['kwargs'])
File "/usr/lib/python2.7/dist-packages/salt/states/svn.py", line 121, in latest
out = __salt__[svn_cmd](cwd, basename, user, username, password, *opts)
File "/usr/lib/python2.7/dist-packages/salt/modules/svn.py", line 248, in update
return _run_svn('update', cwd, user, username, password, opts)
File "/usr/lib/python2.7/dist-packages/salt/modules/svn.py", line 62, in _run_svn
opts.extend(['--username', username])
AttributeError: 'tuple' object has no attribute 'extend'
Started: 18:25:58.133399
Duration: 150.401 ms
Changes:
----------

# Fixed code
def _run_svn(cmd, cwd, user, username, password, opts, **kwargs):
    """
    Execute svn
    return the output of the command

    cmd
        The command to run.

    cwd
        The path to the Subversion repository

    user
        Run svn as a user other than what the minion runs as

    username
        Connect to the Subversion server as another user

    password
        Connect to the Subversion server with this password

        .. versionadded:: 0.17.0

    opts
        Any additional options to add to the command line

    kwargs
        Additional options to pass to the run-cmd
    """
    cmd = ["svn", "--non-interactive", cmd]

    options = list(opts)
    if username:
        options.extend(["--username", username])
    if password:
        options.extend(["--password", password])
    cmd.extend(options)

    result = __salt__["cmd.run_all"](
        cmd, python_shell=False, cwd=cwd, runas=user, **kwargs
    )

    retcode = result["retcode"]

    if retcode == 0:
        return result["stdout"]
    raise exceptions.CommandExecutionError(result["stderr"] + "\n\n" + " ".join(cmd))
# Buggy code
def destroy(device):
    """
    Destroy a RAID device.

    WARNING This will zero the superblock of all members of the RAID array..

    CLI Example:

    .. code-block:: bash

        salt '*' raid.destroy /dev/md0
    """
    try:
        details = detail(device)
    except CommandExecutionError:
        return False

    stop_cmd = ["mdadm", "--stop", device]
    zero_cmd = ["mdadm", "--zero-superblock"]

    if __salt__["cmd.retcode"](stop_cmd):
        for number in details["members"]:
            zero_cmd.append(details["members"][number]["device"])
        __salt__["cmd.retcode"](zero_cmd)

    # Remove entry from config file:
    if __grains__.get("os_family") == "Debian":
        cfg_file = "/etc/mdadm/mdadm.conf"
    else:
        cfg_file = "/etc/mdadm.conf"

    __salt__["file.replace"](cfg_file, "ARRAY {0} .*".format(device), "")

    if __salt__["raid.list"]().get(device) is None:
        return True
    else:
        return False


# Traceback (SaltInvocationError)
[ERROR   ] Command ['mdadm', '--zero-superblock', '/dev/vde', '/dev/vdd'] failed with return code: 2
[ERROR   ] output: Usage: mdadm --help
for help
Passed invalid arguments: File not found: /etc/mdadm.conf
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/cli/caller.py", line 138, in call
ret['return'] = func(*args, **kwargs)
File "/var/cache/salt/extmods/modules/mdadm.py", line 143, in destroy
__salt__['file.replace'](cfg_file, 'ARRAY {0} .*'.format(device), '')
File "/usr/lib/python2.7/site-packages/salt/modules/file.py", line 1158, in replace
raise SaltInvocationError('File not found: {0}'.format(path))
SaltInvocationError: File not found: /etc/mdadm.conf

# Fixed code
def destroy(device):
    """
    Destroy a RAID device.

    WARNING This will zero the superblock of all members of the RAID array..

    CLI Example:

    .. code-block:: bash

        salt '*' raid.destroy /dev/md0
    """
    try:
        details = detail(device)
    except CommandExecutionError:
        return False

    stop_cmd = " ".join(["mdadm", "--stop", device])
    zero_cmd = " ".join(["mdadm", "--zero-superblock"])

    if __salt__["cmd.retcode"](stop_cmd):
        for number in details["members"]:
            zero_cmd.append(details["members"][number]["device"])
        __salt__["cmd.retcode"](zero_cmd)

    # Remove entry from config file:
    if __grains__.get("os_family") == "Debian":
        cfg_file = "/etc/mdadm/mdadm.conf"
    else:
        cfg_file = "/etc/mdadm.conf"

    try:
        __salt__["file.replace"](cfg_file, "ARRAY {0} .*".format(device), "")
    except SaltInvocationError:
        pass

    if __salt__["raid.list"]().get(device) is None:
        return True
    else:
        return False
# Buggy code
def get_event_iter_returns(self, jid, minions, timeout=None):
    """
    Gather the return data from the event system, break hard when timeout
    is reached.
    """
    log.trace("entered - function get_event_iter_returns()")
    if timeout is None:
        timeout = self.opts["timeout"]

    timeout_at = time.time() + timeout

    found = set()
    # Check to see if the jid is real, if not return the empty dict
    if self.returners["{0}.get_load".format(self.opts["master_job_cache"])](jid) == {}:
        log.warning("jid does not exist")
        yield {}
        # stop the iteration, since the jid is invalid
        raise StopIteration()
    # Wait for the hosts to check in
    while True:
        raw = self.event.get_event(timeout)
        if raw is None or time.time() > timeout_at:
            # Timeout reached
            break
        if "minions" in raw.get("data", {}):
            continue
        found.add(raw["id"])
        ret = {raw["id"]: {"ret": raw["return"]}}
        if "out" in raw:
            ret[raw["id"]]["out"] = raw["out"]
        yield ret
        time.sleep(0.02)


# Traceback (KeyError)
Delayed check -- works
{'jid': '20141215172830872294', 'minions': ['qa-master']}
{'qa-master': {'ret': True}}



Immediate check -- fails
{'jid': '20141215172833888811', 'minions': ['qa-master']}
Traceback (most recent call last):
File "./test.py", line 33, in <module>
check_job(job)
File "./test.py", line 19, in check_job
for resp in returned:
File "/usr/lib/python2.6/site-packages/salt/client/__init__.py", line 775, in get_cli_returns
for event in event_iter:
File "/usr/lib/python2.6/site-packages/salt/client/__init__.py", line 1255, in get_event_iter_returns
ret = {raw['id']: {'ret': raw['return']}}
KeyError: 'return'

# Fixed code
def get_event_iter_returns(self, jid, minions, timeout=None):
    """
    Gather the return data from the event system, break hard when timeout
    is reached.
    """
    log.trace("entered - function get_event_iter_returns()")
    if timeout is None:
        timeout = self.opts["timeout"]

    timeout_at = time.time() + timeout

    found = set()
    # Check to see if the jid is real, if not return the empty dict
    if self.returners["{0}.get_load".format(self.opts["master_job_cache"])](jid) == {}:
        log.warning("jid does not exist")
        yield {}
        # stop the iteration, since the jid is invalid
        raise StopIteration()
    # Wait for the hosts to check in
    while True:
        raw = self.event.get_event(timeout)
        if raw is None or time.time() > timeout_at:
            # Timeout reached
            break
        if "minions" in raw.get("data", {}):
            continue
        try:
            found.add(raw["id"])
            ret = {raw["id"]: {"ret": raw["return"]}}
        except KeyError:
            # Ignore other erroneous messages
            continue
        if "out" in raw:
            ret[raw["id"]]["out"] = raw["out"]
        yield ret
        time.sleep(0.02)
# Buggy code
def get_enabled():
    """
    Return the enabled services

    CLI Example:

    .. code-block:: bash

        salt '*' service.get_enabled
    """

    if has_powershell():
        cmd = 'Get-WmiObject win32_service | where {$_.startmode -eq "Auto"} | select-object name'
        lines = __salt__["cmd.run"](cmd, shell="POWERSHELL").splitlines()
        return sorted([line.strip() for line in lines[3:]])
    else:
        ret = set()
        services = []
        cmd = "sc query type= service state= all bufsize= {0}".format(BUFFSIZE)
        lines = __salt__["cmd.run"](cmd).splitlines()
        for line in lines:
            if "SERVICE_NAME:" in line:
                comps = line.split(":", 1)
                if not len(comps) > 1:
                    continue
                services.append(comps[1].strip())
        for service in services:
            cmd2 = list2cmdline(["sc", "qc", service, BUFFSIZE])
            lines = __salt__["cmd.run"](cmd2).splitlines()
            for line in lines:
                if "AUTO_START" in line:
                    ret.add(service)
        return sorted(ret)


# Traceback (TypeError)
ID: check_service
Function: service.running
Name: 135f1bc0-6c6e-11e4-9803-0800200c9a66
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "salt/state.py", line 1533, in call
File "salt/states/service.py", line 290, in running
File "salt/modules/win_service.py", line 256, in status
File "subprocess.py", line 618, in list2cmdline
TypeError: argument of type 'int' is not iterable
Started: 09:06:33.825000
Duration: 2320.0 ms
Changes:

# Fixed code
def get_enabled():
    """
    Return the enabled services

    CLI Example:

    .. code-block:: bash

        salt '*' service.get_enabled
    """

    if has_powershell():
        cmd = 'Get-WmiObject win32_service | where {$_.startmode -eq "Auto"} | select-object name'
        lines = __salt__["cmd.run"](cmd, shell="POWERSHELL").splitlines()
        return sorted([line.strip() for line in lines[3:]])
    else:
        ret = set()
        services = []
        cmd = list2cmdline(
            [
                "sc",
                "query",
                "type=",
                "service",
                "state=",
                "all",
                "bufsize=",
                str(BUFFSIZE),
            ]
        )
        lines = __salt__["cmd.run"](cmd).splitlines()
        for line in lines:
            if "SERVICE_NAME:" in line:
                comps = line.split(":", 1)
                if not len(comps) > 1:
                    continue
                services.append(comps[1].strip())
        for service in services:
            cmd2 = list2cmdline(["sc", "qc", service, str(BUFFSIZE)])
            lines = __salt__["cmd.run"](cmd2).splitlines()
            for line in lines:
                if "AUTO_START" in line:
                    ret.add(service)
        return sorted(ret)
# Buggy code
def get_disabled():
    """
    Return the disabled services

    CLI Example:

    .. code-block:: bash

        salt '*' service.get_disabled
    """
    if has_powershell():
        cmd = 'Get-WmiObject win32_service | where {$_.startmode -ne "Auto"} | select-object name'
        lines = __salt__["cmd.run"](cmd, shell="POWERSHELL").splitlines()
        return sorted([line.strip() for line in lines[3:]])
    else:
        ret = set()
        services = []
        cmd = "sc query type= service state= all bufsize= {0}".format(BUFFSIZE)
        lines = __salt__["cmd.run"](cmd).splitlines()
        for line in lines:
            if "SERVICE_NAME:" in line:
                comps = line.split(":", 1)
                if not len(comps) > 1:
                    continue
                services.append(comps[1].strip())
        for service in services:
            cmd2 = list2cmdline(["sc", "qc", service, BUFFSIZE])
            lines = __salt__["cmd.run"](cmd2).splitlines()
            for line in lines:
                if "DEMAND_START" in line:
                    ret.add(service)
                elif "DISABLED" in line:
                    ret.add(service)
        return sorted(ret)


# Traceback (TypeError)
ID: check_service
Function: service.running
Name: 135f1bc0-6c6e-11e4-9803-0800200c9a66
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "salt/state.py", line 1533, in call
File "salt/states/service.py", line 290, in running
File "salt/modules/win_service.py", line 256, in status
File "subprocess.py", line 618, in list2cmdline
TypeError: argument of type 'int' is not iterable
Started: 09:06:33.825000
Duration: 2320.0 ms
Changes:

# Fixed code
def get_disabled():
    """
    Return the disabled services

    CLI Example:

    .. code-block:: bash

        salt '*' service.get_disabled
    """
    if has_powershell():
        cmd = 'Get-WmiObject win32_service | where {$_.startmode -ne "Auto"} | select-object name'
        lines = __salt__["cmd.run"](cmd, shell="POWERSHELL").splitlines()
        return sorted([line.strip() for line in lines[3:]])
    else:
        ret = set()
        services = []
        cmd = list2cmdline(
            [
                "sc",
                "query",
                "type=",
                "service",
                "state=",
                "all",
                "bufsize=",
                str(BUFFSIZE),
            ]
        )
        lines = __salt__["cmd.run"](cmd).splitlines()
        for line in lines:
            if "SERVICE_NAME:" in line:
                comps = line.split(":", 1)
                if not len(comps) > 1:
                    continue
                services.append(comps[1].strip())
        for service in services:
            cmd2 = list2cmdline(["sc", "qc", service, BUFFSIZE])
            lines = __salt__["cmd.run"](cmd2).splitlines()
            for line in lines:
                if "DEMAND_START" in line:
                    ret.add(service)
                elif "DISABLED" in line:
                    ret.add(service)
        return sorted(ret)
# Buggy code
def status(name, sig=None):
    """
    Return the status for a service, returns the PID or an empty string if the
    service is running or not, pass a signature to use to find the service via
    ps

    CLI Example:

    .. code-block:: bash

        salt '*' service.status <service name> [service signature]
    """
    cmd = list2cmdline(["sc", "query", name, BUFFSIZE])
    statuses = __salt__["cmd.run"](cmd).splitlines()
    for line in statuses:
        if "RUNNING" in line:
            return True
        elif "STOP_PENDING" in line:
            return True
    return False


# Traceback (TypeError)
ID: check_service
Function: service.running
Name: 135f1bc0-6c6e-11e4-9803-0800200c9a66
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "salt/state.py", line 1533, in call
File "salt/states/service.py", line 290, in running
File "salt/modules/win_service.py", line 256, in status
File "subprocess.py", line 618, in list2cmdline
TypeError: argument of type 'int' is not iterable
Started: 09:06:33.825000
Duration: 2320.0 ms
Changes:

# Fixed code
def status(name, sig=None):
    """
    Return the status for a service, returns the PID or an empty string if the
    service is running or not, pass a signature to use to find the service via
    ps

    CLI Example:

    .. code-block:: bash

        salt '*' service.status <service name> [service signature]
    """
    cmd = list2cmdline(["sc", "query", name])
    statuses = __salt__["cmd.run"](cmd).splitlines()
    for line in statuses:
        if "RUNNING" in line:
            return True
        elif "STOP_PENDING" in line:
            return True
    return False
# Buggy code
def exists(name):
    """
    Verify that the named file or directory is present or exists.
    Ensures pre-requisites outside of Salt's purview
    (e.g., keytabs, private keys, etc.) have been previously satisfied before
    deployment.

    name
        Absolute path which must exist
    """
    ret = {"name": name, "changes": {}, "result": True, "comment": ""}
    if not os.path.exists(name):
        return _error(ret, ("Specified path {0} does not exist").format(name))

    ret["comment"] = "Path {0} exists".format(name)
    return ret


# Traceback (TypeError)
2014-11-24 16:03:42,245 [salt.minion      ][WARNING ] TypeError encountered executing state.highstate: expected string or buffer. See debug log for more info.  Possibly a missing arguments issue:  ArgSpec(args=['test', 'queue'], varargs=None, keywords='kwargs', defaults=(None, False))
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/salt/minion.py", line 809, in _thread_return
return_data = func(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/salt/modules/state.py", line 275, in highstate
force=kwargs.get('force', False)
File "/usr/lib/pymodules/python2.7/salt/state.py", line 2546, in call_highstate
return self.state.call_high(high)
File "/usr/lib/pymodules/python2.7/salt/state.py", line 1715, in call_high
ret = self.call_chunks(chunks)
File "/usr/lib/pymodules/python2.7/salt/state.py", line 1437, in call_chunks
running = self.call_chunk(low, running, chunks)
File "/usr/lib/pymodules/python2.7/salt/state.py", line 1562, in call_chunk
status = self.check_requisite(low, running, chunks, True)
File "/usr/lib/pymodules/python2.7/salt/state.py", line 1489, in check_requisite
if (fnmatch.fnmatch(chunk['name'], req_val) or
File "/usr/lib/python2.7/fnmatch.py", line 43, in fnmatch
return fnmatchcase(name, pat)
File "/usr/lib/python2.7/fnmatch.py", line 79, in fnmatchcase
return _cache[pat].match(name) is not None
TypeError: expected string or buffer

# Fixed code
def exists(name):
    """
    Verify that the named file or directory is present or exists.
    Ensures pre-requisites outside of Salt's purview
    (e.g., keytabs, private keys, etc.) have been previously satisfied before
    deployment.

    name
        Absolute path which must exist
    """
    ret = {"name": name, "changes": {}, "result": True, "comment": ""}
    if not name:
        return _error(ret, "Must provide name to file.exists")
    if not os.path.exists(name):
        return _error(ret, ("Specified path {0} does not exist").format(name))

    ret["comment"] = "Path {0} exists".format(name)
    return ret
# Buggy code
def missing(name):
    """
    Verify that the named file or directory is missing, this returns True only
    if the named file is missing but does not remove the file if it is present.

    name
        Absolute path which must NOT exist
    """
    ret = {"name": name, "changes": {}, "result": True, "comment": ""}
    if os.path.exists(name):
        return _error(ret, ("Specified path {0} exists").format(name))

    ret["comment"] = "Path {0} is missing".format(name)
    return ret


# Traceback (TypeError)
2014-11-24 16:03:42,245 [salt.minion      ][WARNING ] TypeError encountered executing state.highstate: expected string or buffer. See debug log for more info.  Possibly a missing arguments issue:  ArgSpec(args=['test', 'queue'], varargs=None, keywords='kwargs', defaults=(None, False))
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/salt/minion.py", line 809, in _thread_return
return_data = func(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/salt/modules/state.py", line 275, in highstate
force=kwargs.get('force', False)
File "/usr/lib/pymodules/python2.7/salt/state.py", line 2546, in call_highstate
return self.state.call_high(high)
File "/usr/lib/pymodules/python2.7/salt/state.py", line 1715, in call_high
ret = self.call_chunks(chunks)
File "/usr/lib/pymodules/python2.7/salt/state.py", line 1437, in call_chunks
running = self.call_chunk(low, running, chunks)
File "/usr/lib/pymodules/python2.7/salt/state.py", line 1562, in call_chunk
status = self.check_requisite(low, running, chunks, True)
File "/usr/lib/pymodules/python2.7/salt/state.py", line 1489, in check_requisite
if (fnmatch.fnmatch(chunk['name'], req_val) or
File "/usr/lib/python2.7/fnmatch.py", line 43, in fnmatch
return fnmatchcase(name, pat)
File "/usr/lib/python2.7/fnmatch.py", line 79, in fnmatchcase
return _cache[pat].match(name) is not None
TypeError: expected string or buffer

# Fixed code
def missing(name):
    """
    Verify that the named file or directory is missing, this returns True only
    if the named file is missing but does not remove the file if it is present.

    name
        Absolute path which must NOT exist
    """
    ret = {"name": name, "changes": {}, "result": True, "comment": ""}
    if not name:
        return _error(ret, "Must provide name to file.missing")
    if os.path.exists(name):
        return _error(ret, ("Specified path {0} exists").format(name))

    ret["comment"] = "Path {0} is missing".format(name)
    return ret
# Buggy code
def deploy(self):
    """
    Deploy salt-thin
    """
    if self.opts.get("_caller_cachedir"):
        cachedir = self.opts.get("_caller_cachedir")
    else:
        cachedir = self.opts["cachedir"]
    thin = salt.utils.thin.gen_thin(cachedir)
    self.shell.send(
        thin,
        os.path.join(self.thin_dir, "salt-thin.tgz"),
    )
    self.deploy_ext()
    return True


# 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 deploy(self):
    """
    Deploy salt-thin
    """
    self.shell.send(
        self.thin,
        os.path.join(self.thin_dir, "salt-thin.tgz"),
    )
    self.deploy_ext()
    return True
# Buggy code
def get_availability_zone(vm_):
    """
    Return the availability zone to use
    """
    avz = config.get_cloud_config_value(
        "availability_zone", vm_, __opts__, search_global=False
    )

    if avz is None:
        return None

    zones = _list_availability_zones(vm_)

    # Validate user-specified AZ
    if avz not in zones:
        raise SaltCloudException(
            "The specified availability zone isn't valid in this region: {}\n".format(
                avz
            )
        )

    # check specified AZ is available
    elif zones[avz] != "available":
        raise SaltCloudException(
            "The specified availability zone isn't currently available: {}\n".format(
                avz
            )
        )

    return avz


# Traceback (TypeError)
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/cloud/cli.py", line 321, in run
self.function_provider, self.function_name, kwargs
File "/usr/lib/python2.6/site-packages/salt/cloud/__init__.py", line 1053, in do_function
driver: self.clouds[fun](call='function')
File "/usr/lib64/python2.6/contextlib.py", line 34, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/lib/python2.6/site-packages/salt/utils/context.py", line 43, in func_globals_inject
yield
File "/usr/lib/python2.6/site-packages/salt/cloud/__init__.py", line 1053, in do_function
driver: self.clouds[fun](call='function')
TypeError: list_availability_zones() takes no arguments (1 given)

# Fixed code
def get_availability_zone(vm_):
    """
    Return the availability zone to use
    """
    avz = config.get_cloud_config_value(
        "availability_zone", vm_, __opts__, search_global=False
    )

    if avz is None:
        return None

    zones = list_availability_zones(vm_)

    # Validate user-specified AZ
    if avz not in zones:
        raise SaltCloudException(
            "The specified availability zone isn't valid in this region: {}\n".format(
                avz
            )
        )

    # check specified AZ is available
    elif zones[avz] != "available":
        raise SaltCloudException(
            "The specified availability zone isn't currently available: {}\n".format(
                avz
            )
        )

    return avz
# Buggy code
def get_availability_zone(vm_):
    """
    Return the availability zone to use
    """
    avz = config.get_cloud_config_value(
        "availability_zone", vm_, __opts__, search_global=False
    )

    if avz is None:
        return None

    zones = list_availability_zones()

    # Validate user-specified AZ
    if avz not in zones.keys():
        raise SaltCloudException(
            "The specified availability zone isn't valid in this region: {0}\n".format(
                avz
            )
        )

    # check specified AZ is available
    elif zones[avz] != "available":
        raise SaltCloudException(
            "The specified availability zone isn't currently available: {0}\n".format(
                avz
            )
        )

    return avz


# Traceback (TypeError)
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/cloud/cli.py", line 321, in run
self.function_provider, self.function_name, kwargs
File "/usr/lib/python2.6/site-packages/salt/cloud/__init__.py", line 1053, in do_function
driver: self.clouds[fun](call='function')
File "/usr/lib64/python2.6/contextlib.py", line 34, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/lib/python2.6/site-packages/salt/utils/context.py", line 43, in func_globals_inject
yield
File "/usr/lib/python2.6/site-packages/salt/cloud/__init__.py", line 1053, in do_function
driver: self.clouds[fun](call='function')
TypeError: list_availability_zones() takes no arguments (1 given)

# Fixed code
def get_availability_zone(vm_):
    """
    Return the availability zone to use
    """
    avz = config.get_cloud_config_value(
        "availability_zone", vm_, __opts__, search_global=False
    )

    if avz is None:
        return None

    zones = _list_availability_zones()

    # Validate user-specified AZ
    if avz not in zones.keys():
        raise SaltCloudException(
            "The specified availability zone isn't valid in this region: {0}\n".format(
                avz
            )
        )

    # check specified AZ is available
    elif zones[avz] != "available":
        raise SaltCloudException(
            "The specified availability zone isn't currently available: {0}\n".format(
                avz
            )
        )

    return avz
# Buggy code
def list_nodes_full():
    """
    Return a list of the VMs that are on the provider
    """
    ret = {}
    conn = get_conn()
    nodes = conn.get_registered_vms()
    for node in nodes:
        instance = conn.get_vm_by_path(node)
        properties = salt.utils.cloud.simple_types_filter(instance.get_properties())
        ret[properties["name"]] = {}
        for prop in (
            "guest_full_name",
            "guest_id",
            "memory_mb",
            "name",
            "num_cpu",
            "path",
            "devices",
            "disks",
            "files",
            "ip_address",
            "net",
            "hostname",
        ):
            if prop in properties:
                ret[properties["name"]][prop] = properties[prop]
        count = 0
        for disk in ret[properties["name"]]["disks"]:  # pylint: disable=W0612
            del ret[properties["name"]]["disks"][count]["device"]["_obj"]
            count += 1
        for device in ret[properties["name"]]["devices"]:
            del ret[properties["name"]]["devices"][device]["_obj"]
        ret[properties["name"]]["status"] = instance.get_status()
        ret[properties["name"]]["tools_status"] = instance.get_tools_status()
    return ret


# Traceback (TypeError)
salt-cloud -f list_nodes vsphere
[ERROR   ] There was an error running the function: list_nodes() takes no arguments (1 given)
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/salt/cloud/cli.py", line 221, in run
self.function_provider, self.function_name, kwargs
File "/usr/local/lib/python2.7/dist-packages/salt/cloud/__init__.py", line 1407, in do_function
driver: self.clouds[fun](call='function')
TypeError: list_nodes() takes no arguments (1 given)

# Fixed code
def list_nodes_full(kwargs=None, call=None):  # pylint: disable=W0613
    """
    Return a list of the VMs that are on the provider
    """
    ret = {}
    conn = get_conn()
    nodes = conn.get_registered_vms()
    for node in nodes:
        instance = conn.get_vm_by_path(node)
        properties = salt.utils.cloud.simple_types_filter(instance.get_properties())
        ret[properties["name"]] = {}
        for prop in (
            "guest_full_name",
            "guest_id",
            "memory_mb",
            "name",
            "num_cpu",
            "path",
            "devices",
            "disks",
            "files",
            "ip_address",
            "net",
            "hostname",
        ):
            if prop in properties:
                ret[properties["name"]][prop] = properties[prop]
        count = 0
        for disk in ret[properties["name"]]["disks"]:  # pylint: disable=W0612
            del ret[properties["name"]]["disks"][count]["device"]["_obj"]
            count += 1
        for device in ret[properties["name"]]["devices"]:
            del ret[properties["name"]]["devices"][device]["_obj"]
        ret[properties["name"]]["status"] = instance.get_status()
        ret[properties["name"]]["tools_status"] = instance.get_tools_status()
    return ret
# Buggy code
def list_nodes_min():
    """
    Return a list of the nodes in the provider, with no details
    """
    log.debug("function list_nodes_min()")
    ret = {}
    conn = get_conn()
    nodes = conn.get_registered_vms()
    for node in nodes:
        comps1 = node.split()
        comps2 = comps1[1].split("/")
        ret[comps2[0]] = True

    return ret


# Traceback (TypeError)
salt-cloud -f list_nodes vsphere
[ERROR   ] There was an error running the function: list_nodes() takes no arguments (1 given)
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/salt/cloud/cli.py", line 221, in run
self.function_provider, self.function_name, kwargs
File "/usr/local/lib/python2.7/dist-packages/salt/cloud/__init__.py", line 1407, in do_function
driver: self.clouds[fun](call='function')
TypeError: list_nodes() takes no arguments (1 given)

# Fixed code
def list_nodes_min(kwargs=None, call=None):  # pylint: disable=W0613
    """
    Return a list of the nodes in the provider, with no details
    """
    log.debug("function list_nodes_min()")
    ret = {}
    conn = get_conn()
    nodes = conn.get_registered_vms()
    for node in nodes:
        comps1 = node.split()
        comps2 = comps1[1].split("/")
        ret[comps2[0]] = True

    return ret
# Buggy code
def list_nodes():
    """
    Return a list of the VMs that are on the provider
    """
    ret = {}
    conn = get_conn()
    nodes = conn.get_registered_vms()
    for node in nodes:
        instance = conn.get_vm_by_path(node)
        properties = salt.utils.cloud.simple_types_filter(instance.get_properties())
        ret[properties["name"]] = {
            "id": properties["name"],
            "ram": properties["memory_mb"],
            "cpus": properties["num_cpu"],
        }
        if "ip_address" in properties:
            ret[properties["name"]]["ip_address"] = properties["ip_address"]
    return ret


# Traceback (TypeError)
salt-cloud -f list_nodes vsphere
[ERROR   ] There was an error running the function: list_nodes() takes no arguments (1 given)
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/salt/cloud/cli.py", line 221, in run
self.function_provider, self.function_name, kwargs
File "/usr/local/lib/python2.7/dist-packages/salt/cloud/__init__.py", line 1407, in do_function
driver: self.clouds[fun](call='function')
TypeError: list_nodes() takes no arguments (1 given)

# Fixed code
def list_nodes(kwargs=None, call=None):  # pylint: disable=W0613
    """
    Return a list of the VMs that are on the provider
    """
    ret = {}
    conn = get_conn()
    nodes = conn.get_registered_vms()
    for node in nodes:
        instance = conn.get_vm_by_path(node)
        properties = salt.utils.cloud.simple_types_filter(instance.get_properties())
        ret[properties["name"]] = {
            "id": properties["name"],
            "ram": properties["memory_mb"],
            "cpus": properties["num_cpu"],
        }
        if "ip_address" in properties:
            ret[properties["name"]]["ip_address"] = properties["ip_address"]
    return ret
# Buggy code
def refresh_pillar():
    """
    Signal the minion to refresh the pillar data.

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.refresh_pillar
    """
    return __salt__["event.fire"]({}, "pillar_refresh")


# Traceback (KeyError)
The minion function caused an exception: Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/salt/minion.py", line 793, in _thread_return
return_data = func(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/salt/modules/saltutil.py", line 331, in sync_all
refresh_modules()
File "/usr/lib/pymodules/python2.7/salt/modules/saltutil.py", line 358, in refresh_modules
__salt__['event.fire']({}, 'module_refresh')
KeyError: 'event.fire'

# Fixed code
def refresh_pillar():
    """
    Signal the minion to refresh the pillar data.

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.refresh_pillar
    """
    try:
        ret = __salt__["event.fire"]({}, "pillar_refresh")
    except Exception as exc:
        log.error("Event module not available. Module refresh failed.")
        ret = False  # Effectively a no-op, since we can't really return without an event system
    return ret
# Buggy code
def refresh_modules():
    """
    Signal the minion to refresh the module and grain data

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.refresh_modules
    """
    return __salt__["event.fire"]({}, "module_refresh")


# Traceback (KeyError)
The minion function caused an exception: Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/salt/minion.py", line 793, in _thread_return
return_data = func(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/salt/modules/saltutil.py", line 331, in sync_all
refresh_modules()
File "/usr/lib/pymodules/python2.7/salt/modules/saltutil.py", line 358, in refresh_modules
__salt__['event.fire']({}, 'module_refresh')
KeyError: 'event.fire'

# Fixed code
def refresh_modules():
    """
    Signal the minion to refresh the module and grain data

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.refresh_modules
    """
    try:
        ret = __salt__["event.fire"]({}, "module_refresh")
    except Exception as exc:
        log.error("Event module not available. Module refresh failed.")
        ret = False  # Effectively a no-op, since we can't really return without an event system
    return ret
# Buggy code
def __exit__(self, exc_type, exc_value, traceback):
    self.close(force=True)
    # Wait for the process to terminate, to avoid zombies.
    self.wait()


# Traceback (OSError)
2014-02-12 13:06:50,022 [salt.utils.cloud ][DEBUG   ] SSH command: "ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -oPasswordAuthentication=no -oChallengeResponseAuthentica
tion=no -oPubkeyAuthentication=yes -oKbdInteractiveAuthentication=no -i /mnt/stackdio_root/stackdio/storage/cloud/aws-qatp/id_rsa root@10.44.13.132 '/tmp/.saltcloud/deploy.sh -c /tmp/.saltcloud -D git 3a894d76069
9ab155bc63a3e35e6730f87cc7d8c'"
2014-02-12 13:06:50,024 [salt.utils.vt    ][WARNING ] Failed to spawn the VT: out of pty devices
Traceback (most recent call last):
File "/home/stackdio/.virtualenvs/stackdio/src/salt/salt/utils/vt.py", line 198, in __init__
self._spawn()
File "/home/stackdio/.virtualenvs/stackdio/src/salt/salt/utils/vt.py", line 377, in _spawn
self.pid, self.child_fd, self.child_fde = self.__fork_ptys()
File "/home/stackdio/.virtualenvs/stackdio/src/salt/salt/utils/vt.py", line 451, in __fork_ptys
stderr_parent_fd, stderr_child_fd = pty.openpty()
File "/usr/lib/python2.7/pty.py", line 29, in openpty
master_fd, slave_name = _open_terminal()
File "/usr/lib/python2.7/pty.py", line 70, in _open_terminal
raise os.error, 'out of pty devices'
OSError: out of pty devices
2014-02-12 13:06:50,025 [salt.utils.cloud ][ERROR   ] Failed to execute command '/tmp/.saltcloud/deploy.sh -c /tmp/.saltcloud -D git 3a894d760699ab155bc63a3e35e6730f87cc7d8c': Failed to spawn the VT. Error: out of pty devices
Traceback (most recent call last):
File "/home/stackdio/.virtualenvs/stackdio/src/salt/salt/utils/cloud.py", line 1235, in root_cmd
stream_stderr=kwargs.get('display_ssh_output', True)
File "/home/stackdio/.virtualenvs/stackdio/src/salt/salt/utils/vt.py", line 207, in __init__
'Failed to spawn the VT. Error: {0}'.format(err)
TerminalException: Failed to spawn the VT. Error: out of pty devices
2014-02-12 13:06:50,026 [salt.cloud       ][ERROR   ] Failed to deploy 'test-spot-dn-126'. Error: Executing the command '/tmp/.saltcloud/deploy.sh -c /tmp/.saltcloud -D git 3a894d760699ab155bc63a3e35e6730f87cc7d8c' failed
Traceback (most recent call last):
File "/home/stackdio/.virtualenvs/stackdio/src/salt/salt/cloud/__init__.py", line 1699, in create_multiprocessing
local_master=parallel_data['local_master']
File "/home/stackdio/.virtualenvs/stackdio/src/salt/salt/cloud/__init__.py", line 854, in create
output = self.clouds[func](vm_)
File "/home/stackdio/.virtualenvs/stackdio/src/salt/salt/cloud/clouds/ec2.py", line 1576, in create
deployed = salt.utils.cloud.deploy_script(**deploy_kwargs)
File "/home/stackdio/.virtualenvs/stackdio/src/salt/salt/utils/cloud.py", line 864, in deploy_script
deploy_command
SaltCloudSystemExit: Executing the command '/tmp/.saltcloud/deploy.sh -c /tmp/.saltcloud -D git 3a894d760699ab155bc63a3e35e6730f87cc7d8c' failed

# Fixed code
def __exit__(self, exc_type, exc_value, traceback):
    self.close(force=True)
    # Wait for the process to terminate, to avoid zombies.
    if self.isalive():
        self.wait()
# Buggy code
def save_load(jid, clear_load):
    """
    Save the load to the specified jid
    """
    jid_dir = _jid_dir(clear_load["jid"])

    serial = salt.payload.Serial(__opts__)

    # if you have a tgt, save that for the UI etc
    if "tgt" in clear_load:
        ckminions = salt.utils.minions.CkMinions(__opts__)
        # Retrieve the minions list
        minions = ckminions.check_minions(
            clear_load["tgt"], clear_load.get("tgt_type", "glob")
        )
        # save the minions to a cache so we can see in the UI
        serial.dump(minions, salt.utils.fopen(os.path.join(jid_dir, MINIONS_P), "w+b"))

    # Save the invocation information
    serial.dump(clear_load, salt.utils.fopen(os.path.join(jid_dir, LOAD_P), "w+b"))


# Traceback (IOError)
2014-05-22 13:05:42,936 [salt.master                              ][ERROR   ] Error in function _syndic_return:
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/salt/master.py", line 1527, in run_func
ret = getattr(self, func)(load)
File "/usr/lib/pymodules/python2.7/salt/master.py", line 1285, in _syndic_return
self.mminion.returners[fstr](load['jid'], load)
File "/usr/lib/pymodules/python2.7/salt/returners/local_cache.py", line 191, in save_load
salt.utils.fopen(os.path.join(jid_dir, LOAD_P), 'w+b')
File "/usr/lib/pymodules/python2.7/salt/utils/__init__.py", line 1098, in fopen
fhandle = open(*args, **kwargs)
IOError: [Errno 2] No such file or directory: '/var/cache/salt/master/jobs/4a/c8c5814389de2debc586a7d9135e71/.load.p'

# Fixed code
def save_load(jid, clear_load):
    """
    Save the load to the specified jid
    """
    jid_dir = _jid_dir(clear_load["jid"])

    serial = salt.payload.Serial(__opts__)

    # if you have a tgt, save that for the UI etc
    if "tgt" in clear_load:
        ckminions = salt.utils.minions.CkMinions(__opts__)
        # Retrieve the minions list
        minions = ckminions.check_minions(
            clear_load["tgt"], clear_load.get("tgt_type", "glob")
        )
        # save the minions to a cache so we can see in the UI
        try:
            serial.dump(
                minions, salt.utils.fopen(os.path.join(jid_dir, MINIONS_P), "w+b")
            )
        except IOError:
            pass

    # Save the invocation information
    try:
        serial.dump(clear_load, salt.utils.fopen(os.path.join(jid_dir, LOAD_P), "w+b"))
    except IOError:
        pass
# Buggy code
def _crypted_transfer(self, load, tries=3, timeout=60, payload="aes"):
    """
    In case of authentication errors, try to renogiate authentication
    and retry the method.
    Indeed, we can fail too early in case of a master restart during a
    minion state executon call
    """

    def _do_transfer():
        return self.auth.crypticle.loads(
            self.sreq.send(payload, self.auth.crypticle.dumps(load), tries, timeout)
        )

    try:
        return _do_transfer()
    except salt.crypt.AuthenticationError:
        self.auth = salt.crypt.SAuth(self.opts)
        return _do_transfer()


# Traceback (012ValueError)
[ERROR   ] Error in function _file_hash:
#012Traceback (most recent call last):
#012  File "/usr/lib/python2.6/site-packages/salt/master.py", line 1444, in run_func
#012    ret = getattr(self, func)(load)
#012  File "/usr/lib/python2.6/site-packages/salt/fileserver/__init__.py", line 233, in file_hash
#012    return self.servers[fstr](load, fnd)
#012  File "/usr/lib/python2.6/site-packages/salt/fileserver/roots.py", line 153, in file_hash
#012    hsum, mtime = fp_.read().split(':')
#012ValueError: need more than 1 value to unpack

# Fixed code
def _crypted_transfer(self, load, tries=3, timeout=60, payload="aes"):
    """
    In case of authentication errors, try to renegotiate authentication
    and retry the method.
    Indeed, we can fail too early in case of a master restart during a
    minion state execution call
    """

    def _do_transfer():
        return self.auth.crypticle.loads(
            self.sreq.send(payload, self.auth.crypticle.dumps(load), tries, timeout)
        )

    try:
        return _do_transfer()
    except salt.crypt.AuthenticationError:
        self.auth = salt.crypt.SAuth(self.opts)
        return _do_transfer()
# Buggy code
def update(self, back=None):
    """
    Update all of the fileservers that support the update function or the
    named fileserver only.
    """
    back = self._gen_back(back)
    for fsb in back:
        fstr = "{0}.update".format(fsb)
        if fstr in self.servers:
            self.servers[fstr]()


# Traceback (012ValueError)
[ERROR   ] Error in function _file_hash:
#012Traceback (most recent call last):
#012  File "/usr/lib/python2.6/site-packages/salt/master.py", line 1444, in run_func
#012    ret = getattr(self, func)(load)
#012  File "/usr/lib/python2.6/site-packages/salt/fileserver/__init__.py", line 233, in file_hash
#012    return self.servers[fstr](load, fnd)
#012  File "/usr/lib/python2.6/site-packages/salt/fileserver/roots.py", line 153, in file_hash
#012    hsum, mtime = fp_.read().split(':')
#012ValueError: need more than 1 value to unpack

# Fixed code
def update(self, back=None):
    """
    Update all of the file-servers that support the update function or the
    named fileserver only.
    """
    back = self._gen_back(back)
    for fsb in back:
        fstr = "{0}.update".format(fsb)
        if fstr in self.servers:
            self.servers[fstr]()