def __init__(self): self.hier = Hier() self.category = Category() self.dashuser = Dashuser() host = 'gnats.juniper.net' db = 'default' # username = os.getusername() ... for Linux username = getpass.getuser() #... for Windows and linux # Get a database object, which holds the metadata (field names, etc.) self.db_obj = gnats.get_database(host, db) # Get a db handle, a connection to the server self.db_handle = self.db_obj.get_handle(username, passwd='*')
''' Created on Jun 12, 2013 @author: richilb ''' import hier from hier import Hier H = Hier() # Test 1: checks the manager of user if H.manager("alex") == 'hmprabhu': print 'test for manager("alex") passed' else: print 'test for manager("alex") failed' # Test 2: checks a list of all reports if H.reports("lmandic", 0) == sorted([ 'aassadza', 'cdahm', 'kpagadala', 'ksivaraj', 'mfong', 'tbirajdar', 'tkekan', 'vkpatel', 'yishijima', 'rboileau', 'emacneil', 'etempest', 'hshanmugam', 'hstewart', 'jethridge', 'knasim', 'lbazinet', 'mqiao', 'pchen', 'ppieda', 'vasanth', 'wangh', 'rgovindarajan', 'aranpise', 'bpalaniswami', 'bselbrede', 'cna', 'manang', 'pcomstock', 'ptaravind', 'sbhagwath', 'venukonda', 'vsriram', 'angelat', 'deo', 'dmitrym', 'dvdgray', 'jessicah', 'jestin', 'jvanhorne', 'klash', 'kraj', 'ravindg', 'trix', 'tyreddy', 'ehunter', 'abstine', 'amandshahi', 'anjali', 'groeck', 'jsurya', 'marcelm', 'mguglani', 'anshukla', 'aronen', 'gvdl', 'jelliott', 'jkai', 'kshrikanth', 'sdmishra', 'stevek', 'tvenkata', 'pnh', 'pramod', 'ragreddy', 'ylu', 'gheorghiu',
''' Created on Jun 12, 2013 @author: richilb ''' import hier from hier import Hier H = Hier() # Test 1: checks the manager of user if H.manager("alex") == 'hmprabhu': print 'test for manager("alex") passed' else: print 'test for manager("alex") failed' # Test 2: checks a list of all reports if H.reports("lmandic", 0) == sorted(['aassadza', 'cdahm', 'kpagadala', 'ksivaraj', 'mfong', 'tbirajdar', 'tkekan', 'vkpatel', 'yishijima', 'rboileau', 'emacneil', 'etempest', 'hshanmugam', 'hstewart', 'jethridge', 'knasim', 'lbazinet', 'mqiao', 'pchen', 'ppieda', 'vasanth', 'wangh', 'rgovindarajan', 'aranpise', 'bpalaniswami', 'bselbrede', 'cna', 'manang', 'pcomstock', 'ptaravind', 'sbhagwath', 'venukonda', 'vsriram', 'angelat', 'deo', 'dmitrym', 'dvdgray', 'jessicah', 'jestin', 'jvanhorne', 'klash', 'kraj', 'ravindg', 'trix', 'tyreddy', 'ehunter', 'abstine', 'amandshahi', 'anjali', 'groeck', 'jsurya', 'marcelm', 'mguglani', 'anshukla', 'aronen', 'gvdl', 'jelliott', 'jkai', 'kshrikanth', 'sdmishra', 'stevek', 'tvenkata', 'pnh', 'pramod', 'ragreddy', 'ylu', 'gheorghiu', 'abarakat', 'andyle', 'carlos', 'chinh', 'ekelly', 'hiepd', 'hyan', 'jkojo', 'kazotsuka', 'kokorelis', 'kuljinder', 'mckiernan', 'mhaluza', 'barak', 'bhan', 'akroy', 'amitk', 'kartheek', 'manikandan', 'manojkumar', 'mprabhu', 'nbudoor', 'pjude', 'raghup', 'rohitj', 'amsuls', 'arjun', 'devaraj', 'kalin', 'madhusr', 'maheshkg', 'malleshi', 'nravi', 'sathikk', 'srim', 'stephend', 'gvrengan', 'ilavarasu', 'ksathish', 'kumark', 'nanmathi', 'praju', 'ranjithas', 'rrajesh', 'sabarishk', 'sendilk', 'vjanand', 'sambiger', 'vigneshwaran', 'shripad', 'sureshjd', 'velur', 'gigiguo', 'bobfan', 'henryyin', 'leanli', 'mattma', 'xinli', 'grose', 'jay', 'daman', 'bharper', 'cangus', 'cclarke', 'dlloyd', 'dougt', 'torekolee', 'estrada', 'kriss', 'acorstorphine', 'amarans', 'bjames', 'dannyt', 'dmcdowell', 'kbasi', 'ksandhu', 'mresngit', 'pgarcia', 'rharwood', 'vmathiya', 'kdubray', 'lchai', 'rwells', 'hpurewal', 'jarmstrong', 'klloyd', 'nickp', 'vjohnican', 'sbottcher', 'aouldsfiya', 'damurray', 'etwine', 'galopez', 'jpmurray', 'rlmartin', 'jmolinari', 'mlopez', 'tbaltimore', 'highstreet', 'dalebrown', 'bning', 'davidchen', 'derafshan', 'eovadia', 'aantony', 'allenyu', 'clotito', 'dsreddy', 'gchavan', 'gstovall', 'igaikwad', 'mbasha', 'mgodi', 'mshivanna', 'msrivastav', 'ndivya', 'phanin', 'richilb', 'rkunwor', 'sdsouza', 'sgodbole', 'smulyono', 'jkatinsky', 'hmprabhu', 'alex', 'hnswamy', 'ajsingh', 'bmontoya', 'deeptil', 'dtripathi', 'jeffchen', 'kishorbs', 'kniranjan', 'krajagopal', 'krvenk', 'ksharma', 'mgokhale', 'rajesha', 'ravikp', 'scmohan', 'shameer', 'skarisala', 'spaku', 'mayankr', 'ranjit', 'akashm', 'lsandip', 'pawan', 'poonams', 'rdash', 'ssammiti', 'suris', 'vhiremath', 'vishalgupta', 'siddalingesh', 'syrajendra', 'vinreddy', 'dhavnoor', 'mmazur', 'smithal', 'ssagar', 'bbanerje', 'biyer', 'ibarker', 'praveenm', 'smedanci', 'tapplegate', 'tpham', 'tquilici', 'wambold', 'daveu', 'dwolf', 'justinb', 'nraja', 'ssiano', 'tp', 'zzhao', 'kjain', 'avinod', 'amitarora', 'bkumara', 'chandru', 'jana', 'ktabrez', 'manojnayak', 'nabil', 'psarathi', 'rgumasta', 'rkdavid', 'shyamk', 'srinivds', 'viveka', 'vsudharsan', 'satishd', 'amitrao', 'bhargav', 'cpraveen', 'dvsingh', 'jithing', 'kmunna', 'mavj', 'rbadiger', 'rejithomas', 'rkrishan', 'rvivek', 'saurabg', 'silambu', 'sjindal', 'svashisht', 'tanmoyk', 'saurabhm', 'amitg', 'anandmr', 'anupraoy', 'avink', 'cskumar', 'gauravg', 'kprash', 'ksukesh', 'roraveen', 'srushtigs', 'sseth', 'swarns', 'shivayenigalla', 'abishek', 'harmeets', 'manirk', 'nsairam', 'prashr', 'singhpra', 'subram', 'vpasikanti', 'pallavi', 'arunmr', 'hant', 'amgowano', 'atchandra', 'dchuang', 'gbhavani', 'knilangekar', 'mdsouza', 'nmichraf', 'rcheh', 'rjohnst', 'sksubra', 'hlakshmi', 'jschulman', 'oansari', 'bivanic', 'anupamas', 'bdinh', 'jgiorgis', 'jsding', 'kwu', 'nguyenc', 'nnishiya', 'pingli', 'yfang', 'emccolgan', 'charliel', 'eolson', 'lovan', 'pwisdom', 'rdonle', 'wasim', 'jammyc', 'kenjim', 'qhao', 'rjnaroth', 'rocker', 'sbattu', 'jhayes', 'uchandra', 'psen', 'gkarthi', 'kaleem', 'kmani', 'msumit', 'nithyaram', 'shree', 'ssathya', 'sundararajk', 'tapanswain', 'victord', 'anishl', 'awadhn', 'bhavya', 'ddash', 'ksmanoj', 'nivethar', 'pmullapudi', 'rkishore', 'smithashan', 'sreenig', 'sweekark', 'vui', 'phil', 'pushpavally', 'rameshrn', 'adimulam', 'dhilipkr', 'jurid', 'ksanjay', 'lokeswarab', 'mchandra', 'nsimaria', 'rsankar', 'subodh', 'aanbarasan', 'ajaykc', 'ankitj', 'arus', 'asifa', 'balasank', 'dsatya', 'dtrivedi', 'ericv', 'ganeshvs', 'gnalawade', 'katharh', 'ktiwari', 'pkumarpr', 'ramas', 'ravikv', 'sgoudar', 'somasm', 'svitta', 'abhinavt', 'bijchand', 'mvivek', 'rnaren', 'svivek', 'tchittar', 'rpiyush', 'agovinde', 'akhiljha', 'arajagopal', 'babum', 'hrajendran', 'karthikeyan', 'lekshmin', 'poojag', 'ppalani', 'rajuk', 'rushabhs', 'sahubars', 'sarathg', 'surengr', 'arunad', 'ashishks', 'beena', 'ahiriadaka', 'akjha', 'jayaganesh', 'karthia', 'mwasif', 'prathapcv', 'ravisankar', 'rmaiya', 'sateeshk', 'sundarkh', 'vikashc', 'vivk', 'ckevin', 'djadhav', 'ksacca', 'amychen', 'aprabakaran', 'dlau', 'dsolis', 'htseng', 'ilum', 'jblock', 'joline', 'kpacunas', 'moina', 'slau', 'tcliu', 'mvenu', 'anildkum', 'athangaraj', 'ayuvaraj', 'cviswana', 'ihazra', 'mgsreenath', 'srimadhav', 'ssamanth', 'narayanbt', 'aarul', 'kfathima', 'manojn', 'rafikp', 'thilagavathyp', 'tvranga', 'rajis', 'sindhujha', 'smondal', 'srreddy', 'aparnar', 'aramamurthy', 'ashweta', 'asish', 'chipujar', 'eers', 'gvenkata', 'jnanesh', 'jyothin', 'kaverib', 'kevinr', 'nsonali', 'ramtsb', 'rdevulapalli', 'santoshm', 'shanbhag', 'sraju', 'vinaykants', 'sumangala', 'apreethi', 'arula', 'arunr', 'ashag', 'chandraiahp', 'karneys', 'kkalyani', 'kmeka', 'krishnar', 'lajadas', 'lohithab', 'mamallan', 'mpavan', 'msakamuri', 'pravnara', 'priyab', 'prkaruna', 'pseenivasagam', 'rajasi', 'rksathish', 'rmanju', 'rreddy', 'sathish', 'sibis', 'skmohan', 'spagadal', 'sraghavendr', 'sravilla', 'ssinduja', 'sumati', 'thangap', 'trajkumar', 'vijaygadde', 'viswanathn', 'vpendela', 'wgriffeth', 'wing', 'setember', 'seth', 'amesh', 'chitrad', 'dcc', 'gerd', 'janem', 'jduncan', 'kavi', 'mdb', 'siv', 'tlarock', 'sjg', 'thiraoka', 'akalaiah', 'austinlee', 'biddyc', 'dqiao', 'kiruba', 'leccese', 'mbiswal', 'rsunkoji', 'vikastr', 'yqiu', 'dfalak', 'jshaw', 'minchenet', 'mjsharma', 'mmitchell', 'nshook', 'rakurati', 'sjeffries', 'sonalk', 'viveksingh', 'vsatish'], key=str.lower): print 'test for reports("lmandic", 0) passed' else: print 'test for reports("lmandic", 0) failed' # Test 3: checks a list of only immmediate reports if H.reports("lmandic", 1) == sorted(['aassadza', 'angelat', 'ehunter', 'gheorghiu', 'highstreet', 'kjain', 'pallavi', 'setember', 'seth', 'sjg', 'thiraoka'], key=str.lower): print 'test for reports("lmandic", 1) passed' else: print 'test for reports("lmandic", 1) failed'
class Rule(object): # Initialize the connection string required to connect to GNATS database def __init__(self): self.hier = Hier() self.category = Category() self.dashuser = Dashuser() host = 'gnats.juniper.net' db = 'default' # username = os.getusername() ... for Linux username = getpass.getuser() #... for Windows and linux # Get a database object, which holds the metadata (field names, etc.) self.db_obj = gnats.get_database(host, db) # Get a db handle, a connection to the server self.db_handle = self.db_obj.get_handle(username, passwd='*') # build an OR query e.g.: (responsible == "user1" | responsible == "user2"...) def getORquery(self, field, userlist, op='=='): query = '' concat = '' for user in userlist: query += concat query += ''.join('(%(1)s %(2)s "%(3)s")' % { "1": field, "2": op, "3": user }) concat = ' | ' return '(%s)' % query # Using employee hierarchy build a list of all reports of a particular manager def buildUserList(self, responsible): userlist = self.hier.reports(responsible, 0) # we should also consider count of that user if he/she is a manager userlist.append(responsible) return userlist # Filter out user list to remove users which are not under JUNOS system def buildJunosUserList(self, responsible): userlist = self.hier.reports(responsible, 0) # we should also consider count of that user if he/she is a manager userlist.append(responsible) # remove those users which are not junos dashboard users userlistcopy = copy.copy(userlist) for user in userlistcopy: if user not in self.dashuser.dashuserlist: userlist.remove(user) return userlist ''' Build list of all reports for category or category alias: if islias = 1 -> generate alias list if isalias = 0 -> generate catgeory list ''' def buildCatAliasList(self, responsible, isAlias=1): aliaslist = [] userlist = self.buildUserList(responsible) for user in userlist: if isAlias == 1: alist = self.category.listAliasForUser(user) else: alist = self.category.listCategoriesForUser(user) if alist != None: for a in alist: aliaslist.append(a) # remove duplicates aliaslist = list(set(aliaslist)) return aliaslist ''' Build query as: responsible == Aliaslist & (dev-owner == "" | dev-owner == Aliaslist) & Category == Categorylist ''' def getCategoryOwnerQuery(self, responsible): aliaslist = self.buildCatAliasList(responsible) catlist = self.buildCatAliasList(responsible, 0) if len(aliaslist) > 0: return '| (%(1)s & (dev-owner == "" | %(2)s) & %(3)s)' % {"1": self.getORquery('responsible', aliaslist), \ "2": self.getORquery('dev-owner', aliaslist, '~'), \ "3": self.getORquery('category', catlist)} else: return '' # generate rule specific query e.g.: blocker == "test" def getQueryForRuleType(self, ruletype): if ruletype.lower() == 'test blocker': return '(blocker == "test")' elif ruletype.lower() == "regression": return '(attributes ~ "regression-pr")' elif ruletype.lower() == "beta blocker": return '((blocker == "beta") | ((planned-release ~ "b1" | planned-release ~ "b2" | planned-release ~ "b3") & (blocker != "")))' elif ruletype.lower() == "cl1": return '(problem-level == "1-CL1")' elif ruletype.lower() == "cl2": return '(problem-level == "2-CL2")' elif ruletype.lower() == "il1": return '(problem-level == "3-IL1")' elif ruletype.lower() == "il2": return '(problem-level == "4-IL2")' # Get the count if PRs from the PRlist that was generated def getCount(self, responsible, ruletype): try: # Run the query PRlist = self.getPRlist(responsible, ruletype) return len(PRlist) except gnats.GnatsException, err: print "Error in query: %s" % err.message return 0
class Rule(object): # Initialize the connection string required to connect to GNATS database def __init__(self): self.hier = Hier() self.category = Category() self.dashuser = Dashuser() host = 'gnats.juniper.net' db = 'default' # username = os.getusername() ... for Linux username = getpass.getuser() #... for Windows and linux # Get a database object, which holds the metadata (field names, etc.) self.db_obj = gnats.get_database(host, db) # Get a db handle, a connection to the server self.db_handle = self.db_obj.get_handle(username, passwd='*') # build an OR query e.g.: (responsible == "user1" | responsible == "user2"...) def getORquery(self, field, userlist, op = '=='): query = '' concat = '' for user in userlist: query += concat query += ''.join('(%(1)s %(2)s "%(3)s")' % {"1": field, "2": op, "3": user}) concat = ' | ' return '(%s)' % query # Using employee hierarchy build a list of all reports of a particular manager def buildUserList(self, responsible): userlist = self.hier.reports(responsible, 0) # we should also consider count of that user if he/she is a manager userlist.append(responsible) return userlist # Filter out user list to remove users which are not under JUNOS system def buildJunosUserList(self, responsible): userlist = self.hier.reports(responsible, 0) # we should also consider count of that user if he/she is a manager userlist.append(responsible) # remove those users which are not junos dashboard users userlistcopy = copy.copy(userlist) for user in userlistcopy: if user not in self.dashuser.dashuserlist: userlist.remove(user) return userlist ''' Build list of all reports for category or category alias: if islias = 1 -> generate alias list if isalias = 0 -> generate catgeory list ''' def buildCatAliasList(self, responsible, isAlias=1): aliaslist = [] userlist = self.buildUserList(responsible) for user in userlist: if isAlias == 1: alist = self.category.listAliasForUser(user) else: alist = self.category.listCategoriesForUser(user) if alist != None: for a in alist: aliaslist.append(a) # remove duplicates aliaslist = list(set(aliaslist)) return aliaslist ''' Build query as: responsible == Aliaslist & (dev-owner == "" | dev-owner == Aliaslist) & Category == Categorylist ''' def getCategoryOwnerQuery(self, responsible): aliaslist = self.buildCatAliasList(responsible) catlist = self.buildCatAliasList(responsible, 0) if len(aliaslist) > 0: return '| (%(1)s & (dev-owner == "" | %(2)s) & %(3)s)' % {"1": self.getORquery('responsible', aliaslist), \ "2": self.getORquery('dev-owner', aliaslist, '~'), \ "3": self.getORquery('category', catlist)} else: return '' # generate rule specific query e.g.: blocker == "test" def getQueryForRuleType(self, ruletype): if ruletype.lower() == 'test blocker': return '(blocker == "test")' elif ruletype.lower() == "regression": return '(attributes ~ "regression-pr")' elif ruletype.lower() == "beta blocker": return '((blocker == "beta") | ((planned-release ~ "b1" | planned-release ~ "b2" | planned-release ~ "b3") & (blocker != "")))' elif ruletype.lower() == "cl1": return '(problem-level == "1-CL1")' elif ruletype.lower() == "cl2": return '(problem-level == "2-CL2")' elif ruletype.lower() == "il1": return '(problem-level == "3-IL1")' elif ruletype.lower() == "il2": return '(problem-level == "4-IL2")' # Get the count if PRs from the PRlist that was generated def getCount(self, responsible, ruletype): try: # Run the query PRlist = self.getPRlist(responsible, ruletype) return len(PRlist) except gnats.GnatsException, err: print "Error in query: %s" % err.message return 0