# Buggy code
def check_authentication(self, load, auth_type, key=None, show_username=False):
    """
    .. versionadded:: Oxygen

    Go through various checks to see if the token/eauth/user can be authenticated.

    Returns a dictionary containing the following keys:

    - auth_list
    - username
    - error

    If an error is encountered, return immediately with the relevant error dictionary
    as authentication has failed. Otherwise, return the username and valid auth_list.
    """
    auth_list = []
    username = load.get("username", "UNKNOWN")
    ret = {"auth_list": auth_list, "username": username, "error": {}}

    # Authenticate
    if auth_type == "token":
        token = self.authenticate_token(load)
        if not token:
            ret["error"] = {
                "name": "TokenAuthenticationError",
                "message": 'Authentication failure of type "token" occurred.',
            }
            return ret

        # Update username for token
        username = token["name"]
        ret["username"] = username
        auth_list = self.get_auth_list(load, token=token)
    elif auth_type == "eauth":
        if not self.authenticate_eauth(load):
            ret["error"] = {
                "name": "EauthAuthenticationError",
                "message": 'Authentication failure of type "eauth" occurred for '
                "user {0}.".format(username),
            }
            return ret

        auth_list = self.get_auth_list(load)
    elif auth_type == "user":
        auth_ret = self.authenticate_key(load, key)
        msg = 'Authentication failure of type "user" occurred'
        if not auth_ret:  # auth_ret can be a boolean or the effective user id
            if show_username:
                msg = "{0} for user {1}.".format(msg, username)
            ret["error"] = {"name": "UserAuthenticationError", "message": msg}
            return ret

        # Verify that the caller has root on master
        if auth_ret is not True:
            if AuthUser(load["user"]).is_sudo():
                if not self.opts["sudo_acl"] or not self.opts["publisher_acl"]:
                    auth_ret = True

        if auth_ret is not True:
            auth_list = salt.utils.master.get_values_of_matching_keys(
                self.opts["publisher_acl"], auth_ret
            )
            if not auth_list:
                ret["error"] = {"name": "UserAuthenticationError", "message": msg}
                return ret
    else:
        ret["error"] = {
            "name": "SaltInvocationError",
            "message": "Authentication type not supported.",
        }
        return ret

    # Authentication checks passed
    ret["auth_list"] = auth_list
    return ret


# Traceback (ImportError)
running install_egg_info
Writing /usr/lib/python2.7/dist-packages/salt-2017.7.0_792_g8ffe91f.egg-info
*  INFO: Running install_ubuntu_git_post()
* DEBUG: Copying /tmp/git/salt/pkg/salt-minion.service to /lib/systemd/system/salt-minion.service
disabled
Created symlink from /etc/systemd/system/multi-user.target.wants/salt-minion.service to /lib/systemd/system/salt-minion.service.
*  INFO: Running install_ubuntu_check_services()
* DEBUG: Checking if service salt-minion is enabled
* DEBUG: Service salt-minion is enabled
*  INFO: Running install_ubuntu_restart_daemons()
* DEBUG: Waiting 3 seconds for processes to settle before checking for them
* DEBUG: There's systemd support while checking salt-minion
*  INFO: Running daemons_running()
* DEBUG: Waiting 3 seconds for processes to settle before checking for them
* ERROR: salt-minion was not found running
* ERROR: Failed to run daemons_running()!!!
nohup: ignoring input
Traceback (most recent call last):
File "/usr/bin/salt-minion", line 26, in <module>
salt_minion()
File "/usr/lib/python2.7/dist-packages/salt/scripts.py", line 163, in salt_minion
import salt.cli.daemons
File "/usr/lib/python2.7/dist-packages/salt/cli/daemons.py", line 48, in <module>
import salt.utils.parsers
File "/usr/lib/python2.7/dist-packages/salt/utils/parsers.py", line 28, in <module>
import salt.config as config
File "/usr/lib/python2.7/dist-packages/salt/config/__init__.py", line 100, in <module>
_DFLT_IPC_WBUFFER = _gather_buffer_space() * .5
File "/usr/lib/python2.7/dist-packages/salt/config/__init__.py", line 90, in _gather_buffer_space
import salt.grains.core
File "/usr/lib/python2.7/dist-packages/salt/grains/core.py", line 45, in <module>
import salt.utils.dns
File "/usr/lib/python2.7/dist-packages/salt/utils/dns.py", line 31, in <module>
import salt.modules.cmdmod
File "/usr/lib/python2.7/dist-packages/salt/modules/cmdmod.py", line 34, in <module>
import salt.utils.templates
File "/usr/lib/python2.7/dist-packages/salt/utils/templates.py", line 41, in <module>
import salt.utils.jinja
File "/usr/lib/python2.7/dist-packages/salt/utils/jinja.py", line 30, in <module>
import salt.fileclient
File "/usr/lib/python2.7/dist-packages/salt/fileclient.py", line 21, in <module>
import salt.client
File "/usr/lib/python2.7/dist-packages/salt/client/__init__.py", line 39, in <module>
import salt.utils.minions
File "/usr/lib/python2.7/dist-packages/salt/utils/minions.py", line 23, in <module>
import salt.auth.ldap
File "/usr/lib/python2.7/dist-packages/salt/auth/__init__.py", line 32, in <module>
import salt.utils.master
File "/usr/lib/python2.7/dist-packages/salt/utils/master.py", line 21, in <module>
import salt.pillar
File "/usr/lib/python2.7/dist-packages/salt/pillar/__init__.py", line 21, in <module>
import salt.minion
File "/usr/lib/python2.7/dist-packages/salt/minion.py", line 115, in <module>
from salt.config import DEFAULT_MINION_OPTS
ImportError: cannot import name DEFAULT_MINION_OPTS
* DEBUG: Running salt-minion by hand outputs:
* DEBUG: /var/log/salt/minion does not exist. Can't cat its contents!

# Fixed code
def check_authentication(self, load, auth_type, key=None, show_username=False):
    """
    .. versionadded:: Oxygen

    Go through various checks to see if the token/eauth/user can be authenticated.

    Returns a dictionary containing the following keys:

    - auth_list
    - username
    - error

    If an error is encountered, return immediately with the relevant error dictionary
    as authentication has failed. Otherwise, return the username and valid auth_list.
    """
    auth_list = []
    username = load.get("username", "UNKNOWN")
    ret = {"auth_list": auth_list, "username": username, "error": {}}

    # Authenticate
    if auth_type == "token":
        token = self.authenticate_token(load)
        if not token:
            ret["error"] = {
                "name": "TokenAuthenticationError",
                "message": 'Authentication failure of type "token" occurred.',
            }
            return ret

        # Update username for token
        username = token["name"]
        ret["username"] = username
        auth_list = self.get_auth_list(load, token=token)
    elif auth_type == "eauth":
        if not self.authenticate_eauth(load):
            ret["error"] = {
                "name": "EauthAuthenticationError",
                "message": 'Authentication failure of type "eauth" occurred for '
                "user {0}.".format(username),
            }
            return ret

        auth_list = self.get_auth_list(load)
    elif auth_type == "user":
        auth_ret = self.authenticate_key(load, key)
        msg = 'Authentication failure of type "user" occurred'
        if not auth_ret:  # auth_ret can be a boolean or the effective user id
            if show_username:
                msg = "{0} for user {1}.".format(msg, username)
            ret["error"] = {"name": "UserAuthenticationError", "message": msg}
            return ret

        # Verify that the caller has root on master
        if auth_ret is not True:
            if AuthUser(load["user"]).is_sudo():
                if not self.opts["sudo_acl"] or not self.opts["publisher_acl"]:
                    auth_ret = True

        if auth_ret is not True:
            # Avoid a circular import
            import salt.utils.master

            auth_list = salt.utils.master.get_values_of_matching_keys(
                self.opts["publisher_acl"], auth_ret
            )
            if not auth_list:
                ret["error"] = {"name": "UserAuthenticationError", "message": msg}
                return ret
    else:
        ret["error"] = {
            "name": "SaltInvocationError",
            "message": "Authentication type not supported.",
        }
        return ret

    # Authentication checks passed
    ret["auth_list"] = auth_list
    return ret