[MediaWiki-commits] [Gerrit] labs/toollabs[master]: Improve error message of become

2017-10-04 Thread Mridubhatnagar (Code Review)
Mridubhatnagar has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/382200 )

Change subject: Improve error message of become
..

Improve error message of become

To change to the tool user command
become  is run. As of now,
when toolname does not start with
prefix "tools. " or home directory for
the tool is not present. Error message
"become: no such tool" is returned.
This patch makes the error message
precise and specific. When the name of
the tool does not start with "tools. "
message "A valid toolname must start
with "tools. " is returned. And if
home directory is not created. Then
error message would be "No home
directory for  is
created"

Bug: T149511
Change-Id: I70caae782e6015ae5477ad1d539715138b942df1
---
M misctools/become
1 file changed, 6 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/labs/toollabs 
refs/changes/00/382200/1

diff --git a/misctools/become b/misctools/become
index c4cd3f6..05e4f7e 100755
--- a/misctools/become
+++ b/misctools/become
@@ -24,8 +24,12 @@
 shift
 
 # Test whether the given tool exists.
-if ! id "$prefix.$tool" >/dev/null 2>&1 || ! [ -d "/data/project/$tool" ]; then
-  echo "$(basename $0): no such tool '$tool'" >&2
+if ! id "$prefix.$tool" >/dev/null 2>&1 then
+  echo "$(basename $0): A valid toolname starts with prefix tools.">&2
+  exit 1
+fi
+if ! [ -d "/data/project/$tool" ]; then
+  echo "$(basename $0): Home directory for tool '$tool' has not yet been 
created" >&2
   exit 1
 fi
 

-- 
To view, visit https://gerrit.wikimedia.org/r/382200
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I70caae782e6015ae5477ad1d539715138b942df1
Gerrit-PatchSet: 1
Gerrit-Project: labs/toollabs
Gerrit-Branch: master
Gerrit-Owner: Mridubhatnagar 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] operations...tools-webservice[master]: Explaination of what scripts/webservice does when a user run...

2017-09-28 Thread Mridubhatnagar (Code Review)
Mridubhatnagar has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/381296 )

Change subject: Explaination of what scripts/webservice does when a user runs 
it as: webservice --backend kubernetes start webservice --backend kubernetes 
stop Along with this the file contains line by line explaination of source code 
present in scripts/webservice.
..

Explaination of what scripts/webservice does when a user runs it as:
webservice --backend kubernetes start
webservice --backend kubernetes stop
Along with this the file contains line by line explaination of
source code present in scripts/webservice.

Change-Id: I537663a2c92a725eccee4448d8f772f6fc619fb3
---
A Outreachy-task.mridub.txt
1 file changed, 259 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/operations/software/tools-webservice 
refs/changes/96/381296/1

diff --git a/Outreachy-task.mridub.txt b/Outreachy-task.mridub.txt
new file mode 100644
index 000..a9b05b2
--- /dev/null
+++ b/Outreachy-task.mridub.txt
@@ -0,0 +1,259 @@
+Microtask for Outreachy Round 15
+
+*Read over the source code and try to understand what scripts/webservice does 
when a user runs it as:
+ -webservice --backend kubernetes start
+ -webservice --backend kubernetes stop
+
+
+Line 65 if __name__ == '__main__':
+   Signifies that file script/webservice must be run from the python 
interpreter directly and must not be
+   imported.
+
+Line 66 log_command_invocation('webservice', ' '.join(sys.argv))
+Function call is made to log_command_invocation(commandname, commandline)
+commandname - 'webservice'
+commandline - ' '.join(sys.argv)
+ 
+tools-webservice/toollabs/common/el.py - file path where 
log_command_invocation is defined.
+   
+log_command_invocation(commandname, commandline)- in this method username 
and hostname are setup. 
+This queries the  user by userid. 
+
+a) os.getuid() - returns the userid.(Integer)
+b) pwd.getpwd(uid) - returns (pwd_name, pw_passwd, pw_uid, pw_gid, 
pw_gecos, pw_dir, pw_shell)
+   password database entry for numeric user ID.
+   example: 
+   pw_name='mridu'(username)
+   pw_passwd = 'X'
+   pw_uid = 1000
+   pw_gid = 1000
+   pw_gecos = 'Mridu,,,'
+   pw_dir = '/home/mridu'
+   pw_shell = '/bin/bash'
+   
+   username = pwd.getpwuid(os.getuid()).pw_name  # Sets username to mridu
+   hostname = socket.getfqdn() # returns a domain name for name. Incase 
the name is empty, it is interpreted as localhost.
+   event variable is assigned a dictionary. Dictionary consists of keys 
like username, commandname, commandline, hostname, 
+   parentcommandline. 
+
+ Once the command is invoked. Logging of events takes place. And method 
log_event(schema, rev_id, wiki, event) is called.
+ 
+ schema - 'CommandInvocation'
+ rev_id - 15243810
+ wiki - 'metawiki'
+ event - event ( dictionary consisting of username,hostname,commandname, 
commandline)
+ Events are sent to the client-side Event logging endpoint. 
+ 
+ URL = 'https://meta.wikimedia.org/beacon/event'
+
+ A valid url is assigned to variable url. 
+ a)url = "%s?%s" % (URL, urllib.quote_plus(json.dumps(payload)))
+   urllib.quote_plus(string, safe='') - Replaces ' '(space) with a '+'. 
Example urllib.quote_plus(' connolly') would return '+connolly'.
+ 
+ b)urllib2.urlopen(url).read() # fetches the data present in the url. 
fetched data is string.
+ 
+Line 67 args = argparser.parse_args()
+  Argument parser parses the arguments through parse_args(). The arguments 
that are added to be parsed include 
+  type - type of webservice to start.
+  backend - Which cluster backend to use run the webservice. Ex - 
gridengine or kubernetes
+  action - Action to perform. Ex - start, stop, shell etc
+  extra_args- extra arguments are optional.
+  release -
+  Once the arguments are parsed. They can be accessed as args.type, 
args.backend, args.action, args.release etc.
+
+Line 69 tool = Tool.from_currentuser()
+Creates a tools instance from the current running user. 
+pwd_entry = pwd.getpwuid(os.geteuid())
+from_currentuser() method consists of details of the user. pwd_entry 
will have (pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir,
+pw_shell)
+Example:
+pw_name='mridu'(username)
+pw_passwd = 'X'
+pw_uid = 1000
+pw_gid = 1000
+pw_gecos = 'Mridu,,,'
+pw_dir = '/home/mridu'
+pw_shell = '/bin/bash'
+This method returns Tool.from_pwd(pwd_entry). from_pwd(pwd_entry) 
method gets called. 
+
+a) from_pwd(pwd_entry)
+   Creates tool instance from a given pwd entry.
+   If pw_name does not start with Tools.PREFIX--->'tools.'. Invalid 
tool exception will be raised. If userid is less than 50,000
+