|
1 | 1 | from io import StringIO |
2 | 2 |
|
3 | 3 | from tasks.cephfs.fuse_mount import FuseMount |
4 | | -from tasks.cephfs.cephfs_test_case import CephFSTestCase |
| 4 | +from tasks.cephfs.cephfs_test_case import CephFSTestCase, classhook |
5 | 5 | from teuthology.exceptions import CommandFailedError |
6 | 6 | from textwrap import dedent |
7 | 7 | from threading import Thread |
@@ -521,6 +521,84 @@ def test_session_ls(self): |
521 | 521 |
|
522 | 522 | def test_client_ls(self): |
523 | 523 | self._session_client_ls(['client', 'ls']) |
| 524 | + |
| 525 | + |
| 526 | +@classhook('_add_session_client_evictions') |
| 527 | +class TestSessionClientEvict(CephFSTestCase): |
| 528 | + CLIENTS_REQUIRED = 3 |
| 529 | + |
| 530 | + def _evict_without_filter(self, cmd): |
| 531 | + info_initial = self.fs.rank_asok(cmd + ['ls']) |
| 532 | + # without any filter or flags |
| 533 | + with self.assertRaises(CommandFailedError) as ce: |
| 534 | + self.fs.rank_asok(cmd + ['evict']) |
| 535 | + self.assertEqual(ce.exception.exitstatus, errno.EINVAL) |
| 536 | + # without any filter but with existing flag |
| 537 | + with self.assertRaises(CommandFailedError) as ce: |
| 538 | + self.fs.rank_asok(cmd + ['evict', '--help']) |
| 539 | + self.assertEqual(ce.exception.exitstatus, errno.EINVAL) |
| 540 | + info = self.fs.rank_asok(cmd + ['ls']) |
| 541 | + self.assertEqual(len(info), len(info_initial)) |
| 542 | + # without any filter but with non-existing flag |
| 543 | + with self.assertRaises(CommandFailedError) as ce: |
| 544 | + self.fs.rank_asok(cmd + ['evict', '--foo']) |
| 545 | + self.assertEqual(ce.exception.exitstatus, errno.EINVAL) |
| 546 | + info = self.fs.rank_asok(cmd + ['ls']) |
| 547 | + self.assertEqual(len(info), len(info_initial)) |
| 548 | + |
| 549 | + def _evict_with_id_zero(self, cmd): |
| 550 | + # with id=0 |
| 551 | + with self.assertRaises(CommandFailedError) as ce: |
| 552 | + self.fs.rank_tell(cmd + ['evict', 'id=0']) |
| 553 | + self.assertEqual(ce.exception.exitstatus, errno.EINVAL) |
| 554 | + |
| 555 | + def _evict_with_invalid_id(self, cmd): |
| 556 | + # with invalid id |
| 557 | + with self.assertRaises(CommandFailedError) as ce: |
| 558 | + self.fs.rank_tell(cmd + ['evict', 'id=1']) |
| 559 | + self.assertEqual(ce.exception.exitstatus, errno.ESRCH) |
| 560 | + |
| 561 | + def _evict_with_negative_id(self, cmd): |
| 562 | + # with negative id |
| 563 | + with self.assertRaises(CommandFailedError) as ce: |
| 564 | + self.fs.rank_tell(cmd + ['evict', 'id=-9']) |
| 565 | + self.assertEqual(ce.exception.exitstatus, errno.ESRCH) |
| 566 | + |
| 567 | + def _evict_with_valid_id(self, cmd): |
| 568 | + info_initial = self.fs.rank_asok(cmd + ['ls']) |
| 569 | + mount_a_client_id = self.mount_a.get_global_id() |
| 570 | + # with a valid id |
| 571 | + self.fs.rank_asok(cmd + ['evict', f'id={mount_a_client_id}']) |
| 572 | + info = self.fs.rank_asok(cmd + ['ls']) |
| 573 | + self.assertEqual(len(info), len(info_initial) - 1) # client with id provided is evicted |
| 574 | + self.assertNotIn(mount_a_client_id, [val['id'] for val in info]) |
| 575 | + |
| 576 | + def _evict_all_clients(self, cmd): |
| 577 | + # with id=* to evict all clients |
| 578 | + info = self.fs.rank_asok(cmd + ['ls']) |
| 579 | + self.assertGreater(len(info), 0) |
| 580 | + self.fs.rank_asok(cmd + ['evict', 'id=*']) |
| 581 | + info = self.fs.rank_asok(cmd + ['ls']) |
| 582 | + self.assertEqual(len(info), 0) # multiple clients are evicted |
| 583 | + |
| 584 | + @classmethod |
| 585 | + def _add_session_client_evictions(cls): |
| 586 | + tests = [ |
| 587 | + "_evict_without_filter", |
| 588 | + "_evict_with_id_zero", |
| 589 | + "_evict_with_invalid_id", |
| 590 | + "_evict_with_negative_id", |
| 591 | + "_evict_with_valid_id", |
| 592 | + "_evict_all_clients", |
| 593 | + ] |
| 594 | + def create_test(t, cmd): |
| 595 | + def test(self): |
| 596 | + getattr(self, t)(cmd) |
| 597 | + return test |
| 598 | + for t in tests: |
| 599 | + setattr(cls, 'test_session' + t, create_test(t, ['session'])) |
| 600 | + setattr(cls, 'test_client' + t, create_test(t, ['client'])) |
| 601 | + |
524 | 602 |
|
525 | 603 | class TestCacheDrop(CephFSTestCase): |
526 | 604 | CLIENTS_REQUIRED = 1 |
|
0 commit comments