# Buggy code
def check_requisite(self, low, running, chunks, pre=False):
    """
    Look into the running data to check the status of all requisite
    states
    """
    present = False
    # If mod_watch is not available make it a require
    if "watch" in low:
        if "{0}.mod_watch".format(low["state"]) not in self.states:
            if "require" in low:
                low["require"].extend(low.pop("watch"))
            else:
                low["require"] = low.pop("watch")
        else:
            present = True
    if "require" in low:
        present = True
    if "prerequired" in low:
        present = True
    if "prereq" in low:
        present = True
    if "onfail" in low:
        present = True
    if "onchanges" in low:
        present = True
    if not present:
        return "met", ()
    reqs = {"require": [], "watch": [], "prereq": [], "onfail": [], "onchanges": []}
    if pre:
        reqs["prerequired"] = []
    for r_state in reqs:
        if r_state in low and low[r_state] is not None:
            for req in low[r_state]:
                if isinstance(req, six.string_types):
                    req = {"id": req}
                req = trim_req(req)
                found = False
                for chunk in chunks:
                    req_key = next(iter(req))
                    req_val = req[req_key]
                    if req_val is None:
                        continue
                    if req_key == "sls":
                        # Allow requisite tracking of entire sls files
                        if fnmatch.fnmatch(chunk["__sls__"], req_val):
                            found = True
                            reqs[r_state].append(chunk)
                        continue
                    if fnmatch.fnmatch(chunk["name"], req_val) or fnmatch.fnmatch(
                        chunk["__id__"], req_val
                    ):
                        if req_key == "id" or chunk["state"] == req_key:
                            found = True
                            reqs[r_state].append(chunk)
                if not found:
                    return "unmet", ()
    fun_stats = set()
    for r_state, chunks in six.iteritems(reqs):
        if r_state == "prereq":
            run_dict = self.pre
        else:
            run_dict = running
        for chunk in chunks:
            tag = _gen_tag(chunk)
            if tag not in run_dict:
                fun_stats.add("unmet")
                continue
            if r_state == "onfail":
                if run_dict[tag]["result"] is True:
                    fun_stats.add("onfail")
                    continue
            else:
                if run_dict[tag]["result"] is False:
                    fun_stats.add("fail")
                    continue
            if r_state == "onchanges":
                if not run_dict[tag]["changes"]:
                    fun_stats.add("onchanges")
                else:
                    fun_stats.add("onchangesmet")
                continue
            if r_state == "watch" and run_dict[tag]["changes"]:
                fun_stats.add("change")
                continue
            if r_state == "prereq" and run_dict[tag]["result"] is None:
                fun_stats.add("premet")
            if r_state == "prereq" and not run_dict[tag]["result"] is None:
                fun_stats.add("pre")
            else:
                fun_stats.add("met")

    if "unmet" in fun_stats:
        status = "unmet"
    elif "fail" in fun_stats:
        status = "fail"
    elif "pre" in fun_stats:
        if "premet" in fun_stats:
            status = "met"
        else:
            status = "pre"
    elif "onfail" in fun_stats:
        status = "onfail"
    elif "onchanges" in fun_stats and "onchangesmet" not in fun_stats:
        status = "onchanges"
    elif "change" in fun_stats:
        status = "change"
    else:
        status = "met"

    return status, reqs


# Traceback (KeyError)
The minion function caused an exception: Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/minion.py", line 1320, in _thread_return
return_data = executor.execute()
File "/usr/lib/python2.6/site-packages/salt/executors/direct_call.py", line 28, in execute
return self.func(*self.args, **self.kwargs)
File "/usr/lib/python2.6/site-packages/salt/modules/state.py", line 722, in highstate
whitelist=kwargs.get('whitelist')
File "/usr/lib/python2.6/site-packages/salt/state.py", line 3271, in call_highstate
os.umask(cumask)
File "/usr/lib/python2.6/site-packages/salt/state.py", line 2276, in call_high
return errors
File "/usr/lib/python2.6/site-packages/salt/state.py", line 1799, in call_chunks
running = self.call_chunk(low, running, chunks)
File "/usr/lib/python2.6/site-packages/salt/state.py", line 2066, in call_chunk
return running
File "/usr/lib/python2.6/site-packages/salt/state.py", line 1982, in call_chunk
requisites.append('prerequired')
File "/usr/lib/python2.6/site-packages/salt/state.py", line 1868, in check_requisite
if (fnmatch.fnmatch(chunk['name'], req_val) or
File "/usr/lib64/python2.6/fnmatch.py", line 43, in fnmatch
return fnmatchcase(name, pat)
File "/usr/lib64/python2.6/fnmatch.py", line 75, in fnmatchcase
res = translate(pat)
File "/usr/lib64/python2.6/fnmatch.py", line 90, in translate
c = pat[i]
KeyError: 0

# Fixed code
def check_requisite(self, low, running, chunks, pre=False):
    """
    Look into the running data to check the status of all requisite
    states
    """
    present = False
    # If mod_watch is not available make it a require
    if "watch" in low:
        if "{0}.mod_watch".format(low["state"]) not in self.states:
            if "require" in low:
                low["require"].extend(low.pop("watch"))
            else:
                low["require"] = low.pop("watch")
        else:
            present = True
    if "require" in low:
        present = True
    if "prerequired" in low:
        present = True
    if "prereq" in low:
        present = True
    if "onfail" in low:
        present = True
    if "onchanges" in low:
        present = True
    if not present:
        return "met", ()
    reqs = {"require": [], "watch": [], "prereq": [], "onfail": [], "onchanges": []}
    if pre:
        reqs["prerequired"] = []
    for r_state in reqs:
        if r_state in low and low[r_state] is not None:
            for req in low[r_state]:
                if isinstance(req, six.string_types):
                    req = {"id": req}
                req = trim_req(req)
                found = False
                for chunk in chunks:
                    req_key = next(iter(req))
                    req_val = req[req_key]
                    if req_val is None:
                        continue
                    if req_key == "sls":
                        # Allow requisite tracking of entire sls files
                        if fnmatch.fnmatch(chunk["__sls__"], req_val):
                            found = True
                            reqs[r_state].append(chunk)
                        continue
                    try:
                        if fnmatch.fnmatch(chunk["name"], req_val) or fnmatch.fnmatch(
                            chunk["__id__"], req_val
                        ):
                            if req_key == "id" or chunk["state"] == req_key:
                                found = True
                                reqs[r_state].append(chunk)
                    except KeyError:
                        raise SaltRenderError(
                            "Could not locate requisite of [{0}] present in state with name [{1}]".format(
                                req_key, chunk["name"]
                            )
                        )
                if not found:
                    return "unmet", ()
    fun_stats = set()
    for r_state, chunks in six.iteritems(reqs):
        if r_state == "prereq":
            run_dict = self.pre
        else:
            run_dict = running
        for chunk in chunks:
            tag = _gen_tag(chunk)
            if tag not in run_dict:
                fun_stats.add("unmet")
                continue
            if r_state == "onfail":
                if run_dict[tag]["result"] is True:
                    fun_stats.add("onfail")
                    continue
            else:
                if run_dict[tag]["result"] is False:
                    fun_stats.add("fail")
                    continue
            if r_state == "onchanges":
                if not run_dict[tag]["changes"]:
                    fun_stats.add("onchanges")
                else:
                    fun_stats.add("onchangesmet")
                continue
            if r_state == "watch" and run_dict[tag]["changes"]:
                fun_stats.add("change")
                continue
            if r_state == "prereq" and run_dict[tag]["result"] is None:
                fun_stats.add("premet")
            if r_state == "prereq" and not run_dict[tag]["result"] is None:
                fun_stats.add("pre")
            else:
                fun_stats.add("met")

    if "unmet" in fun_stats:
        status = "unmet"
    elif "fail" in fun_stats:
        status = "fail"
    elif "pre" in fun_stats:
        if "premet" in fun_stats:
            status = "met"
        else:
            status = "pre"
    elif "onfail" in fun_stats:
        status = "onfail"
    elif "onchanges" in fun_stats and "onchangesmet" not in fun_stats:
        status = "onchanges"
    elif "change" in fun_stats:
        status = "change"
    else:
        status = "met"

    return status, reqs