Example #1
0
def main(args):
    """The main entry point of the application

    The script follows a simple workflow in order to parse and persist
    the test run information to a database. It runs the main logic under a
    TestRun/PerfTestRun object designed to encapsulate information for a
    specific test run.

    The parser expects at least two arguments, an xml and a log file, in order
    to parse minimum information regarding the tests that have been run and
    the test environment.
    """
    # Parse arguments and check if they exist
    arg_parser = config.init_arg_parser()
    parsed_arguments = arg_parser.parse_args(args)

    path_validation = config.validate_input(parsed_arguments)
    if isinstance(path_validation, list):
        print("\n%s \n" % path_validation[1])
        print(arg_parser.parse_args(['-h']))
        sys.exit(0)

    config.setup_logging(default_level=int(parsed_arguments.loglevel))

    logger.debug('Parsing env variables')
    env.read_envfile(parsed_arguments.config)

    logger.info('Initializing TestRun object')
    if parsed_arguments.perf:
        test_run = PerfTestRun(parsed_arguments.perf, parsed_arguments.skipkvp)
    else:
        test_run = TestRun(skip_vm_check=parsed_arguments.skipkvp)

    logger.info('Parsing XML file - %s', parsed_arguments.xml_file_path)
    test_run.update_from_xml(parsed_arguments.xml_file_path)

    logger.info('Parsing log file - %s', parsed_arguments.log_file_path)
    test_run.update_from_ica(parsed_arguments.log_file_path)

    if not parsed_arguments.skipkvp:
        logger.info('Getting KVP values from VM')
        test_run.update_from_vm(['OSBuildNumber', 'OSName', 'OSMajorVersion'],
                                stop_vm=True)

    # Parse values to be inserted
    logger.info('Parsing test run for database insertion')
    insert_values = test_run.parse_for_db_insertion()
    # Connect to db and insert values in the table
    logger.info('Initializing database connection')
    db_connection, db_cursor = sql_utils.init_connection()

    logger.info('Executing insertion commands')
    for table_line in insert_values:
        sql_utils.insert_values(db_cursor, table_line)

    logger.info('Committing changes to the database')
    db_connection.commit()

    logger.info("Checking insert validity")
    sql_utils.check_insert(db_cursor, insert_values)
Example #2
0
def main(args):
    """The main entry point of the application

    The script follows a simple workflow in order to parse and persist
    the test run information to a database. It runs the main logic under a
    TestRun/PerfTestRun object designed to encapsulate information for a
    specific test run.

    The parser expects at least two arguments, an xml and a log file, in order
    to parse minimum information regarding the tests that have been run and
    the test environment.
    """
    # Parse arguments and check if they exist
    arg_parser = config.init_arg_parser()
    parsed_arguments = arg_parser.parse_args(args)

    if not config.validate_input(parsed_arguments):
        print('Invalid command line arguments')
        print(arg_parser.parse_args(['-h']))
        sys.exit(0)

    config.setup_logging(
        default_level=int(parsed_arguments.loglevel)
    )

    logger.debug('Parsing env variables')
    env.read_envfile(parsed_arguments.config)

    logger.info('Initializing TestRun object')
    if parsed_arguments.perf:
        test_run = PerfTestRun(parsed_arguments.perf,
                               parsed_arguments.skipkvp)
    else:
        test_run = TestRun(skip_vm_check=parsed_arguments.skipkvp)

    logger.info('Parsing XML file - %s', parsed_arguments.xml_file_path)
    test_run.update_from_xml(parsed_arguments.xml_file_path)

    logger.info('Parsing log file - %s', parsed_arguments.log_file_path)
    test_run.update_from_ica(parsed_arguments.log_file_path)

    if not parsed_arguments.skipkvp:
        logger.info('Getting KVP values from VM')
        test_run.update_from_vm([
            'OSBuildNumber', 'OSName', 'OSMajorVersion'
        ], stop_vm=True)

    # Parse values to be inserted
    logger.info('Parsing test run for database insertion')
    insert_values = test_run.parse_for_db_insertion()
    # Connect to db and insert values in the table
    logger.info('Initializing database connection')
    db_connection, db_cursor = sql_utils.init_connection()

    logger.info('Executing insertion commands')
    for table_line in insert_values:
        sql_utils.insert_values(db_cursor, table_line)

    logger.info('Committing changes to the database')
    db_connection.commit()
Example #3
0
def main(args):
    """The main entry point of the application

    The script follows a simple workflow in order to parse and persist
    the test run information to a database. It runs the main logic under a
    TestRun/PerfTestRun object designed to encapsulate information for a
    specific test run.

    The parser expects at least two arguments, an xml and a log file, in order
    to parse minimum information regarding the tests that have been run and
    the test environment.
    """
    # Parse arguments and check if they exist
    arg_parser = config.init_arg_parser()
    parsed_arguments = arg_parser.parse_args(args)
    config.setup_logging(default_level=int(parsed_arguments.loglevel))

    print(parsed_arguments)
    path_validation = config.validate_input(parsed_arguments)
    if isinstance(path_validation, list):
        print("\n%s \n" % path_validation[1])
        print(arg_parser.parse_args(['-h']))
        sys.exit(0)

    # Connect to db
    env.read_envfile(parsed_arguments.config)
    logger.info('Initializing database connection')
    db_connection, db_cursor = sql_utils.init_connection()
    # Parse results
    test_run = parse_results(parsed_arguments.xml_file_path,
                             parsed_arguments.log_file_path,
                             parsed_arguments.perf,
                             parsed_arguments.skipkvp,
                             parsed_arguments.snapshot,
                             db_cursor)

    insert_list = test_run.parse_for_db_insertion()
    if not parsed_arguments.nodbcommit:
        if test_run:
            commit_results(db_connection, db_cursor, insert_list)
        else:
            logger.warning('Results need to be parsed first.')
    else:
        logger.info('Skipping db insertion.') 

    if parsed_arguments.report:
        MonitorRuns.write_json(parsed_arguments.report, MonitorRuns.get_test_summary(insert_list))
    if parsed_arguments.summary:
        MonitorRuns(parsed_arguments.summary)()
Example #4
0
def commit_results(insert_values, config_file_path):
    env.read_envfile(config_file_path)
    # Connect to db and insert values in the table
    logger.info('Initializing database connection')
    db_connection, db_cursor = sql_utils.init_connection()

    logger.info('Executing insertion commands')
    for table_line in insert_values:
        sql_utils.insert_values(db_cursor, table_line)

    logger.info('Committing changes to the database')
    db_connection.commit()

    logger.info("Checking insert validity")
    sql_utils.check_insert(db_cursor, insert_values)
Example #5
0
def commit_results(insert_values, config_file_path):
    env.read_envfile(config_file_path)
    # Connect to db and insert values in the table
    logger.info('Initializing database connection')
    db_connection, db_cursor = sql_utils.init_connection()

    logger.info('Executing insertion commands')
    for table_line in insert_values:
        sql_utils.insert_values(db_cursor, table_line)

    logger.info('Committing changes to the database')
    db_connection.commit()

    logger.info("Checking insert validity")
    sql_utils.check_insert(db_cursor, insert_values)
Example #6
0
def main(args):
    """The main entry point of the application

    """
    # Parse arguments and check if they exist
    parsed_arguments = config.parse_arguments(args)

    if not config.validate_input(parsed_arguments):
        print('Invalid command line arguments')
        sys.exit(0)

    config.setup_logging(
        default_level=int(parsed_arguments['level'])
    )

    logger.debug('Parsing env variables')
    env.read_envfile(parsed_arguments['env'])

    logger.info('Initializing TestRun object')
    test_run = TestRun()

    logger.info('Parsing XML file - %s', parsed_arguments['xml'])
    test_run.update_from_xml(parsed_arguments['xml'])

    logger.info('Parsing log file - %s', parsed_arguments['log'])
    test_run.update_from_ica(parsed_arguments['log'])

    if parsed_arguments['kvp']:
        logger.info('Getting KVP values from VM')
        test_run.update_from_vm([
            'OSBuildNumber', 'OSName', 'OSMajorVersion'
        ], stop_vm=True)

    # Parse values to be inserted
    logger.info('Parsing test run for database insertion')
    insert_values = test_run.parse_for_db_insertion()

    # Connect to db and insert values in the table
    logger.info('Initializing database connection')
    db_connection, db_cursor = sql_utils.init_connection()

    logger.info('Executing insertion commands')
    for table_line in insert_values:
        sql_utils.insert_values(db_cursor, table_line)

    logger.info('Committing changes to the database')
    db_connection.commit()
Example #7
0
    def parse_build():

        db_connection, db_cursor = sql_utils.init_connection()
        logger.info("Successfully connected to Database")

        results = parser.get_results()
        logger.info("Successfully parsed the results")

        try:
            for result in results:
                d = parser.process_entry()
                d['TestCaseName'] = result
                d['TestResult'] = results[result]
                sql_utils.insert_values(db_cursor, d)
            db_connection.commit()
        except Exception as e:
            logger.error(e[1])
        else:
            logger.info("Successfully added to database!")
Example #8
0
    def parse_build():

        db_connection, db_cursor = sql_utils.init_connection()
        logger.info("Successfully connected to Database")

        results = parser.get_results()
        logger.info("Successfully parsed the results")

        try:
            for result in results:
                d = parser.process_entry()
                d['TestCaseName'] = result
                d['TestResult'] = results[result]
                sql_utils.insert_values(db_cursor, d)
            db_connection.commit()
        except Exception as e:
            logger.error(e[1])
        else:
            logger.info("Successfully added to database!")