Exemple #1
0
def classify_kie_file(pathname):
    """Classify a kie-api-* file.

    :param pathname: the path to the file
    :returns: a BRMS version string, or None if not a Red Hat kie file.
    """
    # os.path.basename behaves differently if the last part of the
    # path ends in a /, so normalize.
    if pathname.endswith('/'):
        pathname = pathname[:-1]

    basename = os.path.basename(pathname)

    version_string = strip_suffix(strip_prefix(basename, 'kie-api-'), '.jar')

    if version_string in BRMS_CLASSIFICATIONS:
        return BRMS_CLASSIFICATIONS[version_string]

    if 'redhat' in version_string:
        return version_string

    return None
Exemple #2
0
def _process_satellite_fact(source, fact):
    """Process a fact and convert to a fingerprint.

    :param source: The source that provided this fact.
    :param facts: fact to process
    :returns: fingerprint produced from fact
    """
    # pylint: disable=too-many-branches

    fingerprint = {META_DATA_KEY: {}}

    # Common facts
    add_fact_to_fingerprint(source, 'hostname', fact, 'name', fingerprint)

    add_fact_to_fingerprint(source, 'os_release', fact, 'os_release',
                            fingerprint)
    add_fact_to_fingerprint(source, 'os_name', fact, 'os_name', fingerprint)
    add_fact_to_fingerprint(source, 'os_version', fact, 'os_version',
                            fingerprint)

    add_fact_to_fingerprint(source, 'mac_addresses', fact, 'mac_addresses',
                            fingerprint)
    add_fact_to_fingerprint(source, 'ip_addresses', fact, 'ip_addresses',
                            fingerprint)

    add_fact_to_fingerprint(source, 'cores', fact, 'cpu_count', fingerprint)
    add_fact_to_fingerprint(source, 'architecture', fact, 'architecture',
                            fingerprint)

    # Common network/satellite
    add_fact_to_fingerprint(source, 'uuid', fact, 'subscription_manager_id',
                            fingerprint)
    add_fact_to_fingerprint(source, 'virt_type', fact, 'virtualized_type',
                            fingerprint)

    is_virtualized = fact.get('is_virtualized')
    infrastructure_type = None
    if is_virtualized:
        infrastructure_type = 'virtualized'
    elif is_virtualized is False:
        infrastructure_type = SystemFingerprint.BARE_METAL
    if infrastructure_type:
        add_fact_to_fingerprint(source,
                                'is_virtualized',
                                fact,
                                'infrastructure_type',
                                fingerprint,
                                fact_value=infrastructure_type)
    # Satellite specific facts
    add_fact_to_fingerprint(source, 'cores', fact, 'cpu_core_count',
                            fingerprint)
    add_fact_to_fingerprint(source, 'num_sockets', fact, 'cpu_socket_count',
                            fingerprint)

    # Raw fact for system_creation_date
    reg_time = fact.get('registration_time')
    if reg_time:
        reg_time = strip_suffix(reg_time, ' UTC')
        add_fact_to_fingerprint(source,
                                'registration_time',
                                fact,
                                'registration_time',
                                fingerprint,
                                fact_value=reg_time)

    last_checkin = fact.get('last_checkin_time')
    if last_checkin:
        try:
            last_checkin = strip_suffix(last_checkin, ' UTC')
            dt_obj = datetime.strptime(last_checkin, '%Y-%m-%d %H:%M:%S')
            add_fact_to_fingerprint(source,
                                    'last_checkin_time',
                                    fact,
                                    'system_last_checkin_date',
                                    fingerprint,
                                    fact_value=dt_obj.date())
        except ValueError as date_err:
            logger.error('Could not parse date %s: %s', last_checkin, date_err)

    add_entitlements_to_fingerprint(source, 'entitlements', fact, fingerprint)
    add_products_to_fingerprint(source, fact, fingerprint)

    return fingerprint
Exemple #3
0
def _process_satellite_fact(source, fact):
    """Process a fact and convert to a fingerprint.

    :param source: The source that provided this fact.
    :param facts: fact to process
    :returns: fingerprint produced from fact
    """
    # pylint: disable=too-many-branches
    rhel_versions = {
        '4Server': 'Red Hat Enterprise Linux 4 Server',
        '5Server': 'Red Hat Enterprise Linux 5 Server',
        '6Server': 'Red Hat Enterprise Linux 6 Server',
        '7Server': 'Red Hat Enterprise Linux 7 Server',
        '8Server': 'Red Hat Enterprise Linux 8 Server'
    }

    fingerprint = {META_DATA_KEY: {}}

    # Common facts
    add_fact_to_fingerprint(source, 'hostname', fact, 'name', fingerprint)

    add_fact_to_fingerprint(source, 'os_name', fact, 'os_name', fingerprint)
    # Get the os name
    satellite_os_name = fact.get('os_name')
    is_redhat = False
    rhel_version = None
    # if the os name is none
    if not satellite_os_name:
        # grab the os release
        satellite_os_release = fact.get('os_release', '')
        if satellite_os_release in rhel_versions.keys():
            # if the os release is a rhel version
            # 1. set the is redhat fact to true and add it to fingerprint
            # 2. set the rhel version to the rhel versions value
            is_redhat = True
            rhel_version = rhel_versions[satellite_os_release]
        add_fact_to_fingerprint(source,
                                'os_release',
                                fact,
                                'is_redhat',
                                fingerprint,
                                fact_value=is_redhat)
    else:
        # if the os name indicates redhat, set is_redhat to true
        rhel_os_names = ['rhel', 'redhat', 'redhatenterpriselinux']
        if satellite_os_name.lower().replace(' ', '') in rhel_os_names:
            is_redhat = True
        add_fact_to_fingerprint(source,
                                'os_name',
                                fact,
                                'is_redhat',
                                fingerprint,
                                fact_value=is_redhat)
    if rhel_version:
        add_fact_to_fingerprint(source,
                                'os_release',
                                fact,
                                'os_release',
                                fingerprint,
                                fact_value=rhel_version)
    else:
        add_fact_to_fingerprint(source, 'os_release', fact, 'os_release',
                                fingerprint)

    add_fact_to_fingerprint(source, 'os_version', fact, 'os_version',
                            fingerprint)

    add_fact_to_fingerprint(source, 'mac_addresses', fact, 'mac_addresses',
                            fingerprint)
    add_fact_to_fingerprint(source, 'ip_addresses', fact, 'ip_addresses',
                            fingerprint)

    add_fact_to_fingerprint(source, 'cores', fact, 'cpu_count', fingerprint)
    add_fact_to_fingerprint(source, 'architecture', fact, 'architecture',
                            fingerprint)

    # Common network/satellite
    add_fact_to_fingerprint(source, 'uuid', fact, 'subscription_manager_id',
                            fingerprint)
    add_fact_to_fingerprint(source, 'virt_type', fact, 'virtualized_type',
                            fingerprint)

    is_virtualized = fact.get('is_virtualized')
    infrastructure_type = None
    if is_virtualized:
        infrastructure_type = 'virtualized'
    elif is_virtualized is False:
        infrastructure_type = SystemFingerprint.BARE_METAL
    if infrastructure_type:
        add_fact_to_fingerprint(source,
                                'is_virtualized',
                                fact,
                                'infrastructure_type',
                                fingerprint,
                                fact_value=infrastructure_type)
    # Satellite specific facts
    add_fact_to_fingerprint(source, 'cores', fact, 'cpu_core_count',
                            fingerprint)
    add_fact_to_fingerprint(source, 'num_sockets', fact, 'cpu_socket_count',
                            fingerprint)

    # Raw fact for system_creation_date
    reg_time = fact.get('registration_time')
    if reg_time:
        reg_time = strip_suffix(reg_time, ' UTC')
        add_fact_to_fingerprint(source,
                                'registration_time',
                                fact,
                                'registration_time',
                                fingerprint,
                                fact_value=reg_time)

    last_checkin = fact.get('last_checkin_time')
    if last_checkin:
        try:
            last_checkin = strip_suffix(last_checkin, ' UTC')
            dt_obj = datetime.strptime(last_checkin, '%Y-%m-%d %H:%M:%S')
            add_fact_to_fingerprint(source,
                                    'last_checkin_time',
                                    fact,
                                    'system_last_checkin_date',
                                    fingerprint,
                                    fact_value=dt_obj.date())
        except ValueError as date_err:
            logger.error('Could not parse date %s: %s', last_checkin, date_err)

    add_entitlements_to_fingerprint(source, 'entitlements', fact, fingerprint)
    add_products_to_fingerprint(source, fact, fingerprint)

    return fingerprint
 def test_strip_suffix(self):
     """Test the strip_suffix method."""
     string = 'modules.jar'
     suffix = '.jar'
     stripped = strip_suffix(string, suffix)
     self.assertEqual(stripped, 'modules')