2.5. autogen

2.5.1. Regenerator suite

Module defining utilities for test directory regeneration.

TODO: How can we check each suite id is unique,

when currently the suite generation is run on each directory separately?

class resources.libraries.python.autogen.Regenerator.Regenerator(quiet=True)

Bases: object

Class containing file generating methods.

regenerate_glob(pattern, protocol='ip4')

Regenerate files matching glob pattern based on arguments.

In the current working directory, find all files matching the glob pattern. Use testcase template to regenerate test cases according to suffix, governed by protocol, autonumbering them. Also generate suites for other NICs and drivers.

Log-like prints are emitted to sys.stderr.

Parameters
  • pattern (str) – Glob pattern to select files. Example: *-ndrpdr.robot

  • protocol (str) – String determining minimal frame size. Default: “ip4”

Raises

RuntimeError – If invalid source suite is encountered.

resources.libraries.python.autogen.Regenerator.add_default_testcases(testcase, iface, suite_id, file_out, tc_kwargs_list)

Add default testcases to file.

Parameters
  • testcase (Testcase) – Testcase class.

  • iface (str) – Interface.

  • suite_id (str) – Suite ID.

  • file_out (file) – File to write testcases to.

  • tc_kwargs_list (dict) – Key-value pairs used to construct testcases.

resources.libraries.python.autogen.Regenerator.add_iperf3_testcases(testcase, file_out, tc_kwargs_list)

Add iperf3 testcases to file.

Parameters
  • testcase (Testcase) – Testcase class.

  • file_out (file) – File to write testcases to.

  • tc_kwargs_list (dict) – Key-value pairs used to construct testcases.

resources.libraries.python.autogen.Regenerator.add_tcp_testcases(testcase, file_out, tc_kwargs_list)

Add TCP testcases to file.

Parameters
  • testcase (Testcase) – Testcase class.

  • file_out (file) – File to write testcases to.

  • tc_kwargs_list (dict) – Key-value pairs used to construct testcases.

resources.libraries.python.autogen.Regenerator.add_trex_testcases(testcase, suite_id, file_out, tc_kwargs_list)

Add trex testcases to file.

Parameters
  • testcase (Testcase) – Testcase class.

  • suite_id (str) – Suite ID.

  • file_out (file) – File to write testcases to.

  • tc_kwargs_list (dict) – Key-value pairs used to construct testcases.

resources.libraries.python.autogen.Regenerator.check_suite_tag(suite_tag, prolog)

Verify suite tag occurres once in prolog.

Call this after all edits are done, to confirm the (edited) suite tag still matches the (edited) suite name.

Currently, the edited suite tag is expect to be identical to the primary suite tag, but having a function is more flexible.

The occurences are counted including “| ” prefix, to lower the chance to match a comment.

Parameters
  • suite_tag (str) – Part of suite name, between NIC driver and suite type.

  • prolog (str) – The part of .robot file content without test cases.

Raises

ValueError – If suite_tag not found exactly once.

resources.libraries.python.autogen.Regenerator.filter_and_edit_kwargs_for_astf(suite_id, kwargs)

Return possibly edited kwargs, or None if to be skipped.

This is a code block used in few places. Kwargs is (a copy of) one item from tc_kwargs_list. Currently, the editable field is frame_size, to be increased to for tests with data (not just CPS).

Parameters
  • suite_id (str) – Suite ID.

  • kwargs – Key-value pairs used to construct one testcase.

Returns

Edited kwargs.

:rtype Optional[dict]

resources.libraries.python.autogen.Regenerator.get_iface_and_suite_ids(filename)

Get NIC code, suite ID and suite tag.

NIC code is the part of suite name which should be replaced for other NIC. Suite ID is the part os suite name which is appended to test case names. Suite tag is suite ID without both test type and NIC driver parts.

Parameters

filename (str) – Suite file.

Returns

NIC code, suite ID, suite tag.

Return type

3-tuple of str

resources.libraries.python.autogen.Regenerator.replace_defensively(whole, to_replace, replace_with, how_many, msg, in_filename)

Replace substrings while checking the number of occurrences.

Return edited copy of the text. Assuming “whole” is really a string, or something else with .replace not affecting it.

Parameters
  • whole (str) – The text to perform replacements on.

  • to_replace (str) – Substring occurrences of which to replace.

  • replace_with (str) – Substring to replace occurrences with.

  • how_many (int) – Number of occurrences to expect.

  • msg (str) – Error message to raise.

  • in_filename (str) – File name in which the error occurred.

Returns

The whole text after replacements are done.

Return type

str

Raises

ValueError – If number of occurrences does not match.

resources.libraries.python.autogen.Regenerator.write_default_files(in_filename, in_prolog, kwargs_list)

Using given filename and prolog, write all generated suites.

Parameters
  • in_filename (str) – Template filename to derive real filenames from.

  • in_prolog (str) – Template content to derive real content from.

  • kwargs_list (list of dict) – List of kwargs for add_default_testcase.

resources.libraries.python.autogen.Regenerator.write_device_files(in_filename, in_prolog, kwargs_list)

Using given filename and prolog, write all generated suites.

Parameters
  • in_filename (str) – Template filename to derive real filenames from.

  • in_prolog (str) – Template content to derive real content from.

  • kwargs_list (list of dict) – List of kwargs for add_default_testcase.

resources.libraries.python.autogen.Regenerator.write_iperf3_files(in_filename, in_prolog, kwargs_list)

Using given filename and prolog, write all generated iperf3 suites.

Parameters
  • in_filename (str) – Template filename to derive real filenames from.

  • in_prolog (str) – Template content to derive real content from.

  • kwargs_list (list of dict) – List of kwargs for add_default_testcase.

resources.libraries.python.autogen.Regenerator.write_reconf_files(in_filename, in_prolog, kwargs_list)

Using given filename and prolog, write all generated reconf suites.

Use this for suite type reconf, as its local template is incompatible with mrr/ndrpdr/soak local template, while test cases are compatible.

Parameters
  • in_filename (str) – Template filename to derive real filenames from.

  • in_prolog (str) – Template content to derive real content from.

  • kwargs_list (list of dict) – List of kwargs for add_testcase.

resources.libraries.python.autogen.Regenerator.write_tcp_files(in_filename, in_prolog, kwargs_list)

Using given filename and prolog, write all generated tcp suites.

Parameters
  • in_filename (str) – Template filename to derive real filenames from.

  • in_prolog (str) – Template content to derive real content from.

  • kwargs_list (list of dict) – List of kwargs for add_default_testcase.

resources.libraries.python.autogen.Regenerator.write_trex_files(in_filename, in_prolog, kwargs_list)

Using given filename and prolog, write all generated trex suites.

Parameters
  • in_filename (str) – Template filename to derive real filenames from.

  • in_prolog (str) – Template content to derive real content from.

  • kwargs_list (list of dict) – List of kwargs for add_trex_testcase.

2.5.2. Testcase suite

Module defining utilities for testcase autogeneration.

class resources.libraries.python.autogen.Testcase.Testcase(template_string)

Bases: object

Class containing a template string and a substitution method.

classmethod default(suite_id)

Factory method for creating “default” testcase objects.

Testcase name will contain both frame size and core count. Used for most performance tests, except TCP ones.

Parameters

suite_id (str) – Part of suite name to distinguish from other suites.

Returns

Instance for generating testcase text of this type.

Return type

Testcase

generate(frame_size, phy_cores=None)

Return string of test case code with placeholders filled.

Fail if there are placeholders left unfilled. It is not required for all placeholders to be present in template.

Parameters
  • frame_size (str or int) – Imix string or numeric frame size. Example: 74.

  • phy_cores (int, str or None) – Number of physical cores to use. Example: 2. It can be None in n2n testcases.

Returns

Filled template, usable as test case code.

Return type

str

classmethod iperf3(suite_id)

Factory method for creating “iperf3” testcase objects.

Testcase name will contain core count, but not frame size.

Parameters

suite_id (str) – Part of suite name to distinguish from other suites.

Returns

Instance for generating testcase text of this type.

Return type

Testcase

classmethod tcp(suite_id)

Factory method for creating “tcp” testcase objects.

Testcase name will contain core count, but not frame size.

Parameters

suite_id (str) – Part of suite name to distinguish from other suites.

Returns

Instance for generating testcase text of this type.

Return type

Testcase

classmethod trex(suite_id)

Factory method for creating “trex” testcase objects.

Testcase name will contain frame size, but not core count.

Parameters

suite_id (str) – Part of suite name to distinguish from other suites.

Returns

Instance for generating testcase text of this type.

Return type

Testcase

2.5.3. add_suite_tag suite

Script for mass editing suites to add suite tag there.

resources.libraries.python.autogen.add_suite_tag.edit(text, suite_tag)

Return the edited text.

Parameters
  • text (str) – Content of .robot file as read.

  • suite_tag (str) – The value of suite tag to insert if not present.

Returns

New content to rewrite the file with.

Return type

str

Raises

RuntimeError – If something failed during the editing.

resources.libraries.python.autogen.add_suite_tag.main()

Do it all, return return code.

Returns

0 as everything works.

Return type

int