summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-12-01 16:54:51 +0100
committerChristian Poessinger <christian@poessinger.com>2020-12-01 16:54:51 +0100
commite1bef612c75575e8263b0d10d1a43138dd77a0f8 (patch)
tree097387d79eb8c734749b1d2ecd85f7fc4a692d4f
parent0a7888e165396dd200bc73a060c330c04fec0920 (diff)
downloadvyos-1x-e1bef612c75575e8263b0d10d1a43138dd77a0f8.tar.gz
vyos-1x-e1bef612c75575e8263b0d10d1a43138dd77a0f8.zip
smoketest: dhcp: T3100: add testcase for static host mappings
-rw-r--r--data/templates/dhcp-server/dhcpd.conf.tmpl2
-rwxr-xr-xsmoketest/scripts/cli/test_service_dhcp-server.py55
2 files changed, 55 insertions, 2 deletions
diff --git a/data/templates/dhcp-server/dhcpd.conf.tmpl b/data/templates/dhcp-server/dhcpd.conf.tmpl
index 3e0fd8d1d..d172018bf 100644
--- a/data/templates/dhcp-server/dhcpd.conf.tmpl
+++ b/data/templates/dhcp-server/dhcpd.conf.tmpl
@@ -150,7 +150,7 @@ shared-network {{ network.name }} {
max-lease-time {{ subnet.lease }};
{% endif %}
{% for host in subnet.static_mapping if not host.disabled %}
- host {% if host_decl_name %} {{ host.name }} {% else %} {{ network.name }}_{{ host.name }} {% endif %} {
+ host {{ host.name if host_decl_name else network.name + '_' + host.name }} {
{% if host.ip_address %}
fixed-address {{ host.ip_address }};
{% endif %}
diff --git a/smoketest/scripts/cli/test_service_dhcp-server.py b/smoketest/scripts/cli/test_service_dhcp-server.py
index 03537472a..8d6917cf1 100755
--- a/smoketest/scripts/cli/test_service_dhcp-server.py
+++ b/smoketest/scripts/cli/test_service_dhcp-server.py
@@ -45,7 +45,7 @@ class TestServiceDHCPServer(unittest.TestCase):
self.session.commit()
del self.session
- def test_single_pool(self):
+ def test_single_pool_range(self):
shared_net_name = 'SMOKE-1'
dns_1 = inc_ip(subnet, 2)
@@ -91,5 +91,58 @@ class TestServiceDHCPServer(unittest.TestCase):
# Check for running process
self.assertTrue(process_named_running(PROCESS_NAME))
+ def test_single_pool_static_mapping(self):
+ shared_net_name = 'SMOKE-2'
+
+ dns_1 = inc_ip(subnet, 2)
+ dns_2 = inc_ip(subnet, 3)
+ domain_name = 'vyos.net'
+
+ pool = base_path + ['shared-network-name', shared_net_name, 'subnet', subnet]
+ # we use the first subnet IP address as default gateway
+ self.session.set(pool + ['default-router', router])
+ self.session.set(pool + ['dns-server', dns_1])
+ self.session.set(pool + ['dns-server', dns_2])
+ self.session.set(pool + ['domain-name', domain_name])
+
+ # check validate() - No DHCP address range or active static-mapping set
+ with self.assertRaises(ConfigSessionError):
+ self.session.commit()
+
+ client_base = 10
+ for client in ['client1', 'client2', 'client3']:
+ mac = '00:50:00:00:00:{}'.format(client_base)
+ self.session.set(pool + ['static-mapping', client, 'mac-address', mac])
+ self.session.set(pool + ['static-mapping', client, 'ip-address', inc_ip(subnet, client_base)])
+ client_base += 1
+
+ # commit changes
+ self.session.commit()
+
+ config = read_file(DHCPD_CONF)
+ network = address_from_cidr(subnet)
+ netmask = netmask_from_cidr(subnet)
+ self.assertIn(f'ddns-update-style none;', config)
+ self.assertIn(f'subnet {network} netmask {netmask}' + r' {', config)
+ self.assertIn(f'option domain-name-servers {dns_1}, {dns_2};', config)
+ self.assertIn(f'option routers {router};', config)
+ self.assertIn(f'option domain-name "{domain_name}";', config)
+ self.assertIn(f'default-lease-time 86400;', config)
+ self.assertIn(f'max-lease-time 86400;', config)
+
+ client_base = 10
+ for client in ['client1', 'client2', 'client3']:
+ mac = '00:50:00:00:00:{}'.format(client_base)
+ ip = inc_ip(subnet, client_base)
+ self.assertIn(f'host {shared_net_name}_{client}' + ' {', config)
+ self.assertIn(f'fixed-address {ip};', config)
+ self.assertIn(f'hardware ethernet {mac};', config)
+ client_base += 1
+
+ self.assertIn(f'set shared-networkname = "{shared_net_name}";', config)
+
+ # Check for running process
+ self.assertTrue(process_named_running(PROCESS_NAME))
+
if __name__ == '__main__':
unittest.main()