From c7be258e11aab434ecdbb6b17782d0b4d2019548 Mon Sep 17 00:00:00 2001 From: Jamo Luhrsen Date: Fri, 5 May 2017 16:16:47 -0700 Subject: [PATCH] Give some life to AAA CSIT suite I have no idea if/how/when this suite and it's library ever worked. I am not trying to do anything here but make it work. Locally, these changes give 13 pass, 4 failures. I think the 4 failures may be valid bugs, and will follow up with that. Currently, upstream this suite is failing every test case and has for as long as I know. The python AAAJsonUtils.py library is not used by any other suites so the changes will not affect anyone else. Again, I was not looking to be pretty/nice/refactor/etc. I just wanted to see this stuff start to work. Change-Id: I3438e7e197d673b2afc37033cf446dfa57c5f9ff Signed-off-by: Jamo Luhrsen --- csit/libraries/AAAJsonUtils.py | 76 +++++-------------- .../idmlite/010_CRUD_Rest_CommandsTests.robot | 30 ++++---- 2 files changed, 36 insertions(+), 70 deletions(-) diff --git a/csit/libraries/AAAJsonUtils.py b/csit/libraries/AAAJsonUtils.py index 35994589fe..b39b9b39b7 100644 --- a/csit/libraries/AAAJsonUtils.py +++ b/csit/libraries/AAAJsonUtils.py @@ -158,7 +158,7 @@ def get_id_by_name(args): :returns nodelist: return the first id that has same corresponding name """ try: - jsonobj = json.loads(args['jsonblob']) + jsonobj = json.loads(str(args['jsonblob'])) except KeyError: print "get_id_by_name: json blob not specified:" raise @@ -199,34 +199,15 @@ def get_id_by_name(args): bkey2 = '$.' + blobkey + '[' + str(i) + '].' + typename # find records with same name - name_record = jsonpath.jsonpath(jsonobj, bkey1) + name_record = jsonobj[blobkey][i]['name'] # find corresponding node info, for that name - node_record = jsonpath.jsonpath(jsonobj, bkey2) - - # build up an alternative set of keys. This lets you deal with - # other format of json - bkey3 = '$.' + blobkey + '.name' - typename2 = datatype + 'id' - bkey4 = '$.' + blobkey + '.' + typename2 + node_record = jsonobj[blobkey][i][typename] - # find records with same name - altname_record = jsonpath.jsonpath(jsonobj, bkey3) - # find corresponding record node info, for that name - altnode_record = jsonpath.jsonpath(jsonobj, bkey4) try: - if name in list(name_record): - nodelist.append(node_record.pop()) + if name == name_record: + return node_record except: - try: - if name in list(altname_record): - nodelist.append(altnode_record.pop()) - except: - raise - - try: - return nodelist.pop() - except LookupError: - raise + raise def get_attribute_by_id(args): @@ -290,44 +271,24 @@ def get_attribute_by_id(args): print "get_attribute_by_id: specify number of records we need" raise + typename = datatype + 'id' + # Loop through the records looking for the nodeid, when found, return # the corresponding attribute value ncount = size if ncount > 0: for i in range(ncount): - bkey1 = '$.' + blobkey + '[' + str(i) + '].' + attr - bkey2 = '$.' + blobkey + '[' + str(i) + '].' + datatype + 'id' - - bkey3 = '$.' + blobkey + '.' + attr - bkey4 = '$.' + blobkey + '.' + datatype + 'id' - - name_record = jsonpath.jsonpath(jsonobj, bkey1) - node_record = jsonpath.jsonpath(jsonobj, bkey2) - altname_record = jsonpath.jsonpath(jsonobj, bkey3) - altnode_record = jsonpath.jsonpath(jsonobj, bkey4) - - if type(node_record) is list: - if nodeid in list(node_record): - return name_record.pop() - else: - try: - node_record - except: - print "not in list" - else: - return name_record - - if type(altnode_record) is list: - if nodeid in list(altnode_record): - return altname_record.pop() - else: - try: - altnode_record - except: - print "not in list" - else: - return altname_record + + try: + name_record = jsonobj[blobkey][i]['name'] + node_record = jsonobj[blobkey][i][typename] + except: + name_record = jsonobj['name'] + node_record = jsonobj[typename] + + if nodeid == node_record: + return name_record def get_role_id_by_rolename(pobject, rolename, number_nodes): @@ -461,6 +422,7 @@ def get_domain_id_by_domainname(pobject, domainname, number_nodes): the domain-name given """ domainid = get_id_by_name({'jsonblob': pobject, + 'head': 'domains', 'name': domainname, 'size': number_nodes, 'typeval': 'domain'}) diff --git a/csit/suites/aaa/idmlite/010_CRUD_Rest_CommandsTests.robot b/csit/suites/aaa/idmlite/010_CRUD_Rest_CommandsTests.robot index 37958c5b2b..27eae36a1f 100644 --- a/csit/suites/aaa/idmlite/010_CRUD_Rest_CommandsTests.robot +++ b/csit/suites/aaa/idmlite/010_CRUD_Rest_CommandsTests.robot @@ -81,7 +81,6 @@ Test Get Domains ${content}= Get Domains # parse through that massive blob and get the individual name created in Setup ${node_count}= Nodecount ${content} domains domainid - ${domainid}= Convert To Integer ${domainid} # Get the domain name from the database, looking it up by its domainid ${domainentry}= Get Domain Name By Domainid ${content} ${domainid} ${node_count} Log ${domainentry} @@ -170,7 +169,6 @@ Test Get Users ${content}= Get Users # parse through that massive blob and get the individual name ${node_count}= Nodecount ${content} users userid - ${userid}= Convert To Integer ${userid} ${userentry}= Get User Name By Userid ${content} ${userid} ${node_count} Log ${userentry} # compare to see if the parsed user id matches the one we grabbed from list @@ -227,7 +225,7 @@ Test Post New User [Documentation] Test the POST command to create a new user. # create information for a new role (for the test) ${testusername}= Create Random Name Darth-Maul - ${data}= Set Variable {"description":"sample user description", "name":"${testusername}", "userid":1} + ${data}= Set Variable {"description":"sample user description", "name":"${testusername}", "userid":1,"domainid":"${testdomain}","email":"${testemail}"} Log ${testusername} # Post this puppy ${content}= Post New User ${testusername} ${data} @@ -246,7 +244,7 @@ Test Delete User # create a user and then delete it. Use Get to verify it's gone # create information for a new user (for the test) ${testusername}= Create Random Name force-user - ${data}= Set Variable {"description":"sample test description", "name":"${testusername}", "userid":1} + ${data}= Set Variable {"description":"sample test description", "name":"${testusername}", "userid":1,"domainid":"${testdomain}","email":"${testemail}"} Log ${testusername} # Post this disposable user ${content}= Post New User ${testusername} ${data} @@ -295,7 +293,7 @@ Test Get Roles ${content}= Get Roles # parse through that massive blob and get the individual name ${node_count}= Nodecount ${content} roles roleid - ${roleid}= Convert To Integer ${roleid} + # ${roleid}= Convert To Integer ${roleid} ${roleentry}= Get Role Name By Roleid ${content} ${roleid} ${node_count} Log ${roleentry} # compare to see if the parsed user id matches the one we grabbed from list @@ -327,7 +325,7 @@ Test Post New Role [Documentation] Exercise POST command to create a new Role. # create information for a new role (for the test) ${testrolename}= Create Random Name force-brother-cousin - ${data}= Set Variable {"description":"sample test description", "name":"${testrolename}", "roleid":1} + ${data}= Set Variable {"description":"sample test description", "name":"${testrolename}", "roleid":1,"domainid":"${testdomain}"} Log ${testrolename} # Post this puppy ${content}= Post New Role ${data} @@ -347,7 +345,7 @@ Test Delete Role # create a role and then delete it. Use Get to verify it's gone # create information for a new role (for the test) ${testrolename}= Create Random Name force-usurper - ${data}= Set Variable {"description":"sample test description", "name":"${testrolename}", "roleid":1} + ${data}= Set Variable {"description":"sample test description", "name":"${testrolename}", "roleid":1,"domainid":"${testdomain}"} Log ${testrolename} # Post this disposable role ${content}= Post New Role ${data} @@ -389,7 +387,7 @@ Test Grant Role To Domain And User ${domainname}= Parse Item From Blob By Offset ${domain_item} 1 Log ${domainname} # generate the data payload that we wish to post - ${data}= Set Variable {"roleid":"${roleid}", "description":"fabricated test roleid"} + ${data}= Set Variable {"roleid":"${roleid}"} # post this monster ${content}= Post Role To Domain And User ${data} ${domainid} ${userid} # add new json string to the cleanup list for later cleanup @@ -405,9 +403,11 @@ IdMLight Suite Setup Set Global Variable ${HEADERS} # create a name to use in each case ${testdomain}= Create Random Name Alderaan + Set Suite Variable ${testdomain} ${testuser}= Create Random Name Leia ${testrole}= Create Random Name Force-User ${testemail}= Set Variable sdn@opendaylight.org + Set Suite Variable ${testemail} # now create the domain, role and userid # create the test domain Create Session httpbin ${URI} auth=${AUTH} headers=${HEADERS} @@ -416,12 +416,12 @@ IdMLight Suite Setup # add new domain name to the cleanup list for later cleanup Append To List ${cleanup_domain_list} ${newdomain} # now create the test user - ${userdata}= Set Variable {"description":"User-of-the-Force","name":"${testuser}","enabled":"true","domainid":"${testdomain}", "email":"${testemail}"} + ${userdata}= Set Variable {"description":"User-of-the-Force","name":"${testuser}","enabled":"true","domainid":"${testdomain}","email":"${testemail}"} ${newuser}= Post New User ${testuser} ${userdata} # add new user name to the cleanup list for later cleanup Append To List ${cleanup_user_list} ${newuser} # now create the test role - ${roledata}= Set Variable {"name":"${testrole}","description":"Force User"} + ${roledata}= Set Variable {"name":"${testrole}","description":"Force User","domainid":"${testdomain}"} ${newrole}= Post New Role ${roledata} # add new role name to the cleanup list for later cleanup Append To List ${cleanup_role_list} ${newrole} @@ -440,6 +440,7 @@ IdMLight Suite Teardown \ ${y}= Get From List ${x} 0 \ ${z}= Split String ${y} : \ ${domainid}= Get From List ${z} 1 + \ ${domainid}= Strip Quotes ${domainid} \ Log ${domainid} \ # convert name on the list to an ID, by which we delete this stuff \ Delete Domain ${domainid} @@ -454,6 +455,7 @@ IdMLight Suite Teardown \ ${y}= Get From List ${x} 0 \ ${z}= Split String ${y} : \ ${roleid}= Get From List ${z} 1 + \ ${roleid}= Strip Quotes ${roleid} \ Log ${roleid} \ # convert name on the list to an ID, by which we delete this stuff \ Delete Role ${roleid} @@ -468,6 +470,7 @@ IdMLight Suite Teardown \ ${y}= Get From List ${x} 0 \ ${z}= Split String ${y} : \ ${userid}= Get From List ${z} 1 + \ ${userid}= Strip Quotes ${userid} \ Log ${userid} \ Delete User ${userid} Log ${cleanup_user_list} @@ -572,6 +575,8 @@ Post New User # grab the list of users, count the list, and then search the list for the specific user id ${users}= Get Users ${depth}= Nodecount ${users} users userid + Log ${resp.status_code} + Log ${resp.content} ${abc}= Get User Id By Username ${users} ${username} ${depth} Should Be Equal As Strings ${resp.status_code} 201 Should Contain ${resp.content} ${username} @@ -674,9 +679,8 @@ Parse Item From Blob By Offset Create Random Name [Arguments] ${basename} [Documentation] Take the basename given and return a new name with date-time-stamp appended. - ${datetime}= Get Current Date result_format=%Y-%m-%d-%H-%M - Log ${datetime} - ${newname}= Catenate SEPARATOR=- ${basename} ${datetime} + ${random_number}= Generate Random String 6 [NUMBERS] + ${newname}= Catenate SEPARATOR=- ${basename} ${random_number} [Return] ${newname} Pop Name Off Json -- 2.36.6