Skip to content

Commit e1a9b9f

Browse files
committed
[Livepatching][MVP] Completing all items earlier marked as todo
1 parent dd09f52 commit e1a9b9f

2 files changed

Lines changed: 36 additions & 10 deletions

File tree

src/core/src/package_managers/AptitudePackageManager.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -858,15 +858,17 @@ def are_livepatch_prereq_met(self):
858858
These pre-reqs are: Machine should be attached to a pro subscription and livepatch service should be enabled on the VM. """
859859
self.composite_logger.log_debug("[APM] Checking if all the pre-reqs to receive livepatches are met. NOTE: Livepatches is only available on Ubuntu LTS paid pro VMs and has to be in enabled state")
860860
if not self.ubuntu_pro_client.is_livepatching_applicable_for_machine():
861-
self.composite_logger.log_warning("[APM] Livepatching is not applicable for this machine, hence no livepatches will be installed")
861+
error_message = "[APM] Livepatching is not applicable for this machine, hence no livepatches will be installed"
862+
self.composite_logger.log_error(error_message)
863+
self.status_handler.add_error_to_status(error_message, Constants.PatchOperationErrorCodes.LIVEPATCH_ERROR)
862864
return False
863-
# todo: add to error?
864865

865866
if not self.ubuntu_pro_client.is_livepatch_service_enabled_on_machine():
866-
self.composite_logger.log_warning("[APM] Livepatch service is not enabled on this machine, hence no livepatches will be installed."
867-
" Please enable livepatch service if you want AzGPS to apply livepatches on this machine")
867+
error_message = ("[APM] Livepatch service is not enabled on this machine, hence no livepatches will be installed."
868+
" Please enable livepatch service if you want AzGPS to apply livepatches on this machine")
869+
self.composite_logger.log_error(error_message)
870+
self.status_handler.add_error_to_status(error_message, Constants.PatchOperationErrorCodes.LIVEPATCH_ERROR)
868871
return False
869-
# todo: add to error?
870872

871873
self.composite_logger.log_debug("[APM] All Livepatch pre-reqs are met. VM is eligible to receive livepatches")
872874
return True
@@ -937,11 +939,13 @@ def try_get_livepatch_status(self):
937939
livepatch_status = json.loads(output)
938940
self.composite_logger.log_debug("[APM] Successfully fetched livepatch status. [Status={0}]".format(str(livepatch_status)))
939941
else:
940-
self.composite_logger.log_warning("[APM] Failed to fetch livepatch status. [Cmd={0}][Code={1}][Output={2}]".format(str(cmd), str(code), str(output)))
941-
# todo: add to error object?
942+
error_msg = "[APM] Failed to fetch livepatch status. [Cmd={0}][Code={1}][Output={2}]".format(str(cmd), str(code), str(output))
943+
self.composite_logger.log_error(error_msg)
944+
self.status_handler.add_error_to_status(error_msg, Constants.PatchOperationErrorCodes.LIVEPATCH_ERROR)
942945
except Exception as error:
943-
livepatch_status_fetch_exception = repr(error) # todo: applies everywhere, see if this should be logged as error in status blob. If not, refactor code
944-
self.composite_logger.log_warning("[APM] Exception while fetching livepatch status. [Cmd={0}][Exception={1}]".format(str(cmd), livepatch_status_fetch_exception))
946+
error_msg = "[APM] Exception while fetching livepatch status. [Cmd={0}][Exception={1}]".format(str(cmd), repr(error))
947+
self.composite_logger.log_error(error_msg)
948+
self.status_handler.add_error_to_status(error_msg, Constants.PatchOperationErrorCodes.LIVEPATCH_ERROR)
945949
return livepatch_status
946950

947951
def update_livepatch_status_in_patch_installation_summary(self, livepatch_status):

src/core/tests/Test_AptitudePackageManager.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,15 +1085,24 @@ def test_are_livepatch_prereq_met_success(self):
10851085
def test_are_livepatch_prereq_met_failure(self):
10861086
package_manager = self.__setup_package_manager()
10871087
self.assertIsNotNone(package_manager)
1088+
self.runtime.status_handler.set_current_operation(Constants.INSTALLATION)
10881089

10891090
# VM is not attached
10901091
package_manager.ubuntu_pro_client.is_ubuntu_pro_client_attached = False
10911092
self.assertFalse(package_manager.are_livepatch_prereq_met())
1093+
substatus_file_data = self.__get_substatus_from_status_file()[0]
1094+
errors = json.loads(substatus_file_data["formattedMessage"]["message"])["errors"]
1095+
self.assertNotEqual(errors, None)
1096+
self.assertTrue("Livepatching is not applicable for this machine" in str(errors))
10921097

10931098
#VM is attached but livepatch service not enabled
10941099
package_manager = self.__setup_package_manager(legacy_type='SadPath')
10951100
package_manager.ubuntu_pro_client.is_ubuntu_pro_client_attached = True
10961101
self.assertFalse(package_manager.are_livepatch_prereq_met())
1102+
substatus_file_data = self.__get_substatus_from_status_file()[0]
1103+
updated_errors = json.loads(substatus_file_data["formattedMessage"]["message"])["errors"]
1104+
self.assertNotEqual(updated_errors, None)
1105+
self.assertTrue("Livepatch service is not enabled on this machine" in str(updated_errors))
10971106

10981107
def test_try_set_livepatch_cutoff_date_in_config_success(self):
10991108
package_manager = self.__setup_package_manager()
@@ -1141,13 +1150,23 @@ def test_try_get_livepatch_status_success(self):
11411150

11421151
def test_try_get_livepatch_status_failure(self):
11431152
package_manager = self.__setup_package_manager(legacy_type='SadPath')
1153+
self.runtime.status_handler.set_current_operation(Constants.INSTALLATION)
11441154
self.assertEqual(package_manager.try_get_livepatch_status(), {})
1155+
substatus_file_data = self.__get_substatus_from_status_file()[0]
1156+
errors = json.loads(substatus_file_data["formattedMessage"]["message"])["errors"]
1157+
self.assertNotEqual(errors, None)
1158+
self.assertTrue("Failed to fetch livepatch status." in str(errors))
11451159

11461160
def test_try_get_livepatch_status_exception_path(self):
11471161
package_manager = self.__setup_package_manager()
1162+
self.runtime.status_handler.set_current_operation(Constants.INSTALLATION)
11481163
backup_run_command_output = package_manager.env_layer.run_command_output
11491164
package_manager.env_layer.run_command_output = self.mock_run_command_output_raise_exception
11501165
self.assertEqual(package_manager.try_get_livepatch_status(), {})
1166+
substatus_file_data = self.__get_substatus_from_status_file()[0]
1167+
errors = json.loads(substatus_file_data["formattedMessage"]["message"])["errors"]
1168+
self.assertNotEqual(errors, None)
1169+
self.assertTrue("Exception while fetching livepatch status" in str(errors))
11511170
package_manager.env_layer.run_command_output = backup_run_command_output
11521171

11531172
def test_update_livepatch_status_in_patch_installation_summary_success(self):
@@ -1240,7 +1259,10 @@ def test_start_livepatch_when_pre_req_not_met(self):
12401259

12411260
package_manager.start_livepatch()
12421261
substatus_file_data = self.__get_substatus_from_status_file()
1243-
self.assertEqual(len(substatus_file_data), 0)
1262+
self.assertEqual(len(substatus_file_data), 1)
1263+
errors = json.loads(substatus_file_data[0]["formattedMessage"]["message"])["errors"]
1264+
self.assertNotEqual(errors, None)
1265+
self.assertTrue("Livepatch service is not enabled on this machine" in str(errors))
12441266

12451267
def test_start_livepatch_when_livepatch_config_date_not_set(self):
12461268
# cmd to set config date in livepatch service failed. So livepatch client is not launched and status not updated with livepatch data

0 commit comments

Comments
 (0)