Exemplo n.º 1
0
    def setUp(self):
        self.sorter = Mock()
        self.sorter.valid_products = [INST_PID_1]
        self.sorter.valid_entitlement_certs = [
            StubEntitlementCertificate(PROD_2, ent_id=ENT_ID_2),
            StubEntitlementCertificate(PROD_1, ent_id=ENT_ID_1),
            StubEntitlementCertificate(product=PROD_4,
                                       stacking_id=STACK_1,
                                       ent_id=ENT_ID_4),
            StubEntitlementCertificate(StubProduct('not_installed_product',
                                                   name="Some Product"),
                                       ent_id="SomeSubId")
        ]
        reason_list = []
        reason_list.append(
            self.build_reason('NOTCOVERED',
                              'Not covered by a valid subscription.', {
                                  'product_id': '801',
                                  'name': 'RAM Limiting Product'
                              }))
        reason_list.append(
            self.build_ent_reason_with_attrs(
                'CORES',
                'Only covers 16 of 32 cores.',
                '32',
                '16',
                name='Multi-Attribute Stackable (16 cores, 4 sockets, 8GB RAM)',
                stack='multiattr-stack-test'))
        reason_list.append(
            self.build_ent_reason_with_attrs(
                'SOCKETS',
                'Only covers 4 of 8 sockets.',
                '8',
                '4',
                name='Multi-Attribute Stackable (16 cores, 4 sockets, 8GB RAM)',
                stack='multiattr-stack-test'))
        reason_list.append(
            self.build_ent_reason_with_attrs(
                'RAM',
                'Only covers 8GB of 31GB of RAM.',
                '31',
                '8',
                name='Multi-Attribute Stackable (16 cores, 4 sockets, 8GB RAM)',
                stack='multiattr-stack-test'))
        reason_list.append(
            self.build_ent_reason_with_attrs(
                'ARCH',
                'Covers architecture ppc64 but the system is x86_64.',
                'x86_64',
                'ppc64',
                name='Awesome OS for ppc64',
                ent='ff8080813e468fd8013e4694a4921179'))

        self.sorter.reasons = Reasons(reason_list, self.sorter)
Exemplo n.º 2
0
    def test_get_subscription_reasons_map_ent_id_not_in_valid_ent_certs(self):
        reason_expired_entid = \
            self.build_ent_reason_with_attrs(key='ARCH', message='This is not a reason reasons.',
                                             has='x86_64', covered='ppc64',
                                             name='Awesome OS for ppc64',
                                             ent=NOT_VALID_ENT_ID)

        self.sorter.valid_entitlement_certs = []
        self.sorter.reasons = Reasons([reason_expired_entid], self.sorter)

        sub_reason_map = self.sorter.reasons.get_subscription_reasons_map()
        self.assertTrue(NOT_VALID_ENT_ID not in sub_reason_map)
Exemplo n.º 3
0
    def load(self):
        # All products installed on this machine, regardless of status. Maps
        # installed product ID to product certificate.
        self.installed_products = self.product_dir.get_installed_products()

        # Installed products which do not have an entitlement that is valid,
        # or expired. They may however have entitlements for the future.
        # Maps installed product ID to the product certificate.
        self.unentitled_products = {}

        # Products which are installed, there are entitlements, but they have
        # expired on the date in question. If another valid or partially valid
        # entitlement provides the installed product, that product should not
        # appear in this dict.
        # Maps product ID to the expired entitlement certificate:
        self.expired_products = {}

        # Products that are only partially entitled (aka, "yellow"). If another
        # non-stacked entitlement is valid and provides the installed product,
        # it will not appear in this dict.
        # Maps installed product ID to the stacked entitlement certificates
        # providing it.
        self.partially_valid_products = {}

        # Products which are installed, and entitled on the given date.
        # Maps product ID to a list of all valid entitlement certificates:
        self.valid_products = {}

        # Maps stack ID to a list of the entitlement certs composing a
        # partially valid stack:
        self.partial_stacks = {}

        # Products which are installed and entitled sometime in the future.
        # Maps product ID to future entitlements.
        self.future_products = {}

        # Reasons that products aren't fully compliant
        self.reasons = Reasons([], self)
        self.supports_reasons = False

        self.system_status = 'unknown'

        self.valid_entitlement_certs = []

        self._parse_server_status()
Exemplo n.º 4
0
    def setUp(self):
        self.sorter = Mock()
        self.sorter.valid_products = [INST_PID_1]
        self.sorter.valid_entitlement_certs = [
            StubEntitlementCertificate(PROD_2, ent_id=ENT_ID_2),
            StubEntitlementCertificate(PROD_1, ent_id=ENT_ID_1),
            StubEntitlementCertificate(product=PROD_4, stacking_id=STACK_1, ent_id=ENT_ID_4),
            StubEntitlementCertificate(
                StubProduct("not_installed_product", name="Some Product"), ent_id="SomeSubId"
            ),
        ]
        reason_list = []
        reason_list.append(
            self.build_reason(
                "NOTCOVERED",
                "Not covered by a valid subscription.",
                {"product_id": "801", "name": "RAM Limiting Product"},
            )
        )
        reason_list.append(
            self.build_ent_reason_with_attrs(
                "CORES",
                "Only covers 16 of 32 cores.",
                "32",
                "16",
                name="Multi-Attribute Stackable (16 cores, 4 sockets, 8GB RAM)",
                stack="multiattr-stack-test",
            )
        )
        reason_list.append(
            self.build_ent_reason_with_attrs(
                "SOCKETS",
                "Only covers 4 of 8 sockets.",
                "8",
                "4",
                name="Multi-Attribute Stackable (16 cores, 4 sockets, 8GB RAM)",
                stack="multiattr-stack-test",
            )
        )
        reason_list.append(
            self.build_ent_reason_with_attrs(
                "RAM",
                "Only covers 8GB of 31GB of RAM.",
                "31",
                "8",
                name="Multi-Attribute Stackable (16 cores, 4 sockets, 8GB RAM)",
                stack="multiattr-stack-test",
            )
        )
        reason_list.append(
            self.build_ent_reason_with_attrs(
                "RAM",
                "A different way to say Only covers 8GB of 31GB of RAM.",
                "31",
                "8",
                name="Multi-Attribute Stackable (16 cores, 4 sockets, 8GB RAM)",
                stack="multiattr-stack-test",
            )
        )
        # This is a dupe of the above, since reasons.py has code for detecting
        # dupe messages or names.
        reason_list.append(
            self.build_ent_reason_with_attrs(
                "RAM",
                "Only covers 8GB of 31GB of RAM.",
                "31",
                "8",
                name="Multi-Attribute Stackable (16 cores, 4 sockets, 8GB RAM)",
                stack="multiattr-stack-test",
            )
        )
        reason_list.append(
            self.build_ent_reason_with_attrs(
                "ARCH",
                "Covers architecture ppc64 but the system is x86_64.",
                "x86_64",
                "ppc64",
                name="Awesome OS for ppc64",
                ent=ENT_ID_2,
            )
        )

        self.sorter.reasons = Reasons(reason_list, self.sorter)
Exemplo n.º 5
0
    def _parse_server_status(self):
        """ Fetch entitlement status info from server and parse. """

        if not self.is_registered():
            log.debug("Unregistered, skipping server compliance check.")
            return

        # Override get_status
        status = self.get_compliance_status()
        if status is None:
            return

        # TODO: we're now mapping product IDs to entitlement cert JSON,
        # previously we mapped to actual entitlement cert objects. However,
        # nothing seems to actually use these, so it may not matter for now.
        self.valid_products = status['compliantProducts']

        self.partially_valid_products = status['partiallyCompliantProducts']

        self.partial_stacks = status['partialStacks']

        if 'reasons' in status:
            self.supports_reasons = True
            self.reasons = Reasons(status['reasons'], self)

        if 'status' in status and len(status['status']):
            self.system_status = status['status']
        # Some old candlepin versions do not return 'status' with information
        elif status['nonCompliantProducts']:
            self.system_status = 'invalid'
        elif self.partially_valid_products or self.partial_stacks or \
                self.reasons.reasons:
            self.system_status = 'partial'
        else:
            self.system_status = 'unknown'

        # For backward compatability with old find first invalid date,
        # we drop one second from the compliant until from server (as
        # it is returning the first second we are invalid), then add a full
        # 24 hours giving us the first date where we know we're completely
        # invalid from midnight to midnight.
        self.compliant_until = None

        if status['compliantUntil'] is not None:
            self.compliant_until = parse_date(status['compliantUntil'])

        # Lookup product certs for each unentitled product returned by
        # the server:
        unentitled_pids = status['nonCompliantProducts']
        # Add in any installed products not in the server response. This
        # could happen if something changes before the certd runs. Log
        # a warning if it does, and treat it like an unentitled product.
        for pid in list(self.installed_products.keys()):
            if pid not in self.valid_products and pid not in \
                    self.partially_valid_products and pid not in \
                    unentitled_pids:
                log.warn("Installed product %s not present in response from "
                         "server." % pid)
                unentitled_pids.append(pid)

        for unentitled_pid in unentitled_pids:
            prod_cert = self.product_dir.find_by_product(unentitled_pid)
            # Ignore anything server thinks we have but we don't.
            if prod_cert is None:
                log.warn("Server reported installed product not on system: %s" %
                         unentitled_pid)
                continue
            self.unentitled_products[unentitled_pid] = prod_cert

        self._scan_entitlement_certs()

        self.log_products()