Commit Graph

18 Commits

Author SHA1 Message Date
Alexander V. Chernikov
90bc2120b5 tests: fix python parsing of netlink nested attributes
MFC after:	2 weeks
2023-03-13 10:17:36 +00:00
Alexander V. Chernikov
c57dfd92c8 tests: add more netlink tests for neighbors/routes
Differential Revision: https://reviews.freebsd.org/D38912
MFC after:	2 weeks
2023-03-07 17:31:26 +00:00
Alexander V. Chernikov
828d3c6c4c tests: add netlink large dump buffer check
Differential Revision: https://reviews.freebsd.org/D38665
MFC after:	2 weeks
2023-02-20 10:20:54 +00:00
Alexander V. Chernikov
ff8da9b2ba netlink: improve attribute decoding in python tests
MFC after:	2 weeks
2023-02-17 18:16:08 +00:00
Alexander V. Chernikov
25c2dd2f2c netlink: return optional metadata with the operation result.
Some operations like interface creation may need to return metadata
 - in this case, interface name - back to the caller if the operation
 is successful.
This change implements attaching an `NLMSGERR_ATTR_COOKIE` nla to the
operation reply message via `nlmsg_report_cookie()`.
Additionally, on successful interface creation, interface index and
 interface name are returned in the `IFLA_NEW_IFINDEX` and `IFLA_IFNAME
 TLVs, encapsulated in the `NLMSGERR_ATTR_COOKIE`.

Reviewed By: pauamma
Differential Revision: https://reviews.freebsd.org/D38283
MFC after:	1 week
2023-02-09 15:30:00 +00:00
Alexander V. Chernikov
6332ef8941 testing: handling non-root users with VNETs in pytest-based tests.
Currently isolation and resource requirements are handled directly
 by the kyua runner, based on the requirements specified by the test.
It works well for simple tests, but may cause discrepancy with tests
 doing complex pre-setups. For example, all tests that perform
 VNET setups require root access to properly function.

This change adds additional handling of the "require_user" property
 within the python testing framework. Specifically, it requests
 root access if the test class signals its root requirements and
 drops privileges to the desired user after performing the pre-setup.

Differential Revision: https://reviews.freebsd.org/D37923
MFC after:	2 weeks
2023-02-09 14:49:27 +00:00
Alexander V. Chernikov
20ea7f26e4 pytest: delete interfaces from inside the jail.
This change follows the approach used in 80fc25025f, to
 minimise the impact of the delayed interface migration.

MFC after:	2 weeks
2023-01-25 16:34:17 +00:00
Jose Luis Duran
4856aeaaed tests: Add an IPv4 loopback address of 127.0.0.1/8 to the lo0
interface by default when creating VNETSs using pytest.

Reviewed By: asomers
Differential Revision: https://reviews.freebsd.org/D38021
2023-01-11 14:34:41 +00:00
Alexander V. Chernikov
c1871a3372 netlink: improve RTM_GETADDR handling.
* Allow filtering by ifa_family & ifa_index.
* Add common RTM_<NEW|DEL|GET>ADDR parser
* Add tests verifying RTM_GETADDR filtering behaviour & output
* Factor out common netlink socket test methods into NetlinkTestTemplate
* Add NLMSG_DONE message handler

Reviewed By: pauamma
Differential Revision: https://reviews.freebsd.org/D37970
2023-01-08 15:06:34 +00:00
Alexander V. Chernikov
bb60d265c9 testing: fix tests without cleanup in pytest.
It was broken by 89ffac3b01,
which added "cleanup" method to the base test class,
 resulting in reporting cleanup for all of the tests.
2023-01-01 14:11:18 +00:00
Alexander V. Chernikov
89ffac3b01 testing: allow custom test cleanup handlers in pytest
In order to provide more flexibility for the test writers,
add per-test-method cleanups in addition to the per-class cleanups.

Now the test 'test_one' can perform cleanup by either defining
per-class 'cleanup' method (typically used in VNET classes) and
per-test method 'cleanup_test_one'. The latter has preference.
In order to handle paramatrization, testid is passed as a single
 argument to both of the methods.

MFC after:	2 weeks
2022-12-31 16:27:27 +00:00
Alexander V. Chernikov
f63825ff21 testing: improve python vnet wrapper.
* Derive jail name from class name and method name, instead of just
method name. This change reduces the chances of different tests
clashing.
 Old: 'jail_test_one'. New: 'pytest:TestExampleSimplest:test_one'
* Simplify vnetX_handler() method signature by skipping obj_map (unused)
 and pipe. The latter can be accessed as the vnet property.
* Add `send_object()` method as a pair to the `wait_object` inside the
 VnetTestTemplate class.
* Add `test_id` property to the BaseTest method. Previously it was
 provided only for the VnetTestTemplate class. This change makes
 the identifier easily accessible for all users.

MFC after:	2 weeks
2022-12-29 19:59:11 +00:00
Alexander V. Chernikov
3873bdc2f2 netlink: connect netlink tests to the build
Reviewed By: ngie
Differential Revision: https://reviews.freebsd.org/D37708
2022-12-16 12:02:50 +00:00
Alexander V. Chernikov
80f03e63d6 netlink: improve interface handling
* Separate interface creation from interface modification code
* Support setting some interface attributes (ifdescr, mtu, up/down, promisc)
* Improve interaction with the cloners requiring to parse/write custom
 interface attributes
* Add bitmask-based way of checking if the attribute is present in the
message
* Don't use multipart RTM_GETLINK replies when searching for the
specific interface names
* Use ENODEV instead of ENOENT in case of failed RTM_GETLINK search
* Add python netlink test helpers
* Add some netlink interface tests

Differential Revision: https://reviews.freebsd.org/D37668
2022-12-14 19:52:35 +00:00
Alexander V. Chernikov
7064c94a02 tests: add routing tests for switching between same prefixes
Differential Revision: https://reviews.freebsd.org/D36055
MFC after:	2 weeks
2022-08-07 19:45:25 +00:00
Alexander V. Chernikov
cfc9cf9baf testing: add ability to specify multi-vnet topologies in the pytest framework.
Notable amount of tests related to the packet IO require two VNET jails
 for proper testing and avoiding side effects for the host system.
Additionally, it is often required to run actions in the jails seme-sequentially
- waiting for the listener initialisation can be an example of such
  dependency.

This change extends pytest vnet framework to allow defining multi-vnet
 multi-epair topologies in declarative style, without any need to bother
 about jail or repair names. All jail creation/teardown, interface
 creation/teardown and address assignments are handled automatically.

Example:

TOPOLOGY = {
  "vnet1": {"ifaces": ["if1", "if2", "if3"]},
  "vnet2": {"ifaces": ["if1", "if2", "if3"]},
  "if1": {"prefixes6": [("2001:db8:a::1/64", "2001:db8:a::2/64")]},
  "if2": {"prefixes6": [("2001:db8:b::1/64", "2001:db8:b::2/64")]},
  "if3": {"prefixes6": [("2001:db8:c::1/64", "2001:db8:c::2/64")]},
}
def vnet2_handler(self, vnet, obj_map, pipe):
  ss = VerboseSocketServer("::", self.DEFAULT_PORT)
  pipe.send("READY")

def test_output6_base(self):
  self.wait_object(second_vnet.pipe)

The definitions above will create 2 vnets ("jail_test_output6_base",
 "jail_test_output6_base_2"), 3 epairs, attached to both first and
 second jails, set up the IP addresses for each epair, spawn another
 process for vnet2_handler and pass control to vnet2_handler and
 test_output6_base. Both processes can pass objects between each
 other using pre-created pipes.

Differential Revision: https://reviews.freebsd.org/D35708
2022-07-07 10:05:06 +00:00
Alexander V. Chernikov
513ce835b5 testing: pass ATF vars to pytest via env instead of arguments.
This change is a continuation of 9c42645a1e workaround.
Apparently pytest argument parser is not happy when parsing values
 with spaces or just more than one --atf-var argument.
Switch wrapper to send these kv pairs as env variables. Specifically,
 use _ATF_VAR_key=value format to distinguish from the other vars.

Add the `atf_vars` fixture returning all passed kv pairs as a dict.

Reviewed by:	lwhsu
Differential Revision: https://reviews.freebsd.org/D35625
MFC after:	2 weeks
2022-06-28 12:20:16 +00:00
Alexander V. Chernikov
8eb2bee6c0 testing: Add basic atf support to pytest.
Implementation consists of the pytest plugin implementing ATF format and
a simple C++ wrapper, which reorders the provided arguments from ATF format
to the format understandable by pytest. Each test has this wrapper specified
after the shebang. When kyua executes the test, wrapper calls pytest, which
loads atf plugin, does the work and returns the result. Additionally, a
separate python "package", `/usr/tests/atf_python` has been added to collect
code that may be useful across different tests.

Current limitations:
* Opaque metadata passing via X-Name properties. Require some fixtures to write
* `-s srcdir` parameter passed by the runner is ignored.
* No `atf-c-api(3)` or similar - relying on pytest framework & existing python libraries
* No support for `atf_tc_<get|has>_config_var()` & `atf_tc_set_md_var()`.
 Can be probably implemented with env variables & autoload fixtures

Differential Revision: https://reviews.freebsd.org/D31084
Reviewed by:	kp, ngie
2022-06-25 19:25:15 +00:00