[Fleet] remove old assets for manual upgrade too (#115926)
* remove old assets for manual upgarde too * fixed tests * fixed tests
This commit is contained in:
parent
e3aba08ea9
commit
b6c3762556
4 changed files with 19 additions and 8 deletions
|
@ -17,7 +17,7 @@ import { removeOldAssets } from './cleanup';
|
|||
jest.mock('../..', () => ({
|
||||
appContextService: {
|
||||
getLogger: () => ({
|
||||
info: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
}),
|
||||
},
|
||||
}));
|
||||
|
|
|
@ -57,7 +57,7 @@ async function removeAssetsFromVersion(
|
|||
if (total > 0) {
|
||||
appContextService
|
||||
.getLogger()
|
||||
.info(`Package "${pkgName}-${oldVersion}" still being used by policies`);
|
||||
.debug(`Package "${pkgName}-${oldVersion}" still being used by policies`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -128,6 +128,12 @@ jest.mock('./agent_policy', () => {
|
|||
};
|
||||
});
|
||||
|
||||
jest.mock('./epm/packages/cleanup', () => {
|
||||
return {
|
||||
removeOldAssets: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
const mockedFetchInfo = fetchInfo as jest.Mock<ReturnType<typeof fetchInfo>>;
|
||||
|
||||
type CombinedExternalCallback = PutPackagePolicyUpdateCallback | PostPackagePolicyCreateCallback;
|
||||
|
|
|
@ -424,7 +424,17 @@ class PackagePolicyService {
|
|||
user: options?.user,
|
||||
});
|
||||
|
||||
return (await this.get(soClient, id)) as PackagePolicy;
|
||||
const newPolicy = (await this.get(soClient, id)) as PackagePolicy;
|
||||
|
||||
if (packagePolicy.package) {
|
||||
await removeOldAssets({
|
||||
soClient,
|
||||
pkgName: packagePolicy.package.name,
|
||||
currentVersion: packagePolicy.package.version,
|
||||
});
|
||||
}
|
||||
|
||||
return newPolicy;
|
||||
}
|
||||
|
||||
public async delete(
|
||||
|
@ -596,11 +606,6 @@ class PackagePolicyService {
|
|||
name: packagePolicy.name,
|
||||
success: true,
|
||||
});
|
||||
await removeOldAssets({
|
||||
soClient,
|
||||
pkgName: packageInfo.name,
|
||||
currentVersion: packageInfo.version,
|
||||
});
|
||||
} catch (error) {
|
||||
// We only want to specifically handle validation errors for the new package policy. If a more severe or
|
||||
// general error is thrown elsewhere during the upgrade process, we want to surface that directly in
|
||||
|
|
Loading…
Reference in a new issue