]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: fix linting errors and add test 46220/head
authorAashish Sharma <aasharma@redhat.com>
Fri, 8 Apr 2022 05:19:04 +0000 (10:49 +0530)
committerAvan Thakkar <athakkar@redhat.com>
Tue, 10 May 2022 16:40:08 +0000 (22:10 +0530)
Fixes: https://tracker.ceph.com/issues/55218
Signed-off-by: Aashish Sharma <aasharma@redhat.com>
(cherry picked from commit b496f5837803a915daac98b0fad56eac3174db85)

 Conflicts:
src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/services.po.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-daemon-list/service-daemon-list.component.html
     - Neglecting e2e changes as they aren't adopted fully to master yet- no regression. Adopting daemon-list html with master.

src/cephadm/cephadm
src/cephadm/tests/test_cephadm.py
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-daemon-list/service-daemon-list.component.html
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-daemon-list/service-daemon-list.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-daemon-list/service-daemon-list.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/components/usage-bar/usage-bar.component.html
src/pybind/mgr/dashboard/frontend/src/app/shared/components/usage-bar/usage-bar.component.ts

index e1d639614845ef8ab8ea16a4ec6bc8622300b7a1..7b8ea349aa393be4f1337eb79521e43177ba287f 100755 (executable)
@@ -6186,16 +6186,16 @@ def list_daemons(ctx, detail=True, legacy_dir=None):
     # keep track of image digests
     seen_digests = {}   # type: Dict[str, List[str]]
 
-    # keep track of memory usage we've seen
+    # keep track of memory and cpu usage we've seen
     seen_memusage = {}  # type: Dict[str, int]
-    seen_cpuperc = {}  # type: Dict[str, int]
+    seen_cpuperc = {}  # type: Dict[str, str]
     out, err, code = call(
         ctx,
         [container_path, 'stats', '--format', '{{.ID}},{{.MemUsage}}', '--no-stream'],
         verbosity=CallVerbosity.DEBUG
     )
     seen_memusage_cid_len, seen_memusage = _parse_mem_usage(code, out)
-    
+
     out, err, code = call(
         ctx,
         [container_path, 'stats', '--format', '{{.ID}},{{.CPUPerc}}', '--no-stream'],
@@ -6382,11 +6382,8 @@ def list_daemons(ctx, detail=True, legacy_dir=None):
                             os.path.join(data_dir, fsid, j, 'unit.image'))
                         val['configured'] = get_file_timestamp(
                             os.path.join(data_dir, fsid, j, 'unit.configured'))
-                        
-                    logger.info("helo %s", val)
                     ls.append(val)
 
-    logger.info("waah %s", ls)
     return ls
 
 
@@ -6407,7 +6404,8 @@ def _parse_mem_usage(code: int, out: str) -> Tuple[int, Dict[str, int]]:
                 pass
     return seen_memusage_cid_len, seen_memusage
 
-def _parse_cpu_perc(code: int, out: str):
+
+def _parse_cpu_perc(code: int, out: str) -> Tuple[int, Dict[str, str]]:
     seen_cpuperc = {}
     seen_cpuperc_cid_len = 0
     if not code:
@@ -6422,6 +6420,7 @@ def _parse_cpu_perc(code: int, out: str):
                 pass
     return seen_cpuperc_cid_len, seen_cpuperc
 
+
 def get_daemon_description(ctx, fsid, name, detail=False, legacy_dir=None):
     # type: (CephadmContext, str, str, bool, Optional[str]) -> Dict[str, str]
 
index 9d03bf4496dabca5b81970b7d54ac350a40a62a6..0aa99de8b33b12ab0f8f43a0a25ad1fe46d4a685 100644 (file)
@@ -1013,7 +1013,7 @@ class TestMaintenance:
     @mock.patch('cephadm.call')
     @mock.patch('cephadm.systemd_target_state')
     def test_enter_failure_2(self, _target_state, _call, _listdir):
-        _call.side_effect = [('', '', 0), ('', '', 999)]
+        _call.side_effect = [('', '', 0), ('', '', 999), ('', '', 0), ('', '', 999)]
         _target_state.return_value = True
         ctx: cd.CephadmContext = cd.cephadm_init_ctx(
             ['host-maintenance', 'enter', '--fsid', TestMaintenance.fsid])
@@ -1040,7 +1040,7 @@ class TestMaintenance:
     @mock.patch('cephadm.systemd_target_state')
     @mock.patch('cephadm.target_exists')
     def test_exit_failure_2(self, _target_exists, _target_state, _call, _listdir):
-        _call.side_effect = [('', '', 0), ('', '', 999)]
+        _call.side_effect = [('', '', 0), ('', '', 999), ('', '', 0), ('', '', 999)]
         _target_state.return_value = False
         _target_exists.return_value = True
         ctx: cd.CephadmContext = cd.cephadm_init_ctx(
@@ -2280,4 +2280,4 @@ class TestNetworkValidation:
 
         # invalid IPv6 and valid subnets list
         with pytest.raises(Exception):
-            rc = cd.ip_in_sublets('fe80:2030:31:24', 'fe80::/64')
+            rc = cd.ip_in_sublets('fe80:2030:31:24', 'fe80::/64')
\ No newline at end of file
index 5b631453f8b3d78debf9d2f149192b9ff6c0e3ba..a8a2b742959314ef5d1697acfbd024f02d3a5ff9 100644 (file)
     </li>
   </ul>
   <ng-template #noEventsAvailable>
-    <div *ngIf="events?.length === 0">
+    <div *ngIf="events?.length === 0"
+         class="list-group-item">
       <span>No data available</span>
     </div>
   </ng-template>
 </ng-template>
+
+<ng-template #serviceDaemonDetailsTpl>
+  <cd-table *ngIf="hasOrchestrator"
+            #daemonsTable
+            [data]="daemons"
+            selectionType="single"
+            [columns]="columns"
+            columnMode="flex"
+            identifier="daemon_name"
+            (fetchData)="getDaemons($event)"
+            (updateSelection)="updateSelection($event)">
+    <cd-table-actions id="service-daemon-list-actions"
+                      class="table-actions"
+                      [selection]="selection"
+                      [permission]="permissions.hosts"
+                      [tableActions]="tableActions">
+    </cd-table-actions>
+  </cd-table>
+</ng-template>
+
+<ng-template #cpuTpl
+             let-row="row">
+  <cd-usage-bar [total]="total"
+                [calculatePerc]="false"
+                [used]="row.cpu_percentage"
+                [isBinary]="false"
+                [warningThreshold]="warningThreshold"
+                [errorThreshold]="errorThreshold">
+  </cd-usage-bar>
+</ng-template>
+
index 7e2148c1a261023c584f6eef52e522be3f3979a7..31739a7c2988f26875bfd381d3ed99b787dfc730 100644 (file)
@@ -29,6 +29,8 @@ describe('ServiceDaemonListComponent', () => {
       daemon_type: 'osd',
       daemon_name: 'osd.3',
       version: '15.1.0-1174-g16a11f7',
+      memory_usage: '17.7',
+      cpu_percentage: '3.54%',
       status: 1,
       status_desc: 'running',
       last_refresh: '2020-02-25T04:33:26.465699',
@@ -47,6 +49,8 @@ describe('ServiceDaemonListComponent', () => {
       daemon_type: 'osd',
       daemon_name: 'osd.4',
       version: '15.1.0-1174-g16a11f7',
+      memory_usage: '17.7',
+      cpu_percentage: '3.54%',
       status: 1,
       status_desc: 'running',
       last_refresh: '2020-02-25T04:33:26.465822',
@@ -61,6 +65,8 @@ describe('ServiceDaemonListComponent', () => {
       daemon_type: 'osd',
       daemon_name: 'osd.5',
       version: '15.1.0-1174-g16a11f7',
+      memory_usage: '17.7',
+      cpu_percentage: '3.54%',
       status: 1,
       status_desc: 'running',
       last_refresh: '2020-02-25T04:33:26.465886',
@@ -75,6 +81,8 @@ describe('ServiceDaemonListComponent', () => {
       daemon_name: 'mon.a',
       daemon_type: 'mon',
       version: '15.1.0-1174-g16a11f7',
+      memory_usage: '17.7',
+      cpu_percentage: '3.54%',
       status: 1,
       status_desc: 'running',
       last_refresh: '2020-02-25T04:33:26.465886',
index 1870b14bfb603ebc52e20f6581b046a1bdd83338..93d2a3822aba3631ce225ba77322018978785363 100644 (file)
@@ -21,7 +21,6 @@ import { HostService } from '~/app/shared/api/host.service';
 import { OrchestratorService } from '~/app/shared/api/orchestrator.service';
 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
 import { TableComponent } from '~/app/shared/datatable/table/table.component';
-import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
 import { Icons } from '~/app/shared/enum/icons.enum';
 import { NotificationType } from '~/app/shared/enum/notification-type.enum';
 import { CdTableAction } from '~/app/shared/models/cd-table-action';
@@ -48,6 +47,9 @@ export class ServiceDaemonListComponent implements OnInit, OnChanges, AfterViewI
   @ViewChild('listTpl', { static: true })
   listTpl: TemplateRef<any>;
 
+  @ViewChild('cpuTpl', { static: true })
+  cpuTpl: TemplateRef<any>;
+
   @ViewChildren('daemonsTable')
   daemonsTableTpls: QueryList<TemplateRef<TableComponent>>;
 
@@ -60,6 +62,12 @@ export class ServiceDaemonListComponent implements OnInit, OnChanges, AfterViewI
   @Input()
   flag?: string;
 
+  total = 100;
+
+  warningThreshold = 0.8;
+
+  errorThreshold = 0.9;
+
   icons = Icons;
 
   daemons: Daemon[] = [];
@@ -82,7 +90,7 @@ export class ServiceDaemonListComponent implements OnInit, OnChanges, AfterViewI
     private cephServiceService: CephServiceService,
     private orchService: OrchestratorService,
     private relativeDatePipe: RelativeDatePipe,
-    private dimlessBinaryPipe: DimlessBinaryPipe,
+    private dimlessBinary: DimlessBinaryPipe,
     public actionLabels: ActionLabelsI18n,
     private authStorageService: AuthStorageService,
     private daemonService: DaemonService,
@@ -140,32 +148,6 @@ export class ServiceDaemonListComponent implements OnInit, OnChanges, AfterViewI
         flexGrow: 1,
         filterable: true
       },
-      {
-        name: $localize`Container ID`,
-        prop: 'container_id',
-        flexGrow: 2,
-        filterable: true,
-        cellTransformation: CellTemplate.truncate,
-        customTemplateConfig: {
-          length: 12
-        }
-      },
-      {
-        name: $localize`Container Image name`,
-        prop: 'container_image_name',
-        flexGrow: 3,
-        filterable: true
-      },
-      {
-        name: $localize`Container Image ID`,
-        prop: 'container_image_id',
-        flexGrow: 2,
-        filterable: true,
-        cellTransformation: CellTemplate.truncate,
-        customTemplateConfig: {
-          length: 12
-        }
-      },
       {
         name: $localize`Version`,
         prop: 'version',
@@ -186,21 +168,23 @@ export class ServiceDaemonListComponent implements OnInit, OnChanges, AfterViewI
         flexGrow: 1
       },
       {
-        name: $localize`Daemon Events`,
-        prop: 'events',
-        flexGrow: 5,
-        cellTemplate: this.listTpl
+        name: $localize`CPU Usage`,
+        prop: 'cpu_percentage',
+        flexGrow: 1,
+        cellTemplate: this.cpuTpl
       },
       {
         name: $localize`Memory Usage`,
         prop: 'memory_usage',
         flexGrow: 1,
-        pipe: this.dimlessBinaryPipe
+        pipe: this.dimlessBinary,
+        cellClass: 'text-right'
       },
       {
-        name: $localize`CPU %`,
-        prop: 'cpu_percentage',
-        flexGrow: 1
+        name: $localize`Daemon Events`,
+        prop: 'events',
+        flexGrow: 2,
+        cellTemplate: this.listTpl
       }
     ];
 
index 655215c45bfef1be2cc9a5a51891466c05b997aa..0602a4e59c8220a34efd6be3e43b08340d03d7b2 100644 (file)
@@ -4,7 +4,7 @@
       <td class="text-left">Used:&nbsp;</td>
       <td class="text-right"><strong> {{ isBinary ? (used | dimlessBinary) : (used | dimless) }}</strong></td>
     </tr>
-    <tr>
+    <tr *ngIf="calculatePerc">
       <td class="text-left">Free:&nbsp;</td>
       <td class="'text-right"><strong>{{ isBinary ? (total - used | dimlessBinary) : (total - used | dimless) }}</strong></td>
     </tr>
index bb11e4e80c80f128f217dde4c70b5aeab6df206d..203f2c9e05d962b5fe7d8243ac24bc35e9d68f8f 100644 (file)
@@ -11,7 +11,7 @@ export class UsageBarComponent implements OnChanges {
   @Input()
   total: number;
   @Input()
-  used: number;
+  used: any;
   @Input()
   warningThreshold: number;
   @Input()
@@ -20,12 +20,24 @@ export class UsageBarComponent implements OnChanges {
   isBinary = true;
   @Input()
   decimals = 0;
+  @Input()
+  calculatePerc = true;
 
   usedPercentage: number;
   freePercentage: number;
 
   ngOnChanges() {
-    this.usedPercentage = this.total > 0 ? (this.used / this.total) * 100 : 0;
-    this.freePercentage = 100 - this.usedPercentage;
+    if (this.calculatePerc) {
+      this.usedPercentage = this.total > 0 ? (this.used / this.total) * 100 : 0;
+      this.freePercentage = 100 - this.usedPercentage;
+    } else {
+      if (this.used) {
+        this.used = this.used.slice(0, -1);
+        this.usedPercentage = Number(this.used);
+        this.freePercentage = 100 - this.usedPercentage;
+      } else {
+        this.usedPercentage = 0;
+      }
+    }
   }
 }