コード例 #1
0
def process_fact_collection(sender, instance, **kwargs):
    """Process facts using engine and convert to fingerprints.

    :param sender: Class that was saved
    :param instance: FactCollection that was saved
    :param kwargs: Other args
    :returns: None
    """
    # pylint: disable=unused-argument

    # Convert to python dictionary
    fact_collection = FactCollectionSerializer(instance).data

    # Extract facts and collection id
    fact_collection_id = fact_collection['id']
    facts = fact_collection['facts']

    # Invoke ENGINE to create fingerprints from facts
    fingerprints_list = ENGINE.process_facts(fact_collection_id, facts)

    for fingerprint_dict in fingerprints_list:
        serializer = FingerprintSerializer(data=fingerprint_dict)
        if serializer.is_valid():
            serializer.save()
        else:
            logger.error('%s could not persist fingerprint. SystemFacts: %s',
                         __name__, fingerprint_dict)
            logger.error('Errors: %s', serializer.errors)
コード例 #2
0
def process_fact_collection(sender, instance, **kwargs):
    """Process the fact collection.

    :param sender: Class that was saved
    :param instance: FactCollection that was saved
    :param kwargs: Other args
    :returns: None
    """
    # pylint: disable=unused-argument
    logger.info('Fingerprint engine (report id=%d) - start processing',
                instance.id)

    # Invoke ENGINE to create fingerprints from facts
    fingerprints_list = _process_sources(instance)

    number_valid = 0
    number_invalid = 0
    for fingerprint_dict in fingerprints_list:
        serializer = FingerprintSerializer(data=fingerprint_dict)
        if serializer.is_valid():
            number_valid += 1
            serializer.save()
        else:
            number_invalid += 1
            logger.error('Invalid fingerprint: %s', fingerprint_dict)
            logger.error('Fingerprint errors: %s', serializer.errors)

    logger.info(
        'Fingerprint engine (report id=%d) - end processing '
        '(valid fingerprints=%d, invalid fingerprints=%d)', instance.id,
        number_valid, number_invalid)

    # Mark completed because engine has process raw facts
    instance.status = FactCollection.FC_STATUS_COMPLETE
    instance.save()
コード例 #3
0
    def test_empty_fingerprint(self):
        """Create an empty fingerprint."""
        fingerprint_dict = {'fact_collection_id': self.fact_collection.id,
                            'metadata': {}}

        serializer = FingerprintSerializer(data=fingerprint_dict)
        is_valid = serializer.is_valid()
        if not is_valid:
            print(serializer.errors)
        self.assertTrue(is_valid)
        serializer.save()
コード例 #4
0
    def test_entitlement_fingerprint(self):
        """Create a fingerprint with entitlements."""
        entitlement_dict = {
            'name': 'RHEL Server',
            'entitlement_id': '69',
            'metadata': {}
        }
        fingerprint_dict = {
            'report_id': self.fact_collection.id,
            'metadata': {},
            'entitlements': [entitlement_dict],
            'sources': []
        }

        serializer = FingerprintSerializer(data=fingerprint_dict)
        is_valid = serializer.is_valid()
        if not is_valid:
            print(serializer.errors)
        self.assertTrue(is_valid)
        serializer.save()
コード例 #5
0
    def test_product_fingerprint(self):
        """Create a fingerprint with products."""
        product_dict = {
            'name': 'product1',
            'presence': 'unknown',
            'metadata': {}
        }
        fingerprint_dict = {
            'report_id': self.fact_collection.id,
            'metadata': {},
            'products': [product_dict],
            'sources': []
        }

        serializer = FingerprintSerializer(data=fingerprint_dict)
        is_valid = serializer.is_valid()
        if not is_valid:
            print(serializer.errors)
        self.assertTrue(is_valid)
        serializer.save()