Skip to content

Commit ebf1dbc

Browse files
author
Kyr Shatskyy
committed
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 <[email protected]>
1 parent 46d7dd9 commit ebf1dbc

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

qa/tasks/cephfs/mount.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@ def _set_filemode_on_mntpt(self):
264264
if 'permission denied' in stderr.getvalue().lower():
265265
pass
266266

267+
def _default_gateway(self):
268+
routes = self.client_remote.sh('ip r', timeout=(5*60))
269+
defaults = re.findall(r'^default .*', routes)
270+
if defaults == False:
271+
raise RuntimeError("No default gw found")
272+
return defaults[0].split()[4]
273+
267274
def _setup_brx_and_nat(self):
268275
# The ip for ceph-brx should be
269276
ip = IP(self.ceph_brx_net)[-2]
@@ -296,11 +303,7 @@ def _setup_brx_and_nat(self):
296303
self.client_remote.run(args=args, timeout=(5*60), omit_sudo=False)
297304

298305
# Setup the NAT
299-
routes = self.client_remote.sh('ip r', timeout=(5*60))
300-
defaults = re.findall(r'^default .*', routes)
301-
if defaults == False:
302-
raise RuntimeError("No default gw found")
303-
gw = defaults[0].split()[4]
306+
gw = self._default_gateway()
304307

305308
self.run_shell_payload(f"""
306309
set -e
@@ -440,11 +443,7 @@ def _cleanup_brx_and_nat(self):
440443
ip = IP(self.ceph_brx_net)[-2]
441444
mask = self.ceph_brx_net.split('/')[1]
442445

443-
routes = self.client_remote.sh('ip r', timeout=(5*60))
444-
defaults = re.findall(r'^default .*', routes)
445-
if defaults == False:
446-
raise RuntimeError("No default gw found")
447-
gw = defaults[0].split()[4]
446+
gw = self._default_gateway()
448447

449448
self.run_shell_payload(f"""
450449
set -e

0 commit comments

Comments
 (0)