Skip to content

Commit

Permalink
fixed problem not being able to find ETM configuraitons for opt-in pr…
Browse files Browse the repository at this point in the history
…ojects - not sure about opt-out
  • Loading branch information
barny committed Oct 5, 2023
1 parent b08b76e commit a74693c
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
63 changes: 61 additions & 2 deletions elmclient/_qm.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(self, name, project_uri, app, is_optin=False, singlemode=False,defa
self.is_singlemode = False # this is only true if config enabled is true and single mode is true
self.gcconfiguri = None
self.default_query_resource = "oslc_qm:TestCaseQuery"
self._confs_to_load = []

def load_components_and_configurations(self,force=False):
if self._components is not None and self._configurations is not None and not force:
Expand Down Expand Up @@ -70,7 +71,7 @@ def load_components_and_configurations(self,force=False):
assert compuri is not None, "compuri is None"

ncomps += 1
self._components[compuri] = {'name': self.name, 'configurations': {}}
self._components[compuri] = {'name': self.name, 'configurations': {}, 'confs_to_load': []}
configs = self.execute_get_xml( compuri+"/configurations", intent="Retrieve all project/component configurations (singlemode)" )
for conf in rdfxml.xml_find_elements(configs,'.//rdfs:member'):
confu = rdfxml.xmlrdf_get_resource_uri(conf)
Expand Down Expand Up @@ -121,9 +122,10 @@ def load_components_and_configurations(self,force=False):
compu = rdfxml.xmlrdf_get_resource_uri(component_el)
comptitle = rdfxml.xmlrdf_get_resource_text(component_el, './/dcterms:title')
logger.info( f"Found component {comptitle}" )
self._components[compu] = {'name': comptitle, 'configurations': {}}
ncomps += 1
confu = rdfxml.xmlrdf_get_resource_uri(component_el, './/oslc_config:configurations')
self._components[compu] = {'name': comptitle, 'configurations': {}, 'confs_to_load': [confu]}

configs_xml = self.execute_get_rdf_xml( confu, intent="Retrieve all project/component configuration definitions" )
# Each config: <ldp:contains rdf:resource="https://jazz.ibm.com:9443/qm/oslc_config/resources/com.ibm.team.vvc.Configuration/_qT1EcEB4Eeus6Zk4qsm_Cw"/>

Expand All @@ -149,6 +151,8 @@ def load_components_and_configurations(self,force=False):
else:
c = self._create_component_api(cu, cname)
c._configurations = self._components[cu]['configurations']
c._confs_to_load = self._components[cu]['confs_to_load']
self._confs_to_load.extend(self._components[cu]['confs_to_load'])
self._components[cu]['component'] = c
return (ncomps, nconfs)

Expand All @@ -174,6 +178,61 @@ def get_local_config(self, name_or_uri, global_config_uri=None):
return cu
return None

def load_configs(self):
# load configurations
while self._confs_to_load:
confu = self._confs_to_load.pop()
if not confu:
# skip None in list
continue
logger.debug( f"Retrieving config {confu}" )
try:
configs_xml = self.execute_get_rdf_xml(confu, intent="Retrieve a configuration definition")
except:
logger.info( f"Config ERROR {thisconfu} !!!!!!!" )
continue
confmemberx = rdfxml.xml_find_elements(configs_xml, './/rdfs:member[@rdf:resource]')
if confmemberx:
# a list of members
for confmember in confmemberx:
thisconfu = confmember.get("{%s}resource" % rdfxml.RDF_DEFAULT_PREFIX["rdf"])
self._confs_to_load.append(thisconfu)
# maybe it's got configuration(s)
confmemberx = rdfxml.xml_find_elements(configs_xml, './/oslc_config:Configuration') + rdfxml.xml_find_elements(configs_xml, './/oslc_config:Stream') + rdfxml.xml_find_elements(configs_xml, './/oslc_config:Baseline') + rdfxml.xml_find_elements(configs_xml, './/oslc_config:ChangeSet')

for confmember in confmemberx:
thisconfu = rdfxml.xmlrdf_get_resource_uri( confmember )
logger.debug( f"{thisconfu=}" )
conftitle = rdfxml.xmlrdf_get_resource_text(confmember, './/dcterms:title')
if rdfxml.xmlrdf_get_resource_uri( confmember,'.//rdf:type[@rdf:resource="http://open-services.net/ns/config#ChangeSet"]') is not None:
conftype = "ChangeSet"
elif rdfxml.xmlrdf_get_resource_uri( confmember,'.//rdf:type[@rdf:resource="http://open-services.net/ns/config#Baseline"]') is not None:
conftype = "Baseline"
elif rdfxml.xmlrdf_get_resource_uri( confmember,'.//rdf:type[@rdf:resource="http://open-services.net/ns/config#Stream"]') is not None:
conftype = "Stream"
elif rdfxml.xmlrdf_get_resource_uri( confmember,'.//rdf:type[@rdf:resource="http://open-services.net/ns/config#Configuration"]') is not None:
conftype = "Stream"
else:
print( ET.tostring(confmember) )
raise Exception( f"Unrecognized configuration type" )
created = rdfxml.xmlrdf_get_resource_uri(confmember, './/dcterms:created')
if thisconfu not in self._configurations:
logger.debug( f"Adding {conftitle}" )
self._configurations[thisconfu] = {
'name': conftitle
, 'conftype': conftype
,'confXml': confmember
,'created': created
}
# self._configurations[thisconfu] = self._components[self.project_uri]['configurations'][thisconfu]
else:
logger.debug( f"Skipping {thisconfu} because already defined" )
# add baselines and changesets
self._confs_to_load.append( rdfxml.xmlrdf_get_resource_uri(confmember, './oslc_config:streams') )
self._confs_to_load.append( rdfxml.xmlrdf_get_resource_uri(confmember, './oslc_config:baselines') )
self._confs_to_load.append( rdfxml.xmlrdf_get_resource_uri(confmember, './rm_config:changesets') )


def list_configs( self ):
configs = []
self.load_configs()
Expand Down
8 changes: 7 additions & 1 deletion elmclient/examples/oslcquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ def do_oslc_query(inputargs=None):
raise Exception( f"Multiple matches for GC configuration {args.globalconfiguration}" )
gcconfiguri = list(conf.keys())[0]
logger.info( f"{gcconfiguri=}" )
logger.debug( f"{gcconfiguri=}" )
# check the gc config uri exists - a GET from it shouldn't fail!
if not gcapp.check_valid_config_uri(gcconfiguri,raise_exception=False):
raise Exception( f"GC configuration URI {gcconfiguri} not valid!" )
Expand Down Expand Up @@ -385,6 +384,7 @@ def do_oslc_query(inputargs=None):
for c in c.list_configs():
print( f" '{c}'" )
raise Exception( f"Configuration '{args.configuration}' not found in component {args.component}" )

queryon = c

elif gcconfiguri:
Expand Down Expand Up @@ -413,6 +413,12 @@ def do_oslc_query(inputargs=None):
queryon = p
queryon.set_local_config(config,gcconfiguri)
logger.debug( f"setting {config=} {gcconfiguri=}" )
if args.verbose:
if config:
print( f"Local config {config}" )
if gcconfiguri:
print( f"Global config {gcconfiguri}" )

# we're querying the component
else:
if args.saveconfigs:
Expand Down
2 changes: 1 addition & 1 deletion elmclient/httpops.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def get_auth_path(self, request_url, response):
def tidy_cookies(self):
'''
LQE 7.0.2SR1 and 7.0.3 has the unpleasant habit of including double-quotes in the auth cookie path so it looks like "/lqe" (which includes the quotation marks in the path) rather than /lqe, and then the path is never matched so authentication is lost
This code cleans up the path on all cookies on the session4
This code cleans up the path on all cookies on the session
# return True if any cookie changed
'''
result = False
Expand Down
3 changes: 2 additions & 1 deletion elmclient/oslcqueryapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ def _execute_vanilla_oslc_query(self, querycapabilityuri, query_params, orderby=
fullurl = f"{query_url}?{urllib.parse.urlencode( params, quote_via=urllib.parse.quote, safe='/')}"
if verbose:
print( f"Full query URL is {fullurl}" )

# print( f"Full query URL is {fullurl}" )
# retrieve all pages of results - they will be processed later
total = 1
Expand Down Expand Up @@ -808,7 +809,7 @@ def _execute_vanilla_oslc_query(self, querycapabilityuri, query_params, orderby=
# dup = False
else:
# dup = True
# print( f"DUP {about}" )
print( f"DUPLICATED RESULT {about}" )
# print( f"{result[about]=}" )
# print( f"{desc=}" )
# print( f"{ET.tostring(desc)=}" )
Expand Down

0 comments on commit a74693c

Please sign in to comment.