Skip to content

Commit

Permalink
fix upgradeable check to allow to newer snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaElastic committed Oct 2, 2023
1 parent c1aabee commit 87a460d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 42 deletions.
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'
)
).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
5 changes: 1 addition & 4 deletions x-pack/plugins/fleet/common/services/is_agent_upgradeable.ts
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

0 comments on commit 87a460d

Please sign in to comment.