# 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(ProxyMinion, self).prepare()

    if not self.values.proxyid:
        raise SaltSystemExit("salt-proxy requires --proxyid")

    # Proxies get their ID from the command line.  This may need to change in
    # the future.
    self.config["id"] = self.values.proxyid

    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"],
            )
            if "proxy_log" in self.config:
                logfile = self.config["proxy_log"]
            else:
                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:
        logger.exception("Failed to prepare salt environment")
        self.shutdown(err.errno)

    self.setup_logfile_logger()
    verify_log(self.config)
    logger.info('Setting up a Salt Proxy Minion "{0}"'.format(self.config["id"]))
    migrations.migrate_paths(self.config)
    # 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()
        # TODO Proxy minions don't currently support failover
        self.minion = salt.minion.ProxyMinion(self.config)
    else:
        # For proxy minions, this doesn't work yet.
        import salt.daemons.flo

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


# Traceback (optparse.OptionConflictError)
/usr/lib/python2.7/dist-packages/salt/utils/parsers.py:953: DeprecationWarning: Please stop sub-classing PidfileMix and instead subclass DaemonMixIn which contains the same behavior. PidfileMixin will be supported until Salt Nitrogen (Unreleased).
Traceback (most recent call last):
File "/usr/bin/salt-api", line 8, in <module>
salt_api()
File "/usr/lib/python2.7/dist-packages/salt/scripts.py", line 441, in salt_api
sapi = salt.cli.api.SaltAPI()  # pylint: disable=E1120
File "/usr/lib/python2.7/dist-packages/salt/utils/parsers.py", line 152, in __init__
optparse.OptionParser.__init__(self, *args, **kwargs)
File "/usr/lib/python2.7/optparse.py", line 1220, in __init__
add_help=add_help_option)
File "/usr/lib/python2.7/dist-packages/salt/utils/parsers.py", line 233, in _populate_option_list
mixin_setup_func(self)
File "/usr/lib/python2.7/dist-packages/salt/utils/parsers.py", line 962, in _mixin_setup
help=('Specify the location of the pidfile. Default: %default')
File "/usr/lib/python2.7/optparse.py", line 1021, in add_option
self._check_conflict(option)
File "/usr/lib/python2.7/optparse.py", line 996, in _check_conflict
option)
optparse.OptionConflictError: option --pid-file: conflicting option string(s): --pid-file

# 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(ProxyMinion, self).prepare()

    if not self.values.proxyid:
        raise SaltSystemExit("salt-proxy requires --proxyid")

    # Proxies get their ID from the command line.  This may need to change in
    # the future.
    self.config["id"] = self.values.proxyid

    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"],
            )
            if "proxy_log" in self.config:
                logfile = self.config["proxy_log"]
            else:
                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:
        log.exception("Failed to prepare salt environment")
        self.shutdown(err.errno)

    self.setup_logfile_logger()
    verify_log(self.config)
    log.info('Setting up a Salt Proxy Minion "{0}"'.format(self.config["id"]))
    migrations.migrate_paths(self.config)
    # 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()
        # TODO Proxy minions don't currently support failover
        self.minion = salt.minion.ProxyMinion(self.config)
    else:
        # For proxy minions, this doesn't work yet.
        import salt.daemons.flo

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