Skip to content

Commit

Permalink
avahi: T6908: add option to define max-cache entries (#4207)
Browse files Browse the repository at this point in the history
* avahi: T6908: reduce runtime overhead in smoketests by using setUpClass/tearDownClass

* avahi: T6908: add option to define mdns-repeater max-cache entries

Add CLI option to configure `cache-entries-max` entries in Avahi daemon
configuration.

Default value of 4096 for "cache-entries" CVLI node was retrieved from
source code.
  • Loading branch information
c-po authored Nov 23, 2024
1 parent b91aaed commit ec18cc3
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 17 deletions.
3 changes: 3 additions & 0 deletions data/templates/mdns-repeater/avahi-daemon.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ allow-interfaces={{ interface | join(', ') }}
{% if browse_domain is vyos_defined and browse_domain | length %}
browse-domains={{ browse_domain | join(', ') }}
{% endif %}
{% if cache_entries is vyos_defined %}
cache-entries-max={{ cache_entries }}
{% endif %}
disallow-other-stacks=no

[wide-area]
Expand Down
17 changes: 17 additions & 0 deletions interface-definitions/service_mdns_repeater.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@
<multi/>
</properties>
</leafNode>
<leafNode name="cache-entries">
<properties>
<help>Number of resource records cached per interface</help>
<valueHelp>
<format>u32:0</format>
<description>Disable caching</description>
</valueHelp>
<valueHelp>
<format>u32:1-65535</format>
<description>Resource records to cache per interface</description>
</valueHelp>
<constraint>
<validator name="numeric" argument="--range 0-65535"/>
</constraint>
</properties>
<defaultValue>4096</defaultValue>
</leafNode>
<leafNode name="vrrp-disable">
<properties>
<help>Disables mDNS repeater on VRRP interfaces not in MASTER state</help>
Expand Down
76 changes: 59 additions & 17 deletions smoketest/scripts/cli/test_service_mdns_repeater.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,45 @@
from configparser import ConfigParser
from vyos.configsession import ConfigSessionError
from vyos.utils.process import process_named_running
from vyos.xml_ref import default_value

base_path = ['service', 'mdns', 'repeater']
intf_base = ['interfaces', 'dummy']
config_file = '/run/avahi-daemon/avahi-daemon.conf'


class TestServiceMDNSrepeater(VyOSUnitTestSHIM.TestCase):
def setUp(self):
# Start with a clean CLI instance
self.cli_delete(base_path)
@classmethod
def setUpClass(cls):
super(TestServiceMDNSrepeater, cls).setUpClass()

# Service required a configured IP address on the interface
self.cli_set(intf_base + ['dum10', 'address', '192.0.2.1/30'])
self.cli_set(intf_base + ['dum10', 'ipv6', 'address', 'no-default-link-local'])
self.cli_set(intf_base + ['dum20', 'address', '192.0.2.5/30'])
self.cli_set(intf_base + ['dum20', 'address', '2001:db8:0:2::5/64'])
self.cli_set(intf_base + ['dum30', 'address', '192.0.2.9/30'])
self.cli_set(intf_base + ['dum30', 'address', '2001:db8:0:2::9/64'])
self.cli_set(intf_base + ['dum40', 'address', '2001:db8:0:2::11/64'])
self.cli_commit()
# ensure we can also run this test on a live system - so lets clean
# out the current configuration :)
cls.cli_delete(cls, base_path)

cls.cli_set(cls, intf_base + ['dum10', 'address', '192.0.2.1/30'])
cls.cli_set(cls, intf_base + ['dum10', 'ipv6', 'address', 'no-default-link-local'])
cls.cli_set(cls, intf_base + ['dum20', 'address', '192.0.2.5/30'])
cls.cli_set(cls, intf_base + ['dum20', 'address', '2001:db8:0:2::5/64'])
cls.cli_set(cls, intf_base + ['dum30', 'address', '192.0.2.9/30'])
cls.cli_set(cls, intf_base + ['dum30', 'address', '2001:db8:0:2::9/64'])
cls.cli_set(cls, intf_base + ['dum40', 'address', '2001:db8:0:2::11/64'])

cls.cli_commit(cls)

@classmethod
def tearDownClass(cls):
cls.cli_delete(cls, intf_base + ['dum10'])
cls.cli_delete(cls, intf_base + ['dum20'])
cls.cli_delete(cls, intf_base + ['dum30'])
cls.cli_delete(cls, intf_base + ['dum40'])

cls.cli_commit(cls)

def tearDown(self):
# Check for running process
self.assertTrue(process_named_running('avahi-daemon'))

self.cli_delete(base_path)
self.cli_delete(intf_base + ['dum10'])
self.cli_delete(intf_base + ['dum20'])
self.cli_delete(intf_base + ['dum30'])
self.cli_delete(intf_base + ['dum40'])
self.cli_commit()

# Check that there is no longer a running process
Expand Down Expand Up @@ -130,5 +139,38 @@ def test_service_ipv6(self):
self.assertEqual(conf['server']['allow-interfaces'], 'dum30, dum40')
self.assertEqual(conf['reflector']['enable-reflector'], 'yes')

def test_service_max_cache_entries(self):
cli_default_max_cache = default_value(base_path + ['cache-entries'])
self.cli_set(base_path)

# Need at least two interfaces
with self.assertRaises(ConfigSessionError):
self.cli_commit()
self.cli_set(base_path + ['interface', 'dum20'])

# Need at least two interfaces
with self.assertRaises(ConfigSessionError):
self.cli_commit()
self.cli_set(base_path + ['interface', 'dum30'])

self.cli_commit()

# Validate configuration values
conf = ConfigParser(delimiters='=')
conf.read(config_file)
self.assertEqual(conf['server']['cache-entries-max'], cli_default_max_cache)

# Set max cache entries
cache_entries = '1234'
self.cli_set(base_path + ['cache-entries', cache_entries])

self.cli_commit()

# Validate configuration values
conf = ConfigParser(delimiters='=')
conf.read(config_file)

self.assertEqual(conf['server']['cache-entries-max'], cache_entries)

if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit ec18cc3

Please sign in to comment.