class Avant_Rally(object): iterations = [] rally = None def __init__(self, project): self.project = project def connect(self, username, password): self.rally = Rally(server, user, password, project=self.project) self.rally.enableLogging('rally.simple-use.log') def fetch_Iterations(self): self.iterations = [] response = self.rally.get('Iteration', fetch=True) for rls in response: iter = Iteration() rlsStart = rls.StartDate.split('T')[0] # just need the date part rlsDate = rls.EndDate.split('T')[0] # ditto self.iterations.append(iter.set_Iteration(rlsStart, rlsDate, rls.Name, rls.PlannedVelocity, self.rally)) def display_Iterations(self): for i in self.iterations: print "\n\n%s %s --> %s\t" % \ (i.name, i.start_date, i.end_date) i.display_User_Stories(i.name)
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] if not args: print USAGE sys.exit(9) # specify the Rally server and credentials server, username, password, workspace, project = rallySettings(options) #print " ".join(["|%s|" % opt for opt in [server, username, '********', workspace]]) rally = Rally(server, user=username, password=password, workspace=workspace, warn=False) rally.enableLogging('rally.hist.chgsets') # name of file you want the logging to go to repo_name = args.pop(0) since = None if args: since = args.pop(0) try: days = int(since) now = time.time() since_ts = now - (days * 86400) since = time.strftime("%Y-%m-%dT%H:%M:%S.000Z", time.gmtime(since_ts)) except: since = None showRepoItems(rally, repo_name, workspace=workspace, limit=ITEM_LIMIT, since_date=since)
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] server, user, password, workspace, project = rallySettings(options) #print " ".join(["|%s|" % item for item in [server, user, '********', workspace, project]]) rally = Rally(server, user, password, workspace=workspace, warn=False) target_workspace, byproject, art_types = processCommandLineArguments(args) rally.enableLogging('rally.hist.articount') # name of file you want logging to go to workspaces = rally.getWorkspaces() if target_workspace != 'all': hits = [wksp for wksp in workspaces if wksp.Name == target_workspace] if not hits: problem = "The specified target workspace: '%s' either does not exist or is not accessible" errout("ERROR: %s\n" % (problem % target_workspace)) sys.exit(2) workspaces = hits for wksp in workspaces: print wksp.Name print "=" * len(wksp.Name) rally.setWorkspace(wksp.Name) projects = [None] if byproject: projects = rally.getProjects(workspace=wksp.Name) for project in projects: if project: print "" print " %s" % project.Name print " %s" % ('-' * len(project.Name)) for artifact_type in art_types: count = getArtifactCount(rally, artifact_type, project=project) print " %-16.16s : %4d items" % (artifact_type, count) print ""
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] if len(args) != 1: errout(USAGE) sys.exit(1) server, username, password, apikey, workspace, project = rallyWorkset(options) if apikey: rally = Rally(server, apikey=apikey, workspace=workspace, project=project) else: rally = Rally(server, user=username, password=password, workspace=workspace, project=project) rally.enableLogging("rally.history.uptask") taskID = args.pop() # for this example use the FormattedID print "attempting to update Task: %s" % taskID target_workspace = rally.getWorkspace() target_project = rally.getProject() info = { "FormattedID" : taskID, "State" : "In-Progress" } ## print info try: task = rally.update('Task', info) except RallyRESTAPIError, details: sys.stderr.write('ERROR: %s \n' % details) sys.exit(2)
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] server, user, password, workspace, project = rallySettings(options) #print " ".join(["|%s|" % item for item in [server, user, '********', workspace, project]]) rally = Rally(server, user, password, workspace=workspace, warn=False) rally.enableLogging('rally.hist.articount') # name of file you want logging to go to prog_opts = [opt for opt in args if opt.startswith('-')] byproject = False if '-byproject' in prog_opts: byproject = True #if not args: # errout(USAGE) # sys.exit(1) print "" workspaces = rally.getWorkspaces() for wksp in workspaces: rally.setWorkspace(wksp.Name) print wksp.Name print "=" * len(wksp.Name) projects = [None] if byproject: projects = rally.getProjects(workspace=wksp.Name) for project in projects: if project: print "" print project.Name print " %s" % ('-' * len(project.Name)) for artifact_type in COUNTABLE_ARTIFACT_TYPES: count = getArtifactCount(rally, artifact_type, project=project) print " %-16.16s : %4d items" % (artifact_type, count) print ""
def main(args): options = [opt for opt in args if opt.startswith('--')] server, user, password, workspace, project = rallySettings(options) rally = Rally(server, user, password, workspace=workspace) rally.enableLogging("rally.history.blddefs") for workspace, project in wps: print "workspace: %s project: %s" % (workspace, project) rally.setWorkspace(workspace) response = rally.get('BuildDefinition', fetch=True, order='Name', workspace=workspace, project=project) if response.errors: print response.errors sys.exit(9) for builddef in response: if builddef.Project.Name != project: continue if builddef.LastStatus == "NO BUILDS": print "NO BUILDS" continue #print builddef.oid, builddef.Name, builddef.LastStatus lbt = builddef.LastBuild.CreationDate.split('T') last_build_time = "%s %s" % (lbt[0], lbt[1][:5] ) bd_name = "%-24.24s" % builddef.Name status = "%-10.10s" % builddef.LastStatus print builddef.oid, builddef.CreationDate[:10], \ bd_name, status, last_build_time, len(builddef.Builds) print "\n"
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] server, user, password, workspace, project = rallySettings(options) print " ".join(["|%s|" % item for item in [server, user, '********', workspace, project]]) rally = Rally(server, user, password, workspace=workspace, project=project) rally.enableLogging('rally.hist.statecount') # name of file you want logging to go to if not args: errout(USAGE) sys.exit(1) rally.setWorkspace(workspace) rally.setProject(project) artifact_type = args[0] if artifact_type not in VALID_ARTIFACT_TYPES: errout(USAGE) errout('The artifact_type argument must be one of: %s\n' % ", ".join(VALID_ARTIFACT_TYPES)) sys.exit(1) art_type = artifact_type[:] state = 'State' # default to this and change below if necessary if artifact_type in ['Story', 'UserStory', 'HierarchicalRequirement']: artifact_type = 'HierarchicalRequirement' state = 'ScheduleState' t_zero = time.time() state_values = rally.getAllowedValues(artifact_type, state) t_one = time.time() av_time = t_one - t_zero show_counts(rally, artifact_type, state, state_values, av_time)
def main(args): options = [opt for opt in args if opt.startswith('--')] server, user, password, workspace, project = rallySettings(options) rally = Rally(server, user, password, workspace=workspace) rally.enableLogging("rally.history.blddefs") for workspace, project in wps: rally.setWorkspace(workspace) print "workspace: %s project: %s\n" % (workspace, project) response = rally.get('BuildDefinition', fetch=True, query='Project.Name = "%s"' % project, order='Name', workspace=workspace, project=project) if response.errors: print response.errors sys.exit(9) print "%-12.12s %-10.10s %-36.36s %12s %-20.20s %s" % \ ('BuildDef OID', 'CreateDate', 'BuildDefinition.Name', 'LastStatus', 'LastBuildDateTime', 'NumBuilds') print "%-12.12s %-10.10s %-36.36s %10s %-19.19s %s" % \ ('-' * 12, '-' * 10, '-' * 36, '-' * 10, '-' * 19, '-' * 9) for builddef in response: if builddef.LastStatus == "NO BUILDS": print "%s %s %-24.24s NO BUILDS" % \ (builddef.oid, builddef.CreationDate[:10], builddef.Name) continue lbt = builddef.LastBuild.CreationDate.split('T') last_build_time = "%s %s" % (lbt[0], lbt[1][:8] ) bdf = "%12.12s %-10.10s %-36.36s %12s %-20.20s %4s" print bdf % (builddef.oid, builddef.CreationDate[:10], builddef.Name, builddef.LastStatus, last_build_time, len(builddef.Builds))
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] if not args: print USAGE sys.exit(9) server, username, password, apikey, workspace, project = rallyWorkset(options) if apikey: rally = Rally(server, apikey=apikey, workspace=workspace, project=project) else: rally = Rally(server, user=username, password=password, workspace=workspace, project=project) rally.enableLogging('rally.hist.chgsets') # name of file you want the logging to go to repo_name = args.pop(0) since = None if args: since = args.pop(0) try: days = int(since) now = time.time() since_ts = now - (days * 86400) since = time.strftime("%Y-%m-%dT%H:%M:%S.000Z", time.gmtime(since_ts)) except: since = None showRepoItems(rally, repo_name, workspace=workspace, limit=ITEM_LIMIT, since_date=since)
def get_rally_connection(USER, PASSWORD, PROJECT, VERSION='1.43', SERVER='rally1.rallydev.com'): ''' return a rally connection object ''' # get the rally connection object rally = Rally(SERVER, USER, PASSWORD, version=VERSION, project=PROJECT) rally.enableLogging('/tmp/rally.log') return rally
def get_story(formatted_id): r = Rally(server, apikey=apikey, project=project) r.enableLogging('rally.log') aa = r.get('UserStory', fetch=True, query='FormattedID = "' + formatted_id + '"', instance=True) return dict_from_story(aa)
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] server, username, password, apikey, workspace, project = rallyWorkset(options) if apikey: rally = Rally(server, apikey=apikey, workspace=workspace, project=project) else: rally = Rally(server, user=username, password=password, workspace=workspace, project=project) rally.enableLogging("rally.hist.add_tcrs") if len(args) < 2: errout(USAGE) sys.exit(1) test_case_id, tcr_info_filename = args if not os.path.exists(tcr_info_filename): errout("ERROR: file argument '%s' does not exist. Respecify using corrent name or path\n" % tcr_info_filename) errout(USAGE) sys.exit(2) try: with open(tcr_info_filename, 'r') as tcif: content = tcif.readlines() tcr_info = [] # each line must have Build, Date, Verdict for ix, line in enumerate(content): fields = line.split(',') if len(fields) != 3: raise Exception('Line #%d has invalid number of fields: %s' % (ix+1, repr(fields))) tcr_info.append([field.strip() for field in fields]) except Exception: errout("ERROR: reading file '%s'. Check the permissions or the content format for correctness." % tcr_info_filename) errout(USAGE) sys.exit(2) test_case = rally.get('TestCase', query="FormattedID = %s" % test_case_id, workspace=workspace, project=None, instance=True) if not test_case or hasattr(test_case, 'resultCount'): print "Sorry, unable to find a TestCase with a FormattedID of %s in the %s workspace" % \ (test_case_id, workspace) sys.exit(3) wksp = rally.getWorkspace() for build, run_date, verdict in tcr_info: tcr_data = { "Workspace" : wksp.ref, "TestCase" : test_case.ref, "Build" : build, "Date" : run_date, "Verdict" : verdict } try: tcr = rally.create('TestCaseResult', tcr_data) except RallyRESTAPIError, details: sys.stderr.write('ERROR: %s \n' % details) sys.exit(4) print "Created TestCaseResult OID: %s TestCase: %s Build: %s Date: %s Verdict: %s" % \ (tcr.oid, test_case.FormattedID, tcr.Build, tcr.Date, tcr.Verdict)
def rallyLogin(self): server = 'rally1.rallydev.com' user = '******' password = '******' project = 'MBH - HNL' workspace = 'default' rally = Rally(server, user, password, workspace=workspace, project=project) rally.enableLogging('mypyral.log') return rally
class RallyClient: rally = None debug = False PrefixActionMap = {"US": "HierarchicalRequirement", "DE": "Defect" } def __init__(self, config): self.rally = Rally(config.rallyUrl, config.username, config.password, workspace="Betfair", project="Betfair") self.rally.enableLogging('rallycli.log') self.debug = config.debug def retrieveItems(self, itemIds): ''' Use pyral to retrieve items from Rally. ''' items = {} for itemId in itemIds: query_criteria = 'formattedID = "%s"' % itemId prefix = itemId[0:2] response = self.rally.get(self.PrefixActionMap[prefix], fetch=True, query=query_criteria) if self.debug: print response.content if response.errors: sys.stdout.write("\n".join(response.errors)) print "ERROR" sys.exit(1) for item in response: # there should only be one qualifying item # items[itemId] = item # print "%s: %s (%s)" % (item.FormattedID, item.Name, item.Project.Name) items[item.FormattedID] = item return items def info(self, args): ''' Return information for specified work items, in a variety of formats. ''' itemIds = args.workItems # print "Retrieving items %s..." % (itemIds) items = self.retrieveItems(itemIds) for itemId, item in items.iteritems(): if item == None: print "ERROR: Could not retrieve item %s from Rally" % itemId else: # print item.attributes() # print item.ObjectID # @TODO Refactor these into configurable/dynamic values baseUrl = "https://rally1.rallydev.com/#" workspaceId = "3254856811d" itemUrl = "%s/%s/detail/userstory/%s" % (baseUrl, workspaceId, item.ObjectID) if args.format == "confluence" : print "# [%s: %s|%s]" % (itemId, item.Name, itemUrl) elif args.format == "conftable" : print "| %s | %s | %s |" % (itemId, item.Name, itemUrl) elif args.format == "csv": print "%s,%s,%s" % (itemId, item.Name, itemUrl) elif args.format == "tsv": print "%s\t%s\t%s" % (itemId, item.Name, itemUrl) else: print "%s: %s (%s)" % (itemId, item.Name, itemUrl)
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] entity = args.pop(0) attributes = args server, user, password, apikey, workspace, project = rallyWorkset(options) print(" ".join([ "|%s|" % item for item in [server, user, password, apikey, workspace, project] ])) #rally = Rally(server, user, password, apikey=apikey, workspace=workspace, project=project, server_ping=False) rally = Rally(server, user, password, apikey=apikey, server_ping=False) rally.enableLogging( 'rally.hist.avl') # name of file you want the logging to go to target = entity if entity in ['Story', 'User Story', 'UserStory']: entity = "HierarchicalRequirement" target = entity mo = CAMEL_CASED_NAME_PATT.search(entity) if mo: txfm = re.sub(CAMEL_CASED_NAME_PATT, r'\1 \2', entity) print('transforming query target "%s" to "%s"' % (entity, txfm)) entity = txfm print("%s" % entity) response = rally.get('TypeDefinition', fetch="Name,Attributes", query='Name = "%s"' % entity) # could check for response.errors here... if response.errors: print("Errors: %s" % response.errors) if response.warnings: print("Warnings: %s" % response.warnings) td = response.next() for attribute in td.Attributes: attr_name = attribute.Name.replace(' ', '') if attributes and attr_name not in attributes: continue if attribute.AttributeType not in ['STATE', 'RATING', 'STRING']: continue allowed_values = rally.getAllowedValues(target, attr_name) if not allowed_values: continue print(" %-28.28s (%s)" % (attr_name, attribute.AttributeType)) for av in allowed_values: print(" |%s|" % av)
def make_story(story_name, story_detail, username): r = Rally(server, apikey=apikey, project=project) r.enableLogging('rally.log') wksp = r.getWorkspace() proj = r.getProject(project) info = {"Workspace": wksp.ref, "Project": proj.ref, "Name": story_name + " (web intake form from " + username + ")", "Story Type": "New Feature", "Description": story_detail} story = r.put('Story', info) return dict_from_story(story)
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] server, username, password, apikey, workspace, project = rallyWorkset(options) print " | ".join([server, username, password, workspace, project]) if apikey: rally = Rally(server, apikey=apikey, workspace=workspace, project=project) else: rally = Rally(server, user=username, password=password, workspace=workspace, project=project) rally.enableLogging('rally.hist.getattachs') # name of file you want logging to go to if len(args) != 2: errout(USAGE) sys.exit(2) entity_name, ident = args if entity_name in STORY_ALIASES: entity_name = 'HierarchicalRequirement' mo = OID_PATT.match(ident) if mo: ident_query = 'ObjectID = %s' % ident else: mo = FORMATTED_ID_PATT.match(ident) if mo: ident_query = 'FormattedID = "%s"' % ident else: errout('ERROR: Unable to determine ident scheme for %s\n' % ident) sys.exit(3) response = rally.get(entity_name, fetch=True, query=ident_query, workspace=workspace, project=project) if response.errors: errout("Request could not be successfully serviced, error code: %d\n" % response.status_code) errout("\n".join(response.errors)) sys.exit(1) if response.resultCount == 0: errout('No item found for %s %s\n' % (entity_name, ident)) sys.exit(4) elif response.resultCount > 1: errout('WARNING: more than 1 item returned matching your criteria\n') artifact = response.next() attachments = rally.getAttachments(artifact) for attachment in attachments: print("-" * 32) print(attachment.Name) print("~" * len(attachment.Name)) print(attachment.Content) print("") print("=" * 64)
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] server, username, password, workspace, project = rallySettings(options) print "|%s| |%s| |%s| |%s| |%s|" % (server, username, '********', workspace, project) rally = Rally(server, username, password, workspace=workspace) # specify the Rally server and credentials rally.enableLogging('rally.hist.periscope') # name of file for logging content for workspace in rally.getWorkspaces(): print "%s %s" % (workspace.oid, workspace.Name) for project in rally.getProjects(workspace=workspace.Name): print " %12.12s %s" % (project.oid, project.Name) print ""
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] server, user, password, apikey, workspace, project = rallyWorkset(options) #rally = Rally(server, user, password, apikey=apikey, workspace=workspace) rally = Rally(server, user, password, workspace=workspace, project=project) rally.enableLogging("rally.history.addtags") if len(args) < 2: print(USAGE) sys.exit(1) story_id = args.pop(0) tag_names = args[:] tags = [] story = rally.get('Story', fetch="FormattedID,Name,Description,Tags", query="FormattedID = %s" % story_id, server_ping=False, isolated_workspace=True, instance=True) response = rally.get('Tag', fetch="true", order="Name", server_ping=False, isolated_workspace=True) for tag in response: print("Workspace %s has tag: %-14.14s created on %s Name: %s" % \ (tag.Workspace.Name, tag.oid, tag.CreationDate[:-5].replace('T', ' '), tag.Name)) if tag.Name in tag_names: tags.append(tag) print("=====================================================") print(", ".join([tag.Name for tag in tags])) adds = rally.addCollectionItems(story, tags) print(adds) droppable_tags = [tag for tag in tags if tag.Name == VICTIM_TAG_NAME] print("dropping Tags %s ..." % ", ".join([tag.Name for tag in droppable_tags])) drops = rally.dropCollectionItems(story, droppable_tags) if drops.errors: print("Problem attempting to drop tags: %s" % drops.errors) sys.exit(2) story = rally.get('Story', fetch="FormattedID,Name,Description,Tags", query="FormattedID = %s" % story_id, server_ping=False, isolated_workspace=True, instance=True) #print(story.details()) print "story tags after deleting the '%s' Tag" % (droppable_tags[0].Name) story_tags = [str(tag.Name) for tag in story.Tags] print(story_tags)
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] server, username, password, apikey, workspace, project = rallyWorkset(options) if apikey: rally = Rally(server, apikey=apikey, workspace=workspace, project=project) else: rally = Rally(server, user=username, password=password, workspace=workspace, project=project) rally.enableLogging('rally.hist.periscope') # name of file for logging content for workspace in rally.getWorkspaces(): print "%s %s" % (workspace.oid, workspace.Name) for project in rally.getProjects(workspace=workspace.Name): print " %12.12s %-36.36s |%s|" % (project.oid, project.Name, project.State) print ""
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] if not args: print USAGE sys.exit(9) # specify the Rally server and credentials server, username, password, workspace, project = rallySettings(options) #print " ".join(["|%s|" % opt for opt in [server, username, '********', workspace]]) rally = Rally(server, user=username, password=password, workspace=workspace, warn=False) rally.enableLogging('rally.hist.chgsets') # name of file you want the logging to go to repo_name = args.pop() showRepoItems(rally, repo_name, workspace=workspace, limit=ITEM_LIMIT)
def main(args): options = [opt for opt in args if opt.startswith("--")] args = [arg for arg in args if arg not in options] server, user, password, apikey, workspace, project = rallyWorkset(options) # print(" ".join(["|%s|" % item for item in [server, user, password, apikey[:8], workspace, project]])) # If you want to use BasicAuth, use the following form rally = Rally(server, user, password, workspace=workspace, project=project) # If you want to use API Key, you can use the following form # rally = Rally(server, apikey=apikey, workspace=workspace, project=project) # the following form of obtaining a Rally instance will use the apikey if it is present (non None) # otherwise it will use the user and password for BasicAuth # add in the debug=True keyword arg if you want more verbiage ... # rally = Rally(server, user, password, apikey=apikey, workspace=workspace, project=project, # debug=True, server_ping=False, isolated_workspace=True) rally.enableLogging("fire.log") specified_workspace = workspace workspace = rally.getWorkspace() print("Workspace: %s " % workspace.Name) if specified_workspace != workspace.Name: print( " ** The workspace you specified: %s is not a valid workspace name for your account, using your default workspace instead" % specified_workspace ) # print "Workspace: %12.12s %-18.18s (%s)" % (workspace.oid, workspace.Name, workspace.ref) project = rally.getProject() print("Project : %s " % project.Name) # uncomment this to see all of your accessible workspaces and projects # workspaces = rally.getWorkspaces() # for workspace in workspaces: # print(" ", workspace.Name) # projects = rally.getProjects(workspace=workspace.Name) # if projects: # print("") # print(" Projects:") # for project in projects: # print(" ", project.Name) # else: # print(" No projects") # print("") sys.exit(0)
def main(): server='rally1.rallydev.com' user='******' password='******' #workspace= #project = rallySettings(options) #print " ".join(["|%s|" % item for item in [server, user, '********', workspace, project]]) rally = Rally(server, user, password) # specify the Rally server and credentials rally.enableLogging('rally.hist.item') # name of file you want logging to go to if len(args) != 1: errout(USAGE) sys.exit(2) ident = 3726723403 mo = FORMATTED_ID_PATT.match(ident) if mo: ident_query = 'FormattedID = "%s"' % ident entity_name = ARTIFACT_TYPE[mo.group('prefix')] else: errout('ERROR: Unable to determine ident scheme for %s\n' % ident) sys.exit(3) response = rally.get(entity_name, fetch=True, query=ident_query) if response.errors: errout("Request could not be successfully serviced, error code: %d\n" % response.status_code) errout("\n".join(response.errors)) sys.exit(1) if response.resultCount == 0: errout('No item found for %s %s\n' % (entity_name, ident)) sys.exit(4) elif response.resultCount > 1: errout('WARNING: more than 1 item returned matching your criteria\n') for item in response: for attr in COMMON_ATTRIBUTES: print " %-16.16s : %s" % (attr, getattr(item, attr)) attrs = [attr for attr in item.attributes() if attr not in COMMON_ATTRIBUTES] for attr in sorted(attrs): attribute = getattr(item, attr) cn = attribute.__class__.__name__ if cn[0] in string.uppercase: attribute = attribute.Name if cn != 'NoneType' else None print " %-16.16s : %s" % (attr, attribute)
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] entity = args.pop(0) attributes = args server, user, password, apikey, workspace, project = rallyWorkset(options) print(" ".join(["|%s|" % item for item in [server, user, password, apikey, workspace, project]])) #rally = Rally(server, user, password, apikey=apikey, workspace=workspace, project=project, server_ping=False) rally = Rally(server, user, password, apikey=apikey,server_ping=False) rally.enableLogging('rally.hist.avl') # name of file you want the logging to go to target = entity if entity in ['Story', 'User Story', 'UserStory']: entity = "HierarchicalRequirement" target = entity mo = CAMEL_CASED_NAME_PATT.search(entity) if mo: txfm = re.sub(CAMEL_CASED_NAME_PATT, r'\1 \2', entity) print('transforming query target "%s" to "%s"' % (entity, txfm)) entity = txfm print("%s" % entity) response = rally.get('TypeDefinition', fetch="Name,Attributes", query='Name = "%s"' % entity) # could check for response.errors here... if response.errors: print("Errors: %s" % response.errors) if response.warnings: print("Warnings: %s" % response.warnings) td = response.next() for attribute in td.Attributes: attr_name = attribute.Name.replace(' ', '') if attributes and attr_name not in attributes: continue if attribute.AttributeType not in ['STATE', 'RATING', 'STRING']: continue allowed_values = rally.getAllowedValues(target, attr_name) if not allowed_values: continue print(" %-28.28s (%s)" % (attr_name, attribute.AttributeType)) for av in allowed_values: print(" |%s|" % av)
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] server, user, password, workspace, project = rallySettings(options) rally = Rally(server, user, password, workspace=workspace, project=project) rally.enableLogging("rally.history.showdefects") fields = "FormattedID,State,Name,Severity,Priority", criterion = 'State != Closed' response = rally.get('Defect', fetch=fields, query=criterion, order="FormattedID", pagesize=200, limit=400) for defect in response: print "%-6.6s %-46.46s %s" % (defect.FormattedID, defect.Name, defect.State) print "-----------------------------------------------------------------" print response.resultCount, "qualifying defects"
def main(args): options = [opt for opt in args if opt.startswith('--')] server, username, password, apikey, workspace, project = rallyWorkset( options) if apikey: rally = Rally(server, apikey=apikey, workspace=workspace) else: rally = Rally(server, user=username, password=password, workspace=workspace) rally.enableLogging("rally.history.blddefs") for workspace, project in wps: rally.setWorkspace(workspace) print("workspace: %s project: %s\n" % (workspace, project)) response = rally.get('BuildDefinition', fetch=True, query='Project.Name = "%s"' % project, order='Name', workspace=workspace, project=project) if response.errors: print(response.errors) sys.exit(9) print("%-12.12s %-10.10s %-36.36s %12s %-20.20s %s" % \ ('BuildDef OID', 'CreateDate', 'BuildDefinition.Name', 'LastStatus', 'LastBuildDateTime', 'NumBuilds')) print("%-12.12s %-10.10s %-36.36s %10s %-19.19s %s" % \ ('-' * 12, '-' * 10, '-' * 36, '-' * 10, '-' * 19, '-' * 9)) for builddef in response: if builddef.LastStatus == "NO BUILDS": print("%s %s %-24.24s NO BUILDS" % \ (builddef.oid, builddef.CreationDate[:10], builddef.Name)) continue lbt = builddef.LastBuild.CreationDate.split('T') last_build_time = "%s %s" % (lbt[0], lbt[1][:8]) bdf = "%12.12s %-10.10s %-36.36s %12s %-20.20s %4s" print(bdf % (builddef.oid, builddef.CreationDate[:10], builddef.Name, builddef.LastStatus, last_build_time, len(builddef.Builds)))
def test_query_with_special_chars_in_criteria(): """ DE3228 in DEFAULT_WORKSPACE / NON_DEFAULT_PROJECT has Name = Special chars:/!@#$%^&*()-=+[]{};:./<>?/ query for it by looking for it by the name value """ rally = Rally(server=TRIAL, user=TRIAL_USER, password=TRIAL_PSWD) rally.setWorkspace(DEFAULT_WORKSPACE) rally.setProject(NON_DEFAULT_PROJECT) rally.enableLogging('spec_char_query') criteria = 'Name = "distinctive criteria of -32% degradation in rust protection"' response = rally.get('Defect', fetch=True, query=criteria, limit=10) assert response.__class__.__name__ == 'RallyRESTResponse' assert response.status_code == 200 assert response.errors == [] assert response.warnings == [] assert response.resultCount == 1 criteria = 'Name = "Looking for the #blowback hashtag"' response = rally.get('Defect', fetch=True, query=criteria, limit=10) assert response.status_code == 200 assert response.errors == [] assert response.warnings == [] assert response.resultCount == 1 special_chars = "/!@#$%^*_-+=?{}[]:;,<>" # characters that break the RallyQueryFormatter and/or WSAPI: ( ) ~ & | backslash for character in special_chars: criteria = 'Name contains "%s"' % character response = rally.get('Defect', fetch=True, query=criteria, limit=10) assert response.__class__.__name__ == 'RallyRESTResponse' assert response.status_code == 200 assert response.errors == [] assert response.warnings == [] assert response.resultCount >= 1 criteria = 'Name = "Special chars:/!@#$%^*-=+[]{};:.<>? in the name field"' response = rally.get('Defect', fetch=True, query=criteria, limit=10) assert response.__class__.__name__ == 'RallyRESTResponse' assert response.status_code == 200 assert response.errors == [] assert response.warnings == [] assert response.resultCount >= 1
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] server, user, password, workspace, project = rallySettings(options) print " ".join(["|%s|" % item for item in [server, user, '********', workspace, project]]) rally = Rally(server, user, password, workspace=workspace, version="1.30") # specify the Rally server and credentials rally.enableLogging('rally.hist.creattach') # name of file you want logging to go to if len(args) != 2: errout('ERROR: You must supply an Artifact identifier and an attachment file name') errout(USAGE) sys.exit(1) target, attachment_file_name = args artifact = validateTarget(rally, target) me = rally.getUserInfo(username=user).pop(0) #print "%s user oid: %s" % (user, me.oid) att = rally.addAttachment(artifact, attachment_file_name) print "created Attachment: %s for %s" % (attachment_file_name, target)
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] server, username, password, apikey, workspace, project = rallyWorkset(options) if apikey: rally = Rally(server, apikey=apikey, workspace=workspace, project=project) else: rally = Rally(server, user=username, password=password, workspace=workspace, project=project) rally.enableLogging("rally.history.showdefects") fields = "FormattedID,State,Name,Severity,Priority" criterion = 'State != Closed' response = rally.get('Defect', fetch=fields, query=criterion, order="FormattedID", pagesize=200, limit=400) for defect in response: print("%-8.8s %-52.52s %s" % (defect.FormattedID, defect.Name, defect.State)) print("-----------------------------------------------------------------") print(response.resultCount, "qualifying defects")
def test_query_with_matched_parens_in_condition_value(): """ 'REST Toolkit Testing' / 'Sample Project' has a Release in it whose name contains a matched paren pair make sure a query containing a condition looking for the Release by this name succeeds. """ target_workspace = 'REST Toolkit Testing' target_project = 'Sample Project' rally = Rally(server=TRIAL, user=TRIAL_USER, password=TRIAL_PSWD, workspace=target_workspace, project=target_project) rally.enableLogging('query_condition_value_has_matched_internal_parens') criteria = 'Name = "8.5 (Blah and Stuff)"' response = rally.get('Release', fetch=True, query=criteria, limit=10) assert response.__class__.__name__ == 'RallyRESTResponse' assert response.status_code == 200 assert response.errors == [] assert response.warnings == [] assert response.resultCount >= 1 release = response.next() assert release.Name == '8.5 (Blah and Stuff)'
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] if len(args) != 1: errout(USAGE) sys.exit(1) storyID = args[0] server, user, password, apikey, workspace, project = rallyWorkset(options) if apikey: rally = Rally(server, apikey=apikey, workspace=workspace, project=project) else: rally = Rally(server, user=username, password=password, workspace=workspace, project=project) rally.enableLogging("rally.history.crtask") # For a task: Workspace, Project, WorkProduct, Name, State, TaskIndex are required; # Workspace cannot be specified in the JSON, it defaults to # the logged in account's Workspace setting # Project and WorkProduct must be object refs to relevant Rally Entity instances. # In this example the WorkProduct is a UserStory (HierarchicalRequirement). target_project = rally.getProject() target_story = rally.get('UserStory', query='FormattedID = %s' % storyID, instance=True) info = { "Project" : target_project.ref, "WorkProduct" : target_story.ref, "Name" : "BigTaters", "State" : "Defined", "TaskIndex" : 1, "Description" : "Fly to Chile next week to investigate the home of potatoes. Find the absolute gigantoidist spuds and bring home the eyes to Idaho. Plant, water, wonder, harvest, wash, slice, plunge in and out of hot oil, drain and enjoy! Repeat as needed.", "Estimate" : 62.0, "Actuals" : 1.0, "ToDo" : 61.0, "Notes" : "I have really only done some daydreaming wrt this task. Sorry Jane, I knew you had big plans for Frankie's blowout BBQ next month, but the honeycomb harvest project is taking all my time." } print "Creating Task ..." task = rally.put('Task', info) print "Created Task: %s OID: %s" % (task.FormattedID, task.oid)
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] server, username, password, apikey, workspace, project = rallyWorkset(options) if apikey: rally = Rally(server, apikey=apikey, workspace=workspace, project=project) else: rally = Rally(server, user=username, password=password, workspace=workspace, project=project) rally.enableLogging("rally.history.showstories") fields = "FormattedID,Name,Iteration,Feature" #criterion = 'Iteration.Name contains "Iteration 7"' criterion = '((Iteration.Name contains "Iteration 6")OR(Iteration.Name contains "Iteration 7")) AND (Feature != null)' response = rally.get('HierarchicalRequirement', fetch=fields, query=criterion, order="FormattedID", pagesize=200, limit=400) for story in response: print "%-8.8s %-52.52s %s %s" % (story.FormattedID, story.Name, story.Iteration.Name, story.Feature.Name) print "-----------------------------------------------------------------" print response.resultCount, "qualifying stories"