Skip to content

Commit befa360

Browse files
authored
ceph-nfs: make mount retry (#17)
1 parent 475abc1 commit befa360

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

ceph-nfs/tests/nfs_ganesha.py

+22-15
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import unittest
2222
import yaml
2323
import zaza
24+
import zaza.model as model
2425
import zaza.utilities.installers
26+
from tenacity import stop_after_attempt, wait_exponential, retry_if_result
2527

2628

2729
class NfsGaneshaTest(unittest.TestCase):
@@ -89,28 +91,31 @@ def _grant_access(self, share_name: str, access_ip: str):
8991
self.assertEqual(action.status, 'completed')
9092

9193
def _mount_share(self, unit_name: str, share_ip: str,
92-
export_path: str, retry: bool = True):
94+
export_path: str, perform_retry: bool = True):
9395
self._install_dependencies(unit_name)
94-
ssh_cmd = (
96+
cmd = (
9597
'sudo mkdir -p {0} && '
9698
'sudo mount -t {1} -o nfsvers=4.1,proto=tcp {2}:{3} {0}'.format(
9799
self.mount_dir,
98100
self.share_protocol,
99101
share_ip,
100102
export_path))
101-
if retry:
102-
for attempt in tenacity.Retrying(
103-
stop=tenacity.stop_after_attempt(5),
104-
wait=tenacity.wait_exponential(multiplier=3,
105-
min=2, max=10)):
106-
with attempt:
107-
zaza.utilities.generic.run_via_ssh(
108-
unit_name=unit_name,
109-
cmd=ssh_cmd)
103+
if perform_retry:
104+
@tenacity.retry(
105+
stop=stop_after_attempt(5),
106+
wait=wait_exponential(multiplier=3, min=2, max=10),
107+
retry=retry_if_result(lambda res: res.get('Code') != '0')
108+
)
109+
def _do_mount():
110+
logging.info(f"Mounting CephFS on {unit_name}")
111+
res = model.run_on_unit(unit_name, cmd)
112+
logging.info(f"Mount result: {res}")
113+
return res
114+
115+
_do_mount()
110116
else:
111-
zaza.utilities.generic.run_via_ssh(
112-
unit_name=unit_name,
113-
cmd=ssh_cmd)
117+
model.run_on_unit(unit_name, cmd)
118+
114119
self.mounts_share = True
115120

116121
def _install_dependencies(self, unit: str):
@@ -158,7 +163,9 @@ def test_create_share(self):
158163
self._write_testing_file_on_instance('ceph-osd/0')
159164
# Todo - enable ACL testing
160165
try:
161-
self._mount_share('ceph-osd/1', ip, export_path, retry=False)
166+
self._mount_share(
167+
'ceph-osd/1', ip, export_path, perform_retry=False
168+
)
162169
self.fail('Mounting should not have succeeded')
163170
except: # noqa: E722
164171
pass

0 commit comments

Comments
 (0)