def farm(request: FixtureRequest) -> Farm: if CONF.main.farm_id is None: LOG.info('Farm ID not set, create a new farm for test') test_farm = Farm.create(f'tmprev-{datetime.now().strftime("%d%m%H%M%f")}', 'Revizor farm for tests\n' f'RV_BRANCH={CONF.feature.branch}\n' f'RV_PLATFORM={CONF.feature.platform.name}\n' f'RV_DIST={CONF.feature.dist.dist}\n') CONF.main.farm_id = test_farm.id else: LOG.info(f'Farm ID is set in config, use it: {CONF.main.farm_id}') test_farm = Farm.get(CONF.main.farm_id) lib_farm.clear(test_farm) LOG.info(f'Returning test farm: {test_farm.id}') try: yield test_farm finally: failed_count = request.session.testsfailed LOG.info('Failed tests: %s' % failed_count) if (failed_count == 0 and CONF.feature.stop_farm) or (CONF.feature.stop_farm and CONF.scalr.te_id): LOG.info('Clear and stop farm...') test_farm.terminate() IMPL.farm.clear_roles(test_farm.id) if test_farm.name.startswith('tmprev'): LOG.info('Delete working temporary farm') try: LOG.info('Wait all servers in farm terminated before delete') wait_until(lib_server.farm_servers_state, args=(test_farm, 'terminated'), timeout=1800, error_text='Servers in farm not terminated too long') test_farm.destroy() except Exception as e: LOG.warning(f'Farm cannot be deleted: {str(e)}') LOG.info('Farm finalize complete')
def give_empty_farm(launched=False): if CONF.main.farm_id is None: LOG.info('Farm ID not setted, create a new farm for test') world.farm = Farm.create('tmprev-%s' % datetime.now().strftime('%d%m%H%M%f'), "Revizor farm for tests\n" "RV_BRANCH={}\n" "RV_PLATFORM={}\n" "RV_DIST={}\n".format( CONF.feature.branch, CONF.feature.platform.name, CONF.feature.dist.dist )) CONF.main.farm_id = world.farm.id else: LOG.info('Farm ID is setted in config use it: %s' % CONF.main.farm_id) world.farm = Farm.get(CONF.main.farm_id) world.farm.roles.reload() if len(world.farm.roles): LOG.info('Clear farm roles') IMPL.farm.clear_roles(world.farm.id) world.farm.vhosts.reload() for vhost in world.farm.vhosts: LOG.info('Delete vhost: %s' % vhost.name) vhost.delete() try: world.farm.domains.reload() for domain in world.farm.domains: LOG.info('Delete domain: %s' % domain.name) domain.delete() except Exception: pass if world.farm.terminated and launched: world.farm.launch() elif world.farm.running and not launched: world.farm.terminate() LOG.info('Return empty running farm: %s' % world.farm.id)