|
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 |
@@ -123,6 +124,108 @@ def wait_till_health_warn(self, health_warn, active_mds_id, sleep=3, |
123 | 124 | return |
124 | 125 |
|
125 | 126 |
|
| 127 | +class TestMdsLastSeen(CephFSTestCase): |
| 128 | + """ |
| 129 | + Tests for `mds last-seen` command. |
| 130 | + """ |
| 131 | + |
| 132 | + MDSS_REQUIRED = 2 |
| 133 | + |
| 134 | + def test_in_text(self): |
| 135 | + """ |
| 136 | + That `mds last-seen` returns 0 for an MDS currently in the map. |
| 137 | + """ |
| 138 | + |
| 139 | + status = self.fs.status() |
| 140 | + r0 = self.fs.get_rank(0, status=status) |
| 141 | + s = self.get_ceph_cmd_stdout("mds", "last-seen", r0['name']) |
| 142 | + seconds = int(re.match(r"^(\d+)s$", s).group(1)) |
| 143 | + self.assertEqual(seconds, 0) |
| 144 | + |
| 145 | + def test_in_json(self): |
| 146 | + """ |
| 147 | + That `mds last-seen` returns 0 for an MDS currently in the map. |
| 148 | + """ |
| 149 | + |
| 150 | + status = self.fs.status() |
| 151 | + r0 = self.fs.get_rank(0, status=status) |
| 152 | + s = self.get_ceph_cmd_stdout("--format=json", "mds", "last-seen", r0['name']) |
| 153 | + J = json.loads(s) |
| 154 | + seconds = int(re.match(r"^(\d+)s$", J['last-seen']).group(1)) |
| 155 | + self.assertEqual(seconds, 0) |
| 156 | + |
| 157 | + def test_unknown(self): |
| 158 | + """ |
| 159 | + That `mds last-seen` returns ENOENT for an mds not in recent maps. |
| 160 | + """ |
| 161 | + |
| 162 | + try: |
| 163 | + self.get_ceph_cmd_stdout("--format=json", "mds", "last-seen", 'foo') |
| 164 | + except CommandFailedError as e: |
| 165 | + self.assertEqual(e.exitstatus, errno.ENOENT) |
| 166 | + else: |
| 167 | + self.fail("non-existent mds should fail ENOENT") |
| 168 | + |
| 169 | + def test_standby(self): |
| 170 | + """ |
| 171 | + That `mds last-seen` returns 0 for a standby. |
| 172 | + """ |
| 173 | + |
| 174 | + status = self.fs.status() |
| 175 | + for info in status.get_standbys(): |
| 176 | + s = self.get_ceph_cmd_stdout("--format=json", "mds", "last-seen", info['name']) |
| 177 | + J = json.loads(s) |
| 178 | + seconds = int(re.match(r"^(\d+)s$", J['last-seen']).group(1)) |
| 179 | + self.assertEqual(seconds, 0) |
| 180 | + |
| 181 | + def test_stopped(self): |
| 182 | + """ |
| 183 | + That `mds last-seen` returns >0 for mds that is stopped. |
| 184 | + """ |
| 185 | + |
| 186 | + status = self.fs.status() |
| 187 | + r0 = self.fs.get_rank(0, status=status) |
| 188 | + self.fs.mds_stop(mds_id=r0['name']) |
| 189 | + self.fs.rank_fail() |
| 190 | + sleep(2) |
| 191 | + with safe_while(sleep=1, tries=self.fs.beacon_timeout, action='wait for last-seen >0') as proceed: |
| 192 | + while proceed(): |
| 193 | + s = self.get_ceph_cmd_stdout("--format=json", "mds", "last-seen", r0['name']) |
| 194 | + J = json.loads(s) |
| 195 | + seconds = int(re.match(r"^(\d+)s$", J['last-seen']).group(1)) |
| 196 | + if seconds == 0: |
| 197 | + continue |
| 198 | + self.assertGreater(seconds, 1) |
| 199 | + break |
| 200 | + |
| 201 | + def test_gc(self): |
| 202 | + """ |
| 203 | + That historical mds information is eventually garbage collected. |
| 204 | + """ |
| 205 | + |
| 206 | + prune_time = 20 |
| 207 | + sleep_time = 2 |
| 208 | + self.config_set('mon', 'mon_fsmap_prune_threshold', prune_time) |
| 209 | + status = self.fs.status() |
| 210 | + r0 = self.fs.get_rank(0, status=status) |
| 211 | + self.fs.mds_stop(mds_id=r0['name']) |
| 212 | + self.fs.rank_fail() |
| 213 | + last = 0 |
| 214 | + for i in range(prune_time): |
| 215 | + sleep(sleep_time) # we will sleep twice prune_time |
| 216 | + try: |
| 217 | + s = self.get_ceph_cmd_stdout("--format=json", "mds", "last-seen", r0['name']) |
| 218 | + J = json.loads(s) |
| 219 | + seconds = int(re.match(r"^(\d+)s$", J['last-seen']).group(1)) |
| 220 | + self.assertGreater(seconds, last) |
| 221 | + log.debug("last_seen: %ds", seconds) |
| 222 | + last = seconds |
| 223 | + except CommandFailedError as e: |
| 224 | + self.assertEqual(e.exitstatus, errno.ENOENT) |
| 225 | + self.assertGreaterEqual(last + sleep_time + 1, prune_time) # rounding error add 1 |
| 226 | + return |
| 227 | + self.fail("map was no garbage collected as expected") |
| 228 | + |
126 | 229 | @classhook('_add_valid_tell') |
127 | 230 | class TestValidTell(TestAdminCommands): |
128 | 231 | @classmethod |
|
0 commit comments