From 86d3364dfee60003697994a704d0198534ee59fb Mon Sep 17 00:00:00 2001 From: Jen Patague Date: Tue, 26 Nov 2024 11:23:06 -0800 Subject: [PATCH 1/2] Fix reported target version in bounce status --- paasta_tools/cli/cmds/status.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/paasta_tools/cli/cmds/status.py b/paasta_tools/cli/cmds/status.py index acb1f0ba1f..a831c38fb2 100644 --- a/paasta_tools/cli/cmds/status.py +++ b/paasta_tools/cli/cmds/status.py @@ -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 = [] From 095823bc7ccaee70c7b30764c9813ca2bdeda4ef Mon Sep 17 00:00:00 2001 From: Jen Patague Date: Tue, 26 Nov 2024 12:25:31 -0800 Subject: [PATCH 2/2] Fix tests --- tests/cli/test_cmds_status.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/cli/test_cmds_status.py b/tests/cli/test_cmds_status.py index cef5ca266d..cb4457837e 100644 --- a/tests/cli/test_cmds_status.py +++ b/tests/cli/test_cmds_status.py @@ -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, @@ -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,