Esempio n. 1
0
def main():

    wsOpts = WSOpts()

    parser = wsOpts.get_common_opts()

    parser.add_option("--username",
                      dest="username",
                      help="User to add to group")
    parser.add_option("--email",
                      dest="email",
                      help="New email to replace existing")
    parser.add_option("--role", dest="role", help="New role to add")

    (options, args) = parser.parse_args()

    if wsOpts.checkRequiredMissing(options, ('username', 'email'),
                                   ('username', 'role')):
        logging.error("Must specify username and either new email or new role")
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)

    configServiceClient.update_user(options.username, options.email,
                                    options.role)
def main():

    wsOpts = WSOpts()

    parser = wsOpts.get_common_opts()

    parser.add_option("--username",dest="username",help="User to print details")

    (options, args) = parser.parse_args()

    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('username',)):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)

    u=configServiceClient.user_details(options.username)
    logging.debug(u)
    for attr in u.__dict__.keys():
        if attr[0:2] == '__':
            continue
        if type(getattr(u, attr, None)) == type([]):
            logging.debug("Skipping attribute " + attr)
            # could add special handling for groups and roles
            continue
        if getattr(u, attr, None):
            print attr," \tis \t", getattr(u, attr)
Esempio n. 3
0
def main():

    wsOpts = WSOpts()

    parser = wsOpts.get_common_opts()

    parser.add_option("--username",  dest="username",  help="Username")
    parser.add_option("--first",  dest="first",  help="First name")
    parser.add_option("--last",  dest="last",  help="Last Name")
    parser.add_option("--email", dest="email",  help="Email")
    parser.add_option("--group", dest="group",  help="Local Groups to add to")
    parser.add_option("--role",  dest="role",  help="Role")
    parser.add_option("--ldap",  default=False,  dest="ldap",  action="store_true", help="LDAP or local account, specify for LDAP, default is local")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('username',)):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options);

    if options.ldap:
        logging.debug("Creating ldap account " + options.username)
        configServiceClient.create_user(options.username, ldap=True,role=options.role,groups=options.group)
    else:
        logging.debug("Creating local account " + options.username)
        configServiceClient.create_user(options.username,options.first,options.last,options.email,options.group,'coverity',role=options.role)
Esempio n. 4
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()
    parser.add_option("--file", dest="filename", help="Limit defects to those in file <filename>")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ()):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)
    defectServiceClient = DefectServiceClient(options)

    streamIdDO = configServiceClient.get_streams(options.project, options.stream)
    if not streamIdDO:
        logging.error("Not a valid stream")
        sys.exit(1)

    mergedDefectDOs = defectServiceClient.get_merged_defects(streamIdDO, statusFilter="New", filename=options.filename)
    total = mergedDefectDOs.totalNumberOfRecords
    if total < 1:
        sys.exit(1)

    mdDOs = mergedDefectDOs.mergedDefects

    for md in sorted(mdDOs):
        defectServiceClient.print_stream_defect_brief(md.cid, streamIdDO[0], options.project)
Esempio n. 5
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    parser.add_option("--check", dest="action", action="store_const", const="check", \
                                 help="Check server commit status")
    parser.add_option("--start", dest="action", action="store_const", const="start", \
                                 help="Start accepting commits if turned off")
    parser.add_option("--stop", dest="action", action="store_const", const="stop", \
                                 help="Stop new commits, wait till they finish")
    parser.add_option("--stop-now", dest="action", action="store_const", const="stop-now", \
                                 help="Stop new commits, don't wait till they finish")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('action', )):
        parser.print_help()
        sys.exit(-1)

    wsOpts.setLogging(options.debug)

    configServiceClient = ConfigServiceClient(options)

    configServiceClient.new_commits(options.action)
Esempio n. 6
0
def main():

    wsOpts = WSOpts()

    parser = wsOpts.get_common_opts()

    parser.add_option("--username",  dest="username",  help="Username")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('username',)):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options);

    logging.debug("Creating LDAP account " + options.username)
    success = configServiceClient.create_user(options.username,role=None, ldap=True)
    successConvert=False
    if not success:
        # assume the user exists as local user and switch to LDAP
        successConvert=configServiceClient.convert_to_ldap_user(options.username)
        if not successConvert:
           print "Couldn't create and couldn't convert, sorry!"
           sys.exit(1)
    subject = "Your Coverity account has been created"
    userDO = configServiceClient.get_user(options.username)
    url = "http://coverity.mongodb.com"
    if successConvert: subject = "Your Coverity account has been converted to Crowd/Jira"
    text = """
       <html><pre>
          Dear %s,
          \n
          An account has been created for you at MongoDB Coverity Instance.
          Your username is %s, same as your Crowd/Jira username.
          You can go to <a href=%s>%s</a> to securely log in using your Crowd/Jira password.
          \n
          Your Coverity Admin Team
          \n
       </pre></html>
    """
    name = str(options.username)
    body = text % (name, options.username, url, url)
    try:
        configServiceClient.send_notifications(options.username, subject, body)
    except Exception, err:
        print "Error sending user notification", str(err)
        sys.exit(1)
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()
    parser.add_option("--file",  dest="filename",  help="Limit defects to those in file <filename>")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ()):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)
    defectServiceClient = DefectServiceClient(options)

    streamIdDO = configServiceClient.get_streams(options.project,options.stream)
    if not streamIdDO:
        print "Not a valid stream"
        sys.exit(1)


    mergedDefectDOs = defectServiceClient.get_merged_defects(streamIdDO, filename=options.filename)
#Y    mergedDefectDOs = defectServiceClient.get_merged_defects(streamIdDO, statusFilter='New', filename=options.filename)
    total = mergedDefectDOs.totalNumberOfRecords
    if total < 1:
        logging.warning("No new defects")
        sys.exit(1)

    mdDOs = mergedDefectDOs.mergedDefects

    logging.debug("Got "+str(len(mdDOs))+" defects")
    for md in sorted(mdDOs):
        if md.severity in ['Major']:
            logging.debug(md)
            logging.debug(md.checkerName)
            logging.debug(md.checkerSubcategory)
            logging.debug(md.domain)
            cat = configServiceClient.get_checker_properties(md.checkerName, md.checkerSubcategory, md.domain)
            if cat:
                print cat.categoryDescription
                print cat.subcategoryLocalEffect
                print cat.subcategoryLongDescription

            defectServiceClient.print_stream_defect_occurrences(md.cid, streamIdDO[0], options.project)
            c = getattr(md, 'comment',None)
            if c:
                print "Last comment [asya]: ", c
                print ""
                print ""
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()
    parser.add_option("--filepath",dest="filepath",help="path of file to map")
    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('stream','filepath')):
        parser.print_help()
        sys.exit(-1)

    if not options.stream or not options.filepath:
        optionParser.error("Must specify both stream and filepath")

    configServiceClient = ConfigServiceClient(options)
    print configServiceClient.fileToComponent(options.filepath, options.stream)
Esempio n. 9
0
def main():

    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    parser.add_option("--cid", dest="cid", help="CID for URL")
    parser.add_option(
        "--url",
        dest="url",
        help=
        "Defect Manager URL (server/port must be used as DM label during migration)"
    )
    (options, args) = parser.parse_args()

    wsOpts.setLogging(options.debug)
    if wsOpts.checkRequiredMissing(options, ('cid', )):
        if wsOpts.checkRequiredMissing(options, ('url', )):
            parser.print_help()
            logging.error("Must specify EITHER cid or Defect Manager URL")
            print "\nMust specify EITHER cid or Defect Manager URL"
            sys.exit(-1)

    makeurl = makeUrl()
    url = makeurl.make_url(options, options.url, options.cid, options.project)
    if url:
        print url
    else:
        logging.error("No valid project for cid " + str(options.cid))
        sys.exit(-1)
Esempio n. 10
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()
    
    parser.add_option("--check", dest="action", action="store_const", const="check", \
                                 help="Check server commit status")
    parser.add_option("--start", dest="action", action="store_const", const="start", \
                                 help="Start accepting commits if turned off")
    parser.add_option("--stop", dest="action", action="store_const", const="stop", \
                                 help="Stop new commits, wait till they finish")
    parser.add_option("--stop-now", dest="action", action="store_const", const="stop-now", \
                                 help="Stop new commits, don't wait till they finish")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('action',)):
        parser.print_help()
        sys.exit(-1)

    wsOpts.setLogging(options.debug)

    configServiceClient = ConfigServiceClient(options)

    configServiceClient.new_commits(options.action)
Esempio n. 11
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    (options, args) = parser.parse_args()

    if wsOpts.checkRequiredMissing(options, ('stream',)):
        parser.print_help()
        sys.exit(-1)

    wsOpts.setLogging(options.debug)

    configServiceClient = ConfigServiceClient(options)
    defectServiceClient = DefectServiceClient(options)

    streamIdDO = configServiceClient.get_stream(options.stream)

    mergedDefectDOs = defectServiceClient.get_merged_defects(streamIdDO, statusFilter='all')
    logging.debug(mergedDefectDOs.totalNumberOfRecords)
    total = mergedDefectDOs.totalNumberOfRecords
    if total < 1:
        logging.warning("No defects")
        sys.exit(1)

    mdDOs = mergedDefectDOs.mergedDefects
    got = len(mergedDefectDOs.mergedDefects)

    cidlist = []
    ciddict = {}
    logging.debug("Got "+str(len(mdDOs))+" out of "+str(total)+" defects")
    for md in mdDOs:
        occurrences = defectServiceClient.get_num_stream_defect_occurrences(md.cid, options.stream)
        logging.debug("Cid %d, status %s, %d occurrences" % (md.cid, md.status, occurrences))
        cidlist.append((md.cid, md.classification, max(1,occurrences)))

    totals = sum(x[2] for x in cidlist)
    print "Total occurrences:", totals
    ones = len(set(y[0] for y in cidlist if y[2] == 1))
    moreThanOne = ( (y[0],y[2]) for y in cidlist if y[2] > 1)

    logging.debug( str(ones) + " defects have one occurrence")
    if ones < totals:
        logging.debug("The following " + str(len(set(moreThanOne))) + " defects have more than one occurrence")
        for z in sorted(moreThanOne):
            logging.debug("CID " + str(z[0]) + ": " + str(z[1]))
Esempio n. 12
0
def main():

    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    parser.add_option("--group",    dest="group",  help="Group Name")
    parser.add_option("--newname",    dest="newname",  help="New name")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('group','newname')):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options);

    configServiceClient.rename_group(options.group,options.newname)
def main():

    wsOpts = WSOpts()

    parser = wsOpts.get_common_opts()

    parser.add_option("--group",    dest="group",  help="Group name")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('group',)):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options);

    print configServiceClient.get_users_for_group(options.group)
def main():

    wsOpts = WSOpts()

    parser = wsOpts.get_common_opts()

    parser.add_option("--username",    dest="username",  help="Username")

    (options, args) = parser.parse_args()

    wsOpts.setLogging(options.debug)
    if wsOpts.checkRequiredMissing(options, ('username',)):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options);

    print configServiceClient.user_details(options.username)
Esempio n. 15
0
def main():
    wsOpts = WSOpts()

    parser = wsOpts.get_common_opts()

    parser.add_option("--username",    dest="username",  help="User to add to group")
    parser.add_option("--group",    dest="group",  help="Group name")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('username','group')):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)

    configServiceClient.add_user_to_group(options.username, options.group)
Esempio n. 16
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    (options, args) = parser.parse_args()

    if wsOpts.checkRequiredMissing(options, ('stream',)):
        parser.print_help()
        sys.exit(-1)

    wsOpts.setLogging(options.debug)

    configServiceClient = ConfigServiceClient(options)
    defectServiceClient = DefectServiceClient(options)

    streamIdDO = configServiceClient.get_stream(options.stream)

    mergedDefectDOs = defectServiceClient.get_merged_defects(streamIdDO, statusFilter='all')
    total = mergedDefectDOs.totalNumberOfRecords
    logging.debug(total)
    if total < 1:
        logging.warning("No defects")
        sys.exit(1)

    mdDOs = mergedDefectDOs.mergedDefects
    got = len(mergedDefectDOs.mergedDefects)

    attrlist = ['mergeKey','classification','severity','action','comment','filePathname','functionDisplayName']
    cidlist = []
    logging.debug("Got "+str(len(mdDOs))+" out of "+str(total)+" defects")
    for md in mdDOs:
        ciddict = {}
        logging.debug("Cid %d, status %s, %s mergeKey" % (md.cid, md.status, md.mergeKey))
        for attr in attrlist:
            ciddict[attr]=getattr(md,attr,None)
            logging.debug(ciddict[attr])
        cidlist.append(ciddict)

    logging.debug("Exporting " + str(len(cidlist)) + " defects")
    Writer = csv.DictWriter(open("keysTriage.csv",'wb'), attrlist)
    Writer.writerow(dict((fn,fn) for fn in attrlist))
    for z in cidlist:
         logging.debug("CID " + str(z['mergeKey']) + ": " + str(z['classification']))
         Writer.writerow(z)
Esempio n. 17
0
def main():

    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    parser.add_option("--group",    dest="group",  help="Group Name")
    parser.add_option("--ldap",  default=False,  dest="ldap",  action="store_true", help="Ldap")
    parser.add_option("--role",  dest="role",  help="Role to add to group")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('group',)):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options);

    configServiceClient.create_group(options.group,options.ldap,options.role)
Esempio n. 18
0
def main():

    wsOpts = WSOpts()

    parser = wsOpts.get_common_opts()

    parser.add_option("--username", dest="username", help="User to add to group")
    parser.add_option("--email", dest="email", help="New email to replace existing")
    parser.add_option("--role", dest="role", help="New role to add")

    (options, args) = parser.parse_args()

    if wsOpts.checkRequiredMissing(options, ("username", "email"), ("username", "role")):
        logging.error("Must specify username and either new email or new role")
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)

    configServiceClient.update_user(options.username, options.email, options.role)
Esempio n. 19
0
def main():

    wsOpts = WSOpts()

    parser = wsOpts.get_common_opts()

    parser.add_option("--olduser",    dest="olduser",  help="Username")
    parser.add_option("--newuser",    dest="newuser",  help="Username")

    (options, args) = parser.parse_args()

    if wsOpts.checkRequiredMissing(options, ('newuser','olduser')):
        parser.print_help()
        sys.exit(-1)

    wsOpts.setLogging(options.debug)
    configServiceClient = ConfigServiceClient(options);

    logging.info("Creating new account "+ options.newuser +" from "+ options.olduser)
    configServiceClient.copy_user(options.newuser,options.olduser)
Esempio n. 20
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()
    parser.add_option("--file",  dest="filename",  help="Limit defects to those in file <filename>")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('stream',)):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)
    defectServiceClient = DefectServiceClient(options)

    streamIdDO = configServiceClient.get_stream(options.stream)

    mergedDefectDOs = defectServiceClient.get_merged_defects(streamIdDO, statusFilter='New', filename=options.filename)
    total = mergedDefectDOs.totalNumberOfRecords
    if total < 1:
        logging.warning("No new defects")
        sys.exit(1)

    mdDOs = mergedDefectDOs.mergedDefects

    cidlist = []
    for md in mdDOs:
        occurrences = defectServiceClient.get_stream_defect_occurrences(md.cid, options.stream)
        logging.debug("CID %d, status %s, %d occurrences" % (md.cid, md.status, len(occurrences)))
        cidlist.append((md.cid, md.classification, max(1,len(occurrences))))

    totals = sum(x[2] for x in cidlist)
    print "Total occurrences:", totals
    ones = len(set(y[0] for y in cidlist if y[2] == 1))
    moreThanOne = ( (y[0],y[2]) for y in cidlist if y[2] > 1)

    print ones, " defects have one occurrence"
    if ones < totals:
        print "The following defects have more than one occurrence"
        for z in sorted(moreThanOne):
            print "CID ", z[0], ": ", z[1]
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    # parser.add_option("--reverse",  action="store_true", dest="reverse", default=False, help="Reverse order of groups if Users is on the wrong end");

    (options, args) = parser.parse_args()

    if not options.password:
        parser.print_help()
        sys.exit(-1)

    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ()):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)

    componentMaps = configServiceClient.get_component_maps()
    if len(componentMaps) == 0:
        # if they are no maps, something is wrong where is Default?
        logging.error( "Where is default component map?")
        sys.exit(-1)

    for cm in componentMaps:
        print ("Checking component map" + cm.componentMapId.name + ":")
        print ( str(len(cm.components)) + " components found")
        for c in cm.components:
            name = c.componentId.name
            print ("Component " + name)
            numGroups = len(getattr(c,'groupPermissions',[]))
            if numGroups == 0:
                logging.error("    ERROR: component ",name," has no group permissions!!!")
            else:
                gPerms = c.groupPermissions
                gPermsNum = len(gPerms)
                for g in gPerms:
                    permission= g.groupRole
                    print (g.groupId.name + "  \t/\t" + permission)
Esempio n. 22
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    parser.add_option("--cid",  dest="dmcid",  help="Defect Manager CID");
    parser.add_option("--dm-label",  dest="dmlabel",  help="Defect Manager label (used in cov-migrate-db");
    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('dmcid','dmlabel')):
        parser.print_help()
        sys.exit(-1)

    defectServiceClient = DefectServiceClient(options);

    cid = defectServiceClient.get_cid_from_dm(options.dmcid,options.dmlabel)
    if cid > 0:
        print options.dmcid + " is CID " + str(cid) + " in Integrity Manager"
    else:
        logging.error("Defect not found")
        print "Not found - please double check the DM label"
Esempio n. 23
0
def main():

    wsOpts = WSOpts()

    parser = wsOpts.get_common_opts()

    parser.add_option("--username",
                      dest="username",
                      help="User to print details")

    (options, args) = parser.parse_args()

    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('username', )):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)

    u = configServiceClient.user_details(options.username)
    logging.debug(u)
    for attr in u.__dict__.keys():
        if attr[0:2] == '__':
            continue
        if type(getattr(u, attr, None)) == type([]):
            logging.debug("Skipping attribute " + attr)
            # could add special handling for groups and roles
            continue
        if getattr(u, attr, None):
            print attr, " \tis \t", getattr(u, attr)
Esempio n. 24
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()
    parser.add_option("--file",
                      dest="filename",
                      help="Limit defects to those in file <filename>")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ()):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)
    defectServiceClient = DefectServiceClient(options)

    streamIdDO = configServiceClient.get_streams(options.project,
                                                 options.stream)
    if not streamIdDO:
        logging.error("Not a valid stream")
        sys.exit(1)

    mergedDefectDOs = defectServiceClient.get_merged_defects(
        streamIdDO, statusFilter='New', filename=options.filename)
    total = mergedDefectDOs.totalNumberOfRecords
    if total < 1:
        sys.exit(1)

    mdDOs = mergedDefectDOs.mergedDefects

    for md in sorted(mdDOs):
        defectServiceClient.print_stream_defect_brief(md.cid, streamIdDO[0],
                                                      options.project)
Esempio n. 25
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    parser.add_option("--attr",  dest="attr",  help="attribute to filter on");
    parser.add_option("--pattern",  dest="pattern",  help="pattern (glob)");

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ()):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)

    streamIdDO = configServiceClient.get_streams(options.project,options.stream)
    if len(streamIdDO) == 0:
        logging.error("No matching streams")
        sys.exit(-1)
    else:
        logging.debug("Getting snapshots for "+str(len(streamIdDO))+" streams")
        #streamSnapshots = configServiceClient.get_snapshots(streamIdDO, options.attr, options.pattern)

    #for (streamname, snapshotDOs) in streamSnapshots:
    for stream in streamIdDO:
        print "Stream " + stream.name + ":"
        snapshots = configServiceClient.get_snapshots_by_stream(stream)
        for s in snapshots:
            if len(s) != 1:
                print "Error!!!"
                continue
            print "Stream " + stream.name,
            print '\t',
            print s[0].snapshotId.id,
            print s[0].dateCreated,
            print s[0].analysisVersion,
            #print s[0].enabledCheckers
            print str(len(getattr(s[0],'enabledCheckers',[]))) + " checkers enabled"
Esempio n. 26
0
def main():

    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    parser.add_option("--from_stream",  dest="fromStream",  help="get states from from this stream")
    parser.add_option("--to_stream",    dest="toStream",  help="update triage in this stream\n\t\tSpecial stream name Every_stream reserved for all stream update")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('fromStream','toStream')):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)
    streamFromDO = configServiceClient.get_stream(options.fromStream)
    streamToDO = configServiceClient.get_stream(options.toStream)

    defectServiceClient = DefectServiceClient(options)

    defects_done = 0
    batch = 200
    matching_cids = []
    # Fetch the set of defects to copy triage from
    mergedDefectDOs = defectServiceClient.get_merged_defects(streamFromDO, statusFilter='all')
    TotalCids = mergedDefectDOs.totalNumberOfRecords
    if TotalCids < 0:
        logging.error("Error!  Failed to get Merged Defects to copy from!")
        sys.exit(-1)
    matching_cids = [d.cid for d in mergedDefectDOs.mergedDefects]
    if TotalCids != len(matching_cids):
        logging.error("Should not happen: length of matching_cids isn't same as TotalCids")
    while defects_done < TotalCids:
        logging.debug("Got %d of %d total MDs" % (defects_done, TotalCids))
        defectServiceClient.copy_triage(matching_cids[defects_done::batch], streamFromDO, streamToDO)
        defects_done += batch
        logging.debug("Got %d of %d total MDs" % (min(defects_done,TotalCids), TotalCids))
    logging.info("Copied triage for %d defects" % (TotalCids))
Esempio n. 27
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    (options, args) = parser.parse_args()

    if wsOpts.checkRequiredMissing(options,()):
        parser.print_help()
        sys.exit(-1)

    wsOpts.setLogging(options.debug)

    configServiceClient = ConfigServiceClient(options)
    defectServiceClient = DefectServiceClient(options)

    streamIdDO = configServiceClient.get_streams()

    mergedDefectDOs = defectServiceClient.get_merged_defects(streamIdDO, statusFilter='all')
    total = mergedDefectDOs.totalNumberOfRecords
    logging.debug(total)
    if total < 1:
        logging.warning("No defects")
        sys.exit(1)

    mdDOs = mergedDefectDOs.mergedDefects
    got = len(mergedDefectDOs.mergedDefects)
    mkeys = [m.mergeKey for m in mdDOs]

    Reader = csv.DictReader(open("keysTriage.csv"))
    
    for r in Reader:
        #mergeKey,classification,severity,action,comment
        if r['mergeKey'] in mkeys:
            cid = cid_for_mkey(r['mergeKey'], mdDOs)
            if r['action'] == 'Modeling Required':
                defectServiceClient.update_merged_defect([cid], '*/*',r['classification'],r['severity'],'Analysis Tuning Required',r['comment'])
            else:
                defectServiceClient.update_merged_defect([cid], '*/*',r['classification'],r['severity'],r['action'],r['comment'])
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    (options, args) = parser.parse_args()

    if wsOpts.checkRequiredMissing(options, ()):
        parser.print_help()
        sys.exit(-1)

    wsOpts.setLogging(options.debug)

    configServiceClient = ConfigServiceClient(options)

    highs = configServiceClient.get_checkers_by_impact('High')
    #domains = ['STATIC_C', 'STATIC_JAVA', 'STATIC_CS']
    domains = ['STATIC_C']
    for d in domains:
      dh = [h for h in highs if h.domain==d]
      for c in sorted(dh):
        print c.checkerName
    meds = configServiceClient.get_checkers_by_impact('Medium')
    for d in domains:
      print '\tMedium impact for domain ',d
      dh = [h for h in meds if h.domain==d]
      for c in sorted(dh):
        print c.checkerName

    sys.exit(0)
    print "----------------------******--------------------"
    print "----------------------******--------------------"
    print "How to get all Low Impact Checkers"
    lows = configServiceClient.get_checkers_by_impact('Low')
    for d in domains:
      print '\tLow impact for domain ',d
      dh = [h for h in lows if h.domain==d]
      for c in sorted(dh):
        print "\t\t", c.checkerName, c.subcategory
Esempio n. 29
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ()):
        parser.print_help()
        sys.exit(-1)

    wsOpts.setLogging(options.debug)

    configServiceClient = ConfigServiceClient(options)

    configServiceClient.print_system_config()
Esempio n. 30
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()
    parser.add_option("--file",
                      dest="filename",
                      help="Limit defects to those in file <filename>")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ()):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)
    defectServiceClient = DefectServiceClient(options)

    streamIdDO = configServiceClient.get_streams(options.project,
                                                 options.stream)
    if not streamIdDO:
        print "Not a valid stream"
        sys.exit(1)

    mergedDefectDOs = defectServiceClient.get_merged_defects(
        streamIdDO, filename=options.filename)
    #Y    mergedDefectDOs = defectServiceClient.get_merged_defects(streamIdDO, statusFilter='New', filename=options.filename)
    total = mergedDefectDOs.totalNumberOfRecords
    if total < 1:
        logging.warning("No new defects")
        sys.exit(1)

    mdDOs = mergedDefectDOs.mergedDefects

    logging.debug("Got " + str(len(mdDOs)) + " defects")
    for md in sorted(mdDOs):
        if md.severity in ['Major']:
            logging.debug(md)
            logging.debug(md.checkerName)
            logging.debug(md.checkerSubcategory)
            logging.debug(md.domain)
            cat = configServiceClient.get_checker_properties(
                md.checkerName, md.checkerSubcategory, md.domain)
            if cat:
                print cat.categoryDescription
                print cat.subcategoryLocalEffect
                print cat.subcategoryLongDescription

            defectServiceClient.print_stream_defect_occurrences(
                md.cid, streamIdDO[0], options.project)
            c = getattr(md, 'comment', None)
            if c:
                print "Last comment [asya]: ", c
                print ""
                print ""
Esempio n. 31
0
def main():

    wsOpts = WSOpts()

    parser = wsOpts.get_common_opts()

    parser.add_option("--username", dest="username", help="Username")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('username', )):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)

    logging.debug("Creating LDAP account " + options.username)
    success = configServiceClient.create_user(options.username,
                                              role=None,
                                              ldap=True)
    successConvert = False
    if not success:
        # assume the user exists as local user and switch to LDAP
        successConvert = configServiceClient.convert_to_ldap_user(
            options.username)
        if not successConvert:
            print "Couldn't create and couldn't convert, sorry!"
            sys.exit(1)
    subject = "Your Coverity account has been created"
    userDO = configServiceClient.get_user(options.username)
    url = "http://coverity.mongodb.com"
    if successConvert:
        subject = "Your Coverity account has been converted to Crowd/Jira"
    text = """
       <html><pre>
          Dear %s,
          \n
          An account has been created for you at MongoDB Coverity Instance.
          Your username is %s, same as your Crowd/Jira username.
          You can go to <a href=%s>%s</a> to securely log in using your Crowd/Jira password.
          \n
          Your Coverity Admin Team
          \n
       </pre></html>
    """
    name = str(options.username)
    body = text % (name, options.username, url, url)
    try:
        configServiceClient.send_notifications(options.username, subject, body)
    except Exception, err:
        print "Error sending user notification", str(err)
        sys.exit(1)
Esempio n. 32
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()
    
    parser.add_option("--motd", dest="motd", \
                                 help="Message of the Day to set")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('motd',)):
        parser.print_help()
        sys.exit(-1)

    wsOpts.setLogging(options.debug)

    configServiceClient = ConfigServiceClient(options)

    configServiceClient.client.service.setMessageOfTheDay(options.motd)
Esempio n. 33
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ()):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)
    defectServiceClient = DefectServiceClient(options)

    a = configServiceClient.client.service.getAttribute({'name':'custom'})
    attrDefSpec = configServiceClient.client.factory.create('attributeDefinitionSpecDataObj')
    attrDefSpec.attributeName='custom'
    attrDefSpec.attributeType=a.attributeType
    attrDefSpec.showInTriage=a.showInTriage
    attrDefSpec.description='attempt to get something to change'
    changeSpec = configServiceClient.client.factory.create('attributeValueChangeSpecDataObj')
    changeSpec.attributeValueIds=[]
    changeSpec.attributeValues=[]
    attribValId = configServiceClient.client.factory.create('attributeValueId')
    attribVal = configServiceClient.client.factory.create('attributeValueSpecDataObj')
    attribValId.name = 'four'
    attribVal.name = 'five'
    changeSpec.attributeValueIds.append(attribValId)
    changeSpec.attributeValues.append(attribVal)
    attribValId = configServiceClient.client.factory.create('attributeValueId')
    attribVal = configServiceClient.client.factory.create('attributeValueSpecDataObj')
    attribValId = null()
    attribVal.name = 'one'
    changeSpec.attributeValueIds.append(attribValId)
    changeSpec.attributeValues.append(attribVal)
    attribValId = configServiceClient.client.factory.create('attributeValueId')
    attribVal = configServiceClient.client.factory.create('attributeValueSpecDataObj')
    attribValId = null()
    attribVal.name = 'two'
    changeSpec.attributeValueIds.append(attribValId)
    changeSpec.attributeValues.append(attribVal)
    attribValId = configServiceClient.client.factory.create('attributeValueId')
    attribVal = configServiceClient.client.factory.create('attributeValueSpecDataObj')
    attribValId = null()
    attribVal.name = 'three'
    changeSpec.attributeValueIds.append(attribValId)
    changeSpec.attributeValues.append(attribVal)
    print changeSpec
    attrDefSpec.attributeValueChangeSpec=changeSpec
    print a.attributeDefinitionId
    print attrDefSpec
    configServiceClient.client.service.updateAttribute(a.attributeDefinitionId, attrDefSpec)
    print configServiceClient.client.service.getAttribute({'name':'custom'})
Esempio n. 34
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ()):
        parser.print_help()
        sys.exit(-1)

    wsOpts.setLogging(options.debug)

    configServiceClient = ConfigServiceClient(options)

    configServiceClient.print_system_config()
Esempio n. 35
0
def main():

    wsOpts = WSOpts()

    parser = wsOpts.get_common_opts()

    parser.add_option("--username",  dest="username",  help="Username")
    parser.add_option("--first",  dest="first",  help="First name")
    parser.add_option("--last",  dest="last",  help="Last Name")
    parser.add_option("--email", dest="email",  help="Email")
    parser.add_option("--group", dest="group",  help="Existing Group to add user to")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('username','email','group')):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options);

    logging.debug("Creating local account " + options.username)
    success = configServiceClient.create_user(options.username,options.first,options.last,options.email,'Administrators','xxxxxx',role=None, locked=True)
    if not success:
        print "Error!"
        sys.exit(1)
    subject = "Your Coverity account has been created"
    text = """
       <html><pre>
          Dear %s,
          \n
          An account has been created for you at MongoDB Coverity Instance.
          Your username is %s
          You have been added to %s group
          Please go to %s
          and click on "Forgot Password?" link - this will allow you to set your password.
          \n
          Your Coverity Admin Team
          \n
       </pre></html>
    """
    name = str(options.username)
    if options.first:
        name = str(options.first)
    url = configServiceClient.create_url()
    body = text % (name, options.username, options.group, url)
    try:
        configServiceClient.send_notifications(options.username, subject, body)
    except Exception, err:
        print "Error sending user notification", str(err)
        sys.exit(1)
Esempio n. 36
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    (options, args) = parser.parse_args()

    if wsOpts.checkRequiredMissing(options, ('stream', )):
        parser.print_help()
        sys.exit(-1)

    wsOpts.setLogging(options.debug)

    configServiceClient = ConfigServiceClient(options)
    defectServiceClient = DefectServiceClient(options)

    streamIdDO = configServiceClient.get_stream(options.stream)

    mergedDefectDOs = defectServiceClient.get_merged_defects(
        streamIdDO, statusFilter='all')
    total = mergedDefectDOs.totalNumberOfRecords
    logging.debug(total)
    if total < 1:
        logging.warning("No defects")
        sys.exit(1)

    mdDOs = mergedDefectDOs.mergedDefects
    got = len(mergedDefectDOs.mergedDefects)

    attrlist = [
        'mergeKey', 'classification', 'severity', 'action', 'comment',
        'filePathname', 'functionDisplayName'
    ]
    cidlist = []
    logging.debug("Got " + str(len(mdDOs)) + " out of " + str(total) +
                  " defects")
    for md in mdDOs:
        ciddict = {}
        logging.debug("Cid %d, status %s, %s mergeKey" %
                      (md.cid, md.status, md.mergeKey))
        for attr in attrlist:
            ciddict[attr] = getattr(md, attr, None)
            logging.debug(ciddict[attr])
        cidlist.append(ciddict)

    logging.debug("Exporting " + str(len(cidlist)) + " defects")
    Writer = csv.DictWriter(open("keysTriage.csv", 'wb'), attrlist)
    Writer.writerow(dict((fn, fn) for fn in attrlist))
    for z in cidlist:
        logging.debug("CID " + str(z['mergeKey']) + ": " +
                      str(z['classification']))
        Writer.writerow(z)
Esempio n. 37
0
def main():

    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    parser.add_option("--from_stream",
                      dest="fromStream",
                      help="get states from from this stream")
    parser.add_option(
        "--to_stream",
        dest="toStream",
        help=
        "update triage in this stream\n\t\tSpecial stream name Every_stream reserved for all stream update"
    )

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('fromStream', 'toStream')):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)
    streamFromDO = configServiceClient.get_stream(options.fromStream)
    streamToDO = configServiceClient.get_stream(options.toStream)

    defectServiceClient = DefectServiceClient(options)

    defects_done = 0
    batch = 200
    matching_cids = []
    # Fetch the set of defects to copy triage from
    mergedDefectDOs = defectServiceClient.get_merged_defects(
        streamFromDO, statusFilter='all')
    TotalCids = mergedDefectDOs.totalNumberOfRecords
    if TotalCids < 0:
        logging.error("Error!  Failed to get Merged Defects to copy from!")
        sys.exit(-1)
    matching_cids = [d.cid for d in mergedDefectDOs.mergedDefects]
    if TotalCids != len(matching_cids):
        logging.error(
            "Should not happen: length of matching_cids isn't same as TotalCids"
        )
    while defects_done < TotalCids:
        logging.debug("Got %d of %d total MDs" % (defects_done, TotalCids))
        defectServiceClient.copy_triage(matching_cids[defects_done::batch],
                                        streamFromDO, streamToDO)
        defects_done += batch
        logging.debug("Got %d of %d total MDs" %
                      (min(defects_done, TotalCids), TotalCids))
    logging.info("Copied triage for %d defects" % (TotalCids))
Esempio n. 38
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    (options, args) = parser.parse_args()

    if wsOpts.checkRequiredMissing(options, ('stream', )):
        parser.print_help()
        sys.exit(-1)

    wsOpts.setLogging(options.debug)

    configServiceClient = ConfigServiceClient(options)
    defectServiceClient = DefectServiceClient(options)

    streamIdDO = configServiceClient.get_stream(options.stream)

    mergedDefectDOs = defectServiceClient.get_merged_defects(
        streamIdDO, statusFilter='all')
    logging.debug(mergedDefectDOs.totalNumberOfRecords)
    total = mergedDefectDOs.totalNumberOfRecords
    if total < 1:
        logging.warning("No defects")
        sys.exit(1)

    mdDOs = mergedDefectDOs.mergedDefects
    got = len(mergedDefectDOs.mergedDefects)

    cidlist = []
    ciddict = {}
    logging.debug("Got " + str(len(mdDOs)) + " out of " + str(total) +
                  " defects")
    for md in mdDOs:
        occurrences = defectServiceClient.get_num_stream_defect_occurrences(
            md.cid, options.stream)
        logging.debug("Cid %d, status %s, %d occurrences" %
                      (md.cid, md.status, occurrences))
        cidlist.append((md.cid, md.classification, max(1, occurrences)))

    totals = sum(x[2] for x in cidlist)
    print "Total occurrences:", totals
    ones = len(set(y[0] for y in cidlist if y[2] == 1))
    moreThanOne = ((y[0], y[2]) for y in cidlist if y[2] > 1)

    logging.debug(str(ones) + " defects have one occurrence")
    if ones < totals:
        logging.debug("The following " + str(len(set(moreThanOne))) +
                      " defects have more than one occurrence")
        for z in sorted(moreThanOne):
            logging.debug("CID " + str(z[0]) + ": " + str(z[1]))
Esempio n. 39
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('snapshot',)):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)
    defectServiceClient = DefectServiceClient(options)

    snapshotIdDO = configServiceClient.get_snapshot(options.snapshot)
    if not snapshotIdDO:
        logging.error("No valid snapshot found")
        parser.print_help()
        sys.exit(-1)

    streamname = configServiceClient.get_stream_by_snapshot(options.snapshot)
    streamIdDOs = configServiceClient.get_stream(streamname)
    if not streamIdDOs:
        logging.error("No valid stream for this snapshot found")
        sys.exit(-1)
    if len(streamIdDOs) != 1:
        logging.error("Found more than one stream for this snapshot!!!")
        sys.exit(-1)
    streamIdDO = streamIdDOs[0]

    try:
        md = defectServiceClient.get_merged_defects_by_snapshot(snapshotIdDO,streamIdDO)
    except:
        logging.warning("No merged defects for snapshot found")
        sys.exit(-1)
    try:
        cids = [d.cid for d in md.mergedDefects]
    except:
        logging.error("Error getting cids for snapshot")
        sys.exit(-1)

    totalFetched = len(cids)
    if totalFetched < 1:
        print "No defects in snapshot", snapshotIdDO.id.snapshotId.id
        sys.exit(1)
    else:
        print "Fetched "+ str(totalFetched) + " cids in snapshot", options.snapshot
Esempio n. 40
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()
    parser.add_option("--file",
                      dest="filename",
                      help="Limit defects to those in file <filename>")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('stream', )):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)
    defectServiceClient = DefectServiceClient(options)

    streamIdDO = configServiceClient.get_stream(options.stream)

    mergedDefectDOs = defectServiceClient.get_merged_defects(
        streamIdDO, statusFilter='New', filename=options.filename)
    total = mergedDefectDOs.totalNumberOfRecords
    if total < 1:
        logging.warning("No new defects")
        sys.exit(1)

    mdDOs = mergedDefectDOs.mergedDefects

    cidlist = []
    for md in mdDOs:
        occurrences = defectServiceClient.get_stream_defect_occurrences(
            md.cid, options.stream)
        logging.debug("CID %d, status %s, %d occurrences" %
                      (md.cid, md.status, len(occurrences)))
        cidlist.append((md.cid, md.classification, max(1, len(occurrences))))

    totals = sum(x[2] for x in cidlist)
    print "Total occurrences:", totals
    ones = len(set(y[0] for y in cidlist if y[2] == 1))
    moreThanOne = ((y[0], y[2]) for y in cidlist if y[2] > 1)

    print ones, " defects have one occurrence"
    if ones < totals:
        print "The following defects have more than one occurrence"
        for z in sorted(moreThanOne):
            print "CID ", z[0], ": ", z[1]
Esempio n. 41
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    (options, args) = parser.parse_args()

    if wsOpts.checkRequiredMissing(options, ()):
        parser.print_help()
        sys.exit(-1)

    wsOpts.setLogging(options.debug)

    configServiceClient = ConfigServiceClient(options)
    defectServiceClient = DefectServiceClient(options)

    streamIdDO = configServiceClient.get_streams()

    mergedDefectDOs = defectServiceClient.get_merged_defects(
        streamIdDO, statusFilter='all')
    total = mergedDefectDOs.totalNumberOfRecords
    logging.debug(total)
    if total < 1:
        logging.warning("No defects")
        sys.exit(1)

    mdDOs = mergedDefectDOs.mergedDefects
    got = len(mergedDefectDOs.mergedDefects)
    mkeys = [m.mergeKey for m in mdDOs]

    Reader = csv.DictReader(open("keysTriage.csv"))

    for r in Reader:
        #mergeKey,classification,severity,action,comment
        if r['mergeKey'] in mkeys:
            cid = cid_for_mkey(r['mergeKey'], mdDOs)
            if r['action'] == 'Modeling Required':
                defectServiceClient.update_merged_defect(
                    [cid], '*/*', r['classification'], r['severity'],
                    'Analysis Tuning Required', r['comment'])
            else:
                defectServiceClient.update_merged_defect([cid], '*/*',
                                                         r['classification'],
                                                         r['severity'],
                                                         r['action'],
                                                         r['comment'])
Esempio n. 42
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()
    parser.add_option("--filepath",
                      dest="filepath",
                      help="path of file to map")
    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('stream', 'filepath')):
        parser.print_help()
        sys.exit(-1)

    if not options.stream or not options.filepath:
        optionParser.error("Must specify both stream and filepath")

    configServiceClient = ConfigServiceClient(options)
    print configServiceClient.fileToComponent(options.filepath, options.stream)
Esempio n. 43
0
def main():

    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    parser.add_option("--group", dest="group", help="Group Name")
    parser.add_option("--newname", dest="newname", help="New name")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('group', 'newname')):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)

    configServiceClient.rename_group(options.group, options.newname)
Esempio n. 44
0
def main():

    wsOpts = WSOpts()

    parser = wsOpts.get_common_opts()

    parser.add_option("--username", dest="username", help="Username")

    (options, args) = parser.parse_args()

    wsOpts.setLogging(options.debug)
    if wsOpts.checkRequiredMissing(options, ('username', )):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)

    print configServiceClient.user_details(options.username)
Esempio n. 45
0
def main():

    wsOpts = WSOpts()

    parser = wsOpts.get_common_opts()

    parser.add_option("--group", dest="group", help="Group name")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('group', )):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)

    print configServiceClient.get_users_for_group(options.group)
Esempio n. 46
0
def main():

    wsOpts = WSOpts()

    parser = wsOpts.get_common_opts()

    parser.add_option("--username", dest="username", help="Username")
    parser.add_option("--first", dest="first", help="First name")
    parser.add_option("--last", dest="last", help="Last Name")
    parser.add_option("--email", dest="email", help="Email")
    parser.add_option("--group", dest="group", help="Local Groups to add to")
    parser.add_option("--role", dest="role", help="Role")
    parser.add_option(
        "--ldap",
        default=False,
        dest="ldap",
        action="store_true",
        help="LDAP or local account, specify for LDAP, default is local")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('username', )):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)

    if options.ldap:
        logging.debug("Creating ldap account " + options.username)
        configServiceClient.create_user(options.username,
                                        ldap=True,
                                        role=options.role,
                                        groups=options.group)
    else:
        logging.debug("Creating local account " + options.username)
        configServiceClient.create_user(options.username,
                                        options.first,
                                        options.last,
                                        options.email,
                                        options.group,
                                        'coverity',
                                        role=options.role)
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    # parser.add_option("--reverse",  action="store_true", dest="reverse", default=False, help="Reverse order of groups if Users is on the wrong end");

    (options, args) = parser.parse_args()

    if not options.password:
        parser.print_help()
        sys.exit(-1)

    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ()):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)

    componentMaps = configServiceClient.get_component_maps()
    if len(componentMaps) == 0:
        # if they are no maps, something is wrong where is Default?
        logging.error("Where is default component map?")
        sys.exit(-1)

    for cm in componentMaps:
        print("Checking component map" + cm.componentMapId.name + ":")
        print(str(len(cm.components)) + " components found")
        for c in cm.components:
            name = c.componentId.name
            print("Component " + name)
            numGroups = len(getattr(c, 'groupPermissions', []))
            if numGroups == 0:
                logging.error("    ERROR: component ", name,
                              " has no group permissions!!!")
            else:
                gPerms = c.groupPermissions
                gPermsNum = len(gPerms)
                for g in gPerms:
                    permission = g.groupRole
                    print(g.groupId.name + "  \t/\t" + permission)
Esempio n. 48
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    parser.add_option("--attr", dest="attr", help="attribute to filter on")
    parser.add_option("--pattern", dest="pattern", help="pattern (glob)")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ()):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)

    streamIdDO = configServiceClient.get_streams(options.project,
                                                 options.stream)
    if len(streamIdDO) == 0:
        logging.error("No matching streams")
        sys.exit(-1)
    else:
        logging.debug("Getting snapshots for " + str(len(streamIdDO)) +
                      " streams")
        #streamSnapshots = configServiceClient.get_snapshots(streamIdDO, options.attr, options.pattern)

    #for (streamname, snapshotDOs) in streamSnapshots:
    for stream in streamIdDO:
        print "Stream " + stream.name + ":"
        snapshots = configServiceClient.get_snapshots_by_stream(stream)
        for s in snapshots:
            if len(s) != 1:
                print "Error!!!"
                continue
            print "Stream " + stream.name,
            print '\t',
            print s[0].snapshotId.id,
            print s[0].dateCreated,
            print s[0].analysisVersion,
            #print s[0].enabledCheckers
            print str(len(getattr(s[0], 'enabledCheckers',
                                  []))) + " checkers enabled"
Esempio n. 49
0
def main():
    wsOpts = WSOpts()

    parser = wsOpts.get_common_opts()

    parser.add_option("--username",
                      dest="username",
                      help="User to add to group")
    parser.add_option("--group", dest="group", help="Group name")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('username', 'group')):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)

    configServiceClient.add_user_to_group(options.username, options.group)
Esempio n. 50
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()
    parser.add_option("--user1", dest="user1", help="Owner of defects")
    parser.add_option("--user2", dest="user2", help="New owner to assign defects to")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('user1','user2')):
        parser.print_help()
        sys.exit(-1)

    if options.user1 == options.user2:
        logging.warning("Users are the same.  Nothing to do")
        sys.exit(0)

    configServiceClient = ConfigServiceClient(options)
    defectServiceClient = DefectServiceClient(options)

    streamIdDO = configServiceClient.get_stream(options.stream)

    mergedDefectDOs = defectServiceClient.get_merged_defects(streamIdDO, users=options.user1,statusFilter='all')
    logging.debug(mergedDefectDOs.totalNumberOfRecords)
    total = mergedDefectDOs.totalNumberOfRecords
    if total < 1:
        logging.warning("No defects returned")
        sys.exit(1)

    mdDOs = mergedDefectDOs.mergedDefects
    got = len(mergedDefectDOs.mergedDefects)

    logging.debug("Length of list %d %d" % (got, total))
    cidlist = []
    for md in mdDOs:
        cidlist.append(md.cid)

    scope = defectServiceClient.set_scope(options.project, options.stream)
    logging.debug("Setting %d defects to owner=%s in scope %s" % (len(cidlist), options.user2, scope))
    defectServiceClient.update_merged_defect(cidlist, scope, owner=options.user2)
Esempio n. 51
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    (options, args) = parser.parse_args()

    if wsOpts.checkRequiredMissing(options, ()):
        parser.print_help()
        sys.exit(-1)

    wsOpts.setLogging(options.debug)

    configServiceClient = ConfigServiceClient(options)

    highs = configServiceClient.get_checkers_by_impact('High')
    #domains = ['STATIC_C', 'STATIC_JAVA', 'STATIC_CS']
    domains = ['STATIC_C']
    for d in domains:
        dh = [h for h in highs if h.domain == d]
        for c in sorted(dh):
            print c.checkerName
    meds = configServiceClient.get_checkers_by_impact('Medium')
    for d in domains:
        print '\tMedium impact for domain ', d
        dh = [h for h in meds if h.domain == d]
        for c in sorted(dh):
            print c.checkerName

    sys.exit(0)
    print "----------------------******--------------------"
    print "----------------------******--------------------"
    print "How to get all Low Impact Checkers"
    lows = configServiceClient.get_checkers_by_impact('Low')
    for d in domains:
        print '\tLow impact for domain ', d
        dh = [h for h in lows if h.domain == d]
        for c in sorted(dh):
            print "\t\t", c.checkerName, c.subcategory
Esempio n. 52
0
def main():

    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    parser.add_option("--group", dest="group", help="Group Name")
    parser.add_option("--ldap",
                      default=False,
                      dest="ldap",
                      action="store_true",
                      help="Ldap")
    parser.add_option("--role", dest="role", help="Role to add to group")

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('group', )):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)

    configServiceClient.create_group(options.group, options.ldap, options.role)
Esempio n. 53
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    parser.add_option("--cid", dest="dmcid", help="Defect Manager CID")
    parser.add_option("--dm-label",
                      dest="dmlabel",
                      help="Defect Manager label (used in cov-migrate-db")
    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('dmcid', 'dmlabel')):
        parser.print_help()
        sys.exit(-1)

    defectServiceClient = DefectServiceClient(options)

    cid = defectServiceClient.get_cid_from_dm(options.dmcid, options.dmlabel)
    if cid > 0:
        print options.dmcid + " is CID " + str(cid) + " in Integrity Manager"
    else:
        logging.error("Defect not found")
        print "Not found - please double check the DM label"
Esempio n. 54
0
def main():

    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    parser.add_option("--cid", dest="cid", help="CID for URL")
    parser.add_option("--url", dest="url", help="Defect Manager URL (server/port must be used as DM label during migration)")
    (options, args) = parser.parse_args()

    wsOpts.setLogging(options.debug)
    if wsOpts.checkRequiredMissing(options, ('cid',)):
        if wsOpts.checkRequiredMissing(options, ('url',)):
            parser.print_help()
            logging.error("Must specify EITHER cid or Defect Manager URL")
            print "\nMust specify EITHER cid or Defect Manager URL"
            sys.exit(-1)

    makeurl = makeUrl()
    url = makeurl.make_url(options, options.url, options.cid, options.project)
    if url:
        print url
    else:
        logging.error("No valid project for cid " + str(options.cid))
        sys.exit(-1)
def main():
    """
     create and send notifications to all users who were assigned
     any new defects in the past N days (N=1 or specified)
    """
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    # use --test flag to avoid sending e-mail while debugging this script
    parser.set_defaults(testing="False")
    parser.add_option("--test",  action="store_true", dest="testing",  default="False", help="Testing flag: no mail just echo to stdout");
    parser.add_option("--days",  dest="days",  type=int, default=1, help="Days to check to notify about (default last 24 hours)");

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ()):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)
    defectServiceClient = DefectServiceClient(options)

    # calculate when the action would have to be since to get reported
    cutoff = datetime.datetime.today()-datetime.timedelta(options.days)

    # all assignable users - no disabled users, since they should not be notified
    users = configServiceClient.get_all_users()

    # get the streams for relevant project or get all if none
    streamIdDO = configServiceClient.get_streams(options.project,options.stream)

    mergedDefectDOs = defectServiceClient.get_merged_defects(streamIdDO,users=users)

    email_cid = {}
    totalFetched = mergedDefectDOs.totalNumberOfRecords
    if totalFetched < 1:
        logging.info("No defects")
        sys.exit(totalFetched)
    logging.info("Total fetched "+ repr(totalFetched))
    for md in mergedDefectDOs.mergedDefects:
        defectChangeDataObj = defectServiceClient.get_md_history(md.cid,streamIdDO)
        i = len(defectChangeDataObj)-1
        while i >= 0:
            if defectChangeDataObj[i].dateModified > cutoff and len(set(defectChangeDataObj[i].affectedStreams).difference(set(streamIdDO))) > 0:
                for fieldChangeDO in defectChangeDataObj[i].attributeChanges:
                  if fieldChangeDO != None and fieldChangeDO.fieldName=='Owner': 
                    logging.debug("defectChangeDataObj with new owner is "+ repr(defectChangeDataObj[i]))
                    new_owner = fieldChangeDO.newValue
                    if new_owner not in email_cid:
                        email_cid[new_owner] = []
                    if md.cid not in email_cid[new_owner]:
                        email_cid[new_owner].append(md.cid)
                    break
            i = i - 1


    if len(email_cid) == 0:
        logging.info("Nothing to notify about")
        sys.exit(0)

    if options.project:
        subject = "New defects assigned to you in Coverity Project "+options.project
    else:
        subject = "New defects assigned to you in Coverity Projects"
    project_id = None
    url = None
    if options.project and '*' not in options.project:
        project_id =configServiceClient.get_project_id(options.project)
    else:
        if options.project:
            projectDOs = configServiceClient.get_projects(options.project)
        else:
            projectDOs = configServiceClient.get_projects()
            logging.debug("Got Project DOs " + str(len(projectDOs)))
    if options.days == 1:
        leadin = "<html>\n<br>The following defects were assigned to you in the past 24 hours<br>\n"
    else:
        leadin = "<html>\n<br>The following defects were assigned to you in the past " + str(options.days) + " days<br>\n"
    if project_id:
        projId=str(project_id)
    for u in email_cid.keys():
        body = leadin
        for cid in email_cid[u]:
            if not project_id:
                (projId,streamDefectId) = defectServiceClient.get_project_for_CID_and_user(projectDOs, cid, u)
                url = defectServiceClient.create_url(cid, projId,streamDefectId)
            else:
                url = defectServiceClient.create_url(cid, projId)
            body = body + "CID " + str(cid) + ": <a href=" + url + ">" + url + "</a><br>\n"

        body = body + "</html>"
        if options.testing == True:
            logging.warning("Testing: no actual e-mail will be sent")
            print "Username:  "******"Subject:   " + subject
            print body
        else:
            logging.debug("Users:" + str(u))
            logging.debug("Subject:" + str(subject))
            logging.debug("Body:" + str(body))
            try:
                resp = configServiceClient.send_notifications(u, subject, body)
                logging.debug("Mail sent to %d recepient" % (len(resp)))
            except Exception, err:
                logging.error(str(err))
                logging.error("Mail not sent to " + u)
Esempio n. 56
0
def main():
    wsOpts = WSOpts()
    parser = wsOpts.get_common_opts()

    (options, args) = parser.parse_args()
    wsOpts.setLogging(options.debug)

    if wsOpts.checkRequiredMissing(options, ('snapshot', )):
        parser.print_help()
        sys.exit(-1)

    configServiceClient = ConfigServiceClient(options)
    defectServiceClient = DefectServiceClient(options)

    snapshotIdDO = configServiceClient.get_snapshot(options.snapshot)
    snapshotInfoDO = configServiceClient.get_snapshot_info(options.snapshot)

    if not snapshotInfoDO:
        logging.warning("No valid snapshot found")
        parser.print_help()
        sys.exit(-1)
    streamname = configServiceClient.get_stream_by_snapshot(options.snapshot)
    streamIdDOs = configServiceClient.get_stream(streamname)
    if not streamIdDOs:
        logging.error("No valid stream for this snapshot found")
        parser.print_help()
        sys.exit(-1)
    if len(streamIdDOs) != 1:
        logging.error("Found more than one stream for this snapshot!!!")
        parser.print_help()
        sys.exit(-1)
    streamIdDO = streamIdDOs[0]

    lastSnapshotIdDO = configServiceClient.get_snapshot_by_date(
        datetime.datetime.now(), streamIdDO)
    logging.debug("Last snapshot in stream %s is " % (streamIdDO.name))
    logging.debug(lastSnapshotIdDO.id.snapshotId.id)

    mergedDefectDOs = defectServiceClient.get_merged_defects_by_snapshot(
        snapshotIdDO, streamIdDO)
    logging.debug("Last snapshot in this stream is " +
                  str(lastSnapshotIdDO.id.snapshotId.id))

    totalFetched = mergedDefectDOs.totalNumberOfRecords
    if totalFetched < 1:
        logging.warning("No defects")
        sys.exit(1)
    else:
        logging.debug(
            str(totalFetched) + " merged defects fetched for snapshot " +
            str(snapshotIdDO.id) + " " + streamIdDO.name)
        pass

    currentMDDOs = defectServiceClient.get_merged_defects(streamIdDOs, 'all')
    if currentMDDOs.totalNumberOfRecords < 1:
        logging.warning("Something is wrong: no current defects")
        sys.exit(1)
    cids = [md.cid for md in currentMDDOs.mergedDefects]
    logging.debug(len(cids))
    badcids = ([
        md.cid for md in mergedDefectDOs.mergedDefects if md.cid not in cids
    ])
    goodcids = ([
        md.cid for md in mergedDefectDOs.mergedDefects if md.cid in cids
    ])
    allcids = [md.cid for md in mergedDefectDOs.mergedDefects]
    logging.debug(len(allcids))
    logging.debug(len(set(cids).difference(set(allcids))))
    logging.debug(len(set(allcids).difference(set(cids))))
    mds = ([md for md in mergedDefectDOs.mergedDefects if md.cid in cids])
    logging.info(str(len(cids)) + " cids were committed - " + str(len(mds)))
    # things to add
    # get previous snapshot CIDs, compare
    # get next snapshot CIDs, compare
    # give breakdown of CIDs in that snapshot by current status
    print "Number of CIDs committed to stream %s in snapshot %s: %d " % (
        streamname, options.snapshot, len(cids))
    print " of which:"
    Fixed = [md.cid for md in mds if md.status == 'Fixed']
    Dismissed = [md.cid for md in mds if md.status == 'Dismissed']
    Triaged = [md.cid for md in mds if md.status == 'Triaged']
    New = [md.cid for md in mds if md.status == 'New']
    print len(Fixed), " were fixed"
    print len(Dismissed), " are dismissed"
    print len(Triaged), " were triaged but still outstanding"
    print len(New), " are still New and untriaged"