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 #36846 - Override REX job names for package install by search #10772

Merged
merged 1 commit into from
Oct 25, 2023
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
Expand Up @@ -124,7 +124,7 @@ const PackageInstallModal = ({
const selectedPackageNames = () => selectedResults.map(({ name }) => name);

const installViaRex = () => {
triggerPackageInstall(fetchBulkParams());
triggerPackageInstall(fetchBulkParams(), selectedPackageNames().join(', '));
selectNone();
closeModal();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,10 @@ export const PackagesTab = () => {
isPolling: isRemoveInProgress,
} = useRexJobPolling(packageRemoveAction);

const packageBulkRemoveAction = bulkParams => removePackages({
const packageBulkRemoveAction = (bulkParams, packageNames) => removePackages({
hostname,
search: bulkParams,
descriptionFormat: `Remove package(s) ${packageNames}`,
});

const {
Expand All @@ -253,10 +254,11 @@ export const PackagesTab = () => {
isPolling: isUpgradeInProgress,
} = useRexJobPolling(packageUpgradeAction, getHostDetails({ hostname }));

const packageBulkUpgradeAction = bulkParams => updatePackages({
const packageBulkUpgradeAction = (bulkParams, descriptionFormat) => updatePackages({
hostname,
search: bulkParams,
versions: JSON.stringify(selectedNVRAVersions || []),
descriptionFormat,
});

const {
Expand All @@ -266,7 +268,7 @@ export const PackagesTab = () => {
} = useRexJobPolling(packageBulkUpgradeAction, getHostDetails({ hostname }));

const packageInstallAction
= bulkParams => installPackageBySearch({ hostname, search: bulkParams });
= (bulkParams, packageNames) => installPackageBySearch({ hostname, search: bulkParams, descriptionFormat: `Install package(s) ${packageNames}` });

const {
triggerJobStart: triggerPackageInstall,
Expand Down Expand Up @@ -306,9 +308,10 @@ export const PackagesTab = () => {

const removePackagesViaRemoteExecution = () => {
const selected = fetchBulkParams();
const packageNames = selectedResults.map(({ name }) => name);
setIsBulkActionOpen(false);
selectNone();
triggerBulkPackageRemove(selected);
triggerBulkPackageRemove(selected, packageNames.join(', '));
};

const removeBulk = () => removePackagesViaRemoteExecution();
Expand All @@ -321,9 +324,13 @@ export const PackagesTab = () => {

const upgradeBulkViaRemoteExecution = () => {
const selected = fetchBulkParams();
const packageNames = selectedResults.map(({ name }) => name);
const allRowsSelected = areAllRowsSelected();
let descriptionFormatText = allRowsSelected ? 'Upgrade all packages' : `Upgrade package(s) ${packageNames.join(', ')}`;
if (selectAllMode && !allRowsSelected) descriptionFormatText = 'Upgrade lots of packages'; // we don't know the package names in the exclusion set
setIsBulkActionOpen(false);
selectNone();
triggerBulkPackageUpgrade(selected);
triggerBulkPackageUpgrade(selected, descriptionFormatText);
};

const upgradeBulk = () => upgradeBulkViaRemoteExecution();
Expand Down Expand Up @@ -462,7 +469,6 @@ export const PackagesTab = () => {
);

const resetFilters = () => setPackageStatusSelected(PACKAGE_STATUS);

return (
<div>
<div id="packages-tab">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import { PACKAGE_SEARCH_QUERY } from './PackagesTab/YumInstallablePackagesConsta
import { PACKAGES_SEARCH_QUERY, SELECTED_UPDATE_VERSIONS } from './PackagesTab/HostPackagesConstants';

// PARAM BUILDING
const baseParams = ({ feature, hostname, inputs = {} }) => ({
const baseParams = ({
feature, hostname, descriptionFormat, inputs = {},
}) => ({
job_invocation: {
feature,
inputs,
descriptionFormat,
search_query: `name ^ (${hostname})`,
},
});
Expand All @@ -33,11 +36,12 @@ const katelloPackageInstallParams = ({ hostname, packageName }) =>
});

// used when we know package Id(s)
const katelloPackageInstallBySearchParams = ({ hostname, search }) =>
const katelloPackageInstallBySearchParams = ({ hostname, search, descriptionFormat }) =>
baseParams({
hostname,
inputs: { [PACKAGE_SEARCH_QUERY]: search },
feature: REX_FEATURES.KATELLO_PACKAGE_INSTALL_BY_SEARCH,
description_format: descriptionFormat,
});

const katelloPackageRemoveParams = ({ hostname, packageName }) =>
Expand All @@ -47,11 +51,12 @@ const katelloPackageRemoveParams = ({ hostname, packageName }) =>
feature: REX_FEATURES.KATELLO_PACKAGE_REMOVE,
});

const katelloPackagesRemoveParams = ({ hostname, search }) =>
const katelloPackagesRemoveParams = ({ hostname, search, descriptionFormat }) =>
baseParams({
hostname,
inputs: { [PACKAGES_SEARCH_QUERY]: search },
feature: REX_FEATURES.KATELLO_PACKAGES_REMOVE_BY_SEARCH,
description_format: descriptionFormat,
});

const katelloPackageUpdateParams = ({ hostname, packageName }) =>
Expand All @@ -61,11 +66,14 @@ const katelloPackageUpdateParams = ({ hostname, packageName }) =>
feature: REX_FEATURES.KATELLO_PACKAGE_UPDATE,
});

const katelloPackagesUpdateParams = ({ hostname, search, versions }) => ({
const katelloPackagesUpdateParams = ({
hostname, search, versions, descriptionFormat,
}) => ({
job_invocation: {
feature: REX_FEATURES.KATELLO_PACKAGES_UPDATE_BY_SEARCH,
inputs: { [PACKAGES_SEARCH_QUERY]: search, [SELECTED_UPDATE_VERSIONS]: versions },
search_query: `name ^ (${hostname})`,
description_format: descriptionFormat,
},
});

Expand Down Expand Up @@ -134,11 +142,11 @@ export const installPackage = ({ hostname, packageName, handleSuccess }) => post
errorToast,
});

export const installPackageBySearch = ({ hostname, search }) => post({
export const installPackageBySearch = ({ hostname, search, descriptionFormat }) => post({
type: API_OPERATIONS.POST,
key: REX_JOB_INVOCATIONS_KEY,
url: foremanApi.getApiUrl('/job_invocations'),
params: katelloPackageInstallBySearchParams({ hostname, search }),
params: katelloPackageInstallBySearchParams({ hostname, search, descriptionFormat }),
handleSuccess: showRexToast,
errorToast,
});
Expand All @@ -152,11 +160,11 @@ export const removePackage = ({ hostname, packageName }) => post({
errorToast,
});

export const removePackages = ({ hostname, search }) => post({
export const removePackages = ({ hostname, search, descriptionFormat }) => post({
type: API_OPERATIONS.POST,
key: REX_JOB_INVOCATIONS_KEY,
url: foremanApi.getApiUrl('/job_invocations'),
params: katelloPackagesRemoveParams({ hostname, search }),
params: katelloPackagesRemoveParams({ hostname, search, descriptionFormat }),
handleSuccess: showRexToast,
errorToast,
});
Expand All @@ -170,11 +178,15 @@ export const updatePackage = ({ hostname, packageName }) => post({
errorToast,
});

export const updatePackages = ({ hostname, search, versions }) => post({
export const updatePackages = ({
hostname, search, versions, descriptionFormat,
}) => post({
type: API_OPERATIONS.POST,
key: REX_JOB_INVOCATIONS_KEY,
url: foremanApi.getApiUrl('/job_invocations'),
params: katelloPackagesUpdateParams({ hostname, search, versions }),
params: katelloPackagesUpdateParams({
hostname, search, versions, descriptionFormat,
}),
handleSuccess: showRexToast,
errorToast,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ test('Can bulk upgrade via remote execution', async (done) => {
},
search_query: `name ^ (${hostname})`,
feature: REX_FEATURES.KATELLO_PACKAGES_UPDATE_BY_SEARCH,
description_format: 'Upgrade package(s) chrony, coreutils',
},
})
.reply(201);
Expand Down
Loading