forked from indigo-dc/orchestrator-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
211 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# | ||
# IM - Infrastructure Manager Dashboard | ||
# Copyright (C) 2020 - GRyCAP - Universitat Politecnica de Valencia | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
"""Function to get sites info from https://github.com/EGI-Federation/fedcloud-catchall-operations/tree/main/sites.""" | ||
import requests | ||
import yaml | ||
from urllib.parse import urlparse | ||
|
||
|
||
GIT_REPO = "EGI-Federation/fedcloud-catchall-operations" | ||
GIT_BRANCH = "main" | ||
REQUESTS_TIMEOUT = 10 | ||
RAW_URL = "https://raw.githubusercontent.com/%s/%s/sites/" % (GIT_REPO, GIT_BRANCH) | ||
SITES_CACHE = {} | ||
|
||
|
||
def get_sites(vo=None): | ||
global SITES_CACHE | ||
sites = {} | ||
url = "https://api.github.com/repos/%s/contents/sites?branch%s" % (GIT_REPO, GIT_BRANCH) | ||
headers = {"Accept": "application/vnd.github+json", | ||
"X-GitHub-Api-Version": "2022-11-28"} | ||
resp = requests.get(url, headers=headers, timeout=REQUESTS_TIMEOUT) | ||
if resp.status_code == 200: | ||
for file_info in resp.json(): | ||
if file_info["type"] == "file": | ||
name = file_info["name"] | ||
if (name in SITES_CACHE and SITES_CACHE[name] and SITES_CACHE[name]["sha"] == file_info["sha"] and | ||
SITES_CACHE[name]["size"] == file_info["size"]): | ||
site_info = SITES_CACHE[name]["info"] | ||
else: | ||
site_info = get_site_info(name) | ||
SITES_CACHE[name] = {"sha": file_info["sha"], | ||
"size": file_info["size"], | ||
"info": site_info} | ||
if vo is None or vo in site_info["vos"]: | ||
sites[site_info["name"]] = site_info | ||
|
||
return sites | ||
|
||
|
||
def get_site_info(site_name): | ||
site_file = "%s%s" % (RAW_URL, site_name if site_name.endswith(".yaml") else site_name + ".yaml") | ||
resp = requests.get(site_file, timeout=REQUESTS_TIMEOUT) | ||
if resp.status_code == 200: | ||
site_info = yaml.safe_load(resp.text) | ||
site_info["gocdb"] | ||
site_info["endpoint"] | ||
vos = {} | ||
for vo in site_info["vos"]: | ||
vos[vo["name"]] = vo["auth"]["project_id"] | ||
|
||
url = urlparse(site_info["endpoint"]) | ||
return {"url": "%s://%s" % url[0:2], | ||
"state": "", | ||
"id": site_info["gocdb"], | ||
"name": site_info["gocdb"], | ||
"vos": vos} | ||
|
||
|
||
def get_images(site_id, vo): | ||
return [] | ||
|
||
|
||
def get_project_ids(site_name): | ||
site_info = get_site_info(site_name) | ||
return site_info["vos"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#! /usr/bin/env python | ||
# | ||
# IM - Infrastructure Manager | ||
# Copyright (C) 2011 - GRyCAP - Universitat Politecnica de Valencia | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import unittest | ||
import os | ||
import xmltodict | ||
|
||
from app import egi_catch_all | ||
from mock import patch, MagicMock | ||
from urllib.parse import urlparse | ||
|
||
|
||
class TestEGICatchAll(unittest.TestCase): | ||
"""Class to test the EGI Catch all functions.""" | ||
|
||
@staticmethod | ||
def requests_response(url, **kwargs): | ||
resp = MagicMock() | ||
parts = urlparse(url) | ||
url = parts[2] | ||
|
||
resp.status_code = 404 | ||
resp.ok = False | ||
|
||
if url == "/repos/EGI-Federation/fedcloud-catchall-operations/contents/sites": | ||
resp.status_code = 200 | ||
resp.json.return_value = [{ | ||
"name": "UPV-GRyCAP.yaml", | ||
"sha": "f9688bafd4d5645611b2905cdffd8e1b9cd1676a", | ||
"size": 390, | ||
"type": "file", | ||
}] | ||
elif url == "/EGI-Federation/fedcloud-catchall-operations/main/sites/UPV-GRyCAP.yaml": | ||
resp.status_code = 200 | ||
resp.text = """--- | ||
gocdb: UPV-GRyCAP | ||
endpoint: https://menoscloud.i3m.upv.es:5000/v3 | ||
vos: | ||
- name: eosc-synergy.eu | ||
auth: | ||
project_id: 6f84e31391024330b16d29d6ccd26932 | ||
- name: fedcloud.egi.eu | ||
auth: | ||
project_id: db929e9034f04d1698c1a0d58283366e | ||
- name: ops | ||
auth: | ||
project_id: 292568ead7454709a17f19189d5a840a | ||
- name: saps-vo.i3m.upv.es | ||
auth: | ||
project_id: e7608e969cfd4f49907cff17d1774898""" | ||
|
||
return resp | ||
|
||
@patch('requests.get') | ||
def test_get_sites(self, requests): | ||
requests.side_effect = self.requests_response | ||
res = egi_catch_all.get_sites() | ||
expected = { | ||
"UPV-GRyCAP": { | ||
"id": "UPV-GRyCAP", | ||
"name": "UPV-GRyCAP", | ||
"state": "", | ||
"url": "https://menoscloud.i3m.upv.es:5000", | ||
"vos": { | ||
"eosc-synergy.eu": "6f84e31391024330b16d29d6ccd26932", | ||
"fedcloud.egi.eu": "db929e9034f04d1698c1a0d58283366e", | ||
"ops": "292568ead7454709a17f19189d5a840a", | ||
"saps-vo.i3m.upv.es": "e7608e969cfd4f49907cff17d1774898", | ||
}, | ||
} | ||
} | ||
self.assertEquals(res, expected) | ||
|
||
@patch('requests.get') | ||
def test_get_project_ids(self, requests): | ||
requests.side_effect = self.requests_response | ||
res = egi_catch_all.get_project_ids('UPV-GRyCAP') | ||
expected = { | ||
"eosc-synergy.eu": "6f84e31391024330b16d29d6ccd26932", | ||
"fedcloud.egi.eu": "db929e9034f04d1698c1a0d58283366e", | ||
"ops": "292568ead7454709a17f19189d5a840a", | ||
"saps-vo.i3m.upv.es": "e7608e969cfd4f49907cff17d1774898", | ||
} | ||
self.assertEquals(res, expected) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters