]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: fix image size in nvmeof namespace create/update api
authorAfreen Misbah <afreen@ibm.com>
Fri, 7 Feb 2025 11:43:51 +0000 (17:13 +0530)
committerNizamudeen A <nia@redhat.com>
Tue, 4 Mar 2025 07:49:47 +0000 (13:19 +0530)
- Different name is used in POST and PATCH for `rbd_image_size`
- Using same name in both requests
- fixing typing issues in frontend

Fixes https://tracker.ceph.com/issues/69864

Signed-off-by: Afreen Misbah <afreen@ibm.com>
(cherry picked from commit 7fa78e62a456bd706dafd6fd30568dfd88acf3b4)

 Conflicts:
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/nvmeof-namespaces-form/nvmeof-namespaces-form.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/nvmeof.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/nvmeof.service.ts
        - restore it to the request type where groups is not present

src/pybind/mgr/dashboard/controllers/nvmeof.py
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/nvmeof-namespaces-form/nvmeof-namespaces-form.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/nvmeof-namespaces-form/nvmeof-namespaces-form.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/nvmeof.service.ts
src/pybind/mgr/dashboard/openapi.yaml

index f199867943d14c9a7e4c1d027839867cd7e4dae9..182cdf10e3288047cd59470cc6066d097f9f501f 100644 (file)
@@ -251,7 +251,7 @@ else:
                 "rbd_pool": Param(str, "RBD pool name"),
                 "rbd_image_name": Param(str, "RBD image name"),
                 "create_image": Param(bool, "Create RBD image"),
-                "size": Param(int, "RBD image size"),
+                "rbd_image_size": Param(int, "RBD image size"),
                 "block_size": Param(int, "NVMeoF namespace block size"),
                 "load_balancing_group": Param(int, "Load balancing group"),
                 "gw_group": Param(str, "NVMeoF gateway group", True, None),
@@ -265,7 +265,7 @@ else:
             rbd_image_name: str,
             rbd_pool: str = "rbd",
             create_image: Optional[bool] = True,
-            size: Optional[int] = 1024,
+            rbd_image_size: Optional[int] = 1024,
             block_size: int = 512,
             load_balancing_group: Optional[int] = None,
             gw_group: Optional[str] = None,
@@ -277,7 +277,7 @@ else:
                     rbd_pool_name=rbd_pool,
                     block_size=block_size,
                     create_image=create_image,
-                    size=size,
+                    size=rbd_image_size,
                     anagrpid=load_balancing_group,
                 )
             )
index b6d0c27a70c3712a6e93723798c06382c1fc45a0..1cb2b0167069a1f5f72b1b24b73ab20504c7edf9 100644 (file)
@@ -63,7 +63,7 @@ describe('NvmeofNamespacesFormComponent', () => {
       expect(nvmeofService.createNamespace).toHaveBeenCalledWith(mockSubsystemNQN, {
         rbd_image_name: image,
         rbd_pool: null,
-        size: 1073741824
+        rbd_image_size: 1073741824
       });
     });
 
index f5721e11ab6d3e27b3880200803af7de059afc72..9181f8bdffef150a0783384a06466e65ba7ebc5f 100644 (file)
@@ -4,7 +4,7 @@ import { ActivatedRoute, Router } from '@angular/router';
 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
 import {
   NamespaceCreateRequest,
-  NamespaceEditRequest,
+  NamespaceUpdateRequest,
   NvmeofService
 } from '~/app/shared/api/nvmeof.service';
 import { ActionLabelsI18n, URLVerbs } from '~/app/shared/constants/app.constants';
@@ -116,22 +116,39 @@ export class NvmeofNamespacesFormComponent implements OnInit {
     });
   }
 
-  buildRequest(): NamespaceCreateRequest | NamespaceEditRequest {
+  updateRequest(rbdImageSize: number): NamespaceUpdateRequest {
+    const request: NamespaceUpdateRequest = {
+      rbd_image_size: rbdImageSize
+    };
+    return request;
+  }
+
+  createRequest(rbdImageSize: number): NamespaceCreateRequest {
+    const image = this.nsForm.getValue('image');
+    const pool = this.nsForm.getValue('pool');
+    const request: NamespaceCreateRequest = {
+      rbd_image_name: image,
+      rbd_pool: pool
+    };
+    if (rbdImageSize) {
+      request['rbd_image_size'] = rbdImageSize;
+    }
+    return request;
+  }
+
+  buildRequest() {
     const image_size = this.nsForm.getValue('image_size');
-    const image_size_unit = this.nsForm.getValue('unit');
-    const request = {} as NamespaceCreateRequest | NamespaceEditRequest;
+    let rbdImageSize: number = null;
     if (image_size) {
-      const key: string = this.edit ? 'rbd_image_size' : 'size';
+      const image_size_unit = this.nsForm.getValue('unit');
       const value: number = this.formatterService.toBytes(image_size + image_size_unit);
-      request[key] = value;
+      rbdImageSize = value;
     }
-    if (!this.edit) {
-      const image = this.nsForm.getValue('image');
-      const pool = this.nsForm.getValue('pool');
-      request['rbd_image_name'] = image;
-      request['rbd_pool'] = pool;
+    if (this.edit) {
+      return this.updateRequest(rbdImageSize);
+    } else {
+      return this.createRequest(rbdImageSize);
     }
-    return request;
   }
 
   validateSize() {
@@ -152,7 +169,7 @@ export class NvmeofNamespacesFormComponent implements OnInit {
       this.invalidSizeError = false;
       const component = this;
       const taskUrl: string = `nvmeof/namespace/${this.edit ? URLVerbs.EDIT : URLVerbs.CREATE}`;
-      const request = this.buildRequest();
+      const request: NamespaceCreateRequest | NamespaceUpdateRequest = this.buildRequest();
       let action: Observable<any>;
 
       if (this.edit) {
@@ -164,7 +181,7 @@ export class NvmeofNamespacesFormComponent implements OnInit {
           call: this.nvmeofService.updateNamespace(
             this.subsystemNQN,
             this.nsid,
-            request as NamespaceEditRequest
+            request as NamespaceUpdateRequest
           )
         });
       } else {
index 7c72530e84a288ff7c3cbabd2445d7b031512c63..a4a98f29441246142f17ee8b2bb16a985758119a 100644 (file)
@@ -16,10 +16,10 @@ export interface ListenerRequest {
 export interface NamespaceCreateRequest {
   rbd_image_name: string;
   rbd_pool: string;
-  size: number;
+  rbd_image_size?: number;
 }
 
-export interface NamespaceEditRequest {
+export interface NamespaceUpdateRequest {
   rbd_image_size: number;
 }
 
@@ -125,7 +125,7 @@ export class NvmeofService {
     });
   }
 
-  updateNamespace(subsystemNQN: string, nsid: string, request: NamespaceEditRequest) {
+  updateNamespace(subsystemNQN: string, nsid: string, request: NamespaceUpdateRequest) {
     return this.http.patch(`${API_PATH}/subsystem/${subsystemNQN}/namespace/${nsid}`, request, {
       observe: 'response'
     });
index e6a577e8d3b0a36f553cb3d129f5918de57cd9ea..a24d3cdd75a23c8891a5e40974124531be2e9910 100644 (file)
@@ -8419,14 +8419,14 @@ paths:
                 rbd_image_name:
                   description: RBD image name
                   type: string
+                rbd_image_size:
+                  default: 1024
+                  description: RBD image size
+                  type: integer
                 rbd_pool:
                   default: rbd
                   description: RBD pool name
                   type: string
-                size:
-                  default: 1024
-                  description: RBD image size
-                  type: integer
               required:
               - rbd_image_name
               type: object