From: Afreen Misbah Date: Fri, 7 Feb 2025 11:43:51 +0000 (+0530) Subject: mgr/dashboard: fix image size in nvmeof namespace create/update api X-Git-Tag: testing/wip-pdonnell-testing-20250305.192429-squid-debug~4^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=1521b82cf97ac40da5c01c98d573be8c5168ee21;p=ceph-ci.git mgr/dashboard: fix image size in nvmeof namespace create/update api - 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 (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 --- diff --git a/src/pybind/mgr/dashboard/controllers/nvmeof.py b/src/pybind/mgr/dashboard/controllers/nvmeof.py index f199867943d..182cdf10e32 100644 --- a/src/pybind/mgr/dashboard/controllers/nvmeof.py +++ b/src/pybind/mgr/dashboard/controllers/nvmeof.py @@ -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, ) ) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/nvmeof-namespaces-form/nvmeof-namespaces-form.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/nvmeof-namespaces-form/nvmeof-namespaces-form.component.spec.ts index b6d0c27a70c..1cb2b016706 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/nvmeof-namespaces-form/nvmeof-namespaces-form.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/nvmeof-namespaces-form/nvmeof-namespaces-form.component.spec.ts @@ -63,7 +63,7 @@ describe('NvmeofNamespacesFormComponent', () => { expect(nvmeofService.createNamespace).toHaveBeenCalledWith(mockSubsystemNQN, { rbd_image_name: image, rbd_pool: null, - size: 1073741824 + rbd_image_size: 1073741824 }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/nvmeof-namespaces-form/nvmeof-namespaces-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/nvmeof-namespaces-form/nvmeof-namespaces-form.component.ts index f5721e11ab6..9181f8bdffe 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/nvmeof-namespaces-form/nvmeof-namespaces-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/nvmeof-namespaces-form/nvmeof-namespaces-form.component.ts @@ -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; 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 { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/nvmeof.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/nvmeof.service.ts index 7c72530e84a..a4a98f29441 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/nvmeof.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/nvmeof.service.ts @@ -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' }); diff --git a/src/pybind/mgr/dashboard/openapi.yaml b/src/pybind/mgr/dashboard/openapi.yaml index e6a577e8d3b..a24d3cdd75a 100644 --- a/src/pybind/mgr/dashboard/openapi.yaml +++ b/src/pybind/mgr/dashboard/openapi.yaml @@ -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