| 
13 | 13 | """  | 
14 | 14 | 
 
  | 
15 | 15 | # For ease of use hc refers to host-collection throughout this document  | 
 | 16 | +from datetime import timezone, datetime  | 
16 | 17 | from time import sleep, time  | 
17 | 18 | 
 
  | 
18 | 19 | import pytest  | 
 | 20 | +import requests  | 
19 | 21 | 
 
  | 
20 | 22 | from robottelo.config import settings  | 
21 | 23 | from robottelo.constants import (  | 
@@ -1618,3 +1620,145 @@ def test_positive_incremental_update_apply_to_envs_cvs(  | 
1618 | 1620 |     assert response == [], (  | 
1619 | 1621 |         f'No incremental updates should currently be available to host: {rhel8_contenthost.hostname}.'  | 
1620 | 1622 |     )  | 
 | 1623 | + | 
 | 1624 | + | 
 | 1625 | +@pytest.mark.tier3  | 
 | 1626 | +def test_positive_filter_errata_type_other(  | 
 | 1627 | +    module_sca_manifest_org,  | 
 | 1628 | +    target_sat,  | 
 | 1629 | +    module_cv,  | 
 | 1630 | +):  | 
 | 1631 | +    """  | 
 | 1632 | +    Sync the EPEL repository, containing many Erratum that are not of the  | 
 | 1633 | +        usual types: 'Bugfix', 'Enhancement', 'Security'.  | 
 | 1634 | +    Publish a content view version, filtering inclusively all Errata types, including 'Other'.  | 
 | 1635 | +
  | 
 | 1636 | +    We expect filtering by all types including Other, does not change package or errata counts,  | 
 | 1637 | +        between the unfiltered and filtered content view versions.  | 
 | 1638 | +
  | 
 | 1639 | +    Note: We need to fetch a dynamically created PGP public key to sync the EPEL repository.  | 
 | 1640 | +
  | 
 | 1641 | +    :id: 062bb1a5-814c-4573-bedc-aaa4e2ef557a  | 
 | 1642 | +
  | 
 | 1643 | +    :setup:  | 
 | 1644 | +        1. Fetch the latest supported RHEL major version in supportability.yaml (ie: 10)  | 
 | 1645 | +        2. GET request to EPEL's rpm GPG-key generator (dl.fedoraproject.org/pub/epel/)  | 
 | 1646 | +        3. Create GPG-key on satellite from URL's response.  | 
 | 1647 | +        4. Create custom product using the GPG-key.  | 
 | 1648 | +
  | 
 | 1649 | +    :steps:  | 
 | 1650 | +        1. Create and sync the EPEL repository as a custom repo (~5 minutes)  | 
 | 1651 | +        2. Verify presence of new Erratum types that would fall under 'other'.  | 
 | 1652 | +        3. Create a content view, add the EPEL repo, publish the first version.  | 
 | 1653 | +        4. Create a content view filter for Erratum (by Date), inclusive.  | 
 | 1654 | +        5. Update Erratum filter rules: set end_date to today (UTC),  | 
 | 1655 | +            set flag --allow-other-types to True <<<  | 
 | 1656 | +            no start_date specified.  | 
 | 1657 | +        6. Create another content view filter for RPMs, inclusive.  | 
 | 1658 | +        7. Publish a second version (~10 minutes).  | 
 | 1659 | +
  | 
 | 1660 | +    :expectedresults:  | 
 | 1661 | +        1. The second published version with filters, has the same  | 
 | 1662 | +            content counts (packages and erratum) as the first unfiltered version.  | 
 | 1663 | +        2. The second version's filters applied, has published Erratum of types that  | 
 | 1664 | +            fall under 'Other' (ie 'newpackage' , 'unspecified').  | 
 | 1665 | +        3. There are significantly more Total Errata published, than the sum of  | 
 | 1666 | +            the 3 normal types of Errata (bugfix,enhancement,security).  | 
 | 1667 | +
  | 
 | 1668 | +    :BZ: 2160804  | 
 | 1669 | +
  | 
 | 1670 | +    :verifies: SAT-20365  | 
 | 1671 | +
  | 
 | 1672 | +    :customerscenario: true  | 
 | 1673 | +
  | 
 | 1674 | +    """  | 
 | 1675 | +    # newest version rhel  | 
 | 1676 | +    rhel_N = next(  | 
 | 1677 | +        r  | 
 | 1678 | +        for r in reversed(settings.supportability.content_hosts.rhel.versions)  | 
 | 1679 | +        if 'fips' not in str(r)  | 
 | 1680 | +    )  | 
 | 1681 | +    # fetch a newly generated PGP key from address's response  | 
 | 1682 | +    gpg_url = f'https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-{rhel_N}'  | 
 | 1683 | +    _response = requests.get(gpg_url, timeout=120, verify=True)  | 
 | 1684 | +    _response.raise_for_status()  | 
 | 1685 | +    # handle a valid response that might not be a PGP key  | 
 | 1686 | +    if "-----BEGIN PGP PUBLIC KEY BLOCK-----" not in _response.text:  | 
 | 1687 | +        raise ValueError('Fetched content was not a valid credential')  | 
 | 1688 | + | 
 | 1689 | +    # create GPG key on satellite and associated product  | 
 | 1690 | +    gpg_key = target_sat.api.GPGKey(  | 
 | 1691 | +        organization=module_sca_manifest_org.id,  | 
 | 1692 | +        content=_response.text,  | 
 | 1693 | +    ).create()  | 
 | 1694 | +    epel_product = target_sat.api.Product(  | 
 | 1695 | +        organization=module_sca_manifest_org,  | 
 | 1696 | +        gpg_key=gpg_key,  | 
 | 1697 | +    ).create()  | 
 | 1698 | + | 
 | 1699 | +    # create and sync custom EPEL repo  | 
 | 1700 | +    epel_url = f'https://dl.fedoraproject.org/pub/epel/{rhel_N}/Everything/x86_64/'  | 
 | 1701 | +    epel_repo = target_sat.api.Repository(  | 
 | 1702 | +        product=epel_product,  | 
 | 1703 | +        url=epel_url,  | 
 | 1704 | +    ).create()  | 
 | 1705 | +    epel_repo.sync(timeout=1800)  | 
 | 1706 | +    # add repo to CV and publish  | 
 | 1707 | +    module_cv.repository = [epel_repo.read()]  | 
 | 1708 | +    module_cv.update(['repository'])  | 
 | 1709 | +    module_cv.read().publish(timeout=240)  # initial unfiltered Version publishes quick  | 
 | 1710 | +    module_cv = module_cv.read()  | 
 | 1711 | + | 
 | 1712 | +    # create errata filter  | 
 | 1713 | +    errata_filter = target_sat.api.ErratumContentViewFilter(  | 
 | 1714 | +        content_view=module_cv,  | 
 | 1715 | +        name='errata-filter',  | 
 | 1716 | +        inclusion=True,  | 
 | 1717 | +    ).create()  | 
 | 1718 | + | 
 | 1719 | +    today_UTC = datetime.now(timezone.utc).strftime('%Y-%m-%d')  | 
 | 1720 | +    # rule to filter erratum by date, only specify end_date  | 
 | 1721 | +    errata_rule = target_sat.api.ContentViewFilterRule(  | 
 | 1722 | +        content_view_filter=errata_filter,  | 
 | 1723 | +        end_date=today_UTC,  | 
 | 1724 | +    ).create()  | 
 | 1725 | + | 
 | 1726 | +    # hammer update the Erratum filter rule, flag 'allow-other-types' set to True <<<  | 
 | 1727 | +    target_sat.cli.ContentViewFilterRule.update(  | 
 | 1728 | +        {  | 
 | 1729 | +            'id': errata_rule.id,  | 
 | 1730 | +            'allow-other-types': 'true',  | 
 | 1731 | +            'content-view-filter-id': errata_filter.id,  | 
 | 1732 | +        }  | 
 | 1733 | +    )  | 
 | 1734 | +    module_cv = module_cv.read()  | 
 | 1735 | + | 
 | 1736 | +    # create rpm filter  | 
 | 1737 | +    target_sat.api.RPMContentViewFilter(  | 
 | 1738 | +        content_view=module_cv,  | 
 | 1739 | +        name='rpm-filter',  | 
 | 1740 | +        inclusion=True,  | 
 | 1741 | +    ).create()  | 
 | 1742 | + | 
 | 1743 | +    # Publish 2nd Version with inclusive filters applied  | 
 | 1744 | +    module_cv = module_cv.read()  | 
 | 1745 | +    module_cv.publish(timeout=1200)  # can take ~10 minutes, timeout is double that  | 
 | 1746 | +    module_cv = module_cv.read()  | 
 | 1747 | + | 
 | 1748 | +    version_1 = module_cv.version[-1].read()  # unfiltered  | 
 | 1749 | +    version_2 = module_cv.version[0].read()  # filtered  | 
 | 1750 | +    # errata and package counts match between the filtered and unfiltered versions  | 
 | 1751 | +    assert version_1.errata_counts == version_2.errata_counts  | 
 | 1752 | +    assert version_1.package_count == version_2.package_count  | 
 | 1753 | + | 
 | 1754 | +    # most of the EPEL repo's erratum are of type Other (~90%),  | 
 | 1755 | +    # so we expect the total number of errata is much greater  | 
 | 1756 | +    #   than the sum of the 3 regular types (bugfix,enhancement,security)  | 
 | 1757 | +    #   ie. The repo has ~200 errata of the 3 types, but over 2500 total errata.  | 
 | 1758 | +    regular_types_sum = sum(  | 
 | 1759 | +        [version_2.errata_counts[key] for key in ['security', 'bugfix', 'enhancement']]  | 
 | 1760 | +    )  | 
 | 1761 | +    total_errata = version_2.errata_counts['total']  | 
 | 1762 | +    assert total_errata > 2000  | 
 | 1763 | +    # Based on counts, the 3 regular types make up less than 1/5 of the total.  | 
 | 1764 | +    assert regular_types_sum < total_errata / 5  | 
0 commit comments