def test_load_balanced(self):
        # =-=-=-=-=-=-=-
        # read server_config.json and .odbc.ini
        cfg = ServerConfig()

        if cfg.get('catalog_database_type') == "postgres":
            # =-=-=-=-=-=-=-
            # seed load table with fake values - rescA should win
            secs = int(time.time())
            cfg.exec_sql_cmd(
                "insert into r_server_load_digest values ('rescA', 50, %s)" %
                secs)
            cfg.exec_sql_cmd(
                "insert into r_server_load_digest values ('rescB', 75, %s)" %
                secs)
            cfg.exec_sql_cmd(
                "insert into r_server_load_digest values ('rescC', 95, %s)" %
                secs)

            # =-=-=-=-=-=-=-
            # build a logical path for putting a file
            test_file = self.admin.session_collection + "/test_file.txt"

            # =-=-=-=-=-=-=-
            # put a test_file.txt - should be on rescA given load table values
            self.admin.assert_icommand(
                "iput -f ./test_load_balanced_suite.py " + test_file)
            self.admin.assert_icommand("ils -L " + test_file,
                                       'STDOUT_SINGLELINE', "rescA")
            self.admin.assert_icommand("irm -f " + test_file)

            # =-=-=-=-=-=-=-
            # drop rescC to a load of 15 - this should now win
            cfg.exec_sql_cmd(
                "update r_server_load_digest set load_factor=15 where resc_name='rescC'"
            )

            # =-=-=-=-=-=-=-
            # put a test_file.txt - should be on rescC given load table values
            self.admin.assert_icommand(
                "iput -f ./test_load_balanced_suite.py " + test_file)
            self.admin.assert_icommand("ils -L " + test_file,
                                       'STDOUT_SINGLELINE', "rescC")
            self.admin.assert_icommand("irm -f " + test_file)

            # =-=-=-=-=-=-=-
            # clean up our alterations to the load table
            cfg.exec_sql_cmd(
                "delete from r_server_load_digest where resc_name='rescA'")
            cfg.exec_sql_cmd(
                "delete from r_server_load_digest where resc_name='rescB'")
            cfg.exec_sql_cmd(
                "delete from r_server_load_digest where resc_name='rescC'")
        else:
            print 'skipping test_load_balanced due to unsupported database for this test.'
Example #2
0
def update_database_to_latest_version():
    # get config
    cfg = ServerConfig()
    # get current version
    current_schema_version = get_current_schema_version(cfg)
    # get target version
    target_schema_version = get_target_schema_version()
    # check if any work to be done
    if current_schema_version > target_schema_version:
        print_error('Catalog Schema Version is from the future (current=%d > target=%d).' % (
            current_schema_version, target_schema_version))
        return
    if current_schema_version == target_schema_version:
        print('Catalog Schema Version is already up to date (version=%d).' %
              target_schema_version)
        return
    # read possible update sql files
    foundfiles = get_update_files(current_schema_version, cfg.get('catalog_database_type'))
    print_debug('files: %s' % foundfiles)
    updatefiles = {}
    for f in foundfiles:
        version = int(f.split('/')[-1].split('.')[0])
        updatefiles[version] = f
    print_debug('updatefiles: %s' % updatefiles)
    # check all necessary update files exist
    for version in range(current_schema_version + 1, target_schema_version + 1):
        print_debug('checking... %d' % version)
        if version not in updatefiles.keys():
            print_error('ERROR: SQL Update File Not Found for Schema Version %d' % version)
            return
    # run each update sql file
    for version in range(current_schema_version + 1, target_schema_version + 1):
        print('Updating to Catalog Schema... %d' % version)
        print_debug('running: %s' % updatefiles[version])
        result = cfg.exec_sql_file(updatefiles[version])
        if result[2].decode('utf-8') != '':
            print_error('ERROR: SQL did not complete...')
            print_error(result[2])
            return
        print_debug('sql result...')
        print_debug(result)
        # update schema_version in database
        update_schema_version(cfg, version)
    # done
    print('Done.')
    def test_load_balanced(self):
        # =-=-=-=-=-=-=-
        # read server_config.json and .odbc.ini
        cfg = ServerConfig()

        if cfg.get('catalog_database_type') == "postgres":
            # =-=-=-=-=-=-=-
            # seed load table with fake values - rescA should win
            secs = int(time.time())
            cfg.exec_sql_cmd("insert into r_server_load_digest values ('rescA', 50, %s)" % secs)
            cfg.exec_sql_cmd("insert into r_server_load_digest values ('rescB', 75, %s)" % secs)
            cfg.exec_sql_cmd("insert into r_server_load_digest values ('rescC', 95, %s)" % secs)

            # =-=-=-=-=-=-=-
            # build a logical path for putting a file
            test_file_path = "/" + s.adminsession.get_zone_name() + "/home/" + s.adminsession.get_username() + \
                "/" + s.adminsession._session_id
            test_file = test_file_path + "/test_file.txt"

            # =-=-=-=-=-=-=-
            # put a test_file.txt - should be on rescA given load table values
            assertiCmd(s.adminsession, "iput -f ./test_load_balanced_suite.py " + test_file)
            assertiCmd(s.adminsession, "ils -L " + test_file, "LIST", "rescA")
            assertiCmd(s.adminsession, "irm -f " + test_file)

            # =-=-=-=-=-=-=-
            # drop rescC to a load of 15 - this should now win
            cfg.exec_sql_cmd("update r_server_load_digest set load_factor=15 where resc_name='rescC'")

            # =-=-=-=-=-=-=-
            # put a test_file.txt - should be on rescC given load table values
            assertiCmd(s.adminsession, "iput -f ./test_load_balanced_suite.py " + test_file)
            assertiCmd(s.adminsession, "ils -L " + test_file, "LIST", "rescC")
            assertiCmd(s.adminsession, "irm -f " + test_file)

            # =-=-=-=-=-=-=-
            # clean up our alterations to the load table
            cfg.exec_sql_cmd("delete from r_server_load_digest where resc_name='rescA'")
            cfg.exec_sql_cmd("delete from r_server_load_digest where resc_name='rescB'")
            cfg.exec_sql_cmd("delete from r_server_load_digest where resc_name='rescC'")
        else:
            print 'skipping test_load_balanced due to unsupported database for this test.'