From 01d5bec5e6f2756c458d0986151792885c470149 Mon Sep 17 00:00:00 2001 From: Shubha Jain Date: Fri, 17 Apr 2026 17:11:10 +0530 Subject: [PATCH] tests: add coverage for virtual_ip bind_addr in nfs Signed-off-by: Shubha Jain --- .../templates/services/nfs/ganesha.conf.j2 | 7 ++--- .../mgr/cephadm/tests/services/test_nfs.py | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/pybind/mgr/cephadm/templates/services/nfs/ganesha.conf.j2 b/src/pybind/mgr/cephadm/templates/services/nfs/ganesha.conf.j2 index 768e64302f4..1c10f2b9128 100644 --- a/src/pybind/mgr/cephadm/templates/services/nfs/ganesha.conf.j2 +++ b/src/pybind/mgr/cephadm/templates/services/nfs/ganesha.conf.j2 @@ -11,6 +11,9 @@ NFS_CORE_PARAM { Enable_UDP = false; NFS_Port = {{ port }}; allow_set_io_flusher_fail = true; +{% if haproxy_hosts %} + HAProxy_Hosts = {{ haproxy_hosts|join(", ") }}; +{% endif %} {% if monitoring_addr %} Monitoring_Addr = {{ monitoring_addr }}; {% endif %} @@ -20,9 +23,6 @@ NFS_CORE_PARAM { {% if bind_addr %} Bind_addr = {{ bind_addr }}; {% endif %} -{% if haproxy_hosts %} - HAProxy_Hosts = {{ haproxy_hosts|join(", ") }}; -{% endif %} {% if enable_rdma and rdma_port %} NFS_RDMA_Port = {{ rdma_port }}; {% endif %} @@ -94,5 +94,4 @@ TLS_CONFIG{ {% endif %} } {% endif %} - %url {{ url }} diff --git a/src/pybind/mgr/cephadm/tests/services/test_nfs.py b/src/pybind/mgr/cephadm/tests/services/test_nfs.py index 0094aad24f5..21a94f40a61 100644 --- a/src/pybind/mgr/cephadm/tests/services/test_nfs.py +++ b/src/pybind/mgr/cephadm/tests/services/test_nfs.py @@ -99,6 +99,37 @@ class TestNFS: ganesha_conf = nfs_generated_conf['files']['ganesha.conf'] assert "Bind_addr = 1.2.3.7" in ganesha_conf + @patch("cephadm.serve.CephadmServe._run_cephadm") + @patch("cephadm.services.nfs.NFSService.fence_old_ranks", MagicMock()) + @patch("cephadm.services.nfs.NFSService.run_grace_tool", MagicMock()) + @patch("cephadm.services.nfs.NFSService.purge", MagicMock()) + @patch("cephadm.services.nfs.NFSService.create_rados_config_obj", MagicMock()) + def test_nfs_bind_addr_virtual_ip(self, _run_cephadm, cephadm_module: CephadmOrchestrator): + _run_cephadm.side_effect = async_side_effect(('{}', '', 0)) + + with with_host(cephadm_module, 'host1', addr='1.2.3.7'): + cephadm_module.cache.update_host_networks('host1', { + '1.2.3.0/24': { + 'if0': ['1.2.3.7'] + } + }) + + nfs_spec = NFSServiceSpec( + service_id="foo", + placement=PlacementSpec(hosts=['host1']), + virtual_ip='1.2.3.100', + enable_haproxy_protocol=False + ) + + with with_service(cephadm_module, nfs_spec, status_running=True) as _: + dds = wait(cephadm_module, cephadm_module.list_daemons()) + daemon_spec = CephadmDaemonDeploySpec.from_daemon_description(dds[0]) + + nfs_generated_conf, _ = service_registry.get_service('nfs').generate_config(daemon_spec) + ganesha_conf = nfs_generated_conf['files']['ganesha.conf'] + + assert "Bind_addr = 1.2.3.100" in ganesha_conf + @patch("cephadm.serve.CephadmServe._run_cephadm") def test_ingress_without_haproxy_stats(self, _run_cephadm, cephadm_module: CephadmOrchestrator): _run_cephadm.side_effect = async_side_effect(('{}', '', 0)) -- 2.47.3