Skip to content

Commit 1275f1a

Browse files
committed
Merge PR ceph#59161 into main
* refs/pull/59161/head: qa: test failure for duplicate retention spec mgr/snap_schedule: fix message format error Reviewed-by: Christopher Hoffman <[email protected]> Reviewed-by: Venky Shankar <[email protected]>
2 parents a6174b7 + 074f05a commit 1275f1a

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

qa/tasks/cephfs/test_snap_schedules.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,30 @@ def test_snap_schedule_for_number_of_snaps_retention(self):
545545

546546
self.mount_a.run_shell(['rmdir', test_dir[1:]])
547547

548+
def test_failure_for_duplicate_retention(self):
549+
"""
550+
Test that adding retention for same spec fails for second time.
551+
"""
552+
test_dir = '/' + TestSnapSchedules.TEST_DIRECTORY
553+
554+
self.mount_a.run_shell(['mkdir', '-p', test_dir[1:]])
555+
556+
self.fs_snap_schedule_cmd('add', path=test_dir, snap_schedule='1m')
557+
self.fs_snap_schedule_cmd('retention', 'add', path=test_dir,
558+
retention_spec_or_period='m',
559+
retention_count='50')
560+
561+
# Adding a duplicate retention spec should fail
562+
with self.assertRaises(CommandFailedError):
563+
self.fs_snap_schedule_cmd('retention', 'add', path=test_dir,
564+
retention_spec_or_period='m',
565+
retention_count='50')
566+
567+
# remove snapshot schedule
568+
self.fs_snap_schedule_cmd('remove', path=test_dir)
569+
570+
self.mount_a.run_shell(['rmdir', test_dir[1:]])
571+
548572
def test_snap_schedule_all_periods(self):
549573
test_dir = TestSnapSchedulesSnapdir.TEST_DIRECTORY + "/minutes"
550574
self.mount_a.run_shell(['mkdir', '-p', test_dir])

src/pybind/mgr/snap_schedule/fs/schedule.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,9 @@ def add_retention(cls,
364364
current_retention = json.loads(current)
365365
for r, v in retention.items():
366366
if r in current_retention:
367-
msg = (f'Retention for {r} is already present with value'
368-
f'{current_retention[r]}. Please remove first')
369-
raise ValueError(msg)
367+
msg = (f'Retention for {r} is already present with value '
368+
f'{current_retention[r]}. Please remove it first.')
369+
raise FileExistsError(msg)
370370
current_retention.update(retention)
371371
db.execute(cls.UPDATE_RETENTION,
372372
(json.dumps(current_retention), path))

0 commit comments

Comments
 (0)