示例#1
0
def test_main( testName, newProgramArgs, createOptionParserFn, createCommandFn, extraOutputGenerators, expectedOutput) :
    global gTestOutput

    # update args
    previousArgs = sys.argv
    sys.argv = []
    sys.argv.append(getProgramName())
    sys.argv.extend(newProgramArgs)

    # register command factory
    setExecutionContextFactory(TestExecutionContextFactory())

    commandObject=None
    parser = None

    startTest(testName)

    try:
        gplog.setup_tool_logging(gProgramName,unix.getLocalHostname(),unix.getUserName(),nonuser=False)

        parser = createOptionParserFn()
        (options, args) = parser.parse_args()
        gplog.enable_verbose_logging()

        commandObject = createCommandFn(options, args)
        exitCode = commandObject.run()

        testOutput("sys.exit %s" % exitCode)

    except ProgramArgumentValidationException, e:
        testOutput( "Validation error: %s" % e.getMessage())
    def close(self):
        """
        Closes all handles to the logs we're watching.
        """
        for h in self.handles.values():
            h.close()
        self.handles = {}



if __name__ == '__main__':

    # setup gpAdminLogs logging
    execname = os.path.split(sys.argv[0])[-1]
    hostname = unix.getLocalHostname()
    username = unix.getUserName()
    setup_tool_logging(execname, hostname, username)
    logger = get_default_logger()

    # watch syncmaster logs
    if len(sys.argv) > 2 and sys.argv[2] == 'debug':
        logger.info("Checking standby master status")
    watcher = SyncmasterWatcher( sys.argv[1] )
    rc = watcher.monitor_logs()
    watcher.close()

    # report final status
    # logger.info("exiting with %s" % rc)
    sys.exit( rc )
示例#3
0
def simple_main_locked(createOptionParserFn, createCommandFn, mainOptions):
    """
    Not to be called externally -- use simple_main instead
    """
    logger = gplog.get_default_logger()

    configurationInterface.registerConfigurationProvider(
        configurationImplGpdb.GpConfigurationProviderUsingGpdbCatalog())
    fileSystemInterface.registerFileSystemProvider(fileSystemImplOs.GpFileSystemProviderUsingOs())
    osInterface.registerOsProvider(osImplNative.GpOsProviderUsingNative())
    faultProberInterface.registerFaultProber(faultProberImplGpdb.GpFaultProberImplGpdb())

    commandObject = None
    parser = None

    forceQuiet = mainOptions is not None and mainOptions.get("forceQuietOutput")
    options = None

    if mainOptions is not None and mainOptions.get("programNameOverride"):
        global gProgramName
        gProgramName = mainOptions.get("programNameOverride")
    suppressStartupLogMessage = mainOptions is not None and mainOptions.get("suppressStartupLogMessage")

    useHelperToolLogging = mainOptions is not None and mainOptions.get("useHelperToolLogging")
    nonuser = True if mainOptions is not None and mainOptions.get("setNonuserOnToolLogger") else False
    exit_status = 1

    # NOTE: if this logic is changed then also change test_main in testUtils.py
    try:
        execname = getProgramName()
        hostname = unix.getLocalHostname()
        username = unix.getUserName()

        parser = createOptionParserFn()
        (options, args) = parser.parse_args()

        if useHelperToolLogging:
            gplog.setup_helper_tool_logging(execname, hostname, username)
        else:
            gplog.setup_tool_logging(execname, hostname, username,
                                     logdir=options.ensure_value("logfileDirectory", None), nonuser=nonuser)

        if forceQuiet:
            gplog.quiet_stdout_logging()
        else:
            if options.ensure_value("verbose", False):
                gplog.enable_verbose_logging()
            if options.ensure_value("quiet", False):
                gplog.quiet_stdout_logging()

        if options.ensure_value("masterDataDirectory", None) is not None:
            options.master_data_directory = os.path.abspath(options.masterDataDirectory)

        if not suppressStartupLogMessage:
            logger.info("Starting %s with args: %s" % (gProgramName, ' '.join(sys.argv[1:])))

        commandObject = createCommandFn(options, args)
        exitCode = commandObject.run()
        exit_status = exitCode

    except ProgramArgumentValidationException, e:
        if e.shouldPrintHelp():
            parser.print_help()
        logger.error("%s: error: %s" % (gProgramName, e.getMessage()))
        exit_status = 2
示例#4
0
#!/usr/bin/env python

"""
test script to provide gplog.feature (behave) test with logging samples.
"""
import logging

from gppylib import gplog

logger = gplog.get_default_logger()
gplog.setup_tool_logging("test_logging", "localhost", "gpadmin")
logger.warning("foobar to stdout and file")
gplog.log_to_file_only("blah to file only, not to stdout", logging.WARN)
gplog.log_to_file_only("another to file only, not to stdout")
示例#5
0
    if len(toasts) > 0:
        logger.info("Found %d spurious toast relations." % len(toasts))
        fixed_or_found = True
        if dryrun:
            for row in toasts:
                logger.debug("    %s" % row[1])
        else:
            gpdb.drop_spurious_toasts(toasts)
            logger.info("Dropped spurious toast relations.")
    gpdb.cleanup()
    return fixed_or_found

if __name__ == "__main__":
    options = parseargs(sys.argv)
    try:
        logger = gplog.setup_tool_logging(
            EXEC_NAME, socket.gethostname().split('.')[0], getpass.getuser())
        gplog._SOUT_HANDLER.addFilter(ExceptionFilter())
        if options.verbose:
            gplog.enable_verbose_logging()
        for db in get_dbs(options.host, options.port, options.user,
                          options.passwd):
            print
            logger.info("Database %s:" % db)
            fixed = rectify_db(db, options.host, options.port, options.user,
                               options.passwd, options.report)
            if not fixed:
                logger.info("No inconsistencies found in %s." % db)
            elif not options.report:
                logger.info("Upgrade fix applied to %s." % db)
    except (pg.InternalError, GPDBException), e:
        logger.exception(e)
    logger.info('Starting expunge commands...')
    for host in hosts:
        hostname, port = host[0], host[1]
        cmd = Command("Expunging index %s on host %s port %d" % (index, hostname, port),
                      EXPUNGE_COMMAND % (hostname, port, index))
        cmd.run(validateAfter=True)
    return

def main():
    options = parseargs()
    database = find_gptext_schema()
    if not database:
        logger.error('Could not find schema %s.' % GPTEXT_SCHEMA)
        logger.error('Use the --database option to specify the database that')
        logger.error('contains the %s schema.' % GPTEXT_SCHEMA)
        sys.exit(1)
    url = dbconn.DbURL(dbname=database)
    validate_solr_up(url)
    validate_index_exists(url, options.index)
    hosts   = get_solr_instances(url)
    if not userinput.ask_yesno(None, "\nContinue with GPText index '%s' expunge?" % options.index, 'N'):
        logger.error ('User asked for termination')
        sys.exit(1)
    gptext_index_expunge(options.index, hosts)
    logger.info('Done')
    logger.info('To check the process use "ps -ef | grep curl" - it will show you all the expunge requests issued')

gplog.setup_tool_logging('gptext_expunge', getLocalHostname(), getUserName())
logger  = gplog.get_default_logger()
main()