# Buggy code
def absent(name, bridge=None):
    """
    Ensures that the named port exists on bridge, eventually deletes it.
    If bridge is not set, port is removed from  whatever bridge contains it.

    Args:
        name: The name of the port.
        bridge: The name of the bridge.

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

    if bridge:
        bridge_exists = __salt__["openvswitch.bridge_exists"](bridge)
        if bridge_exists:
            port_list = __salt__["openvswitch.port_list"](bridge)
        else:
            port_list = ()
    else:
        port_list = [name]

    # Comment and change messages
    comment_bridge_notexists = "Bridge {0} does not exist.".format(bridge)
    comment_port_notexists = "Port {0} does not exist on bridge {1}.".format(
        name, bridge
    )
    comment_port_deleted = "Port {0} deleted.".format(name)
    comment_port_notdeleted = "Unable to delete port {0}.".format(name)
    changes_port_deleted = {
        name: {
            "old": "Port named {0} may exist.".format(name),
            "new": "Deleted port {0}.".format(name),
        }
    }

    # Dry run, test=true mode
    if __opts__["test"]:
        if bridge and not bridge_exists:
            ret["result"] = None
            ret["comment"] = comment_bridge_notexists
        elif name not in port_list:
            ret["result"] = True
            ret["comment"] = comment_port_notexists
        else:
            ret["result"] = None
            ret["comment"] = comment_port_deleted
        return ret

    if bridge and not bridge_exists:
        ret["result"] = False
        ret["comment"] = comment_bridge_notexists
    elif name not in port_list:
        ret["result"] = True
        ret["comment"] = comment_port_notexists
    else:
        if bridge:
            port_remove = __salt__["openvswitch.port_remove"](br=bridge, port=name)
        else:
            port_remove = __salt__["openvswitch.port_remove"](br=None, port=name)

        if port_remove:
            ret["result"] = True
            ret["comment"] = comment_port_deleted
            ret["changes"] = changes_port_deleted
        else:
            ret["result"] = False
            ret["comment"] = comment_port_notdeleted

    return ret


# Traceback (TypeError)
----------
ID: ovs-tun-gre
Function: openvswitch_port.present
Name: ovs-tun-gre
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/var/tmp/.root_e78424_salt/py3/salt/state.py", line 1744, in call
**cdata['kwargs'])
File "/var/tmp/.root_e78424_salt/py3/salt/loader.py", line 1702, in wrapper
return f(*args, **kwargs)
File "/var/tmp/.root_e78424_salt/py3/salt/states/openvswitch_port.py", line 75, in present
comment_dstport = ' (dst_port' + str(dst_port) + ')' if 0 < dst_port <= 65535 else ''
TypeError: '<' not supported between instances of 'int' and 'NoneType'
Started: 18:26:22.079644
Duration: 29.143 ms
Changes:

# Fixed code
def absent(name, bridge=None):
    """
    Ensures that the named port exists on bridge, eventually deletes it.
    If bridge is not set, port is removed from  whatever bridge contains it.

    Args:
        name: The name of the port.
        bridge: The name of the bridge.

    """
    ret = {"name": name, "changes": {}, "result": False, "comment": ""}
    bridge_exists = False
    if bridge:
        bridge_exists = __salt__["openvswitch.bridge_exists"](bridge)
        if bridge_exists:
            port_list = __salt__["openvswitch.port_list"](bridge)
        else:
            port_list = ()
    else:
        port_list = [name]

    # Comment and change messages
    comments = {}
    comments["comment_bridge_notexists"] = "Bridge {0} does not exist.".format(bridge)
    comments["comment_port_notexists"] = (
        "Port {0} does not exist on bridge {1}.".format(name, bridge)
    )
    comments["comment_port_deleted"] = "Port {0} deleted.".format(name)
    comments["comment_port_notdeleted"] = "Unable to delete port {0}.".format(name)
    comments["changes_port_deleted"] = {
        name: {
            "old": "Port named {0} may exist.".format(name),
            "new": "Deleted port {0}.".format(name),
        }
    }

    # Dry run, test=true mode
    if __opts__["test"]:
        if bridge and not bridge_exists:
            ret["result"] = None
            ret["comment"] = comments["comment_bridge_notexists"]
        elif name not in port_list:
            ret["result"] = True
            ret["comment"] = comments["comment_port_notexists"]
        else:
            ret["result"] = None
            ret["comment"] = comments["comment_port_deleted"]
        return ret

    if bridge and not bridge_exists:
        ret["result"] = False
        ret["comment"] = comments["comment_bridge_notexists"]
    elif name not in port_list:
        ret["result"] = True
        ret["comment"] = comments["comment_port_notexists"]
    else:
        if bridge:
            port_remove = __salt__["openvswitch.port_remove"](br=bridge, port=name)
        else:
            port_remove = __salt__["openvswitch.port_remove"](br=None, port=name)

        if port_remove:
            ret["result"] = True
            ret["comment"] = comments["comment_port_deleted"]
            ret["changes"] = comments["changes_port_deleted"]
        else:
            ret["result"] = False
            ret["comment"] = comments["comment_port_notdeleted"]

    return ret