From d74250f07c4af96da41c0fbd2138a091497871cd Mon Sep 17 00:00:00 2001 From: Enol Fernandez Date: Wed, 3 Jan 2024 15:02:24 +0000 Subject: [PATCH 1/4] Allow multiple VOs in a single tenant --- .../cloud_info_catchall/share_discovery.py | 14 ++++++-------- .../cloud_info_catchall/test_share_discovery.py | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/cloud-info/cloud_info_catchall/share_discovery.py b/cloud-info/cloud_info_catchall/share_discovery.py index 3bd5b59e..cbdfd05e 100644 --- a/cloud-info/cloud_info_catchall/share_discovery.py +++ b/cloud-info/cloud_info_catchall/share_discovery.py @@ -18,20 +18,20 @@ def __init__(self, config, secret): def build_share(self, project, access_token): return {"auth": {"project_id": project["id"]}} - def get_project_vo(self, project): + def get_project_vos(self, project): if not project.get("enabled", False): logging.warning( f"Discarding project {project['name']} as it is not enabled" ) return None - vo = project.get("egi.VO", None) + vo = project.get("egi.VO", "") if not vo: - vo = project.get("VO", None) + vo = project.get("VO", "") if not vo: logging.warning( f"Discarding project {project['name']} as it does not have VO property" ) - return vo + return vo.split(",") def get_token_shares(self): access_token = self.get_token() @@ -47,10 +47,8 @@ def get_token_shares(self): return shares projects = fedcli.get_projects_from_single_site(self.auth_url, token) for p in projects: - vo = self.get_project_vo(p) - if not vo: - continue - shares[vo] = self.build_share(p, access_token) + for vo in self.get_project_vos(p): + shares[vo.strip()] = self.build_share(p, access_token) self.config_shares(shares, access_token) return shares diff --git a/cloud-info/cloud_info_catchall/test_share_discovery.py b/cloud-info/cloud_info_catchall/test_share_discovery.py index 64cec439..667c4d6a 100644 --- a/cloud-info/cloud_info_catchall/test_share_discovery.py +++ b/cloud-info/cloud_info_catchall/test_share_discovery.py @@ -31,7 +31,7 @@ def test_get_project_vo_disabled(self): "name": "foo.eu", "VO": "foo", } - self.assertEqual(self.discoverer.get_project_vo(p), None) + self.assertEqual(self.discoverer.get_project_vos(p), None) def test_get_project_vo_egi_property(self): p = { @@ -40,7 +40,7 @@ def test_get_project_vo_egi_property(self): "VO": "bar", "egi.VO": "foo", } - self.assertEqual(self.discoverer.get_project_vo(p), "foo") + self.assertEqual(self.discoverer.get_project_vos(p), ["foo"]) def test_get_project_vo_property(self): p = { @@ -48,14 +48,22 @@ def test_get_project_vo_property(self): "name": "foo.eu", "VO": "bar", } - self.assertEqual(self.discoverer.get_project_vo(p), "bar") + self.assertEqual(self.discoverer.get_project_vos(p), ["bar"]) def test_get_project_no_vo_property(self): p = { "enabled": True, "name": "foo.eu", } - self.assertEqual(self.discoverer.get_project_vo(p), None) + self.assertEqual(self.discoverer.get_project_vos(p), None) + + def test_get_project_multiple_vo_property(self): + p = { + "enabled": True, + "name": "foo.eu", + "egi.VO": "foo,bar" + } + self.assertEqual(self.discoverer.get_project_vos(p), ["foo", "bar"]) @patch("fedcloudclient.endpoint.get_projects_from_single_site") @patch("fedcloudclient.endpoint.retrieve_unscoped_token") From fd688495e26ca83e20a051a51dab726a4711df8e Mon Sep 17 00:00:00 2001 From: Enol Fernandez Date: Wed, 3 Jan 2024 15:13:30 +0000 Subject: [PATCH 2/4] Fix tests --- cloud-info/cloud_info_catchall/share_discovery.py | 2 +- cloud-info/cloud_info_catchall/test_share_discovery.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cloud-info/cloud_info_catchall/share_discovery.py b/cloud-info/cloud_info_catchall/share_discovery.py index cbdfd05e..54c277be 100644 --- a/cloud-info/cloud_info_catchall/share_discovery.py +++ b/cloud-info/cloud_info_catchall/share_discovery.py @@ -23,7 +23,7 @@ def get_project_vos(self, project): logging.warning( f"Discarding project {project['name']} as it is not enabled" ) - return None + return [] vo = project.get("egi.VO", "") if not vo: vo = project.get("VO", "") diff --git a/cloud-info/cloud_info_catchall/test_share_discovery.py b/cloud-info/cloud_info_catchall/test_share_discovery.py index 667c4d6a..bae24835 100644 --- a/cloud-info/cloud_info_catchall/test_share_discovery.py +++ b/cloud-info/cloud_info_catchall/test_share_discovery.py @@ -31,7 +31,7 @@ def test_get_project_vo_disabled(self): "name": "foo.eu", "VO": "foo", } - self.assertEqual(self.discoverer.get_project_vos(p), None) + self.assertEqual(self.discoverer.get_project_vos(p), []) def test_get_project_vo_egi_property(self): p = { @@ -55,7 +55,7 @@ def test_get_project_no_vo_property(self): "enabled": True, "name": "foo.eu", } - self.assertEqual(self.discoverer.get_project_vos(p), None) + self.assertEqual(self.discoverer.get_project_vos(p), []) def test_get_project_multiple_vo_property(self): p = { From 7aa66f544568c49763e7f01aa4b7fa021fcd1ebc Mon Sep 17 00:00:00 2001 From: Enol Fernandez Date: Wed, 3 Jan 2024 15:14:16 +0000 Subject: [PATCH 3/4] Black --- cloud-info/cloud_info_catchall/test_share_discovery.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cloud-info/cloud_info_catchall/test_share_discovery.py b/cloud-info/cloud_info_catchall/test_share_discovery.py index bae24835..990fe881 100644 --- a/cloud-info/cloud_info_catchall/test_share_discovery.py +++ b/cloud-info/cloud_info_catchall/test_share_discovery.py @@ -58,11 +58,7 @@ def test_get_project_no_vo_property(self): self.assertEqual(self.discoverer.get_project_vos(p), []) def test_get_project_multiple_vo_property(self): - p = { - "enabled": True, - "name": "foo.eu", - "egi.VO": "foo,bar" - } + p = {"enabled": True, "name": "foo.eu", "egi.VO": "foo,bar"} self.assertEqual(self.discoverer.get_project_vos(p), ["foo", "bar"]) @patch("fedcloudclient.endpoint.get_projects_from_single_site") From fa3ac4b0d51d8396e3663af291bafb3605dbdcd0 Mon Sep 17 00:00:00 2001 From: Enol Fernandez Date: Wed, 3 Jan 2024 15:17:59 +0000 Subject: [PATCH 4/4] More test fixing --- cloud-info/cloud_info_catchall/share_discovery.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cloud-info/cloud_info_catchall/share_discovery.py b/cloud-info/cloud_info_catchall/share_discovery.py index 54c277be..e9eb8b8f 100644 --- a/cloud-info/cloud_info_catchall/share_discovery.py +++ b/cloud-info/cloud_info_catchall/share_discovery.py @@ -24,13 +24,14 @@ def get_project_vos(self, project): f"Discarding project {project['name']} as it is not enabled" ) return [] - vo = project.get("egi.VO", "") + vo = project.get("egi.VO", None) if not vo: - vo = project.get("VO", "") + vo = project.get("VO", None) if not vo: logging.warning( f"Discarding project {project['name']} as it does not have VO property" ) + return [] return vo.split(",") def get_token_shares(self):