: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
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):
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):
the domain-name given
"""
domainid = get_id_by_name({'jsonblob': pobject,
+ 'head': 'domains',
'name': domainname,
'size': number_nodes,
'typeval': 'domain'})
${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}
${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
[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}
# 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}
${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
[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}
# 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}
${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
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}
# 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}
\ ${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}
\ ${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}
\ ${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}
# 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}
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