Example #1
0
    def setUpClass(cls):
        mdb, datastore = run_environment(config,
                                         apis=['mongodb'],
                                         override_integration_config={
                                             'default_mongodb': {
                                                 'publish': True,
                                                 'port': 27002,
                                                 'host': '127.0.0.1',
                                                 'type': 'mongodb',
                                                 'user': '',
                                                 'password': ''
                                             }
                                         },
                                         mindsdb_database=MINDSDB_DATABASE)
        cls.mdb = mdb

        if USE_EXTERNAL_DB_SERVER:
            open_ssh_tunnel(27002, direction='L')  # 27002 - mongos port
            wait_port(27002, timeout=10)

        cls.mongos_client = MongoClient('mongodb://127.0.0.1:27002/')
        mdb_shard = f"127.0.0.1:{config['api']['mongodb']['port']}"
        try:
            cls.mongos_client.admin.command('removeShard', mdb_shard)
        except Exception:
            # its ok if shard not exiss
            pass

        models = cls.mdb.get_models()
        models = [x['name'] for x in models]
        if TEST_PREDICTOR_NAME in models:
            cls.mdb.delete_model(TEST_PREDICTOR_NAME)

        if not USE_EXTERNAL_DB_SERVER:
            test_csv_path = Path(DATASETS_PATH).joinpath(
                TEST_DATASET).joinpath('data.csv')

            db = cls.mongos_client['test_data']
            colls = db.list_collection_names()

            if TEST_DATASET not in colls:
                print('creatating test data')
                with open(test_csv_path) as f:
                    csvf = csv.reader(f)
                    data = []
                    DS = DATASETS_COLUMN_TYPES[TEST_DATASET]
                    for i, row in enumerate(csvf):
                        if i == 0:
                            continue
                        data.append({
                            column[0]: column[1](row[i])
                            for i, column in enumerate(DS)
                        })
                    db[TEST_DATASET].insert_many(data)
                print('done')

        cls.mongos_client.admin.command('addShard', mdb_shard)
Example #2
0
    if status == 0:
        atexit.register(close_ssh_tunnel, sp=sp, port=port)
    return status


def is_mssql_test():
    for x in sys.argv:
        if 'test_mssql.py' in x:
            return True
    return False


if USE_EXTERNAL_DB_SERVER:
    config = Config(TEST_CONFIG)
    open_ssh_tunnel(5005, 'L')
    wait_port(5005, timeout=10)

    close_all_ssh_tunnels()

    for _ in range(10):
        r = requests.get('http://127.0.0.1:5005/port')
        if r.status_code != 200:
            raise Exception('Cant get port to run mindsdb')
        mindsdb_port = r.content.decode()
        status = open_ssh_tunnel(mindsdb_port, 'R')
        if status == 0:
            break
    else:
        raise Exception('Cant get empty port to run mindsdb')

    print(f'use mindsdb port={mindsdb_port}')
Example #3
0
def wait_api_ready(config, api='mysql'):
    port_num = config['api'][api]['port']
    api_ready = wait_port(port_num, START_TIMEOUT)
    return api_ready