From 09048aa032d449c5d1c207baed8a4916b8c96334 Mon Sep 17 00:00:00 2001 From: Jessica Castelino Date: Mon, 6 Feb 2023 22:53:37 +0000 Subject: [PATCH] Fix: Patchstate incorrect when there are no hosts If there are no hosts, the patchstate is expected to be "n/a" since we can't be sure of the current patch state. However, only the first patch's patchstate is set to "n/a" while the remaining patch's have a patchstate of "Available" (or whatever was previously reported for them). This commit fixes the issue. Test Plan: Tested with unit test case Closes-Bug: 2006398 Signed-off-by: Jessica Castelino Change-Id: I7f34d35f552a04d46e3f88af9548d2e74c241310 --- sw-patch/cgcs-patch/cgcs_patch/patch_controller.py | 2 +- .../cgcs_patch/tests/test_patch_controller.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/sw-patch/cgcs-patch/cgcs_patch/patch_controller.py b/sw-patch/cgcs-patch/cgcs_patch/patch_controller.py index 13067f47..cd05b31b 100644 --- a/sw-patch/cgcs-patch/cgcs_patch/patch_controller.py +++ b/sw-patch/cgcs-patch/cgcs_patch/patch_controller.py @@ -781,7 +781,7 @@ class PatchController(PatchService): if len(self.hosts) == 0: for patch_id in self.patch_data.metadata: self.patch_data.metadata[patch_id]["patchstate"] = constants.UNKNOWN - return + return # Default to allowing in-service patching self.allow_insvc_patching = True diff --git a/sw-patch/cgcs-patch/cgcs_patch/tests/test_patch_controller.py b/sw-patch/cgcs-patch/cgcs_patch/tests/test_patch_controller.py index f6c86365..77847985 100644 --- a/sw-patch/cgcs-patch/cgcs_patch/tests/test_patch_controller.py +++ b/sw-patch/cgcs-patch/cgcs_patch/tests/test_patch_controller.py @@ -943,3 +943,14 @@ class CgcsPatchControllerTestCase(testtools.TestCase): _mock_exists.return_value = True response = self.pc.patch_commit(patch_ids) self.assertEqual(response["info"], "The patches have been committed.") + + def test_check_patch_states_no_hosts(self): + self.create_patch_data(self.pc, + PATCH_LIST_AVAILABLE, + CONTENTS_WITH_OSTREE_DATA) + self.pc.hosts = [] + self.pc.check_patch_states() + self.assertEqual(self.pc.patch_data.metadata["First_Patch"]["patchstate"], "n/a") + self.assertEqual(self.pc.patch_data.metadata["Second_Patch"]["patchstate"], "n/a") + self.assertEqual(self.pc.patch_data.metadata["Third_Patch"]["patchstate"], "n/a") + self.assertEqual(self.pc.patch_data.metadata["Fourth_Patch"]["patchstate"], "n/a")