Skip to content

Commit

Permalink
Merge pull request apel#377 from Will-Cross1/374-fix-VOMS-attribute-p…
Browse files Browse the repository at this point in the history
…arser-fails

Added extra checks for fqan fields
  • Loading branch information
tofu-rocketry authored Aug 21, 2024
2 parents d202ff8 + f2f38f0 commit c41ba12
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
3 changes: 0 additions & 3 deletions apel/db/records/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ def __init__(self):
"NodeCount", "StartTime", "EndTime", "InfrastructureDescription", "InfrastructureType", "MemoryReal",
"MemoryVirtual", "ServiceLevelType", "ServiceLevel"]

# Not used in the message format, but required by the database.
# self._fqan_fields = ["VO", "VOGroup", "VORole"]

# Fields which are accepted but currently ignored.
self._ignored_fields = ["SubmitHostType", "UpdateTime"]

Expand Down
7 changes: 5 additions & 2 deletions apel/db/records/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def __init__(self):
self._datetime_fields = []
# The dictionary into which all the information goes
self._record_content = {}
# These fields need special handling as they shouldn't be inserted as
# Null into the database
self._fqan_fields = ["VO", "VOGroup", "VORole"]

def set_all(self, fielddict):
'''
Expand Down Expand Up @@ -126,8 +129,8 @@ def checked(self, name, value):
Otherwise it raises an error.
'''
try:
# Convert any null equivalents to a None object
if check_for_null(value):
# Convert null equivalents (except VOMS attributes) to None object
if name not in self._fqan_fields and check_for_null(value):
value = None
# firstly we must ensure that we do not put None
# in mandatory field
Expand Down
21 changes: 21 additions & 0 deletions test/test_blah.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,34 @@ def test_parse(self):
line1_values = {"TimeStamp": datetime.datetime(2012, 5, 20, 23, 59, 47),
"GlobalUserName":"/O=GermanGrid/OU=UniWuppertal/CN=Torsten Harenberg",
"FQAN": "/atlas/Role=production/Capability=NULL",
"VO": "atlas",
"VOGroup": "/atlas",
"VORole": "Role=production",
"CE": "cream-2-fzk.gridka.de:8443/cream-pbs-atlasXL",
"GlobalJobId": "CREAM410741480",
"LrmsId": "9575064.lrms1",
}

line2 = ('"timestamp=2012-05-20 23:59:47" '
+'"userDN=/O=GermanGrid/OU=UniWuppertal/CN=Torsten Harenberg" '
+'"userFQAN=/wlcg" '
+'"ceID=cream-2-fzk.gridka.de:8443/cream-pbs-atlasXL" '
+'"jobID=CREAM410741480" "lrmsID=9575064.lrms1" "localUser=11999"')

line2_values = {"TimeStamp": datetime.datetime(2012, 5, 20, 23, 59, 47),
"GlobalUserName":"/O=GermanGrid/OU=UniWuppertal/CN=Torsten Harenberg",
"FQAN": "/wlcg",
"VO": "wlcg",
"VOGroup": "/wlcg",
"VORole": "None",
"CE": "cream-2-fzk.gridka.de:8443/cream-pbs-atlasXL",
"GlobalJobId": "CREAM410741480",
"LrmsId": "9575064.lrms1",
}

cases = {}
cases[line1] = line1_values
cases[line2] = line2_values

for line in list(cases.keys()):

Expand Down
4 changes: 4 additions & 0 deletions test/test_parsing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def test_parse_fqan(self):
right_fqan2 = "/atlas/somethingelse/role=doer"
right_fqan3 = "/atlas/Role=production/Capability=NULL;/atlas/Role=NULL/Capability=NULL;/atlas/alarm/Role=NULL/Capability=NULL;/atlas/au/Role=NULL/Capability=NULL;/atlas/dataprep/Role=NULL/Capability=NULL;/atlas/lcg1/Role=NULL/Capability=NULL;/atlas/team/Role=NULL/Capability=NULL;/atlas/uk/Role=NULL/Capability=NULL"
right_fqan4 = "/ilc/Role=NULL/Capability=NULL"
right_fqan5 = "/wlcg"
right_fqan6 = "/wlcg/Role=pilot/Capability=NULL"

short_fqan1 = "/no/role/or/equals"
short_fqan2 = "/someorg/somegroup"
Expand All @@ -30,6 +32,8 @@ def test_parse_fqan(self):
self.assertEqual(parse_fqan(right_fqan2), ("role=doer", "/atlas/somethingelse", "atlas"))
self.assertEqual(parse_fqan(right_fqan3), ("Role=production", "/atlas", "atlas"))
self.assertEqual(parse_fqan(right_fqan4), ("Role=NULL", "/ilc", "ilc"))
self.assertEqual(parse_fqan(right_fqan5), ("None", "/wlcg", "wlcg"))
self.assertEqual(parse_fqan(right_fqan6), ("Role=pilot", "/wlcg", "wlcg"))

self.assertEqual(parse_fqan(short_fqan1), ('None', '/no/role/or/equals', 'no'))
self.assertEqual(parse_fqan(short_fqan2), ('None', '/someorg/somegroup', 'someorg'))
Expand Down

0 comments on commit c41ba12

Please sign in to comment.