taf.testlib.linux

Submodules

taf.testlib.linux.bench

bench.py

exception taf.testlib.linux.bench.BenchmarkException[source]

Bases: Exception

class taf.testlib.linux.bench.Config(config=None, master_ip=None)[source]

Bases: object

CLASS_LOGGER = <logging.LoggerAdapter object>
load(config)[source]
set_labels(mode)[source]
class taf.testlib.linux.bench.Constants[source]

Bases: object

class taf.testlib.linux.bench.IterableMetaclass[source]

Bases: type

class taf.testlib.linux.bench.KubernetesBenchmark(config)[source]

Bases: taf.testlib.linux.bench.Test

clean_up()[source]
class taf.testlib.linux.bench.Labels[source]

Bases: taf.testlib.linux.bench.Constants

LOCAL_CLIENT = 'local-cl'
LOCAL_SERVER = 'local-srv'
REMOTE_CLIENT = 'remote-cl'
REMOTE_SERVER = 'remote-srv'
SINGLE_VM = 'single-vm'
class taf.testlib.linux.bench.Modes[source]

Bases: taf.testlib.linux.bench.Constants

LOCAL = 'local'
REMOTE = 'remote'
SINGLE_VM = 'single_vm'
class taf.testlib.linux.bench.Test(config=None)[source]

Bases: abc.ABC

AGGREGATORS = {'ab': <class 'utils.ab_parser.AbAggregator'>}
CLASS_LOGGER = <logging.LoggerAdapter object>
PARSERS = {'ab': <class 'utils.ab_parser.AbParser'>}
clean_up()[source]
collect()[source]
prepare()[source]
run()[source]
test_type
taf.testlib.linux.bench.set_node_selector(cfg, selector)[source]

taf.testlib.linux.collectd

collectd.py

Class to abstract collectd operations

Note

collectd.conf path is retrieved from testcases/config/setup/setup.json in format:

{
    "env": [
      {
        "id": "213207",
        "collectd_conf_path": "/opt/collectd/etc/collectd.conf"
      }
    ],
    "cross": {}
}

If “collectd_conf_path” is not specified in setup.json then default value is set: /etc/collectd.conf

Examples of collectd usage in tests:

# If required, stop running collectd service:
env.lhost[1].ui.collectd.stop()

# Start collectd service:
env.lhost[1].ui.collectd.start()

Consistent and valid collectd.conf content is built from OrderedDict object, e.g.:

python_plugin_config = collections.OrderedDict(
    (('ModulePath', '"/tmp/"'),
     ('Interactive', 'false'),
     ('Import', '"python_module_name"'),
     ('Module "python_module_name"', {'Test': 'arg1'})))

env.lhost[1].ui.collectd.plugins_config = collections.OrderedDict(
    (('Interval', 3),
     ('AutoLoadPlugins', 'false'),
     ('LoadPlugin cpu', {}),
     ('LoadPlugin "csv"', {}),
     ('LoadPlugin "python"', {'Interval': 5, 'Globals': 'true'}),
     ('Plugin "csv"', {'DataDir': '"/tmp/csv_data/"'}),
     ('Plugin "python"', python_plugin_config)))

As shown above, config parts that depend on parameters order should be presented as OrderedDict objects. Otherwise, dict() object can be used.

Transform data structure into multiline text block:

env.lhost[1].ui.collectd.update_config_file()

If required, in other test the default plugins configuration may be changed, e.g.:

env.lhost[1].ui.collectd.plugins_config['LoadPlugin "csv"'].update({'Interval': 9})
env.lhost[1].ui.collectd.update_config_file()

Some plugins support multiple entries of parameter with same name. Such case should be presented as:

{param_name: [param1_value, ...]}

Example of resulting collectd.conf file:

Interval 3
AutoLoadPlugins false
<LoadPlugin cpu>
</LoadPlugin>
<LoadPlugin "csv">
    Interval 9
</LoadPlugin>
<LoadPlugin "python">
    Interval 5
    Globals true
</LoadPlugin>
<Plugin "csv">
    DataDir "/tmp/csv_data/"
</Plugin>
<Plugin "python">
    ModulePath "/tmp/"
    Interactive false
    Import "python_module_name"
    <Module "python_module_name">
        Test arg1
    </Module>
</Plugin>

Restart collectd service:

env.lhost[1].ui.collectd.restart()
class taf.testlib.linux.collectd.Collectd(cli_send_command)[source]

Bases: object

SERVICE = 'collectd'
__call__(cmd, expected_rc)[source]

Overloaded call method.

Parameters:
  • cmd (str) – command to execute
  • expected_rc (int | set | list | frozenset) – expected return code
Returns:

named tuple

Return type:

tuple

__getattr__(name)[source]

Method for getting attribute from service_manager.

Parameters:name (str) – attribute name
__init__(cli_send_command)[source]

Initialize Collectd class.

update_config_file()[source]

Create collectd configuration text and write it to collectd.conf file.

class taf.testlib.linux.collectd.IndentationContext(char=' ', count=4, buffer=None)[source]

Bases: object

pad
class taf.testlib.linux.collectd.TagContext(buffer, indent, *tag_args)[source]

Bases: object

taf.testlib.linux.collectd.build_tagged_section(config_data, indent=None, buffer=None)[source]

Fill in data into text block.

Parameters:
  • config_data (collections.Mapping) – plugins configuration data structure
  • indent (int) – indentation level
  • buffer (StringIO object) – resulting text block
Returns:

resulting text block

Return type:

str

taf.testlib.linux.commands.cmd_helper

cmd_helper.py

Flexible command representation with parsing and building support

class taf.testlib.linux.commands.cmd_helper.ArgumentBuilder(args_order=None, args_formatter=None)[source]

Bases: object

ARGS_ORDER = []
classmethod FORMATTER_BY_VALUE_MAP(val_map, default=None)[source]
classmethod FORMATTER_JOIN_KEY_VAL(key=None, val=None, joiner=None)[source]
classmethod FORMAT_ARG_APPEND_LIST(params, key_fmtd=None, val_fmtd=None, **kwargs)[source]
classmethod FORMAT_ARG_JOIN_STR(join_char=None)[source]
classmethod FORMAT_KEY_BY_TAG(tag)[source]
classmethod FORMAT_KEY_FIRST(params, arg_name=None, **kwargs)[source]
classmethod FORMAT_KEY_LAST(params, arg_name=None, **kwargs)[source]
classmethod FORMAT_KEY_LONGEST(params, arg_name=None, **kwargs)[source]
classmethod FORMAT_KEY_SHORTEST(params, arg_name=None, **kwargs)[source]
classmethod FORMAT_NONE(*args, **kwargs)[source]
classmethod FORMAT_VAL_TRANSFORM(trans_f)[source]
build_args(opts_map, pos_map, args, order=None, formatter=None)[source]
classmethod get_formatter()[source]
class taf.testlib.linux.commands.cmd_helper.Command(*args, **kwargs)[source]

Bases: collections.abc.Mapping

Command holder object flexible representation.

CMD_HELPER = <taf.testlib.linux.commands.cmd_helper.CommandHelper object>
check_args(**kwargs)[source]
clear()[source]
classmethod cmd_2_list(cmd)[source]
classmethod cmd_2_str(cmd)[source]
classmethod copy(cmd)[source]
extend(*args, **kwargs)[source]

Add new stuff only

cmd{a: 1, b: 2, c:3} + (cmd{b: ‘b’, c: ‘c’, d: ‘d’}) => cmd{a: 1, b: 2, c: 3, d: ‘d’}

classmethod from_kwargs(**kwargs)[source]
get(k[, d]) → D[k] if k in D, else d. d defaults to None.[source]
get_set_args(**kwargs)[source]
items() → a set-like object providing a view on D's items[source]
keys() → a set-like object providing a view on D's keys[source]
classmethod list_2_cmd(cmd_list)[source]
classmethod merge(cmd_lhs, cmd_rhs)[source]
classmethod str_2_cmd(cmd_str)[source]
to_args_list()[source]
unset(*args, **kwargs)[source]

Remove stuff

cmd{a: 1, b: 2, c: 3} - {cmd{b: ‘b’, c: ‘c’, d: ‘d’} => cmd{a: 1}

update(*args, **kwargs)[source]

Add new stuff and update existing

cmd{a: 1, b: 2, c:3} + (cmd{b: ‘b’, c: ‘c’, d: ‘d’}) => cmd{a: 1, b: ‘b’, c: ‘c’, d: ‘d’}

values() → an object providing a view on D's values[source]
class taf.testlib.linux.commands.cmd_helper.CommandHelper(prog=None, arg_parser=None, conflict_handler=None, params=None, arg_builder=None, default_list=None)[source]

Bases: object

MANGLED_CLS_PREFIX = None
__init__(prog=None, arg_parser=None, conflict_handler=None, params=None, arg_builder=None, default_list=None)[source]
build_cmd_list(**kwargs)[source]

A command builder helper function.

Reverse parse_args() functionality. Converts the input sequence of command arguments(key[:value] pairs) to a command options list.

classmethod check_args(**kwargs)[source]

Input command arguments checking API.

get_set_args(args_in, args_out=None, args_order=None)[source]

A command builder helper function.

Strips the dict off the unset (default) arguments. Learns which fields in ‘args_in’ (dict or argparse.Namespace instance), possibly parsed earlier, had been set before the parsing took place. If an intermediate dict is provided in ‘args_out’, mutate in place and overwrite it on collision.

parse_args(args_list)[source]

taf.testlib.linux.commands.mkdir_cmd

‘’iperf_cmd.py’‘

‘iperf command parsing and building support’

class taf.testlib.linux.commands.mkdir_cmd.CmdMkdir(*args, **kwargs)[source]

Bases: testlib.linux.commands.cmd_helper.Command

CMD_HELPER = <taf.testlib.linux.commands.mkdir_cmd.CmdMkdirHelper object>
class taf.testlib.linux.commands.mkdir_cmd.CmdMkdirHelper(prog=None, arg_parser=None, conflict_handler=None, params=None, arg_builder=None, default_list=None)[source]

Bases: testlib.linux.commands.cmd_helper.CommandHelper

classmethod check_args(*args, **kwargs)[source]

Input command arguments checking API.

class taf.testlib.linux.commands.mkdir_cmd.MkdirArgumentBuilder[source]

Bases: testlib.linux.commands.cmd_helper.ArgumentBuilder

ARGS_ORDERED = ['mode', 'parents', 'verbose', 'context', 'help', 'version', 'name']
classmethod GET_KEY_TAG_SHORT_IF_EXIST_ELSE_LONG(params, arg_name=None, **kwargs)[source]
classmethod get_formatter()[source]

taf.testlib.linux.commands.suricata_cmd

‘’suricata_cmd.py’‘

Suricata command parsing and building support

class taf.testlib.linux.commands.suricata_cmd.CmdSuricata(*args, **kwargs)[source]

Bases: testlib.linux.commands.cmd_helper.Command

CMD_HELPER = <taf.testlib.linux.commands.suricata_cmd.CmdSuricataHelper object>
class taf.testlib.linux.commands.suricata_cmd.CmdSuricataHelper(prog=None, arg_parser=None, conflict_handler=None, params=None, arg_builder=None, default_list=None)[source]

Bases: testlib.linux.commands.cmd_helper.CommandHelper

classmethod check_args(*args, **kwargs)[source]

Input command arguments checking API.

classmethod check_keywords(_CmdSuricataHelper__config=None, _CmdSuricataHelper__pcap_live_mode=None, _CmdSuricataHelper__bpf_filter=None, _CmdSuricataHelper__pcap_offline_mode=None, _CmdSuricataHelper__inline_nfqueue_mode=None, _CmdSuricataHelper__sig_file=None, _CmdSuricataHelper__sig_exc_file=None, _CmdSuricataHelper__log_dir=None, _CmdSuricataHelper__checksum_check=None, _CmdSuricataHelper__runmode=None, _CmdSuricataHelper__pid_file=None, _CmdSuricataHelper__pcap_buf_size=None, _CmdSuricataHelper__user=None, _CmdSuricataHelper__group=None, _CmdSuricataHelper__erf_in=None, _CmdSuricataHelper__set=None, **_CmdSuricataHelper__kwargs)[source]
classmethod check_opt_keywords(_CmdSuricataHelper__list_keywords=None, _CmdSuricataHelper__pcap_mode=None, _CmdSuricataHelper__af_packet=None, _CmdSuricataHelper__unix_socket=None, **_CmdSuricataHelper__kwargs)[source]
classmethod check_opts(_CmdSuricataHelper__test_config=False, _CmdSuricataHelper__daemon=False, _CmdSuricataHelper__version=False, _CmdSuricataHelper__verbosity=False, _CmdSuricataHelper__list_app_layer_prots=False, _CmdSuricataHelper__list_runmodes=False, _CmdSuricataHelper__engine_analysis=False, _CmdSuricataHelper__init_errors_fatal=False, _CmdSuricataHelper__disable_detection=False, _CmdSuricataHelper__dump_config=False, _CmdSuricataHelper__build_info=False, **_CmdSuricataHelper__kwargs)[source]
class taf.testlib.linux.commands.suricata_cmd.SuricataArgumentBuilder[source]

Bases: testlib.linux.commands.cmd_helper.ArgumentBuilder

ARGS_FORMATTER = {'optional': <function ArgumentBuilder.FORMATTER_BY_VALUE_MAP.<locals>.wrapper>, 'positional': <function ArgumentBuilder.FORMAT_VAL_TRANSFORM.<locals>.wrapper>}
ARGS_ORDERED = {'af_packet': {'const': <object object>, 'default': <object object>, 'help': '[=<dev>]: run in af-packet mode, no value select interfaces from suricata.yaml', 'names': {'long': '--af-packet'}, 'nargs': '?'}, 'bpf_filter': {'help': '<bpf filter file>: bpf filter file', 'names': {'short': '-F'}}, 'build_info': {'action': 'store_true', 'help': 'display build information', 'names': {'long': '--build-info'}}, 'checksum_check': {'choices': ['all', 'none'], 'help': '[all|none]: force checksum check (all) or disabled it (none)', 'names': {'short': '-k'}}, 'config': {'help': '<path>: path to configuration file', 'names': {'short': '-c'}}, 'daemon': {'action': 'store_true', 'help': 'run as daemon', 'names': {'short': '-D'}}, 'disable_detection': {'action': 'store_true', 'help': 'disable detection engine', 'names': {'long': '--disable-detection'}}, 'dump_config': {'action': 'store_true', 'help': 'show the running configuration', 'names': {'long': '--dump-config'}}, 'engine_analysis': {'action': 'store_true', 'help': 'print reports on analysis of different sections in the engine and exit. Please have a look at the conf parameter engine-analysis on what reports can be printed', 'names': {'long': '--engine-analysis'}}, 'erf_in': {'help': '<path>: process an ERF file', 'names': {'long': '--erf-in'}}, 'group': {'help': '<group>: run suricata as this group after init', 'names': {'long': '--group'}}, 'init_errors_fatal': {'action': 'store_true', 'help': 'enable fatal failure on signature init error', 'names': {'long': '--init-errors-fatal'}}, 'inline_nfqueue_mode': {'help': '<qid>: run in inline nfqueue mode', 'names': {'short': '-q'}}, 'list_app_layer_prots': {'action': 'store_true', 'help': 'list supported app layer protocols', 'names': {'long': '--list-app-layer-protos'}}, 'list_keywords': {'const': <object object>, 'default': <object object>, 'help': '[=all|csv|<kword>]: list keywords implemented by the engine', 'names': {'long': '--list-keywords'}, 'nargs': '?'}, 'list_runmodes': {'action': 'store_true', 'help': 'list supported runmodes', 'names': {'long': '--list-runmodes'}}, 'log_dir': {'help': '<dir>: default log directory', 'names': {'short': '-l'}}, 'pcap_buf_size': {'help': '<size>: size of the pcap buffer value from 0 - 2147483647', 'names': {'long': '--pcap-buffer-size'}, 'type': <class 'int'>}, 'pcap_live_mode': {'help': '<dev or ip>: run in pcap live mode', 'names': {'short': '-i'}}, 'pcap_mode': {'const': <object object>, 'default': <object object>, 'help': '[=<dev>]: run in pcap mode, no value select interfaces from suricata.yaml', 'names': {'long': '--pcap'}, 'nargs': '?'}, 'pcap_offline_mode': {'help': '<path>: run in pcap file/offline mode', 'names': {'short': '-r'}}, 'pid_file': {'help': '<file>: write pid to this file', 'names': {'long': '--pidfile'}}, 'runmode': {'help': '<unmode_id>: specific runmode modification the engine should run. The argument supplied should be the id for the runmode obtained by running --list-runmodes', 'names': {'long': '--runmode'}}, 'set': {'help': 'name=value: set a configuration value', 'names': {'long': '--set'}}, 'sig_exc_file': {'help': '<path>: path to signature file loaded exclusively (optional)', 'names': {'short': '-S'}}, 'sig_file': {'help': '<path>: path to signature file loaded in addition to suricata.yaml settings (optional)', 'names': {'short': '-s'}}, 'test_config': {'action': 'store_true', 'help': 'test configuration file (use with -c)', 'names': {'short': '-T'}}, 'unix_socket': {'const': <object object>, 'default': <object object>, 'help': '[=<file>]: use unix socket to control suricata work', 'names': {'long': '--unix-socket'}, 'nargs': '?'}, 'user': {'help': '<user>: run suricata as this user after init', 'names': {'long': '--user'}}, 'verbosity': {'action': 'store_true', 'help': 'increase default Suricata verbosity', 'names': {'short': '-v'}}, 'version': {'action': 'store_true', 'help': 'display Suricata version', 'names': {'short': '-V'}}}
classmethod FORMAT_ARG_JOIN_BY_KEY_CLASS(params, arg_name=None, key_fmtd=None, val_fmtd=None, **kwargs)[source]
classmethod get_args_formatter(redo=False)[source]

taf.testlib.linux.dcrpd.dcrpd

dcrpd.py

Class to abstract dcrpd operations

class taf.testlib.linux.dcrpd.dcrpd.Dcrpd(run_command, switch)[source]

Bases: object

CONFIG_PATH = '/usr/lib/systemd/system/'
MANIFEST_FILE = '/usr/lib/systemd/system/dcrpd.service'
SERVICE = 'dcrpd'
__init__(run_command, switch)[source]

Initialize Dcrpd class.

Parameters:run_command (function) – function that runs the actual commands
disable()[source]

Disabling dcrpd service on start.

Raises:UICmdException – On non-zero return code
enable()[source]

Enabling dcrpd service on start.

Raises:UICmdException – On non-zero return code
force_reload()[source]

Restarting the switch driver and then the dcrpd process.

Raises:UICmdException – On non-zero return code
get_status()[source]

Get dcrpd process status.

Raises:UICmdException – On non-zero or non-three return code
Returns:str
restart()[source]

Restarting dcrpd process.

Raises:UICmdException – On non-zero return code
start()[source]

Start dcrpd process.

Raises:UICmdException – On non-zero return code
stop()[source]

Stop dcrpd process.

Raises:UICmdException – On non-zero return code

taf.testlib.linux.dpdk

dpdk.py

Class for dpdk operations

Note

Examples of dpdk usage in tests:

inst.ui.dpdk.modify_iface_status(bind_action='bind', ifaces=["0000:01:00.0", "01:00.0"],
                                 drv='igb_uio', force=False, show_status=True)
class taf.testlib.linux.dpdk.Dpdk(cli_send_command)[source]

Bases: object

Class for interfaces modifications using DPDK tools.

SERVICE = 'dpdk-devbind'
__init__(cli_send_command)[source]

Initialize DPDK class.

modify_iface_status(bind_action='', ifaces=None, drv='', force=False, show_status=False)[source]

Performs binding, unbinding NICs to specific driver and/or showing NICs status.

Parameters:
  • ifaces (str) – List of network interfaces in format <domain:bus:slot.func> or <bus:slot.func>
  • bind_action (str) – action to be performed on NICs: bind | unbind
  • drv (str) – Driver file name (without extension)
  • force (bool) – Flag to override modifying NIC used by Linux
  • show_status (bool) – Flag to override modifying NIC used by Linux
Returns:

None or dictionary with interfaces status information

Return type:

None or list(dict)

taf.testlib.linux.etcd_helper

etcd_helper.py

class taf.testlib.linux.etcd_helper.EtcdHelper(endpoint)[source]

Bases: object

CLASS_LOGGER = <logging.LoggerAdapter object>
change_dir(directory)[source]
init_etcd()[source]
latest_id
read_list(key)[source]
wait_for_key_count(key, count, timeout=15)[source]
exception taf.testlib.linux.etcd_helper.EtcdHelperException[source]

Bases: Exception

taf.testlib.linux.hugepages

hugepages.py

Class to abstract hugepages operations

class taf.testlib.linux.hugepages.HugePages(cli_send_command)[source]

Bases: object

__init__(cli_send_command)[source]

Initialize Hugepages class.

_hugepages_helper(kwargs)[source]

Helper function for getting and setting hugepages.

Parameters:kwargs (dict) – Arguments to pass
Returns:Returns CmdStatus namedtuple of stdout, stderr, return code
Return type:tuple(str, str, int) | CmdStatus
change_number(nr_hugepages, per_node=None, hugepage_size=2048)[source]

Change number of hugepages.

Parameters:
  • nr_hugepages (int) – Number of hugepages
  • per_node (int) – Number of hugepages per node or per system
  • hugepage_size (int) – Current hugepage allocated size
get_free_memory(per_node=None, hugepage_size=2048)[source]

Get free hugepages

Parameters:
  • per_node (int) – Get number of free hugepages per node or per system
  • hugepage_size (int) – Current hugepage allocated size
Returns:

Returns number of free hugepages

Return type:

int

get_number(per_node=None, hugepage_size=2048)[source]

Get number of hugepages.

Parameters:
  • per_node (int) – Get number of hugepages per node or per system
  • hugepage_size (int) – Current hugepage allocated size
Returns:

Returns number of hugepages

Return type:

int

mount(nr_hugepages, per_node=None, mnt_dir='/mnt/huge', hugepage_size=2048, **kwargs)[source]

Mount hugepages.

Parameters:
  • nr_hugepages (int) – Number of hugepages
  • per_node (int) – Mount per node or per system
  • mnt_dir (str) – Mount dir
  • hugepage_size (int) – Current hugepage allocated size
  • kwargs (dict) – Additional arguments to pass to commandline
umount(mnt_dir='/mnt/huge', **kwargs)[source]

Unmount hugepages.

Parameters:
  • mnt_dir (str) – Dir to unmount
  • kwargs (dict) – Additional arguments to pass to commandline

taf.testlib.linux.ipmitool

ipmitool.py

Class to abstract ipmitool operations

class taf.testlib.linux.ipmitool.IpmiTool(run_command)[source]

Bases: object

SERVICE = 'ipmitool'
__init__(run_command)[source]

Initialize IpmiTool class.

clear_sel()[source]

Method for clear System Event Log.

generate_event(sensor, sensor_state)[source]

Method for generating event for sensor with sensor state.

Parameters:
  • sensor (str) – name of sensor
  • sensor_state (str) – name of sensor state
get_sdr_list()[source]

Get all available Sensor Data Repository entries.

Returns:Returns list of sdr
Return type:list
get_sensors_states(sensor, expected_rcs=frozenset({0, 1}))[source]

Get all available sensor states for sensor.

Parameters:
  • sensor (str) – name of sensor
  • expected_rcs (set) – if sensor is not available in HW rc=1, but events for sensor could be generated
Returns:

Returns list of sensor states

Return type:

list

is_ipmi_supported_by_system()[source]

Method for check if ipmi is supported by device.

taf.testlib.linux.kubernetes

kubernetes.py

class taf.testlib.linux.kubernetes.Kubernetes(endpoint)[source]

Bases: object

class taf.testlib.linux.kubernetes.KubernetesHelper(kubernetes)[source]

Bases: object

clear_labels(nodes, labels)[source]
get_number_of_pods()[source]
label_node(name, labels)[source]

taf.testlib.linux.libvirt

libvirt.py

Class to abstract libvirt operations

Notes

Examples of libvirt usage in tests:

env.lhost[1].ui.libvirt.start()
env.lhost[1].ui.libvirt.stop()
env.lhost[1].ui.libvirt.restart()
env.lhost[1].ui.libvirt.virsh_execute_command('list')
env.lhost[1].ui.libvirt.virsh_execute_command('domstats vm_name', exp_rc = frozenset({1})))
class taf.testlib.linux.libvirt.Libvirt(cli_send_command)[source]

Bases: object

SERVICE = 'libvirtd'
__call__(cmd, expected_rc)[source]

Overloaded call method.

Parameters:
  • cmd (str) – command to execute
  • expected_rc (int | set | list | frozenset) – expected return code
Returns:

named tuple

Return type:

tuple

__getattr__(name)[source]

Method for getting attribute from service_manager.

Parameters:name (str) – attribute name
__init__(cli_send_command)[source]

Initialize libvirt class.

virsh_execute_command(command, expected_rc=frozenset({0}))[source]

Method for virsh command execution.

Parameters:
  • command (str) – command to execute
  • expected_rc (int | set | list | frozenset) – expected return code
Returns:

named tuple

Return type:

tuple

taf.testlib.linux.lldp.lldp

lldp.py

class taf.testlib.linux.lldp.lldp.ChassisIdSubTypes[source]

Bases: enum.IntEnum

An enumeration.

CHASSIS_COMPONENT = 1
INTERFACE_ALIAS = 2
INTERFACE_NAME = 6
LOCALLY_ASSIGNED = 7
MAC_ADDRESS = 4
NETWORK_ADDRESS = 5
PORT_COMPONENT = 3
RESERVED = 0
class taf.testlib.linux.lldp.lldp.Lldp(run_command)[source]

Bases: object

_get_lldp_tlvs_list(show_command)[source]
Parameters:show_command (str) – lldptool show-tlv command
Returns:list of tlvs
Return type:list
clear_settings()[source]
get_adminstatus(port_name)[source]
get_local_tlvs(port_name)[source]
get_remote_tlvs(port_name)[source]
set_adminstatus(port_name, status)[source]
set_enable_tx(port_name, tlv, enable_tx)[source]
class taf.testlib.linux.lldp.lldp.ManAddrIfSubTypes[source]

Bases: enum.IntEnum

An enumeration.

IFINDEX = 2
SYS_PORT_NUM = 3
UNKNOWN = 1
class taf.testlib.linux.lldp.lldp.ManAddrSubTypes[source]

Bases: enum.IntEnum

An enumeration.

AFI = 25
ALL802 = 6
APPLETALK = 12
ASNUMBER = 18
BANYANVINES = 14
BBN1822 = 5
DECNETIV = 13
DISTINGUISHEDNAME = 17
DNS = 16
E163 = 7
E164 = 8
E164WITHNSAP = 15
F69 = 9
FIBRECHANNELWWNN = 23
FIBRECHANNELWWPN = 22
GWID = 24
HDLC = 4
IPV4 = 1
IPV6 = 2
IPX = 11
NSAP = 3
OTHER = 0
RESERVED = 65535
X121 = 10
XTPNATIVEMODEXTP = 21
XTPOVERIPV4 = 19
XTPOVERIPV6 = 20
class taf.testlib.linux.lldp.lldp.PortIdSubTypes[source]

Bases: enum.IntEnum

An enumeration.

AGENT_CIRCUIT_ID = 6
INTERFACE_ALIAS = 1
INTERFACE_NAME = 5
LOCALLY_ASSIGNED = 7
MAC_ADDRESS = 3
NETWORK_ADDRESS = 4
PORT_COMPONENT = 2
RESERVED = 0

taf.testlib.linux.lldp.lldptool

lldptool.py

class taf.testlib.linux.lldp.lldptool.AppCollector[source]

Bases: object

class taf.testlib.linux.lldp.lldptool.CEESubTLVParser(tlv_handlers=None)[source]

Bases: object

TLV_DATA_RE = re.compile('^(?:\t| {8})\\s+\\S[^\n]+')
TLV_RE = re.compile('^(?:\t| {8})\\S[^\n]+TLV')
add_tlv(tlv)[source]
parse(lines)[source]
class taf.testlib.linux.lldp.lldptool.EndState(parser)[source]

Bases: taf.testlib.linux.lldp.lldptool.State

class taf.testlib.linux.lldp.lldptool.ErrorState(parser)[source]

Bases: taf.testlib.linux.lldp.lldptool.State

class taf.testlib.linux.lldp.lldptool.IEEEAppTLVParser(tlv_handlers=None)[source]

Bases: object

add_tlv(tlv)[source]
parse(lines)[source]
class taf.testlib.linux.lldp.lldptool.Parser(tlv_handlers)[source]

Bases: object

END_TLV_RE = re.compile('^End of LLDPDU TLV')
NON_TLV_RE = re.compile('^(\\S[^\n]+)(?!TLV)')
TLV_DATA_RE = re.compile('^\\s+([^\n]+)')
TLV_RE = re.compile('^(\\S[^\n]+)TLV')
add_tlv(tlv)[source]
parse(lines)[source]
class taf.testlib.linux.lldp.lldptool.Start(parser)[source]

Bases: taf.testlib.linux.lldp.lldptool.State

end_tlv(l)[source]
non_tlv(l)[source]
tlv(l)[source]
tlv_data(_)[source]
class taf.testlib.linux.lldp.lldptool.State(parser)[source]

Bases: object

class taf.testlib.linux.lldp.lldptool.TLV(parser)[source]

Bases: taf.testlib.linux.lldp.lldptool.State

end_tlv(_)[source]
non_tlv(_)[source]
set_tlv_type(l)[source]
tlv(_)[source]
tlv_data(l)[source]
class taf.testlib.linux.lldp.lldptool.TLVData(parser)[source]

Bases: taf.testlib.linux.lldp.lldptool.State

end_tlv(l)[source]
non_tlv(l)[source]
start_tlv(name, l)[source]
tlv(l)[source]
tlv_data(l)[source]
class taf.testlib.linux.lldp.lldptool.TlvNames[source]

Bases: object

CEE_DCBX = 'CEE DCBX TLV'
CHASSIS_ID = 'Chassis ID TLV'
END_OF_LLDPDU = 'End of LLDPDU TLV'
EVB_DRAFT_0_2_CONFIGURATION = 'EVB draft 0.2 Configuration TLV'
IEEE_8021QAZ_ETS_CONFIGURATION = 'IEEE 8021QAZ ETS Configuration TLV'
IEEE_8021QAZ_PFC = 'IEEE 8021QAZ PFC TLV'
LLDP_MED_ASSET_ID = 'LLDP-MED Asset ID TLV'
LLDP_MED_CAPABILITIES = 'LLDP-MED Capabilities TLV'
LLDP_MED_FIRMWARE_REVISION = 'LLDP-MED Firmware Revision TLV'
LLDP_MED_HARDWARE_REVISION = 'LLDP-MED Hardware Revision TLV'
LLDP_MED_MANUFACTURER_NAME = 'LLDP-MED Manufacturer Name TLV'
LLDP_MED_MODEL_NAME = 'LLDP-MED Model Name TLV'
LLDP_MED_SERIAL_NUMBER = 'LLDP-MED Serial Number TLV'
LLDP_MED_SOFTWARE_REVISION = 'LLDP-MED Software Revision TLV'
MAC_PHY_CONFIGURATION_STATUS = 'MAC/PHY Configuration Status TLV'
MANAGEMENT_ADDRESS = 'Management Address TLV'
MAXIMUM_FRAME_SIZE = 'Maximum Frame Size TLV'
PORT_DESCRIPTION = 'Port Description TLV'
PORT_ID = 'Port ID TLV'
SYSTEM_CAPABILITIES = 'System Capabilities TLV'
SYSTEM_DESCRIPTION = 'System Description TLV'
SYSTEM_NAME = 'System Name TLV'
TIME_TO_LIVE = 'Time to Live TLV'
taf.testlib.linux.lldp.lldptool.application_tlv_handler(val)[source]
taf.testlib.linux.lldp.lldptool.cee_sub_tlv_handler(val)[source]
taf.testlib.linux.lldp.lldptool.cee_sub_tlv_handler_into_list(val)[source]
taf.testlib.linux.lldp.lldptool.comma_sep_ints(s)[source]
taf.testlib.linux.lldp.lldptool.control_tlv_handler(val)[source]
taf.testlib.linux.lldp.lldptool.find_all_colon_key_vals(s)[source]
taf.testlib.linux.lldp.lldptool.ieee_app_tlv_handler(val)[source]
taf.testlib.linux.lldp.lldptool.ieee_priority_flow_control_enabled_handler(pfc_enabled)[source]
taf.testlib.linux.lldp.lldptool.int_auto_base(n)[source]

Convert string to an int, automatically detecting the base.

taf.testlib.linux.lldp.lldptool.non_subtype_handler(tlvs)[source]
taf.testlib.linux.lldp.lldptool.parse(s)[source]
taf.testlib.linux.lldp.lldptool.parse_enabled_willing_error(val)[source]
taf.testlib.linux.lldp.lldptool.parse_into_list(s)[source]
taf.testlib.linux.lldp.lldptool.parse_set(s)[source]
taf.testlib.linux.lldp.lldptool.pgid_percentages(pgid_percents)[source]
taf.testlib.linux.lldp.lldptool.pgid_priorities(pgid_prios)[source]
taf.testlib.linux.lldp.lldptool.priority_flow_control_enabled_handler(pfc_enabled)[source]
taf.testlib.linux.lldp.lldptool.priority_flow_control_tlv_handler(val)[source]
taf.testlib.linux.lldp.lldptool.priority_group_tlv_handler(val)[source]
taf.testlib.linux.lldp.lldptool.sub_tlv_as_dict_handler_factory(sub_tlv_handlers)[source]
taf.testlib.linux.lldp.lldptool.subtype_handler(tlvs)[source]
Parameters:tlvs
Returns:list of subtype, value pairs
Return type:list
taf.testlib.linux.lldp.lldptool.tlv_name_to_python_const(t)[source]
taf.testlib.linux.lldp.lldptool.tsa_value(s)[source]
taf.testlib.linux.lldp.lldptool.up2tc_value(s)[source]
taf.testlib.linux.lldp.lldptool.yes_no_to_bool(s)[source]

taf.testlib.linux.lldp.lldptool_unittest

lldptool_unittest.py

class taf.testlib.linux.lldp.lldptool_unittest.LLDPToolParse(methodName='runTest')[source]

Bases: unittest.case.TestCase

test_cee_app()[source]
test_ieee_pfc()[source]
static test_lldptool_set()[source]
test_pg()[source]
test_pgid_percentages()[source]
test_pgid_priorites()[source]
test_set_config_ets()[source]
test_set_config_pfc()[source]
class taf.testlib.linux.lldp.lldptool_unittest.TestLldptool(methodName='runTest')[source]

Bases: unittest.case.TestCase

test_full_ti()[source]
test_full_tni()[source]
test_ieee_full_ti()[source]
test_ieee_full_tni()[source]
test_just_tlv_data()[source]
test_mutiple_tlv_names_no_data()[source]
test_only_errors()[source]
test_tlv_data()[source]
test_tlv_name()[source]
test_tlv_name_end_junk()[source]
test_tlv_no_data_end_tlv()[source]
test_tlv_no_data_with_error()[source]
test_whitespace_before_tlv_name()[source]
test_zero_lenght_value()[source]

taf.testlib.linux.maa.maa

maa.py

Class to abstract match action acceleration operations

class taf.testlib.linux.maa.maa.MatchActionAcceleration(run_command)[source]

Bases: object

__init__(run_command)[source]

Initialize MatchActionAcceleration class.

Parameters:run_command (function) – function that runs the actual commands
create_maa_rule(prio_id, handle_id, table_id, match_field_value_mask_list, action, action_value=None)[source]

Set a rule into the table.

Parameters:
  • prio_id (int) – Higher id has a higher priority.
  • handle_id (int) – handle for match.
  • table_id (int) – the source table id where match to be set.
  • match_field_value_mask_list (list[tuple(str, str, str)]) – field with match field, value and mask.
  • action (str) – given action for source table
  • action_value (int) – action value for a specified action
Raises:
  • UIException – for TypeError - Not enough arguments for format string
  • UIException – In case of Command execution Error reported in MatchAPI
create_maa_tcam_subtable(source_id, table_id, table_name, max_table_entries, match_field_type_pairs, actions)[source]

Create a sub-table of tcam.

Parameters:
  • source_id (int) – the source id in the tcam table.
  • table_id (int) – a given table id. If switchd is running, table id starts from 5 If matchd is running, table id starts from 4
  • table_name (str) – a given table name.
  • max_table_entries (int) – maximum number of rules can be set.
  • match_field_type_pairs (list[tuple(str, str)]) – list of given match field with match type
  • actions (list[str]) – list of actions for configurable matches
Raises:
  • UIException – System table id not supported
  • UIException – for TypeError - Not enough arguments for format string
  • UIException – In case of Command execution Error reported in MatchAPI
delete_maa_rule(handle_id, table_id)[source]

Delete a rule from the table.

Parameters:
  • handle_id (int) – handle for rule.[MANDATORY]
  • table_id (int) – the source table id where rule to be set.[MANDATORY]
Raises:

UIException – In case of Command execution Error reported in MatchAPI

delete_maa_tcam_subtable(source_id, table_id=0, table_name=None)[source]

Destroy a sub-table of tcam.

Parameters:
  • source_id (int) – the source id in the tcam table.[MANDATORY]
  • table_id (int) – a given table id.[MANDATORY if table_name not specified]
  • table_name (str) – a given table name.[MANDATORY if table_id not specified]
Raises:
  • UIException – System table id not supported
  • UIException – In case of Command execution Error reported in MatchAPI
get_maa_rules(table_id, handle_id=None)[source]

Lists the match api rules of the table.

Parameters:
  • table_id (int) – table ID (mandatory parameter)
  • handle_id (int) – optional parameter
Returns:

list[dict]

get_maa_table(table_id=None)[source]

Lists the match api tables.

Parameters:table_id (int) – table ID
Returns:list[dict]

taf.testlib.linux.networkd

networkd.py

Class to abstract networkd operations

class taf.testlib.linux.networkd.NetworkD(run_command, mgmt_ports)[source]

Bases: object

CONFIG_PATH = '/etc/systemd/network/'
SERVICE = 'systemd-networkd'
__init__(run_command, mgmt_ports)[source]

Initialize NetworkD class.

Parameters:
  • run_command (function) – function that runs the actual commands
  • mgmt_ports (iter) – list of mgmt ports to treat specially
clear_settings(exclude_ports=None)[source]

Clear networkd settings for all ports except those excluded.

Parameters:exclude_ports (iter()) – list of extra ports to exclude from clear settings, is appended to mgmt_ports
restart()[source]

Restarting systemd-networkd process.

Returns:True if result is none otherwise false
Return type:bool
start()[source]
stop()[source]

taf.testlib.linux.openvswitch

openvswitch.py

Class to abstract openvswitch operations

Note

Examples of openvswitch usage in tests:

env.lhost[1].ui.openvswitch.start()
env.lhost[1].ui.openvswitch.stop()
env.lhost[1].ui.openvswitch.restart()
env.lhost[1].ui.openvswitch.add_bridge('br0')
env.lhost[1].ui.openvswitch.get_interface_info('br0')
env.lhost[1].ui.openvswitch.del_interface('br0')
env.lhost[1].ui.openvswitch.set_ovsdb_manager(ptcp=6640)
class taf.testlib.linux.openvswitch.OpenvSwitch(cli_send_command, switch_map, name_to_switchid_map)[source]

Bases: object

SERVICE = 'openvswitch-switch'
__init__(cli_send_command, switch_map, name_to_switchid_map)[source]

Initialize openvswitch class.

add_bond(br_name, bond_name, ports)[source]

Bond ovs interfaces.

Parameters:
  • br_name (str) – name of ovs bridge
  • bond_name (str) – name of the bond
  • ports (list) – ports to bond
add_bridge(br_name)[source]

Add new openvswitch bridge.

Parameters:br_name (str) – name of ovs bridge
add_interface(br_name, iface_name)[source]

Add new openvswitch interface.

Parameters:
  • br_name (str) – name of ovs bridge
  • iface_name (str) – name of ovs interface
del_bridge(br_name)[source]

Delete openvswitch bridgew.

Parameters:br_name (str) – name of ovs bridge
del_interface(br_name, iface_name)[source]

Delete interface from openvswitch.

Parameters:
  • br_name (str) – name of ovs bridge
  • iface_name (str) – name of ovs interface
delete_all_bridges()[source]

Delete all existing bridges from ovsdb.

get_existing_bridges_interfaces()[source]

Get already existing bridges and interfaces from ovsdb.

Returns:list of existing ovs bridges and interfaces
Return type:list
get_interface_info(interface_name)[source]

Get ovs interface information from ovsdb.

Parameters:interface_name (str) – name of ovs interface
Returns:Output of OVS interface information
Return type:dict
get_interface_statistic(iface_name)[source]

Get ovs interface statistic from ovsdb.

Parameters:iface_name (str) – name of ovs interface
Returns:Output of OVS interface statistics
Return type:dict
get_interface_statistic_counter(iface_name, counter_name)[source]

Get ovs interface statistic from ovsdb.

Parameters:
  • iface_name (str) – name of ovs interface
  • counter_name (str) – name of ovs interface counter
Returns:

Output of OVS interface statistics

Return type:

dict

get_status()[source]

Method for get openvswitch status.

Returns:ovs status ‘active’ or ‘inactive’
Return type:list
get_table_record(table, rec, column)[source]

Get column value in record in specific table.

Parameters:
  • table (str) – name of ovs table
  • rec (str) – name of ovs record
  • column (str) – Column value to get
Returns:

Returns StdOut of get command

Return type:

str

restart()[source]

Restart openvswitch service.

set_bridge_port_interface(inst_type, name, **kwargs)[source]

Method set parameters for bridge, port or interface.

Parameters:
  • inst_type (str) – could be Bridge, Port or Interface
  • name (str) – name of ovs bridge, port or interface
  • kwargs (dict) – options to be set for bridge, port or interface
Raises:

CustomException

set_ovsdb_manager(**kwargs)[source]

Set connection type to ovsdb.

Parameters:kwargs (dict) – type of ovsdb connection
Raises:CustomException
set_table_record(table, rec, **kwargs)[source]

Set column values in record in specific table.

Parameters:
  • table (str) – name of ovs table
  • rec (str) – name of ovs record
  • kwargs (dict) – Column values dict to set
start(ovs_dpdk_opts=None)[source]

Start openvswitch service

Parameters:ovs_dpdk_opts (dict | None) – option indicating OVS run with or without DPDK

Note

If ovs_dpdk_opts is provided, a dictionary with EAL parameters is expected. Else it is assumed that vanilla OVS service start is expected.

status(exp_rc=frozenset({0, 3}))[source]

Get openvswitch process status.

Parameters:exp_rc (int | set | list | frozenset) – expected return code
Returns:named tuple
stop()[source]

Stop openvswitch service.

update_map(iface_name, delete=False)[source]

Update switch_map and name_to_switchid_map.

Parameters:
  • iface_name (str) – name of ovs bridge or interface
  • delete (bool) – if True - remove from switch_map and name_to_switchid_map

taf.testlib.linux.service_lib

service_lib.py

SystemD service library

class taf.testlib.linux.service_lib.GenericServiceManager(run_func, command_list=None)[source]

Bases: object

is_running(service='')[source]
is_stopped(service='')[source]
class taf.testlib.linux.service_lib.ReturnCodes[source]

Bases: object

RUNNING = 0
STOPPED = 3
SUCCESS = 0
UNKNOWN = None
class taf.testlib.linux.service_lib.ServiceCommandGenerator(command_generator, return_codes=<class 'taf.testlib.linux.service_lib.ReturnCodes'>, command_list=None)[source]

Bases: object

class taf.testlib.linux.service_lib.ServiceConfigChangeContext(specific_service_manager)[source]

Bases: object

Context manager suitable for service configuration.

class taf.testlib.linux.service_lib.SpecificServiceManager(service_name, run_func)[source]

Bases: taf.testlib.linux.service_lib.GenericServiceManager

class taf.testlib.linux.service_lib.SystemdReturnCodes[source]

Bases: taf.testlib.linux.service_lib.ReturnCodes

class taf.testlib.linux.service_lib.SystemdServiceManager(run)[source]

Bases: taf.testlib.linux.service_lib.GenericServiceManager

static change_default_runlevel(runlevel='multi-user.target')[source]
taf.testlib.linux.service_lib.systemd_command_generator(command)[source]

taf.testlib.linux.stresstool

stresstool.py

Run stress tool on the remote host and parse output

class taf.testlib.linux.stresstool.Line(loglevel, worker, message)

Bases: tuple

__getnewargs__()

Return self as a plain tuple. Used by copy and pickle.

static __new__(_cls, loglevel, worker, message)

Create new instance of Line(loglevel, worker, message)

__repr__()

Return a nicely formatted representation string

_asdict()

Return a new OrderedDict which maps field names to their values.

classmethod _make(iterable, new=<built-in method __new__ of type object>, len=<built-in function len>)

Make a new Line object from a sequence or iterable

_replace(**kwds)

Return a new Line object replacing specified fields with new values

loglevel

Alias for field number 0

message

Alias for field number 2

worker

Alias for field number 1

class taf.testlib.linux.stresstool.StressParser[source]

Bases: object

Class for parsing stress output.

__init__()[source]

Initialize StressParser class.

static parse(output)[source]

Parse output from stress execution.

Parameters:output (str) – stress output
Returns:list of parsed stress results
Return type:list
class taf.testlib.linux.stresstool.StressTool(run_command)[source]

Bases: testlib.linux.tool_general.GenericTool

Class for Stress tool functionality.

__init__(run_command)[source]

Initialize StressTool class.

Parameters:run_command (function) – function that runs the actual commands
parse(output)[source]

Parse the stress output.

Parameters:output (str) – stress origin output
Returns:list of parsed stress results
Return type:list
start(cpu=None, vm=None, vm_bytes=None, io=None, disk=None, time=10, **kwargs)[source]

Generate stress command, launch stress and store results in the file.

Parameters:
  • cpu (int) – number of CPU workers
  • vm (int) – number of memory workers
  • vm_bytes (str) – amount of used memory
  • io (int) – number of IO workers
  • disk (str) – number of disk workers
  • time (int) – time of execution
Returns:

tool instance ID

Return type:

int

taf.testlib.linux.suricata.parser

parser.py

Suricata rules parsing support

class taf.testlib.linux.suricata.parser.AST_N_Node(n, parent=<taf.testlib.linux.suricata.parser.TreeNodeBase object>, data=None)[source]

Bases: taf.testlib.linux.suricata.parser.AST_Node

AST Nonterminal nodes.

classmethod NP_GEN_DATA(data_predicate)[source]
classmethod NP_IS_NONTERMINAL(node)[source]
classmethod NP_IS_TERMINAL(node)[source]
expand_node(products, is_terminal=None)[source]
classmethod from_products(products, parent=<taf.testlib.linux.suricata.parser.TreeNodeBase object>, is_terminal=None)[source]
get_child_nodes(**kwargs)[source]
get_nodes(predicate=None, depth=None, add_self=False)[source]
class taf.testlib.linux.suricata.parser.AST_Node(parent=<taf.testlib.linux.suricata.parser.TreeNodeBase object>, data=None)[source]

Bases: taf.testlib.linux.suricata.parser.TreeNode

is_leaf()[source]
class taf.testlib.linux.suricata.parser.AST_Node_Iterator(ast_node)[source]

Bases: object

next()
class taf.testlib.linux.suricata.parser.AST_Node_Pred[source]

Bases: object

AST Node predicates helper.

classmethod NP_GEN_DATA(data_predicate)[source]
classmethod NP_IS_LEAF(node)[source]
classmethod NP_IS_NONTERMINAL(node)[source]
classmethod NP_IS_TERMINAL(node)[source]
class taf.testlib.linux.suricata.parser.AST_T_Node(parent=<taf.testlib.linux.suricata.parser.TreeNodeBase object>, data=None)[source]

Bases: taf.testlib.linux.suricata.parser.AST_Node

AST Terminal - leaf nodes.

is_leaf()[source]
class taf.testlib.linux.suricata.parser.HostLexer(**options)[source]

Bases: pygments.lexer.RegexLexer

tokens = {'root': [('\\s+', Token.Text.Whitespace), ('any', Token.Keyword.Any), ('pass', Token.Keyword.Action.Pass), ('reject', Token.Keyword.Action.Reject), ('drop', Token.Keyword.Action.Drop), ('alert', Token.Keyword.Action.Alert), ('ip', Token.Keyword.Proto.Ip), ('tcp', Token.Keyword.Proto.Tcp), ('udp', Token.Keyword.Proto.Udp), ('icmp', Token.Keyword.Proto.Icmp), ('\\[', Token.Operator.LeftBracket), (']', Token.Operator.RightBracket), ('!', Token.Operator.ExclMark), (',', Token.Operator.Comma), ('\\d+\\.\\d+\\.\\d+\\.\\d+/\\d+', Token.IPv4.Addr_w_Mask), ('\\d+\\.\\d+\\.\\d+\\.\\d+', Token.IPv4.Addr), ('\\$[\\w_][\\w_\\d]*', Token.Variable)]}
class taf.testlib.linux.suricata.parser.HostParser[source]

Bases: taf.testlib.linux.suricata.parser.LL_Parser

HOST_GRAMMAR = {'N': {'<HOST_EXPR>', '<HOST_GRP>', '<HOST_PARENS_CONTD>'}, 'R': {(('<HOST_GRP>',), (Token.Operator.ExclMark, '<HOST_GRP>')), (('<HOST_PARENS_CONTD>',), ()), (('<HOST_GRP>',), ('<HOST_EXPR>',)), (('<HOST_PARENS_CONTD>',), (Token.Operator.Comma, '<HOST_GRP>', '<HOST_PARENS_CONTD>')), (('<HOST_EXPR>',), (Token.Variable,)), (('<HOST_EXPR>',), (Token.IPv4,)), (('<HOST_GRP>',), (Token.Operator.LeftBracket, '<HOST_GRP>', '<HOST_PARENS_CONTD>', Token.Operator.RightBracket))}, 'S': '<HOST_GRP>', 'T': {Token.IPv4.Addr, Token.IPv4.Addr_w_Mask, Token.Operator.Comma, Token.Operator.ExclMark, Token.Operator.LeftBracket, Token.Operator.RightBracket, Token.Variable}}
classmethod disjoint_sets(*args)[source]
classmethod interpret_host(host_node, symbol_table)[source]
classmethod semantics(tree_node, symbol_table, check=False)[source]
class taf.testlib.linux.suricata.parser.LL_Parser(grammar)[source]

Bases: object

classmethod SyntaxError(node_root=None, node_ptr=None, tokens=None, got=None)[source]
parse(tokens, ignore_ws=False)[source]
class taf.testlib.linux.suricata.parser.SR_Header(proto, src_host, src_port, direction, dst_host, dst_port)

Bases: tuple

__getnewargs__()

Return self as a plain tuple. Used by copy and pickle.

static __new__(_cls, proto, src_host, src_port, direction, dst_host, dst_port)

Create new instance of SR_Header(proto, src_host, src_port, direction, dst_host, dst_port)

__repr__()

Return a nicely formatted representation string

_asdict()

Return a new OrderedDict which maps field names to their values.

classmethod _make(iterable, new=<built-in method __new__ of type object>, len=<built-in function len>)

Make a new SR_Header object from a sequence or iterable

_replace(**kwds)

Return a new SR_Header object replacing specified fields with new values

direction

Alias for field number 3

dst_host

Alias for field number 4

dst_port

Alias for field number 5

proto

Alias for field number 0

src_host

Alias for field number 1

src_port

Alias for field number 2

class taf.testlib.linux.suricata.parser.Semantic[source]

Bases: object

class taf.testlib.linux.suricata.parser.SuricataRule(action, header, options)

Bases: tuple

__getnewargs__()

Return self as a plain tuple. Used by copy and pickle.

static __new__(_cls, action, header, options)

Create new instance of SuricataRule(action, header, options)

__repr__()

Return a nicely formatted representation string

_asdict()

Return a new OrderedDict which maps field names to their values.

classmethod _make(iterable, new=<built-in method __new__ of type object>, len=<built-in function len>)

Make a new SuricataRule object from a sequence or iterable

_replace(**kwds)

Return a new SuricataRule object replacing specified fields with new values

action

Alias for field number 0

header

Alias for field number 1

options

Alias for field number 2

class taf.testlib.linux.suricata.parser.Tree(root)[source]

Bases: object

class taf.testlib.linux.suricata.parser.TreeNode(parent=<taf.testlib.linux.suricata.parser.TreeNodeBase object>, data=None)[source]

Bases: taf.testlib.linux.suricata.parser.TreeNodeBase

TN_NO_PARENT = <taf.testlib.linux.suricata.parser.TreeNodeBase object>
is_leaf()[source]
is_root()[source]
iter_nodes()[source]
class taf.testlib.linux.suricata.parser.TreeNodeBase[source]

Bases: object

is_leaf()[source]
is_root()[source]
iter_nodes()[source]

taf.testlib.linux.suricata.suricata

suricata.py

Suricata support and helpers

class taf.testlib.linux.suricata.suricata.Suricata(run_command)[source]

Bases: testlib.linux.tool_general.GenericTool

__init__(run_command)[source]

Initialize Suricata class.

Parameters:run_command (function) – function that runs the actual commands
start(prefix=None, options=None, command=None, **kwargs)[source]

Generate suricata command, launch it and store results in the file.

Parameters:
  • prefix (str) – command prefix
  • options (list of str) – intermediate iperf options list
  • command (Command) – intermediate iperf command object
Returns:

suricata instance process info

Return type:

dict

class taf.testlib.linux.suricata.suricata.SuricataHelper[source]

Bases: object

classmethod DATA_DETECT_ENGINE_RULE_RELOAD_ENABLE(yaml_data)[source]
classmethod DATA_OUTPUTS_DROP_ENABLE(yaml_data)[source]
classmethod config_update(ssh_obj, yaml_file, yaml_mods=None, rule_mods=None)[source]

Suricata yaml and rule files config management.

classmethod rule_fmt(action, proto, src_host, src_port, direc, dst_host, dst_port, **kwargs)[source]

taf.testlib.linux.testpmd

testpmd.py

Class for testpmd operations

Note

Examples of testpmd usage in tests:

inst.ui.testpmd.start(end_options='--burst=64', cores='0x3', mem_channels=4, driver_dir='librte_pmd_e1000.so', socket_mem='1024,0', huge_unlink=True)
inst.ui.testpmd.exec_cmd('help')
inst.ui.testpmd.stop()
class taf.testlib.linux.testpmd.TestPmd(host)[source]

Bases: object

__init__(host)[source]

Initialize TestPmd class.

exec_cmd(cmd, timeout=5)[source]

Execute command in interactive testpmd shell.

Parameters:timeout (int) – Timeout
Raises:CustomException – in case testpmd is not started in interactive mode
Returns:Output of command execution
Return type:str
start(interactive_shell=True, end_options='', timeout=10, **kwargs)[source]

Start testpmd tool.

Parameters:
  • interactive_shell (bool) – Interactive shell flag
  • end_options (str) – Arguments to be passed after ‘–’ in command line
  • timeout (int) – Timeout
  • kwargs (dict) – Arguments to be passed for testpmd tool
Raises:

AssertionError – in case unsupported arguments are passed

Returns:

None

stop(timeout=2)[source]

Stop testpmd tool.

Parameters:timeout (int) – Timeout
Raises:CustomException – in case testpmd is not started
Returns:None
taf.testlib.linux.testpmd.reformat_dpdk_eal_options(**kwargs)[source]

Re-format DPDK EAL options from human-readable dict format to command-line parameters string.

taf.testlib.linux.tool_general

tool_general.py

General functionality for Linux tool

class taf.testlib.linux.tool_general.GenericTool(run_command, tool)[source]

Bases: object

General Linux tool functionality.

__init__(run_command, tool)[source]

Initialize GenericTool class.

Parameters:run_command (function) – function that runs the actual commands.
_stop(instance_id, timeout=None, expected_rcs=frozenset({0}))[source]

Stop the tool instance.

Parameters:
  • instance_id (int) – tool instance ID
  • timeout (int) – command runner execution timeout
  • expected_rcs (set) – command runner expected return codes
Raises:

UICmdException

cleanup()[source]

Cleanup the Iperf instance.

get_results(instance_id)[source]

Read the tool results from the file.

Parameters:instance_id (int) – instance_id
Returns:tool output
Return type:str
is_active(instance_id, timeout=None, expected_rcs=frozenset({0}))[source]

Get process info for specific tool instance.

Parameters:
  • instance_id (int) – tool instance ID
  • timeout (int) – command runner execution timeout
  • expected_rcs (set) – command runner expected return codes
Raises:

UICmdException

Returns:

tool process info

Return type:

bool

next_id()[source]

Generate an id for the next instance.

Returns:the generated id
Return type:int
start(command, prefix=None, timeout=None, tool_name=None, tool_instance_id=None, pid=None, service_name=None, **kwargs)[source]

Generate command for tool execution.

Parameters:
  • command (str) – tool command
  • prefix (str) – command prefix
  • timeout (int) – time of tool execution
Returns:

tool instance ID

Return type:

int

stop(instance_id, timeout=None, ignore_failed=False, ignore_inactive=False)[source]

Human readable params wrapper for _stop - the actual worker method.

taf.testlib.linux.utils

utils.py

exception taf.testlib.linux.utils.TimeoutExceeded[source]

Bases: Exception

class taf.testlib.linux.utils.TimerContext(func=None)[source]

Bases: object

taf.testlib.linux.utils.create_directory(path)[source]
taf.testlib.linux.utils.recursive_format(container, kwargs)[source]
taf.testlib.linux.utils.wait_for(iterator, timeout)[source]

taf.testlib.linux.iperf.iperf

iperf.py

Run iperf on the remote host and parse output

class taf.testlib.linux.iperf.iperf.IPerfParser(*args, **kwargs)[source]

Bases: utils.iperflexer.sumparser.SumParser

Class for parsing Iperf output.

__init__(*args, **kwargs)[source]

Initialize IPerfParser class.

parse(output)[source]

Parse output from iperf execution.

Parameters:output (str) – iperf output
Returns:list of parsed iperf results
Return type:list
class taf.testlib.linux.iperf.iperf.Iperf(run_command)[source]

Bases: testlib.linux.tool_general.GenericTool

Class for Iperf functionality.

__init__(run_command)[source]

Initialize Iperf class.

Parameters:run_command (function) – function that runs the actual commands
parse(output, parser=None, threads=1, units='m')[source]

Parse the Iperf output.

Parameters:
  • output (str) – Iperf origin output
  • parser (IPerfParser) – parser object
  • threads (int) – num iperf threads
  • units (str) – iperf units
Returns:

list of parsed iperf results

Return type:

list

start(prefix=None, options=None, command=None, **kwargs)[source]

Generate Iperf command, launch iperf and store results in the file.

Parameters:
  • prefix (str) – command prefix
  • options (list of str) – intermediate iperf options list
  • command (Command) – intermediate iperf command object
Returns:

iperf instance process info

Return type:

dict

class taf.testlib.linux.iperf.iperf.Line(interval, transfer, t_units, bandwidth, b_units)

Bases: tuple

__getnewargs__()

Return self as a plain tuple. Used by copy and pickle.

static __new__(_cls, interval, transfer, t_units, bandwidth, b_units)

Create new instance of Line(interval, transfer, t_units, bandwidth, b_units)

__repr__()

Return a nicely formatted representation string

_asdict()

Return a new OrderedDict which maps field names to their values.

classmethod _make(iterable, new=<built-in method __new__ of type object>, len=<built-in function len>)

Make a new Line object from a sequence or iterable

_replace(**kwds)

Return a new Line object replacing specified fields with new values

b_units

Alias for field number 4

bandwidth

Alias for field number 3

interval

Alias for field number 0

t_units

Alias for field number 2

transfer

Alias for field number 1

taf.testlib.linux.iperf.iperf_cmd

iperf_cmd.py

iperf command parsing and building support

class taf.testlib.linux.iperf.iperf_cmd.CmdIperf(*args, **kwargs)[source]

Bases: testlib.linux.commands.cmd_helper.Command

CMD_HELPER = <taf.testlib.linux.iperf.iperf_cmd.CmdIperfHelper object>
class taf.testlib.linux.iperf.iperf_cmd.CmdIperfHelper(prog=None, arg_parser=None, conflict_handler=None, params=None, arg_builder=None, default_list=None)[source]

Bases: testlib.linux.commands.cmd_helper.CommandHelper

classmethod check_args(**kwargs)[source]

Input command arguments checking API

class taf.testlib.linux.iperf.iperf_cmd.IperfArgumentBuilder[source]

Bases: testlib.linux.commands.cmd_helper.ArgumentBuilder

ARGS_ORDERED = ['server', 'client', 'daemon', 'single_udp', 'bandwidth', 'dualtest', 'fileinput', 'linux-congestion', 'listenport', 'num', 'parallel', 'stdin', 'time', 'tradeoff', 'ttl', 'IPv6Version', 'bind', 'compatibility', 'format', 'help', 'interval', 'len', 'mss', 'nodelay', 'output', 'port', 'print_mss', 'reportexclude', 'reportstyle', 'udp', 'version', 'window']
classmethod get_formatter()[source]
taf.testlib.linux.iperf.iperf_cmd.chain_it()

chain.from_iterable(iterable) –> chain object

Alternate chain() constructor taking a single iterable argument that evaluates lazily.

taf.testlib.linux.iperf.iperf_tool