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 having_a_running_server(step): world.farm = Farm.get(CONF.main.farm_id) world.server = None for server in world.farm.servers: if server.status == ServerStatus.RUNNING: world.server = server break world.assert_not_exist(world.server, 'Not see running server')
def having_a_stopped_farm(step): """Clear all roles from farm and stop farm""" world.farm = Farm.get(CONF.main.farm_id) IMPL.farm.clear_roles(world.farm.id) LOG.info('Clear farm') if world.farm.running: LOG.info('Terminate farm %s' % world.farm.id) world.farm.terminate()
def having_a_stopped_farm(step): """Clear all roles from farm and stop farm""" world.farm = Farm.get(CONF.main.farm_id) IMPL.farm.clear_roles(world.farm.id) LOG.info('Clear farm') if world.farm.running: LOG.info('Terminate farm %s' % world.farm.id) world.farm.terminate()
def give_empty_running_farm(): farm_id = os.environ.get('RV_FARM_ID', CONF.main.farm_id) world.farm = Farm.get(farm_id) world.farm.roles.reload() if len(world.farm.roles): IMPL.farm.clear_roles(world.farm.id) world.farm.vhosts.reload() world.farm.domains.reload() for vhost in world.farm.vhosts: LOG.info('Delete vhost: %s' % vhost.name) vhost.delete() for domain in world.farm.domains: LOG.info('Delete domain: %s' % domain.name) domain.delete() if world.farm.terminated: world.farm.launch() LOG.info('Return empty running farm: %s' % world.farm.id)
def give_empty_running_farm(): farm_id = os.environ.get('RV_FARM_ID', CONF.main.farm_id) world.farm = Farm.get(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: world.farm.launch() LOG.info('Return empty running farm: %s' % world.farm.id)
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)
def get_farm_state(state): world.farm = Farm.get(world.farm.id) if world.farm.status == state: return True else: raise AssertionError('Farm is Not in %s state' % state)
def get_farm_state(farm: Farm, state: str): farm = Farm.get(farm.id) if farm.status == state: return True else: raise AssertionError('Farm is Not in %s state' % state)