gurudesh/pytracebugs huggingface dataset:
# Buggy code
def returners(opts, functions, whitelist=None, context=None):
    """
    Returns the returner modules
    """
    if context is None:
        context = {}
    return LazyLoader(
        _module_dirs(opts, "returners", "returner"),
        opts,
        tag="returner",
        whitelist=whitelist,
        pack={"__salt__": functions, "__context__": context},
    )


# Traceback (RuntimeError)
2015-05-05 15:52:48,917 [salt.loader                                ][ERROR   ][25815] Failed to read the virtual function for states: xmpp
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1098, in process_virtual
virtual = mod.__virtual__()
File "/usr/lib/python2.6/site-packages/salt/states/xmpp.py", line 25, in __virtual__
return 'xmpp' if 'xmpp.send_msg' in __salt__ else False
File "/usr/lib64/python2.6/_abcoll.py", line 342, in __contains__
self[key]
File "/usr/lib/python2.6/site-packages/salt/utils/lazy.py", line 85, in __getitem__
if self._load(key):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1024, in _load
ret = _inner_load(mod_name)
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1013, in _inner_load
if self._load_module(name) and key in self._dict:
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 990, in _load_module
Depends.enforce_dependencies(self._dict, self.tag)
File "/usr/lib/python2.6/site-packages/salt/utils/decorators/__init__.py", line 81, in enforce_dependencies
for module, func, fallback_function in dependent_set:
RuntimeError: Set changed size during iteration

# Fixed code
def returners(opts, functions, whitelist=None, context=None):
    """
    Returns the returner modules
    """
    return LazyLoader(
        _module_dirs(opts, "returners", "returner"),
        opts,
        tag="returner",
        whitelist=whitelist,
        pack={"__salt__": functions, "__context__": context},
    )
# Buggy code
def utils(opts, whitelist=None, context=None):
    """
    Returns the utility modules
    """
    if context is None:
        context = {}
    return LazyLoader(
        _module_dirs(opts, "utils", "utils", ext_type_dirs="utils_dirs"),
        opts,
        tag="utils",
        whitelist=whitelist,
        pack={"__context__": context},
    )


# Traceback (RuntimeError)
2015-05-05 15:52:48,917 [salt.loader                                ][ERROR   ][25815] Failed to read the virtual function for states: xmpp
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1098, in process_virtual
virtual = mod.__virtual__()
File "/usr/lib/python2.6/site-packages/salt/states/xmpp.py", line 25, in __virtual__
return 'xmpp' if 'xmpp.send_msg' in __salt__ else False
File "/usr/lib64/python2.6/_abcoll.py", line 342, in __contains__
self[key]
File "/usr/lib/python2.6/site-packages/salt/utils/lazy.py", line 85, in __getitem__
if self._load(key):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1024, in _load
ret = _inner_load(mod_name)
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1013, in _inner_load
if self._load_module(name) and key in self._dict:
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 990, in _load_module
Depends.enforce_dependencies(self._dict, self.tag)
File "/usr/lib/python2.6/site-packages/salt/utils/decorators/__init__.py", line 81, in enforce_dependencies
for module, func, fallback_function in dependent_set:
RuntimeError: Set changed size during iteration

# Fixed code
def utils(opts, whitelist=None, context=None):
    """
    Returns the utility modules
    """
    return LazyLoader(
        _module_dirs(opts, "utils", "utils", ext_type_dirs="utils_dirs"),
        opts,
        tag="utils",
        whitelist=whitelist,
        pack={"__context__": context},
    )
# Buggy code
def pillars(opts, functions, context=None):
    """
    Returns the pillars modules
    """
    if context is None:
        context = {}
    ret = LazyLoader(
        _module_dirs(opts, "pillar", "pillar"),
        opts,
        tag="pillar",
        pack={"__salt__": functions, "__context__": context},
    )
    return FilterDictWrapper(ret, ".ext_pillar")


# Traceback (RuntimeError)
2015-05-05 15:52:48,917 [salt.loader                                ][ERROR   ][25815] Failed to read the virtual function for states: xmpp
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1098, in process_virtual
virtual = mod.__virtual__()
File "/usr/lib/python2.6/site-packages/salt/states/xmpp.py", line 25, in __virtual__
return 'xmpp' if 'xmpp.send_msg' in __salt__ else False
File "/usr/lib64/python2.6/_abcoll.py", line 342, in __contains__
self[key]
File "/usr/lib/python2.6/site-packages/salt/utils/lazy.py", line 85, in __getitem__
if self._load(key):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1024, in _load
ret = _inner_load(mod_name)
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1013, in _inner_load
if self._load_module(name) and key in self._dict:
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 990, in _load_module
Depends.enforce_dependencies(self._dict, self.tag)
File "/usr/lib/python2.6/site-packages/salt/utils/decorators/__init__.py", line 81, in enforce_dependencies
for module, func, fallback_function in dependent_set:
RuntimeError: Set changed size during iteration

# Fixed code
def pillars(opts, functions, context=None):
    """
    Returns the pillars modules
    """
    ret = LazyLoader(
        _module_dirs(opts, "pillar", "pillar"),
        opts,
        tag="pillar",
        pack={"__salt__": functions, "__context__": context},
    )
    return FilterDictWrapper(ret, ".ext_pillar")
# Buggy code
def beacons(opts, functions, context=None):
    """
    Load the beacon modules

    :param dict opts: The Salt options dictionary
    :param dict functions: A dictionary of minion modules, with module names as
                            keys and funcs as values.
    """
    if context is None:
        context = {}
    return LazyLoader(
        _module_dirs(opts, "beacons", "beacons"),
        opts,
        tag="beacons",
        pack={"__context__": context, "__salt__": functions},
    )


# Traceback (RuntimeError)
2015-05-05 15:52:48,917 [salt.loader                                ][ERROR   ][25815] Failed to read the virtual function for states: xmpp
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1098, in process_virtual
virtual = mod.__virtual__()
File "/usr/lib/python2.6/site-packages/salt/states/xmpp.py", line 25, in __virtual__
return 'xmpp' if 'xmpp.send_msg' in __salt__ else False
File "/usr/lib64/python2.6/_abcoll.py", line 342, in __contains__
self[key]
File "/usr/lib/python2.6/site-packages/salt/utils/lazy.py", line 85, in __getitem__
if self._load(key):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1024, in _load
ret = _inner_load(mod_name)
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1013, in _inner_load
if self._load_module(name) and key in self._dict:
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 990, in _load_module
Depends.enforce_dependencies(self._dict, self.tag)
File "/usr/lib/python2.6/site-packages/salt/utils/decorators/__init__.py", line 81, in enforce_dependencies
for module, func, fallback_function in dependent_set:
RuntimeError: Set changed size during iteration

# Fixed code
def beacons(opts, functions, context=None):
    """
    Load the beacon modules

    :param dict opts: The Salt options dictionary
    :param dict functions: A dictionary of minion modules, with module names as
                            keys and funcs as values.
    """
    return LazyLoader(
        _module_dirs(opts, "beacons", "beacons"),
        opts,
        tag="beacons",
        pack={"__context__": context, "__salt__": functions},
    )
# Buggy code
def ssh_wrapper(opts, functions=None, context=None):
    """
    Returns the custom logging handler modules
    """
    if context is None:
        context = {}
    if functions is None:
        functions = {}
    return LazyLoader(
        _module_dirs(
            opts,
            "wrapper",
            "wrapper",
            base_path=os.path.join(SALT_BASE_PATH, os.path.join("client", "ssh")),
        ),
        opts,
        tag="wrapper",
        pack={"__salt__": functions, "__context__": context},
    )


# Traceback (RuntimeError)
2015-05-05 15:52:48,917 [salt.loader                                ][ERROR   ][25815] Failed to read the virtual function for states: xmpp
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1098, in process_virtual
virtual = mod.__virtual__()
File "/usr/lib/python2.6/site-packages/salt/states/xmpp.py", line 25, in __virtual__
return 'xmpp' if 'xmpp.send_msg' in __salt__ else False
File "/usr/lib64/python2.6/_abcoll.py", line 342, in __contains__
self[key]
File "/usr/lib/python2.6/site-packages/salt/utils/lazy.py", line 85, in __getitem__
if self._load(key):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1024, in _load
ret = _inner_load(mod_name)
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1013, in _inner_load
if self._load_module(name) and key in self._dict:
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 990, in _load_module
Depends.enforce_dependencies(self._dict, self.tag)
File "/usr/lib/python2.6/site-packages/salt/utils/decorators/__init__.py", line 81, in enforce_dependencies
for module, func, fallback_function in dependent_set:
RuntimeError: Set changed size during iteration

# Fixed code
def ssh_wrapper(opts, functions=None, context=None):
    """
    Returns the custom logging handler modules
    """
    return LazyLoader(
        _module_dirs(
            opts,
            "wrapper",
            "wrapper",
            base_path=os.path.join(SALT_BASE_PATH, os.path.join("client", "ssh")),
        ),
        opts,
        tag="wrapper",
        pack={"__salt__": functions, "__context__": context},
    )
# Buggy code
def __prep_mod_opts(self, opts):
    """
    Strip out of the opts any logger instance
    """
    if "grains" in opts:
        self._grains = opts["grains"]
    else:
        self._grains = {}
    if "pillar" in opts:
        self._pillar = opts["pillar"]
    else:
        self._pillar = {}

    mod_opts = {}
    for key, val in list(opts.items()):
        if key == "logger":
            continue
        mod_opts[key] = val
    return mod_opts


# Traceback (RuntimeError)
2015-05-05 15:52:48,917 [salt.loader                                ][ERROR   ][25815] Failed to read the virtual function for states: xmpp
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1098, in process_virtual
virtual = mod.__virtual__()
File "/usr/lib/python2.6/site-packages/salt/states/xmpp.py", line 25, in __virtual__
return 'xmpp' if 'xmpp.send_msg' in __salt__ else False
File "/usr/lib64/python2.6/_abcoll.py", line 342, in __contains__
self[key]
File "/usr/lib/python2.6/site-packages/salt/utils/lazy.py", line 85, in __getitem__
if self._load(key):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1024, in _load
ret = _inner_load(mod_name)
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1013, in _inner_load
if self._load_module(name) and key in self._dict:
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 990, in _load_module
Depends.enforce_dependencies(self._dict, self.tag)
File "/usr/lib/python2.6/site-packages/salt/utils/decorators/__init__.py", line 81, in enforce_dependencies
for module, func, fallback_function in dependent_set:
RuntimeError: Set changed size during iteration

# Fixed code
def __prep_mod_opts(self, opts):
    """
    Strip out of the opts any logger instance
    """
    if "__grains__" not in self.pack:
        self.context_dict["grains"] = opts.get("grains", {})
        self.pack["__grains__"] = salt.utils.context.NamespacedDictWrapper(
            self.context_dict, "grains"
        )

    if "__pillar__" not in self.pack:
        self.context_dict["pillar"] = opts.get("pillar", {})
        self.pack["__pillar__"] = salt.utils.context.NamespacedDictWrapper(
            self.context_dict, "pillar"
        )

    mod_opts = {}
    for key, val in list(opts.items()):
        if key == "logger":
            continue
        mod_opts[key] = val
    return mod_opts
# Buggy code
def global_injector_decorator(inject_globals):
    """
    Decorator used by the LazyLoader to inject globals into a function at
    execute time.

    globals
        Dictionary with global variables to inject
    """

    def inner_decorator(f):
        @functools.wraps(f)
        def wrapper(*args, **kwargs):
            with context.func_globals_inject(f, **inject_globals):
                return f(*args, **kwargs)

        return wrapper

    return inner_decorator


# Traceback (RuntimeError)
2015-05-05 15:52:48,917 [salt.loader                                ][ERROR   ][25815] Failed to read the virtual function for states: xmpp
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1098, in process_virtual
virtual = mod.__virtual__()
File "/usr/lib/python2.6/site-packages/salt/states/xmpp.py", line 25, in __virtual__
return 'xmpp' if 'xmpp.send_msg' in __salt__ else False
File "/usr/lib64/python2.6/_abcoll.py", line 342, in __contains__
self[key]
File "/usr/lib/python2.6/site-packages/salt/utils/lazy.py", line 85, in __getitem__
if self._load(key):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1024, in _load
ret = _inner_load(mod_name)
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1013, in _inner_load
if self._load_module(name) and key in self._dict:
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 990, in _load_module
Depends.enforce_dependencies(self._dict, self.tag)
File "/usr/lib/python2.6/site-packages/salt/utils/decorators/__init__.py", line 81, in enforce_dependencies
for module, func, fallback_function in dependent_set:
RuntimeError: Set changed size during iteration

# Fixed code
def global_injector_decorator(inject_globals):
    """
    Decorator used by the LazyLoader to inject globals into a function at
    execute time.

    globals
        Dictionary with global variables to inject
    """

    def inner_decorator(f):
        @functools.wraps(f)
        def wrapper(*args, **kwargs):
            with salt.utils.context.func_globals_inject(f, **inject_globals):
                return f(*args, **kwargs)

        return wrapper

    return inner_decorator
# Buggy code
def inner_decorator(f):
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        with context.func_globals_inject(f, **inject_globals):
            return f(*args, **kwargs)

    return wrapper


# Traceback (RuntimeError)
2015-05-05 15:52:48,917 [salt.loader                                ][ERROR   ][25815] Failed to read the virtual function for states: xmpp
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1098, in process_virtual
virtual = mod.__virtual__()
File "/usr/lib/python2.6/site-packages/salt/states/xmpp.py", line 25, in __virtual__
return 'xmpp' if 'xmpp.send_msg' in __salt__ else False
File "/usr/lib64/python2.6/_abcoll.py", line 342, in __contains__
self[key]
File "/usr/lib/python2.6/site-packages/salt/utils/lazy.py", line 85, in __getitem__
if self._load(key):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1024, in _load
ret = _inner_load(mod_name)
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1013, in _inner_load
if self._load_module(name) and key in self._dict:
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 990, in _load_module
Depends.enforce_dependencies(self._dict, self.tag)
File "/usr/lib/python2.6/site-packages/salt/utils/decorators/__init__.py", line 81, in enforce_dependencies
for module, func, fallback_function in dependent_set:
RuntimeError: Set changed size during iteration

# Fixed code
def inner_decorator(f):
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        with salt.utils.context.func_globals_inject(f, **inject_globals):
            return f(*args, **kwargs)

    return wrapper
# Buggy code
def wrapper(*args, **kwargs):
    with context.func_globals_inject(f, **inject_globals):
        return f(*args, **kwargs)


# Traceback (RuntimeError)
2015-05-05 15:52:48,917 [salt.loader                                ][ERROR   ][25815] Failed to read the virtual function for states: xmpp
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1098, in process_virtual
virtual = mod.__virtual__()
File "/usr/lib/python2.6/site-packages/salt/states/xmpp.py", line 25, in __virtual__
return 'xmpp' if 'xmpp.send_msg' in __salt__ else False
File "/usr/lib64/python2.6/_abcoll.py", line 342, in __contains__
self[key]
File "/usr/lib/python2.6/site-packages/salt/utils/lazy.py", line 85, in __getitem__
if self._load(key):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1024, in _load
ret = _inner_load(mod_name)
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1013, in _inner_load
if self._load_module(name) and key in self._dict:
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 990, in _load_module
Depends.enforce_dependencies(self._dict, self.tag)
File "/usr/lib/python2.6/site-packages/salt/utils/decorators/__init__.py", line 81, in enforce_dependencies
for module, func, fallback_function in dependent_set:
RuntimeError: Set changed size during iteration

# Fixed code
def wrapper(*args, **kwargs):
    with salt.utils.context.func_globals_inject(f, **inject_globals):
        return f(*args, **kwargs)
# Buggy code
def _traverse(tree, blobs, prefix):
    """
    Traverse through a pygit2 Tree object recursively, accumulating all
    the file paths and symlink info in the "blobs" dict
    """
    for entry in iter(tree):
        obj = self.repo[entry.oid]
        if isinstance(obj, pygit2.Blob):
            repo_path = os.path.join(prefix, entry.name)
            blobs.setdefault("files", []).append(repo_path)
            if stat.S_ISLNK(tree[entry.name].filemode):
                link_tgt = self.repo[tree[entry.name].oid].data
                blobs.setdefault("symlinks", {})[repo_path] = link_tgt
        elif isinstance(obj, pygit2.Tree):
            _traverse(obj, blobs, os.path.join(prefix, entry.name))


# Traceback (KeyError)
2015-12-11 17:28:20,418 [salt.master      ][ERROR   ][1255] Error in function _file_list:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/master.py", line 1379, in run_func
ret = getattr(self, func)(load)
File "/usr/lib/python2.7/dist-packages/salt/fileserver/__init__.py", line 607, in file_list
ret.update(self.servers[fstr](load))
File "/usr/lib/python2.7/dist-packages/salt/fileserver/gitfs.py", line 180, in file_list
return gitfs.file_list(load)
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 2308, in file_list
return self._file_lists(load, 'files')
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 2285, in _file_lists
repo_files, repo_symlinks = repo.file_list(load['saltenv'])
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 1017, in file_list
_traverse(tree, blobs, self.root)
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 994, in _traverse
_traverse(obj, blobs, os.path.join(prefix, entry.name))
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 994, in _traverse
_traverse(obj, blobs, os.path.join(prefix, entry.name))
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 994, in _traverse
_traverse(obj, blobs, os.path.join(prefix, entry.name))
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 986, in _traverse
obj = self.repo[entry.oid]
File "/usr/local/lib/python2.7/dist-packages/pygit2/repository.py", line 99, in __getitem__
raise KeyError(key)
KeyError: f16c3f1b33223c7ab82744fb00e6bbc3f48ce61b

# Fixed code
def _traverse(tree, blobs, prefix):
    """
    Traverse through a pygit2 Tree object recursively, accumulating all
    the file paths and symlink info in the "blobs" dict
    """
    for entry in iter(tree):
        if entry.oid not in self.repo:
            # Entry is a submodule, skip it
            continue
        obj = self.repo[entry.oid]
        if isinstance(obj, pygit2.Blob):
            repo_path = os.path.join(prefix, entry.name)
            blobs.setdefault("files", []).append(repo_path)
            if stat.S_ISLNK(tree[entry.name].filemode):
                link_tgt = self.repo[tree[entry.name].oid].data
                blobs.setdefault("symlinks", {})[repo_path] = link_tgt
        elif isinstance(obj, pygit2.Tree):
            _traverse(obj, blobs, os.path.join(prefix, entry.name))
# Buggy code
def upgrade(refresh=False):
    """
    Run a full system upgrade, a pacman -Syu

    refresh
        Whether or not to refresh the package database before installing.

    Return a dict containing the new package names and versions::

        {'<package>': {'old': '<old-version>',
                       'new': '<new-version>'}}

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.upgrade
    """
    ret = {
        "changes": {},
        "result": True,
        "comment": "",
    }

    old = list_pkgs()
    cmd = "pacman -Su --noprogressbar --noconfirm"
    if salt.utils.is_true(refresh):
        cmd += " -y"
    call = __salt__["cmd.run_all"](cmd, output_loglevel="trace")
    if call["retcode"] != 0:
        ret["result"] = False
        if "stderr" in call:
            ret["comment"] += call["stderr"]
        if "stdout" in call:
            ret["comment"] += call["stdout"]
    else:
        __context__.pop("pkg.list_pkgs", None)
        new = list_pkgs()
        ret["changes"] = salt.utils.compare_dicts(old, new)
    return ret


# Traceback (TypeError)
skynet.
----------
ID: uptodate
Function: pkg.uptodate
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/state.py", line 1594, in call
**cdata['kwargs'])
File "/usr/lib/python2.7/site-packages/salt/loader.py", line 1491, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/salt/states/pkg.py", line 1808, in uptodate
updated = __salt__['pkg.upgrade'](refresh=refresh, **kwargs)
TypeError: upgrade() got an unexpected keyword argument '__agg__'
Started: 20:18:41.390723
Duration: 1848.303 ms
Changes:

Summary for skynet
------------
Succeeded: 0
Failed:    1

# Fixed code
def upgrade(refresh=False, **kwargs):
    """
    Run a full system upgrade, a pacman -Syu

    refresh
        Whether or not to refresh the package database before installing.

    Return a dict containing the new package names and versions::

        {'<package>': {'old': '<old-version>',
                       'new': '<new-version>'}}

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.upgrade
    """
    ret = {
        "changes": {},
        "result": True,
        "comment": "",
    }

    old = list_pkgs()
    cmd = "pacman -Su --noprogressbar --noconfirm"
    if salt.utils.is_true(refresh):
        cmd += " -y"
    call = __salt__["cmd.run_all"](cmd, output_loglevel="trace")
    if call["retcode"] != 0:
        ret["result"] = False
        if "stderr" in call:
            ret["comment"] += call["stderr"]
        if "stdout" in call:
            ret["comment"] += call["stdout"]
    else:
        __context__.pop("pkg.list_pkgs", None)
        new = list_pkgs()
        ret["changes"] = salt.utils.compare_dicts(old, new)
    return ret
# Buggy code
def check_nova():
    if HAS_NOVA:
        novaclient_ver = LooseVersion(novaclient.__version__)
        min_ver = LooseVersion(NOVACLIENT_MINVER)
        if novaclient_ver >= min_ver:
            return HAS_NOVA
        log.debug("Newer novaclient version required.  Minimum: 2.6.1")
    return False


# Traceback (SaltRenderError)
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1594, in call
**cdata['kwargs'])
File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1491, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/salt/states/file.py", line 2355, in recurse
manage_file(dest, src)
File "/usr/lib/python2.7/dist-packages/salt/states/file.py", line 2232, in manage_file
**pass_kwargs)
File "/usr/lib/python2.7/dist-packages/salt/states/file.py", line 1451, in managed
**kwargs
File "/usr/lib/python2.7/dist-packages/salt/modules/file.py", line 3720, in check_managed_changes
**kwargs)
File "/usr/lib/python2.7/dist-packages/salt/modules/file.py", line 3419, in get_managed
**kwargs)
File "/usr/lib/python2.7/dist-packages/salt/utils/templates.py", line 180, in render_tmpl
output = render_str(tmplstr, context, tmplpath)
File "/usr/lib/python2.7/dist-packages/salt/utils/templates.py", line 415, in render_jinja_tmpl
trace=tracestr)
SaltRenderError: Jinja error: 'module' object has no attribute 'discover_extensions'
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/utils/templates.py", line 368, in render_jinja_tmpl
output = template.render(**decoded_context)
File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 969, in render
return self.environment.handle_exception(exc_info, True)
File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 742, in handle_exception
reraise(exc_type, exc_value, tb)
File "<template>", line 4, in top-level template code
File "/usr/lib/python2.7/dist-packages/salt/modules/nova.py", line 504, in image_list
conn = _auth(profile)
File "/usr/lib/python2.7/dist-packages/salt/modules/nova.py", line 99, in _auth
return suon.SaltNova(**kwargs)
File "/usr/lib/python2.7/dist-packages/salt/utils/openstack/nova.py", line 145, in __init__
self.extensions = client.discover_extensions('1.1')
AttributeError: 'module' object has no attribute 'discover_extensions'

# Fixed code
def check_nova():
    if HAS_NOVA:
        novaclient_ver = LooseVersion(novaclient.__version__)
        min_ver = LooseVersion(NOVACLIENT_MINVER)
        if novaclient_ver >= min_ver:
            return HAS_NOVA
        log.debug(
            "Newer novaclient version required.  Minimum: {0}".format(NOVACLIENT_MINVER)
        )
    return False
# Buggy code
def __virtual__():
    """
    Only work when npm is installed.
    """
    try:
        if salt.utils.which("npm") is not None:
            _check_valid_version()
            return True
        else:
            return (
                False,
                "npm execution module could not be loaded "
                "because the npm binary could not be located",
            )
    except CommandExecutionError as exc:
        return (False, str(exc))


# Traceback (NameError)
# salt-cloud -m map_lxc_test
[snip]
ping_status:
True
result:
True
ursa:
|_
----------
changes:
----------
init:
|_
----------
create:
Container cloned
|_
----------
password:
Password(s) updated
|_
----------
dns:
DNS updated
|_
----------
bootstrap:
Continer successfully bootstrapped
|_
----------
state:
----------
new:
running
old:
None
comment:
Container 'bagu.logilab.priv' successfully initialized
container_name:
bagu.logilab.priv
name:
bagu.logilab.priv
result:
True
[INFO    ] Runner completed: 20150513153844491566
[ERROR   ] Failed to read the virtual function for module: npm
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1176, in process_virtual
virtual = mod.__virtual__()
File "/usr/lib/python2.7/dist-packages/salt/modules/npm.py", line 31, in __virtual__
_check_valid_version()
File "/usr/lib/python2.7/dist-packages/salt/modules/npm.py", line 47, in _check_valid_version
__salt__['cmd.run']('npm --version'))
NameError: global name '__salt__' is not defined
[ERROR   ] There was a query error: unhashable type: 'dict'
# salt-run --versions-report
Salt: 2015.5.0
Python: 2.7.6 (default, Mar 22 2014, 22:59:56)
Jinja2: 2.7.2
M2Crypto: 0.21.1
msgpack-python: 0.3.0
msgpack-pure: Not Installed
pycrypto: 2.6.1
libnacl: Not Installed
PyYAML: 3.10
ioflo: Not Installed
PyZMQ: 14.0.1
RAET: Not Installed
ZMQ: 4.0.4
Mako: 0.9.1
Debian source package: 2015.5.0+ds-1trusty1

# Fixed code
def __virtual__():
    """
    Only work when npm is installed.
    """
    try:
        if salt.utils.which("npm") is not None:
            _check_valid_version(__salt__)
            return True
        else:
            return (
                False,
                "npm execution module could not be loaded "
                "because the npm binary could not be located",
            )
    except CommandExecutionError as exc:
        return (False, str(exc))
# Buggy code
def _check_valid_version():
    """
    Check the version of npm to ensure this module will work. Currently
    npm must be at least version 1.2.
    """
    # pylint: disable=no-member
    npm_version = distutils.version.LooseVersion(__salt__["cmd.run"]("npm --version"))
    valid_version = distutils.version.LooseVersion("1.2")
    # pylint: enable=no-member
    if npm_version < valid_version:
        raise CommandExecutionError(
            "'npm' is not recent enough({0} < {1}). Please Upgrade.".format(
                npm_version, valid_version
            )
        )


# Traceback (NameError)
# salt-cloud -m map_lxc_test
[snip]
ping_status:
True
result:
True
ursa:
|_
----------
changes:
----------
init:
|_
----------
create:
Container cloned
|_
----------
password:
Password(s) updated
|_
----------
dns:
DNS updated
|_
----------
bootstrap:
Continer successfully bootstrapped
|_
----------
state:
----------
new:
running
old:
None
comment:
Container 'bagu.logilab.priv' successfully initialized
container_name:
bagu.logilab.priv
name:
bagu.logilab.priv
result:
True
[INFO    ] Runner completed: 20150513153844491566
[ERROR   ] Failed to read the virtual function for module: npm
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1176, in process_virtual
virtual = mod.__virtual__()
File "/usr/lib/python2.7/dist-packages/salt/modules/npm.py", line 31, in __virtual__
_check_valid_version()
File "/usr/lib/python2.7/dist-packages/salt/modules/npm.py", line 47, in _check_valid_version
__salt__['cmd.run']('npm --version'))
NameError: global name '__salt__' is not defined
[ERROR   ] There was a query error: unhashable type: 'dict'
# salt-run --versions-report
Salt: 2015.5.0
Python: 2.7.6 (default, Mar 22 2014, 22:59:56)
Jinja2: 2.7.2
M2Crypto: 0.21.1
msgpack-python: 0.3.0
msgpack-pure: Not Installed
pycrypto: 2.6.1
libnacl: Not Installed
PyYAML: 3.10
ioflo: Not Installed
PyZMQ: 14.0.1
RAET: Not Installed
ZMQ: 4.0.4
Mako: 0.9.1
Debian source package: 2015.5.0+ds-1trusty1

# Fixed code
def _check_valid_version(salt):
    """
    Check the version of npm to ensure this module will work. Currently
    npm must be at least version 1.2.
    """
    # pylint: disable=no-member
    npm_version = distutils.version.LooseVersion(salt["cmd.run"]("npm --version"))
    valid_version = distutils.version.LooseVersion("1.2")
    # pylint: enable=no-member
    if npm_version < valid_version:
        raise CommandExecutionError(
            "'npm' is not recent enough({0} < {1}). Please Upgrade.".format(
                npm_version, valid_version
            )
        )
# Buggy code
def _gen_back(self, back):
    """
    Return the backend list
    """
    ret = []
    if not back:
        back = self.opts["fileserver_backend"]
    if isinstance(back, six.string_types):
        back = back.split(",")
    if all((x.startswith("-") for x in back)):
        # Only subtracting backends from enabled ones
        ret = self.opts["fileserver_backend"]
        for sub in back:
            if "{0}.envs".format(sub[1:]) in self.servers:
                ret.remove(sub[1:])
            elif "{0}.envs".format(sub[1:-2]) in self.servers:
                ret.remove(sub[1:-2])
    else:
        for sub in back:
            if "{0}.envs".format(sub) in self.servers:
                ret.append(sub)
            elif "{0}.envs".format(sub[:-2]) in self.servers:
                ret.append(sub[:-2])
    return ret


# Traceback (AttributeError)
# salt-run fileserver.file_list saltenv=1.0
Exception occurred in runner fileserver.file_list: Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/client/mixins.py", line 337, in low
data['return'] = self.functions[fun](*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/salt/runners/fileserver.py", line 83, in file_list
output = fileserver.file_list(load=load)
File "/usr/lib/python2.7/dist-packages/salt/fileserver/__init__.py", line 555, in file_list
ret.update(self.servers[fstr](load))
File "/usr/lib/python2.7/dist-packages/salt/fileserver/gitfs.py", line 180, in file_list
return gitfs.file_list(load)
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 2255, in file_list
return self._file_lists(load, 'files')
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 2216, in _file_lists
'{0}.p'.format(load['saltenv'].replace(os.path.sep, '_|-'))
AttributeError: 'float' object has no attribute 'replace'

# Fixed code
def _gen_back(self, back):
    """
    Return the backend list
    """
    if not back:
        back = self.opts["fileserver_backend"]
    else:
        try:
            back = back.split(",")
        except AttributeError:
            back = six.text_type(back).split(",")

    ret = []
    if not isinstance(back, list):
        return ret

    try:
        subtract_only = all((x.startswith("-") for x in back))
    except AttributeError:
        pass
    else:
        if subtract_only:
            # Only subtracting backends from enabled ones
            ret = self.opts["fileserver_backend"]
            for sub in back:
                if "{0}.envs".format(sub[1:]) in self.servers:
                    ret.remove(sub[1:])
                elif "{0}.envs".format(sub[1:-2]) in self.servers:
                    ret.remove(sub[1:-2])
            return ret

    for sub in back:
        if "{0}.envs".format(sub) in self.servers:
            ret.append(sub)
        elif "{0}.envs".format(sub[:-2]) in self.servers:
            ret.append(sub[:-2])
    return ret
# Buggy code
def serve_file(self, load):
    """
    Serve up a chunk of a file
    """
    ret = {"data": "", "dest": ""}
    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")

    if "path" not in load or "loc" not in load or "saltenv" not in load:
        return ret
    fnd = self.find_file(load["path"], load["saltenv"])
    if not fnd.get("back"):
        return ret
    fstr = "{0}.serve_file".format(fnd["back"])
    if fstr in self.servers:
        return self.servers[fstr](load, fnd)
    return ret


# Traceback (AttributeError)
# salt-run fileserver.file_list saltenv=1.0
Exception occurred in runner fileserver.file_list: Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/client/mixins.py", line 337, in low
data['return'] = self.functions[fun](*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/salt/runners/fileserver.py", line 83, in file_list
output = fileserver.file_list(load=load)
File "/usr/lib/python2.7/dist-packages/salt/fileserver/__init__.py", line 555, in file_list
ret.update(self.servers[fstr](load))
File "/usr/lib/python2.7/dist-packages/salt/fileserver/gitfs.py", line 180, in file_list
return gitfs.file_list(load)
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 2255, in file_list
return self._file_lists(load, 'files')
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 2216, in _file_lists
'{0}.p'.format(load['saltenv'].replace(os.path.sep, '_|-'))
AttributeError: 'float' object has no attribute 'replace'

# Fixed code
def serve_file(self, load):
    """
    Serve up a chunk of a file
    """
    ret = {"data": "", "dest": ""}
    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")

    if "path" not in load or "loc" not in load or "saltenv" not in load:
        return ret
    if not isinstance(load["saltenv"], six.string_types):
        load["saltenv"] = six.text_type(load["saltenv"])

    fnd = self.find_file(load["path"], load["saltenv"])
    if not fnd.get("back"):
        return ret
    fstr = "{0}.serve_file".format(fnd["back"])
    if fstr in self.servers:
        return self.servers[fstr](load, fnd)
    return ret
# Buggy code
def file_hash(self, load):
    """
    Return the hash of a given file
    """
    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")

    if "path" not in load or "saltenv" not in load:
        return ""
    fnd = self.find_file(salt.utils.locales.sdecode(load["path"]), load["saltenv"])
    if not fnd.get("back"):
        return ""
    fstr = "{0}.file_hash".format(fnd["back"])
    if fstr in self.servers:
        return self.servers[fstr](load, fnd)
    return ""


# Traceback (AttributeError)
# salt-run fileserver.file_list saltenv=1.0
Exception occurred in runner fileserver.file_list: Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/client/mixins.py", line 337, in low
data['return'] = self.functions[fun](*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/salt/runners/fileserver.py", line 83, in file_list
output = fileserver.file_list(load=load)
File "/usr/lib/python2.7/dist-packages/salt/fileserver/__init__.py", line 555, in file_list
ret.update(self.servers[fstr](load))
File "/usr/lib/python2.7/dist-packages/salt/fileserver/gitfs.py", line 180, in file_list
return gitfs.file_list(load)
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 2255, in file_list
return self._file_lists(load, 'files')
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 2216, in _file_lists
'{0}.p'.format(load['saltenv'].replace(os.path.sep, '_|-'))
AttributeError: 'float' object has no attribute 'replace'

# Fixed code
def file_hash(self, load):
    """
    Return the hash of a given file
    """
    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")

    if "path" not in load or "saltenv" not in load:
        return ""
    if not isinstance(load["saltenv"], six.string_types):
        load["saltenv"] = six.text_type(load["saltenv"])

    fnd = self.find_file(salt.utils.locales.sdecode(load["path"]), load["saltenv"])
    if not fnd.get("back"):
        return ""
    fstr = "{0}.file_hash".format(fnd["back"])
    if fstr in self.servers:
        return self.servers[fstr](load, fnd)
    return ""
# Buggy code
def file_list(self, load):
    """
    Return a list of files from the dominant environment
    """
    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 = set()
    if "saltenv" not in load:
        return []
    for fsb in self._gen_back(load.pop("fsbackend", None)):
        fstr = "{0}.file_list".format(fsb)
        if fstr in self.servers:
            ret.update(self.servers[fstr](load))
    # upgrade all set elements to a common encoding
    ret = [salt.utils.locales.sdecode(f) for f in ret]
    # some *fs do not handle prefix. Ensure it is filtered
    prefix = load.get("prefix", "").strip("/")
    if prefix != "":
        ret = [f for f in ret if f.startswith(prefix)]
    return sorted(ret)


# Traceback (AttributeError)
# salt-run fileserver.file_list saltenv=1.0
Exception occurred in runner fileserver.file_list: Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/client/mixins.py", line 337, in low
data['return'] = self.functions[fun](*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/salt/runners/fileserver.py", line 83, in file_list
output = fileserver.file_list(load=load)
File "/usr/lib/python2.7/dist-packages/salt/fileserver/__init__.py", line 555, in file_list
ret.update(self.servers[fstr](load))
File "/usr/lib/python2.7/dist-packages/salt/fileserver/gitfs.py", line 180, in file_list
return gitfs.file_list(load)
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 2255, in file_list
return self._file_lists(load, 'files')
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 2216, in _file_lists
'{0}.p'.format(load['saltenv'].replace(os.path.sep, '_|-'))
AttributeError: 'float' object has no attribute 'replace'

# Fixed code
def file_list(self, load):
    """
    Return a list of files from the dominant environment
    """
    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 = set()
    if "saltenv" not in load:
        return []
    if not isinstance(load["saltenv"], six.string_types):
        load["saltenv"] = six.text_type(load["saltenv"])

    for fsb in self._gen_back(load.pop("fsbackend", None)):
        fstr = "{0}.file_list".format(fsb)
        if fstr in self.servers:
            ret.update(self.servers[fstr](load))
    # upgrade all set elements to a common encoding
    ret = [salt.utils.locales.sdecode(f) for f in ret]
    # some *fs do not handle prefix. Ensure it is filtered
    prefix = load.get("prefix", "").strip("/")
    if prefix != "":
        ret = [f for f in ret if f.startswith(prefix)]
    return sorted(ret)
# Buggy code
def file_list_emptydirs(self, load):
    """
    List all emptydirs in the given environment
    """
    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 = set()
    if "saltenv" not in load:
        return []
    for fsb in self._gen_back(None):
        fstr = "{0}.file_list_emptydirs".format(fsb)
        if fstr in self.servers:
            ret.update(self.servers[fstr](load))
    # upgrade all set elements to a common encoding
    ret = [salt.utils.locales.sdecode(f) for f in ret]
    # some *fs do not handle prefix. Ensure it is filtered
    prefix = load.get("prefix", "").strip("/")
    if prefix != "":
        ret = [f for f in ret if f.startswith(prefix)]
    return sorted(ret)


# Traceback (AttributeError)
# salt-run fileserver.file_list saltenv=1.0
Exception occurred in runner fileserver.file_list: Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/client/mixins.py", line 337, in low
data['return'] = self.functions[fun](*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/salt/runners/fileserver.py", line 83, in file_list
output = fileserver.file_list(load=load)
File "/usr/lib/python2.7/dist-packages/salt/fileserver/__init__.py", line 555, in file_list
ret.update(self.servers[fstr](load))
File "/usr/lib/python2.7/dist-packages/salt/fileserver/gitfs.py", line 180, in file_list
return gitfs.file_list(load)
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 2255, in file_list
return self._file_lists(load, 'files')
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 2216, in _file_lists
'{0}.p'.format(load['saltenv'].replace(os.path.sep, '_|-'))
AttributeError: 'float' object has no attribute 'replace'

# Fixed code
def file_list_emptydirs(self, load):
    """
    List all emptydirs in the given environment
    """
    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 = set()
    if "saltenv" not in load:
        return []
    if not isinstance(load["saltenv"], six.string_types):
        load["saltenv"] = six.text_type(load["saltenv"])

    for fsb in self._gen_back(None):
        fstr = "{0}.file_list_emptydirs".format(fsb)
        if fstr in self.servers:
            ret.update(self.servers[fstr](load))
    # upgrade all set elements to a common encoding
    ret = [salt.utils.locales.sdecode(f) for f in ret]
    # some *fs do not handle prefix. Ensure it is filtered
    prefix = load.get("prefix", "").strip("/")
    if prefix != "":
        ret = [f for f in ret if f.startswith(prefix)]
    return sorted(ret)
# Buggy code
def dir_list(self, load):
    """
    List all directories in the given environment
    """
    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 = set()
    if "saltenv" not in load:
        return []
    for fsb in self._gen_back(load.pop("fsbackend", None)):
        fstr = "{0}.dir_list".format(fsb)
        if fstr in self.servers:
            ret.update(self.servers[fstr](load))
    # upgrade all set elements to a common encoding
    ret = [salt.utils.locales.sdecode(f) for f in ret]
    # some *fs do not handle prefix. Ensure it is filtered
    prefix = load.get("prefix", "").strip("/")
    if prefix != "":
        ret = [f for f in ret if f.startswith(prefix)]
    return sorted(ret)


# Traceback (AttributeError)
# salt-run fileserver.file_list saltenv=1.0
Exception occurred in runner fileserver.file_list: Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/client/mixins.py", line 337, in low
data['return'] = self.functions[fun](*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/salt/runners/fileserver.py", line 83, in file_list
output = fileserver.file_list(load=load)
File "/usr/lib/python2.7/dist-packages/salt/fileserver/__init__.py", line 555, in file_list
ret.update(self.servers[fstr](load))
File "/usr/lib/python2.7/dist-packages/salt/fileserver/gitfs.py", line 180, in file_list
return gitfs.file_list(load)
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 2255, in file_list
return self._file_lists(load, 'files')
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 2216, in _file_lists
'{0}.p'.format(load['saltenv'].replace(os.path.sep, '_|-'))
AttributeError: 'float' object has no attribute 'replace'

# Fixed code
def dir_list(self, load):
    """
    List all directories in the given environment
    """
    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 = set()
    if "saltenv" not in load:
        return []
    if not isinstance(load["saltenv"], six.string_types):
        load["saltenv"] = six.text_type(load["saltenv"])

    for fsb in self._gen_back(load.pop("fsbackend", None)):
        fstr = "{0}.dir_list".format(fsb)
        if fstr in self.servers:
            ret.update(self.servers[fstr](load))
    # upgrade all set elements to a common encoding
    ret = [salt.utils.locales.sdecode(f) for f in ret]
    # some *fs do not handle prefix. Ensure it is filtered
    prefix = load.get("prefix", "").strip("/")
    if prefix != "":
        ret = [f for f in ret if f.startswith(prefix)]
    return sorted(ret)