{"action":"created","comment":{"url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/comments/85744203","pull_request_review_id":6437196,"id":85744203,"diff_hunk":"@@ -0,0 +1,189 @@\n+\"\"\" A computing element class that uses sudo\n+\"\"\"\n+\n+__RCSID__ = \"$Id$\"\n+\n+import os\n+import pwd\n+import stat\n+import distutils.spawn\n+\n+import DIRAC\n+\n+from DIRAC                                                  import S_OK, S_ERROR\n+\n+from DIRAC.ConfigurationSystem.Client.Config                import gConfig\n+from DIRAC.Resources.Computing.ComputingElement             import ComputingElement\n+from DIRAC.Core.Utilities.ThreadScheduler                   import gThreadScheduler\n+from DIRAC.Core.Utilities.Subprocess                        import shellCall\n+\n+MandatoryParameters = [ ]\n+\n+class SudoComputingElement( ComputingElement ):\n+\n+  mandatoryParameters = MandatoryParameters\n+\n+  #############################################################################\n+  def __init__( self, ceUniqueID ):\n+    \"\"\" Standard constructor.\n+    \"\"\"\n+    ComputingElement.__init__( self, ceUniqueID )\n+    self.submittedJobs = 0\n+\n+  #############################################################################\n+  def _addCEConfigDefaults( self ):\n+    \"\"\"Method to make sure all necessary Configuration Parameters are defined\n+    \"\"\"\n+    # First assure that any global parameters are loaded\n+    ComputingElement._addCEConfigDefaults( self )\n+    # Now Sudo CE specific ones\n+\n+  #############################################################################\n+  def submitJob( self, executableFile, proxy, dummy = None ):\n+    \"\"\" Method to submit job, overridden from super-class.\n+    \"\"\"\n+    self.log.verbose( 'Setting up proxy for payload' )\n+    result = self.writeProxyToFile( proxy )\n+    if not result['OK']:\n+      return result\n+\n+    payloadProxy = result['Value']\n+    if not 'X509_USER_PROXY' in os.environ:\n+      self.log.error( 'X509_USER_PROXY variable for pilot proxy not found in local environment' )\n+      return S_ERROR( 'X509_USER_PROXY not found' )\n+\n+    pilotProxy = os.environ['X509_USER_PROXY']\n+    self.log.info( 'Pilot proxy X509_USER_PROXY=%s' % pilotProxy )\n+\n+    # See if a fixed value has been given\n+    payloadUsername = self.ceParameters.get( 'PayloadUser' )\n+    \n+    if payloadUsername:\n+      self.log.info( 'Payload username %s from PayloadUser in ceParameters' % payloadUsername )\n+    else:\n+      # First username in the sequence to use when running payload job\n+      # If first is pltXXp00 then have pltXXp01, pltXXp02, ...\n+      try:\n+        baseUsername = self.ceParameters.get('BaseUsername')\n+        baseCounter = int( baseUsername[-2:] )\n+        self.log.info( \"Base username from BaseUsername in ceParameters : %s\" % baseUsername )\n+      except:\n+        baseUsername = os.environ['USER'] + '00p00'\n+        baseCounter  = 0\n+        self.log.info( 'Base username from $USER + 00p00 : %s' % baseUsername )\n+\n+      # Next one in the sequence\n+      payloadUsername = baseUsername[:-2] + ( '%02d' % (baseCounter + self.submittedJobs) )\n+      self.log.info( 'Payload username set to %s using jobs counter' % payloadUsername )\n+\n+    try:\n+      payloadUID = pwd.getpwnam(payloadUsername).pw_uid\n+      payloadGID = pwd.getpwnam(payloadUsername).pw_gid\n+    except:\n+      error = S_ERROR( 'User \"' + str(payloadUsername) + '\" does not exist!' )\n+      error['Value'] = ( 201, '', '' )\n+      return error\n+\n+    self.log.verbose( 'Starting process for monitoring payload proxy' )\n+    gThreadScheduler.addPeriodicTask( self.proxyCheckPeriod, self.monitorProxy,\n+                                      taskArgs = ( pilotProxy, payloadProxy, payloadUsername, payloadUID, payloadGID ),\n+                                      executions = 0, elapsedTime = 0 )\n+\n+    # Submit job\n+    self.log.info( 'Changing permissions of executable (%s) to 0755' % executableFile )\n+    try:\n+      os.chmod( os.path.abspath( executableFile ), stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH )\n+    except Exception, x:\n+      self.log.error( 'Failed to change permissions of executable to 0755 with exception', \n+                      '\\n%s' % ( x ) )\n+\n+    result = self.SudoExecute( os.path.abspath( executableFile ), payloadProxy, payloadUsername, payloadUID, payloadGID )\n+    if not result['OK']:\n+      self.log.error( 'Failed SudoExecute', result )\n+      return result\n+\n+    self.log.debug( 'Sudo CE result OK' )\n+    self.submittedJobs += 1\n+    return S_OK()\n+\n+  #############################################################################\n+  def SudoExecute( self, executableFile, payloadProxy, payloadUsername, payloadUID, payloadGID ):","path":"Resources/Computing/SudoComputingElement.py","position":110,"original_position":110,"commit_id":"0d3c717d0f6a5a96845c7771c67e35a34a3598b5","original_commit_id":"0d3c717d0f6a5a96845c7771c67e35a34a3598b5","user":{"login":"fstagni","id":785576,"avatar_url":"https://avatars.githubusercontent.com/u/785576?v=3","gravatar_id":"","url":"https://api.github.com/users/fstagni","html_url":"https://github.com/fstagni","followers_url":"https://api.github.com/users/fstagni/followers","following_url":"https://api.github.com/users/fstagni/following{/other_user}","gists_url":"https://api.github.com/users/fstagni/gists{/gist_id}","starred_url":"https://api.github.com/users/fstagni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fstagni/subscriptions","organizations_url":"https://api.github.com/users/fstagni/orgs","repos_url":"https://api.github.com/users/fstagni/repos","events_url":"https://api.github.com/users/fstagni/events{/privacy}","received_events_url":"https://api.github.com/users/fstagni/received_events","type":"User","site_admin":false},"body":"Minor, but please call this `sudoExecute`","created_at":"2016-10-31T14:05:58Z","updated_at":"2016-10-31T14:09:52Z","html_url":"https://github.com/DIRACGrid/DIRAC/pull/3157#discussion_r85744203","pull_request_url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/3157","_links":{"self":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/comments/85744203"},"html":{"href":"https://github.com/DIRACGrid/DIRAC/pull/3157#discussion_r85744203"},"pull_request":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/3157"}}},"pull_request":{"url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/3157","id":91577959,"html_url":"https://github.com/DIRACGrid/DIRAC/pull/3157","diff_url":"https://github.com/DIRACGrid/DIRAC/pull/3157.diff","patch_url":"https://github.com/DIRACGrid/DIRAC/pull/3157.patch","issue_url":"https://api.github.com/repos/DIRACGrid/DIRAC/issues/3157","number":3157,"state":"open","locked":false,"title":"SudoComputingElement.py","user":{"login":"Andrew-McNab-UK","id":4834885,"avatar_url":"https://avatars.githubusercontent.com/u/4834885?v=3","gravatar_id":"","url":"https://api.github.com/users/Andrew-McNab-UK","html_url":"https://github.com/Andrew-McNab-UK","followers_url":"https://api.github.com/users/Andrew-McNab-UK/followers","following_url":"https://api.github.com/users/Andrew-McNab-UK/following{/other_user}","gists_url":"https://api.github.com/users/Andrew-McNab-UK/gists{/gist_id}","starred_url":"https://api.github.com/users/Andrew-McNab-UK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Andrew-McNab-UK/subscriptions","organizations_url":"https://api.github.com/users/Andrew-McNab-UK/orgs","repos_url":"https://api.github.com/users/Andrew-McNab-UK/repos","events_url":"https://api.github.com/users/Andrew-McNab-UK/events{/privacy}","received_events_url":"https://api.github.com/users/Andrew-McNab-UK/received_events","type":"User","site_admin":false},"body":"This PR adds the sudoComputingElement used within VMs to run each payload as a different user. Otherwise, it operates the same as the InProcess CE. It includes checking for PayloadUser in ceParameters and uses that if set. Otherwise it uses BaseUsername plus the jobs count, or failing that a name derived from the username of the pilot plus the jobs count.","created_at":"2016-10-31T09:26:40Z","updated_at":"2016-10-31T14:09:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"06d417d8302609b315fba6c044f96c6c71d6ea3d","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/3157/commits","review_comments_url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/3157/comments","review_comment_url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/comments{/number}","comments_url":"https://api.github.com/repos/DIRACGrid/DIRAC/issues/3157/comments","statuses_url":"https://api.github.com/repos/DIRACGrid/DIRAC/statuses/0d3c717d0f6a5a96845c7771c67e35a34a3598b5","head":{"label":"Andrew-McNab-UK:patch-2","ref":"patch-2","sha":"0d3c717d0f6a5a96845c7771c67e35a34a3598b5","user":{"login":"Andrew-McNab-UK","id":4834885,"avatar_url":"https://avatars.githubusercontent.com/u/4834885?v=3","gravatar_id":"","url":"https://api.github.com/users/Andrew-McNab-UK","html_url":"https://github.com/Andrew-McNab-UK","followers_url":"https://api.github.com/users/Andrew-McNab-UK/followers","following_url":"https://api.github.com/users/Andrew-McNab-UK/following{/other_user}","gists_url":"https://api.github.com/users/Andrew-McNab-UK/gists{/gist_id}","starred_url":"https://api.github.com/users/Andrew-McNab-UK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Andrew-McNab-UK/subscriptions","organizations_url":"https://api.github.com/users/Andrew-McNab-UK/orgs","repos_url":"https://api.github.com/users/Andrew-McNab-UK/repos","events_url":"https://api.github.com/users/Andrew-McNab-UK/events{/privacy}","received_events_url":"https://api.github.com/users/Andrew-McNab-UK/received_events","type":"User","site_admin":false},"repo":{"id":44836515,"name":"DIRAC","full_name":"Andrew-McNab-UK/DIRAC","owner":{"login":"Andrew-McNab-UK","id":4834885,"avatar_url":"https://avatars.githubusercontent.com/u/4834885?v=3","gravatar_id":"","url":"https://api.github.com/users/Andrew-McNab-UK","html_url":"https://github.com/Andrew-McNab-UK","followers_url":"https://api.github.com/users/Andrew-McNab-UK/followers","following_url":"https://api.github.com/users/Andrew-McNab-UK/following{/other_user}","gists_url":"https://api.github.com/users/Andrew-McNab-UK/gists{/gist_id}","starred_url":"https://api.github.com/users/Andrew-McNab-UK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Andrew-McNab-UK/subscriptions","organizations_url":"https://api.github.com/users/Andrew-McNab-UK/orgs","repos_url":"https://api.github.com/users/Andrew-McNab-UK/repos","events_url":"https://api.github.com/users/Andrew-McNab-UK/events{/privacy}","received_events_url":"https://api.github.com/users/Andrew-McNab-UK/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Andrew-McNab-UK/DIRAC","description":"DIRAC Grid","fork":true,"url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC","forks_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/forks","keys_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/teams","hooks_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/hooks","issue_events_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/issues/events{/number}","events_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/events","assignees_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/assignees{/user}","branches_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/branches{/branch}","tags_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/tags","blobs_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/git/refs{/sha}","trees_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/statuses/{sha}","languages_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/languages","stargazers_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/stargazers","contributors_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/contributors","subscribers_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/subscribers","subscription_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/subscription","commits_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/commits{/sha}","git_commits_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/git/commits{/sha}","comments_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/comments{/number}","issue_comment_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/issues/comments{/number}","contents_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/contents/{+path}","compare_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/merges","archive_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/downloads","issues_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/issues{/number}","pulls_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/pulls{/number}","milestones_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/milestones{/number}","notifications_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/labels{/name}","releases_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/releases{/id}","deployments_url":"https://api.github.com/repos/Andrew-McNab-UK/DIRAC/deployments","created_at":"2015-10-23T20:22:14Z","updated_at":"2015-10-23T20:22:22Z","pushed_at":"2016-10-31T09:23:05Z","git_url":"git://github.com/Andrew-McNab-UK/DIRAC.git","ssh_url":"git@github.com:Andrew-McNab-UK/DIRAC.git","clone_url":"https://github.com/Andrew-McNab-UK/DIRAC.git","svn_url":"https://github.com/Andrew-McNab-UK/DIRAC","homepage":"http://diracgrid.org","size":42912,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"integration"}},"base":{"label":"DIRACGrid:rel-v6r16","ref":"rel-v6r16","sha":"43376619c5458d5d899299dba578b36a967e5346","user":{"login":"DIRACGrid","id":694842,"avatar_url":"https://avatars.githubusercontent.com/u/694842?v=3","gravatar_id":"","url":"https://api.github.com/users/DIRACGrid","html_url":"https://github.com/DIRACGrid","followers_url":"https://api.github.com/users/DIRACGrid/followers","following_url":"https://api.github.com/users/DIRACGrid/following{/other_user}","gists_url":"https://api.github.com/users/DIRACGrid/gists{/gist_id}","starred_url":"https://api.github.com/users/DIRACGrid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DIRACGrid/subscriptions","organizations_url":"https://api.github.com/users/DIRACGrid/orgs","repos_url":"https://api.github.com/users/DIRACGrid/repos","events_url":"https://api.github.com/users/DIRACGrid/events{/privacy}","received_events_url":"https://api.github.com/users/DIRACGrid/received_events","type":"Organization","site_admin":false},"repo":{"id":1576831,"name":"DIRAC","full_name":"DIRACGrid/DIRAC","owner":{"login":"DIRACGrid","id":694842,"avatar_url":"https://avatars.githubusercontent.com/u/694842?v=3","gravatar_id":"","url":"https://api.github.com/users/DIRACGrid","html_url":"https://github.com/DIRACGrid","followers_url":"https://api.github.com/users/DIRACGrid/followers","following_url":"https://api.github.com/users/DIRACGrid/following{/other_user}","gists_url":"https://api.github.com/users/DIRACGrid/gists{/gist_id}","starred_url":"https://api.github.com/users/DIRACGrid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DIRACGrid/subscriptions","organizations_url":"https://api.github.com/users/DIRACGrid/orgs","repos_url":"https://api.github.com/users/DIRACGrid/repos","events_url":"https://api.github.com/users/DIRACGrid/events{/privacy}","received_events_url":"https://api.github.com/users/DIRACGrid/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DIRACGrid/DIRAC","description":"DIRAC Grid","fork":false,"url":"https://api.github.com/repos/DIRACGrid/DIRAC","forks_url":"https://api.github.com/repos/DIRACGrid/DIRAC/forks","keys_url":"https://api.github.com/repos/DIRACGrid/DIRAC/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DIRACGrid/DIRAC/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DIRACGrid/DIRAC/teams","hooks_url":"https://api.github.com/repos/DIRACGrid/DIRAC/hooks","issue_events_url":"https://api.github.com/repos/DIRACGrid/DIRAC/issues/events{/number}","events_url":"https://api.github.com/repos/DIRACGrid/DIRAC/events","assignees_url":"https://api.github.com/repos/DIRACGrid/DIRAC/assignees{/user}","branches_url":"https://api.github.com/repos/DIRACGrid/DIRAC/branches{/branch}","tags_url":"https://api.github.com/repos/DIRACGrid/DIRAC/tags","blobs_url":"https://api.github.com/repos/DIRACGrid/DIRAC/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DIRACGrid/DIRAC/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DIRACGrid/DIRAC/git/refs{/sha}","trees_url":"https://api.github.com/repos/DIRACGrid/DIRAC/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DIRACGrid/DIRAC/statuses/{sha}","languages_url":"https://api.github.com/repos/DIRACGrid/DIRAC/languages","stargazers_url":"https://api.github.com/repos/DIRACGrid/DIRAC/stargazers","contributors_url":"https://api.github.com/repos/DIRACGrid/DIRAC/contributors","subscribers_url":"https://api.github.com/repos/DIRACGrid/DIRAC/subscribers","subscription_url":"https://api.github.com/repos/DIRACGrid/DIRAC/subscription","commits_url":"https://api.github.com/repos/DIRACGrid/DIRAC/commits{/sha}","git_commits_url":"https://api.github.com/repos/DIRACGrid/DIRAC/git/commits{/sha}","comments_url":"https://api.github.com/repos/DIRACGrid/DIRAC/comments{/number}","issue_comment_url":"https://api.github.com/repos/DIRACGrid/DIRAC/issues/comments{/number}","contents_url":"https://api.github.com/repos/DIRACGrid/DIRAC/contents/{+path}","compare_url":"https://api.github.com/repos/DIRACGrid/DIRAC/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DIRACGrid/DIRAC/merges","archive_url":"https://api.github.com/repos/DIRACGrid/DIRAC/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DIRACGrid/DIRAC/downloads","issues_url":"https://api.github.com/repos/DIRACGrid/DIRAC/issues{/number}","pulls_url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls{/number}","milestones_url":"https://api.github.com/repos/DIRACGrid/DIRAC/milestones{/number}","notifications_url":"https://api.github.com/repos/DIRACGrid/DIRAC/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DIRACGrid/DIRAC/labels{/name}","releases_url":"https://api.github.com/repos/DIRACGrid/DIRAC/releases{/id}","deployments_url":"https://api.github.com/repos/DIRACGrid/DIRAC/deployments","created_at":"2011-04-06T11:47:53Z","updated_at":"2016-10-24T10:57:22Z","pushed_at":"2016-10-31T10:53:37Z","git_url":"git://github.com/DIRACGrid/DIRAC.git","ssh_url":"git@github.com:DIRACGrid/DIRAC.git","clone_url":"https://github.com/DIRACGrid/DIRAC.git","svn_url":"https://github.com/DIRACGrid/DIRAC","homepage":"http://diracgrid.org","size":62397,"stargazers_count":53,"watchers_count":53,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":97,"mirror_url":null,"open_issues_count":102,"forks":97,"open_issues":102,"watchers":53,"default_branch":"integration"}},"_links":{"self":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/3157"},"html":{"href":"https://github.com/DIRACGrid/DIRAC/pull/3157"},"issue":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/issues/3157"},"comments":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/issues/3157/comments"},"review_comments":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/3157/comments"},"review_comment":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/3157/commits"},"statuses":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/statuses/0d3c717d0f6a5a96845c7771c67e35a34a3598b5"}}}}
{"actor":{"display_login":"fstagni"}}