Actions.CliActions package

Submodules

Actions.CliActions.cli_actions 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 Actions.CliActions.cli_actions.CliActions[source]

Bases: object

CliActions class which has methods(keywords) related to actions performed on any command line interface

connect(system_name, session_name=None, prompt='.*(%|#|\\$)', ip_type='ip', via_host=None, tuple_pty_dimensions=None)[source]

This is a generic connect that can connect to ssh/telnet based on the conn_type provided by the user in the input datafile.

Datafile usage:

Tags or attributes to be used in input datafile for the system or subsystem If both tag and attribute is provided the attribute will be used.

  1. ip = IP address of the system.

    Default value for ip type is ip, it can take any type of ip’s to connect to (like ipv4, ipv6, dns etc)

    Users can provide tag/attribute for any ip_type under the system in the input datafile and specify the tag/attribute name as the value for ip_type argument, then the connection will be established using that value.

  2. username = username for the session.

  3. password = password for the session.

  4. timeout = use if you want to set timeout while connecting,

    used for both ssh and telnet

  5. prompt = for ssh connections, this is the prompt expected when

    the connection is successful, not required for telnet.

  6. conn_type = the type of connection to be created (ssh/telnet).

  7. ssh_port = use this tag to provide ssh port to connect to, if

    not provided default ssh port of 22 will be used.

  8. telnet_port = use this tag to provide a telnet port to connect to

    if not provided default telnet port 23 will be used.

  9. conn_options = extra arguments that will be used when sending

    the ssh/telnet command, default is empty

10.custom_keystroke = a keystroke that will be sent after the initial

timeout, in case of server require a keystroke to show any prompt. Default is the enter key

11.pty_dimensions = size of the pseudo-terminal specified as a

two-entry tuple (rows, columns), eg. (24, 80).

Arguments:
  1. system_name (string) = This can be name of the system or a subsystem.

    To connect to a system provided system_name=system_name.

    To connect to a single subsystem provide system_name=system_name[subsystem_name].

    To connect to multiple subsystems provide system_name=system_name[subsystem1_name,subsystem2_name..etc..].

    To connect to all subsystems under a system provide system_name=”system_name[all]”.

  2. session_name(string) = name of the session to the system.

  3. prompt(string) = prompt expected in the terminal.

  4. ip_type(string) = type of the ip address(ip, ipv4, ipv6, dns, etc).

  5. via_host = Name of the system in the data file to be used as an

    intermediate system for establishing nested connections, currently it is applicable only for SSH connections.

  6. tuple_pty_dimensions(tuple) = size of the pseudo-terminal specified as a

    two-entry tuple(rows, columns), eg. (24, 80).

Returns:
  1. status(bool)= True / False.
  2. session_id (dict element)= an id is generated for each connection
    and each connection is stored in the framework’s data_repository. session_id=system_name+subsystem_name+session_name.
  3. response dictionary(dict): an empty dictionary to store the responses of all
    commands sent to the particular system or subsystem. This dictionary is available in warrior frameworks global data_repository and can be retrieved using the key= “session_id + _td_response”.
connect_all()[source]

This is a connect all operation that can connect to all ssh/telnet based on the conn_type provided by the user in the input datafile.

Datafile usage:

Tags or attributes to be used in input datafile for the system or subsystem If both tag and attribute is provided the attribute will be used.

  1. ip = IP address of the system.

    Default value for ip type is ip, it can take any type of ip’s to connect to (like ipv4, ipv6, dns etc)

    Users can provide tag/attribute for any ip_type under the system in the input datafile and specify the tag/attribute name as the value for ip_type argument, then the connection will be established using that value.

  2. username = username for the session.

  3. password = password for the session.

  4. timeout = use if you want to set timeout while connecting, used for both ssh and telnet

  5. prompt = for ssh connections, this is the prompt expected when the connection is successful, not required for telnet.

  6. conn_type = the type of connection to be created (ssh/telnet).

  7. ssh_port = use this tag to provide ssh port to connect to, if not provided default ssh port of 22 will be used.

  8. telnet_port = use this tag to provide a telnet port to connect to if not provided default telnet port 23 will be used.

Arguments:

None. Keyword will read the input datafile and get the data from tag <system> and <subsystem>.

Returns:
  1. status(bool)= True / False.
  2. session_id (dict element)= an id is generated for each connection
    and each connection is stored in the framework’s data_repository. session_id=system_name+subsystem_name+session_name.
  3. response dictionary(dict): an empty dictionary to store the responses of all
    commands sent to the particular system or subsystem. This dictionary is available in warrior frameworks global data_repository and can be retrieved using the key= “session_id + _td_response”.
connect_ssh(system_name, session_name=None, prompt='.*(%|#|\\$)', ip_type='ip', int_timeout=60, via_host=None, tuple_pty_dimensions=None)[source]

Connects to the ssh port of the the given system or subsystems

Datafile usage:

Tags or attributes to be used in input datafile for the system or subsystem If both tag and attribute is provided the attribute will be used.

  1. ip = IP address of the system.

    Default value for ip type is ip, it can take any type of ip’s to connect to (like ipv4, ipv6, dns etc)

    Users can provide tag/attribute for any ip_type under the system in the input datafile and specify the tag/attribute name as the value for ip_type argument, then the connection will be established using that value.

  2. username = username for the ssh session

  3. password = password for the ssh session

  4. timeout = use if you want to set timeout while connecting

  5. prompt = the prompt expected when the connection is successful

  6. ssh_port = use this tag to provide a ssh port to connect to,

    if not provided default ssh port 22 will be used.

  7. conn_options = extra arguments that will be used when sending

    the ssh/telnet command, default is empty

  8. custom_keystroke = a keystroke that will be sent after the initial

    timeout, in case of server require a keystroke to show any prompt. Default is the enter key

  9. pty_dimensions = size of the pseudo-terminal specified as a

    two-entry tuple(rows, columns), eg. (24, 80).

Arguments:
  1. system_name (string) = This can be name of the system or a subsystem.

    To connect to a system provided system_name=system_name.

    To connect to a single subsystem provide system_name=system_name[subsystem_name].

    To connect to multiple subsystems provide system_name=system_name[subsystem1_name,subsystem2_name..etc..].

    To connect to all subsystems under a system provide system_name=”system_name[all]”.

  2. session_name(string) = name of the session to the system/subsystem.

  3. prompt(string) = prompt expected in the terminal

  4. ip_type(string) = type of the ip address(ip, ipv4, ipv6, dns, etc).

  5. int_timeout(int) = use this to set timeout value for commands

    issued in this session.

  6. via_host(string) = name of the system in the data file to be

    used as an intermediate system for establishing nested ssh connections.

  7. tuple_pty_dimensions(tuple) = size of the pseudo-terminal specified as a

    two-entry tuple(rows, columns), eg. (24, 80).

Returns:
  1. status(bool)= True / False.
  2. session_id (dict element)= an id is generated for each connection
    and each connection is stored in the framework’s data_repository. session_id=system_name+subsystem_name+session_name.
  3. response dictionary(dict): an empty dictionary to store the responses of all
    commands sent to the particular system or subsystem. This dictionary is available in warrior frameworks global data_repository and can be retrieved using the key= “session_id + _td_response”.
connect_telnet(system_name, session_name=None, ip_type='ip', int_timeout=60, tuple_pty_dimensions=None)[source]

Connects to the telnet port of the the given system and/or subsystem and creates a pexpect session object for the system

A session_id is created using the combination system_name+session_name, system_name+subsystem+session_name and returned by this keyword to be stored in Warrior framework’s data repository

Datafile usage:

Tags or attributes to be used in input datafile for the system or subsystem If both tag and attribute is provided the attribute will be used.

  1. ip = IP address of the system.

    Default value for ip type is ip, it can take any type of ip’s to connect to (like ipv4, ipv6, dns etc)

    Users can provide tag/attribute for any ip_type under the system in the input datafile and specify the tag/attribute name as the value for ip_type argument, then the connection will be established using that value.

  2. username = username for the ssh session

  3. password = password for the ssh session

  4. prompt = prompt expected in the terminal

  5. timeout = use if you want to set timeout while connecting.

  6. telnet_port = use this tag to provide a telnet port to connect to, if not provided default telnet port 23 will be used.

  7. conn_options = extra arguments that will be used when sending the ssh/telnet command, default is empty

  8. custom_keystroke = a keystroke that will be sent after the initial timeout, in case of server require a keystroke to show any prompt.

    Default is the enter key

  9. pty_dimensions = size of the pseudo-terminal specified as a

    two-entry tuple(rows, columns), eg. (24, 80).

Arguments:
  1. system_name (string) = This can be name of the system or a subsystem.

    To connect to a system provided system_name=system_name.

    To connect to a single subsystem provide system_name=system_name[subsystem_name].

    To connect to multiple subsystems provide system_name=system_name[subsystem1_name,subsystem2_name..etc..].

    To connect to all subsystems under a system provide system_name=”system_name[all]”.

  2. session_name(string) = name of the session to the system

  3. ip_type(string) = type of the ip address(ip, ipv4, ipv6, dns, etc).

  4. int_timeout(int) = use this to set timeout value for commands

    issued in this session.

  5. tuple_pty_dimensions(tuple) = size of the pseudo-terminal specified as a

    two-entry tuple(rows, columns), eg. (24, 80).

Returns:
  1. status(bool)= True / False.
  2. session_id (dict element)= an id is generated for each connection and each connection is stored in the framework’s data_repository. session_id=system_name+subsystem_name+session_name
  3. response dictionary(dict): an empty dictionary to store the responses of all commands sent to the particular system or subsystem. This dictionary is available in warrior frameworks global data_repository and can be retrieved using the key= “session_id + _td_response”.
disconnect(system_name, session_name=None)[source]

Disconnects/Closes session established with the system

Arguments:
  1. system_name (string) = This can be name of the system or a subsystem.

    To connect to a system provided system_name=system_name.

    To connect to a single subsystem provide system_name=system_name[subsystem_name].

    To connect to multiple subsystems provide system_name=system_name[subsystem1_name,subsystem2_name..etc..].

    To connect to all subsystems under a system provide system_name=”system_name[all]”.

  2. session_name(string) = name of the session to the system

Returns:
  1. status(bool)= True / False
disconnect_all()[source]

This is a disconnect all operation that can disconnect all ssh/telnet sessions based on the details provided by the user in the input datafile.

Arguments:

None. Keyword will read the input datafile and get the data from tag <system> and <subsystem>.

Returns:
  1. status(bool)= True / False.
send_all_testdata_commands(system_name, session_name=None, var_sub=None, description=None, td_tag=None, vc_tag=None)[source]

Sends all commands from all rows that are marked execute=yes from the testdata

This keyword expects the usage of warrior framework’s recommended testdata xml files, sample testdata file is available in Warriorspace/Config_files/sample/testdata_sample.xml

Datafile usage:

Tags or attributes to be used in input datafile for the system or subsystem If both tag and attribute is provided the attribute will be used.

  1. testdata = absolute/relative path of the testdata file.
  2. variable_config = absolute/relative path of the variable config file.

By default the “testdata” and “variable_config” tag/attribute will be used to get the details of testdata and variable config file. If a different tag/attribute name is used, provide the tagnames as the value to the arguments td_tag and vc_tag.

Arguments:
  1. system_name (string) = This can be name of the system or a subsystem. In case of subsystem only single subsystem is supported. Format for subsystem is “system_name[subsystem_name]”
  2. session_name(string) = name of the session to the string
  3. var_sub(string) = the pattern [var_sub] in the testdata commands, start_prompt, end_prompt, verification search will substituted with this value.
  4. description(string) = optional description string that overwrites the default description(wdesc) of the keyword.
    This string will be printed as the keyword description in console logs and result files.
  5. td_tag = custom tag/attribute name of testdata file.
  6. vc_tag = custom tag/attribute name of variable conig file.
Returns:
  1. status(bool)
  2. response dictionary(dict): a dictionary having the responses of all commands sent to the particular system or subsystem. This dictionary is available in warrior frameworks global data_repository and can be retrieved using the key= “session_id + _td_response” where session_id=”system_name+subsystem_name+session_name”
send_command(command, system_name, session_name=None, start_prompt='.*', end_prompt='.*', int_timeout=60)[source]

Sends a command to a system or a subsystem

Arguments:
  1. command(string) = the command to be sent to the system
  2. system_name (string) = This can be name of the system or a subsystem. In case of subsystem only single subsystem is supported. Format for subsystem is “system_name[subsystem_name]”
  3. session_name(string) = name of the session to the system
  4. start_prompt(string) = starting prompt for the command
  5. end_prompt(string) = ending prompt for the command
  6. int_timeout (integer) = timeout for the command
Returns:
  1. command_status(bool)
send_commands_by_testdata_rownum(row_num, system_name, session_name=None, var_sub=None, description=None, td_tag=None, vc_tag=None)[source]

Sends all the commands from testdata that has row equal to the provided row_num

This keyword expects the usage of warrior framework’s recommended testdata xml files, sample testdata file is available in Warriorspace/Config_files/sample/testdata_sample.xml

Datafile usage:

Tags or attributes to be used in input datafile for the system or subsystem If both tag and attribute is provided the attribute will be used.

  1. testdata = absolute/relative path of the testdata file.
  2. variable_config = absolute/relative path of the variable
    config file.

By default the “testdata” and “variable_config” tag/attribute will be used to get the details of testdata and variable config file. If a different tag/attribute name is used, provide the tagnames as the value to the arguments td_tag and vc_tag.

Arguments:
  1. row_num (string) = row number in string representation
  2. system_name (string) = This can be name of the
    system or a subsystem. In case of subsystem only single subsystem is supported. Format for subsystem is “system_name[subsystem_name]”
  3. session_name(string) = name of the session to the string
  4. var_sub(string) = the pattern [var_sub] in the testdata commands,
    start_prompt, end_prompt, verification search will substituted with this value.
  5. description(string) = optional description string that overwrites the
    default description(wdesc) of the keyword. This string will be printed as the keyword description in console logs and result files.
  6. td_tag = custom tag/attribute name of testdata file
  7. vc_tag = custom tag/attribute name of variable config file.
Returns:
  1. status(bool)
  2. response dictionary(dict): a dictionary having the responses of all
    commands sent to the particular system or subsystem. This dictionary is available in warrior frameworks global data_repository and can be retrieved using the key= “session_id + _td_response” where session_id=”system_name+subsystem_name+session_name”
send_commands_by_testdata_title(title, system_name, session_name=None, var_sub=None, description=None, td_tag=None, vc_tag=None)[source]

Sends all the commands from testdata that has title equal to the provided title

This keyword expects the usage of warrior framework’s recommended testdata xml files, sample testdata file is available in Warriorspace/Config_files/sample/testdata_sample.xml

Datafile usage:

Tags or attributes to be used in input datafile for the system or subsystem If both tag and attribute is provided the attribute will be used.

  1. testdata = absolute/relative path of the testdata file.
  2. variable_config = absolute/relative path of the variable
    config file.

By default the “testdata” and “variable_config” tag/attribute will be used to get the details of testdata and variable config file. If a different tag/attribute name is used, provide the tagname as the value to the arguments td_tag and vc_tag.

Arguments:
  1. title (string) = title in string representation
  2. system_name (string) = This can be name of the
    system or a subsystem. In case of subsystem only single subsystem is supported. Format for subsystem is “system_name[subsystem_name]”
  3. session_name(string) = name of the session to the string
  4. var_sub(string) = the pattern [var_sub] in the testdata commands,
    start_prompt, end_prompt, verification search will substituted with this value.
  5. description(string) = optional description string that overwrites the
    default description(wdesc) of the keyword. This string will be printed as the keyword description in console logs and result files.
  6. td_tag = custom tag/attribute name of testdata file.
  7. vc_tag = custom tag/attribute name of variable config file.
Returns:
  1. status(bool)
  2. response dictionary(dict): a dictionary having the responses of all
    commands sent to the particular system or subsystem. This dictionary is available in warrior frameworks global data_repository and can be retrieved using the key= “session_id + _td_response” where session_id=”system_name+subsystem_name+session_name”
send_commands_by_testdata_title_rownum(title, row_num, system_name, session_name=None, var_sub=None, description=None, td_tag=None, vc_tag=None)[source]

Sends all the commands from testdata that has title/row equal to the provided title/row_num

This keyword expects the usage of warrior framework’s recommended testdata xml files, sample testdata file is available in Warriorspace/Config_files/sample/testdata_sample.xml

Datafile usage:

Tags or attributes to be used in input datafile for the system or subsystem If both tag and attribute is provided the attribute will be used.

  1. testdata = absolute/relative path of the testdata file.
  2. variable_config = absolute/relative path of the variable
    config file.

By default the “testdata” and “variable_config” tag/attribute will be used to get the details of testdata and variable config file. If a different tag/attribute name is used, provide the tagnames as the value to the arguments td_tag and vc_tag.

Arguments:
  1. title = Title of the testdata block
  2. row = Row number of the testdata block
  3. system_name (string) = This can be name of the
    system or a subsystem. In case of subsystem only single subsystem is supported. Format for subsystem is “system_name[subsystem_name]”
  4. session_name(string) = name of the session to the string
  5. var_sub(string) = the pattern [var_sub] in the testdata commands,
    start_prompt, end_prompt, verification search will substituted with this value.
  6. description(string) = optional description string that overwrites the
    default description(wdesc) of the keyword. This string will be printed as the keyword description in console logs and result files.
  7. td_tag = custom tag/attribute name of testdata file.
  8. vc_tag = custom tag/attribute name of variable config file.
Returns:
  1. status(bool)
  2. response dictionary(dict): a dictionary having the responses of all
    commands sent to the particular system or subsystem. This dictionary is available in warrior frameworks global data_repository and can be retrieved using the key= “session_id + _td_response” where session_id=”system_name+subsystem_name+session_name”
send_testdata_command_kw(system_name, session_name=None, wdesc='', var_sub=None, title=None, row_num=None, td_tag=None, vc_tag=None)[source]

UseAsKeyword=No - This will not be listed as a keyword in Katana

Arguments:
  1. system_name (string) = name of the system in the input datafile
  2. session_name(string) = name of the session to the string
  3. wdesc(string) = Keyword description
  4. var_sub(string) = the pattern [var_sub] in the testdata commands,
    start_prompt, end_prompt, verification search will substituted with this value.
  5. title = title from the testdata file.
  6. row_num = row from the testdata file.
  7. td_tag = tag/attribute name of testdata file.
  8. vc_tag = tag/attribute name of variable config file.
Returns:
  1. status(bool)
  2. response dictionary(dict): a dictionary having the responses of all
    commands sent to the particular system or subsystem. This dictionary is available in warrior frameworks global data_repository and can be retrieved using the key= “session_id + _td_response” where session_id=”system_name+subsystem_name+session_name”
set_session_timeout(system_name, session_name=None, int_timeout=30)[source]

Sets the timeout period for the ssh/telnet session

Arguments:
  1. system_name(string-mandatory) = name of the system from the input datafile
  2. session_name(string) = name of the session to the system
  3. int_timeout(integer) = timeout value in minutes
Returns:
  1. status(bool)
verify_session_status(system_name, session_name=None)[source]

Checks whether the ssh/telnet session is alive or not

Arguments:
  1. system_name(string-mandatory) = name of the system from the input datafile
  2. session_name(string) = name of the session to the system
Returns:
  1. status(bool) : True if alive, False if not alive

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.