def test_remove_columns(): """Test workaround for dropping columns in sqlite3.""" with create_temp_db() as (temp_db, conn): conn.execute( r''' CREATE TABLE foo ( bar, baz, pub ) ''' ) conn.execute( r''' INSERT INTO foo VALUES (?,?,?) ''', ['BAR', 'BAZ', 'PUB'] ) conn.commit() conn.close() dao = CylcSuiteDAO(temp_db) dao.remove_columns('foo', ['bar', 'baz']) conn = dao.connect() data = [row for row in conn.execute(r'SELECT * from foo')] assert data == [('PUB',)]
def test_upgrade_hold_swap(): """Pre Cylc8 DB upgrade compatibility test.""" # test data initial_data = [ # (name, cycle, status, hold_swap) ('foo', '1', 'waiting', ''), ('bar', '1', 'held', 'waiting'), ('baz', '1', 'held', 'running'), ('pub', '1', 'waiting', 'held') ] expected_data = [ # (name, cycle, status, hold_swap, is_held) ('foo', '1', 'waiting', 0), ('bar', '1', 'waiting', 1), ('baz', '1', 'running', 1), ('pub', '1', 'waiting', 1) ] tables = [ CylcSuiteDAO.TABLE_TASK_POOL, CylcSuiteDAO.TABLE_TASK_POOL_CHECKPOINTS ] with create_temp_db() as (temp_db, conn): # initialise tables for table in tables: conn.execute( rf''' CREATE TABLE {table} ( name varchar(255), cycle varchar(255), status varchar(255), hold_swap varchar(255) ) ''' ) conn.executemany( rf''' INSERT INTO {table} VALUES (?,?,?,?) ''', initial_data ) # close database conn.commit() conn.close() # open database as cylc dao dao = CylcSuiteDAO(temp_db) conn = dao.connect() # check the initial data was correctly inserted for table in tables: dump = [x for x in conn.execute(rf'SELECT * FROM {table}')] assert dump == initial_data # upgrade assert dao.upgrade_is_held() # check the data was correctly upgraded for table in tables: dump = [x for x in conn.execute(r'SELECT * FROM task_pool')] assert dump == expected_data # make sure the upgrade is skipped on future runs assert not dao.upgrade_is_held()
def test_upgrade_to_platforms(mock_glbl_cfg): """Test upgrader logic for platforms in the database. """ # Set up the global config mock_glbl_cfg('cylc.flow.rundb.glbl_cfg', GLOBAL_CONFIG) # task name, cycle, user_at_host, batch_system initial_data = [ ('hpc_with_pbs', '1', 'hpcl1', 'pbs'), ('desktop_with_bg', '1', 'desktop01', 'background'), ('slurm_no_host', '1', '', 'slurm'), ('hpc_bg', '1', 'hpcl1', 'background'), ('username_given', '1', 'slartibartfast@hpcl1', 'pbs') ] # task name, cycle, user, platform expected_data = [ ('hpc_with_pbs', '1', '', 'hpc'), ('desktop_with_bg', '1', '', 'desktop01'), ('slurm_no_host', '1', '', 'sugar'), ('hpc_bg', '1', '', 'hpcl1-bg'), ('username_given', '1', 'slartibartfast', 'hpc'), ] with create_temp_db() as (temp_db, conn): conn.execute( rf''' CREATE TABLE {CylcSuiteDAO.TABLE_TASK_JOBS} ( name varchar(255), cycle varchar(255), user_at_host varchar(255), batch_system varchar(255) ) ''' ) conn.executemany( rf''' INSERT INTO {CylcSuiteDAO.TABLE_TASK_JOBS} VALUES (?,?,?,?) ''', initial_data ) # close database conn.commit() conn.close() # open database as cylc dao dao = CylcSuiteDAO(temp_db) conn = dao.connect() # check the initial data was correctly inserted dump = [ x for x in conn.execute( rf'SELECT * FROM {CylcSuiteDAO.TABLE_TASK_JOBS}' ) ] assert dump == initial_data # Upgrade function returns True? assert dao.upgrade_to_platforms() # check the data was correctly upgraded dump = [ x for x in conn.execute( r'SELECT name, cycle, user, platform_name FROM task_jobs' ) ] assert dump == expected_data # make sure the upgrade is skipped on future runs assert not dao.upgrade_to_platforms()
def test_upgrade_retry_state(): """Pre Cylc8 DB upgrade compatibility test.""" initial_data = [ # (name, cycle, status) ('foo', '1', 'waiting'), ('bar', '1', 'running'), ('baz', '1', 'retrying'), ('pub', '1', 'submit-retrying') ] expected_data = [ # (name, cycle, status) ('foo', '1', 'waiting'), ('bar', '1', 'running'), ('baz', '1', 'waiting'), ('pub', '1', 'waiting') ] tables = [ CylcSuiteDAO.TABLE_TASK_POOL, CylcSuiteDAO.TABLE_TASK_POOL_CHECKPOINTS ] with create_temp_db() as (temp_db, conn): # initialise tables for table in tables: conn.execute( rf''' CREATE TABLE {table} ( name varchar(255), cycle varchar(255), status varchar(255) ) ''' ) conn.executemany( rf''' INSERT INTO {table} VALUES (?,?,?) ''', initial_data ) # close database conn.commit() conn.close() # open database as cylc dao dao = CylcSuiteDAO(temp_db) conn = dao.connect() # check the initial data was correctly inserted for table in tables: dump = [x for x in conn.execute(rf'SELECT * FROM {table}')] assert dump == initial_data # upgrade assert dao.upgrade_retry_state() == [ ('1', 'baz', 'retrying'), ('1', 'pub', 'submit-retrying') ] # check the data was correctly upgraded for table in tables: dump = [x for x in conn.execute(r'SELECT * FROM task_pool')] assert dump == expected_data