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

Add additional host, machine and node selectors #355

Merged
merged 4 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/selectors/host/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ export const getHostRole = hostMachine =>
get(hostMachine, ['metadata', 'labels', 'machine.openshift.io/cluster-api-machine-role']);

export const getHostMachineName = host => get(host, 'spec.machineRef.name');
export const getHostBmcAddress = host => get(host, 'spec.bmc.address');
export const getHostErrorMessage = host => get(host, 'status.errorMessage');
export const isHostPoweredOn = host => get(host, 'status.poweredOn', false);
2 changes: 2 additions & 0 deletions src/selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ export * from './common';
export * from './dv';
export * from './host';
export * from './infrastructure';
export * from './machine';
export * from './migration';
export * from './node';
export * from './pod';
export * from './pvc';
export * from './vm';
Expand Down
4 changes: 4 additions & 0 deletions src/selectors/machine/combined.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { find, get } from 'lodash';

export const getMachineNode = (nodes, machine) =>
find(nodes, node => get(node, 'metadata.name') === get(machine, 'status.nodeRef.name'));
1 change: 1 addition & 0 deletions src/selectors/machine/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './combined';
1 change: 1 addition & 0 deletions src/selectors/node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './selectors';
3 changes: 3 additions & 0 deletions src/selectors/node/selectors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { get } from 'lodash';

export const isNodeUnschedulable = node => get(node, 'spec.unschedulable', false);
83 changes: 83 additions & 0 deletions src/utils/status/host/fixtures/hostStatus.fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import {
HOST_STATUS_READY,
HOST_STATUS_DISCOVERED,
HOST_STATUS_OK,
HOST_STATUS_PROVISIONED,
HOST_STATUS_DEPROVISIONED,
HOST_STATUS_REGISTERING,
HOST_STATUS_INSPECTING,
HOST_STATUS_PREPARING_TO_PROVISION,
HOST_STATUS_PROVISIONING,
HOST_STATUS_DEPROVISIONING,
HOST_STATUS_MAKING_HOST_AVAILABLE,
HOST_STATUS_VALIDATION_ERROR,
HOST_STATUS_REGISTRATION_ERROR,
} from '../constants';

const getHost = (provisioningState, operationalStatus = 'OK', errorMessage = '') => ({
metadata: {
name: 'test-host',
namespace: 'openshift-machine-api',
},
spec: {},
status: {
errorMessage,
operationalStatus,
provisioning: { state: provisioningState },
},
});

export default [
{
host: getHost('ready'),
expectedSimple: HOST_STATUS_READY,
},
{
host: getHost('discovered'),
expectedSimple: HOST_STATUS_DISCOVERED,
},
{
host: getHost(undefined, 'OK'),
expectedSimple: HOST_STATUS_OK,
},
{
host: getHost('provisioned'),
expectedSimple: HOST_STATUS_PROVISIONED,
},
{
host: getHost('deprovisioned'),
expectedSimple: HOST_STATUS_DEPROVISIONED,
},
{
host: getHost('registering'),
expectedSimple: HOST_STATUS_REGISTERING,
},
{
host: getHost('inspecting'),
expectedSimple: HOST_STATUS_INSPECTING,
},
{
host: getHost('preparing to provision'),
expectedSimple: HOST_STATUS_PREPARING_TO_PROVISION,
},
{
host: getHost('provisioning'),
expectedSimple: HOST_STATUS_PROVISIONING,
},
{
host: getHost('deprovisioning'),
expectedSimple: HOST_STATUS_DEPROVISIONING,
},
{
host: getHost('making host available'),
expectedSimple: HOST_STATUS_MAKING_HOST_AVAILABLE,
},
{
host: getHost('validation error', 'error', 'some validation error'),
expectedSimple: HOST_STATUS_VALIDATION_ERROR,
},
{
host: getHost('registration error', 'error', 'failed to register new host'),
expectedSimple: HOST_STATUS_REGISTRATION_ERROR,
},
];
9 changes: 8 additions & 1 deletion src/utils/status/host/hostStatus.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { getOperationalStatus, getProvisioningState, getHostErrorMessage } from '../../../selectors';
import {
getOperationalStatus,
getProvisioningState,
getHostErrorMessage,
isNodeUnschedulable,
} from '../../../selectors';

import { HOST_STATUS_TO_TEXT, HOST_STATUS_READY, HOST_STATUS_REGISTERING } from './constants';

Expand All @@ -18,3 +23,5 @@ export const getHostStatus = host => {
export const getSimpleHostStatus = host => getHostStatus(host).status;

export const canHostAddMachine = host => [HOST_STATUS_READY].includes(getSimpleHostStatus(host));
export const canHostStartMaintenance = hostNode => hostNode && !isNodeUnschedulable(hostNode);
export const canHostStopMaintenance = hostNode => isNodeUnschedulable(hostNode);
20 changes: 20 additions & 0 deletions src/utils/status/host/tests/hostStatus.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { getHostStatus, getSimpleHostStatus } from '../hostStatus';
import hostFixtures from '../fixtures/hostStatus.fixture';

describe('getHostStatus()', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this method or add .expected results to fixtures

hostFixtures.forEach((fixture, idx) => {
const resultStatus = fixture.expectedSimple;
it(`return status correctly ${idx} (${resultStatus})`, () => {
expect(getHostStatus(fixture.host).status).toBe(resultStatus);
});
});
});

describe('getSimpleHostStatus()', () => {
hostFixtures.forEach((fixture, idx) => {
const resultStatus = fixture.expectedSimple;
it(`return status correctly ${idx} (${resultStatus})`, () => {
expect(getSimpleHostStatus(fixture.host)).toBe(resultStatus);
});
});
});