From ebf1dbca5f1492cac03ff847cda69839545a7da6 Mon Sep 17 00:00:00 2001 From: Kyr Shatskyy Date: Wed, 12 Mar 2025 13:01:12 +0100 Subject: [PATCH] qa/tasks/cephfs/mount: introduce _default_gateway method Create function for getting default gateway in order to reduce code duplication. Signed-off-by: Kyr Shatskyy --- qa/tasks/cephfs/mount.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/qa/tasks/cephfs/mount.py b/qa/tasks/cephfs/mount.py index 57b3096c3c512..3899ad2aa8cde 100644 --- a/qa/tasks/cephfs/mount.py +++ b/qa/tasks/cephfs/mount.py @@ -264,6 +264,13 @@ class CephFSMountBase(object): if 'permission denied' in stderr.getvalue().lower(): pass + def _default_gateway(self): + routes = self.client_remote.sh('ip r', timeout=(5*60)) + defaults = re.findall(r'^default .*', routes) + if defaults == False: + raise RuntimeError("No default gw found") + return defaults[0].split()[4] + def _setup_brx_and_nat(self): # The ip for ceph-brx should be ip = IP(self.ceph_brx_net)[-2] @@ -296,11 +303,7 @@ class CephFSMountBase(object): self.client_remote.run(args=args, timeout=(5*60), omit_sudo=False) # Setup the NAT - routes = self.client_remote.sh('ip r', timeout=(5*60)) - defaults = re.findall(r'^default .*', routes) - if defaults == False: - raise RuntimeError("No default gw found") - gw = defaults[0].split()[4] + gw = self._default_gateway() self.run_shell_payload(f""" set -e @@ -440,11 +443,7 @@ class CephFSMountBase(object): ip = IP(self.ceph_brx_net)[-2] mask = self.ceph_brx_net.split('/')[1] - routes = self.client_remote.sh('ip r', timeout=(5*60)) - defaults = re.findall(r'^default .*', routes) - if defaults == False: - raise RuntimeError("No default gw found") - gw = defaults[0].split()[4] + gw = self._default_gateway() self.run_shell_payload(f""" set -e -- 2.39.5