コード例 #1
0
def main():
    rhnSQL.initDB()

    blob_values1 = [
        # Regular update
        [1, 1,     'value 11', 'value 12', 1],
        [2, 1,     'value 21', 'value 22', 2],
        # Update with one of the primary keys being None
        [3, None,  'value 31', 'value 32', 3],
        [4, None,  'value 41', 'value 42', 4],
        # Test for writing an empty string into the blob
        [5, 5,     '',         'value 52', 5],
        # Test for writing a shorter string into the blob
        [6, 6,     'value 61', 'value 62', 6],
    ]
    newval1_1 = 'new value 11'
    newval1_2 = 'new value 12'
    newval3_1 = 'new value 31 ' * 1024
    newval3_2 = 'new value 32' * 2048
    newval5_1 = 'new value 51'
    newval5_2 = ''
    newval6_1 = 'v61'
    newval6_2 = 'v61'
    blob_values2 = blob_values1[:]
    for r in [0, 2, 4, 5]:
        # Copy the old values
        blob_values2[r] = blob_values1[r][:]
    blob_values2[0][2:5] = [newval1_1, newval1_2, 11]
    blob_values2[2][2:5] = [newval3_1, newval3_2, 2]
    blob_values2[4][2:5] = [newval5_1, newval5_2, 33]
    blob_values2[5][2:5] = [newval6_1, newval6_2, 4]

    test_blob_update = Table("test_blob_update",
                             fields={
                                 'id1': DBint(),
                                 'id2': DBint(),
                                 'val1': DBblob(),
                                 'val2': DBblob(),
                                 'nval': DBint(),
                             },
                             # Setting the nullable column to be the first one, to force a specific codepath
                             pk=['id2', 'id1'],
                             nullable=['id2'],
                             )

    fields = ['id1', 'id2', 'val1', 'val2', 'nval']
    setup(test_blob_update, blob_values1, fields)
    print("Insert test")
    verify(blob_values1)

    t = TableUpdate(test_blob_update, rhnSQL)

    rows = [0, 2, 4, 5]
    values = _build_update_hash(fields, blob_values2, rows)

    t.query(values)
    rhnSQL.commit()

    print("Updates test")
    verify(blob_values2)
コード例 #2
0
def main():
    global options_table, debug, verbose
    parser = OptionParser(option_list=options_table)

    (options, args) = parser.parse_args()

    if args:
        for arg in args:
            sys.stderr.write("Not a valid option ('%s'), try --help\n" % arg)
        sys.exit(-1)

    if options.verbose:
        verbose = 1

    if options.debug:
        debug = 1

    if not options.db:
        sys.stderr.write("--db not specified\n")
        sys.exit(1)

    print "Connecting to %s" % options.db
    rhnSQL.initDB(options.db)

    if options.update_filer:
        process_package_data()

    if options.update_sha256:
        process_sha256_packages()

    if options.update_kstrees:
        process_kickstart_trees()
コード例 #3
0
ファイル: cdnsync.py プロジェクト: jiridostal/spacewalk
    def __init__(self):
        rhnSQL.initDB()
        initCFG('server.satellite')

        # Channel families mapping to channels
        with open(constants.CHANNEL_FAMILY_MAPPING_PATH, 'r') as f:
            self.families = json.load(f)

        # Channel metadata
        with open(constants.CHANNEL_DEFINITIONS_PATH, 'r') as f:
            self.channel_metadata = json.load(f)

        # Dist/Release channel mapping
        with open(constants.CHANNEL_DIST_MAPPING_PATH, 'r') as f:
            self.channel_dist_mapping = json.load(f)

        # Channel to repositories mapping
        with open(constants.CONTENT_SOURCE_MAPPING_PATH, 'r') as f:
            self.content_source_mapping = json.load(f)

        # Map channels to their channel family
        self.channel_to_family = {}
        for family in self.families:
            for channel in self.families[family]['channels']:
                self.channel_to_family[channel] = family

        # Set already synced channels
        h = rhnSQL.prepare("""
            select label from rhnChannel where org_id is null
        """)
        h.execute()
        channels = h.fetchall_dict() or []
        self.synced_channels = [ch['label'] for ch in channels]
コード例 #4
0
ファイル: activation.py プロジェクト: jdobes/spacewalk
 def deactivate():
     """Function to remove certificates and manifest repositories from DB"""
     rhnSQL.initDB()
     log(0, "Removing certificates...")
     Activation._remove_certificates()
     log(0, "Removing manifest repositories...")
     Activation._remove_repositories()
コード例 #5
0
ファイル: repository.py プロジェクト: phurrelmann/spacewalk
    def __init__(self, local_mount_point=None):
        rhnSQL.initDB()
        self.local_mount_point = local_mount_point
        self.repository_tree = CdnRepositoryTree()
        self._populate_repository_tree()

        f = None
        try:
            try:
                # Channel to repositories mapping
                f = open(constants.CONTENT_SOURCE_MAPPING_PATH, 'r')
                self.content_source_mapping = json.load(f)
                f.close()

                # Channel to kickstart repositories mapping
                f = open(constants.KICKSTART_SOURCE_MAPPING_PATH, 'r')
                self.kickstart_source_mapping = json.load(f)
                f.close()

                # Kickstart metadata
                f = open(constants.KICKSTART_DEFINITIONS_PATH, 'r')
                self.kickstart_metadata = json.load(f)
                f.close()
            except IOError:
                e = sys.exc_info()[1]
                raise CdnMappingsLoadError("Problem with loading file: %s" % e)
        finally:
            if f is not None:
                f.close()
コード例 #6
0
def main():
    global debug, verbose
    parser = OptionParser(option_list=options_table)

    (options, args) = parser.parse_args()

    if args:
        for arg in args:
            sys.stderr.write("Not a valid option ('%s'), try --help\n" % arg)
        sys.exit(-1)

    if options.verbose:
        initLOG("stdout", options.verbose or 0)
        verbose = 1

    if options.debug:
        initLOG(CFG.LOG_FILE, options.debug or 0)
        debug = 1

    rhnSQL.initDB()

    if options.update_filer:
        process_package_data()

    if options.update_sha256:
        process_sha256_packages()

    if options.update_kstrees:
        process_kickstart_trees()

    if options.update_package_files:
        process_package_files()

    if options.update_changelog:
        process_changelog()
コード例 #7
0
def main():
    rhnSQL.initDB()

    channel = {"label": "mibanescu-test2"}

    orgid = 1198839
    package_template = {"name": "useless", "version": "1.0.0", "arch": "noarch", "org_id": orgid}

    batch = []
    p = importLib.IncompletePackage()
    p.populate(package_template)
    p["release"] = "2"
    p["channels"] = [channel]
    batch.append(p)

    p = importLib.IncompletePackage()
    p.populate(package_template)
    p["release"] = "3"
    p["channels"] = [channel]
    batch.append(p)

    backend = backendOracle.OracleBackend()
    cps = packageImport.ChannelPackageSubscription(batch, backend, caller="misa.testing", strict=1)
    cps.run()
    print cps.affected_channel_packages
コード例 #8
0
ファイル: rhn_ssl_dbstore.py プロジェクト: T-D-Oe/spacewalk
def processCommandline():

    options = [
        Option('--ca-cert',      action='store', default=DEFAULT_TRUSTED_CERT, type="string", help='public CA certificate, default is %s' % DEFAULT_TRUSTED_CERT),
        Option('--label',        action='store', default='RHN-ORG-TRUSTED-SSL-CERT', type="string", help='FOR TESTING ONLY - alternative database label for this CA certificate, default is "RHN-ORG-TRUSTED-SSL-CERT"'),
        Option('-v','--verbose', action='count', help='be verbose (accumulable: -vvv means "be *really* verbose").'),
              ]

    values, args = OptionParser(option_list=options).parse_args()

    # we take no extra commandline arguments that are not linked to an option
    if args:
        msg = ("ERROR: these arguments make no sense in this context (try "
               "--help): %s\n" % repr(args))
        raise ValueError(msg)

    if not os.path.exists(values.ca_cert):
        sys.stderr.write("ERROR: can't find CA certificate at this location: "
                         "%s\n" % values.ca_cert)
        sys.exit(10)

    try:
        rhnSQL.initDB()
    except:
        sys.stderr.write("""\
ERROR: there was a problem trying to initialize the database:

%s\n""" % rhnTB.fetchTraceback())
        sys.exit(11)

    if values.verbose:
        print 'Public CA SSL certificate:  %s' % values.ca_cert

    return values
コード例 #9
0
ファイル: repository.py プロジェクト: jdobes/spacewalk
    def __init__(self, local_mount_point=None, client_cert_id=None):
        rhnSQL.initDB()
        self.local_mount_point = local_mount_point
        self.repository_tree = CdnRepositoryTree()
        self._populate_repository_tree(client_cert_id=client_cert_id)

        f = None
        try:
            try:
                # Channel to repositories mapping
                f = open(constants.CONTENT_SOURCE_MAPPING_PATH, 'r')
                self.content_source_mapping = json.load(f)
                f.close()

                # Channel to kickstart repositories mapping
                f = open(constants.KICKSTART_SOURCE_MAPPING_PATH, 'r')
                self.kickstart_source_mapping = json.load(f)
                f.close()

                # Kickstart metadata
                f = open(constants.KICKSTART_DEFINITIONS_PATH, 'r')
                self.kickstart_metadata = json.load(f)
                f.close()
            except IOError:
                e = sys.exc_info()[1]
                log(1, "Ignoring channel mappings: %s" % e)
                self.content_source_mapping = {}
                self.kickstart_source_mapping = {}
                self.kickstart_metadata = {}
        finally:
            if f is not None:
                f.close()

        self.__init_repository_to_channels_mapping()
コード例 #10
0
def main():
    initCFG("server.app")
    rhnSQL.initDB('rhnuser/rhnuser@webdev')

    channel = { 'label' : 'mibanescu-test2' }

    orgid = 1198839
    package_template = {
        'name'      : 'useless',
        'version'   : '1.0.0',
        'arch'      : 'noarch',
        'org_id'    : orgid,
    }
        
    batch = []
    p = importLib.IncompletePackage()
    p.populate(package_template)
    p['release'] = '2'
    p['channels'] = [channel]
    batch.append(p)
    
    p = importLib.IncompletePackage()
    p.populate(package_template)
    p['release'] = '3'
    p['channels'] = [channel]
    batch.append(p)

    backend = backendOracle.OracleBackend()
    cps = packageImport.ChannelPackageSubscription(batch, backend,
        caller="misa.testing", strict=1)
    cps.run()
    print cps.affected_channel_packages
コード例 #11
0
ファイル: suseLib.py プロジェクト: m47ik/uyuni
def getISSCurrentMaster():
    rhnSQL.initDB()
    master = rhnSQL.fetchone_dict(
        "select label from rhnISSMaster where is_current_master = 'Y'")
    if not master:
        return None
    return master['label']
コード例 #12
0
ファイル: suseLib.py プロジェクト: m47ik/uyuni
def isAllowedSlave(hostname):
    rhnSQL.initDB()
    if not rhnSQL.fetchone_dict("select 1 from rhnISSSlave where slave = :hostname and enabled = 'Y'",
                                hostname=idn_puny_to_unicode(hostname)):
        log_error('Server "%s" is not enabled for ISS.' % hostname)
        return False
    return True
コード例 #13
0
ファイル: reposync.py プロジェクト: cliffy94/spacewalk
def getParentsChilds():

    initCFG('server')
    rhnSQL.initDB()

    sql = """
        select c1.label, c2.label parent_channel, c1.id
        from rhnChannel c1 left outer join rhnChannel c2 on c1.parent_channel = c2.id
        order by c2.label desc, c1.label asc
    """
    h = rhnSQL.prepare(sql)
    h.execute()
    d_parents = {}
    while 1:
        row = h.fetchone_dict()
        if not row:
            break
        if rhnChannel.isCustomChannel(row['id']):
            parent_channel = row['parent_channel']
            if not parent_channel:
                d_parents[row['label']] = []
            else:
                d_parents[parent_channel].append(row['label'])

    return d_parents
コード例 #14
0
ファイル: test_exceptions.py プロジェクト: flavio/spacewalk
    def test_failed_connection(self):
        # Connect to localhost and look for db on a totally bogus port, this
        # makes the test faster.
        host = "localhost"
        username = "******"
        password = "******"
        database = "z"
        port = 9000

        self.assertRaises(
            rhnSQL.SQLConnectError,
            rhnSQL.initDB,
            "oracle",
            host,
            port,
            database,
            username,
            password
        )

        try:
            rhnSQL.initDB(
                backend="oracle",
                username=DB_SETTINGS["user"],
                password=DB_SETTINGS["password"],
                database=DB_SETTINGS["database"]
            )
        except:
            self.fail(
                "Exception raised while trying to connect to the db using proper settings. That's not expected to happen.")
コード例 #15
0
ファイル: db-checker.py プロジェクト: jdobes/spacewalk
def main():
    rhnSQL.initDB()

    if not args:
        print("No module specified")
        return 0

    if '.' not in sys.path:
        sys.path.append('.')

    g = globals()

    for module_name in args:
        print("Checking module %s" % module_name)
        pmn = proper_module_name(module_name)
        try:
            m = __import__(pmn)
            g[module_name] = m
        except ImportError:
            e = sys.exc_info()[1]
            print("Unable to import module %s: %s" % (module_name, e))
            continue

        comps = pmn.split('.')
        for c in comps[1:]:
            m = getattr(m, c)

        for mod, name, statement in get_class_instances(m, rhnSQL.Statement):
            try:
                rhnSQL.prepare(statement)
            except rhnSQL.SQLStatementPrepareError:
                e = sys.exc_info()[1]
                print("Error: %s.%s: %s" % (mod.__name__, name, e))
コード例 #16
0
ファイル: satComputePkgHeaders.py プロジェクト: TJM/spacewalk
    def main(self):
        parser = OptionParser(option_list=options_table)

        (self.options, _args) = parser.parse_args()

        rhnSQL.initDB()

        self._channels_hash = self._get_channels()

        package_ids = self._get_packages()
        if package_ids is None:
            return 1

        if self.options.backup_file:
            self._backup_packages(package_ids, self.options.backup_file)

        try:
            self._add_package_header_values(package_ids)
        except:
            rhnSQL.rollback()
            raise

        if self.options.commit:
            print "Commiting work"
            rhnSQL.commit()
        else:
            print "Rolling back"
            rhnSQL.rollback()
コード例 #17
0
ファイル: reposync.py プロジェクト: u-s-p/spacewalk
def getParentsChilds(b_only_custom=False):

    initCFG('server.satellite')
    rhnSQL.initDB()

    sql = """
        select c1.label, c2.label parent_channel, c1.id
        from rhnChannel c1 left outer join rhnChannel c2 on c1.parent_channel = c2.id
        order by c2.label desc, c1.label asc
    """
    h = rhnSQL.prepare(sql)
    h.execute()
    d_parents = {}
    while 1:
        row = h.fetchone_dict()
        if not row:
            break
        if not b_only_custom or rhnChannel.isCustomChannel(row['id']):
            parent_channel = row['parent_channel']
            if not parent_channel:
                d_parents[row['label']] = []
            else:
                # If the parent is not a custom channel treat the child like
                # it's a parent for our purposes
                if parent_channel not in d_parents:
                    d_parents[row['label']] = []
                else:
                    d_parents[parent_channel].append(row['label'])

    return d_parents
コード例 #18
0
ファイル: osa_dispatcher.py プロジェクト: m47ik/uyuni
    def setup_config(self, config, force=0):
        # Figure out the log level
        debug_level = self.options.verbose
        if debug_level is None:
            debug_level = CFG.debug
        self.debug_level = debug_level
        logfile = self.options.logfile
        if logfile is None or logfile == '':
            logfile = CFG.log_file
        initLOG(level=debug_level, log_file=logfile)

        # Get the ssl cert
        ssl_cert = CFG.osa_ssl_cert
        try:
            self.check_cert(ssl_cert)
        except jabber_lib.InvalidCertError:
            e = sys.exc_info()[1]
            log_error("Invalid SSL certificate:", e)
            return 1

        self.ssl_cert = ssl_cert

        rhnSQL.initDB()

        self._username = '******'
        self._password = self.get_dispatcher_password(self._username)
        if not self._password:
            self._password = self.create_dispatcher_password(32)
        self._resource = 'superclient'
        js = config.get('jabber_server')
        self._jabber_servers = [ idn_ascii_to_puny(js) ]
コード例 #19
0
ファイル: test_rhnChannel.py プロジェクト: m47ik/uyuni
 def setUp(self):
     rhnSQL.initDB(
         backend="oracle",
         username=DB_SETTINGS["user"],
         password=DB_SETTINGS["password"],
         database=DB_SETTINGS["database"]
     )
コード例 #20
0
def main():
    if len(sys.argv) == 1:
        server_name = 'xmlrpc.rhn.webdev.redhat.com'
    else:
        server_name = sys.argv[1]

    if len(sys.argv) <= 2:
        db_name = 'rhnuser/rhnuser@webdev'
    else:
        db_name = sys.argv[2]

    rhnSQL.initDB(db_name)

    uri = "http://%s/XMLRPC" % (server_name, )
    s = rpclib.Server(uri)

    username = password = "******" % time.time()
    email = "*****@*****.**" % username

    s.registration.reserve_user(username, password)
    s.registration.new_user(username, password, email)

    data = {
       'os_release'     : '9',
       'architecture'   : 'athlon-redhat-linux',
       'profile_name'   : 'Test profile for %s' % username,
       'username'       : username,
       'password'       : password,
    }
    systemid = s.registration.new_system(data)

    str_caps = [
        'this.is.bogus1(0)=0',
        'this.is.bogus2(1)=1',
        'this.is.bogus3(2)=2',
    ]
    for cap in str_caps:
        s.add_header('X-RHN-Client-Capability', cap)
    
    # Add some packages
    packages = [
        ['a', '1', '1', ''],
        ['b', '2', '2', ''],
        ['c', '3', '3', ''],
    ]
    s.registration.update_packages(systemid, packages)

    sobj = rhnServer.get(systemid)
    server_id = sobj.getid()
    print "Registered server", server_id

    caps = rhnCapability.get_db_client_capabilities(server_id)
    caps_len = len(caps.keys())
    expected_len = len(str_caps)
    if caps_len != expected_len:
        print "FAILED: return %d caps, expected %d" % (caps_len, expected_len)
        return 1
    print "Succeeded", caps
    return 0
コード例 #21
0
ファイル: test_1.py プロジェクト: bjmingyang/spacewalk
    def setUp(self):
        self.table_name = "misatest_%d" % os.getpid()
        rhnSQL.initDB(DB)
        self._cleanup()

        rhnSQL.execute("create table %s (id int, val varchar2(10))" %
            self.table_name)
        rhnSQL.commit()
コード例 #22
0
ファイル: reposync.py プロジェクト: jetsaredim/spacewalk
    def __init__(
        self,
        channel_label,
        repo_type,
        url=None,
        fail=False,
        quiet=False,
        filters=None,
        no_errata=False,
        sync_kickstart=False,
        latest=False,
    ):
        self.regen = False
        self.fail = fail
        self.quiet = quiet
        self.filters = filters or []
        self.no_errata = no_errata
        self.sync_kickstart = sync_kickstart
        self.latest = latest

        initCFG("server")
        rhnSQL.initDB()

        # setup logging
        log_filename = channel_label + ".log"
        rhnLog.initLOG(default_log_location + log_filename)
        # os.fchown isn't in 2.4 :/
        os.system("chgrp apache " + default_log_location + log_filename)

        self.log_msg("\nSync started: %s" % (time.asctime(time.localtime())))
        self.log_msg(str(sys.argv))

        self.channel_label = channel_label
        self.channel = self.load_channel()
        if not self.channel or not rhnChannel.isCustomChannel(self.channel["id"]):
            self.print_msg("Channel does not exist or is not custom.")
            sys.exit(1)

        if not url:
            # TODO:need to look at user security across orgs
            h = rhnSQL.prepare(
                """select s.id, s.source_url, s.label
                                  from rhnContentSource s,
                                       rhnChannelContentSource cs
                                 where s.id = cs.source_id
                                   and cs.channel_id = :channel_id"""
            )
            h.execute(channel_id=int(self.channel["id"]))
            source_data = h.fetchall_dict()
            if source_data:
                self.urls = [(row["id"], row["source_url"], row["label"]) for row in source_data]
            else:
                self.error_msg("Channel has no URL associated")
                sys.exit(1)
        else:
            self.urls = [(None, u, None) for u in url]

        self.repo_plugin = self.load_plugin(repo_type)
コード例 #23
0
ファイル: package_push.py プロジェクト: bjmingyang/spacewalk
    def headerParserHandler(self, req):
        ret = basePackageUpload.BasePackageUpload.headerParserHandler(self, req)
        # Optional headers
        maps = [['Null-Org', 'null_org'], ['Packaging', 'packaging']]
        for hn, sn in maps:
            header_name = "%s-%s" % (self.header_prefix, hn)
            if req.headers_in.has_key(header_name):
                setattr(self, sn, req.headers_in[header_name])

        if ret != apache.OK:
            return ret

        if CFG.SEND_MESSAGE_TO_ALL:
            rhnSQL.closeDB()
            log_debug(1, "send_message_to_all is set")
        
            rhnFlags.set("apache-return-code", apache.HTTP_NOT_FOUND)
            try:
                outage_message = open(CFG.MESSAGE_TO_ALL).read()
            except IOError:
                log_error("Missing outage message file")
                outage_message = "Outage mode"
            raise rhnFault(20001, outage_message, explain=0)

        # Init the database connection
        rhnSQL.initDB()
        use_session = 0
        if self.field_data.has_key('Auth-Session'):
            session_token = self.field_data['Auth-Session']
            use_session = 1
        else:
            encoded_auth_token = self.field_data['Auth']
        
        if not use_session:
            auth_token = self.get_auth_token(encoded_auth_token)

            if len(auth_token) < 2:
                log_debug(3, auth_token)
                raise rhnFault(105, "Unable to autenticate")

            self.username, self.password = auth_token[:2]
        
        force = self.field_data['Force']
        force = int(force)
        log_debug(1, "Username", self.username, "Force", force)
        
        if use_session:
            self.org_id, self.force = rhnPackageUpload.authenticate_session(session_token,
                force=force, null_org=self.null_org)
        else:
            # We don't push to any channels
            self.org_id, self.force = rhnPackageUpload.authenticate(self.username,
                self.password, force=force, null_org=self.null_org)

        nevra = [self.package_name, "", self.package_version, 
            self.package_release, self.package_arch]

        return apache.OK
コード例 #24
0
ファイル: reposync.py プロジェクト: u-s-p/spacewalk
    def __init__(self, channel_label, repo_type, url=None, fail=False,
                 quiet=False, filters=None, no_errata=False, sync_kickstart=False, latest=False,
                 strict=0):
        self.regen = False
        self.fail = fail
        self.quiet = quiet
        self.filters = filters or []
        self.no_errata = no_errata
        self.sync_kickstart = sync_kickstart
        self.latest = latest

        initCFG('server.satellite')
        rhnSQL.initDB()

        # setup logging
        log_filename = channel_label + '.log'
        if CFG.DEBUG is not None:
            log_level = CFG.DEBUG

        rhnLog.initLOG(default_log_location + log_filename, log_level)
        # os.fchown isn't in 2.4 :/
        if isSUSE():
            os.system("chgrp www " + default_log_location + log_filename)
        else:
            os.system("chgrp apache " + default_log_location + log_filename)

        self.log_msg("\nSync started: %s" % (time.asctime(time.localtime())))
        self.log_msg(str(sys.argv))

        self.channel_label = channel_label
        self.channel = self.load_channel()
        if not self.channel:
            self.print_msg("Channel does not exist.")
            sys.exit(1)

        if not url:
            # TODO:need to look at user security across orgs
            h = rhnSQL.prepare("""select s.id, s.source_url, s.label, fm.channel_family_id
                                  from rhnContentSource s,
                                       rhnChannelContentSource cs,
                                       rhnChannelFamilyMembers fm
                                 where s.id = cs.source_id
                                   and cs.channel_id = fm.channel_id
                                   and cs.channel_id = :channel_id""")
            h.execute(channel_id=int(self.channel['id']))
            source_data = h.fetchall_dict()
            if source_data:
                self.urls = [(row['id'], row['source_url'], row['label'],
                              row['channel_family_id']) for row in source_data]
            else:
                self.error_msg("Channel has no URL associated")
                sys.exit(1)
        else:
            self.urls = [(None, u, None, None) for u in url]

        self.repo_plugin = self.load_plugin(repo_type)
        self.strict = strict
コード例 #25
0
def main():
    if len(sys.argv) != 2:
        print "Usage: %s <cert>" % sys.argv[0]
        return 1
    cert = sys.argv[1]

    rhnSQL.initDB()

    satCerts.storeRhnCert(open(cert).read())
コード例 #26
0
def package_details(packageid):
    """displays the details for that package id"""
    #db access
    import sys
    sys.path.append("/usr/share/rhn")
    try:
        import spacewalk.common.rhnConfig as rhnConfig
        import spacewalk.server.rhnSQL as rhnSQL
    except ImportError:
        try:
            import common.rhnConfig as rhnConfig
            import server.rhnSQL as rhnSQL
        except ImportError:
            print "Couldn't load the modules required to connect to the db"
        sys.exit(1)
    rhnConfig.initCFG()
    rhnSQL.initDB()

    query="""
    select
      rp.id as "package_id",
      rpn.name||'-'||rpe.version||'-'||rpe.release||'.'||rpa.label as "package",
      rc.label as "channel_label",
      rc.id as "channel_id",
      coalesce((select name from rhnpackageprovider rpp where rpp.id = rpk.provider_id),'Unknown') as "provider"  
    from rhnpackage rp
      inner join rhnpackagename rpn on rpn.id = rp.name_id
      inner join rhnpackageevr rpe on rpe.id = rp.evr_id
      inner join rhnpackagearch rpa on rpa.id = rp.package_arch_id
      left outer join rhnchannelpackage rcp on rcp.package_id = rp.id
      left outer join rhnchannel rc on rc.id = rcp.channel_id
      left outer join rhnpackagekeyassociation rpka on rpka.package_id = rp.id
      left outer join rhnpackagekey rpk on rpk.id = rpka.key_id
    where rp.id = :packageid
    order by 2, 3
    """
    cursor = rhnSQL.prepare(query)
    cursor.execute(packageid=packageid)
    rows = cursor.fetchall_dict()
    if not rows is None:
        c = 0
        print "Package %d : %s" % (rows[0]['package_id'], rows[0]['package'])
        pkg_channels = []
        pkg_provider = []
        for row in rows:
            c += 1
            if row.channel_id != None:
                pkg_channels[row['channel_id']] = row['channel_label']
                pkg_provider[row['channel_id']] = row['provider']
            else:
                pkg_channels[0] = "Not in a channel"
                pkg_provider[0] = row['provider']
            print "\r%s of %s" % (str(c), str(len(rows))),
        print "Provided by channels : %s" % (', '.join(pkg_channels))
        print "With providers (same order): %s" % (', '.join(pkg_provider))
    else:
        print "no package found for the id %d" % (packageid)
コード例 #27
0
 def setUp(self):
     initCFG("server")
     rhnSQL.initDB(
         backend="oracle",
         username=DB_SETTINGS["user"],
         password=DB_SETTINGS["password"],
         database=DB_SETTINGS["database"]
     )
     rhnSQL.clear_log_id()
コード例 #28
0
def main():
    if len(sys.argv) == 1:
        server_name = 'xmlrpc.rhn.webdev.redhat.com'
    else:
        server_name = sys.argv[1]

    if len(sys.argv) <= 2:
        db_name = 'rhnuser/rhnuser@webdev'
    else:
        db_name = sys.argv[2]

    try:
        rhnSQL.initDB(db_name)
    except ConfigParserError:
        # database is not available when running in rpmbuild time
        print "Test skipped"
        return 0

    uri = "http://%s/XMLRPC" % (server_name, )
    s = rpclib.Server(uri)

    username = password = "******" % time.time()
    email = "*****@*****.**" % username

    s.registration.reserve_user(username, password)
    s.registration.new_user(username, password, email)

    data = {
       'os_release'     : '9',
       'architecture'   : 'athlon-redhat-linux',
       'profile_name'   : 'Test profile for %s' % username,
       'username'       : username,
       'password'       : password,
    }
    systemid = s.registration.new_system(data)

    str_caps = [
        'this.is.bogus1(0)=0',
        'this.is.bogus2(1)=1',
        'this.is.bogus3(2)=2',
    ]
    for cap in str_caps:
        s.add_header('X-RHN-Client-Capability', cap)

    # Add some packages
    packages = [
        ['a', '1', '1', ''],
        ['b', '2', '2', ''],
        ['c', '3', '3', ''],
    ]
    s.registration.update_packages(systemid, packages)

    sobj = rhnServer.get(systemid)
    server_id = sobj.getid()
    print "Registered server", server_id

    return 0
コード例 #29
0
def main():
    if len(sys.argv) != 3:
        print "Usage: %s <db-string> <cert>" % sys.argv[0]
        return 1
    db_string = sys.argv[1]
    cert = sys.argv[2]

    rhnSQL.initDB(db_string)

    satCerts.storeRhnCert(open(cert).read())
コード例 #30
0
ファイル: test_lob.py プロジェクト: TJM/spacewalk
    def setUp(self):
        rhnSQL.initDB(
            backend="oracle",
            username=DB_SETTINGS["user"],
            password=DB_SETTINGS["password"],
            database=DB_SETTINGS["database"]
        )
        self._cleanup()

        rhnSQL.execute("create table misatestlob (id int, val blob)")
        rhnSQL.execute("create sequence misatestlob_id_seq")
コード例 #31
0
def getChannelRepo():

    initCFG('server')
    rhnSQL.initDB()
    items = {}
    sql = """
           select s.source_url, c.label
                       from rhnContentSource s,
                       rhnChannelContentSource cs,
                       rhnChannel c
                       where s.id = cs.source_id and cs.channel_id=c.id
           """
    h = rhnSQL.prepare(sql)
    h.execute()
    while 1:
        row = h.fetchone_dict()
        if not row:
            break
        if not row['label'] in items:
            items[row['label']] = []
        items[row['label']] += [row['source_url']]

    return items
コード例 #32
0
    def __init__(self, manifest_path):
        rhnSQL.initDB()
        self.manifest = Manifest(manifest_path)
        self.sat5_cert = SatelliteCert()
        self.sat5_cert.load(self.manifest.get_satellite_certificate())

        verify_mappings()

        f = None
        # Channel families metadata
        try:
            try:
                f = open(constants.CHANNEL_FAMILY_MAPPING_PATH, 'r')
                self.families = json.load(f)
                f.close()
            except IOError:
                e = sys.exc_info()[1]
                log(1, "Ignoring channel mappings: %s" % e)
                self.families = {}
        finally:
            if f is not None:
                f.close()

        self.families_to_import = []
コード例 #33
0
 def setUp(self):
     rhnSQL.initDB(backend="oracle",
                   username=DB_SETTINGS["user"],
                   password=DB_SETTINGS["password"],
                   database=DB_SETTINGS["database"])
     rhnSQL.clear_log_id()
コード例 #34
0
 def setUp(self):
     rhnSQL.initDB(backend="postgresql",
                   username=DB_SETTINGS["user"],
                   password=DB_SETTINGS["password"],
                   database=DB_SETTINGS["database"],
                   host=DB_SETTINGS["host"])
コード例 #35
0
 def _init_db(self):
     rhnSQL.initDB()
コード例 #36
0
#!/usr/bin/python
import os
import sys

sys.path.append('/usr/share/rhn')
try:
   from spacewalk.server import rhnSQL
   from spacewalk.common.rhnConfig import initCFG, CFG
except:
   print "Couldn't load needed libs, Are you sure you are running this on a satellite?"
   sys.exit(1)

initCFG()

db_string = CFG.DEFAULT_DB 
rhnSQL.initDB(db_string)

query = """ select C.id, C.name, C.label, CS.source_url
               from rhnChannel C inner join 
                    rhnChannelContentSource CCS on CCS.channel_id = C.id inner join
                    rhnContentSource CS on CS.id = CCS.source_id"""

h = rhnSQL.prepare(query)
h.execute()
list = h.fetchall_dict()

for row in list:
    sync_command="spacewalk-repo-sync --type=yum  --url='%s' --channel='%s'" % (row['source_url'], row['label'] )
    print sync_command
    os.system(sync_command)
コード例 #37
0
def db_backup(bkp, pid):
    """captures the data from the db and stores it in the backup"""
    rhnSQL.initDB()
    if isinstance(pid, list):
        query = """
        select  
            rp.id as "package_id", 
            rpn.name as "package_name",
            rpe.version as "package_version",
            rpe.release as "package_release",
            rpe.epoch as "package_epoch",
            rpa.label as "package_arch",
            rc.label as "channel_label",
            rc.id as "channel_id",
            coalesce((select name from rhnpackageprovider rpp where rpp.id = rpk.provider_id),'Unknown') as "provider"
        from rhnpackage rp
            inner join rhnpackagename rpn on rpn.id = rp.name_id
            inner join rhnpackageevr rpe on rpe.id = rp.evr_id
            inner join rhnpackagearch rpa on rpa.id = rp.package_arch_id
            left outer join rhnchannelpackage rcp on rcp.package_id = rp.id
            left outer join rhnchannel rc on rc.id = rcp.channel_id
            left outer join rhnpackagekeyassociation rpka on rpka.package_id = rp.id
            left outer join rhnpackagekey rpk on rpk.id = rpka.key_id
        where rp.id in (:pid)
        order by 2, 3
        """
        cursor = rhnSQL.prepare(query)
        cursor.execute(pid=','.join(pid))
    else:
        query = """
        select  
            rp.id as "package_id", 
            rpn.name as "package_name",
            rpe.version as "package_version",
            rpe.release as "package_release",
            rpe.epoch as "package_epoch",
            rpa.label as "package_arch",
            rc.label as "channel_label",
            rc.id as "channel_id",
            coalesce((select name from rhnpackageprovider rpp where rpp.id = rpk.provider_id),'Unknown') as "provider"
        from rhnpackage rp
            inner join rhnpackagename rpn on rpn.id = rp.name_id
            inner join rhnpackageevr rpe on rpe.id = rp.evr_id
            inner join rhnpackagearch rpa on rpa.id = rp.package_arch_id
            left outer join rhnchannelpackage rcp on rcp.package_id = rp.id
            left outer join rhnchannel rc on rc.id = rcp.channel_id
            left outer join rhnpackagekeyassociation rpka on rpka.package_id = rp.id
            left outer join rhnpackagekey rpk on rpk.id = rpka.key_id
        where rp.id = :pid
        order by 2, 3
        """
        cursor = rhnSQL.prepare(query)
        cursor.execute(pid=pid)
    rows = cursor.fetchall_dict()
    print "backing up the list of packages"
    if not rows is None:
        c = 0
        for row in rows:
            c += 1
            bkp.add(
                row['package_id'], row['channel_label'], {
                    'name': row['package_name'],
                    'version': row['package_version'],
                    'release': row['package_release'],
                    'epoch': row['package_epoch'],
                    'arch': row['package_arch']
                })
            if not verbose:
                print "\r%s of %s" % (str(c), str(len(rows))),
        if not verbose:
            print ""
        else:
            print "%s entries treated" % (str(len(rows)))
    else:
        print "no entries to backup"
    rhnSQL.closeDB()
コード例 #38
0
    def __init__(self, no_packages=False, no_errata=False, no_rpms=False, no_kickstarts=False,
                 log_level=None, mount_point=None, consider_full=False):

        self.cdn_repository_manager = CdnRepositoryManager(mount_point)
        self.no_packages = no_packages
        self.no_errata = no_errata
        self.no_rpms = no_rpms
        self.no_kickstarts = no_kickstarts
        if log_level is None:
            log_level = 0
        self.log_level = log_level

        if mount_point:
            self.mount_point = "file://" + mount_point
            self.consider_full = consider_full
        else:
            self.mount_point = CFG.CDN_ROOT
            self.consider_full = True

        CFG.set('DEBUG', log_level)
        rhnLog.initLOG(self.log_path, self.log_level)
        log2disk(0, "Command: %s" % str(sys.argv))

        rhnSQL.initDB()
        initCFG('server.satellite')

        verify_mappings()

        f = None
        # try block in try block - this is hack for python 2.4 compatibility
        # to support finally
        try:
            try:
                # Channel families mapping to channels
                f = open(constants.CHANNEL_FAMILY_MAPPING_PATH, 'r')
                self.families = json.load(f)
                f.close()

                # Channel metadata
                f = open(constants.CHANNEL_DEFINITIONS_PATH, 'r')
                self.channel_metadata = json.load(f)
                f.close()

                # Dist/Release channel mapping
                f = open(constants.CHANNEL_DIST_MAPPING_PATH, 'r')
                self.channel_dist_mapping = json.load(f)
                f.close()

                # Kickstart metadata
                f = open(constants.KICKSTART_DEFINITIONS_PATH, 'r')
                self.kickstart_metadata = json.load(f)
                f.close()
            except IOError:
                e = sys.exc_info()[1]
                raise CdnMappingsLoadError("Problem with loading file: %s" % e)
        finally:
            if f is not None:
                f.close()

        # Map channels to their channel family
        self.channel_to_family = {}
        for family in self.families:
            for channel in self.families[family]['channels']:
                self.channel_to_family[channel] = family

        # Set already synced channels
        h = rhnSQL.prepare("""
            select label from rhnChannel where org_id is null
        """)
        h.execute()
        channels = h.fetchall_dict() or []
        self.synced_channels = [ch['label'] for ch in channels]
コード例 #39
0
    def __init__(self,
                 no_packages=False,
                 no_errata=False,
                 no_rpms=False,
                 no_kickstarts=False,
                 log_level=None,
                 mount_point=None,
                 consider_full=False,
                 force_kickstarts=False,
                 force_all_errata=False,
                 email=False,
                 import_batch_size=None):

        if log_level is None:
            log_level = 0
        self.log_level = log_level
        CFG.set('DEBUG', log_level)
        self.email = email
        if self.email:
            initEMAIL_LOG()
        rhnLog.initLOG(self.log_path, self.log_level)
        log2disk(0, "Command: %s" % str(sys.argv))

        rhnSQL.initDB()
        initCFG('server.satellite')

        self.cdn_repository_manager = CdnRepositoryManager(mount_point)
        self.no_packages = no_packages
        self.no_errata = no_errata
        self.no_rpms = no_rpms
        if self.no_packages and self.no_rpms:
            log(0, "Parameter --no-rpms has no effect.")
        self.no_kickstarts = no_kickstarts
        self.force_all_errata = force_all_errata
        self.force_kickstarts = force_kickstarts
        if self.no_kickstarts and self.force_kickstarts:
            log(0, "Parameter --force-kickstarts has no effect.")

        if mount_point:
            self.mount_point = "file://" + mount_point
            self.consider_full = consider_full
        else:
            self.mount_point = CFG.CDN_ROOT
            self.consider_full = True

        verify_mappings()

        f = None
        # try block in try block - this is hack for python 2.4 compatibility
        # to support finally
        try:
            try:
                # Channel families mapping to channels
                f = open(constants.CHANNEL_FAMILY_MAPPING_PATH, 'r')
                self.families = json.load(f)
                f.close()

                # Channel metadata
                f = open(constants.CHANNEL_DEFINITIONS_PATH, 'r')
                self.channel_metadata = json.load(f)
                f.close()

                # Dist/Release channel mapping
                f = open(constants.CHANNEL_DIST_MAPPING_PATH, 'r')
                self.channel_dist_mapping = json.load(f)
                f.close()

                # Kickstart metadata
                f = open(constants.KICKSTART_DEFINITIONS_PATH, 'r')
                self.kickstart_metadata = json.load(f)
                f.close()
            except IOError:
                e = sys.exc_info()[1]
                log(1, "Ignoring channel mappings: %s" % e)
                self.families = {}
                self.channel_metadata = {}
                self.channel_dist_mapping = {}
                self.kickstart_metadata = {}
        finally:
            if f is not None:
                f.close()

        # Map channels to their channel family
        self.channel_to_family = {}
        for family in self.families:
            for channel in self.families[family]['channels']:
                self.channel_to_family[channel] = family

        # Set already synced channels, entitled null-org channels and custom channels with associated
        # CDN repositories
        h = rhnSQL.prepare("""
            select distinct c.label, c.org_id
            from rhnChannelFamilyPermissions cfp inner join
                 rhnChannelFamily cf on cfp.channel_family_id = cf.id inner join
                 rhnChannelFamilyMembers cfm on cf.id = cfm.channel_family_id inner join
                 rhnChannel c on cfm.channel_id = c.id
            where c.org_id is null
              or (c.org_id is not null and 
                  exists (
                          select cs.id
                          from rhnContentSource cs inner join
                               rhnChannelContentSource ccs on ccs.source_id = cs.id
                          where ccs.channel_id = c.id
                            and cs.org_id is null
                         )
                 )
            order by c.org_id nulls first, label
        """)
        h.execute()
        channels = h.fetchall_dict() or []
        self.synced_channels = {}
        for channel in channels:
            # Custom channel repositories not available, don't mark as synced
            if channel['org_id']:
                repos = self.cdn_repository_manager.list_associated_repos(
                    channel['label'])
                if not all([
                        self.cdn_repository_manager.
                        check_repository_availability(r) for r in repos
                ]):
                    continue
            self.synced_channels[channel['label']] = channel['org_id']

        # Select available channel families from DB
        h = rhnSQL.prepare("""
            select distinct label
            from rhnChannelFamilyPermissions cfp inner join
                 rhnChannelFamily cf on cfp.channel_family_id = cf.id
            where cf.org_id is null
        """)
        h.execute()
        families = h.fetchall_dict() or []
        self.entitled_families = [f['label'] for f in families]
        self.import_batch_size = import_batch_size
コード例 #40
0
ファイル: suseLib.py プロジェクト: ncounter/uyuni
def hasISSSlaves():
    rhnSQL.initDB()
    if rhnSQL.fetchone_dict("select 1 from rhnISSSlave where enabled = 'Y'"):
        return True
    return False
コード例 #41
0
ファイル: suseLib.py プロジェクト: ncounter/uyuni
def hasISSMaster():
    rhnSQL.initDB()
    if rhnSQL.fetchone_dict(
            "select 1 from rhnISSMaster where is_current_master = 'Y'"):
        return True
    return False
コード例 #42
0
def main():
    rhnSQL.initDB()

    blob_values1 = [
        # Regular update
        [1, 1, 'value 11', 'value 12', 1],
        [2, 1, 'value 21', 'value 22', 2],
        # Update with one of the primary keys being None
        [3, None, 'value 31', 'value 32', 3],
        [4, None, 'value 41', 'value 42', 4],
        # Test for writing an empty string into the blob
        [5, 5, '', 'value 52', 5],
        # Test for writing a shorter string into the blob
        [6, 6, 'value 61', 'value 62', 6],
    ]
    newval1_1 = 'new value 11'
    newval1_2 = 'new value 12'
    newval3_1 = 'new value 31 ' * 1024
    newval3_2 = 'new value 32' * 2048
    newval5_1 = 'new value 51'
    newval5_2 = ''
    newval6_1 = 'v61'
    newval6_2 = 'v61'
    blob_values2 = blob_values1[:]
    for r in [0, 2, 4, 5]:
        # Copy the old values
        blob_values2[r] = blob_values1[r][:]
    blob_values2[0][2:5] = [newval1_1, newval1_2, 11]
    blob_values2[2][2:5] = [newval3_1, newval3_2, 2]
    blob_values2[4][2:5] = [newval5_1, newval5_2, 33]
    blob_values2[5][2:5] = [newval6_1, newval6_2, 4]

    test_blob_update = Table(
        "test_blob_update",
        fields={
            'id1': DBint(),
            'id2': DBint(),
            'val1': DBblob(),
            'val2': DBblob(),
            'nval': DBint(),
        },
        # Setting the nullable column to be the first one, to force a specific codepath
        pk=['id2', 'id1'],
        nullable=['id2'],
    )

    fields = ['id1', 'id2', 'val1', 'val2', 'nval']
    setup(test_blob_update, blob_values1, fields)
    print("Insert test")
    verify(blob_values1)

    t = TableUpdate(test_blob_update, rhnSQL)

    rows = [0, 2, 4, 5]
    values = _build_update_hash(fields, blob_values2, rows)

    t.query(values)
    rhnSQL.commit()

    print("Updates test")
    verify(blob_values2)
コード例 #43
0
ファイル: runtests-oracle.py プロジェクト: lpramuk/spacewalk
sys.path.insert(
    0,
    os.path.abspath(
        os.path.dirname(
            os.path.abspath(__file__) + "/../non-unit/server/rhnSQL/")))
import dbtests

config = ConfigParser()
config.read(os.path.dirname(os.path.abspath(__file__)) + "/db_settings.ini")

USER = config.get('oracle', 'user')
PASSWORD = config.get('oracle', 'password')
DATABASE = config.get('oracle', 'database')

rhnSQL.initDB(backend="oracle",
              username=USER,
              password=PASSWORD,
              database=DATABASE)

# Re-initialize to test re-use of connections:
rhnSQL.initDB(backend="oracle",
              username=USER,
              password=PASSWORD,
              database=DATABASE)


class OracleDatabaseTests(dbtests.RhnSQLDatabaseTests):
    QUERY_CREATE_TABLE = """
        CREATE TABLE %s(id NUMBER, name VARCHAR2(256), num NUMBER(5,2))
    """

    SIMPLE_PROCEDURE = """
コード例 #44
0
 def setUp(self):
     initCFG("server.xmlrpc")
     rhnSQL.initDB(backend="oracle",
                   username=DB_SETTINGS["user"],
                   password=DB_SETTINGS["password"],
                   database=DB_SETTINGS["database"])
コード例 #45
0
    os.path.abspath(
        os.path.dirname(
            os.path.abspath(__file__) + "/../non-unit/server/rhnSQL/")))
import dbtests

config = ConfigParser()
config.read(os.path.dirname(os.path.abspath(__file__)) + "/db_settings.ini")

PG_HOST = config.get('postgresql', 'host')
PG_USER = config.get('postgresql', 'user')
PG_PASSWORD = config.get('postgresql', 'password')
PG_DATABASE = config.get('postgresql', 'database')

rhnSQL.initDB(backend="postgresql",
              host=PG_HOST,
              username=PG_USER,
              password=PG_PASSWORD,
              database=PG_DATABASE)

# Re-initialize to test re-use of connections:
rhnSQL.initDB(backend="postgresql",
              host=PG_HOST,
              username=PG_USER,
              password=PG_PASSWORD,
              database=PG_DATABASE)


class PostgreSQLDatabaseTests(dbtests.RhnSQLDatabaseTests):
    QUERY_CREATE_TABLE = """
        CREATE TABLE %s(id INT, name TEXT, num NUMERIC(5,2))
    """
コード例 #46
0
 def __init__(self):
     rhnSQL.initDB()
コード例 #47
0
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
#
from spacewalk.server import rhnSQL
from spacewalk.common import rhnLog
from spacewalk.server.action_extra_data import solarispkgs

if __name__ == '__main__':
    rhnSQL.initDB('satdev/satdev@citisat')
    rhnLog.initLOG(log_file="stderr", level=5)

    solarispkgs.install(1000010033, 69, {
        'name'      : 'XXX',
        'version'   : 0,
        'status'    : [
            [['SMCsudo', '1.6.7p5', '0', 'sparc-solaris',],
                [1, "", ""]],
            [['SFWungif', '4.1.0', '2001.05.21.04.41', 'sparc-solaris',],
                [1, "out1", "error1"]],
            [['SMCtracer', '1.4a12', '0', 'sparc-solaris',],
                [1, "out1", "error1"]],
            [['SMCrcs', '5.7', '0', 'sparc-solaris',],
                [2, "out2", "error2"]],
            [['SMCngrep', '1.40.1', '0', 'sparc-solaris',],
コード例 #48
0
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
#

from spacewalk.common.rhnConfig import initCFG
from spacewalk.server.rhnSQL import initDB
from spacewalk.server.xmlrpc import registration

initCFG("server.xmlrpc")
initDB('rhnuser/rhnuser@webdev')

r = registration.Registration()

data = {
    'os_release': '8.0',
    'profile_name': 'test local',
    'architecture': 'i686',
    'token': '382c712e94b2505f6070f011e8ec1a7e',
}

open("/tmp/rereg-systemid", "w+").write(r.new_system(data))
コード例 #49
0
#
# Copyright (c) 2008--2016 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
#

from spacewalk.server import rhnSQL

rhnSQL.initDB('rhnuser/rhnuser@phx')

counter = 0
while 1:
    #p = rhnSQL.Procedure('rhn_entitlements.get_server_entitlement')
    p = rhnSQL.Procedure('rhn_entitlements.upgrade_server')
    ret = p(1000102174)
    print((counter, ret))
    counter = counter + 1
    # if counter > 700:
    #    time.sleep(.5)
コード例 #50
0
ファイル: reposync.py プロジェクト: DeadRabb1t/spacewalk
    def __init__(self,
                 channel_label,
                 repo_type,
                 url=None,
                 fail=False,
                 filters=None,
                 no_errata=False,
                 sync_kickstart=False,
                 latest=False,
                 metadata_only=False,
                 strict=0,
                 excluded_urls=None,
                 no_packages=False,
                 log_dir="reposync",
                 log_level=None,
                 force_kickstart=False,
                 force_all_errata=False,
                 check_ssl_dates=False,
                 force_null_org_content=False):
        self.regen = False
        self.fail = fail
        self.filters = filters or []
        self.no_packages = no_packages
        self.no_errata = no_errata
        self.sync_kickstart = sync_kickstart
        self.force_all_errata = force_all_errata
        self.force_kickstart = force_kickstart
        self.latest = latest
        self.metadata_only = metadata_only
        self.ks_tree_type = 'externally-managed'
        self.ks_install_type = None

        initCFG('server.satellite')
        rhnSQL.initDB()

        # setup logging
        log_filename = channel_label + '.log'
        log_path = default_log_location + log_dir + '/' + log_filename
        if log_level is None:
            log_level = 0
        CFG.set('DEBUG', log_level)
        rhnLog.initLOG(log_path, log_level)
        # os.fchown isn't in 2.4 :/
        if isSUSE():
            os.system("chgrp www " + log_path)
        else:
            os.system("chgrp apache " + log_path)

        log2disk(0, "Command: %s" % str(sys.argv))
        log2disk(0, "Sync of channel started.")

        self.channel_label = channel_label
        self.channel = self.load_channel()
        if not self.channel:
            log(0, "Channel %s does not exist." % channel_label)

        if not self.channel['org_id'] or force_null_org_content:
            self.org_id = None
        else:
            self.org_id = int(self.channel['org_id'])

        if not url:
            # TODO:need to look at user security across orgs
            h = rhnSQL.prepare("""select s.id, s.source_url, s.label
                                  from rhnContentSource s,
                                       rhnChannelContentSource cs
                                 where s.id = cs.source_id
                                   and cs.channel_id = :channel_id""")
            h.execute(channel_id=int(self.channel['id']))
            source_data = h.fetchall_dict()
            self.urls = []
            if excluded_urls is None:
                excluded_urls = []
            if source_data:
                for row in source_data:
                    if row['source_url'] not in excluded_urls:
                        self.urls.append(
                            (row['id'], row['source_url'], row['label']))
        else:
            self.urls = [(None, u, None) for u in url]

        if not self.urls:
            log2(0,
                 0,
                 "Channel %s has no URL associated" % channel_label,
                 stream=sys.stderr)

        self.repo_plugin = self.load_plugin(repo_type)
        self.strict = strict
        self.all_packages = []
        self.check_ssl_dates = check_ssl_dates
        # Init cache for computed checksums to not compute it on each reposync run again
        self.checksum_cache = rhnCache.get(checksum_cache_filename)
        if self.checksum_cache is None:
            self.checksum_cache = {}
コード例 #51
0
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
#

import os
import sys
import time
from spacewalk.server import rhnSQL

print os.getpid()
rhnSQL.initDB('rhnuser/rhnuser@webdev')

h = rhnSQL.prepare("select 1 from dual")

start = time.time()
write = sys.stderr.write
i = 0
while i < 10000:
    h.execute()
    if i % 100 == 0:
        f = open("/proc/self/status")
        l = f.readlines()
        vmsize = l[10][10:-1]
        vmrss = l[12][10:-1]
        f.close()
        write("%d %.3f vsz: %s rss: %s \n" %
コード例 #52
0
ファイル: deb_src.py プロジェクト: srbarrios/uyuni
    def __init__(
        self,
        url,
        cache_dir,
        pkg_dir,
        proxy_addr="",
        proxy_user="",
        proxy_pass="",
        gpg_verify=True,
        channel_label=None,
    ):
        self.url = url
        parts = url.rsplit('/dists/', 1)
        self.base_url = [parts[0]]

        parsed_url = urlparse.urlparse(url)
        query = urlparse.parse_qsl(parsed_url.query)
        new_query = []
        suite = None
        component = None
        arch = None
        for qi in query:
            if qi[0] == "uyuni_suite":
                suite = qi[1]
            elif qi[0] == "uyuni_component":
                component = qi[1]
            elif qi[0] == "uyuni_arch":
                arch = qi[1]
            else:
                new_query.append(qi)
        if suite:
            parsed_url = parsed_url._replace(
                query=urlparse.urlencode(new_query))
            base_url = urlparse.urlunparse(parsed_url)
            path_list = parsed_url.path.split("/")
            log2(0, 0, "Base URL: {}".format(base_url))
            log2(0, 0, "Suite: {}".format(suite))
            log2(0, 0, "Component: {}".format(component))
            if "/" not in suite:
                path_list.append("dists")
            path_list.extend(suite.split("/"))
            if component:
                path_list.extend(component.split("/"))
            if "/" not in suite:
                if arch is None:
                    rhnSQL.initDB()
                    h = rhnSQL.prepare("""
                                       SELECT ca.label AS arch_label
                                       FROM rhnChannel AS c
                                       LEFT JOIN rhnChannelArch AS ca
                                           ON c.channel_arch_id = ca.id
                                       WHERE c.label = :channel_label
                                       """)
                    h.execute(channel_label=channel_label)
                    row = h.fetchone_dict()
                    if row and "arch_label" in row:
                        aspl = row["arch_label"].split("-")
                        if len(aspl) == 3 and aspl[0] == "channel" and aspl[
                                2] == "deb":
                            arch_trans = {
                                "ia32": "i386",
                                "arm": "armhf",
                            }
                            if aspl[1] in arch_trans:
                                arch = arch_trans[aspl[1]]
                            else:
                                arch = aspl[1]
                if arch:
                    log2(0, 0, "Channel architecture: {}".format(arch))
                    path_list.append("binary-{}".format(arch))
            while "" in path_list:
                path_list.remove("")
            parsed_url = parsed_url._replace(path="/".join(path_list))
            self.url = url = urlparse.urlunparse(parsed_url)
            self.base_url = [base_url]

        # Make sure baseurl ends with / and urljoin will work correctly
        if self.base_url[0][-1] != '/':
            self.base_url[0] += '/'
        self.urls = self.base_url
        self.sslclientcert = self.sslclientkey = self.sslcacert = None
        self.proxy = proxy_addr
        self.proxy_username = proxy_user
        self.proxy_password = proxy_pass
        self.gpg_verify = gpg_verify

        self.basecachedir = cache_dir
        if not os.path.isdir(self.basecachedir):
            fileutils.makedirs(self.basecachedir, user='******', group='www')
        self.includepkgs = []
        self.exclude = []
        self.pkgdir = pkg_dir
        self.http_headers = {}
コード例 #53
0
ファイル: cdnsync.py プロジェクト: borland667/spacewalk
    def __init__(self,
                 no_packages=False,
                 no_errata=False,
                 no_rpms=False,
                 no_kickstarts=False,
                 log_level=None):

        self.no_packages = no_packages
        self.no_errata = no_errata
        self.no_rpms = no_rpms
        self.no_kickstarts = no_kickstarts
        if log_level is None:
            log_level = 0
        self.log_level = log_level

        CFG.set('DEBUG', log_level)
        rhnLog.initLOG(self.log_path, self.log_level)
        log2disk(0, "Command: %s" % str(sys.argv))

        rhnSQL.initDB()
        initCFG('server.satellite')

        f = None
        # try block in try block - this is hack for python 2.4 compatibility
        # to support finally
        try:
            try:
                # Channel families mapping to channels
                f = open(constants.CHANNEL_FAMILY_MAPPING_PATH, 'r')
                self.families = json.load(f)
                f.close()

                # Channel metadata
                f = open(constants.CHANNEL_DEFINITIONS_PATH, 'r')
                self.channel_metadata = json.load(f)
                f.close()

                # Dist/Release channel mapping
                f = open(constants.CHANNEL_DIST_MAPPING_PATH, 'r')
                self.channel_dist_mapping = json.load(f)
                f.close()

                # Channel to repositories mapping
                f = open(constants.CONTENT_SOURCE_MAPPING_PATH, 'r')
                self.content_source_mapping = json.load(f)
                f.close()

                # Kickstart metadata
                f = open(constants.KICKSTART_DEFINITIONS_PATH, 'r')
                self.kickstart_metadata = json.load(f)
                f.close()

                # Channel to kickstart repositories mapping
                f = open(constants.KICKSTART_SOURCE_MAPPING_PATH, 'r')
                self.kickstart_source_mapping = json.load(f)
                f.close()
            except IOError:
                e = sys.exc_info()[1]
                log2stderr(0, "ERROR: Problem with loading file: %s" % e)
                raise CdnMappingsLoadError()
        finally:
            if f is not None:
                f.close()

        # Map channels to their channel family
        self.channel_to_family = {}
        for family in self.families:
            for channel in self.families[family]['channels']:
                self.channel_to_family[channel] = family

        # Set already synced channels
        h = rhnSQL.prepare("""
            select label from rhnChannel where org_id is null
        """)
        h.execute()
        channels = h.fetchall_dict() or []
        self.synced_channels = [ch['label'] for ch in channels]

        # Set SSL-keys for channel family
        self.family_keys = {}
コード例 #54
0
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
#
import sys
from spacewalk.server import rhnSQL

if len(sys.argv) != 2:
    print("Error: no connection string")
    sys.exit(1)

rhnSQL.initDB(sys.argv[1])

ids = [1, 2, 3]
values = [11, 22, 33]
foo = ['', '', '']

h = rhnSQL.prepare("insert into misatest (id, val) values (:id, :val)")
try:
    h.executemany(id=ids, val=values, foo=foo)
except:
    rhnSQL.rollback()
    raise

rhnSQL.commit()
コード例 #55
0
ファイル: osa_dispatcher.py プロジェクト: tonyc389/spacewalk
class Runner(jabber_lib.Runner):
    client_factory = dispatcher_client.Client

    # We want the dispatcher to check in quite often in case the jabberd
    # connection drops
    _min_sleep = 10
    _max_sleep = 10

    def __init__(self):
        jabber_lib.Runner.__init__(self)
        initCFG("osa-dispatcher")
        self._tcp_server = None
        self._poll_interval = None
        self._next_poll_interval = None
        # Cache states
        self._state_ids = {}

    def read_config(self):
        ret = {
            'jabber_server' : CFG.jabber_server,
        }
        return ret

    _query_get_dispatcher_password = """
    select id, password
      from rhnPushDispatcher
     where jabber_id like :jabber_id
    """

    _update_dispatcher_password = """
    update rhnPushDispatcher
       set password = :password_in
     where id = :id_in
    """

    def get_dispatcher_password(self, username):
        h = rhnSQL.prepare(self._query_get_dispatcher_password)
        h.execute(jabber_id = username + "%")
        ret = h.fetchall_dict()

        if ret and len(ret) == 1:
            if ret[0]['password']:
                return ret[0]['password']
            else:
                # Upgrade Spacewalk 1.5 -> 1.6: the dispatcher row exists,
                # we just need to generate and save the password.
                self._password = self.create_dispatcher_password(32)
                u = rhnSQL.prepare(self._update_dispatcher_password)
                u.execute(password_in = self._password, id_in = ret[0]['id'])
                return self._password
        else:
            return None

    def create_dispatcher_password(self, length):
        chars = string.ascii_letters + string.digits
        return "".join(choice(chars) for x in range(length))

    def setup_config(self, config):
        # Figure out the log level
        debug_level = self.options.verbose
        if debug_level is None:
            debug_level = CFG.debug
        self.debug_level = debug_level
        initLOG(level=debug_level, log_file=CFG.log_file)

        # Get the ssl cert
        ssl_cert = CFG.osa_ssl_cert
        try:
            self.check_cert(ssl_cert)
        except jabber_lib.InvalidCertError, e:
            log_error("Invalid SSL certificate:", e)
            return 1

        self.ssl_cert = ssl_cert

        rhnSQL.initDB()

        self._username = '******'
        self._password = self.get_dispatcher_password(self._username)
        if not self._password:
            self._password = self.create_dispatcher_password(32)
        self._resource = 'superclient'
        js = config.get('jabber_server')
        self._jabber_servers = [ idn_ascii_to_puny(js) ]
コード例 #56
0
# Copyright (c) 2008--2013 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
#

from spacewalk.common.rhnConfig import initCFG
from spacewalk.server import rhnSQL, rhnUser

rhnSQL.initDB("rhnuser/rhnuser@webdev")
initCFG('server.xmlrpc')

u = rhnUser.search("mibanescu-channel-admin")
session = u.create_session()

s = session.get_session()

print("Checking with session", s)

u = rhnUser.session_reload(s)
print(u)
print(u.username)
コード例 #57
0
def gen_idlist_nokeyassoc(channelid=None):
    """generates the list of packages that have no keyid association"""
    import sys
    sys.path.append("/usr/share/rhn")
    try:
        import spacewalk.common.rhnConfig as rhnConfig
        import spacewalk.server.rhnSQL as rhnSQL
    except ImportError:
        try:
            import common.rhnConfig as rhnConfig
            import server.rhnSQL as rhnSQL
        except ImportError:
            print "Couldn't load the libraries required to connect to the db"
            sys.exit(1)

    rhnConfig.initCFG()
    rhnSQL.initDB()
    if channelid == None:
        print "checking on all channels"
        query = """
            select  
                rp.id as "id",  
                rc.label as "label",  
                rcpa.key_id as "key-id",  
                rpn.name||'-'||rpe.version||'-'||rpe.release||'.'||rpa.label as "package"  
            from rhnpackage rp  
                left outer join rhnchannelpackage rcp on rcp.package_id = rp.id  
                inner join rhnpackagename rpn on rpn.id = rp.name_id  
                inner join rhnpackageevr rpe on rpe.id = rp.evr_id  
                inner join rhnpackagearch rpa on rpa.id = rp.package_arch_id  
                left outer join rhnchannel rc on rc.id = rcp.channel_id  
                left outer join rhnpackagekeyassociation rcpa on rcpa.package_id = rp.id  
            where rcpa.key_id is null  
            order by rc.label;  
        """
    else:
        print "checking on channel ID %d" % (channelid)
        query = """
            select  
                rp.id as "id",  
                rc.label as "label",  
                rcpa.key_id as "key-id",  
                rpn.name||'-'||rpe.version||'-'||rpe.release||'.'||rpa.label as "package"  
            from rhnpackage rp  
                left outer join rhnchannelpackage rcp on rcp.package_id = rp.id  
                inner join rhnpackagename rpn on rpn.id = rp.name_id  
                inner join rhnpackageevr rpe on rpe.id = rp.evr_id  
                inner join rhnpackagearch rpa on rpa.id = rp.package_arch_id  
                left outer join rhnchannel rc on rc.id = rcp.channel_id  
                left outer join rhnpackagekeyassociation rcpa on rcpa.package_id = rp.id  
            where rcpa.key_id is null  
              and rpc.channel_id = """ + str(channelid) + """
            order by rc.label;  
        """
    cursor = rhnSQL.prepare(query)
    cursor.execute()
    rows = cursor.fetchall_dict()
    list_ids = []
    if not rows is None:
        c = 0
        for row in rows:
            c += 1
            list_ids.append(row['id'])
            print "\r%s of %s" % (str(c), str(len(rows))),
        print ""
    else:
        print "no packages found"
    return list_ids
コード例 #58
0
 def __init__(self):
     initCFG('server')
     rhnSQL.initDB()
コード例 #59
0
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
#
import sys

from templated_document import ServerTemplatedDocument
from spacewalk.server import rhnServer, rhnSQL

rhnSQL.initDB()

server_id = 1003887108

server = rhnServer.search(server_id)
server.reload_hardware()
server.load_custom_info()

t = ServerTemplatedDocument(server, start_delim='@@', end_delim='@@')
#t = ServerTemplatedDocument(server, start_delim='{|', end_delim='|}')

data = open("test/template1.tmpl").read()

try:
    print "interpolated:  ", t.interpolate(data)
except Exception, e:
コード例 #60
0
def gen_idlist():
    """generates the list of package IDs"""
    import sys
    sys.path.append("/usr/share/rhn")
    try:
        import spacewalk.common.rhnConfig as rhnConfig
        import spacewalk.server.rhnSQL as rhnSQL
    except ImportError:
        try:
            import common.rhnConfig as rhnConfig
            import server.rhnSQL as rhnSQL
        except ImportError:
            print "Couldn't load the libraries required to connect to the db"
            sys.exit(1)

    rhnConfig.initCFG()
    rhnSQL.initDB()
    # part relevant to path
    query = """
    select id from rhnpackage where path is null
    """
    cursor = rhnSQL.prepare(query)
    cursor.execute()
    rows = cursor.fetchall_dict()
    list_ids = []
    print "calculating which packages have no path in the database"
    if not rows is None:
        c = 0
        for row in rows:
            c += 1
            list_ids.append(row['id'])
            print "\r%s of %s" % (str(c), str(len(rows))),
        print ""
    else:
        print "no packages with no path"
    #part relevant to the duplicated packages
    query = """
        select  rpka.package_id as "id", rpn.name||'-'||rpe.version||'-'||rpe.release||'.'||rpa.label as package,
                rpka.key_id, rpk.key_id as signing_key,
                coalesce((select name from rhnpackageprovider rpp where rpp.id = rpk.provider_id),'Unknown') as provider,
                rpka.created, rpka.modified
        from    rhnpackagekeyassociation rpka, rhnpackage rp, rhnpackagename rpn, rhnpackagekey rpk, rhnpackageevr rpe, rhnpackagearch rpa,
                (select package_id,count(*) from rhnpackagekeyassociation group by package_id having count(*) > 1) dups 
        where   rpka.package_id = dups.package_id
        and     rpka.package_id = rp.id
        and     rpka.key_id = rpk.id
        and     rp.name_id = rpn.id
        and     rp.evr_id = rpe.id
        and     rp.package_arch_id = rpa.id
        order by 1, 3
    """
    print "calculating which packages are duplicates and have unknown providers"
    cursor = rhnSQL.prepare(query)
    cursor.execute()
    rows = cursor.fetchall_dict()
    if not rows is None:
        c = 0
        for row in rows:
            c += 1
            if not row['id'] in list_ids:
                list_ids.append(row['id'])
            print "\r%s of %s" % (str(int(round(
                c / 2))), str(int(len(rows) / 2))),
        print ""
    else:
        print "no duplicates with an unknown provider detected"
    return list_ids