]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Predfine labels in create host form 44077/head
authorNizamudeen A <nia@redhat.com>
Thu, 18 Nov 2021 11:09:30 +0000 (16:39 +0530)
committerNizamudeen A <nia@redhat.com>
Tue, 23 Nov 2021 19:07:37 +0000 (00:37 +0530)
Also retains the previously created labels by user in the form

Fixes: https://tracker.ceph.com/issues/53315
Signed-off-by: Nizamudeen A <nia@redhat.com>
(cherry picked from commit e228bf7563a13cc9f0f49a086c5df391c74002b1)

src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/hosts.po.ts
src/pybind/mgr/dashboard/frontend/cypress/integration/orchestrator/workflow/02-create-cluster-add-host.e2e-spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/host-form/host-form.component.html
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/host-form/host-form.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/host.service.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/components/select/select.component.html

index c615b945a5d6a61136c5f15d10cc87780069c745..86ea0ffbac01b1778e4fee26d63c969352151f29 100644 (file)
@@ -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) => {
index 8ea195f89e7aa1f31b1e40b526387e2529ad8c90..33f0922209839b30d689379ce27a6ba77a08da7e 100644 (file)
@@ -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', () => {
index 5b76273030abbdcda68fa44933d8a97c0ac72563..66fe42f7fa845d11759751ee0368a9cd45c79269 100644 (file)
@@ -72,6 +72,7 @@
             <div class="cd-col-form-input">
               <cd-select-badges id="labels"
                                 [data]="hostForm.controls.labels.value"
+                                [options]="labelsOption"
                                 [customBadges]="true"
                                 [messages]="messages">
               </cd-select-badges>
index 6e84da688e581dedb2ea18e049e037ea6696cc06..a36f1fbacaff3bde9de3164fea341d82f690dbbd 100644 (file)
@@ -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<SelectOption> = [];
 
   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
index 920e5f35c7bdbf4b840e39ebd47974160b800fdd..9b5408a4a88151a6714b57257ed5fe760d987fdd 100644 (file)
@@ -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, {
index 2a7c580653c34e62604d717df2bdcbb43e019d4c..f7294f36d21a991afee196803af64decac009462 100644 (file)
@@ -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();
   }
index 190944311bed978827b41cf838c9e9d6143dfc84..1533b94395eb457a3c112e1335642487585d1202 100644 (file)
@@ -63,6 +63,7 @@
 <a class="select-menu-edit float-left"
    [ngClass]="elemClass"
    [ngbPopover]="popTemplate"
+   data-testid="select-menu-edit"
    *ngIf="customBadges || options.length > 0">
   <ng-content></ng-content>
 </a>