.. versionadded:: 2019.2.0

    Makes sure an SELinux port policy for a given port, protocol and SELinux context type is present.

    name
        The protocol and port spec. Can be formatted as ``(tcp|udp)/(port|port-range)``.

    sel_type
        The SELinux Type.

    protocol
        The protocol for the port, ``tcp`` or ``udp``. Required if name is not formatted.

    port
        The port or port range. Required if name is not formatted.

    sel_range
        The SELinux MLS/MCS Security Range.

def port_policy_present(name, sel_type, protocol=None, port=None, sel_range=None):
    '''
    .. versionadded:: 2019.2.0

    Makes sure an SELinux port policy for a given port, protocol and SELinux context type is present.

    name
        The protocol and port spec. Can be formatted as ``(tcp|udp)/(port|port-range)``.

    sel_type
        The SELinux Type.

    protocol
        The protocol for the port, ``tcp`` or ``udp``. Required if name is not formatted.

    port
        The port or port range. Required if name is not formatted.

    sel_range
        The SELinux MLS/MCS Security Range.
    '''
    ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''}
    old_state = __salt__['selinux.port_get_policy'](
        name=name,
        sel_type=sel_type,
        protocol=protocol,
        port=port, )
    if old_state:
        ret.update({'result': True,
                    'comment': 'SELinux policy for "{0}" already present '.format(name) +
                               'with specified sel_type "{0}", protocol "{1}" and port "{2}".'.format(
                                   sel_type, protocol, port)})
        return ret
    if __opts__['test']:
        ret.update({'result': None})
    else:
        add_ret = __salt__['selinux.port_add_policy'](
            name=name,
            sel_type=sel_type,
            protocol=protocol,
            port=port,
            sel_range=sel_range, )
        if add_ret['retcode'] != 0:
            ret.update({'comment': 'Error adding new policy: {0}'.format(add_ret)})
        else:
            ret.update({'result': True})
            new_state = __salt__['selinux.port_get_policy'](
                name=name,
                sel_type=sel_type,
                protocol=protocol,
                port=port, )
            ret['changes'].update({'old': old_state, 'new': new_state})
    return ret