# Buggy code
def prepare(self):
    """
    Run the preparation sequence required to start a salt minion.

    If sub-classed, don't **ever** forget to run:

        super(YourSubClass, self).prepare()
    """
    super(Minion, self).prepare()

    try:
        if self.config["verify_env"]:
            confd = self.config.get("default_include")
            if confd:
                # If 'default_include' is specified in config, then use it
                if "*" in confd:
                    # Value is of the form "minion.d/*.conf"
                    confd = os.path.dirname(confd)
                if not os.path.isabs(confd):
                    # If configured 'default_include' is not an absolute
                    # path, consider it relative to folder of 'conf_file'
                    # (/etc/salt by default)
                    confd = os.path.join(
                        os.path.dirname(self.config["conf_file"]), confd
                    )
            else:
                confd = os.path.join(
                    os.path.dirname(self.config["conf_file"]), "minion.d"
                )

            v_dirs = [
                self.config["pki_dir"],
                self.config["cachedir"],
                self.config["sock_dir"],
                self.config["extension_modules"],
                confd,
            ]

            if self.config.get("transport") == "raet":
                v_dirs.append(os.path.join(self.config["pki_dir"], "accepted"))
                v_dirs.append(os.path.join(self.config["pki_dir"], "pending"))
                v_dirs.append(os.path.join(self.config["pki_dir"], "rejected"))
                v_dirs.append(os.path.join(self.config["cachedir"], "raet"))

            verify_env(
                v_dirs,
                self.config["user"],
                permissive=self.config["permissive_pki_access"],
                pki_dir=self.config["pki_dir"],
            )
            logfile = self.config["log_file"]
            if logfile is not None and not logfile.startswith(
                ("tcp://", "udp://", "file://")
            ):
                # Logfile is not using Syslog, verify
                current_umask = os.umask(0o027)
                verify_files([logfile], self.config["user"])
                os.umask(current_umask)
    except OSError as err:
        self.environment_failure(err)

    self.setup_logfile_logger()
    verify_log(self.config)
    log.info('Setting up the Salt Minion "{0}"'.format(self.config["id"]))
    migrations.migrate_paths(self.config)

    # Bail out if we find a process running and it matches out pidfile
    if self.check_running():
        log.exception("Salt minion is already running. Exiting.")
        self.shutdown(1)

    # TODO: AIO core is separate from transport
    if self.config["transport"].lower() in ("zeromq", "tcp"):
        # Late import so logging works correctly
        import salt.minion

        # If the minion key has not been accepted, then Salt enters a loop
        # waiting for it, if we daemonize later then the minion could halt
        # the boot process waiting for a key to be accepted on the master.
        # This is the latest safe place to daemonize
        self.daemonize_if_required()
        self.set_pidfile()
        if isinstance(self.config.get("master"), list):
            if self.config.get("master_type") == "failover":
                self.minion = salt.minion.Minion(self.config)
            else:
                self.minion = salt.minion.MultiMinion(self.config)
        else:
            self.minion = salt.minion.Minion(self.config)
    else:
        import salt.daemons.flo

        self.daemonize_if_required()
        self.set_pidfile()
        self.minion = salt.daemons.flo.IofloMinion(self.config)


# Traceback (ImportError)
[root@localhost ~]# salt-minion -ldebug
[DEBUG   ] Reading configuration from /etc/salt/minion
[DEBUG   ] Including configuration from '/etc/salt/minion.d/_schedule.conf'
[DEBUG   ] Reading configuration from /etc/salt/minion.d/_schedule.conf
[DEBUG   ] Using cached minion ID from /etc/salt/minion_id: 10.0.2.15
[DEBUG   ] Configuration file path: /etc/salt/minion
[WARNING ] Insecure logging configuration detected! Sensitive data may be logged.
[INFO    ] Setting up the Salt Minion "10.0.2.15"
Process Process-1:
Traceback (most recent call last):
File "/usr/lib64/python2.6/multiprocessing/process.py", line 232, in _bootstrap
self.run()
File "/usr/lib64/python2.6/multiprocessing/process.py", line 88, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python2.6/site-packages/salt/scripts.py", line 86, in minion_process
minion.start()
File "/usr/lib/python2.6/site-packages/salt/cli/daemons.py", line 330, in start
super(Minion, self).start()
File "/usr/lib/python2.6/site-packages/salt/utils/parsers.py", line 996, in start
self.prepare()
File "/usr/lib/python2.6/site-packages/salt/cli/daemons.py", line 315, in prepare
import salt.daemons.flo
File "/usr/lib/python2.6/site-packages/salt/daemons/flo/__init__.py", line 26, in <module>
from . import core
File "/usr/lib/python2.6/site-packages/salt/daemons/flo/core.py", line 23, in <module>
from raet import raeting
ImportError: No module named raet

# Fixed code
def prepare(self):
    """
    Run the preparation sequence required to start a salt minion.

    If sub-classed, don't **ever** forget to run:

        super(YourSubClass, self).prepare()
    """
    super(Minion, self).prepare()

    try:
        if self.config["verify_env"]:
            confd = self.config.get("default_include")
            if confd:
                # If 'default_include' is specified in config, then use it
                if "*" in confd:
                    # Value is of the form "minion.d/*.conf"
                    confd = os.path.dirname(confd)
                if not os.path.isabs(confd):
                    # If configured 'default_include' is not an absolute
                    # path, consider it relative to folder of 'conf_file'
                    # (/etc/salt by default)
                    confd = os.path.join(
                        os.path.dirname(self.config["conf_file"]), confd
                    )
            else:
                confd = os.path.join(
                    os.path.dirname(self.config["conf_file"]), "minion.d"
                )

            v_dirs = [
                self.config["pki_dir"],
                self.config["cachedir"],
                self.config["sock_dir"],
                self.config["extension_modules"],
                confd,
            ]

            if self.config.get("transport") == "raet":
                v_dirs.append(os.path.join(self.config["pki_dir"], "accepted"))
                v_dirs.append(os.path.join(self.config["pki_dir"], "pending"))
                v_dirs.append(os.path.join(self.config["pki_dir"], "rejected"))
                v_dirs.append(os.path.join(self.config["cachedir"], "raet"))

            verify_env(
                v_dirs,
                self.config["user"],
                permissive=self.config["permissive_pki_access"],
                pki_dir=self.config["pki_dir"],
            )
            logfile = self.config["log_file"]
            if logfile is not None and not logfile.startswith(
                ("tcp://", "udp://", "file://")
            ):
                # Logfile is not using Syslog, verify
                current_umask = os.umask(0o027)
                verify_files([logfile], self.config["user"])
                os.umask(current_umask)
    except OSError as err:
        self.environment_failure(err)

    self.setup_logfile_logger()
    verify_log(self.config)
    log.info('Setting up the Salt Minion "{0}"'.format(self.config["id"]))
    migrations.migrate_paths(self.config)

    # Bail out if we find a process running and it matches out pidfile
    if self.check_running():
        log.exception("Salt minion is already running. Exiting.")
        self.shutdown(1)

    transport = self.config.get("transport").lower()

    # TODO: AIO core is separate from transport
    if transport in ("zeromq", "tcp"):
        # Late import so logging works correctly
        import salt.minion

        # If the minion key has not been accepted, then Salt enters a loop
        # waiting for it, if we daemonize later then the minion could halt
        # the boot process waiting for a key to be accepted on the master.
        # This is the latest safe place to daemonize
        self.daemonize_if_required()
        self.set_pidfile()
        if isinstance(self.config.get("master"), list):
            if self.config.get("master_type") == "failover":
                self.minion = salt.minion.Minion(self.config)
            else:
                self.minion = salt.minion.MultiMinion(self.config)
        else:
            self.minion = salt.minion.Minion(self.config)
    elif transport == "raet":
        import salt.daemons.flo

        self.daemonize_if_required()
        self.set_pidfile()
        self.minion = salt.daemons.flo.IofloMinion(self.config)
    else:
        log.error(
            "The transport '{0}' is not supported. Please use one of the following: "
            "tcp, "
            "raet, "
            "or zeromq.".format(transport)
        )
        self.shutdown(1)