Framework.ClassUtils.WNetwork package¶
Submodules¶
Framework.ClassUtils.WNetwork.base_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.WNetwork.base_class.
Base
(*args, **kwargs)[source]¶ Bases:
object
This is a Base class.
This class in inherited in all classes of the Network package.
Inheriting this class avoids the problem of calling object with **args/**kwargs while using super method (while invoking the methods of the Network package using an instance of Network class)
Framework.ClassUtils.WNetwork.connection 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.
Framework.ClassUtils.WNetwork.diagnostics 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.WNetwork.diagnostics.
Diag
(*args, **kwargs)[source]¶ Bases:
Framework.ClassUtils.WNetwork.base_class.Base
Warrior Diagnostics class
-
static
ping_from_remotehost
(session_object, ip_type, dest_address, prompt, count)[source]¶ ping to dest_system from remote host
Arguments: - session_object(string) = expect session object
- command(string) = command to be executed
- ip_type = ip/ipv6/dns
4. dest_address(string) = ip or dns name 3. prompt(string) = prompt
Returns: - bool (True/False)
-
static
traceroute_from_remotehost
(session_object, ip_type, dest_address, prompt)[source]¶ traceroute to dest_system from remote host
Arguments: - session_object(string) = expect session object
- command(string) = command to be executed
- ip_type = ip/ipv6/dns
4. dest_address(string) = ip or dns name 3. prompt(string) = prompt
Returns: - bool (True/False)
-
static
Framework.ClassUtils.WNetwork.file_ops 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.WNetwork.file_ops.
FileOps
(*args, **kwargs)[source]¶ Bases:
Framework.ClassUtils.WNetwork.base_class.Base
Warrior File operations class
-
static
file_exists_on_remote
(session_object, prompt, filename)[source]¶ To check file exists This assumes you are in the correct directory
Arguments: - session_object = session object to be used
- prompt(string) = prompt expected
- filename(string) = filename string
- :Returns
- status(bool) = True/False
-
classmethod
ftp_from_remotehost
(session_object, ip_type, ftp_operation, filepath, prompt, dest_address, username, password, filepath_dest)[source]¶ ftp(test both put and get).This keyword can be used to transfer file from source _system to destination system or vice versa. It checks the size after transfer in both get and put.
Arguments: - session_object(string) = name of the Linux machine on which to execute
- ip_type(string) = iptype of the dest system through which it needs to be connected.
- needs to be one of (ip/ipv4/dns/lmp_ip/lmp_ipv6).It has to be present in the input data file.
- ftp_operation(string) = get/put/both
- filepath(string) = file with filepath in source system(used for put)
- prompt(string) = prompt of the source system
- dest_address(string) = ipv4 address or defaulted to lcn ip
- username(string) = username of the dest system
- password(string) = password of the dest system
- filepath_dest(string) = file with filepath in destination system(used for get)
Returns: - bool (True/False)
-
static
ftp_get_from_remote
(session_object, filename)[source]¶ For fetching the file from destination Assumes a ftp session is already present
Arguments: - session_object-session object to be used
- filename(string) - filename string
- :Returns
- status(bool) - True/False
-
static
ftp_put_from_remote
(session_object, filename)[source]¶ For ftping the file to destination Assumes a ftp session is already present
Arguments: - session_object-session object to be used
- filename(string) - filename string
- :Returns
- status(bool) - True/False
-
static
get_file_size
(session_object, prompt, filename, session=None)[source]¶ To get file size for a given file This assumes you are in the correct directory This also handles file size in ftp and sftp prompt
Arguments: - session_object = session object to be used
2. prompt(string) = prompt expected 2. filename(string) = filename string 3. session(string) = ftp/sftp/others
- :Returns
- status(bool) = True/False
-
classmethod
sftp_from_remotehost
(session_object, ip_type, sftp_operation, port, filepath, prompt, dest_address, username, password, filepath_dest)[source]¶ sftp(test both put and get).This keyword can be used to transfer file from source _system to destination system or vice versa. It checks the size after transfer in both get and put.
Arguments: - session_object(string) = name of the Linux machine on which to execute
- ip_type(string) = iptype of the dest system through which it needs to be connected.
- needs to be one of (ip/ipv4/dns/lmp_ip/lmp_ipv6).It has to be present in the input data file.
- sftp_operation(string) = get/put/both
- port(string) = source port
- filepath(string) = file with filepath in source system(used for put)
- prompt(string) = prompt of the source system
- dest_address(string) = ipv4 address or defaulted to lcn ip
- username(string) = username of the dest system
9. password(string) = password of the dest system 9. filepath_dest(string) = file with filepath in destination system(used for get)
Returns: - bool (True/False)
-
static
sftp_get_from_remote
(session_object, filename, filedir)[source]¶ For Fetching the file from destination Assumes a sftp session is already present
Arguments: - session_object-session object to be used
- filename(string) - filename string
- filedir(string) - directory path of the file
- :Returns
- status(bool) - True/False
-
static
sftp_put_from_remote
(session_object, filename, filedir)[source]¶ For sftping the file to destination Assumes a sftp session is already present
Arguments: - session_object-session object to be used
- filename(string) - filename string
- filedir(string) - directory path of the file
- :Returns
- status(bool) - True/False
-
static
start_ftp_on_remote
(session_object, command, username, password)[source]¶ To start ftp connection on remote machine
Arguments: - session_object = session object to be used
2. command(string) = ftp command 2. username(string) = username 3. password(string) = password
- :Returns
- status(bool) = True/False
-
static
start_sftp_on_remote
(session_object, command, password, prompt)[source]¶ To start sftp connection on remote machine
Arguments: - session_object = session object to be used
- command(string) = sftp command
- username(string) = username
- password(string) = password
- prompt(string) = prompt in source system
- :Returns
- status(bool) = True/False
-
static
Framework.ClassUtils.WNetwork.loging 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.WNetwork.loging.
ThreadedLog
(*args, **kwargs)[source]¶ Bases:
Framework.ClassUtils.WNetwork.base_class.Base
Collect the response from a connected session as a separate thread
-
collect_log
(session)[source]¶ Collects the response from a connected session till the tread is stopped
This function currently collects response from a connected pexpect spawn object using the pexpect read_nonblocking method
-
join_thread
(timeout=30, retry=1)[source]¶ Call join method of Thread class to block caller thread until the current_thread terminates or until the retry counter expires
-
Framework.ClassUtils.WNetwork.network_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.WNetwork.network_class.
Network
(*args, **kwargs)[source]¶ Bases:
Framework.ClassUtils.WNetwork.connection.Connection
,Framework.ClassUtils.WNetwork.diagnostics.Diag
,Framework.ClassUtils.WNetwork.file_ops.FileOps
,Framework.ClassUtils.WNetwork.base_class.Base
This is class that inherits all other classes in the Network package.
Instance of this class may be used to invoke the methods of all the other classes in this package.
While using the instance of this class, if the Base classes have same method name, then the method will be executed based on python’s inheritance MRO (Method Resolution Order)
Execute ‘Network.__mro__’ to find out the current MRO Order is from left to right of the MRO.
Framework.ClassUtils.WNetwork.warrior_cli_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.WNetwork.warrior_cli_class.
ParamikoConnect
(credentials={})[source]¶ Bases:
object
Class to handle SSH operations using Paramiko module
-
connect_ssh
()[source]¶ Initiates SSH connection to target system using paramiko module. For nested SSH connections, session will be established via intermediate system.
-
send_command
(**kwargs)¶ Call corresponding mock method
-
-
class
Framework.ClassUtils.WNetwork.warrior_cli_class.
PexpectConnect
(credentials={})[source]¶ Bases:
object
Class to handle SSH operations using Pexpect module
-
send_command
(**kwargs)¶ Call corresponding mock method
-
-
class
Framework.ClassUtils.WNetwork.warrior_cli_class.
WarriorCli
[source]¶ Bases:
object
Class to handle CLI operations.
-
connect_ssh
(ip, port='22', username='', password='', logfile=None, timeout=60, prompt='.*(%|#|\\$)', conn_options='', custom_keystroke='', escape='')[source]¶ - Initiates SSH connection via a specific port. Creates log file.
Arguments: - ip = destination ip
- port(string) = telnet port
- username(string) = username
- password(string) = password
- logfile(string) = logfile name
- timeout(int) = timeout duration
- prompt(string) = destination prompt
- conn_options(string) = extra arguments that will be used when
- sending the ssh/telnet command
- custom_keystroke(string) = keystroke(to be given after initial
- timeout)
- escape(string) = true/false(to set TERM as dump)
Returns: - session_object(pexpect session object)
- conn_string(pre and post login message)
-
connect_telnet
(ip, port='23', username='', password='', logfile=None, timeout=60, prompt='.*(%|#|\\$)', conn_options='', custom_keystroke='', escape='')[source]¶ Initiates Telnet connection via a specific port. Creates log file. :Arguments:
- ip = destination ip
- port(string) = telnet port
- username(string) = username
- password(string) = password
- logfile(string) = logfile name
- timeout(int) = timeout duration
- prompt(string) = destination prompt
- conn_options(string) = extra arguments that will be used when
- sending the ssh/telnet command
- custom_keystroke(string) = keystroke(to be given after initial
- timeout)
- escape(string) = true/false(to set TERM as dump)
Returns: - session_object(pexpect session object)
- conn_string(pre and post login message)
-
static
get_connection_port
(conn_type, inpdict)[source]¶ Gets the port for ssh or telnet connections 1. ssh :
- looks if ssh_port is present in inpdict.
- if not checks for conn_port
- if both not present returns None
-
static
get_response_dict
(started_thread_for_system, thread_instance_list, same_system, response)[source]¶ This function iterates over thread_instance_list and gets the data that the threads have stored in its data variable. Updates remote_resp_dict with the system name and the corresponding data collected.
The system names in same_system also get stored in the remote_resp_dict but their value is the same as the response that was obtained through the _send_cmd function
Returns: remote_resp_dict (dict) with collected logs as value to the system_name key
-
static
get_unique_log_and_verify_list
(log_list, verify_on_list, system_name)[source]¶ This function loops through the log_list and the verify_on_list and returns a unique list containing unique sustem names fromboth the lists
-
isalive
()[source]¶ Returns whether the paramiko/pexpect session is alive or not :Returns:
True if alive else False
-
static
pexpect_spawn_with_env
(pexpect_obj, command, timeout, escape=False, env=None, pty_dimensions=None)[source]¶ spawn a pexpect object with environment & pty_dimensions variables
-
read_nonblocking
(size=1024, timeout=None, *args, **kwargs)[source]¶ Reads characters(size) from pexpect/paramiko session :Arguments:
- size = maximum number of bytes to read
Returns: - read_string = Characters read from the pexpect/paramiko session
-
static
sendPing
(hostname, count, fname)[source]¶ Sends a ping command :Arguments:
- count(string) = no of pings to be sent
- src_iface(string) = source interface from whihc ping messages
- are to be sent.
- destip(string) = the destination ip address to ping.
- fname = logfile to log ping response.
Returns: status = boolean
-
static
sendSourcePing
(count, src_iface, destip, fname)[source]¶ Sends a source based ping command i.e. if multiple interfaces are configured and available, sends pings from the src_iface provided :Arguments:
- count(string) = no of pings to be sent
- src_iface(string) = source interface from whihc ping messages
- are to be sent.
- destip(string) = the destination ip address to ping.
- fname = logfile to log ping response.
Returns: status = boolean
-
send_command
(**kwargs)¶ Call corresponding mock method
-
send_commands_from_testdata
(testdatafile, **args)[source]¶ - Parses the testdata file and gets the command details
for rows marked execute=yes and row=str_rownum. - Sends the obtained commands to the warrior_cli_class
session object(obj_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: - testdatafile = the xml file where command details are available
- logfile = logfile of the pexpect session object.
- varconfigfile = xml file from which the values will be taken
- for substitution
- var_sub(string) = the pattern [var_sub] in the testdata
- commands, start_prompt, end_prompt, verification search will substituted with this value.
- args = Optional filter to specify title/rownum
Returns: - finalresult = boolean
-
send_smart_cmd
(connect_testdata, session_object, tag_value, call_system_name, pre_tag)[source]¶ The beacons of Gondor are lit send out the smart command :param connect_testdata:
the smart testdata file that contains the smart cmdParameters: - session_object – use this pexpect object to send out command
- tag_value – specify the testdata block of commands that get sent out
- call_system_name – in order to get passed the substitutions, a system name must be provided
- pre_tag – Distinguish if it is a connect smart action or disconnect smart action
-
smart_action
(datafile, call_system_name, raw_prompt, session_object, tag_value, connect_testdata=None)[source]¶ entry function for sending smart command :param datafile:
the testcase datafileParameters: - call_system_name – in order to get passed the substitutions, a system name must be provided
- raw_prompt – The string that will be analyzed in order to find the device system
- session_object – use this pexpect object to send out command
- tag_value – specify the testdata block of commands that get sent out
- connect_testdata – the smart testdata file that contains the smart cmd, optional in here
Returns: the smart testdata file that contains the smart cmd
-
static
smart_analyze
(prompt, testdatafile=None)[source]¶ retrieve the correspond smart testdata file for smart cmd from either Tools/connection or testcase testdata file :param prompt:
The string that will be analyzed in order to find the device systemParameters: testdatafile – optional arg to provide a pre-defined device system in the test datafile Returns: the smart datafile that contains the smart cmd to be sent
-
static
start_threads
(started_thread_for_system, thread_instance_list, same_system, unique_log_verify_list, system_name)[source]¶ - This function iterates over unique_log_verify_list which consists of
- unique values gotten from monitor attributes and verify_on attributes
If a system_name has a * against it, it indicates that the system is the same as the one on which the testcase is running. Thread would not be started for that system.
Returns: started_thread_for_system (list[str]) = Stores the system names for which threads were succesfully created
thread_instance_list (list[str]) = stores the instances of thread created for corresponding system in the started_thread_for_system list,
same_system (list[str]) = stores the system name which was the same as the system on which the TC is running without the trailing *,
-
timeout
¶ Get session timeout(mins) value of pexpect/paramiko session
-
update_resp_ref_to_repo
(details_dict, resp_key_list, i, title_row, td_resp_dict, session_id)[source]¶ Updates the response reference in appropriate session_id. There are two cases:
1. The user gives the system and session name only in testcase, then it updates on testcase’s session id 2. The user gives the system and session name in both testcase and testdata file, then it takes testdata as priority and updates on testdata’s session id
-
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.