Skip to content
This repository was archived by the owner on Apr 28, 2020. It is now read-only.

Commit 7f8e9dd

Browse files
committed
Added disks count to inventory
1 parent 5c9a1a2 commit 7f8e9dd

File tree

8 files changed

+144
-6
lines changed

8 files changed

+144
-6
lines changed

src/components/Dashboard/Inventory/utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { getHostStatus, HOST_STATUS_ALL_ERROR, HOST_STATUS_ALL_WARN } from '../.
66
import { getPvStatus, PV_STATUS_ALL_ERROR, PV_STATUS_ALL_PROGRESS } from '../../../utils/status/pv';
77

88
// same as InventoryItemStatus props
9-
const STATUS_RESULT_OK = 'ok';
10-
const STATUS_RESULT_WARN = 'warn';
11-
const STATUS_RESULT_ERROR = 'error';
12-
const STATUS_RESULT_IN_PROGRESS = 'inProgress';
9+
export const STATUS_RESULT_OK = 'ok';
10+
export const STATUS_RESULT_WARN = 'warn';
11+
export const STATUS_RESULT_ERROR = 'error';
12+
export const STATUS_RESULT_IN_PROGRESS = 'inProgress';
1313

1414
const mapStatuses = (entities, mapEntityToStatusResult) => {
1515
const result = {

src/components/StorageOverview/Inventory/Inventory.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,28 @@ import {
1010
} from '../../Dashboard/DashboardCard';
1111
import { StorageOverviewContext } from '../StorageOverviewContext';
1212
import { mapNodesToProps, mapPvcsToProps, mapPvsToProps } from '../../Dashboard/Inventory/utils';
13+
import diskStatsToProps from './diskInventoryUtils';
1314
import { InventoryRow } from '../../Dashboard/Inventory/InventoryRow';
1415

15-
const InventoryBody = ({ nodes, pvs, pvcs }) => (
16+
const InventoryBody = ({ nodes, pvs, pvcs, diskStats }) => (
1617
<React.Fragment>
1718
<InventoryRow title="Nodes" {...mapNodesToProps(nodes)} />
19+
<InventoryRow title="Disks" {...diskStatsToProps(diskStats)} />
1820
<InventoryRow title="PVs" {...mapPvsToProps(pvs)} />
1921
<InventoryRow title="PVCs" {...mapPvcsToProps(pvcs)} />
2022
</React.Fragment>
2123
);
2224

2325
InventoryBody.defaultProps = {
2426
nodes: undefined,
27+
diskStats: undefined,
2528
pvs: undefined,
2629
pvcs: undefined,
2730
};
2831

2932
InventoryBody.propTypes = {
3033
nodes: PropTypes.array,
34+
diskStats: PropTypes.object,
3135
pvs: PropTypes.array,
3236
pvcs: PropTypes.array,
3337
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { get } from 'lodash';
2+
3+
import { getCapacityStats } from '../../../selectors';
4+
import { STATUS_RESULT_OK, STATUS_RESULT_ERROR } from '../../Dashboard/Inventory/utils';
5+
6+
const diskStatsToProps = disks => {
7+
const result = {
8+
[STATUS_RESULT_OK]: 0,
9+
[STATUS_RESULT_ERROR]: 0,
10+
count: null,
11+
};
12+
13+
const cephOsdUpCount = getCapacityStats(get(disks, 'cephOsdUp'));
14+
const cephOsdDownCount = getCapacityStats(get(disks, 'cephOsdDown'));
15+
16+
if (cephOsdUpCount || cephOsdDownCount) {
17+
result[STATUS_RESULT_OK] = cephOsdUpCount;
18+
result[STATUS_RESULT_ERROR] = cephOsdDownCount;
19+
result.count = cephOsdUpCount + cephOsdDownCount;
20+
}
21+
return result;
22+
};
23+
24+
export default diskStatsToProps;

src/components/StorageOverview/Inventory/fixtures/Inventory.fixture.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Inventory } from '../Inventory';
2-
import { nodes, pvcs, pvs } from '../../fixtures/StorageOverview.fixture';
2+
import { nodes, pvcs, pvs, diskStats } from '../../fixtures/StorageOverview.fixture';
33

44
export default [
55
{
@@ -8,6 +8,7 @@ export default [
88
nodes,
99
pvcs,
1010
pvs,
11+
diskStats,
1112
},
1213
},
1314
{

src/components/StorageOverview/Inventory/tests/__snapshots__/Inventory.test.js.snap

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,46 @@ exports[`<Inventory /> renders correctly 1`] = `
5252
</div>
5353
</div>
5454
</div>
55+
<div
56+
class="kubevirt-inventory__row"
57+
id="inventory-disks"
58+
>
59+
<div
60+
class="kubevirt-inventory__row-title"
61+
>
62+
7 Disks
63+
</div>
64+
<div
65+
class="kubevirt-inventory__row-status"
66+
>
67+
<div
68+
class="kubevirt-inventory__row-status-item"
69+
>
70+
<span
71+
aria-hidden="true"
72+
class="fa fa-exclamation-circle fa-2x kubevirt-inventory__row-status-item-icon--error"
73+
/>
74+
<span
75+
class="kubevirt-inventory__row-status-item-text"
76+
>
77+
2
78+
</span>
79+
</div>
80+
<div
81+
class="kubevirt-inventory__row-status-item"
82+
>
83+
<span
84+
aria-hidden="true"
85+
class="fa fa-check-circle fa-2x kubevirt-inventory__row-status-item-icon--ok"
86+
/>
87+
<span
88+
class="kubevirt-inventory__row-status-item-text"
89+
>
90+
5
91+
</span>
92+
</div>
93+
</div>
94+
</div>
5595
<div
5696
class="kubevirt-inventory__row"
5797
id="inventory-pvs"

src/components/StorageOverview/fixtures/StorageOverview.fixture.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import { StorageOverviewContext } from '../StorageOverviewContext';
99
import { localhostNode } from '../../../tests/mocks/node';
1010
import { persistentVolumeClaims } from '../../../tests/mocks/persistentVolumeClaim';
1111
import { persistentVolumes } from '../../../tests/mocks/persistentVolume';
12+
import { osdDisksCount } from '../../../tests/mocks/disks';
1213

1314
export const nodes = [localhostNode];
1415
export const pvcs = persistentVolumeClaims;
1516
export const pvs = persistentVolumes;
17+
export const diskStats = osdDisksCount;
1618

1719
const StorageOverview = props => (
1820
<StorageOverviewContext.Provider value={props}>
@@ -29,6 +31,7 @@ export default [
2931
nodes,
3032
pvcs,
3133
pvs,
34+
diskStats,
3235
},
3336
},
3437
];

src/components/StorageOverview/tests/__snapshots__/StorageOverview.test.js.snap

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,46 @@ exports[`<StorageOverview /> renders correctly with Provider 1`] = `
132132
</div>
133133
</div>
134134
</div>
135+
<div
136+
class="kubevirt-inventory__row"
137+
id="inventory-disks"
138+
>
139+
<div
140+
class="kubevirt-inventory__row-title"
141+
>
142+
7 Disks
143+
</div>
144+
<div
145+
class="kubevirt-inventory__row-status"
146+
>
147+
<div
148+
class="kubevirt-inventory__row-status-item"
149+
>
150+
<span
151+
aria-hidden="true"
152+
class="fa fa-exclamation-circle fa-2x kubevirt-inventory__row-status-item-icon--error"
153+
/>
154+
<span
155+
class="kubevirt-inventory__row-status-item-text"
156+
>
157+
2
158+
</span>
159+
</div>
160+
<div
161+
class="kubevirt-inventory__row-status-item"
162+
>
163+
<span
164+
aria-hidden="true"
165+
class="fa fa-check-circle fa-2x kubevirt-inventory__row-status-item-icon--ok"
166+
/>
167+
<span
168+
class="kubevirt-inventory__row-status-item-text"
169+
>
170+
5
171+
</span>
172+
</div>
173+
</div>
174+
</div>
135175
<div
136176
class="kubevirt-inventory__row"
137177
id="inventory-pvs"

src/tests/mocks/disks/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export const osdDisksCount = {
2+
cephOsdUp: {
3+
status: 'success',
4+
data: {
5+
resultType: 'vector',
6+
result: [
7+
{
8+
metric: {},
9+
value: [123, '5'],
10+
},
11+
],
12+
},
13+
},
14+
cephOsdDown: {
15+
status: 'success',
16+
data: {
17+
resultType: 'vector',
18+
result: [
19+
{
20+
metric: {},
21+
value: [123, '2'],
22+
},
23+
],
24+
},
25+
},
26+
};

0 commit comments

Comments
 (0)