|
21 | 21 | import unittest
|
22 | 22 | import yaml
|
23 | 23 | import zaza
|
| 24 | +import zaza.model as model |
24 | 25 | import zaza.utilities.installers
|
| 26 | +from tenacity import stop_after_attempt, wait_exponential, retry_if_result |
25 | 27 |
|
26 | 28 |
|
27 | 29 | class NfsGaneshaTest(unittest.TestCase):
|
@@ -89,28 +91,31 @@ def _grant_access(self, share_name: str, access_ip: str):
|
89 | 91 | self.assertEqual(action.status, 'completed')
|
90 | 92 |
|
91 | 93 | 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): |
93 | 95 | self._install_dependencies(unit_name)
|
94 |
| - ssh_cmd = ( |
| 96 | + cmd = ( |
95 | 97 | 'sudo mkdir -p {0} && '
|
96 | 98 | 'sudo mount -t {1} -o nfsvers=4.1,proto=tcp {2}:{3} {0}'.format(
|
97 | 99 | self.mount_dir,
|
98 | 100 | self.share_protocol,
|
99 | 101 | share_ip,
|
100 | 102 | 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() |
110 | 116 | 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 | + |
114 | 119 | self.mounts_share = True
|
115 | 120 |
|
116 | 121 | def _install_dependencies(self, unit: str):
|
@@ -158,7 +163,9 @@ def test_create_share(self):
|
158 | 163 | self._write_testing_file_on_instance('ceph-osd/0')
|
159 | 164 | # Todo - enable ACL testing
|
160 | 165 | 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 | + ) |
162 | 169 | self.fail('Mounting should not have succeeded')
|
163 | 170 | except: # noqa: E722
|
164 | 171 | pass
|
|
0 commit comments