From: Aashish Sharma Date: Fri, 8 Apr 2022 05:19:04 +0000 (+0530) Subject: mgr/dashboard: fix linting errors and add test X-Git-Tag: v16.2.11~564^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F46459%2Fhead;p=ceph.git mgr/dashboard: fix linting errors and add test Fixes: https://tracker.ceph.com/issues/55218 Signed-off-by: Aashish Sharma --- diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 67fbcf73c0a..3742c006543 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -5493,16 +5493,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'], @@ -5689,11 +5689,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 @@ -5714,7 +5711,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: @@ -5729,6 +5727,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] diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index e4d80f44036..4760cdc132e 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -1025,7 +1025,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]) @@ -1052,7 +1052,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( @@ -2335,4 +2335,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 diff --git a/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/services.po.ts b/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/services.po.ts index 29156b2d582..a7959c7b355 100644 --- a/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/services.po.ts +++ b/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/services.po.ts @@ -18,7 +18,7 @@ export class ServicesPageHelper extends PageHelper { serviceDetailColumnIndex = { daemonName: 2, - status: 7 + status: 4 }; check_for_service() { @@ -123,7 +123,7 @@ export class ServicesPageHelper extends PageHelper { cy.url().then((url) => { if (!url.includes(pages.index.url)) { daemonNameIndex = 1; - statusIndex = 6; + statusIndex = 3; } cy.get('cd-service-daemon-list').within(() => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-daemon-list/service-daemon-list.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-daemon-list/service-daemon-list.component.html index 90916518426..fc076a185a0 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-daemon-list/service-daemon-list.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-daemon-list/service-daemon-list.component.html @@ -63,7 +63,8 @@ -
+
No data available
@@ -87,3 +88,15 @@ + + + + + + diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-daemon-list/service-daemon-list.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-daemon-list/service-daemon-list.component.spec.ts index 7e2148c1a26..31739a7c298 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-daemon-list/service-daemon-list.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-daemon-list/service-daemon-list.component.spec.ts @@ -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', diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-daemon-list/service-daemon-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-daemon-list/service-daemon-list.component.ts index 5337058e3ef..d1c2f9cc3f1 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-daemon-list/service-daemon-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-daemon-list/service-daemon-list.component.ts @@ -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; + @ViewChild('cpuTpl', { static: true }) + cpuTpl: TemplateRef; + @ViewChildren('daemonsTable') daemonsTableTpls: QueryList>; @@ -63,6 +65,12 @@ export class ServiceDaemonListComponent implements OnInit, OnChanges, AfterViewI @Input() flag?: string; + total = 100; + + warningThreshold = 0.8; + + errorThreshold = 0.9; + icons = Icons; daemons: Daemon[] = []; @@ -85,7 +93,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, @@ -137,32 +145,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', @@ -183,21 +165,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 } ]; diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/usage-bar/usage-bar.component.html b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/usage-bar/usage-bar.component.html index 655215c45bf..0602a4e59c8 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/usage-bar/usage-bar.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/usage-bar/usage-bar.component.html @@ -4,7 +4,7 @@ Used:  {{ isBinary ? (used | dimlessBinary) : (used | dimless) }} - + Free:  {{ isBinary ? (total - used | dimlessBinary) : (total - used | dimless) }} diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/usage-bar/usage-bar.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/usage-bar/usage-bar.component.ts index bb11e4e80c8..203f2c9e05d 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/usage-bar/usage-bar.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/usage-bar/usage-bar.component.ts @@ -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; + } + } } }