]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: fix columns in host table with NaN Undefined 46446/head
authorAvan Thakkar <athakkar@redhat.com>
Mon, 31 Jan 2022 13:53:10 +0000 (19:23 +0530)
committerErnesto Puerta <epuertat@redhat.com>
Tue, 31 May 2022 12:44:37 +0000 (14:44 +0200)
Fixes: https://tracker.ceph.com/issues/54068
Signed-off-by: Avan Thakkar <athakkar@redhat.com>
(cherry picked from commit 41ca50c81c26107cac50823a7803c0d018933734)

src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/empty.pipe.ts

index b99a485b4edf653e7189b8ae2158ea5010b841f7..f91a8ff83768054d4fda068d8f71c212024a952d 100644 (file)
@@ -203,6 +203,37 @@ describe('HostsComponent', () => {
     expect(spans[7].textContent).toBe('N/A');
   });
 
+  it('should test if memory/raw capacity columns shows N/A if facts are available but in fetching state', () => {
+    const features = [OrchestratorFeature.HOST_FACTS];
+    let hostPayload: any[];
+    hostPayload = [
+      {
+        hostname: 'host_test',
+        services: [
+          {
+            type: 'osd',
+            id: '0'
+          }
+        ],
+        cpu_count: 2,
+        cpu_cores: 1,
+        memory_total_kb: undefined,
+        hdd_count: 4,
+        hdd_capacity_bytes: undefined,
+        flash_count: 4,
+        flash_capacity_bytes: undefined,
+        nic_count: 1
+      }
+    ];
+    OrchestratorHelper.mockStatus(true, features);
+    hostListSpy.and.callFake(() => of(hostPayload));
+    fixture.detectChanges();
+
+    component.getHosts(new CdTableFetchDataContext(() => undefined));
+    expect(component.hosts[0]['memory_total_bytes']).toEqual('N/A');
+    expect(component.hosts[0]['raw_capacity']).toEqual('N/A');
+  });
+
   it('should show force maintenance modal when it is safe to stop host', () => {
     const errorMsg = `WARNING: Stopping 1 out of 1 daemons in Grafana service.
                     Service will not be operational with no daemons left. At
index 71e7d92350f6a7ea2129acbffebc1dc331c74aa2..f7df997c37b0d04a77acd01a4207463b7b6557e2 100644 (file)
@@ -27,6 +27,7 @@ import { OrchestratorFeature } from '~/app/shared/models/orchestrator.enum';
 import { OrchestratorStatus } from '~/app/shared/models/orchestrator.interface';
 import { Permissions } from '~/app/shared/models/permissions';
 import { DimlessBinaryPipe } from '~/app/shared/pipes/dimless-binary.pipe';
+import { EmptyPipe } from '~/app/shared/pipes/empty.pipe';
 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
 import { ModalService } from '~/app/shared/services/modal.service';
 import { NotificationService } from '~/app/shared/services/notification.service';
@@ -109,6 +110,7 @@ export class HostsComponent extends ListWithDetails implements OnDestroy, OnInit
   constructor(
     private authStorageService: AuthStorageService,
     private dimlessBinary: DimlessBinaryPipe,
+    private emptyPipe: EmptyPipe,
     private hostService: HostService,
     private actionLabels: ActionLabelsI18n,
     private modalService: ModalService,
@@ -464,8 +466,10 @@ export class HostsComponent extends ListWithDetails implements OnDestroy, OnInit
   transformHostsData() {
     if (this.checkHostsFactsAvailable()) {
       _.forEach(this.hosts, (hostKey) => {
-        hostKey['memory_total_bytes'] = hostKey['memory_total_kb'] * 1024;
-        hostKey['raw_capacity'] = hostKey['hdd_capacity_bytes'] + hostKey['flash_capacity_bytes'];
+        hostKey['memory_total_bytes'] = this.emptyPipe.transform(hostKey['memory_total_kb'] * 1024);
+        hostKey['raw_capacity'] = this.emptyPipe.transform(
+          hostKey['hdd_capacity_bytes'] + hostKey['flash_capacity_bytes']
+        );
       });
     } else {
       // mark host facts columns unavailable
index fb753e8d9ac48e3c66cffdc11dad185738359c44..2b4df2e3c4fc8b88543bd07613da9c98595a5635 100644 (file)
@@ -7,6 +7,11 @@ import _ from 'lodash';
 })
 export class EmptyPipe implements PipeTransform {
   transform(value: any): any {
-    return _.isUndefined(value) || _.isNull(value) ? '-' : value;
+    if (_.isUndefined(value) || _.isNull(value)) {
+      return '-';
+    } else if (_.isNaN(value)) {
+      return 'N/A';
+    }
+    return value;
   }
 }