Skip to content

Commit

Permalink
Add support for multiple voms hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
darcato committed Mar 28, 2024
1 parent 90a402b commit 8c48102
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
34 changes: 34 additions & 0 deletions lib/VOMSLibrary.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
from datetime import datetime,timedelta,time
import os, glob


openssl_date_format = "%b %d %H:%M:%S %Y %Z"
Expand Down Expand Up @@ -43,6 +44,30 @@ def compare_dates(self, date0, date1):
else:
return 1

def parse_vomses_files(self, vomses_dirs: list = ["/etc/vomses", "~/.glite/vomses"]) -> dict:
"""Read the files in /etc/vomses and in ~/.glite/vomses, returning a dictionary with the following items:
vo: [hosts]"""

vomses_files = []
for vomses_dir in vomses_dirs:
if os.path.exists(os.path.expanduser(vomses_dir)):
vomses_files.extend(glob.glob(os.path.expanduser(os.path.join(vomses_dir,"*"))))
vomses = {}

for vomses_file in vomses_files:
try:
with open(vomses_file) as f:
for line in f:
if not line.startswith("#"):
vo, host, port = line.split()[:3]
vo = vo.strip("\"")
if vo not in vomses:
vomses[vo] = []
vomses[vo].append(host.strip("\"")+":"+port.strip("\""))
except Exception:
pass

return vomses


class DatesTest(unittest.TestCase):
Expand Down Expand Up @@ -74,5 +99,14 @@ def testDateDiff(self):
self.assertEqual(1, l.date_difference_in_seconds("Sep 15 13:04:09 2013 GMT","Sep 15 13:04:08 2013 GMT"))
self.assertEqual(0, l.date_difference_in_seconds("Sep 15 13:04:08 2013 GMT","Sep 15 13:04:08 2013 GMT"))

class VomsesTest(unittest.TestCase):
def testParseVomses(self):
l = VOMSLibrary()
vomses = l.parse_vomses_files(["../compose/assets/vomses"])
self.assertIsInstance(vomses, dict)
self.assertDictEqual(vomses, {"test.vo": ["voms-dev.cloud.cnaf.infn.it:15004"],
"vo.0": ["voms.test.example:15000"],
"vo.1": ["voms.test.example:15001"]})

if __name__ == '__main__':
unittest.main()
4 changes: 4 additions & 0 deletions lib/vomslib.robot
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,7 @@ Myproxy destroy [Arguments] @{params}
${output} Execute and Check Success myproxy-destroy -s ${myproxy_server} ${options}
RETURN ${output}

Get Vomses [Arguments] ${vo}=${vo1}
${vomses}= Parse Vomses Files
${output}= Get From Dictionary ${vomses} ${vo} Create List
RETURN ${output}
3 changes: 2 additions & 1 deletion tests/clients/info/tests.robot
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ See if voms --uri works
[Tags] remote legacy
Create voms proxy
${output} = Get proxy info -uri
Should Match Regexp ${output} ${vo1_host}:\\d+
${vomses_hosts} = Get Vomses
Should Contain ${vomses_hosts} ${output}
[Teardown] Stop using certificate

See if voms --serial works
Expand Down

0 comments on commit 8c48102

Please sign in to comment.