Skip to content

Commit

Permalink
Merge pull request #3989 from Yelp/u/jfong/fix_paasta_status_bouncest…
Browse files Browse the repository at this point in the history
…atus

Fix backwards "Bouncing to" status
  • Loading branch information
jfongatyelp authored Dec 2, 2024
2 parents f65acaf + 095823b commit f715cd8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 3 additions & 1 deletion paasta_tools/cli/cmds/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,9 @@ def get_instance_state(status: InstanceStatusKubernetesV2) -> str:
else:
return PaastaColors.green("Running")
else:
versions = sorted(status.versions, key=lambda x: x.create_timestamp)
versions = sorted(
status.versions, key=lambda x: x.create_timestamp, reverse=True
)
git_shas = {r.git_sha for r in versions}
config_shas = {r.config_sha for r in versions}
bouncing_to = []
Expand Down
26 changes: 24 additions & 2 deletions tests/cli/test_cmds_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -1820,8 +1820,10 @@ def test_running(self, mock_kubernetes_status_v2):
assert remove_ansi_escape_sequences(instance_state) == "Running"

def test_bouncing(self, mock_kubernetes_status_v2):
old_version = mock_kubernetes_status_v2.versions[0]
new_version = paastamodels.KubernetesVersion(
create_timestamp=1.0,
# ensure creation is after current version
create_timestamp=old_version.create_timestamp + 1000,
git_sha="bbb111",
config_sha="config111",
ready_replicas=0,
Expand All @@ -1832,9 +1834,29 @@ def test_bouncing(self, mock_kubernetes_status_v2):
instance_state = remove_ansi_escape_sequences(instance_state)
assert instance_state == "Bouncing to bbb111, config111"

def test_bouncing_ordering(self, mock_kubernetes_status_v2):
old_version = mock_kubernetes_status_v2.versions[0]
new_version = paastamodels.KubernetesVersion(
# ensure creation is _before_ current version
create_timestamp=old_version.create_timestamp - 1000,
git_sha="bbb111",
config_sha="config111",
ready_replicas=0,
)
mock_kubernetes_status_v2.versions.append(new_version)

instance_state = get_instance_state(mock_kubernetes_status_v2)
instance_state = remove_ansi_escape_sequences(instance_state)
assert instance_state != "Bouncing to bbb111, config111"
assert (
instance_state
== f"Bouncing to {old_version.git_sha[:8]}, {old_version.config_sha}"
)

def test_bouncing_git_sha_change_only(self, mock_kubernetes_status_v2):
old_version = mock_kubernetes_status_v2.versions[0]
new_version = paastamodels.KubernetesVersion(
create_timestamp=1.0,
create_timestamp=old_version.create_timestamp + 1000,
git_sha="bbb111",
config_sha=mock_kubernetes_status_v2.versions[0].config_sha,
ready_replicas=0,
Expand Down

0 comments on commit f715cd8

Please sign in to comment.