Пример #1
0
 def _set(self, tag, value):
     if tag == 'columns':
         self.columns = []
         self.column_indexes = {}
         self.column_types = {}
         self.column_descriptions = {}
         lines = filter(lambda x: x != '', re.split('\s*\n\s*', value))
         i = 0
         for l in lines:
             description = None
             try:
                 (c, description) = re.split('\s+', l, 1)
             except:
                 c = l
             try:
                 (c, t) = re.split(':', c, 1)
             except:
                 t = 's'
             self.columns.append(c)
             self.column_indexes[c] = i
             self.column_types[c] = t
             if description != None:
                 self.column_descriptions[c] = description
             i = i + 1
     elif tag == 'params':
         lines = filter(lambda x: x != '', re.split('\s*\n\s*', value))
         for l in lines:
             (p, v) = re.split('\s+', l, 1)
             (component, option) = re.split('\.', v, 1)
             cfg = RHNOptions(component)
             cfg.parse()
             self.params[p] = str(cfg.get(option))
     elif tag == 'multival_columns':
         # the multival_columns specifies either
         # a "stop" column, usually the first one,
         # or a pair of column names separated by colon,
         # where the first on is column which should be
         # joined together and the second one is column
         # whose value should be used to distinguish if
         # we still have the same entity or not.
         for l in filter(lambda x: x != '', re.split('\n', value)):
             m = re.match('^\s*(\S+?)(\s*:\s*(\S*)\s*)?$', l)
             if m == None:
                 continue
             (col, id_col) = (m.group(1), m.group(3))
             if col != None:
                 self.multival_column_names[col] = id_col
     elif tag == 'sql':
         self.sql = value
     elif tag == 'synopsis':
         self.synopsis = re.sub('^(\s*\n)+\s*|(\s*\n)+$', '', value)
     elif tag == 'description':
         self.description = re.sub(
             '(?m)^\s*', '    ', re.sub('^(\s*\n)+\s*|(\s*\n)+$', '',
                                        value))
     else:
         raise spacewalk_report_unknown_tag_exception(tag)
Пример #2
0
 def _set(self, tag, value):
         if tag == 'columns':
                 self.columns = []
                 self.column_indexes = {}
                 self.column_types = {}
                 self.column_descriptions = {}
                 lines = filter(lambda x: x != '', re.split('\s*\n\s*', value))
                 i = 0
                 for l in lines:
                         description = None
                         try:
                                 ( c, description ) = re.split('\s+', l, 1)
                         except:
                                 c = l
                         try:
                                 ( c, t ) = re.split(':', c, 1)
                         except:
                                 t = 's'
                         self.columns.append(c)
                         self.column_indexes[c] = i
                         self.column_types[c] = t
                         if description != None:
                                 self.column_descriptions[c] = description
                         i = i + 1
         elif tag == 'params':
                 lines = filter(lambda x: x != '', re.split('\s*\n\s*', value))
                 for l in lines:
                         ( p, v ) = re.split('\s+', l, 1)
                         ( component, option ) = re.split('\.', v, 1)
                         cfg = RHNOptions(component)
                         cfg.parse()
                         self.params[p] = str(cfg.get(option))
         elif tag == 'multival_columns':
                 # the multival_columns specifies either
                 # a "stop" column, usually the first one,
                 # or a pair of column names separated by colon,
                 # where the first on is column which should be
                 # joined together and the second one is column
                 # whose value should be used to distinguish if
                 # we still have the same entity or not.
                 for l in filter(lambda x: x != '', re.split('\n', value)):
                         m = re.match('^\s*(\S+?)(\s*:\s*(\S*)\s*)?$', l)
                         if m == None:
                                 continue
                         ( col, id_col ) = ( m.group(1), m.group(3) )
                         if col != None:
                                 self.multival_column_names[col] = id_col
         elif tag == 'sql':
                 self.sql = value
         elif tag == 'synopsis':
                 self.synopsis = re.sub('^(\s*\n)+\s*|(\s*\n)+$', '', value)
         elif tag == 'description':
                 self.description = re.sub('(?m)^\s*', '    ', re.sub('^(\s*\n)+\s*|(\s*\n)+$', '', value))
         else:
                 raise spacewalk_report_unknown_tag_exception(tag)
Пример #3
0
def storeRhnCert(cert, check_generation=0, check_version=0):
    """ Pushes an RHN cert into the database, in rhnSatelliteCert
        "cert" is the raw RHN Certificate as a string.
    """

    label = 'rhn-satellite-cert'
    cert = strip(cert)

    # sanity check
    # satellite_cert.ParseException can be thrown
    sc = satellite_cert.SatelliteCert()
    sc.load(cert)

    # gotta make sure there is a first org_id
    create_first_org(owner=sc.owner)

    # dates: formatted for DB
    expires = strftime(sc.datesFormat_db,
                       strptime(sc.expires, sc.datesFormat_cert))
    issued = strftime(sc.datesFormat_db,
                      strptime(sc.issued, sc.datesFormat_cert))

    version = 0
    certAlreadyUploadedYN = 0

    # First, find out the right next version for this cert
    row = retrieve_db_cert()
    if row:
        db_cert = row['cert']
        db_issued = row['issued']
        db_expires = row['expires']
        version = row['version']
        if db_cert == cert and issued == db_issued and expires == db_expires:
            # cert is already uploaded and the expiration dates match
            certAlreadyUploadedYN = 1
        else:
            # cert is not uploaded *or* the expirations are out of whack
            version = version + 1

            if check_generation or check_version:
                # Load the stored cert
                stored_sc = satellite_cert.SatelliteCert()
                stored_sc.load(db_cert)
                if check_generation and stored_sc.generation != sc.generation:
                    raise CertGenerationMismatchError()

                if check_version:
                    old_version = getattr(stored_sc, 'satellite-version')
                    new_version = getattr(sc, 'satellite-version')
                    if old_version != new_version:
                        raise CertVersionMismatchError(old_version, new_version)

    if not certAlreadyUploadedYN:
        # bug 145491 update the cunstomer's name (should be harmless)
        wc_up = rhnSQL.prepare(_query_update_web_customer)
        wc_up.execute(owner=sc.owner)

        wu_up = rhnSQL.prepare(_query_update_web_user)
        wu_up.execute(owner=sc.owner)

        # XXX bug 145491, there may be further work here for rhnchannelfamily,
        # but only if it actually affects rhn's behaviour (because it's a real
        # bitch to fix because the channel family's name column is *based* on
        # the certificate owner

        h = rhnSQL.prepare(_query_insert_cert)
        h.execute(label=label, version=version, expires=expires, issued=issued)

        # Oracle aparently needs a separate query to update the cert blob:
        h.update_blob("rhnSatelliteCert", "cert",
            "WHERE label = :label AND version = :version", cert, label=label,
            version=version)

    # always reset the slots
    set_slots_from_cert(sc)

    cfg = RHNOptions('web')
    cfg.parse()
    if cfg.get('is_monitoring_backend') == 1:
        org_id = get_org_id()
        push_monitoring_configs(org_id)

    rhnSQL.commit()
Пример #4
0
def storeRhnCert(cert, check_generation=0, check_version=0):
    """ Pushes an RHN cert into the database, in rhnSatelliteCert
        "cert" is the raw RHN Certificate as a string.
    """

    label = 'rhn-satellite-cert'
    cert = cert.strip()

    # sanity check
    # satellite_cert.ParseException can be thrown
    sc = satellite_cert.SatelliteCert()
    sc.load(cert)

    # pylint: disable=E1101
    # gotta make sure there is a first org_id
    create_first_org(owner=sc.owner)

    # dates: formatted for DB
    expires = strftime(sc.datesFormat_db,
                       strptime(sc.expires, sc.datesFormat_cert))
    issued = strftime(sc.datesFormat_db,
                      strptime(sc.issued, sc.datesFormat_cert))

    version = 0
    certAlreadyUploadedYN = 0

    # First, find out the right next version for this cert
    row = retrieve_db_cert()
    if row:
        db_cert = row['cert']
        db_issued = row['issued']
        db_expires = row['expires']
        version = row['version']
        if db_cert == cert and issued == db_issued and expires == db_expires:
            # cert is already uploaded and the expiration dates match
            certAlreadyUploadedYN = 1
        else:
            # cert is not uploaded *or* the expirations are out of whack
            version = version + 1

            if check_generation or check_version:
                # Load the stored cert
                stored_sc = satellite_cert.SatelliteCert()
                stored_sc.load(db_cert)
                if check_generation and stored_sc.generation != sc.generation:
                    raise CertGenerationMismatchError()

                if check_version:
                    old_version = getattr(stored_sc, 'satellite-version')
                    new_version = getattr(sc, 'satellite-version')
                    if old_version != new_version:
                        raise CertVersionMismatchError(old_version,
                                                       new_version)

    if not certAlreadyUploadedYN:
        # bug 145491 update the cunstomer's name (should be harmless)
        wc_up = rhnSQL.prepare(_query_update_web_customer)
        wc_up.execute(owner=sc.owner)

        wu_up = rhnSQL.prepare(_query_update_web_user)
        wu_up.execute(owner=sc.owner)

        # XXX bug 145491, there may be further work here for rhnchannelfamily,
        # but only if it actually affects rhn's behaviour (because it's a real
        # bitch to fix because the channel family's name column is *based* on
        # the certificate owner

        h = rhnSQL.prepare(_query_insert_cert)
        h.execute(label=label, version=version, expires=expires, issued=issued)

        # Oracle aparently needs a separate query to update the cert blob:
        h.update_blob("rhnSatelliteCert",
                      "cert",
                      "WHERE label = :label AND version = :version",
                      cert,
                      label=label,
                      version=version)

    # always reset the slots
    set_slots_from_cert(sc)

    cfg = RHNOptions('web')
    cfg.parse()

    rhnSQL.commit()