|
4 | 4 | import uuid |
5 | 5 | from io import StringIO |
6 | 6 | from os.path import join as os_path_join |
| 7 | +import re |
7 | 8 | from time import sleep |
8 | 9 |
|
9 | 10 | from teuthology.exceptions import CommandFailedError |
@@ -196,6 +197,108 @@ def wait_till_health_warn(self, health_warn, active_mds_id, sleep=3, |
196 | 197 | return |
197 | 198 |
|
198 | 199 |
|
| 200 | +class TestMdsLastSeen(CephFSTestCase): |
| 201 | + """ |
| 202 | + Tests for `mds last-seen` command. |
| 203 | + """ |
| 204 | + |
| 205 | + MDSS_REQUIRED = 2 |
| 206 | + |
| 207 | + def test_in_text(self): |
| 208 | + """ |
| 209 | + That `mds last-seen` returns 0 for an MDS currently in the map. |
| 210 | + """ |
| 211 | + |
| 212 | + status = self.fs.status() |
| 213 | + r0 = self.fs.get_rank(0, status=status) |
| 214 | + s = self.get_ceph_cmd_stdout("mds", "last-seen", r0['name']) |
| 215 | + seconds = int(re.match(r"^(\d+)s$", s).group(1)) |
| 216 | + self.assertEqual(seconds, 0) |
| 217 | + |
| 218 | + def test_in_json(self): |
| 219 | + """ |
| 220 | + That `mds last-seen` returns 0 for an MDS currently in the map. |
| 221 | + """ |
| 222 | + |
| 223 | + status = self.fs.status() |
| 224 | + r0 = self.fs.get_rank(0, status=status) |
| 225 | + s = self.get_ceph_cmd_stdout("--format=json", "mds", "last-seen", r0['name']) |
| 226 | + J = json.loads(s) |
| 227 | + seconds = int(re.match(r"^(\d+)s$", J['last-seen']).group(1)) |
| 228 | + self.assertEqual(seconds, 0) |
| 229 | + |
| 230 | + def test_unknown(self): |
| 231 | + """ |
| 232 | + That `mds last-seen` returns ENOENT for an mds not in recent maps. |
| 233 | + """ |
| 234 | + |
| 235 | + try: |
| 236 | + self.get_ceph_cmd_stdout("--format=json", "mds", "last-seen", 'foo') |
| 237 | + except CommandFailedError as e: |
| 238 | + self.assertEqual(e.exitstatus, errno.ENOENT) |
| 239 | + else: |
| 240 | + self.fail("non-existent mds should fail ENOENT") |
| 241 | + |
| 242 | + def test_standby(self): |
| 243 | + """ |
| 244 | + That `mds last-seen` returns 0 for a standby. |
| 245 | + """ |
| 246 | + |
| 247 | + status = self.fs.status() |
| 248 | + for info in status.get_standbys(): |
| 249 | + s = self.get_ceph_cmd_stdout("--format=json", "mds", "last-seen", info['name']) |
| 250 | + J = json.loads(s) |
| 251 | + seconds = int(re.match(r"^(\d+)s$", J['last-seen']).group(1)) |
| 252 | + self.assertEqual(seconds, 0) |
| 253 | + |
| 254 | + def test_stopped(self): |
| 255 | + """ |
| 256 | + That `mds last-seen` returns >0 for mds that is stopped. |
| 257 | + """ |
| 258 | + |
| 259 | + status = self.fs.status() |
| 260 | + r0 = self.fs.get_rank(0, status=status) |
| 261 | + self.fs.mds_stop(mds_id=r0['name']) |
| 262 | + self.fs.rank_fail() |
| 263 | + sleep(2) |
| 264 | + with safe_while(sleep=1, tries=self.fs.beacon_timeout, action='wait for last-seen >0') as proceed: |
| 265 | + while proceed(): |
| 266 | + s = self.get_ceph_cmd_stdout("--format=json", "mds", "last-seen", r0['name']) |
| 267 | + J = json.loads(s) |
| 268 | + seconds = int(re.match(r"^(\d+)s$", J['last-seen']).group(1)) |
| 269 | + if seconds == 0: |
| 270 | + continue |
| 271 | + self.assertGreater(seconds, 1) |
| 272 | + break |
| 273 | + |
| 274 | + def test_gc(self): |
| 275 | + """ |
| 276 | + That historical mds information is eventually garbage collected. |
| 277 | + """ |
| 278 | + |
| 279 | + prune_time = 20 |
| 280 | + sleep_time = 2 |
| 281 | + self.config_set('mon', 'mon_fsmap_prune_threshold', prune_time) |
| 282 | + status = self.fs.status() |
| 283 | + r0 = self.fs.get_rank(0, status=status) |
| 284 | + self.fs.mds_stop(mds_id=r0['name']) |
| 285 | + self.fs.rank_fail() |
| 286 | + last = 0 |
| 287 | + for i in range(prune_time): |
| 288 | + sleep(sleep_time) # we will sleep twice prune_time |
| 289 | + try: |
| 290 | + s = self.get_ceph_cmd_stdout("--format=json", "mds", "last-seen", r0['name']) |
| 291 | + J = json.loads(s) |
| 292 | + seconds = int(re.match(r"^(\d+)s$", J['last-seen']).group(1)) |
| 293 | + self.assertGreater(seconds, last) |
| 294 | + log.debug("last_seen: %ds", seconds) |
| 295 | + last = seconds |
| 296 | + except CommandFailedError as e: |
| 297 | + self.assertEqual(e.exitstatus, errno.ENOENT) |
| 298 | + self.assertGreaterEqual(last + sleep_time + 1, prune_time) # rounding error add 1 |
| 299 | + return |
| 300 | + self.fail("map was no garbage collected as expected") |
| 301 | + |
199 | 302 | @classhook('_add_valid_tell') |
200 | 303 | class TestValidTell(TestAdminCommands): |
201 | 304 | @classmethod |
|
0 commit comments