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

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

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

    try:
        if self.config["verify_env"]:
            v_dirs = [
                self.config["pki_dir"],
                os.path.join(self.config["pki_dir"], "minions"),
                os.path.join(self.config["pki_dir"], "minions_pre"),
                os.path.join(self.config["pki_dir"], "minions_denied"),
                os.path.join(self.config["pki_dir"], "minions_autosign"),
                os.path.join(self.config["pki_dir"], "minions_rejected"),
                self.config["cachedir"],
                os.path.join(self.config["cachedir"], "jobs"),
                os.path.join(self.config["cachedir"], "proc"),
                self.config["sock_dir"],
                self.config["token_dir"],
                self.config["syndic_dir"],
                self.config["sqlite_queue_dir"],
            ]
            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)
            # Clear out syndics from cachedir
            for syndic_file in os.listdir(self.config["syndic_dir"]):
                os.remove(os.path.join(self.config["syndic_dir"], syndic_file))
    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 the Salt Master")

    # TODO: AIO core is separate from transport
    if self.config["transport"].lower() in ("zeromq", "tcp"):
        if not verify_socket(
            self.config["interface"],
            self.config["publish_port"],
            self.config["ret_port"],
        ):
            self.shutdown(4, "The ports are not available to bind")
        self.config["interface"] = ip_bracket(self.config["interface"])
        migrations.migrate_paths(self.config)

        # Late import so logging works correctly
        import salt.master

        self.master = salt.master.Master(self.config)
    else:
        # Add a udp port check here
        import salt.daemons.flo

        self.master = salt.daemons.flo.IofloMaster(self.config)
    self.daemonize_if_required()
    self.set_pidfile()
    salt.utils.process.notify_systemd()


# 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 master server.

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

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

    try:
        if self.config["verify_env"]:
            v_dirs = [
                self.config["pki_dir"],
                os.path.join(self.config["pki_dir"], "minions"),
                os.path.join(self.config["pki_dir"], "minions_pre"),
                os.path.join(self.config["pki_dir"], "minions_denied"),
                os.path.join(self.config["pki_dir"], "minions_autosign"),
                os.path.join(self.config["pki_dir"], "minions_rejected"),
                self.config["cachedir"],
                os.path.join(self.config["cachedir"], "jobs"),
                os.path.join(self.config["cachedir"], "proc"),
                self.config["sock_dir"],
                self.config["token_dir"],
                self.config["syndic_dir"],
                self.config["sqlite_queue_dir"],
            ]
            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)
            # Clear out syndics from cachedir
            for syndic_file in os.listdir(self.config["syndic_dir"]):
                os.remove(os.path.join(self.config["syndic_dir"], syndic_file))
    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 the Salt Master")

    # TODO: AIO core is separate from transport
    if self.config["transport"].lower() in ("zeromq", "tcp"):
        if not verify_socket(
            self.config["interface"],
            self.config["publish_port"],
            self.config["ret_port"],
        ):
            self.shutdown(4, "The ports are not available to bind")
        self.config["interface"] = ip_bracket(self.config["interface"])
        migrations.migrate_paths(self.config)

        # Late import so logging works correctly
        import salt.master

        self.master = salt.master.Master(self.config)
    else:
        # Add a udp port check here
        import salt.daemons.flo

        self.master = salt.daemons.flo.IofloMaster(self.config)
    self.daemonize_if_required()
    self.set_pidfile()
    salt.utils.process.notify_systemd()