Skip to content

Commit

Permalink
Merge pull request #2221 from sarthurdev/configtest_extend
Browse files Browse the repository at this point in the history
smoketest: T5558: Extend configtest to allow checking of migration script results
  • Loading branch information
c-po authored Sep 8, 2023
2 parents fd5517b + 56a6e53 commit c57a519
Show file tree
Hide file tree
Showing 5 changed files with 409 additions and 2 deletions.
4 changes: 4 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ override_dh_auto_install:
mkdir -p $(DIR)/$(VYOS_LIBEXEC_DIR)/tests/config/
cp -r smoketest/configs/* $(DIR)/$(VYOS_LIBEXEC_DIR)/tests/config

# Install smoke test config tests
mkdir -p $(DIR)/$(VYOS_LIBEXEC_DIR)/tests/config-tests/
cp -r smoketest/config-tests/* $(DIR)/$(VYOS_LIBEXEC_DIR)/tests/config-tests

# Install system programs
mkdir -p $(DIR)/$(VYOS_BIN_DIR)
cp -r smoketest/bin/* $(DIR)/$(VYOS_BIN_DIR)
Expand Down
1 change: 1 addition & 0 deletions debian/vyos-1x-smoketest.install
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ usr/bin/vyos-configtest
usr/bin/vyos-configtest-pki
usr/libexec/vyos/tests/smoke
usr/libexec/vyos/tests/config
usr/libexec/vyos/tests/config-tests
23 changes: 21 additions & 2 deletions smoketest/bin/vyos-configtest
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ from vyos.configsession import ConfigSession, ConfigSessionError
from vyos import ConfigError

config_dir = '/usr/libexec/vyos/tests/config'
config_test_dir = '/usr/libexec/vyos/tests/config-tests'
save_config = '/tmp/vyos-configtest-save'

class DynamicClassBase(unittest.TestCase):
Expand All @@ -42,7 +43,7 @@ class DynamicClassBase(unittest.TestCase):
except OSError:
pass

def make_test_function(filename):
def make_test_function(filename, test_path=None):
def test_config_load(self):
config_path = os.path.join(config_dir, filename)
self.session.migrate_and_load_config(config_path)
Expand All @@ -51,6 +52,16 @@ def make_test_function(filename):
except (ConfigError, ConfigSessionError):
self.session.discard()
self.fail()

if test_path:
config_commands = self.session.show(['configuration', 'commands'])

with open(test_path, 'r') as f:
for line in f.readlines():
if not line or line.startswith("#"):
continue

self.assertIn(line, config_commands)
return test_config_load

def class_name_from_func_name(s):
Expand All @@ -69,10 +80,18 @@ if __name__ == '__main__':
config_list.sort()

for config in config_list:
test_func = make_test_function(config)
test_path = os.path.join(config_test_dir, config)

if not os.path.exists(test_path):
test_path = None
else:
log.info(f'Loaded migration result test for config "{config}"')

test_func = make_test_function(config, test_path)

func_name = config.replace('-', '_')
klassname = f'TestConfig{class_name_from_func_name(func_name)}'

globals()[klassname] = type(klassname,
(DynamicClassBase,),
{f'test_{func_name}': test_func})
Expand Down
62 changes: 62 additions & 0 deletions smoketest/config-tests/basic-vyos
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
set interfaces ethernet eth0 address '192.168.0.1/24'
set interfaces ethernet eth0 duplex 'auto'
set interfaces ethernet eth0 speed 'auto'
set interfaces ethernet eth1 duplex 'auto'
set interfaces ethernet eth1 speed 'auto'
set interfaces ethernet eth2 duplex 'auto'
set interfaces ethernet eth2 speed 'auto'
set interfaces ethernet eth2 vif 100 address '100.100.0.1/24'
set interfaces ethernet eth2 vif-s 200 address '100.64.200.254/24'
set interfaces ethernet eth2 vif-s 200 vif-c 201 address '100.64.201.254/24'
set interfaces ethernet eth2 vif-s 200 vif-c 202 address '100.64.202.254/24'
set interfaces loopback lo
set protocols static arp interface eth0 address 192.168.0.20 mac '00:50:00:00:00:20'
set protocols static arp interface eth0 address 192.168.0.30 mac '00:50:00:00:00:30'
set protocols static arp interface eth0 address 192.168.0.40 mac '00:50:00:00:00:40'
set protocols static arp interface eth2.100 address 100.100.0.2 mac '00:50:00:00:02:02'
set protocols static arp interface eth2.100 address 100.100.0.3 mac '00:50:00:00:02:03'
set protocols static arp interface eth2.100 address 100.100.0.4 mac '00:50:00:00:02:04'
set protocols static arp interface eth2.200 address 100.64.200.1 mac '00:50:00:00:00:01'
set protocols static arp interface eth2.200 address 100.64.200.2 mac '00:50:00:00:00:02'
set protocols static arp interface eth2.200.201 address 100.64.201.10 mac '00:50:00:00:00:10'
set protocols static arp interface eth2.200.201 address 100.64.201.20 mac '00:50:00:00:00:20'
set protocols static arp interface eth2.200.202 address 100.64.202.30 mac '00:50:00:00:00:30'
set protocols static arp interface eth2.200.202 address 100.64.202.40 mac '00:50:00:00:00:40'
set protocols static route 0.0.0.0/0 next-hop 100.64.0.1
set service dhcp-server shared-network-name LAN authoritative
set service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 default-router '192.168.0.1'
set service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 domain-name 'vyos.net'
set service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 domain-search 'vyos.net'
set service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 name-server '192.168.0.1'
set service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 range LANDynamic start '192.168.0.20'
set service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 range LANDynamic stop '192.168.0.240'
set service dns forwarding allow-from '192.168.0.0/16'
set service dns forwarding cache-size '10000'
set service dns forwarding dnssec 'off'
set service dns forwarding listen-address '192.168.0.1'
set service ssh ciphers 'aes128-ctr'
set service ssh ciphers 'aes192-ctr'
set service ssh ciphers 'aes256-ctr'
set service ssh ciphers '[email protected]'
set service ssh ciphers '[email protected]'
set service ssh key-exchange '[email protected]'
set service ssh key-exchange 'diffie-hellman-group1-sha1'
set service ssh key-exchange 'diffie-hellman-group-exchange-sha1'
set service ssh key-exchange 'diffie-hellman-group-exchange-sha256'
set service ssh listen-address '192.168.0.1'
set service ssh port '22'
set system config-management commit-revisions '100'
set system console device ttyS0 speed '115200'
set system host-name 'vyos'
set system name-server '192.168.0.1'
set system syslog console facility all level 'emerg'
set system syslog console facility mail level 'info'
set system syslog global facility all level 'info'
set system syslog global facility auth level 'info'
set system syslog global facility local7 level 'debug'
set system syslog global preserve-fqdn
set system syslog host syslog.vyos.net facility auth level 'warning'
set system syslog host syslog.vyos.net facility local7 level 'notice'
set system syslog host syslog.vyos.net format octet-counted
set system syslog host syslog.vyos.net port '8000'
set system time-zone 'Europe/Berlin'
Loading

0 comments on commit c57a519

Please sign in to comment.