Andrew Bogott has submitted this change and it was merged.

Change subject: Flake8 on openstack, part I
......................................................................


Flake8 on openstack, part I

Change-Id: I20e7184b0cc531088a2d1efb0f8ba97f19a75a0b
---
M modules/openstack/files/kilo/virtscripts/logstat.py
1 file changed, 200 insertions(+), 198 deletions(-)

Approvals:
  Andrew Bogott: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/openstack/files/kilo/virtscripts/logstat.py 
b/modules/openstack/files/kilo/virtscripts/logstat.py
index 4337c67..ba60830 100644
--- a/modules/openstack/files/kilo/virtscripts/logstat.py
+++ b/modules/openstack/files/kilo/virtscripts/logstat.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 #####################################################################
-### THIS FILE IS MANAGED BY PUPPET
-### puppet:///modules/openstack/kilo/virtscripts/logstat.py
+# THIS FILE IS MANAGED BY PUPPET
+# puppet:///modules/openstack/kilo/virtscripts/logstat.py
 #####################################################################
 # encoding: utf-8
 """
@@ -39,224 +39,226 @@
 import sys
 import getopt
 import re
-import string
 
 help_message = '''
 Usage: logstat.py [options] file [file ...]
 options:
-\t -a SLA : specifies the SLA in milliseconds
-\t -s operation(s) : specifies which operations to compute stat for. 
-\t -o output : specifies the output file, otherwise stdout is used
-\t -r : include replicated operations
-\t -v : verbose mode
+    -a SLA : specifies the SLA in milliseconds
+    -s operation(s) : specifies which operations to compute stat for.
+    -o output : specifies the output file, otherwise stdout is used
+    -r : include replicated operations
+    -v : verbose mode
 
 '''
 
+
 class OpStat():
-       def __init__(self, type, sla):
-               self.type = type
-               self.count = long(0)
-               self.etime = long(0)
-               self.maxEtime = long(0)
-               self.SLA = sla
-               self.countOverSLA = long(0)
-               self.countOver10SLA = long(0)
-               self.retEntries = long(0)
-               self.count0Entries = long(0)
-               self.count1Entry = long(0)
-               self.maxEntries = long(0)
 
-       def incEtime(self, etime):
-               self.etime += etime
-               self.count += 1
-               if self.maxEtime < etime:
-                       self.maxEtime = etime
-               if etime > self.SLA:
-                       self.countOverSLA += 1
-               if etime > self.SLA * 10:
-                       self.countOver10SLA += 1
+    def __init__(self, type, sla):
+        self.type = type
+        self.count = long(0)
+        self.etime = long(0)
+        self.maxEtime = long(0)
+        self.SLA = sla
+        self.countOverSLA = long(0)
+        self.countOver10SLA = long(0)
+        self.retEntries = long(0)
+        self.count0Entries = long(0)
+        self.count1Entry = long(0)
+        self.maxEntries = long(0)
 
-       def incEntries(self, count):
-               self.retEntries += count
-               if self.maxEntries < count:
-                       self.maxEntries = count
-               if count == 0:
-                       self.count0Entries += 1
-               if count == 1:
-                       self.count1Entry += 1
-                       
-       def printStats(self, outfile):
-               if self.count != 0:
-                       outfile.write(self.type + ":\t" + str(self.count) + 
"\tAvg: " +
-                        str(round(float(self.etime) / float(self.count), 3)) +
-                         " ms\tMax: " + str(self.maxEtime) + " ms\t>" + 
str(self.SLA) +"ms: " +
-                          str(self.countOverSLA) + " (" + 
str(self.countOverSLA * 100 / self.count) + "%)\t>" +
-                          str(self.SLA * 10) + "ms: " +
-                          str(self.countOver10SLA) + " (" + 
str(self.countOver10SLA * 100 / self.count) + "%)\n")
-               if self.retEntries != 0:
-                       outfile.write(self.type + ":\tReturned " + 
str(round(float(self.retEntries) / float(self.count), 1)) +
-                        " entries in average, max: " + str(self.maxEntries) + 
", none: "+ str(self.count0Entries) +
-                        ", single: "+ str(self.count1Entry) +"\n")
+    def incEtime(self, etime):
+        self.etime += etime
+        self.count += 1
+        if self.maxEtime < etime:
+            self.maxEtime = etime
+        if etime > self.SLA:
+            self.countOverSLA += 1
+        if etime > self.SLA * 10:
+            self.countOver10SLA += 1
+
+    def incEntries(self, count):
+        self.retEntries += count
+        if self.maxEntries < count:
+            self.maxEntries = count
+        if count == 0:
+            self.count0Entries += 1
+        if count == 1:
+            self.count1Entry += 1
+
+    def printStats(self, outfile):
+        if self.count != 0:
+            outfile.write(self.type + ":\t" + str(self.count) + "\tAvg: " +
+                          str(round(float(self.etime) / float(self.count), 3)) 
+
+                          " ms\tMax: " + str(self.maxEtime) + " ms\t>" + 
str(self.SLA) + "ms: " +
+                          str(self.countOverSLA) + " (" + 
str(self.countOverSLA * 100 / self.count) + "%)\t>" +
+                          str(self.SLA * 10) + "ms: " +
+                          str(self.countOver10SLA) + " (" + 
str(self.countOver10SLA * 100 / self.count) + "%)\n")
+        if self.retEntries != 0:
+            outfile.write(self.type + ":\tReturned " + 
str(round(float(self.retEntries) / float(self.count), 1)) +
+                          " entries in average, max: " + str(self.maxEntries) 
+ ", none: " + str(self.count0Entries) +
+                          ", single: " + str(self.count1Entry) + "\n")
+
 
 class Usage(Exception):
-       def __init__(self, msg):
-               self.msg = msg
+
+    def __init__(self, msg):
+        self.msg = msg
 
 
 def main(argv=None):
-       output = ""
-       ops= ""
-       includeReplOps = False
-       sla = 100
-       doSearch = True
-       doAdd = True
-       doBind = True
-       doCompare = True
-       doDelete = True
-       doExtended = True
-       doModify = True
-       doModDN = True
-    
-       IDs = {}
-       if argv is None:
-               argv = sys.argv
-       try:
-               try:
-                       opts, args = getopt.getopt(argv[1:], "a:ho:rs:v", 
["help", "output="])
-               except getopt.error, msg:
-                       raise Usage(msg)
+    output = ""
+    ops = ""
+    includeReplOps = False
+    sla = 100
+    doSearch = True
+    doAdd = True
+    doBind = True
+    doCompare = True
+    doDelete = True
+    doExtended = True
+    doModify = True
+    doModDN = True
 
-               # option processing
-               for option, value in opts:
-                       if option == "-v":
-                               verbose = True
-                       if option == "-r":
-                               includeReplOps = True
-                       if option in ("-h", "--help"):
-                               raise Usage(help_message)
-                       if option in ("-o", "--output"):
-                               output = value
-                       if option in ("-s", "--stats"):
-                               ops = value
-                       if option in ("-a", "--agreement"):
-                               sla = int(value)
-                               
-       except Usage, err:
-               print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + 
str(err.msg)
-               print >> sys.stderr, "\t for help use --help"
-               return 2
+    IDs = {}
+    if argv is None:
+        argv = sys.argv
+    try:
+        try:
+            opts, args = getopt.getopt(argv[1:], "a:ho:rs:v", ["help", 
"output="])
+        except getopt.error as msg:
+            raise Usage(msg)
 
-       if output != "":
-               try:
-                       outfile = open(output, "w")
-               except Usage, err:
-                       print >> sys.stderr, "Can't open output file: " + 
str(err.msg)
-       else:
-               outfile = sys.stdout
+        # option processing
+        for option, value in opts:
+            if option == "-v":
+                verbose = True
+            if option == "-r":
+                includeReplOps = True
+            if option in ("-h", "--help"):
+                raise Usage(help_message)
+            if option in ("-o", "--output"):
+                output = value
+            if option in ("-s", "--stats"):
+                ops = value
+            if option in ("-a", "--agreement"):
+                sla = int(value)
 
-       if ops != "":
-               doSearch = False
-               doAdd = False
-               doBind = False
-               doCompare = False
-               doDelete = False
-               doExtended = False
-               doModify = False
-               doModDN = False
-               opers = ops.split(',')
-               for op in opers:
-                       if op == "Search":
-                               doSearch = True
-                               continue;
-                       if op == "Add":
-                               doAdd = True
-                               continue
-                       if op == "Bind":
-                               doBind = True
-                               continue
-                       if op == "Compare":
-                               doCompare = True
-                               continue
-                       if op == "Delete":
-                               doDelete = True
-                               continue
-                       if op == "Extended":
-                               doExtended = True
-                               continue
-                       if op == "Modify":
-                               doModify = True
-                               continue
-                       if op == "ModDN":
-                               doModDN = True
-                               continue
-                       print >> sys.stderr, "Invalid op name in stats: " + op 
+", ignored"
+    except Usage as err:
+        print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
+        print >> sys.stderr, "\t for help use --help"
+        return 2
 
-       searches = OpStat("Search", sla)
-       adds = OpStat("Add", sla)
-       binds = OpStat("Bind", sla)
-       compares = OpStat("Compare", sla)
-       deletes = OpStat("Delete", sla)
-       extops = OpStat("Extend", sla)
-       modifies = OpStat("Modify", sla)
-       moddns = OpStat("ModDN", sla)
+    if output != "":
+        try:
+            outfile = open(output, "w")
+        except Usage as err:
+            print >> sys.stderr, "Can't open output file: " + str(err.msg)
+    else:
+        outfile = sys.stdout
 
-       for logfile in args:
-               try:
-                       infile = open(logfile, "r")
-               except err:
-                       print >> sys.stderr, "Can't open file: " + str(err.msg)
+    if ops != "":
+        doSearch = False
+        doAdd = False
+        doBind = False
+        doCompare = False
+        doDelete = False
+        doExtended = False
+        doModify = False
+        doModDN = False
+        opers = ops.split(',')
+        for op in opers:
+            if op == "Search":
+                doSearch = True
+                continue
+            if op == "Add":
+                doAdd = True
+                continue
+            if op == "Bind":
+                doBind = True
+                continue
+            if op == "Compare":
+                doCompare = True
+                continue
+            if op == "Delete":
+                doDelete = True
+                continue
+            if op == "Extended":
+                doExtended = True
+                continue
+            if op == "Modify":
+                doModify = True
+                continue
+            if op == "ModDN":
+                doModDN = True
+                continue
+            print >> sys.stderr, "Invalid op name in stats: " + op + ", 
ignored"
 
+    searches = OpStat("Search", sla)
+    adds = OpStat("Add", sla)
+    binds = OpStat("Bind", sla)
+    compares = OpStat("Compare", sla)
+    deletes = OpStat("Delete", sla)
+    extops = OpStat("Extend", sla)
+    modifies = OpStat("Modify", sla)
+    moddns = OpStat("ModDN", sla)
 
-               outfile.write("processing file: "+ logfile + "\n")
-               for i in infile:
-                       if re.search(" conn=-1 ", i) and not includeReplOps:
-                               continue
-                       if doSearch and re.search("SEARCH RES", i):
-                               m = re.match(".*nentries=(\d+) etime=(\d+)", i)
-                               if m:
-                                       searches.incEtime(int(m.group(2)))
-                                       searches.incEntries(int(m.group(1)))
-                       if doAdd and re.search("ADD RES", i):
-                               m = re.match(".* etime=(\d+)", i)
-                               if m:
-                                       adds.incEtime(int(m.group(1)))
-                       if doBind and re.search("BIND RES", i):
-                               m = re.match(".* etime=(\d+)", i)
-                               if m:
-                                       binds.incEtime(int(m.group(1)))
-                       if doCompare and re.search("COMPARE RES", i):
-                               m = re.match(".* etime=(\d+)", i)
-                               if m:
-                                       compares.incEtime(int(m.group(1)))
-                       if doDelete and re.search("DELETE RES", i):
-                               m = re.match(".* etime=(\d+)", i)
-                               if m:
-                                       deletes.incEtime(int(m.group(1)))
-                       if doExtended and re.search("EXTENDED RES", i):
-                               m = re.match(".* etime=(\d+)", i)
-                               if m:
-                                       extops.incEtime(int(m.group(1)))
-                       if doModify and re.search("MODIFY RES", i):
-                               m = re.match(".* etime=(\d+)", i)
-                               if m:
-                                       modifies.incEtime(int(m.group(1)))
-                       if doModDN and re.search("MODDN RES", i):
-                               m = re.match(".* etime=(\d+)", i)
-                               if m:
-                                       moddns.incEtime(int(m.group(1)))
+    for logfile in args:
+        try:
+            infile = open(logfile, "r")
+        except err:
+            print >> sys.stderr, "Can't open file: " + str(err.msg)
 
-               # Done processing that file, lets move to next one
+        outfile.write("processing file: " + logfile + "\n")
+        for i in infile:
+            if re.search(" conn=-1 ", i) and not includeReplOps:
+                continue
+            if doSearch and re.search("SEARCH RES", i):
+                m = re.match(".*nentries=(\d+) etime=(\d+)", i)
+                if m:
+                    searches.incEtime(int(m.group(2)))
+                    searches.incEntries(int(m.group(1)))
+            if doAdd and re.search("ADD RES", i):
+                m = re.match(".* etime=(\d+)", i)
+                if m:
+                    adds.incEtime(int(m.group(1)))
+            if doBind and re.search("BIND RES", i):
+                m = re.match(".* etime=(\d+)", i)
+                if m:
+                    binds.incEtime(int(m.group(1)))
+            if doCompare and re.search("COMPARE RES", i):
+                m = re.match(".* etime=(\d+)", i)
+                if m:
+                    compares.incEtime(int(m.group(1)))
+            if doDelete and re.search("DELETE RES", i):
+                m = re.match(".* etime=(\d+)", i)
+                if m:
+                    deletes.incEtime(int(m.group(1)))
+            if doExtended and re.search("EXTENDED RES", i):
+                m = re.match(".* etime=(\d+)", i)
+                if m:
+                    extops.incEtime(int(m.group(1)))
+            if doModify and re.search("MODIFY RES", i):
+                m = re.match(".* etime=(\d+)", i)
+                if m:
+                    modifies.incEtime(int(m.group(1)))
+            if doModDN and re.search("MODDN RES", i):
+                m = re.match(".* etime=(\d+)", i)
+                if m:
+                    moddns.incEtime(int(m.group(1)))
 
-       # We're done with all files. Proceed with displaying stats
-       adds.printStats(outfile)
-       binds.printStats(outfile)
-       compares.printStats(outfile)
-       deletes.printStats(outfile)
-       extops.printStats(outfile)
-       modifies.printStats(outfile)
-       moddns.printStats(outfile)
-       searches.printStats(outfile)
-       outfile.write("Done\n")
-       outfile.close()
+        # Done processing that file, lets move to next one
+
+    # We're done with all files. Proceed with displaying stats
+    adds.printStats(outfile)
+    binds.printStats(outfile)
+    compares.printStats(outfile)
+    deletes.printStats(outfile)
+    extops.printStats(outfile)
+    modifies.printStats(outfile)
+    moddns.printStats(outfile)
+    searches.printStats(outfile)
+    outfile.write("Done\n")
+    outfile.close()
 if __name__ == "__main__":
-       sys.exit(main())
+    sys.exit(main())

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I20e7184b0cc531088a2d1efb0f8ba97f19a75a0b
Gerrit-PatchSet: 2
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Andrew Bogott <abog...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to