Framework.ClassUtils package

Submodules

Framework.ClassUtils.configuration_element_class module

Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class Framework.ClassUtils.configuration_element_class.ConfigurationElement(name='base', start_pat='${', end_pat='}')[source]

Bases: object

Configuration element to support arbitrary xml object depth

expand_variables(string)[source]
Replaces embedded variables in the string with their values. Works with $(var) or ${var}. These can be nested to any level
Parameters:string
Returns:
get_dictionary_of_values(*args)[source]
Looks up all values requested and returns a dictionary of key value pairs
Parameters:args
Returns:
get_list(string)[source]
entry function for __get_list
Parameters:string
Returns:a dictionary if nothing wrong with list range
return a dict with orignal list/range as key “1..4,5,6..7:0.5” parsed list as value [1,2,3,4,5,6,6.5,7]
if invalid range found
return a dict {‘Error’:False}
if no list/range found
return a dict {‘False’:False}
get_list_direct(string)[source]
entry function for __get_list
Parameters:string
Returns:a dictionary if nothing wrong with list range
return a dict with orignal list/range as key “1..4,5,6..7:0.5” parsed list as value [1,2,3,4,5,6,6.5,7]
if invalid range found
return a dict {‘Error’:False}
if no list/range found
return a dict {‘False’:False}
get_list_of_values(*args)[source]
Looks up all values requested and returns a list in the order requested
Parameters:args
Returns:
get_node(value)[source]
Returns a ConfigurationElement that is the tree rooted at the requested node
Parameters:value
Returns:
get_value(value)[source]
Returns requested value or None if not found and prints an error
Parameters:value
Returns:
parse_data(*arg, **kwargs)[source]
parse_data constructs a tree of ConfigurationElements from a list of xml files or a list of ElementTrees. The name attribute is the primary key for each node, so if there is any repetition of names at the same tree level, the two nodes will be merged with the second occurrence over writing the first when there is conflict. This is also true across files if two files/ElementTrees passed in share the same node name structure second file will over write any shared values. The attribute xml_tag comes from the xml structure so any attribute named xml_tag will be over written by the xml structure tag name
Parameters:
  • arg
  • kwargs
    root is a bool default is True
    this drives filepath(True) or ElementTree(False) parsing
Returns:

parse_tree(node)[source]
Method to parse ElementTree to ConfigurationElement Tree
Parameters:node
Returns:
print_me(depth=0)[source]
To String implementation
Parameters:depth
Returns:
set_value(key, value)[source]
Adds or changes the key value pair in the tree
Parameters:
  • key
  • value
Returns:

Framework.ClassUtils.database_utils_class module

Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class Framework.ClassUtils.database_utils_class.WMongodb(details_dict=False)[source]

Bases: object

Class to handle mongodb operations to add html results

add_html_result_to_mongodb(input_xml)[source]

To add case/suite/project results as a document to MongoDB database collections, here collection names are case/suite/project

add_xml_result_to_mongodb(input_xml)[source]

To add case xml results as a document to the MongoDB database collection - ‘case’

close_connection()[source]

To close database connection

connect_mongodb(details_dict)[source]

Establish connection with the mongodb server. URI or IP/port combination is supported in mongodb config file, URI will have higher precedence over IP/Port

convert_tddict_to_xmlobj(root, tddict)[source]

To Convert the testdata dictionary into a xml object.

Testdata dictionary can have following combinations :
  1. dict within dict
  2. list within dict
  3. dict within list
get_details_from_case_element(case_elem)[source]

To get the details from JUnit case element(xml)

get_details_from_case_xml_element(case_xml_elem)[source]

To get the details from testcase xml element

get_details_from_project_element(proj_elem)[source]

To get the details from JUnit project element(xml)

get_details_from_suite_element(suite_elem)[source]

To get the details from JUnit suite element(xml)

get_doc_from_db(collection_name, document_name)[source]

To get the document from the database by matching document_name with ‘_id’ field of each document. It will return False if the document doesn’t exist

get_file_type(root)[source]

To get the type of warrior execution file - case/suite/project

get_globalblock_as_xmlobj(db_details)[source]

To get the global block from the database as xml object

get_html_results(file_type, root)[source]

To get the results from the junit root element

get_tdblock_as_xmlobj(db_details)[source]

To get the testdata blocks from the database as xml object

get_varblock_as_xmlobj(db_details)[source]

To get the variable config details from the database as xml object

Framework.ClassUtils.database_utils_class.create_database_connection(server_type='resultservers', dbsystem=None)[source]

To create object for the database class based on the dbsystem:dbtype value of server_type in Tools/database/database_config.xml

Framework.ClassUtils.database_utils_class.get_database_details(config_file, server_type, system_name, info_list)[source]

To get the database system details from database config file

Framework.ClassUtils.json_utils_class module

Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class Framework.ClassUtils.json_utils_class.JsonUtils[source]

Bases: object

class for json utils

case_conversion_json(json_object, convert_to_lower=False)[source]

Takes json object and converts to upper by default and if user selects convert_to_lower as True, then converts json object to lower

Returns:
Returns json object by converting either to lower or upper case.
compare_json_files(json_file1, json_file2)[source]

Compares two json files and returns true or false This method recursively sorts all the lists and dictionaries in the json files into a sorted json object and then performs the comparison

compare_json_objects(json_object1, json_object2, case_conversion=False, write_diff_to_console=True, check_for_subset=False)[source]

Compares two json objects and returns true or false This method recursively sorts all the lists and dictionaries in the json objects and then performs the comparison If user selects check_for_subset as True, then checks whether json_object2 is a subset of json_object1 or not by recursively sorting the json objects

compare_json_using_jsonpath(response, list_of_jsonpath, list_of_expected_api_responses)[source]

Will get each json_path in list of jsonpath and get the value of that jsonpath in json response Compares the value with the expected_api_response If all values matches returns True else False

diff_json_files(json_file1, json_file2)[source]

Takes two json files as inputs and calculates the difference between them. :Note: This method does an unsorted (or raw) comparison of the input json files

For a sorted comparison use compare_json_files.
Returns:

Returns a status and a comparison result(tuple or None) 1. No difference between two json objects.

  • status = True
  • comparison result = None.
  1. Difference found between two json objects. - status=False - comparison result = a tuple of two lists

    list1= items in json1 but not json2

    list2= items in json2 but not json1

  2. If any exception encountered during comparison:
    • status=False
    • comaprison result = None
diff_json_objects(json_object1, json_object2, case_conversion=False)[source]

Takes two json objects as inputs and calculates the difference between them. :Returns:

Returns a status and a comparison result(tuple or None) 1. No difference between two json objects.

  • status = True
  • comparison result = None.
  1. Difference found between two json objects. - status=False - comparison result = a tuple of two lists

    list1= items in json1 but not json2

    list2= items in json2 but not json1

  2. If any exception encountered during comparison:
    • status=False
    • comaprison result = None
get_value_for_nested_key(json_response, json_path)[source]

Returns the value of the nested key in the dictionary Arguments:

json_response = dictionary from which we get the value of the
nested key

json_path = nested key to which we need to get the value For example: json_response = {“1”:{“2”:{“3”:{“4”:”5”}}}} If we wish to get the value of key ‘4’, you need to give the json_path as “1.2.3.4”

Returns:
returns the value of the nested key
load_path_json(path_login_testdata)[source]

Retrieves data from json file. Returns None if exception occurs.

nested_json_object(json_object)[source]

Param: Takes json_object as input json_object can be a dictionary or nested dictionary. Returns: It returns a frozenset which has a list and it contains tuples ((key,value) pairs in json_object)

pretty_print_json(json_object, indent=4)[source]

Prints the input json object in readable format to the terminal, default indent=4

retrieve_data_from_json(json_file, search_pattern)[source]

Retrieves and returns data from input json file which matches with search pattern

sort_json_object(json_object)[source]

Recursively sort any lists/dictionaries in a json into (key, value) pairs so that they’re sorted

write_json_diff_to_file(json_object1, json_object2, output_file)[source]

Compares two json objects and if they does not match writes the difference into the output file

write_json_to_file(json_object, file_path)[source]

Writes the given json object to the provided file

Framework.ClassUtils.netconf module

Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class Framework.ClassUtils.netconf.client[source]

Bases: threading.Thread

#netconf client class

cancel_commit(persist_id=None)[source]
#send cancel-commit rpc
persist_id = persist-id string
capability_data

netconf capabilities

clear_notification_buffer()[source]

clear the notification buffer

clear_notification_print_buffer()[source]

clear the notification buffer for print

close()[source]

#session close

close_session()[source]

#send close-session rpc

commit(confirmed=None, confirm_timeout=None, persist=None, persist_id=None)[source]
#send commit rpc
confirmed = any string if using confirmed commit confirm_timeout = timeout value in sec. when confirmed commit persist = string of persist-id persist_id = persist-id if specified in previous commit
connect(host, port, username, password, hostkey_verify=False, protocol_version='')[source]

#ssh connect # host = hostname or ip (string) # port = port number (integer) # username = login user name (string) # password = password (string) # hostkey_verify = True/False(default) # protocol_version = 1.0/1.1/null (string)

copy_config(target, source)[source]
#send copy-config rpc
target = destination datastore source = source datastore
create_subscription(stream_from=None, filter_string=None, filter_type=None, start_time=None, stop_time=None)[source]
#send create-subscription rpc (RFC-5277)
stream = stream name (NETCONF/SNMP/syslog…) filterString = xml string or xpath string filterType = subtree or xpath startTime = Start time to replay stopTime = Stop time to replay
current_protocol_version

protocol version

delete_config(target)[source]
#send delete-config rpc
target = target datastore
discard_changes()[source]

#send discard-changes rpc

edit_config(target, config_string, default_operation=None, test_option=None, error_option=None)[source]
#send edit-config rpc
target = datastore name (candidate/running) configString = xml string default_operation = merge(default)/replace/none test_option = test-then-set(default)/set/test-only error_option = stop-on-error(default)/continue-on-error/rollback-on-error
error_message

error message

get(filter_string=None, filter_type=None)[source]
#send get rpc
filterString = filter string, xml string or xpath string
get_config(source, filter_string=None, filter_type='subtree')[source]
#send get-config rpc
source = datastore name (candidate/running/startup) filter_string = filter string, xml string or xpath string filter_type = filter type (subtree or xpath)
get_schema(identifier, version_number=None, format_type=None)[source]

get-schama rpc

isCOMPLD

whether rpc comannd gets ok

isOpen

whether port is opened

kill_session(session_id)[source]
#send kill-session rpc
session_id = session-id to be killed
! not current session !
lock(target)[source]
#send lock rpc
target = target datastore
notification_data

netconf notification data

response_data

netconf reply data

rpc(xml)[source]
#send a rpc
xml = xml string to send returns: response data
run()[source]

#start receiving thread

send_data

previous send data

send_hello()[source]

#send hello # just send, no wait

session_id

session-id

unlock(target)[source]
#send unlock rpc
target = target datastore
validate(source='candidate', config=None)[source]
#send validate rpc
source = datastore
waitfor_subscription(wait_string, timeout=600)[source]

waitfor a notification event report :ARGUMENTS:

wait_string(tuple) = tuple of xpath string and namespace dict(
key - prefix value - namespace string)

timeout(integer) = timeout in sec.

Returns:True: if successful False: if unsuccessful
Framework.ClassUtils.netconf.connect(host, port, username, password, hostkey_verify=False, protocol_version='')[source]

#creates client instance and returns it if connection success

Framework.ClassUtils.netconf_utils_class module

Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class Framework.ClassUtils.netconf_utils_class.WNetConf[source]

Bases: object

WNetConf class has methods required to interact with NetConf interfaces

ErrorMessage

error message when rpc command gets rpc-error

cancel_commit(persist_id=None)[source]

cancel commit :Arguments:

  1. persist_id = persist-id which specifed in confirmed commit operation
Returns:rpc_reply
clear_notification_buffer()[source]

clear notification buffer :Arguments:

None
Returns:always true
clear_notification_buffer_for_print()[source]

clear the notification print buffer

close()[source]

Closes Netconf SSH session :Arguments:

None
Returns:rpc_reply
commit(confirmed=False, timeout=None, persist=None, persist_id=None)[source]

Commit the candidate datastore as the device’s new current configuration :Arguments:

  1. confirmed(bool) = Commit is reverted if there is no followup commit
    within the timeout interval.
  2. timeout(int seconds) = The confirm timeout (Default=600 seconds)
  3. persist = string to persistance
  4. persist-id = persist string when if specified in previous commit
Returns:rpc_reply
copy_config(source, target)[source]
Create or replace an entire configuration datastore
with the contents of another complete configuration datastore
Arguments:
  1. source = name of the configuration datastore to use as the source of the copy
    operation or config element containing the configuration subtree to copy.
  2. target = name of the configuration datastore to use
    as the destination of the copy operation
Returns:

rpc_reply

create_subscription(stream_from='NETCONF', filter_type=None, filter_string=None, start_time=None, stop_time=None)[source]

create subscription to receive event notification :Arguments:

  1. stream_from = NETCONF/SNMP/syslog etc.
  2. filter_type = filter type xpath or subtree
  3. filter_string = filter string, xml string or xpath string
  4. start_time = start time
  5. stop_time = stop time
Returns:rpc_reply
delete_config(datastore)[source]

Delete a configuration datastore

Arguments:
  1. datastore = name of the configuration datastore to be deleted
Returns:

rpc_reply

discard_changes()[source]

discard current modify to candidate datasotre :Arguments:

None
Returns:rpc_reply
edit_config(datastore, config, default_operation=None, test_option=None, error_option=None)[source]

Load config to the datastore :Arguments:

  1. datastore = Name of datastore being edited

  2. config = The configuration data.

  3. default_operation = [merger | replace | none (default)]

  4. test_option = [test_then_set | set | none (default)]

  5. error_option = [stop-on-error | continue-on-error
    rollback-on-error | none (default)]

    rollback-on-error depends on :rollback-on-error capability

Returns:rpc_reply
get(filter_string=None, filter_type=None)[source]

Retrieve running configuration and device state information.

Arguments:
  1. filter = specifies the portion of the configuration to retrieve (by default entire configuration is retrieved) xpath string or xml string
Returns:

rpc_reply

get_config(datastore, filter_string=None, filter_type='subtree')[source]

Get configuration data from datastore :Arguments:

  1. datastore = name of datastore being queried
  2. filter_string = portion of the configuration to retrieve. None = Everything
Returns:rpc_reply
get_notification_buffer(notification_type=None)[source]

get specified notification type from buffer notification_type = Event | Alarm | DB-Change |

any product specific notification type
och-notif, dhcpv6-client-event etc..
get_schema(identifier, version_number=None, format_type=None)[source]

get-schema rpc :Arguments:

  1. identifier(string) = schema id (name of yang module)
  2. version_number(string) = schema version (e.g. 1.0)
  3. format_type(string) = format name (e.g. yang)
Returns:rpc reply
isCOMPLD

indicates whether rpc-reply = ok (True/False)

kill_session(session_id)[source]

Force the termination of a NETCONF session (not the current one!) :Arguments:

  1. session_id = is the session identifier of the NETCONF session
    to be terminated as a string
Returns:rpc_reply
lock(datastore)[source]

Lock the configuration system

Arguments:
  1. datastore = name of the configuration datastore to be locked
Returns:

rpc_reply

notification_data

received event notification data

open(session_kwds)[source]

Opens a SSH connection to a Netconf system

Arguments:

The following keywords are allowed in session_kwds: <ip> = IP address of the system (Required) <nc_port> = use this tag to provide ssh port to connect to (default = 830) <username> = username for the ssh session (default = None) <password> = password for the ssh session (default = None) <hostkey_verify> = enables hostkey verification from ~/.ssh/known_hosts (default = True) belows are not used. <timeout> = use if you want to set timeout while connecting (default = None) <allow_agent> = enables querying SSH agent (default = True) <look_for_keys> = enables looking in the usual locations for ssh keys (default = True) <unknown_host_cb> = called when the server host key is not recognized (default = None) <key_filename> = where the private key can be found (default = None) <ssh_config> = enables parsing of OpenSSH configuration file (default = None) <device_params> = ncclient device name (default = ‘default’)

Returns:
  1. connected(bool)= True / False
request_rpc(request)[source]

Send RPC command :Arguments:

  1. request = command to be sent as xml string
Returns:rpc_reply
response_data

rpc-reply data

send_data

previous send data

session_id

netconf session-id which is in hello message

unlock(datastore)[source]

Release the configuration lock

Arguments:
  1. datastore = name of the configuration datastore to be unlocked
Returns:

rpc_reply

validate(datastore)[source]

Validate the contents of the specified configuration. :Arguments:

  1. datastore = the name of the configuration datastore being validated
Returns:rpc_reply
waitfor_subscription(wait_string, timeout=600)[source]

wait for specified notification event :Arguments:

  1. waitString(tuple) = tuple of xpath string and namespace dict
    prefix and namespace string).

e.g. wait_string = (“//ns:event[./ns:eventClass/text()=’fault’]”,

*xpath string must include namespace prefix

  1. timeout(integer) = timeout value in second
Returns:result(bool)

Framework.ClassUtils.rest_server_class module

Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class Framework.ClassUtils.rest_server_class.RestServer[source]

Bases: object

A Rest server that is powered by the Python Bottle framework

async_response(response_val, async, async_response_value, async_status)[source]

Bottle framework support async response using yield simulate a semi-async response :param:

response_val: the original response value async: time between original response and 2nd response async_response_value: async response value async_status: the async status code
build_route(route, method, specific_res_list, general_res)[source]

Take in route, method and its request/response build a route with the corresponded method loaded with request/response condition return the route method :param:

route: the route name, eg. /att /verizon method: the route method type, eg. GET POST specific_res_list: a list of tuple (verify info, response) general_res: the general response if no specific response is present
build_server(datafile, system_name)[source]

Take in a system and read all its routes Load the routes into Bottle server object Start a thread with the bottle server

return the bottle server adapter and server thread

form_response(res_obj, status=True)[source]

Take in a response object and generate response based on its status :param:

res_obj: object that contains all the response info
verify_forms(incoming_forms, respond_obj)[source]

Verify all items in form/dict match the expect param :param:

incoming_forms: the incoming form in a list of tuple form
eg. [(key1, value1), (key2, value2)]

respond_obj: contains the verification detail from datafile

Returns:True if all items in form/dict match the veri param False if any of the items fail to match
verify_json(incoming_json, respond_obj, file=False)[source]

Verify the incoming_json data with either a. whole json file b. key value pairs :param:

incoming_json: a json string/json obj respond_obj: contains the verification detail from datafile file: indicate if comparing whole file or just pairs
Returns:True if whole file match/all pairs match False if not match
verify_param(incoming_params, respond_obj)[source]

Verify all request param matched with the expect param :param:

incoming_params: the incoming params in a list of tuple form
eg. [(key1, value1), (key2, value2)]

respond_obj: contains the verification detail from datafile

Returns:True if all incoming params match the veri param False if any incoming params fail to match
verify_xml(incoming_xml, respond_obj, file=False)[source]

Verify the incoming_xml data with either a. whole xml file b. tag text pairs :param:

incoming_xml: an xml string respond_obj: contains the verification detail from datafile file: indicate if comparing whole file or just pairs
Returns:True if whole file match/all pairs match False if not match
class Framework.ClassUtils.rest_server_class.ServerHandler(host='127.0.0.1', port=8080, **options)[source]

Bases: Framework.OSS.bottle.ServerAdapter

A wsgiref server that can be shutdown manually so the bottle server can be terminated peacefully Once bottle is capable of terminating itself this can go away

run(app)[source]
server = None
stop()[source]

Framework.ClassUtils.rest_utils_class module

Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class Framework.ClassUtils.rest_utils_class.WRest[source]

Bases: object

WRest class has methods required to interact with REST interfaces

catch_expection_return_error(exception_name, url)[source]

Function for catching expections thrown by REST operations

check_connection(url, auth=None, **kwargs)[source]

Internally uses the http options to check connection status. i.e.

  • If connection is successfull return a true
  • if any ConnectionError is detected returns a False.
cmp_content_response(datafile, system_name, response, expected_api_response, expected_response_type, comparison_mode)[source]

Performs the comparison between api response and expected_api_response

arguments:
  1. datafile: Datafile of the test case

  2. system_name: Name of the system from the datafile

    Pattern: String Pattern Multiple Values: No Max Numbers of Values Accepted: 1 Characters Accepted: All Characters Other Restrictions: Should be valid system name from the datafile eg: http_system_1

  3. response: API response getting from the data repository

  4. expected_api_response : expected response which needs to be compared given by the user.

  5. expected_response_type: The type of the expected response. It can be xml or json or text.

  6. comparison_mode: This is the mode in which you wish to compare The supported comparison modes are file, string, regex=expression, jsonpath=path, xpath=path If you have given comparison_mode as file or string then whole comparison will take place If you wish to check content of expected response and if it is only one value_check pass it in either data file or test case file If it is more than one value_check then pass it in data file in comparison_mode and expected_api_response tags under system If it is xml response then you need to give xpath=path to it If it is string response then you can pass regex=expressions and you can leave expected_api_response empty Ex for passing values in data file if it is json response <comparison_mode>

    <response_path>jsonpath=1.2.3</response_path> <response_path>jsonpath=1.2</response_path>

    </comparison_mode> <expected_api_response>

    <response_value>4</response_value> <response_value>5</response_value>

    </expected_api_response>

returns:
Returns True if the response matches with the expected response else False.
cmp_response(response, expected_api_response, expected_response_type, output_file, generate_output_diff_file=True)[source]

Performs the comparison between api response and expected_api_response

arguments:
1.response: API response getting from the data repository 2.expected_api_response : expected response which needs to be compared given by the user. 3.expected_response_type: The type of the expected response. It can be xml or json or text. 4.output_file: The file in which the difference will be written if the responses are not equal. 5.generate_output_diff_file: If the responses does not match, then generates an output file by writing the difference to the file by default and if it set to False then doesnot generate any file.
returns:
Returns True if the response matches with the expected response else False.
delete(url, expected_response=None, auth=None, **kwargs)[source]

performs a http delete method Please refer to the python-requests docs for parameter type support. api reference: https://github.com/kennethreitz/requests/blob/master/requests/api.py

expected_response is an additional parameter that accepts a string as an input and also a list of strings Eg: “204”

[“201”, “202”, “404”, “302”]
get(url, expected_response=None, params=None, auth=None, **kwargs)[source]

performs a http get method Please refer to the python-requests docs for parameter type support. api reference: https://github.com/kennethreitz/requests/blob/master/requests/api.py

expected_response is an additional parameter that accepts a string as an input and also a list of strings Eg: “204”

[“201”, “202”, “404”, “302”]
static get_output_response(api_response)[source]
head(url, expected_response=None, auth=None, **kwargs)[source]

performs a http head method Please refer to the python-requests docs for parameter type support. api reference: https://github.com/kennethreitz/requests/blob/master/requests/api.py

expected_response is an additional parameter that accepts a string as an input and also a list of strings Eg: “204”

[“201”, “202”, “404”, “302”]
import_requests()[source]

Import the requests module

options(url, expected_response=None, auth=None, **kwargs)[source]

performs a http options method Please refer to the python-requests docs for parameter type support. api reference: https://github.com/kennethreitz/requests/blob/master/requests/api.py

expected_response is an additional parameter that accepts a string as an input and also a list of strings Eg: “204”

[“201”, “202”, “404”, “302”]
patch(url, expected_response=None, data=None, auth=None, **kwargs)[source]

performs a http patch method Please refer to the python-requests docs for parameter type support. api reference: https://github.com/kennethreitz/requests/blob/master/requests/api.py

expected_response is an additional parameter that accepts a string as an input and also a list of strings Eg: “204”

[“201”, “202”, “404”, “302”]
post(url, expected_response=None, data=None, auth=None, **kwargs)[source]

performs a http post method Please refer to the python-requests docs for parameter type support. api reference: https://github.com/kennethreitz/requests/blob/master/requests/api.py

expected_response is an additional parameter that accepts a string as an input and also a list of strings Eg: “204”

[“201”, “202”, “404”, “302”]
put(url, expected_response=None, data=None, auth=None, **kwargs)[source]

performs a http put method Please refer to the python-requests docs for parameter type support. api reference: https://github.com/kennethreitz/requests/blob/master/requests/api.py

expected_response is an additional parameter that accepts a string as an input and also a list of strings Eg: “204”

[“201”, “202”, “404”, “302”]
classmethod report_response_status(status, expected_response, action)[source]

Reports the response status of http actions with a print message to the user

try_until_resource_status(url, auth=None, status='up', trials=5, **kwargs)[source]

Tries to connect to the resource until resource reaches the specified status. Tries for the number mentioned in the trials parameter (default=5) waits for a time of 30 seconds between trials

update_output_dict(system_name, api_response, request_id, status, i)[source]

updates the output dictionary with status code and response object and text response and placing another dictionary inside output dict and updating it with status code and content type and extracted content from object and response object

Framework.ClassUtils.snmp_utlity_class module

Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class Framework.ClassUtils.snmp_utlity_class.WSnmp(communityname, mpModel, ipaddr, port='161', snmp_timeout=60, userName=None, authKey=None, privKey=None, authProtocol=None, privProtocol=None)[source]

Bases: object

SNMP Util class using PYSNMP

classmethod add_community(port, community='public')[source]

Add SNMP Community for this NEW Trap/Inform Reciver its mandatory to add community string also :param port: SNMP TRAP/Inform Port :param community: SNMP community string, default is ‘public’ :return:

classmethod add_user(port, username, securityengineid, authkey=None, privkey=None, authProtocol=None, privProtocol=None)[source]

Add SNMP V3 User :param port: SNMP Trap Port :param username: SNMP User name :param securityengineid: SNMP Engine id in Hex form :param authkey: SNMP Authkey default is None :param privkey: SNMP Privkey string default is None :param authProtocol: Auth Protocol, default is None :param privProtocol: Privacy Protocol, default is None :return: Treu or False

authProtocol = {'usmAesCfb128Protocol': (1, 3, 6, 1, 6, 3, 10, 1, 2, 4), 'usmAesCfb192Protocol': (1, 3, 6, 1, 4, 1, 9, 12, 6, 1, 1), 'usmAesCfb256Protocol': (1, 3, 6, 1, 4, 1, 9, 12, 6, 1, 2), 'usmDESPrivProtocol': (1, 3, 6, 1, 6, 3, 10, 1, 2, 2), 'usmHMACMD5AuthProtocol': (1, 3, 6, 1, 6, 3, 10, 1, 1, 2), 'usmHMACSHAAuthProtocol': (1, 3, 6, 1, 6, 3, 10, 1, 1, 3)}
static checkoctetstring(val)[source]

Check for OctetString Arguments:

1.val: pysnmp object
Returns:True or False
classmethod close_trap_listner_job(port)[source]

Close the trap listner job :param transportDispatcher: :return:None

commandgenerator()[source]

SNMP Command generator Return: command generator object

communitydata()[source]

Creates communityData object for SNMP v1 and V2c :Return: Community data object

classmethod create_trap_listner_job(port='162')[source]

Create Trap listner job :param port: :return:None

data_repo = {}
static get_asn_decoder()[source]
classmethod get_asyncoredispatcher(port)[source]
static get_first_node_name(mib_filepath, mib_filename)[source]

Get the node name from the given mib file path and file name :param mib_filepath: Mib file path of the git url or abs file path :param mib_filename: MIB file name :return: oid, lable, suffix, mibView, mibBuilder

static get_proto_api()[source]
mibViewController = None
mibvariable(mib_name, mib_index, mib_value='')[source]

Creates MIB Object Arguments:

1.(string) mib_name=”IP-MIB” 2.(string) mib_index=”ipAdEntAddr” 3.(string) mib_value=”127.0.0.1”

Return: MIB Object

snmpEngine = {}
classmethod start_trap_listner_job(port)[source]

Start the listner Job Dispatcher will never finish as job#1 never reaches zero :return:None

classmethod trap_decoder(**kwargs)[source]
udp6transporttarget()[source]

Creates IPV6 UDP transport object Returns: IPv6 UDPTransport object

udptransporttarget()[source]

Creates UDP transport object Return: UDPTransport object

usmuserdata()[source]

Creates SNMP v3 User Security Model (USM) configuration entry. Returns: USM object

Framework.ClassUtils.snmp_utlity_class.threadsafe_function(fn)[source]

Decorator for making sure that the decorated function is thread safe Puts a lock before the function uses any resuorces which are not exclusive for a single thread.

Framework.ClassUtils.ssh_utils_class module

Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class Framework.ClassUtils.ssh_utils_class.SSHComm(target, port=22, uid='', pid='', logfile=None)[source]

Bases: object

SSHComm class which has methods related to SSH communication using paramiko

connect_target_via_host(target, user, auth, invoke_shell=False, log=None)[source]

Forward the SSH connection to another target client :Argument:

  1. target(string) - Name/ip target machine to be connected
  2. user - username to connect
  3. auth - password for the user
  4. invoke_shell - open shell for passing commands
Returns:
  1. target_session - Session object for target connection
  2. status(bool)= True / False
copy_file(remotepath, localpath, filename)[source]

Get the file from remotepath

Argument:
  1. remotepath - File path in the remote server
  2. localpath - Local path to save the file
  3. filename - Filename of the file to be tranferred
Returns:
  1. status(bool)= True / False
download_remote_file_sftp(remotepath, localpath, filename, remotehost, username, password, port=22)[source]

Downloads a remote file from the remote server to the localpath using SFTP

Arguments:
  1. remotepath (string) = the remote path to download the file from remotehost
  2. localpath (string) = the local path on the local host
  3. filename (string) = name of the remote file to download
  4. remotehost (string) = remote host
  5. username (string) = remote login username
  6. password (string) = remote login password
Returns:
  1. status(bool)
get_response(command, timeout=None)[source]
Execute a command using the paramiko SSH object and returns
the response string
Arguments:
  1. command - commnad to be executed
  2. timeout - wait for response
Returns:
  1. status(bool)= True / False
  2. out/err = response string
import_param()[source]

Import the paramiko module

invoke_shell(term='vt100')[source]

Opens a terminal for the SSH session :Argument:

  1. term = Type of terminal, default:vt100
Returns:True: if successful False: if unsuccessful
send_testdata_cmds(testdatafile, **args)[source]
  • Parses the testdata file and - gets the command details for rows marked execute=yes (or) - gets the command details for rows marked execute=yes and row=str_rownum (or) - gets the command details for rows marked execute=yes and title=strtitle
  • Sends the obtained commands to the paramiko session.
  • If the commands have verification attribute set,

then verifies the verification text for presence/absence as defined in the respective found attribute in the testdatfile.

Arguments:
  1. testdatafile = the xml file where command details are available
  2. str_rownum = row number of testdata command block to be searched for in the testdata file
  3. strtitle = title of testdata command block title to be searched for in the testdata file
Returns:
  1. finalresult = boolean
ssh_close()[source]

Close the SSH connection object

Returns:
  1. status(bool)= True / False
ssh_con(retries=1, interval=1, timeout=60, verify_keys=False, invoke_shell=False)[source]

Connects to the host using ssh object

Arguments:
  1. retries = No of attempts before returning fail
  2. interval = Time to wait before the next retry
  3. timeout = wait for response
  4. verify_keys = Verify the host entry is available in host key
Returns:
  1. status(bool)= True / False
ssh_exec(command, timeout=None, get_pty=True)[source]

Execution of the command on the remote host

Arguments:

1.command = command to be executed 2.timeout = wait for response 3.get_pty = request a pseudo-terminal

Returns:
  1. out = command output
  2. stderr = command’s error stream object
verify_response(command, exp_string, fail_resp, timeout=None)[source]
Execute a command using the paramiko SSH object and returns

the response string

Arguments:
  1. command - command to be executed
  2. exp_string - String to be expected
  3. fail_resp - Failure response to be expected
  4. timeout - wait for response
Returns:
  1. status(bool)= True / False
  2. out/err = response string

Framework.ClassUtils.testdata_class module

Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class Framework.ClassUtils.testdata_class.TestData[source]

Bases: object

Class to handle generic test data related operations

align_both(details_dict, cmd_index, cmd_match, verify_text_match_list)[source]
In the case of both command list and verify text list get list substitution handle the following case: command and verify text share same substitution: 1-1 match the list value, so cmd 1 - verify 1, cmd2 - verify 2 command and verify text have different substitution: 1-many match the list value, so cmd 1 - verify a, verify b, verify c command has list substitution but verify text doesn’t: 1-1 match, cmd 1 - verify text also expand other lists to match # of cmd
Parameters:
  • details_dict
  • cmd_index – current cmd that we are processing
  • cmd_match – list for value indicating whether cmd text list has list substitution can be [list1, list2, list3] all lists have same length (checked before sub) or []
  • verify_text_match_list – list for value indicating whether verify text list has list substitution can be [[list1_for_ver_text1, list2, list3], [False], [list1_for_ver_text3, list2…]] or []
Returns:

align_cmd(details_dict, cmd_index, cmd_match)[source]
In the case of only command list get list substitution handle the following case: command has list substitution but verify text doesn’t: all expanded cmd have their own copy of verify text also expand other lists to match # of cmd
Parameters:
  • details_dict
  • cmd_index – current cmd that we are processing
  • cmd_match – list for value indicating whether cmd text list has list substitution
Returns:

align_ver(details_dict, cmd_index, verify_text_match_list)[source]
In the case of only verify text list get list substitution handle the following case: verify text has list substitution but cmd text doesn’t: 1 cmd maps to all of its verify texts
Parameters:
  • details_dict
  • cmd_index – current cmd that we are processing
  • verify_text_match_list – list for value indicating whether verify text list has list substitution
Returns:

cmd_quote_check(cfg_elem_obj, details_dict)[source]
check the command text to see if there is any different list substitution
Parameters:
  • cfg_elem_obj – the object that load and parse the varconfig file we can match text in command text to list element
  • details_dict
Returns:

list of boolean shows if the command has list substitution of not

cmd_sub(details_dict, cmd_index, varconfigfile, start_pat='${', end_pat='}')[source]
expand the command_list with list/range value
Parameters:
  • details_dict
  • cmd_index – current cmd that we are processing
  • varconfigfile – reference to find value list
Returns:

list of value indicating if the cmd has list substitution or not

list_check(cfg_elem_obj, text)[source]
check the text to see if there are multiple list substitutions
Parameters:
  • cfg_elem_obj – the object that load and parse the varconfig file we can match text to list element
  • text – the text being analyzed
Returns:

return the particular list or None

list_substitution(details_dict, varconfigfile, cmd_list_substituted, verify_text_substituted, start_pat='${', end_pat='}')[source]
entry function for different list substitution case also handle the deletion of original list after alignment
Parameters:
  • details_dict
  • varconfigfile – reference for list of values
  • cmd_list_substituted – list for value indicating whether cmd list has list substitution
  • verify_text_substituted – list for value indicating whether verify text list has list substitution
Returns:

list_substitution_precheck(varconfigfile, details_dict, start_pat='${', end_pat='}')[source]
entry function for cmd and verify text substitution check
Parameters:
  • cfg_elem_obj – the object that load and parse the varconfig file
  • details_dict
Returns:

pair of list of boolean returned from cmd_quote_check and verify_text_check

string_sub(raw_str, dict_of_list, start_pat='${', end_pat='}')[source]

expand the raw_str into a list using the substitution value from dict_of_list :param raw_str:

the source string that needs to be expanded
Parameters:dict_of_list – a dict with orignal list/range as key “1..4,5,6..7:0.5” parsed list as value [1,2,3,4,5,6,6.5,7]
Returns:a list with expanded raw_str
static varsub_varconfig_substitutions(details_dict, vc_file, var_sub, start_pat='${', end_pat='}')[source]

Substitute the patterns [VAR_SUB] in command, command parameters, verification search, verification parameters with the value of VAR_SUB provided by user in the testcase.

Substitute the value of the variables (provided as dotted notation inside the pattern ${} ) in command, command parameters, verification search, verification parameters with the value provided in the varaiable config file (vc_file).

verify_sub(details_dict, cmd_index, varconfigfile, start_pat='${', end_pat='}')[source]
expand the verify_text_list with list/range value
Parameters:
  • details_dict
  • cmd_index – current cmd that we are processing
  • varconfigfile – reference to find value list
Returns:

list of value indicating if the verify text list has list substitution or not

verify_text_check(cfg_elem_obj, details_dict)[source]
check the verify text to see if there is any different list substitution
Parameters:
  • cfg_elem_obj – the object that load and parse the varconfig file we can match text in verify text to list element
  • details_dict
Returns:

list of boolean shows if the verify text has list substitution of not

static wdf_substitutions(details_dict, datafile, kw_system_name)[source]

Substitute the patterns $wdf{} in command, command parameters, verification search, verification parameters with the value of

provided by user in the datafile.
class Framework.ClassUtils.testdata_class.TestDataIterations[source]

Bases: object

Class to handle iterations in testdata

arrange_per_td_block(details_dict, cmd_loc_list)[source]

Rearrange details_dict values as per cmd_loc_list

Returns updated details_dict with expanded values arranged in per_td_block order

expand_cmd_params(cmd_iter_pattern, details_dict, index, vc_file)[source]

Expand the iteration patterns in the command, command parameters and return a updated details dict

expand_vfy_params(details_dict, index, vc_file, cmd_iter_pattern)[source]

Expand the iter patterns in the verification search and found.

get_iteration_pattern(cmd)[source]

Get the iteration pattern from a string

repeat_per_td_block(details_dict, cmd_loc_list)[source]

Find the max iteration count(td block) from cmd_loc_list. Expand all command values in details_dict for ‘repeat_count’ times if repeat tag is ‘yes’.

resolve_iteration_patterns(details_dict)[source]

Takes a details dict as input and resolves the iteration patterns in each command and its parameters and in each verification search and its parameters

Return:Returns an updated details_dict and cmd_loc_list (cmd_loc_list - list of starting locations of each td command in the expanded cmd_list, last value of this list is the total number of commands in the in the expanded cmd_list)
validate_iteration_patterns(cmd, details_dict, index)[source]

Validate iteration patterns provided in the 1. command string 2. command parameters 3. verification search string of the command 4. verification parameters (found, verify_on)

Framework.ClassUtils.xl_utils_class module

Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class Framework.ClassUtils.xl_utils_class.Wxl[source]

Bases: object

Wxl class has methods required to parse/write from/to xl sheet

get_row_for_value(worksheet, value, col, row_range)[source]

Takes a value, column and row_range as input and returns the row_num that has the matching value, returns None if no match found

get_row_value_dict(worksheet, row_range)[source]
import_openpyxl()[source]

Import the requests module

load_workbook(wb_location)[source]

Load an existing xl workbook

Module contents

Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.