# Buggy code
def install(
    name=None,
    refresh=False,
    fromrepo=None,
    skip_verify=False,
    pkgs=None,
    sources=None,
    **kwargs,
):
    """
    Install the passed package(s), add refresh=True to clean the yum database
    before package is installed.

    name
        The name of the package to be installed. Note that this parameter is
        ignored if either "pkgs" or "sources" is passed. Additionally, please
        note that this option can only be used to install packages from a
        software repository. To install a package file manually, use the
        "sources" option.

        32-bit packages can be installed on 64-bit systems by appending the
        architecture designation (``.i686``, ``.i586``, etc.) to the end of the
        package name.

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.install <package name>

    refresh
        Whether or not to update the yum database before executing.

    skip_verify
        Skip the GPG verification check (e.g., ``--nogpgcheck``)

    version
        Install a specific version of the package, e.g. 1.2.3-4.el5. Ignored
        if "pkgs" or "sources" is passed.


    Repository Options:

    fromrepo
        Specify a package repository (or repositories) from which to install.
        (e.g., ``yum --disablerepo='*' --enablerepo='somerepo'``)

    enablerepo (ignored if ``fromrepo`` is specified)
        Specify a disabled package repository (or repositories) to enable.
        (e.g., ``yum --enablerepo='somerepo'``)

    disablerepo (ignored if ``fromrepo`` is specified)
        Specify an enabled package repository (or repositories) to disable.
        (e.g., ``yum --disablerepo='somerepo'``)


    Multiple Package Installation Options:

    pkgs
        A list of packages to install from a software repository. Must be
        passed as a python list. A specific version number can be specified
        by using a single-element dict representing the package and its
        version.

        CLI Examples:

        .. code-block:: bash

            salt '*' pkg.install pkgs='["foo", "bar"]'
            salt '*' pkg.install pkgs='["foo", {"bar": "1.2.3-4.el5"}]'

    sources
        A list of RPM packages to install. Must be passed as a list of dicts,
        with the keys being package names, and the values being the source URI
        or local path to the package.

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.install sources='[{"foo": "salt://foo.rpm"}, {"bar": "salt://bar.rpm"}]'


    Returns a dict containing the new package names and versions::

        {'<package>': {'old': '<old-version>',
                       'new': '<new-version>'}}
    """
    if salt.utils.is_true(refresh):
        refresh_db()

    pkg_params, pkg_type = __salt__["pkg_resource.parse_targets"](
        name, pkgs, sources, **kwargs
    )
    if pkg_params is None or len(pkg_params) == 0:
        return {}

    version_num = kwargs.get("version")
    if version_num:
        if pkgs is None and sources is None:
            # Allow "version" to work for single package target
            pkg_params = {name: version_num}
        else:
            log.warning(
                '"version" parameter will be ignored for multiple package targets'
            )

    repo_arg = _get_repo_options(fromrepo=fromrepo, **kwargs)

    old = list_pkgs()
    downgrade = []
    if pkg_type == "repository":
        targets = []
        for pkgname, version_num in pkg_params.iteritems():
            if version_num is None:
                targets.append(pkgname)
            else:
                cver = old.get(pkgname, "")
                if __grains__.get("cpuarch", "") == "x86_64":
                    try:
                        arch = re.search(r"(\.i\d86)$", pkgname).group(1)
                    except AttributeError:
                        arch = ""
                    else:
                        # Remove arch from pkgname
                        pkgname = pkgname[: -len(arch)]
                else:
                    arch = ""
                pkgstr = '"{0}-{1}{2}"'.format(pkgname, version_num, arch)
                if not cver or __salt__["pkg.compare"](
                    pkg1=version_num, oper=">=", pkg2=cver
                ):
                    targets.append(pkgstr)
                else:
                    downgrade.append(pkgstr)
    else:
        targets = pkg_params

    if targets:
        cmd = "yum -y {repo} {gpgcheck} install {pkg}".format(
            repo=repo_arg,
            gpgcheck="--nogpgcheck" if skip_verify else "",
            pkg=" ".join(targets),
        )
        __salt__["cmd.run_all"](cmd)

    if downgrade:
        cmd = "yum -y {repo} {gpgcheck} downgrade {pkg}".format(
            repo=repo_arg,
            gpgcheck="--nogpgcheck" if skip_verify else "",
            pkg=" ".join(downgrade),
        )
        __salt__["cmd.run_all"](cmd)

    __context__.pop("pkg.list_pkgs", None)
    new = list_pkgs()
    return __salt__["pkg_resource.find_changes"](old, new)


# Traceback (AttributeError)
[ERROR   ] Error in function _master_opts:
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/salt/master.py", line 1444, in run_func
ret = getattr(self, func)(load)
File "/usr/lib/pymodules/python2.7/salt/master.py", line 891, in _master_opts
envs = self._file_envs()
File "/usr/lib/pymodules/python2.7/salt/fileserver/__init__.py", line 153, in envs
ret.update(self.servers[fstr]())
File "/usr/lib/pymodules/python2.7/salt/fileserver/hgfs.py", line 176, in envs
tags = repo.get_tags()
AttributeError: 'hgclient' object has no attribute 'get_tags'

# Fixed code
def install(
    name=None,
    refresh=False,
    fromrepo=None,
    skip_verify=False,
    pkgs=None,
    sources=None,
    **kwargs,
):
    """
    Install the passed package(s), add refresh=True to clean the yum database
    before package is installed.

    name
        The name of the package to be installed. Note that this parameter is
        ignored if either "pkgs" or "sources" is passed. Additionally, please
        note that this option can only be used to install packages from a
        software repository. To install a package file manually, use the
        "sources" option.

        32-bit packages can be installed on 64-bit systems by appending the
        architecture designation (``.i686``, ``.i586``, etc.) to the end of the
        package name.

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.install <package name>

    refresh
        Whether or not to update the yum database before executing.

    skip_verify
        Skip the GPG verification check (e.g., ``--nogpgcheck``)

    version
        Install a specific version of the package, e.g. 1.2.3-4.el5. Ignored
        if "pkgs" or "sources" is passed.


    Repository Options:

    fromrepo
        Specify a package repository (or repositories) from which to install.
        (e.g., ``yum --disablerepo='*' --enablerepo='somerepo'``)

    enablerepo (ignored if ``fromrepo`` is specified)
        Specify a disabled package repository (or repositories) to enable.
        (e.g., ``yum --enablerepo='somerepo'``)

    disablerepo (ignored if ``fromrepo`` is specified)
        Specify an enabled package repository (or repositories) to disable.
        (e.g., ``yum --disablerepo='somerepo'``)


    Multiple Package Installation Options:

    pkgs
        A list of packages to install from a software repository. Must be
        passed as a python list. A specific version number can be specified
        by using a single-element dict representing the package and its
        version.

        CLI Examples:

        .. code-block:: bash

            salt '*' pkg.install pkgs='["foo", "bar"]'
            salt '*' pkg.install pkgs='["foo", {"bar": "1.2.3-4.el5"}]'

    sources
        A list of RPM packages to install. Must be passed as a list of dicts,
        with the keys being package names, and the values being the source URI
        or local path to the package.

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.install sources='[{"foo": "salt://foo.rpm"}, {"bar": "salt://bar.rpm"}]'


    Returns a dict containing the new package names and versions::

        {'<package>': {'old': '<old-version>',
                       'new': '<new-version>'}}
    """
    if salt.utils.is_true(refresh):
        refresh_db()

    pkg_params, pkg_type = __salt__["pkg_resource.parse_targets"](
        name, pkgs, sources, **kwargs
    )
    if pkg_params is None or len(pkg_params) == 0:
        return {}

    version_num = kwargs.get("version")
    if version_num:
        if pkgs is None and sources is None:
            # Allow "version" to work for single package target
            pkg_params = {name: version_num}
        else:
            log.warning(
                '"version" parameter will be ignored for multiple package targets'
            )

    repo_arg = _get_repo_options(fromrepo=fromrepo, **kwargs)

    old = list_pkgs()
    downgrade = []
    if pkg_type == "repository":
        targets = []
        for pkgname, version_num in pkg_params.iteritems():
            if version_num is None:
                targets.append(pkgname)
            else:
                cver = old.get(pkgname, "")
                if __grains__.get("cpuarch", "") == "x86_64":
                    try:
                        arch = re.search(r"(\.i\d86)$", pkgname).group(1)
                    except AttributeError:
                        arch = ""
                    else:
                        # Remove arch from pkgname
                        pkgname = pkgname[: -len(arch)]
                else:
                    arch = ""
                pkgstr = '"{0}-{1}{2}"'.format(pkgname, version_num, arch)
                if not cver or salt.utils.compare_versions(
                    ver1=version_num, oper=">=", ver2=cver
                ):
                    targets.append(pkgstr)
                else:
                    downgrade.append(pkgstr)
    else:
        targets = pkg_params

    if targets:
        cmd = "yum -y {repo} {gpgcheck} install {pkg}".format(
            repo=repo_arg,
            gpgcheck="--nogpgcheck" if skip_verify else "",
            pkg=" ".join(targets),
        )
        __salt__["cmd.run_all"](cmd)

    if downgrade:
        cmd = "yum -y {repo} {gpgcheck} downgrade {pkg}".format(
            repo=repo_arg,
            gpgcheck="--nogpgcheck" if skip_verify else "",
            pkg=" ".join(downgrade),
        )
        __salt__["cmd.run_all"](cmd)

    __context__.pop("pkg.list_pkgs", None)
    new = list_pkgs()
    return __salt__["pkg_resource.find_changes"](old, new)