def ensure_primary_mirror_switched_roles(): results = execute_sql( "postgres", "select * from gp_segment_configuration where preferred_role <> role") if results.rowcount != 2: raise Exception("expected 2 segments to not be in preferred roles")
def ensure_primary_mirror_switched_roles(): results = execute_sql( "postgres", "select * from gp_segment_configuration where preferred_role <> role" ) if results.rowcount != 2: raise Exception("expected 2 segments to not be in preferred roles")
def step_impl(context): result_cursor = execute_sql( "postgres", "select datadir from gp_segment_configuration where role='m';") for content_id, result in enumerate(result_cursor.fetchall()): path_to_replslot = os.path.join(result[0], 'pg_replslot') if len(os.listdir(path_to_replslot)) > 0: raise Exception("expected replication slot directory to be empty")
def step_impl(context): result_cursor = execute_sql( "postgres", "select datadir from gp_segment_configuration where role='m';" ) for content_id, result in enumerate(result_cursor.fetchall()): path_to_replslot = os.path.join(result[0], 'pg_replslot') if len(os.listdir(path_to_replslot)) > 0: raise Exception("expected replication slot directory to be empty")
def step_impl(context): results = execute_sql( "postgres", "select pg_get_replication_slots() from gp_dist_random('gp_id')") if results.rowcount != 3: raise Exception( "expected all three primaries to have replication slots") for result in results.fetchall(): if not result[0].startswith( '(internal_wal_replication_slot,,physical,,t,'): raise Exception("expected replication slot to be active")
def step_impl(context): result_cursor = execute_sql( "postgres", "select pg_get_replication_slots() from gp_dist_random('gp_id') order by gp_segment_id" ) if result_cursor.rowcount != context.current_cluster_size: raise Exception("expected all %d primaries to have replication slots, only %d have slots" % (context.current_cluster_size, results.rowcount)) for content_id, result in enumerate(result_cursor.fetchall()): if not result[0].startswith('(internal_wal_replication_slot,,physical,,t,'): raise Exception( "expected replication slot to be active for content id %d, got %s" % (content_id, result[0]) )
def step_impl(context): host, datadir = execute_sql( "postgres", "SELECT hostname, datadir FROM gp_segment_configuration WHERE role='m' AND content=0" ).fetchone() # NOTE that these commands are manually escaped; beware when adding dollar # signs or double-quotes! cmd = "ps aux | grep '[p]ostgres .* %s' | awk '{print \$2}' | xargs kill -9" % datadir cmd = 'ssh %s "%s"' % (host, cmd) run_command(context, cmd) # If the kill succeeds, recover the mirror when this test is done. def recover(): run_command(context, "gprecoverseg -a") context.add_cleanup(recover) wait_for_unblocked_transactions(context)
def after_scenario(context, scenario): #TODO: you'd think that the scenario.skip() in before_scenario() would # cause this to not be needed if "skip" in scenario.effective_tags: return if 'tablespaces' in context: for tablespace in list(context.tablespaces.values()): tablespace.cleanup() if 'gpstop' in scenario.effective_tags: context.execute_steps(''' # restart the cluster so that subsequent tests re-use the existing demo cluster Then the user runs "gpstart -a" And gpstart should return a return code of 0 ''') if 'gp_bash_functions.sh' in context.feature.tags or 'backup_restore_bashrc' in scenario.effective_tags: restore_bashrc() # NOTE: gpconfig after_scenario cleanup is in the step `the gpconfig context is setup` tags_to_skip = ['gpexpand', 'gpaddmirrors', 'gpinitstandby', 'gpconfig', 'gpstop', 'gpinitsystem', 'cross_subnet'] if set(context.feature.tags).intersection(tags_to_skip): return tags_to_cleanup = ['gpmovemirrors', 'gpssh-exkeys'] if set(context.feature.tags).intersection(tags_to_cleanup): if 'temp_base_dir' in context and os.path.exists(context.temp_base_dir): os.chmod(context.temp_base_dir, 0o700) shutil.rmtree(context.temp_base_dir) tags_to_not_restart_db = ['analyzedb', 'gpssh-exkeys'] if not set(context.feature.tags).intersection(tags_to_not_restart_db): start_database_if_not_started(context) home_dir = os.path.expanduser('~') if not check_user_permissions(home_dir, 'write') and hasattr(context, 'orig_write_permission')\ and context.orig_write_permission: run_command(context, 'sudo chmod u+w %s' % home_dir) if os.path.isdir('%s/gpAdminLogs.bk' % home_dir): shutil.move('%s/gpAdminLogs.bk' % home_dir, '%s/gpAdminLogs' % home_dir) if 'gpssh' in context.feature.tags: run_command(context, 'sudo tc qdisc del dev lo root netem') # for cleaning up after @given('"{path}" has its permissions set to "{perm}"') if (hasattr(context, 'path_for_which_to_restore_the_permissions') and hasattr(context, 'permissions_to_restore_path_to')): os.chmod(context.path_for_which_to_restore_the_permissions, context.permissions_to_restore_path_to) elif hasattr(context, 'path_for_which_to_restore_the_permissions'): raise Exception('Missing permissions_to_restore_path_to for %s' % context.path_for_which_to_restore_the_permissions) elif hasattr(context, 'permissions_to_restore_path_to'): raise Exception('Missing path_for_which_to_restore_the_permissions despite the specified permission %o' % context.permissions_to_restore_path_to) if 'gpstate' in context.feature.tags: create_fault_query = "CREATE EXTENSION IF NOT EXISTS gp_inject_fault;" execute_sql('postgres', create_fault_query) reset_fault_query = "SELECT gp_inject_fault_infinite('all', 'reset', dbid) FROM gp_segment_configuration WHERE status='u';" execute_sql('postgres', reset_fault_query)