Skip to content

Commit

Permalink
ddclient: T5791: Update smoketest for dynamic dns config path change
Browse files Browse the repository at this point in the history
  • Loading branch information
indrajitr committed Dec 1, 2023
1 parent 7cf735e commit 2d9b005
Showing 1 changed file with 64 additions and 66 deletions.
130 changes: 64 additions & 66 deletions smoketest/scripts/cli/test_service_dns_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
DDCLIENT_PNAME = 'ddclient'

base_path = ['service', 'dns', 'dynamic']
name_path = base_path + ['name']
server = 'ddns.vyos.io'
hostname = 'test.ddns.vyos.io'
zone = 'vyos.io'
Expand All @@ -58,38 +59,38 @@ def tearDown(self):

# IPv4 standard DDNS service configuration
def test_01_dyndns_service_standard(self):
svc_path = ['address', interface, 'service']
services = {'cloudflare': {'protocol': 'cloudflare'},
'freedns': {'protocol': 'freedns', 'username': username},
'zoneedit': {'protocol': 'zoneedit1', 'username': username}}

for svc, details in services.items():
self.cli_set(base_path + svc_path + [svc, 'host-name', hostname])
self.cli_set(base_path + svc_path + [svc, 'password', password])
self.cli_set(base_path + svc_path + [svc, 'zone', zone])
self.cli_set(base_path + svc_path + [svc, 'ttl', ttl])
self.cli_set(name_path + [svc, 'address', interface])
self.cli_set(name_path + [svc, 'host-name', hostname])
self.cli_set(name_path + [svc, 'password', password])
self.cli_set(name_path + [svc, 'zone', zone])
self.cli_set(name_path + [svc, 'ttl', ttl])
for opt, value in details.items():
self.cli_set(base_path + svc_path + [svc, opt, value])
self.cli_set(name_path + [svc, opt, value])

# 'zone' option is supported and required by 'cloudfare', but not 'freedns' and 'zoneedit'
self.cli_set(base_path + svc_path + [svc, 'zone', zone])
self.cli_set(name_path + [svc, 'zone', zone])
if details['protocol'] == 'cloudflare':
pass
else:
# exception is raised for unsupported ones
with self.assertRaises(ConfigSessionError):
self.cli_commit()
self.cli_delete(base_path + svc_path + [svc, 'zone'])
self.cli_delete(name_path + [svc, 'zone'])

# 'ttl' option is supported by 'cloudfare', but not 'freedns' and 'zoneedit'
self.cli_set(base_path + svc_path + [svc, 'ttl', ttl])
self.cli_set(name_path + [svc, 'ttl', ttl])
if details['protocol'] == 'cloudflare':
pass
else:
# exception is raised for unsupported ones
with self.assertRaises(ConfigSessionError):
self.cli_commit()
self.cli_delete(base_path + svc_path + [svc, 'ttl'])
self.cli_delete(name_path + [svc, 'ttl'])

# commit changes
self.cli_commit()
Expand All @@ -113,27 +114,28 @@ def test_01_dyndns_service_standard(self):
# IPv6 only DDNS service configuration
def test_02_dyndns_service_ipv6(self):
interval = '60'
svc_path = ['address', interface, 'service', 'dynv6']
svc_path = name_path + ['dynv6']
proto = 'dyndns2'
ip_version = 'ipv6'
wait_time = '600'
expiry_time_good = '3600'
expiry_time_bad = '360'

self.cli_set(base_path + ['interval', interval])
self.cli_set(base_path + svc_path + ['ip-version', ip_version])
self.cli_set(base_path + svc_path + ['protocol', proto])
self.cli_set(base_path + svc_path + ['server', server])
self.cli_set(base_path + svc_path + ['username', username])
self.cli_set(base_path + svc_path + ['password', password])
self.cli_set(base_path + svc_path + ['host-name', hostname])
self.cli_set(base_path + svc_path + ['wait-time', wait_time])
self.cli_set(svc_path + ['address', interface])
self.cli_set(svc_path + ['ip-version', ip_version])
self.cli_set(svc_path + ['protocol', proto])
self.cli_set(svc_path + ['server', server])
self.cli_set(svc_path + ['username', username])
self.cli_set(svc_path + ['password', password])
self.cli_set(svc_path + ['host-name', hostname])
self.cli_set(svc_path + ['wait-time', wait_time])

# expiry-time must be greater than wait-time, exception is raised otherwise
self.cli_set(base_path + svc_path + ['expiry-time', expiry_time_bad])
with self.assertRaises(ConfigSessionError):
self.cli_set(svc_path + ['expiry-time', expiry_time_bad])
self.cli_commit()
self.cli_set(base_path + svc_path + ['expiry-time', expiry_time_good])
self.cli_set(svc_path + ['expiry-time', expiry_time_good])

# commit changes
self.cli_commit()
Expand All @@ -152,25 +154,25 @@ def test_02_dyndns_service_ipv6(self):

# IPv4+IPv6 dual DDNS service configuration
def test_03_dyndns_service_dual_stack(self):
svc_path = ['address', interface, 'service']
services = {'cloudflare': {'protocol': 'cloudflare', 'zone': zone},
'freedns': {'protocol': 'freedns', 'username': username},
'google': {'protocol': 'googledomains', 'username': username}}
ip_version = 'both'

for name, details in services.items():
self.cli_set(base_path + svc_path + [name, 'host-name', hostname])
self.cli_set(base_path + svc_path + [name, 'password', password])
self.cli_set(name_path + [name, 'address', interface])
self.cli_set(name_path + [name, 'host-name', hostname])
self.cli_set(name_path + [name, 'password', password])
for opt, value in details.items():
self.cli_set(base_path + svc_path + [name, opt, value])
self.cli_set(name_path + [name, opt, value])

# Dual stack is supported by 'cloudfare' and 'freedns' but not 'googledomains'
# exception is raised for unsupported ones
self.cli_set(base_path + svc_path + [name, 'ip-version', ip_version])
self.cli_set(name_path + [name, 'ip-version', ip_version])
if details['protocol'] not in ['cloudflare', 'freedns']:
with self.assertRaises(ConfigSessionError):
self.cli_commit()
self.cli_delete(base_path + svc_path + [name, 'ip-version'])
self.cli_delete(name_path + [name, 'ip-version'])

# commit changes
self.cli_commit()
Expand All @@ -197,16 +199,19 @@ def test_03_dyndns_service_dual_stack(self):

def test_04_dyndns_rfc2136(self):
# Check if DDNS service can be configured and runs
svc_path = ['address', interface, 'rfc2136', 'vyos']
svc_path = name_path + ['vyos']
proto = 'nsupdate'

with tempfile.NamedTemporaryFile(prefix='/config/auth/') as key_file:
key_file.write(b'S3cretKey')

self.cli_set(base_path + svc_path + ['server', server])
self.cli_set(base_path + svc_path + ['zone', zone])
self.cli_set(base_path + svc_path + ['key', key_file.name])
self.cli_set(base_path + svc_path + ['ttl', ttl])
self.cli_set(base_path + svc_path + ['host-name', hostname])
self.cli_set(svc_path + ['address', interface])
self.cli_set(svc_path + ['protocol', proto])
self.cli_set(svc_path + ['server', server])
self.cli_set(svc_path + ['zone', zone])
self.cli_set(svc_path + ['key', key_file.name])
self.cli_set(svc_path + ['ttl', ttl])
self.cli_set(svc_path + ['host-name', hostname])

# commit changes
self.cli_commit()
Expand All @@ -215,24 +220,25 @@ def test_04_dyndns_rfc2136(self):
ddclient_conf = cmd(f'sudo cat {DDCLIENT_CONF}')
self.assertIn(f'use=if', ddclient_conf)
self.assertIn(f'if={interface}', ddclient_conf)
self.assertIn(f'protocol=nsupdate', ddclient_conf)
self.assertIn(f'protocol={proto}', ddclient_conf)
self.assertIn(f'server={server}', ddclient_conf)
self.assertIn(f'zone={zone}', ddclient_conf)
self.assertIn(f'password=\'{key_file.name}\'', ddclient_conf)
self.assertIn(f'ttl={ttl}', ddclient_conf)

def test_05_dyndns_hostname(self):
# Check if DDNS service can be configured and runs
svc_path = ['address', interface, 'service', 'namecheap']
svc_path = name_path + ['namecheap']
proto = 'namecheap'
hostnames = ['@', 'www', hostname, f'@.{hostname}']

for name in hostnames:
self.cli_set(base_path + svc_path + ['protocol', proto])
self.cli_set(base_path + svc_path + ['server', server])
self.cli_set(base_path + svc_path + ['username', username])
self.cli_set(base_path + svc_path + ['password', password])
self.cli_set(base_path + svc_path + ['host-name', name])
self.cli_set(svc_path + ['address', interface])
self.cli_set(svc_path + ['protocol', proto])
self.cli_set(svc_path + ['server', server])
self.cli_set(svc_path + ['username', username])
self.cli_set(svc_path + ['password', password])
self.cli_set(svc_path + ['host-name', name])

# commit changes
self.cli_commit()
Expand All @@ -247,42 +253,32 @@ def test_05_dyndns_hostname(self):

def test_06_dyndns_web_options(self):
# Check if DDNS service can be configured and runs
base_path_iface = base_path + ['address', interface]
base_path_web = base_path + ['address', 'web']
svc_path_iface = base_path_iface + ['service', 'cloudflare']
svc_path_web = base_path_web + ['service', 'cloudflare']
svc_path = name_path + ['cloudflare']
proto = 'cloudflare'
web_url_good = 'https://ifconfig.me/ip'
web_url_bad = 'http:/ifconfig.me/ip'

self.cli_set(svc_path_iface + ['protocol', proto])
self.cli_set(svc_path_iface + ['zone', zone])
self.cli_set(svc_path_iface + ['password', password])
self.cli_set(svc_path_iface + ['host-name', hostname])
self.cli_set(base_path_iface + ['web-options', 'url', web_url_good])
self.cli_set(svc_path + ['protocol', proto])
self.cli_set(svc_path + ['zone', zone])
self.cli_set(svc_path + ['password', password])
self.cli_set(svc_path + ['host-name', hostname])
self.cli_set(svc_path + ['web-options', 'url', web_url_good])

# web-options is supported only with web service based address lookup
# exception is raised for interface based address lookup
with self.assertRaises(ConfigSessionError):
self.cli_set(svc_path + ['address', interface])
self.cli_commit()
self.cli_delete(base_path_iface + ['web-options'])
self.cli_set(svc_path + ['address', 'web'])

# commit changes
self.cli_commit()

# web-options is supported with web service based address lookup
# this should work, but clear interface based config first
self.cli_delete(base_path_iface)
self.cli_set(svc_path_web + ['protocol', proto])
self.cli_set(svc_path_web + ['zone', zone])
self.cli_set(svc_path_web + ['password', password])
self.cli_set(svc_path_web + ['host-name', hostname])

# web-options must be a valid URL
with self.assertRaises(ConfigSessionError) as cm:
self.cli_set(base_path_web + ['web-options', 'url', web_url_bad])
self.assertIn(f'"{web_url_bad.removeprefix("http:")}" is not a valid URI', str(cm.exception))
self.cli_set(base_path_web + ['web-options', 'url', web_url_good])
with self.assertRaises(ConfigSessionError):
self.cli_set(svc_path + ['web-options', 'url', web_url_bad])
self.cli_commit()
self.cli_set(svc_path + ['web-options', 'url', web_url_good])

# commit changes
self.cli_commit()
Expand All @@ -300,15 +296,17 @@ def test_07_dyndns_vrf(self):
# Table number randomized, but should be within range 100-65535
vrf_table = "".join(random.choices(string.digits, k=4))
vrf_name = f'vyos-test-{vrf_table}'
svc_path = ['address', interface, 'service', 'cloudflare']
svc_path = name_path + ['cloudflare']
proto = 'cloudflare'

self.cli_set(['vrf', 'name', vrf_name, 'table', vrf_table])
self.cli_set(base_path + ['vrf', vrf_name])

self.cli_set(base_path + svc_path + ['protocol', 'cloudflare'])
self.cli_set(base_path + svc_path + ['host-name', hostname])
self.cli_set(base_path + svc_path + ['zone', zone])
self.cli_set(base_path + svc_path + ['password', password])
self.cli_set(svc_path + ['address', interface])
self.cli_set(svc_path + ['protocol', proto])
self.cli_set(svc_path + ['host-name', hostname])
self.cli_set(svc_path + ['zone', zone])
self.cli_set(svc_path + ['password', password])

# commit changes
self.cli_commit()
Expand Down

0 comments on commit 2d9b005

Please sign in to comment.