From a74693cd1cf3b54afe0f718816ef168fcf51cddb Mon Sep 17 00:00:00 2001 From: Ian Barnard Date: Thu, 5 Oct 2023 09:25:45 +0100 Subject: [PATCH] fixed problem not being able to find ETM configuraitons for opt-in projects - not sure about opt-out --- elmclient/_qm.py | 63 +++++++++++++++++++++++++++++++-- elmclient/examples/oslcquery.py | 8 ++++- elmclient/httpops.py | 2 +- elmclient/oslcqueryapi.py | 3 +- 4 files changed, 71 insertions(+), 5 deletions(-) diff --git a/elmclient/_qm.py b/elmclient/_qm.py index 648ed09..40e0c22 100644 --- a/elmclient/_qm.py +++ b/elmclient/_qm.py @@ -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: @@ -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) @@ -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: @@ -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) @@ -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() diff --git a/elmclient/examples/oslcquery.py b/elmclient/examples/oslcquery.py index 5b84369..bd947f6 100644 --- a/elmclient/examples/oslcquery.py +++ b/elmclient/examples/oslcquery.py @@ -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!" ) @@ -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: @@ -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: diff --git a/elmclient/httpops.py b/elmclient/httpops.py index 2d6e8c2..cfd3182 100644 --- a/elmclient/httpops.py +++ b/elmclient/httpops.py @@ -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 diff --git a/elmclient/oslcqueryapi.py b/elmclient/oslcqueryapi.py index dbf46d5..f6514b1 100644 --- a/elmclient/oslcqueryapi.py +++ b/elmclient/oslcqueryapi.py @@ -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 @@ -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)=}" )