46 Commits

Author SHA1 Message Date
Íñigo Huguet
a150aab817 test: don't fail if NetworkManager-libreswan is missing
It is not possible to run integration tests if NetworkManager-libreswan
rpm is not installed. Pytest fails during the collection stage,
preventing from running even tests not related to Libreswan.

Fix it.

Signed-off-by: Íñigo Huguet <ihuguet@redhat.com>
2024-08-05 21:38:02 +08:00
Gris Ge
af93eee08c test: Fix incorrect version check on NetworkManager-libreswan
Instead of checking micro version, we should convert version to a
integer to compare using this formula:

    10000 * major_version + 100 * minor_version + micro_version

Introduced `nm_libreswan_version_int()` and `version_str_to_int()` for
this and fixed all version check in ipsec test.

Signed-off-by: Gris Ge <fge@redhat.com>
2024-06-12 10:06:07 +08:00
Gris Ge
bb9981c730 net_state: Add description to top level YAML/JSON API
Introducing `description` as top level key of YAML/JSON API holding a
String. For example:

```yml
description: Abc
```

Currently, this property will be ignored when applying or querying, no
backend will persist this property. It is designed for user to store
description for the whole YAML only for now.

By using `testlib.apply.apply_with_description()`, we could store:
`test_description: <string>` into `.descriptions`. The
`pytest ----dump-ai-train-yaml` will store the YAML file into `.states`
folder for training AI.

The `--dump-ai-train-yaml` will only store YAML files with top level
description and the output will only contains the difference between
desired state and current state.

Signed-off-by: Gris Ge <fge@redhat.com>
2024-05-31 11:26:27 +08:00
Enrique Llorente
163427cca4 integ: Dump applied and showed states
This change dumps the network configuration involved at integration test
so other projects can check their implementations with them.

Signed-off-by: Enrique Llorente <ellorent@redhat.com>
2024-04-03 20:24:42 +08:00
Gris Ge
1a80d6fee9 Revert "ci: Workaround for ip netns bug in container."
This reverts commit a2303e2ce4b852d9ffc833800fcf00fe2caaab65.

Signed-off-by: Gris Ge <fge@redhat.com>
2023-10-20 17:00:05 +08:00
Gris Ge
261adfd722 test: Move eth1 and eth2 setup to pytest fixture
Previously we were using run-tests.sh to setup the eth1 and eth2,
after moving this into pytest fixture, the `pytest` could works out of
box.

Signed-off-by: Gris Ge <fge@redhat.com>
2023-09-30 01:09:51 +08:00
Gris Ge
4f737f3d8d test: Only restore interface with gateway
When testing with SR-IOV cards, it is time consuming to restored the
full old state and also might lead to ethtool failures.

Hence change the `conftest.py` to only restored the IP address, IP route
and DNS config for interface with IPv4 or IPv6 gateway.

Signed-off-by: Gris Ge <fge@redhat.com>
2022-09-30 10:44:03 +02:00
Gris Ge
4fd76316b8 test: Remove the network diff after test finished
The network diff after test finished does not actually helps, but add
scroll back time.

Signed-off-by: Gris Ge <fge@redhat.com>
2022-08-26 12:19:08 +02:00
Gris Ge
a2303e2ce4 ci: Workaround for ip netns bug in container.
Due to `ip netns` issue in https://github.com/containers/podman/issues/11887 ,
`ip netns exec` will fail in podman container.

To workaround it, mount another sysfs to random folder workaround this
problem.

Signed-off-by: Gris Ge <fge@redhat.com>
2022-08-26 12:19:08 +02:00
Gris Ge
a14bdcca61 test: Ignore failure when removing routes/rules/dns
In Github CI, the container environment is changed to use tap interface
to hold the default gateway. Nmstate does not support tap interface
which cause failure during verification on pre-test clean up.

Workaround it by ignoring failure on removing routes/rules/dns during
the pre-test setup.

Signed-off-by: Gris Ge <fge@redhat.com>
2022-08-26 12:19:08 +02:00
Quique Llorente
44b17591e1 test,k8s: Ignore calico interfaces
The integration tests should ignore interfaces related to the CNI used
by the k8s cluster calico. This change introduces an env var to pass
inteface substring to ignore.

Signed-off-by: Quique Llorente <ellorent@redhat.com>
2022-03-02 15:26:15 +01:00
Gris Ge
e87349169d bridge/bond: User permanent MAC address for Interface.COPY_MAC_FROM
Use permanent MAC address when possible for `Interface.COPY_MAC_FROM`.

Integration test case added by require real NIC to test using. Example:

    sudo env TEST_REAL_NIC="enp7s0" pytest -k \
        test_create_linux_bridge_with_copy_mac_from_permanent_mac

Tested on e100e in RHEL 8.4 VM.

Signed-off-by: Gris Ge <fge@redhat.com>
2021-06-07 11:51:06 +02:00
Gris Ge
411cd6a5ab test: Only remove route/dns/route_rule before test
Since nmstate support changing DNS/route/route_rule without interface
defined, there is no need to include full state of all interface to
clean up the test environment.

Updated the integration test case because container will have eth1
unmanaged by NetworkManager which will still hold route and DNS config.

Signed-off-by: Gris Ge <fge@redhat.com>
2021-06-07 10:02:54 +02:00
Gris Ge
3e5aa19f55 pytest: Fix warning of unregistered marker
In Fedora 34, the pytest(6.2.2) will complain about
`PytestUnknownMarkWarning`.

Fixed the manual marker register code.

Signed-off-by: Gris Ge <fge@redhat.com>
2021-05-19 09:36:37 +02:00
Quique Llorente
608840e140 ci, k8s: Skip tests and teardowns that fail on k8s
Signed-off-by: Quique Llorente <ellorent@redhat.com>
2021-05-07 15:46:51 +08:00
Gris Ge
7839647a11 test: Register pytest marker
The pytest-4.6.9 will complain unregister markers:

  /usr/lib/python3.7/site-packages/_pytest/mark/structures.py:335:
  PytestUnknownMarkWarning: Unknown pytest.mark.tier1 - is this a typo?
  You can register custom marks to avoid this warning - for details, see
  https://docs.pytest.org/en/latest/mark.html

To suppress that warning message, use `pytest_configure()` to register
the markers.

Signed-off-by: Gris Ge <fge@redhat.com>
2020-06-23 12:44:05 +08:00
Fernando Fernandez Mancera
74cbd30e86 test, integ: clean auto_routes and auto_dns in the needed tests
In some platforms it is not possible to lose the connectivity during a
long time. In order to fix this, we are only cleaning auto_dns and
auto_routes in the tests when necessary.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2020-06-02 16:13:07 +03:00
Fernando Fernandez Mancera
37bc3c7ae6 test, integ: clean auto_dns and auto_routes before tests
In order to run the tests out of the containers when cleaning the state
nmstate needs to make sure that all the interfaces are using static DNS
and routes.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2020-03-31 17:53:06 +08:00
Fernando Fernandez Mancera
3cfcd1ce40 tests, integ: introduce integ_tier1 and integ_tier2 integration tests
This patch is introducing integ_tier1 and integ_tier2 tests and using it
in travis CI.  This will allow us to run integration test quickly as
both jobs, integ_tier1 and integ_tier2 are going to run at the same
time.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2020-03-19 17:19:08 +08:00
Gris Ge
fb102eac21 test: Create a empty network state before test starts
Some test case like DNS/DHCP/Route tests might got impacted by host's
original network state(for example, the initial removal of eth1/eth2
configure will fail when host is configured as static DNS with dynamic
IP as libnmstate.apply() will try to preserve the DNS information).

To fix that, create a empty network state before test starts using
session level autouse fixture `test_env_setup` to:
    * Setup log level
    * Remove all static route
    * Remove all DNS configuration
    * Remove all route rule configuration
    * Restore host's network states after test ended.
    * Show left over network interfaces created by test cases.

Signed-off-by: Gris Ge <fge@redhat.com>
2020-03-19 12:27:13 +08:00
Gris Ge
a1eff46cc1 Test: Include nmstate version in log
Prefer rpm version, and fallback to `libnmstate.__version__`.

Signed-off-by: Gris Ge <fge@redhat.com>
2020-02-27 22:21:13 +08:00
Fernando Fernandez Mancera
1138f9d346 tests: introduce slow integration tests
Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2020-02-17 21:10:15 +01:00
Fernando Fernandez Mancera
026ed90713 tests, integ: fix missing plugin tests
Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2020-02-12 12:07:45 +01:00
Fernando Fernandez Mancera
cfe7061ee3 integ: download plugin packages before running the tests
This patch is going to avoid connectivity issues during the package
installation when running tests.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2020-01-31 16:57:22 +01:00
Fernando Fernandez Mancera
8585d91ebf nm.team: Team interface basic implementation
This is a team interface state example:

interfaces:
- name: team0
  type: team
  state: up
  ipv4:
    enabled: false
  ipv6:
    enabled: false
  mtu: 1500
  team:
    ports:
    - name: eth1
    - name: eth2
    runner:
      mode: loadbalance

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2020-01-30 13:25:24 +02:00
Till Maas
ca3450dc93 Black: Enable string normalization
Signed-off-by: Till Maas <opensource@till.name>
2019-12-12 15:42:32 +01:00
Edward Haas
33c7e0fc90 python3: Remove six
Now that Nmstate is no longer supporting python2, six usage is no longer
needed and therefore removed.

Signed-off-by: Edward Haas <edwardh@redhat.com>
2019-11-26 18:00:59 +08:00
Till Maas
e287866df6 integration tests: Warn if test run changes network state
Ideally, the tests clean up after themselves. Try to catch differences
by comparing the host state from before and after the test run and warn
if there are differences.

Signed-off-by: Till Maas <opensource@till.name>
2019-11-20 22:32:22 +08:00
Till Maas
759d8a47b9 integration tests: Remove preserve_old_config fixture
The `preserve_old_config` fixture fails when Nmstate reports a
configuration that it cannot set, for example a gateway together with
DHCPv6 and autoconf. If someone needs to restore a certain network state
after running the tests, they need to use a custom wrapper/script to do
so.

References:
https://lists.fedorahosted.org/archives/list/nmstate-devel@lists.fedorahosted.org/thread/XFMPA5IMYCQCDWUSSNGVDBQA7BKB2N3N/
https://nmstate.atlassian.net/browse/NMSTATE-275

Signed-off-by: Till Maas <opensource@till.name>
2019-11-20 22:32:22 +08:00
Till Maas
06d10f853f automation: Enhance pytest header
Mention NetworkManager RPM and Operating System in pytest header.
Example:

```
================= test session starts ==================
[...]
RPMs: NetworkManager-1.20.5-1.cab2e4fc96.el8.x86_64
OS: CentOS Linux 8 (Core)
```

This makes it easier to identify the test environment from the pytest
log. For example when the tests are running on bare-metal or in a VM
instead of the container that is setup with run-tests.sh.

Signed-off-by: Till Maas <opensource@till.name>
2019-11-19 11:31:58 +01:00
Edward Haas
d866ed3b35 tests, integ: Extract iface-up fixtures out of conftest
The existing eth{1,2}_up fixtures serve the integration tests with the
majority of tests. There are however serveral tests which use unique
interfaces (e.g. dhcp tests) which need similar fixtures.

In order to share the functionality, the fixtures implementation have
been extracted to a shared location (testlib) and are aimed to be used
in the following patches by other more focused scoped fixtures.

Signed-off-by: Edward Haas <edwardh@redhat.com>
2019-08-01 12:35:47 +03:00
Edward Haas
15ac912c23 tests, integ: Remove IPv6 exception from the ethX fixtures
IPv6 has been enabled on the test setup interfaces due to the limitation
of disabling IPv6 using NM.

The mentioned limitation has been mitigated by disabling IPv6 through
sysfs. Therefore, always enabling IPv6 in the fixtures is no longer
needed.

Signed-off-by: Edward Haas <edwardh@redhat.com>
2019-08-01 12:35:47 +03:00
Gris Ge
191e6343a2 schema: Add constants for IP subtree
Three class was added:

    * schema.InterfaceIP
    * schema.InterfaceIPv4
    * schema.InterfaceIPv6

Signed-off-by: Gris Ge <fge@redhat.com>
2019-07-22 21:45:51 +03:00
Gris Ge
ab62eeadbe Relicense to LGPL2.1+
Signed-off-by: Gris Ge <fge@redhat.com>
2019-07-03 13:45:37 +08:00
Edward Haas
6eda321f54 tests integ: Alias ethX_up fixtures to portX_up
Bridge tests use `portX` as their name format, abstracting the actual
interface used.
Providing portX alias naming to such tests makes them easier to read and
write.

Signed-off-by: Edward Haas <edwardh@redhat.com>
2019-06-24 10:48:16 +03:00
Edward Haas
339fd1b754 black: Cover all tests
Signed-off-by: Edward Haas <edwardh@redhat.com>
2019-06-20 20:42:02 +03:00
Edward Haas
9bfabbaeea tests integ: eth*_up fixtures return the current state
The eth*_up fixtures are used to setup most of the integration tests.
In some scenarios, it is useful to have these interfaces states just
before the test begins.

The fixtures resturn the current interface state.

Signed-off-by: Edward Haas <edwardh@redhat.com>
2019-06-19 22:59:45 +03:00
Gris Ge
c682eac2ec dns: Support editing
Example has been included as `examples/dns_edit_eth1.yml` and
`examples/dns_remove.yml`.

If DNS section not defined in desire state, old DNS configuration will be
perceived, otherwise, old DNS configuration will be fully override with
desired state. Partial editing of DNS entries is not supported.

To remove static DNS configuration, Please use this state:

```python
{
    DNS.KEY: {
        DNS.CONFIG: {}
    }
}
```

Limitation:
 * Only support saving DNS configuration to state default gateway
   interfaces. If not found, NmstateValueError exception will be raised.
   When DNS config not changed, no DNS changes will be made to profiles.

Unit and integration test cases has been included.

Signed-off-by: Gris Ge <fge@redhat.com>
2019-06-14 00:44:12 +08:00
Gris Ge
fa12bcd9a2 API: Promote the public API to libnmstate level
Promoting these public classes and functions to libnmstate module top level:
 * The 'show()' function of 'netinfo.py'.
 * The 'apply()', 'commit', 'rollback' functions of 'netapplier.py'.
 * The exception classes defined in 'error.py' as exposed as
   'libnmstate.error'
 * The 'PrettyState' class defined in 'prettystate.py' which is used by
   nmstatectl.
 * The schema classes are exposed as 'libnmstate.schema'.

The integration test cases and nmstatctl have been updated to use this
new public interface.

Signed-off-by: Gris Ge <fge@redhat.com>
2019-06-13 21:15:12 +08:00
Edward Haas
aea3286f8d tests integ: Refactor fixture setup of ethX interfaces
The ethX fixtures prepare the base interfaces per test by initializing
their configuration (performing a down-up action).

The existing flow has been initializing the interfaces before a test is
executed with no action taken when it ends. This causes leftovers when
testing bonds/bridges with slaves/ports, affecting the following tests.

In order to resolve the post test leftovers, adjust the test fixtures
to setup the interface at the test setup and to remove them
(set them `down`) at the test teardown.
In order to treat the initial state of the tests session execution,
where the interfaces may have an unknown state/configuration, use a
session-scoped fixture to initialize them (by setting them `down`).

Signed-off-by: Edward Haas <edwardh@redhat.com>
2019-05-16 16:51:00 +03:00
Till Maas
d6f4ddc328 Various: Use nmstate/Nmstate as the uniform name
Signed-off-by: Till Maas <opensource@till.name>
2019-02-26 13:40:49 +01:00
Edward Haas
b30268994b tests integ: Trigger global fixtures explicitly by tests
The interfaces setup fixtures are now triggered explicitly by the tests
per need.

Signed-off-by: Edward Haas <edwardh@redhat.com>
2018-11-26 23:42:11 +02:00
Edward Haas
e02e9f8a62 tests integ: Split global fixture
The global fixture is used to prepare the setup interfaces (eth1, eth2)
for the tests by cleaning their configuration.

As a pre-step to prepare interfaces per need, the existing fixture is
split into 4: eth1_up, eth1_down, eth2_up, eth2_down.

The overall functionality has not changed.
The following patches will require the tests to explicitly specify
which interface they want to consume.

Signed-off-by: Edward Haas <edwardh@redhat.com>
2018-11-26 23:42:11 +02:00
Edward Haas
51b0f1b881 tests integ: Enable test ifaces before each test run
The initial state of an integration test is set to 'up'.

Existing tests are adjusted and reflect that IPv6 is now enabled.

Signed-off-by: Edward Haas <edwardh@redhat.com>
2018-11-12 12:30:29 +02:00
Edward Haas
a49f97e2f4 tests integ: Execute ifaces cleanup before each test
In order to start each test from a clean state and assure there is no
dependency between the tests, the tested interfaces (eth1, eth2) are
taken down using a dedicated fixture.

Signed-off-by: Edward Haas <edwardh@redhat.com>
2018-10-24 14:36:09 +02:00
Edward Haas
305be5d8b9 tests: Add an integ lib test for adding static IPv4
Configuring a static IPv4 address on an interface.

Signed-off-by: Edward Haas <edwardh@redhat.com>
2018-10-24 14:36:09 +02:00