def setUp(self):
     initCFG("server.xmlrpc")
     rhnSQL.initDB(backend="oracle",
                   username=DB_SETTINGS["user"],
                   password=DB_SETTINGS["password"],
                   database=DB_SETTINGS["database"])
     rhnSQL.clear_log_id()
Exemplo n.º 2
0
 def setUp(self):
     rhnSQL.initDB(
         backend="oracle",
         username=DB_SETTINGS["user"],
         password=DB_SETTINGS["password"],
         database=DB_SETTINGS["database"]
     )
     rhnSQL.clear_log_id()
Exemplo n.º 3
0
def register_system(client, minion):
    """
    Adds a spacewalk registration for a minion.
    """
    # ask for the minion data to get its id that tell us
    # if it is registered, and data to register it
    ret = client.cmd_iter(minion, GRAINS_ITEMS_CMD)

    for grains in ret:
        logger.info("Registering new minion: %s", minion)

        if minion in grains:
            values = grains[minion]['ret']
            logger.debug("%s grains:\n%s", minion, pp.pformat(values))

            username = client.cmd(minion, PILLAR_GET_CMD,
                                  [ADMIN_USER_PILLAR_KEY])
            if not username[minion]:
                logger.error("Can't get admin user from pillar key '%s'",
                             ADMIN_USER_PILLAR_KEY)
                continue

            user = rhnUser.search(username[minion])

            rhnSQL.clear_log_id()
            newserv = rhnServer.Server(user, values['osarch'])

            token = client.cmd(minion, PILLAR_GET_CMD,
                               [ACTIVATION_KEY_PILLAR_KEY])

            if not token[minion]:
                tokens_obj = rhnServer.search_org_token(user.contact["org_id"])
                rhnFlags.set("universal_registration_token", tokens_obj)
            else:
                tokens_obj = rhnServer.search_token(token[minion])
                rhnFlags.set("registration_token", tokens_obj)

            # reserve the id
            newserv.getid()
            # overrite the digital id
            # FIXME: None of these values appear in the systems properties
            newserv.server['digital_server_id'] = 'SALT-ID-%s' % minion
            newserv.server['release'] = values['osrelease']
            newserv.server['os'] = values['osfullname']
            newserv.server['name'] = minion
            newserv.server['running_kernel'] = values['kernelrelease']
            newserv.virt_uuid = None
            newserv.save()

            rhnSQL.commit()

            logger.info("%s registered as %s", minion, newserv.getid())
        else:
            logger.error("Registration failed: Can't get grains for %s",
                         minion)
Exemplo n.º 4
0
    def setUp(self):
        self.table_name = "misatest_%d" % os.getpid()
        rhnSQL.initDB(backend="oracle",
                      username=DB_SETTINGS["user"],
                      password=DB_SETTINGS["password"],
                      database=DB_SETTINGS["database"])
        self._cleanup()
        rhnSQL.clear_log_id()

        rhnSQL.execute("create table %s (id int, val varchar2(10))" %
                       self.table_name)
        rhnSQL.commit()
Exemplo n.º 5
0
def register_system(client, minion):
    """
    Adds a spacewalk registration for a minion.
    """
    # ask for the minion data to get its id that tell us
    # if it is registered, and data to register it
    ret = client.cmd_iter(minion, GRAINS_ITEMS_CMD)

    for grains in ret:
        logger.info("Registering new minion: %s", minion)

        if minion in grains:
            values = grains[minion]['ret']
            logger.debug("%s grains:\n%s", minion, pp.pformat(values))

            username = client.cmd(minion, PILLAR_GET_CMD, [ADMIN_USER_PILLAR_KEY])
            if not username[minion]:
                logger.error("Can't get admin user from pillar key '%s'", ADMIN_USER_PILLAR_KEY)
                continue

            user = rhnUser.search(username[minion])

            rhnSQL.clear_log_id()
            newserv = rhnServer.Server(user, values['osarch'])

            token = client.cmd(minion, PILLAR_GET_CMD, [ACTIVATION_KEY_PILLAR_KEY])

            if not token[minion]:
                tokens_obj = rhnServer.search_org_token(user.contact["org_id"])
                rhnFlags.set("universal_registration_token", tokens_obj)
            else:
                tokens_obj = rhnServer.search_token(token[minion])
                rhnFlags.set("registration_token", tokens_obj)

            # reserve the id
            newserv.getid()
            # overrite the digital id
            # FIXME: None of these values appear in the systems properties
            newserv.server['digital_server_id'] = 'SALT-ID-%s' % minion
            newserv.server['release'] = values['osrelease']
            newserv.server['os'] = values['osfullname']
            newserv.server['name'] = minion
            newserv.server['running_kernel'] = values['kernelrelease']
            newserv.virt_uuid = None
            newserv.save()

            rhnSQL.commit()

            logger.info("%s registered as %s", minion, newserv.getid())
        else:
            logger.error("Registration failed: Can't get grains for %s",
                         minion)
Exemplo n.º 6
0
    def setUp(self):
        self.table_name = "misatest_%d" % os.getpid()
        rhnSQL.initDB(
            backend="oracle",
            username=DB_SETTINGS["user"],
            password=DB_SETTINGS["password"],
            database=DB_SETTINGS["database"]
        )
        self._cleanup()
        rhnSQL.clear_log_id()

        rhnSQL.execute("create table %s (id int, val varchar2(10))" %
                       self.table_name)
        rhnSQL.commit()
Exemplo n.º 7
0
    # expiration check
    if not options.ignore_expiration:
        date = expiredYN(options.rhn_cert)
        if date:
            just_date = date.split(' ')[0]
            writeError('RHN Certificate appears to have expired: %s' %
                       just_date)
            return 11

    if not options.sanity_only:
        prepRhnCert(options)
        # local activation
        try:

            rhnSQL.initDB()
            rhnSQL.clear_log_id()
            rhnSQL.set_log_auth_login('SETUP')
            if options.verbose:
                print("Database connectioned initialized: refer to %s" %
                      CFG.filename)
            activateSatellite_local(options)
        except RHNCertLocalActivationException, e:
            writeError(e)
            return 30

        # remote activation
        if not options.disconnected:
            try:
                activateSatellite_remote(options)
            except RHNCertRemoteActivationException, e:
                writeError(e)
    # expiration check
    if not options.ignore_expiration:
        date = expiredYN(options.rhn_cert)
        if date:
            just_date = date.split(' ')[0]
            writeError(
                'RHN Certificate appears to have expired: %s' % just_date)
            return 11

    if not options.sanity_only:
        prepRhnCert(options)
        # local activation
        try:

            rhnSQL.initDB()
            rhnSQL.clear_log_id()
            rhnSQL.set_log_auth_login('SETUP')
            if options.verbose:
                print ("Database connectioned initialized: refer to %s" %
                       CFG.filename)
            activateSatellite_local(options)
        except RHNCertLocalActivationException, e:
            writeError(e)
            return 30

        # remote activation
        if not options.disconnected:
            try:
                activateSatellite_remote(options)
            except RHNCertRemoteActivationException, e:
                writeError(e)