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

[Fleet] fix upgradeable check to allow to newer snapshot #167780

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
51 changes: 13 additions & 38 deletions x-pack/plugins/fleet/common/services/is_agent_upgradeable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,21 @@ const getAgent = ({
return agent;
};
describe('Fleet - isAgentUpgradeable', () => {
it('returns false if agent reports not upgradeable with agent version < kibana version', () => {
it('returns false if agent reports not upgradeable with agent version < latest agent version', () => {
expect(isAgentUpgradeable(getAgent({ version: '7.9.0' }), '8.0.0')).toBe(false);
});
it('returns false if agent reports not upgradeable with agent version > kibana version', () => {
it('returns false if agent reports not upgradeable with agent version > latest agent version', () => {
expect(isAgentUpgradeable(getAgent({ version: '8.0.0' }), '7.9.0')).toBe(false);
});
it('returns false if agent reports not upgradeable with agent version === kibana version', () => {
it('returns false if agent reports not upgradeable with agent version === latest agent version', () => {
expect(isAgentUpgradeable(getAgent({ version: '8.0.0' }), '8.0.0')).toBe(false);
});
it('returns false if agent reports upgradeable, with agent version === kibana version', () => {
it('returns false if agent reports upgradeable, with agent version === latest agent version', () => {
expect(isAgentUpgradeable(getAgent({ version: '8.0.0', upgradeable: true }), '8.0.0')).toBe(
false
);
});
it('returns false if agent reports upgradeable, with agent version > kibana version', () => {
it('returns false if agent reports upgradeable, with agent version > latest agent version', () => {
expect(isAgentUpgradeable(getAgent({ version: '8.0.0', upgradeable: true }), '7.9.0')).toBe(
false
);
Expand All @@ -142,58 +142,33 @@ describe('Fleet - isAgentUpgradeable', () => {
)
).toBe(false);
});
it('returns true if agent reports upgradeable, with agent version < kibana version', () => {
it('returns true if agent reports upgradeable, with agent version < latest agent version', () => {
expect(isAgentUpgradeable(getAgent({ version: '7.9.0', upgradeable: true }), '8.0.0')).toBe(
true
);
});
it('returns false if agent reports upgradeable, with agent snapshot version === kibana version', () => {
it('returns false if agent reports upgradeable, with agent snapshot version === latest agent version', () => {
expect(
isAgentUpgradeable(getAgent({ version: '7.9.0-SNAPSHOT', upgradeable: true }), '7.9.0')
).toBe(false);
});
it('returns false if agent reports upgradeable, with agent version === kibana snapshot version', () => {
expect(
isAgentUpgradeable(getAgent({ version: '7.9.0', upgradeable: true }), '7.9.0-SNAPSHOT')
).toBe(false);
});
it('returns true if agent reports upgradeable, with agent snapshot version < kibana snapshot version', () => {
it('returns true if agent reports upgradeable, with upgrade to agent snapshot version newer than latest agent version', () => {
expect(
isAgentUpgradeable(
getAgent({ version: '7.9.0-SNAPSHOT', upgradeable: true }),
'8.0.0-SNAPSHOT'
getAgent({ version: '8.10.2', upgradeable: true }),
'8.10.2',
'8.11.0-SNAPSHOT'
Copy link
Contributor

Choose a reason for hiding this comment

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

This test should cover the case that was failing, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

)
).toBe(true);
});
it('returns false if agent reports upgradeable, with agent snapshot version === kibana snapshot version', () => {
expect(
isAgentUpgradeable(
getAgent({ version: '8.0.0-SNAPSHOT', upgradeable: true }),
'8.0.0-SNAPSHOT'
)
).toBe(false);
});
it('returns true if agent reports upgradeable, with agent version < kibana snapshot version', () => {
expect(
isAgentUpgradeable(getAgent({ version: '7.9.0', upgradeable: true }), '8.0.0-SNAPSHOT')
).toBe(true);
});
it('returns false if agent reports upgradeable, with target version < current agent version ', () => {
expect(
isAgentUpgradeable(
getAgent({ version: '7.9.0', upgradeable: true }),
'8.0.0-SNAPSHOT',
'7.8.0'
)
isAgentUpgradeable(getAgent({ version: '7.9.0', upgradeable: true }), '8.0.0', '7.8.0')
).toBe(false);
});
it('returns false if agent reports upgradeable, with target version == current agent version ', () => {
expect(
isAgentUpgradeable(
getAgent({ version: '7.9.0', upgradeable: true }),
'8.0.0-SNAPSHOT',
'7.9.0'
)
isAgentUpgradeable(getAgent({ version: '7.9.0', upgradeable: true }), '8.0.0', '7.9.0')
).toBe(false);
});
it('returns false if agent reports upgradeable, but is already updating', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ export function isAgentUpgradeable(
return false;
}
if (versionToUpgrade !== undefined) {
return (
isNotDowngrade(agentVersion, versionToUpgrade) &&
isAgentVersionLessThanLatest(agentVersion, latestAgentVersion)
);
return isNotDowngrade(agentVersion, versionToUpgrade);
}
return isAgentVersionLessThanLatest(agentVersion, latestAgentVersion);
}
Expand Down