From: Nizamudeen A Date: Thu, 18 Nov 2021 11:09:30 +0000 (+0530) Subject: mgr/dashboard: Predfine labels in create host form X-Git-Tag: v17.1.0~382^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=e228bf7563a13cc9f0f49a086c5df391c74002b1;p=ceph-ci.git mgr/dashboard: Predfine labels in create host form Also retains the previously created labels by user in the form Fixes: https://tracker.ceph.com/issues/53315 Signed-off-by: Nizamudeen A --- diff --git a/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/hosts.po.ts b/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/hosts.po.ts index c615b945a5d..86ea0ffbac0 100644 --- a/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/hosts.po.ts +++ b/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/hosts.po.ts @@ -41,7 +41,7 @@ export class HostsPageHelper extends PageHelper { }); } - add(hostname: string, exist?: boolean, maintenance?: boolean) { + add(hostname: string, exist?: boolean, maintenance?: boolean, labels: string[] = []) { cy.get(`${this.pages.add.id}`).within(() => { cy.get('#hostname').type(hostname); if (maintenance) { @@ -50,12 +50,24 @@ export class HostsPageHelper extends PageHelper { if (exist) { cy.get('#hostname').should('have.class', 'ng-invalid'); } - cy.get('cd-submit-button').click(); }); + + if (labels.length) { + this.selectPredefinedLabels(labels); + } + + cy.get('cd-submit-button').click(); // back to host list cy.get(`${this.pages.index.id}`); } + selectPredefinedLabels(labels: string[]) { + cy.get('a[data-testid=select-menu-edit]').click(); + for (const label of labels) { + cy.get('.popover-body div.select-menu-item-content').contains(label).click(); + } + } + checkExist(hostname: string, exist: boolean) { this.clearTableSearchInput(); this.getTableCell(this.columnIndex.hostname, hostname).should(($elements) => { diff --git a/src/pybind/mgr/dashboard/frontend/cypress/integration/orchestrator/workflow/02-create-cluster-add-host.e2e-spec.ts b/src/pybind/mgr/dashboard/frontend/cypress/integration/orchestrator/workflow/02-create-cluster-add-host.e2e-spec.ts index 8ea195f89e7..33f09222098 100644 --- a/src/pybind/mgr/dashboard/frontend/cypress/integration/orchestrator/workflow/02-create-cluster-add-host.e2e-spec.ts +++ b/src/pybind/mgr/dashboard/frontend/cypress/integration/orchestrator/workflow/02-create-cluster-add-host.e2e-spec.ts @@ -12,9 +12,9 @@ describe('Create cluster add host page', () => { 'ceph-node-02.cephlab.com', 'ceph-node-[01-02].cephlab.com' ]; - const addHost = (hostname: string, exist?: boolean, pattern?: boolean) => { + const addHost = (hostname: string, exist?: boolean, pattern?: boolean, labels: string[] = []) => { cy.get('.btn.btn-accent').first().click({ force: true }); - createClusterHostPage.add(hostname, exist, false); + createClusterHostPage.add(hostname, exist, false, labels); if (!pattern) { createClusterHostPage.checkExist(hostname, true); } @@ -43,9 +43,14 @@ describe('Create cluster add host page', () => { addHost(hostnames[3], false, true); }); - it('should delete a host and add it back', () => { + it('should delete a host', () => { createClusterHostPage.delete(hostnames[1]); - addHost(hostnames[1], false); + }); + + it('should add a host with some predefined labels and verify it', () => { + const labels = ['mon', 'mgr', 'rgw', 'osd']; + addHost(hostnames[1], false, false, labels); + createClusterHostPage.checkLabelExists(hostnames[1], labels, true); }); it('should verify "_no_schedule" label is added', () => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/host-form/host-form.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/host-form/host-form.component.html index 5b76273030a..66fe42f7fa8 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/host-form/host-form.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/host-form/host-form.component.html @@ -72,6 +72,7 @@
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/host-form/host-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/host-form/host-form.component.ts index 6e84da688e5..a36f1fbacaf 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/host-form/host-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/host-form/host-form.component.ts @@ -7,6 +7,7 @@ import expand from 'brace-expansion'; import { HostService } from '~/app/shared/api/host.service'; import { SelectMessages } from '~/app/shared/components/select/select-messages.model'; +import { SelectOption } from '~/app/shared/components/select/select-option.model'; import { ActionLabelsI18n, URLVerbs } from '~/app/shared/constants/app.constants'; import { CdForm } from '~/app/shared/forms/cd-form'; import { CdFormGroup } from '~/app/shared/forms/cd-form-group'; @@ -30,6 +31,7 @@ export class HostFormComponent extends CdForm implements OnInit { allLabels: string[]; pageURL: string; hostPattern = false; + labelsOption: Array = []; messages = new SelectMessages({ empty: $localize`There are no labels.`, @@ -60,6 +62,13 @@ export class HostFormComponent extends CdForm implements OnInit { }); this.loadingReady(); }); + + this.hostService.getLabels().subscribe((resp: string[]) => { + const uniqueLabels = new Set(resp.concat(this.hostService.predefinedLabels)); + this.labelsOption = Array.from(uniqueLabels).map((label) => { + return { enabled: true, name: label, selected: false, description: null }; + }); + }); } // check if hostname is a single value or pattern to hide network address field diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts index 920e5f35c7b..9b5408a4a88 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts @@ -263,7 +263,8 @@ export class HostsComponent extends ListWithDetails implements OnDestroy, OnInit editAction() { this.hostService.getLabels().subscribe((resp: string[]) => { const host = this.selection.first(); - const allLabels = resp.map((label) => { + const labels = new Set(resp.concat(this.hostService.predefinedLabels)); + const allLabels = Array.from(labels).map((label) => { return { enabled: true, name: label }; }); this.modalService.show(FormModalComponent, { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/host.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/host.service.ts index 2a7c580653c..f7294f36d21 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/host.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/host.service.ts @@ -21,6 +21,8 @@ export class HostService extends ApiClient { baseURL = 'api/host'; baseUIURL = 'ui-api/host'; + predefinedLabels = ['mon', 'mgr', 'osd', 'mds', 'rgw', 'nfs', 'iscsi', 'rbd', 'grafana']; + constructor(private http: HttpClient, private deviceService: DeviceService) { super(); } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/select/select.component.html b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/select/select.component.html index 190944311be..1533b94395e 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/select/select.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/select/select.component.html @@ -63,6 +63,7 @@