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

Commit

Permalink
CreateVmDialog: V2V VMware report deployment status and all errors
Browse files Browse the repository at this point in the history
  • Loading branch information
suomiy committed May 31, 2019
1 parent b570ce9 commit 644624b
Show file tree
Hide file tree
Showing 45 changed files with 1,454 additions and 93 deletions.
16 changes: 1 addition & 15 deletions src/components/VmStatus/tests/VmStatus.test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
import React from 'react';
import { BrowserRouter } from 'react-router-dom';
import { shape } from 'prop-types';
import { render } from 'enzyme';

import { VmStatus, VmStatuses } from '../VmStatus';
import vmFixtures from '../../../utils/status/vm/fixtures/vmStatus.fixture';

const router = {
history: new BrowserRouter().history,
route: {
location: {},
match: {},
},
};

const createContext = () => ({
context: { router },
childContextTypes: { router: shape({}) },
});
import { createContext } from '../../../tests/router';

describe('<VmStatus vm />', () => {
it('renders correctly', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
PROVIDER_VMWARE_REMEMBER_PASSWORD_KEY,
PROVIDER_VMWARE_VCENTER_KEY,
PROVIDER_VMWARE_VM_KEY,
PROVIDER_VMWARE_V2V_LAST_ERROR,
} from '../../providers/VMwareImportProvider/constants';
import { getSimpleV2vVMwareStatus } from '../../../../../utils/status/v2vVMware/v2vVMwareStatus';

Expand Down Expand Up @@ -38,6 +39,10 @@ export const getVmWareInitialState = props => ({
value: getSimpleV2vVMwareStatus(), // UNKNOWN
},

[PROVIDER_VMWARE_V2V_LAST_ERROR]: {
isHidden: asHidden(true, PROVIDER_VMWARE_V2V_LAST_ERROR),
},

// simple values
[PROVIDER_VMWARE_V2V_NAME_KEY]: null,
});
Expand All @@ -60,6 +65,7 @@ const idResolver = {
[PROVIDER_VMWARE_REMEMBER_PASSWORD_KEY]: 'vcenter-remember-credentials',
[PROVIDER_VMWARE_STATUS_KEY]: 'vcenter-status',
[PROVIDER_VMWARE_VM_KEY]: 'vcenter-vm-dropdown',
[PROVIDER_VMWARE_V2V_LAST_ERROR]: 'v2v-vmware-error',
};

const defaultValueResolver = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import PropTypes from 'prop-types';

import { ResultTabRow } from '../../ResultTabRow';

const VMWareControllerErrors = ({ id, errors }) => {
if (!errors) {
return null;
}

return (
<div id={id}>
{errors.map((result, index) => (
<ResultTabRow key={index} {...result} />
))}
</div>
);
};

VMWareControllerErrors.defaultProps = {
id: null,
errors: null,
};

VMWareControllerErrors.propTypes = {
id: PropTypes.string,
errors: PropTypes.array,
};

export default VMWareControllerErrors;
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import React from 'react';
import PropTypes from 'prop-types';

import { Alert, Col, FormGroup, Spinner } from 'patternfly-react';

import { Link } from 'react-router-dom';

import {
getV2vVMwareDeploymentStatus,
V2V_WMWARE_DEPLOYMENT_STATUS_FAILED,
V2V_WMWARE_DEPLOYMENT_STATUS_POD_FAILED,
V2V_WMWARE_DEPLOYMENT_STATUS_PROGRESSING,
V2V_WMWARE_DEPLOYMENT_STATUS_ROLLOUT_COMPLETE,
V2V_WMWARE_DEPLOYMENT_STATUS_UNKNOWN,
} from '../../../../../utils/status/v2vVMwareDeployment';

import VMwareStatusField from './VMwareStatusField';
import { FormRow } from '../../../../Form/FormRow';
import { getName } from '../../../../../selectors';

import { getSubPagePath } from '../../../../../utils';
import { DeploymentModel, PodModel } from '../../../../../models';

const DeploymentLink = ({ deployment }) => (
<Link to={getSubPagePath(deployment, DeploymentModel, 'events')}>{getName(deployment)}</Link>
);

DeploymentLink.defaultProps = {
deployment: null,
};

DeploymentLink.propTypes = {
deployment: PropTypes.object,
};

const NoDeployment = () => (
<VMwareStatusField>
Starting VMware controller... <Spinner loading size="sm" />
</VMwareStatusField>
);

const DeploymentProgressing = ({ id, deployment }) => (
<VMwareStatusField id={id}>
Deploying VMware controller (<DeploymentLink deployment={deployment} />
)... <Spinner loading size="sm" />
</VMwareStatusField>
);

DeploymentProgressing.defaultProps = {
deployment: null,
id: null,
};

DeploymentProgressing.propTypes = {
deployment: PropTypes.object,
id: PropTypes.string,
};

const DeploymentFailed = ({ deployment, pod, message }) => {
let podMessage;
if (pod) {
podMessage = (
<React.Fragment>
{' '}
Please inspect a failing pod <Link to={getSubPagePath(pod, PodModel, 'events')}>{getName(pod)}</Link>
</React.Fragment>
);
}
return (
<VMwareStatusField>
<Alert type="warning">
Deployment of VMware controller <DeploymentLink deployment={deployment} /> failed: {message}.{podMessage}
</Alert>
</VMwareStatusField>
);
};

DeploymentFailed.defaultProps = {
...DeploymentProgressing.defaultProps,
pod: null,
message: null,
};

DeploymentFailed.propTypes = {
...DeploymentProgressing.propTypes,
pod: PropTypes.object,
message: PropTypes.string,
};

const vmwareStatusComponentResolver = {
[V2V_WMWARE_DEPLOYMENT_STATUS_PROGRESSING]: DeploymentProgressing,
[V2V_WMWARE_DEPLOYMENT_STATUS_POD_FAILED]: DeploymentFailed,
[V2V_WMWARE_DEPLOYMENT_STATUS_FAILED]: DeploymentFailed,
};

const VMWareControllerStatusRow = props => {
const { id, hasErrors, deployment, deploymentPods, controlSize, labelSize } = props;

const status = getV2vVMwareDeploymentStatus(deployment, deploymentPods);
if (
status.status === V2V_WMWARE_DEPLOYMENT_STATUS_ROLLOUT_COMPLETE ||
(status.status === V2V_WMWARE_DEPLOYMENT_STATUS_UNKNOWN && hasErrors) // deployment failed
) {
return null;
}

const StatusComponent = vmwareStatusComponentResolver[status.status] || NoDeployment;

return (
<FormGroup>
<Col sm={labelSize} />
<Col sm={controlSize}>
<StatusComponent id={id} {...status} />
</Col>
</FormGroup>
);
};

VMWareControllerStatusRow.defaultProps = {
id: null,
hasErrors: false,
deployment: null,
deploymentPods: null,
controlSize: FormRow.defaultProps.controlSize,
labelSize: FormRow.defaultProps.labelSize,
};

VMWareControllerStatusRow.propTypes = {
id: PropTypes.string,
hasErrors: PropTypes.bool,
deployment: PropTypes.object,
deploymentPods: PropTypes.array,
controlSize: FormRow.propTypes.controlSize,
labelSize: FormRow.propTypes.labelSize,
};

export default VMWareControllerStatusRow;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { get } from 'lodash';
import { get, isEmpty } from 'lodash';

import PropTypes from 'prop-types';

Expand Down Expand Up @@ -32,13 +32,16 @@ import {
PROVIDER_VMWARE_STATUS_KEY,
PROVIDER_VMWARE_USER_NAME_KEY,
PROVIDER_VMWARE_USER_PASSWORD_KEY,
PROVIDER_VMWARE_V2V_LAST_ERROR,
PROVIDER_VMWARE_VCENTER_KEY,
PROVIDER_VMWARE_VM_KEY,
} from './constants';
import VMWareProviderStatus from './VMWareProviderStatus';
import VMWareObjectStatus from './VMWareObjectStatus';
import { getSimpleV2vVMwareStatus } from '../../../../../utils/status/v2vVMware/v2vVMwareStatus';
import { V2V_WMWARE_STATUS_UNKNOWN } from '../../../../../utils/status/v2vVMware';
import { getVmwareField } from './selectors';
import VMWareControllerErrors from './VMWareControllerErrors';
import VMWareControllerStatusRow from './VMWareControllerStatusRow';

export class VMWareImportProvider extends React.Component {
state = {
Expand Down Expand Up @@ -136,7 +139,7 @@ export class VMWareImportProvider extends React.Component {
}

render() {
const { vCenterSecrets, v2vvmware } = this.props;
const { vCenterSecrets, v2vvmware, deployment, deploymentPods } = this.props;

const secrets = [CONNECT_TO_NEW_INSTANCE, ...vCenterSecrets.map(getName)];

Expand All @@ -148,11 +151,25 @@ export class VMWareImportProvider extends React.Component {
);
}

const hasDeployment = !(!deployment || isEmpty(deployment));

const errors = this.getFieldAttribute(PROVIDER_VMWARE_V2V_LAST_ERROR, 'errors');

return (
<React.Fragment>
<FormRow isHidden={hasDeployment || isFieldHidden(this.getField(PROVIDER_VMWARE_V2V_LAST_ERROR))}>
<VMWareControllerErrors id={getFieldId(PROVIDER_VMWARE_V2V_LAST_ERROR)} errors={errors} />
</FormRow>
<VMWareControllerStatusRow
id="v2v-vmware-status"
hasErrors={!!errors}
deployment={deployment}
deploymentPods={deploymentPods}
/>
<FormRow {...this.getRowMetadata(PROVIDER_VMWARE_VCENTER_KEY)}>
<Dropdown
{...this.getFieldData(PROVIDER_VMWARE_VCENTER_KEY)}
disabled={!hasDeployment || isFieldDisabled(this.getField(PROVIDER_VMWARE_VCENTER_KEY))}
onChange={this.onSecretChange}
choices={secrets}
/>
Expand Down Expand Up @@ -184,7 +201,7 @@ export class VMWareImportProvider extends React.Component {
</Button>
</FormRow>
<FormRow isHidden={isFieldHidden(this.getField(PROVIDER_VMWARE_STATUS_KEY))}>
<VMWareProviderStatus status={this.getValue(PROVIDER_VMWARE_STATUS_KEY)} />
<VMWareObjectStatus status={this.getValue(PROVIDER_VMWARE_STATUS_KEY)} />
</FormRow>
<FormRow {...this.getRowMetadata(PROVIDER_VMWARE_VM_KEY)}>
<Dropdown {...this.getFieldData(PROVIDER_VMWARE_VM_KEY)} choices={vmNames} />
Expand All @@ -195,12 +212,16 @@ export class VMWareImportProvider extends React.Component {
}

VMWareImportProvider.defaultProps = {
deployment: null,
deploymentPods: null,
vCenterSecrets: [], // TODO: add loading when undefined
v2vvmware: null,
vmwareToKubevirtOsConfigMap: null,
};

VMWareImportProvider.propTypes = {
deployment: PropTypes.object,
deploymentPods: PropTypes.array,
vmSettings: PropTypes.object.isRequired,
onChange: PropTypes.func.isRequired,
vCenterSecrets: PropTypes.array,
Expand Down
Loading

0 comments on commit 644624b

Please sign in to comment.