# Buggy code
def mknod(name, ntype, major=0, minor=0, user=None, group=None, mode="0600"):
    """
    Create a special file similar to the 'nix mknod command. The supported
    device types are ``p`` (fifo pipe), ``c`` (character device), and ``b``
    (block device). Provide the major and minor numbers when specifying a
    character device or block device. A fifo pipe does not require this
    information. The command will create the necessary dirs if needed. If a
    file of the same name not of the same type/major/minor exists, it will not
    be overwritten or unlinked (deleted). This is logically in place as a
    safety measure because you can really shoot yourself in the foot here and
    it is the behavior of 'nix ``mknod``. It is also important to note that not
    just anyone can create special devices. Usually this is only done as root.
    If the state is executed as none other than root on a minion, you may
    receive a permission error.

    name
        name of the file

    ntype
        node type 'p' (fifo pipe), 'c' (character device), or 'b'
        (block device)

    major
        major number of the device
        does not apply to a fifo pipe

    minor
        minor number of the device
        does not apply to a fifo pipe

    user
        owning user of the device/pipe

    group
        owning group of the device/pipe

    mode
        permissions on the device/pipe

    Usage:

    .. code-block:: yaml

        /dev/chr:
          file.mknod:
            - ntype: c
            - major: 180
            - minor: 31
            - user: root
            - group: root
            - mode: 660

        /dev/blk:
          file.mknod:
            - ntype: b
            - major: 8
            - minor: 999
            - user: root
            - group: root
            - mode: 660

       /dev/fifo:
         file.mknod:
           - ntype: p
           - user: root
           - group: root
           - mode: 660

    .. versionadded:: 0.17.0
    """
    ret = {"name": name, "changes": {}, "comment": "", "result": False}

    if ntype == "c":
        # Check for file existence
        if __salt__["file.file_exists"](name):
            ret["comment"] = (
                "File exists and is not a character device {0}. Cowardly "
                "refusing to continue".format(name)
            )

        # Check if it is a character device
        elif not __salt__["file.is_chrdev"](name):
            if __opts__["test"]:
                ret["comment"] = ("Character device {0} is set to be created").format(
                    name
                )
                ret["result"] = None
            else:
                ret = __salt__["file.mknod"](
                    name, ntype, major, minor, user, group, mode
                )

        # Check the major/minor
        else:
            devmaj, devmin = __salt__["file.get_devmm"](name)
            if (major, minor) != (devmaj, devmin):
                ret["comment"] = (
                    "Character device {0} exists and has a different "
                    "major/minor {1}/{2}. Cowardly refusing to continue".format(
                        name, devmaj, devmin
                    )
                )
            # Check the perms
            else:
                ret = __salt__["file.check_perms"](name, None, user, group, mode)[0]
                if not ret["changes"]:
                    ret["comment"] = (
                        "Character device {0} is in the correct state".format(name)
                    )

    elif ntype == "b":
        # Check for file existence
        if __salt__["file.file_exists"](name):
            ret["comment"] = (
                "File exists and is not a block device {0}. Cowardly "
                "refusing to continue".format(name)
            )

        # Check if it is a block device
        elif not __salt__["file.is_blkdev"](name):
            if __opts__["test"]:
                ret["comment"] = ("Block device {0} is set to be created").format(name)
                ret["result"] = None
            else:
                ret = __salt__["file.mknod"](
                    name, ntype, major, minor, user, group, mode
                )

        # Check the major/minor
        else:
            devmaj, devmin = __salt__["file.get_devmm"](name)
            if (major, minor) != (devmaj, devmin):
                ret["comment"] = (
                    "Block device {0} exists and has a different major/minor "
                    "{1}/{2}. Cowardly refusing to continue".format(
                        name, devmaj, devmin
                    )
                )
            # Check the perms
            else:
                ret = __salt__["file.check_perms"](name, None, user, group, mode)[0]
                if not ret["changes"]:
                    ret["comment"] = "Block device {0} is in the correct state".format(
                        name
                    )

    elif ntype == "p":
        # Check for file existence
        if __salt__["file.file_exists"](name):
            ret["comment"] = (
                "File exists and is not a fifo pipe {0}. Cowardly refusing "
                "to continue".format(name)
            )

        # Check if it is a fifo
        elif not __salt__["file.is_fifo"](name):
            if __opts__["test"]:
                ret["comment"] = "Fifo pipe {0} is set to be created".format(name)
                ret["result"] = None
            else:
                ret = __salt__["file.mknod"](
                    name, ntype, major, minor, user, group, mode
                )

        # Check the perms
        else:
            ret = __salt__["file.check_perms"](name, None, user, group, mode)[0]
            if not ret["changes"]:
                ret["comment"] = "Fifo pipe {0} is in the correct state".format(name)

    else:
        ret["comment"] = (
            "Node type unavailable: {0!r}. Available node types are "
            "character ('c'), block ('b'), and pipe ('p')".format(ntype)
        )

    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 mknod(name, ntype, major=0, minor=0, user=None, group=None, mode="0600"):
    """
    Create a special file similar to the 'nix mknod command. The supported
    device types are ``p`` (fifo pipe), ``c`` (character device), and ``b``
    (block device). Provide the major and minor numbers when specifying a
    character device or block device. A fifo pipe does not require this
    information. The command will create the necessary dirs if needed. If a
    file of the same name not of the same type/major/minor exists, it will not
    be overwritten or unlinked (deleted). This is logically in place as a
    safety measure because you can really shoot yourself in the foot here and
    it is the behavior of 'nix ``mknod``. It is also important to note that not
    just anyone can create special devices. Usually this is only done as root.
    If the state is executed as none other than root on a minion, you may
    receive a permission error.

    name
        name of the file

    ntype
        node type 'p' (fifo pipe), 'c' (character device), or 'b'
        (block device)

    major
        major number of the device
        does not apply to a fifo pipe

    minor
        minor number of the device
        does not apply to a fifo pipe

    user
        owning user of the device/pipe

    group
        owning group of the device/pipe

    mode
        permissions on the device/pipe

    Usage:

    .. code-block:: yaml

        /dev/chr:
          file.mknod:
            - ntype: c
            - major: 180
            - minor: 31
            - user: root
            - group: root
            - mode: 660

        /dev/blk:
          file.mknod:
            - ntype: b
            - major: 8
            - minor: 999
            - user: root
            - group: root
            - mode: 660

       /dev/fifo:
         file.mknod:
           - ntype: p
           - user: root
           - group: root
           - mode: 660

    .. versionadded:: 0.17.0
    """
    ret = {"name": name, "changes": {}, "comment": "", "result": False}
    if not name:
        return _error(ret, "Must provide name to file.mknod")

    if ntype == "c":
        # Check for file existence
        if __salt__["file.file_exists"](name):
            ret["comment"] = (
                "File exists and is not a character device {0}. Cowardly "
                "refusing to continue".format(name)
            )

        # Check if it is a character device
        elif not __salt__["file.is_chrdev"](name):
            if __opts__["test"]:
                ret["comment"] = ("Character device {0} is set to be created").format(
                    name
                )
                ret["result"] = None
            else:
                ret = __salt__["file.mknod"](
                    name, ntype, major, minor, user, group, mode
                )

        # Check the major/minor
        else:
            devmaj, devmin = __salt__["file.get_devmm"](name)
            if (major, minor) != (devmaj, devmin):
                ret["comment"] = (
                    "Character device {0} exists and has a different "
                    "major/minor {1}/{2}. Cowardly refusing to continue".format(
                        name, devmaj, devmin
                    )
                )
            # Check the perms
            else:
                ret = __salt__["file.check_perms"](name, None, user, group, mode)[0]
                if not ret["changes"]:
                    ret["comment"] = (
                        "Character device {0} is in the correct state".format(name)
                    )

    elif ntype == "b":
        # Check for file existence
        if __salt__["file.file_exists"](name):
            ret["comment"] = (
                "File exists and is not a block device {0}. Cowardly "
                "refusing to continue".format(name)
            )

        # Check if it is a block device
        elif not __salt__["file.is_blkdev"](name):
            if __opts__["test"]:
                ret["comment"] = ("Block device {0} is set to be created").format(name)
                ret["result"] = None
            else:
                ret = __salt__["file.mknod"](
                    name, ntype, major, minor, user, group, mode
                )

        # Check the major/minor
        else:
            devmaj, devmin = __salt__["file.get_devmm"](name)
            if (major, minor) != (devmaj, devmin):
                ret["comment"] = (
                    "Block device {0} exists and has a different major/minor "
                    "{1}/{2}. Cowardly refusing to continue".format(
                        name, devmaj, devmin
                    )
                )
            # Check the perms
            else:
                ret = __salt__["file.check_perms"](name, None, user, group, mode)[0]
                if not ret["changes"]:
                    ret["comment"] = "Block device {0} is in the correct state".format(
                        name
                    )

    elif ntype == "p":
        # Check for file existence
        if __salt__["file.file_exists"](name):
            ret["comment"] = (
                "File exists and is not a fifo pipe {0}. Cowardly refusing "
                "to continue".format(name)
            )

        # Check if it is a fifo
        elif not __salt__["file.is_fifo"](name):
            if __opts__["test"]:
                ret["comment"] = "Fifo pipe {0} is set to be created".format(name)
                ret["result"] = None
            else:
                ret = __salt__["file.mknod"](
                    name, ntype, major, minor, user, group, mode
                )

        # Check the perms
        else:
            ret = __salt__["file.check_perms"](name, None, user, group, mode)[0]
            if not ret["changes"]:
                ret["comment"] = "Fifo pipe {0} is in the correct state".format(name)

    else:
        ret["comment"] = (
            "Node type unavailable: {0!r}. Available node types are "
            "character ('c'), block ('b'), and pipe ('p')".format(ntype)
        )

    return ret