def _db_dropped(): rc, out = ssh.run_command( 'systemctl restart {}-postgresql'.format(db.scl_name()), timeout=60) assert rc == 0, "Failed to restart postgres service: {}".format(out) ssh.run_command('dropdb vmdb_production', timeout=15) rc, out = ssh.run_command("psql -l | grep vmdb_production | wc -l", timeout=15) return rc == 0
def test_service_enabled(ssh_client, service): """Verifies if key services are configured to start on boot up""" if service == 'postgresql': service = '{}-postgresql'.format(db.scl_name()) if pytest.store.current_appliance.os_version >= '7': cmd = 'systemctl is-enabled {}'.format(service) else: cmd = 'chkconfig | grep {} | grep -q "5:on"'.format(service) result = ssh_client.run_command(cmd) assert result.rc == 0, result.output
# copy scripts run_command("cp " + options.scripts + " /var/www/miq/vmdb/") # changedir and untar scripts run_command("cd /var/www/miq/vmdb/;tar xvf " + options.scripts) # stop evm process run_command('service evmserverd stop') # check pg connections and execute restore script psql_output = run_command('psql -d vmdb_production -U root -c ' + '"SELECT count(*) from pg_stat_activity"') count = psql_output.split("\n")[2].strip() if count > 2: logger.info("Too many postgres threads(" + str(count) + ")... restarting") run_command("service {}-postgresql restart".format(db.scl_name())) time.sleep(60) run_command( "cd /var/www/miq/vmdb/backup_and_restore/;./miq_vmdb_background_restore " + options.backupfile + " > /tmp/restore.out 2>&1") run_command("cat /tmp/restore.out") logger.info('Restore completed successfully') # if states relation exists then truncate table psql_output = run_command( 'psql -d vmdb_production -U root -c ' + '"SELECT EXISTS(SELECT 1 FROM information_schema.tables WHERE table_name = \'states\')" ' ) table_output = psql_output.split("\n")[2].strip() if "t" in table_output: out = run_command(
def start_db_process(address): with get_ssh_client(address) as ssh: assert ssh.run_command('service {}-postgresql start'.format(db.scl_name()))[0] == 0,\ "Could not start postgres process on {}".format(address)
# copy scripts run_command("cp " + options.scripts + " /var/www/miq/vmdb/") # changedir and untar scripts run_command("cd /var/www/miq/vmdb/;tar xvf " + options.scripts) # stop evm process run_command('service evmserverd stop') # check pg connections and execute restore script psql_output = run_command('psql -d vmdb_production -U root -c ' + '"SELECT count(*) from pg_stat_activity"') count = psql_output.split("\n")[2].strip() if count > 2: logger.info("Too many postgres threads(" + str(count) + ")... restarting") run_command("service {}-postgresql restart".format(db.scl_name())) time.sleep(60) run_command("cd /var/www/miq/vmdb/backup_and_restore/;./miq_vmdb_background_restore " + options.backupfile + " > /tmp/restore.out 2>&1") run_command("cat /tmp/restore.out") logger.info('Restore completed successfully') # if states relation exists then truncate table psql_output = run_command('psql -d vmdb_production -U root -c ' + '"SELECT EXISTS(SELECT 1 FROM information_schema.tables WHERE table_name = \'states\')" ') table_output = psql_output.split("\n")[2].strip() if "t" in table_output: out = run_command('psql -d vmdb_production -U root -c "truncate table states"') else: logger.debug('Relation states does not exists')
def stop_db_process(address): with get_ssh_client(address) as ssh: assert ( ssh.run_command("service {}-postgresql stop".format(db.scl_name()))[0] == 0 ), "Could not stop postgres process on {}".format(address)