]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: fix snapshot creation with duplicate name
authorAashish Sharma <aasharma@redhat.com>
Mon, 5 Sep 2022 11:59:11 +0000 (17:29 +0530)
committerAashish Sharma <aasharma@redhat.com>
Thu, 15 Sep 2022 06:54:30 +0000 (12:24 +0530)
Snapshot creation with same name on UI throwing 500 Internal Error, This PR intends to fix this issue.

Resolves rhbz#2111650
Fixes: https://tracker.ceph.com/issues/57456
Signed-off-by: Aashish Sharma <aasharma@redhat.com>
(cherry picked from commit 2ae1bca1d9c7a771be0fa9481bef2622ffd7cc45)
(cherry picked from commit 1d5e72d4006ca424ba3047382656e967c91ba734)

src/pybind/mgr/dashboard/controllers/cephfs.py
src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-directories/cephfs-directories.component.ts

index 5da79e35b48e1e75df2aae71992c24e59d920551..3eb7e37e4e32c0c08d4f27cfd3d614dd174b8960 100644 (file)
@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
+import logging
 import os
 from collections import defaultdict
 
@@ -19,6 +20,8 @@ GET_QUOTAS_SCHEMA = {
     'max_files': (int, '')
 }
 
+logger = logging.getLogger("controllers.rgw")
+
 
 @APIRouter('/cephfs', Scope.CEPHFS)
 @APIDoc("Cephfs Management API", "Cephfs")
@@ -467,6 +470,14 @@ class CephFS(RESTController):
         :rtype: str
         """
         cfs = self._cephfs_instance(fs_id)
+        list_snaps = cfs.ls_snapshots(path)
+        for snap in list_snaps:
+            if name == snap['name']:
+                raise DashboardException(code='Snapshot name already in use',
+                                         msg='Snapshot name {} is already in use.'
+                                         'Please use another name'.format(name),
+                                         component='cephfs')
+
         return cfs.mk_snapshot(path, name)
 
     @RESTController.Resource('DELETE', path='/snapshot')
index c2528f7c4511ed1f6980da5fc64b43a81a3863a8..4ae8a159a0559111fa49c1f3164772733f58cfcd 100644 (file)
@@ -1,5 +1,5 @@
 import { Component, Input, OnChanges, OnInit, TemplateRef, ViewChild } from '@angular/core';
-import { Validators } from '@angular/forms';
+import { AbstractControl, Validators } from '@angular/forms';
 
 import {
   ITreeOptions,
@@ -103,6 +103,7 @@ export class CephfsDirectoriesComponent implements OnInit, OnChanges {
     updateSelection: Function;
   };
   nodes: any[];
+  alreadyExists: boolean;
 
   constructor(
     private authStorageService: AuthStorageService,
@@ -546,22 +547,34 @@ export class CephfsDirectoriesComponent implements OnInit, OnChanges {
           type: 'text',
           name: 'name',
           value: `${moment().toISOString(true)}`,
-          required: true
+          required: true,
+          validators: [this.validateValue.bind(this)]
         }
       ],
       submitButtonText: $localize`Create Snapshot`,
       onSubmit: (values: CephfsSnapshot) => {
-        this.cephfsService.mkSnapshot(this.id, path, values.name).subscribe((name) => {
+        if (!this.alreadyExists) {
+          this.cephfsService.mkSnapshot(this.id, path, values.name).subscribe((name) => {
+            this.notificationService.show(
+              NotificationType.success,
+              $localize`Created snapshot '${name}' for '${path}'`
+            );
+            this.forceDirRefresh();
+          });
+        } else {
           this.notificationService.show(
-            NotificationType.success,
-            $localize`Created snapshot '${name}' for '${path}'`
+            NotificationType.error,
+            $localize`Snapshot name '${values.name}' is already in use. Please use another name.`
           );
-          this.forceDirRefresh();
-        });
+        }
       }
     });
   }
 
+  validateValue(control: AbstractControl) {
+    this.alreadyExists = this.selectedDir.snapshots.some((s) => s.name === control.value);
+  }
+
   /**
    * Forces an update of the current selected directory
    *