diff --git a/SunGridEngine/SgeConfig.py b/SunGridEngine/SgeConfig.py index a37a6d8..fcf350b 100755 --- a/SunGridEngine/SgeConfig.py +++ b/SunGridEngine/SgeConfig.py @@ -13,6 +13,8 @@ class SgeConfig: def getAttr( self, strAttrName ): return self.m_attrs[ strAttrName ] def setAttr( self, strAttrName, strAttrValue ): + assert isinstance(strAttrName, str) + assert isinstance(strAttrValue, str) self.m_attrs[ strAttrName ] = strAttrValue def loadFromSgeFormat1String( self, strSgeConfigString ): """ @@ -43,9 +45,10 @@ class SgeConfig: # put multiline attributes on one line strSgeConfigString = re.sub(r"\\\n", "", strSgeConfigString) for strAttrDef in strSgeConfigString.split("\n"): - #print strAttrDef + # print("strAttrDef=%s" % strAttrDef) if len(strAttrDef) != 0: matchObj = re.match( "^(?P[^\s]+)[ ]+(?P[^\s].*)$", strAttrDef ) + assert matchObj is not None #print( '%s = %s\n' % (matchObj.group("attrName"), matchObj.group("attrValue") ) ) self.m_attrs[ matchObj.group("attrName") ] = matchObj.group("attrValue") @@ -76,8 +79,50 @@ class SgeConfig: strResult = "" for (k,v) in self.m_attrs.items(): #print "%s %s" % (k,v) - strResult += "%s %s\n" % (k,v) - #print strSgeConfigString + # if the attribute's value is a list of comma separated strings, make sure there are no spaces after the commas, otherwise the value is not properly interpreted when read back into sge + # for example if the user sets the value of administrator_mail (using qconf -mconf global) to "alice@univ-rennes1.fr, bob@univ-rennes1.fr", then the next call to qconf -sconf global will show a wrong value for administrator_mail, as shown below: + # pag_cmd none + # administrator_mail alice@univ-rennes1.fr, + # token_extend_time none + + # it's even worse, as it messes with the whole config, putting unwanted attributes in the reporting_params attribute. In short, inputting commas followed by spaces seems to confuse sge.... + + # the tests below show that administrator_mail can only take a value, which can be a separator separated list, in which a separator is either : + # - separator_form_a: a comma character (no spaces after) + # - separator_form_b: a comma character, followed by any number of spaces, then a backslash, then \n + + # because we remove carriage returns in our values, the only storage option is separator_form_a + + # administrator_mail alice@univ-rennes1.fr + # -> ok + + # administrator_mail alice@univ-rennes1.fr,bob@univ-rennes1.fr + # -> ok + + # administrator_mail alice@univ-rennes1.fr, bob@univ-rennes1.fr + # -> messes up + + # administrator_mail alice@univ-rennes1.fr, \ + # bob@univ-rennes1.fr + # -> ok + + # administrator_mail alice@univ-rennes1.fr,bob@univ-rennes1.fr, \ + # bob2@univ-rennes1.fr + # -> ok + + # administrator_mail alice@univ-rennes1.fr,bob@univ-rennes1.fr, \ + # bob2@univ-rennes1.fr + # -> ok + + # administrator_mail alice@univ-rennes1.fr,bob@univ-rennes1.fr \ + # bob2@univ-rennes1.fr + # -> error + # root@physix-master:~# qconf -Mconf /tmp/global + # only a single value is allowed for configuration attribute "administrator_mail" + + cleaned_value = re.sub(',\s*', ',', v) + strResult += "%s %s\n" % (k, cleaned_value) + # print("strResult=%s" % strResult) return strResult def asFormat2String( self ): strResult = ""