Skip to content

Commit 80e1207

Browse files
committed
mgr/dashboard: fix retention add for subvolume
- Added parameters for subvolume and subvolume group when adding a new snap schedule. - Added call to remove retention policies when removing a snap schedule in case it is the last one with same path Fixes: https://tracker.ceph.com/issues/64524 Signed-off-by: Ivo Almeida <[email protected]>
1 parent 90760c8 commit 80e1207

File tree

5 files changed

+69
-7
lines changed

5 files changed

+69
-7
lines changed

src/pybind/mgr/dashboard/controllers/cephfs.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,9 @@ def create(self, fs: str, path: str, snap_schedule: str, start: str, retention_p
10291029
path,
10301030
retention_spec_or_period,
10311031
retention_count,
1032-
fs)
1032+
fs,
1033+
subvol,
1034+
group)
10331035
if error_code_retention != 0:
10341036
raise DashboardException(
10351037
f'Failed to add retention policy for path {path}: {err_retention}'
@@ -1071,7 +1073,36 @@ def editRetentionPolicies(method, retention_policy):
10711073

10721074
@RESTController.Resource('DELETE')
10731075
def delete_snapshot(self, fs: str, path: str, schedule: str, start: str,
1074-
subvol=None, group=None):
1076+
retention_policy=None, subvol=None, group=None):
1077+
if retention_policy:
1078+
# check if there are other snap schedules for this exact same path
1079+
error_code, out, err = mgr.remote('snap_schedule', 'snap_schedule_list',
1080+
path, False, fs, subvol, group, 'plain')
1081+
1082+
if error_code != 0:
1083+
raise DashboardException(
1084+
f'Failed to get snapshot schedule list for path {path}: {err}'
1085+
)
1086+
# only remove the retention policies if there no other snap schedules for this path
1087+
snapshot_schedule_list = out.split('\n')
1088+
if len(snapshot_schedule_list) <= 1:
1089+
retention_policies = retention_policy.split('|')
1090+
for retention in retention_policies:
1091+
retention_count = retention.split('-')[0]
1092+
retention_spec_or_period = retention.split('-')[1]
1093+
error_code, _, err = mgr.remote('snap_schedule',
1094+
'snap_schedule_retention_rm',
1095+
path,
1096+
retention_spec_or_period,
1097+
retention_count,
1098+
fs,
1099+
subvol,
1100+
group)
1101+
if error_code != 0:
1102+
raise DashboardException(
1103+
f'Failed to remove retention policy for path {path}: {err}'
1104+
)
1105+
# remove snap schedule
10751106
error_code, _, err = mgr.remote('snap_schedule',
10761107
'snap_schedule_rm',
10771108
path,

src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-snapshotschedule-form/cephfs-snapshotschedule-form.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ export class CephfsSnapshotscheduleFormComponent extends CdForm implements OnIni
389389
frm.get('directory').value,
390390
this.fsName,
391391
retentionList,
392-
this.retentionPoliciesToRemove?.map?.((rp) => rp.retentionFrequency) || []
392+
this.retentionPoliciesToRemove?.map?.((rp) => rp.retentionFrequency) || [],
393+
!!this.subvolume
393394
)
394395
.pipe(
395396
map(({ exists, errorIndex }) => {

src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-snapshotschedule-list/cephfs-snapshotschedule-list.component.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,17 @@ export class CephfsSnapshotscheduleListComponent
291291
}
292292

293293
deleteSnapshotSchedule() {
294-
const { path, start, fs, schedule, subvol, group } = this.selection.first();
294+
const { path, start, fs, schedule, subvol, group, retention } = this.selection.first();
295+
const retentionPolicy = retention
296+
?.split(/\s/gi)
297+
?.filter((r: string) => !!r)
298+
?.map((r: string) => {
299+
const frequency = r.substring(r.length - 1);
300+
const interval = r.substring(0, r.length - 1);
301+
return `${interval}-${frequency}`;
302+
})
303+
?.join('|')
304+
?.toLocaleLowerCase();
295305

296306
this.modalRef = this.modalService.show(CriticalConfirmationModalComponent, {
297307
itemDescription: $localize`snapshot schedule`,
@@ -305,6 +315,7 @@ export class CephfsSnapshotscheduleListComponent
305315
schedule,
306316
start,
307317
fs,
318+
retentionPolicy,
308319
subvol,
309320
group
310321
})

src/pybind/mgr/dashboard/frontend/src/app/shared/api/cephfs-snapshot-schedule.service.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,21 @@ export class CephfsSnapshotScheduleService {
4848
);
4949
}
5050

51-
delete({ fs, path, schedule, start, subvol, group }: Record<string, any>): Observable<any> {
51+
delete({
52+
fs,
53+
path,
54+
schedule,
55+
start,
56+
retentionPolicy,
57+
subvol,
58+
group
59+
}: Record<string, any>): Observable<any> {
5260
let deleteUrl = `${this.baseURL}/snapshot/schedule/${fs}/${encodeURIComponent(
5361
path
5462
)}/delete_snapshot?schedule=${schedule}&start=${encodeURIComponent(start)}`;
63+
if (retentionPolicy) {
64+
deleteUrl += `&retention_policy=${retentionPolicy}`;
65+
}
5566
if (subvol && group) {
5667
deleteUrl += `&subvol=${encodeURIComponent(subvol)}&group=${encodeURIComponent(group)}`;
5768
}
@@ -81,13 +92,16 @@ export class CephfsSnapshotScheduleService {
8192
path: string,
8293
fs: string,
8394
retentionFrequencies: string[],
84-
retentionFrequenciesRemoved: string[] = []
95+
retentionFrequenciesRemoved: string[] = [],
96+
isSubvolume = false
8597
): Observable<{ exists: boolean; errorIndex: number }> {
8698
return this.getSnapshotSchedule(path, fs, false).pipe(
8799
map((response) => {
88100
let errorIndex = -1;
89101
let exists = false;
90-
const index = response.findIndex((x) => x.path === path);
102+
const index = response.findIndex((x) =>
103+
isSubvolume ? x.path.startsWith(path) : x.path === path
104+
);
91105
const result = retentionFrequencies?.length
92106
? intersection(
93107
Object.keys(response?.[index]?.retention).filter(

src/pybind/mgr/dashboard/openapi.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,6 +2081,11 @@ paths:
20812081
required: true
20822082
schema:
20832083
type: string
2084+
- allowEmptyValue: true
2085+
in: query
2086+
name: retention_policy
2087+
schema:
2088+
type: string
20842089
- allowEmptyValue: true
20852090
in: query
20862091
name: subvol

0 commit comments

Comments
 (0)