import itertools


def _errata_keywords(names, keywords, pkeywords):
    """
    Make a list of errata keywords of given list of packages `names`.

    :param names: Package names
    :param keywords: A tuple of keywords to filter 'important' RHBAs
    :param pkeywords: Similar to above but a dict gives the list per RPMs
    :return: A set of keywords

    >>> names = ["kernel", "glibc"]
    >>> keywords = ['crash', 'panic', 'hang']
    >>> pkeywords = dict(kernel=["xfs", "kvm"], glibc=["nss", "segv"])
    >>> kwds = _errata_keywords(names, keywords, pkeywords)
    >>> ref = keywords
    >>> for keys in pkeywords.values():
    ...     ref.extend(keys)
    >>> all(k in ref for k in kwds)
    True
    """
    return set(itertools.chain(keywords,
                               *[pkeywords.get(n, []) for n in names]))