Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #36256 - Allow user to force profile upload when changing host content view #10501

Merged
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { useDispatch, useSelector } from 'react-redux';
import { Modal, Button, Alert } from '@patternfly/react-core';
import { Modal, Button, Alert, Checkbox, TextContent, Text, TextVariants } from '@patternfly/react-core';
import { translate as __ } from 'foremanReact/common/I18n';
import { STATUS } from 'foremanReact/constants';
import { useAPI } from 'foremanReact/common/hooks/API/APIHooks';
Expand All @@ -11,13 +11,15 @@ import { ENVIRONMENT_PATHS_KEY } from '../../../../../scenes/ContentViews/compon
import api from '../../../../../services/api';
import getContentViews from '../../../../../scenes/ContentViews/ContentViewsActions';
import { selectContentViews, selectContentViewStatus } from '../../../../../scenes/ContentViews/ContentViewSelectors';
import updateHostContentViewAndEnvironment from './HostContentViewActions';
import updateHostContentViewAndEnvironment, { runSubmanRepos } from './HostContentViewActions';
import HOST_CV_AND_ENV_KEY from './HostContentViewConstants';
import { getHostDetails } from '../../HostDetailsActions';
import ContentViewSelect from '../../../../../scenes/ContentViews/components/ContentViewSelect/ContentViewSelect';
import ContentViewSelectOption
from '../../../../../scenes/ContentViews/components/ContentViewSelect/ContentViewSelectOption';
import { getCVPlaceholderText } from '../../../../../scenes/ContentViews/components/ContentViewSelect/helpers';
import { useRexJobPolling } from '../../Tabs/RemoteExecutionHooks';
import './ChangeHostCVModal.scss';

const ENV_PATH_OPTIONS = { key: ENVIRONMENT_PATHS_KEY };

Expand All @@ -34,6 +36,7 @@ const ChangeHostCVModal = ({

const [selectedCVForHost, setSelectedCVForHost] = useState(null);
const [cvSelectOpen, setCVSelectOpen] = useState(false);
const [forceProfileUpload, setForceProfileUpload] = useState(false);
const dispatch = useDispatch();
const contentViewsInEnvResponse = useSelector(state => selectContentViews(state, `FOR_ENV_${hostEnvId}`));
const { results } = contentViewsInEnvResponse;
Expand All @@ -48,6 +51,7 @@ const ChangeHostCVModal = ({

const handleModalClose = () => {
setCVSelectOpen(false);
setForceProfileUpload(false);
setSelectedCVForHost(null);
setSelectedEnvForHost([]);
closeModal();
Expand All @@ -74,7 +78,13 @@ const ChangeHostCVModal = ({
const { results: contentViewsInEnv = [] } = contentViewsInEnvResponse;
const canSave = !!(selectedCVForHost && selectedEnvForHost.length);

const { triggerJobStart } =
useRexJobPolling(runSubmanRepos, () => getHostDetails({ hostname: hostName }));

const refreshHostDetails = () => {
if (forceProfileUpload) {
triggerJobStart(hostName);
}
handleModalClose();
return dispatch(getHostDetails({ hostname: hostName }));
};
Expand Down Expand Up @@ -131,6 +141,7 @@ const ChangeHostCVModal = ({
position="top"
actions={modalActions}
id="change-host-cv-modal"
key={`change-host-cv-modal-${hostId}`}
ouiaId="change-host-cv-modal"
>
{contentViewsInEnvStatus === STATUS.RESOLVED &&
Expand Down Expand Up @@ -172,6 +183,21 @@ const ChangeHostCVModal = ({
/>
))}
</ContentViewSelect>
<hr />
<TextContent>
<Text component={TextVariants.small} ouiaId="force-profile-upload-text">
{forceProfileUpload ? __('Errata and package information will be updated immediately.') : __('Errata and package information will be updated at the next host check-in or package action.')}
</Text>
</TextContent>
<Checkbox
isChecked={forceProfileUpload}
onChange={setForceProfileUpload}
label={__('Update the host immediately via remote execution')}
id="force-profile-upload-checkbox"
ouiaId="force-profile-upload-checkbox"
isDisabled={!selectedCVForHost}
/>
<hr />
</Modal>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#force-profile-upload-checkbox {
margin-top: 0.16rem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { translate as __ } from 'foremanReact/common/I18n';
import { API_OPERATIONS, put } from 'foremanReact/redux/API';
import { errorToast } from '../../../../../scenes/Tasks/helpers';
import { foremanApi } from '../../../../../services/api';
import { runCommand } from '../../Tabs/RemoteExecutionActions';
import HOST_CV_AND_ENV_KEY from './HostContentViewConstants';

const updateHostContentViewAndEnvironment = (params, hostId, handleSuccess, handleError) => put({
Expand All @@ -15,5 +16,12 @@ const updateHostContentViewAndEnvironment = (params, hostId, handleSuccess, hand
params,
});

export const runSubmanRepos =
(hostname, handleSuccess) => runCommand({
hostname,
command: 'subscription-manager repos',
handleSuccess,
});

export default updateHostContentViewAndEnvironment;

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ const baseParams = ({ feature, hostname, inputs = {} }) => ({
},
});

const runCommandParams = ({ hostname, command }) =>
baseParams({
hostname,
inputs: { command },
feature: REX_FEATURES.RUN_COMMAND,
});

// used when we know the package name
const katelloPackageInstallParams = ({ hostname, packageName }) =>
baseParams({
Expand Down Expand Up @@ -103,6 +110,18 @@ export const startPollingJob = ({
export const stopPollingJob = ({ key }) => stopInterval(pollJobKey(key));

// JOB INVOCATIONS
export const runCommand = ({ hostname, command, handleSuccess }) => post({
type: API_OPERATIONS.POST,
key: REX_JOB_INVOCATIONS_KEY,
url: foremanApi.getApiUrl('/job_invocations'),
params: runCommandParams({ hostname, command }),
handleSuccess: (response) => {
showRexToast(response);
if (handleSuccess) handleSuccess(response);
},
errorToast,
});

export const installPackage = ({ hostname, packageName, handleSuccess }) => post({
type: API_OPERATIONS.POST,
key: REX_JOB_INVOCATIONS_KEY,
Expand Down Expand Up @@ -190,3 +209,4 @@ export const moduleStreamAction = ({ hostname, action, moduleSpec }) => post({
handleSuccess: showRexToast,
errorToast,
});

Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export const REX_FEATURES = {
KATELLO_HOST_TRACER_RESOLVE: 'katello_host_tracer_resolve',
KATELLO_HOST_ERRATA_INSTALL_BY_SEARCH: 'katello_errata_install_by_search',
KATELLO_HOST_MODULE_STREAM_ACTION: 'katello_module_stream_action',
RUN_COMMAND: 'run_script',
};