Library scope: | GLOBAL |
---|
AAAJSonUtils library for looking up relevant information in a json record
This library can be used to take a chunk of json results and mine out needed information for testing. Author: Carmen Kelling - HP Enterprise
Count the number of nodes in a chunk of JSON.
Because json blobs come in multiple forms, use node, subnode or category to assist in defining what to count.
Args: :param jsonblob: a smattering of JSON data to work through :param node: a node to look for such as users, groups, domains :param subnode: a sub-item to look for, such as domainid :param category: from a simple json record, a field to look for
Returns: :returns ctr: the correct number of records have in the json
Helper-func - use countnodes to count the occurences of field in pobject
example count the occurences of domainid in this single record...
[ { "description": "default odl sdn domain", "domainid": 1, "enabled": "true", "name": "MasterTest Domain" } ]
Args: :param pobject: JSON code to work through :param field: an element to search for and count
Returns: :returns number_nodes: the correct number of fields you counted in the json
Get an attribute by the id field.
Each json record in the json blob has a unique ID, return the corresponding attribute field from that record. Could be description, name, email, password, or any field in available in that record.
Args: :param jsonblob: a smattering of JSON code to work through :param id: the ID to look up in the database of json :param head: will be one of roles, users, domains :param typeval: literal value of either user, role or domain :param size: a count on the number of records to search
Returns: :returns name_record: the name attribute value that corresponds to the provided id
Helper-func - get the domaind descripton for a particular domainid
sample record... "domains": [ { "description": "default odl sdn domain", "domainid": 1, "enabled": true, "name": "admin" } { ... } ]
Args: :param pobject: JSON blob to work through :param domainid: the identifier element to search for :param number_nodes: number of records to process
Returns: :returns domainname: the domain description field that corresponds to the record identified by the domainid
Helper-func - get all domain-ids corresponding to domain-name
sample record... "domains": [ { "description": "default odl sdn domain", "domainid": 1, "enabled": true, "name": "admin" } { ... } ]
Args: :param pobject: JSON blob to work through :param domainname: the name element to search for :param number_nodes: number of records to process
Returns: :returns domainid: a list of one or more domain-id's that match the domain-name given
Helper-func - get domain-name for a particular domainid
sample record... "domains": [ { "description": "default odl sdn domain", "domainid": 1, "enabled": true, "name": "admin" } { ... } ]
Args: :param pobject: JSON blob to work through :param domainid: the identifier element to search for :param number_nodes: number of records to process
Returns: :returns domainname: the domain name that corresponds to the record identified by the domainid
Helper-func - get domain state field for a particular domainid
sample record... "domains": [ { "description": "default odl sdn domain", "domainid": 1, "enabled": true, "name": "admin" } { ... } ]
Args: :param pobject: JSON blob to work through :param domainid: the identifier element to search for :param number_nodes: number of records to process
Returns: :returns domainstate: the domain state (enabled) field that corresponds to the record identified by the domainid
Get an ID by the Name field.
Go through the json given, and pull out all ids that are identified by the corresponding name argument.
Args: :param jsonblob: a smattering of JSON code to work through :param name: a name to look up in the database of json :param head: will be one of roles, users, domains :param typeval: literal value of either user, role or domain :param size: a count on the number of records to search
Returns: :returns nodelist: return the first id that has same corresponding name
Helper-func - get role-description for a role-id
sample record... "roles": [ { "description": "a role for admins", "name": "admin", "roleid": 1 } { ... } ]
Args: :param pobject: JSON blob to work through :param roleid: the identifier element to search for :param number_nodes: number of records to process
Returns: :returns roledesc: the role description that corresponds to the record identified by the role-id
Helper-func - use get_id_by_name to obtain role-ids for a role-name
sample record... "roles": [ { "description": "a role for admins", "name": "admin", "roleid": 1 } { ... } ]
Args: :param pobject: JSON blob to work through :param rolename: the name element to search for :param number_nodes: number of records to process
Returns: :returns roleid: a list of one or more roleid's that match the rolename given
Helper-func - use get_attribute_by_id to get role-name for a role-id
sample record... "roles": [ { "description": "a role for admins", "name": "admin", "roleid": 1 } { ... } ]
Args: :param pobject: JSON blob to work through :param roleid: the identifier element to search for :param number_nodes: number of records to process
Returns: :returns rolename: the role name that corresponds to the record identified by the role-id
Helper-func - get user description field for a particular userid
sample record... "users": [ { "description": "admin user", "email": "admin@anydomain.com", "enabled": true, "userid": 1, "name": "admin", "password": "********", "userid": 1 } { ... } ]
Args: :param pobject: JSON blob to work through :param userid: the identifier element to search for :param number_nodes: number of records to process
Returns: :returns userdesc: the description field that corresponds to the record identified by the userid
Helper-func - get user email field for a particular userid
sample record... "users": [ { "description": "admin user", "email": "admin@anydomain.com", "enabled": true, "userid": 1, "name": "admin", "password": "********", "userid": 1 } { ... } ]
Args: :param pobject: JSON blob to work through :param userid: the identifier element to search for :param number_nodes: number of records to process
Returns: :returns useremail: the email field that corresponds to the record identified by the userid
Helper-func - get user-ids corresponding to username
sample record... "users": [ { "description": "admin user", "email": "admin@anydomain.com", "enabled": true, "userid": 1, "name": "admin", "password": "********", "userid": 1 } { ... } ]
Args: :param pobject: JSON blob to work through :param username: the name element to search for :param number_nodes: number of records to process
Returns: :returns userid: a list of one or more user-id's that match the username given
Helper-func - get the username field for a particular userid
sample record... "users": [ { "description": "admin user", "email": "admin@anydomain.com", "enabled": true, "userid": 1, "name": "admin", "password": "********", "userid": 1 } { ... } ]
Args: :param pobject: JSON blob to work through :param userid: the identifier element to search for :param number_nodes: number of records to process
Returns: :returns username: the name field that corresponds to the record identified by the userid
Helper-func - get user password field for a particular userid
sample record... "users": [ { "description": "admin user", "email": "admin@anydomain.com", "enabled": true, "userid": 1, "name": "admin", "password": "********", "userid": 1 } { ... } ]
Args: :param pobject: JSON blob to work through :param userid: the identifier element to search for :param number_nodes: number of records to process
Returns: :returns userpassword: the raw password field that corresponds to the record identified by the userid
Helper-func - get user state field for a particular userid
sample record... "users": [ { "description": "admin user", "email": "admin@anydomain.com", "enabled": true, "userid": 1, "name": "admin", "password": "********", "userid": 1 } { ... } ]
Args: :param pobject: JSON blob to work through :param userid: the identifier element to search for :param number_nodes: number of records to process
Returns: :returns userstate: the enabled field that corresponds to the record identified by the userid
Helper-func - use countnodes function to count node of a category type
example count the domainid in these properly formatted json blobs...
"domains: [ { "description": "odl master domain", "domainid": 1, "enabled": "true", "name": "Master Test Domain" } { "description": "sdn user domain", "domainid": 2, "enabled": "true", "name": "User Domain" } ... ] "users": [ ... ]
Args: :param pobject: JSON code to work through :param node: a node, such as domainid, to search for in a properly formatted json object, and count
Returns: :returns number_nodes: the correct number of fields you counted in the json
Helper-func - use countnodes to count subnode in pobject
example count the occurences of domainid in this json. this chunk lacks nested dictionary keywords (users, domains, roles)...
{ "description": "odl master domain", "domainid": 1, "enabled": "true", "name": "Master Test Domain" } { "description": "sdn user domain", "domainid": 2, "enabled": "true", "name": "User Domain" } ...
Args: :param pobject: JSON code to work through :param subnode: a subnode, such as domainid, to search for and count
Returns: :returns number_nodes: the correct number of fields you counted in the json