-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add integration tests for veths
- Loading branch information
1 parent
ec9425d
commit b2d5483
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/usr/bin/python3 | ||
# Veths integration tests. | ||
# | ||
# These need to be run in a VM and do change the system | ||
# configuration. | ||
# | ||
# Copyright (C) 2023 Canonical, Ltd. | ||
# Author: Danilo Egea Gondolfo <[email protected]> | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; version 3. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import sys | ||
import subprocess | ||
import unittest | ||
|
||
from base import IntegrationTestsBase, test_backends | ||
|
||
|
||
class _CommonTests(): | ||
|
||
def test_create_veth_pair(self): | ||
self.addCleanup(subprocess.call, ['ip', 'link', 'delete', 'veth0'], stderr=subprocess.DEVNULL) | ||
with open(self.config, 'w') as f: | ||
f.write('''network: | ||
renderer: %(r)s | ||
version: 2 | ||
veths: | ||
veth0: | ||
dhcp4: false | ||
dhcp6: false | ||
peer: veth1 | ||
veth1: | ||
dhcp4: false | ||
dhcp6: false | ||
peer: veth0''' % {'r': self.backend}) | ||
self.generate_and_settle(['veth0', 'veth1']) | ||
self.assert_iface_up('veth0') | ||
self.assert_iface_up('veth1') | ||
|
||
def test_create_veth_pair_with_ip_address(self): | ||
self.addCleanup(subprocess.call, ['ip', 'link', 'delete', 'veth0'], stderr=subprocess.DEVNULL) | ||
with open(self.config, 'w') as f: | ||
f.write('''network: | ||
renderer: %(r)s | ||
version: 2 | ||
veths: | ||
veth0: | ||
dhcp4: false | ||
dhcp6: false | ||
peer: veth1 | ||
addresses: | ||
- 192.168.123.123/24 | ||
- 1234:FFFF::42/64 | ||
veth1: | ||
dhcp4: false | ||
dhcp6: false | ||
peer: veth0''' % {'r': self.backend}) | ||
self.generate_and_settle(['veth0', 'veth1']) | ||
self.assert_iface_up('veth0', ['inet 192.168.123.123/24', 'inet6 1234:ffff::42/64']) | ||
self.assert_iface_up('veth1') | ||
|
||
|
||
@unittest.skipIf("networkd" not in test_backends, | ||
"skipping as networkd backend tests are disabled") | ||
class TestNetworkd(IntegrationTestsBase, _CommonTests): | ||
backend = 'networkd' | ||
|
||
|
||
@unittest.skipIf("NetworkManager" not in test_backends, | ||
"skipping as NetworkManager backend tests are disabled") | ||
class TestNetworkManager(IntegrationTestsBase, _CommonTests): | ||
backend = 'NetworkManager' | ||
|
||
|
||
unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2)) |