def test_get_sites(self, get_services, appdb_call): get_services.return_value = [{"@id": "1"}] va_provider = read_file_as_string("files/va_provider.xml") appdb_call.return_value = xmltodict.parse(va_provider.replace('\n', ''))["appdb:appdb"] res = appdb.get_sites("vo.access.egi.eu") self.assertEquals(res, {'CESGA': {'url': 'https://fedcloud-osservices.egi.cesga.es:5000', 'state': '', 'id': '1', 'name': 'CESGA'}}) self.assertIn(appdb_call.call_args_list[0][0][0], ["/rest/1.0/va_providers/1", "/rest/1.0/va_providers/12355G0"])
def getsites(vo=None): res = "" appdb_sites = appdb.get_sites(vo) for site_name, site in appdb_sites.items(): if site["state"]: site["state"] = " (WARNING: %s state!)" % site["state"] res += '<option name="selectedSite" value=%s>%s%s</option>' % (site_name, site_name, site["state"]) for site_name, _ in utils.getStaticSites(vo).items(): # avoid site duplication if site_name not in appdb_sites: res += '<option name="selectedSite" value=%s>%s</option>' % (site_name, site_name) return res
def getCachedSiteList(): global SITE_LIST global LAST_UPDATE now = int(time.time()) if not SITE_LIST or now - LAST_UPDATE > g.settings.appdb_cache_timeout: try: SITE_LIST = appdb.get_sites() # in case of error do not update time LAST_UPDATE = now except Exception as ex: flash("Error retrieving site list from AppDB: %s" % ex, 'warning') SITE_LIST.update(getStaticSites()) return SITE_LIST
def getCachedSiteList(): global SITE_LIST global LAST_UPDATE global CACHE_DELAY now = int(time.time()) if not SITE_LIST or now - LAST_UPDATE > CACHE_DELAY: LAST_UPDATE = now SITE_LIST = getStaticSites() SITE_LIST.update(appdb.get_sites()) if not SITE_LIST: flash("Error retrieving site list", 'warning') return [] else: return SITE_LIST