Skip to content

Commit ff91f97

Browse files
committed
[UEFI] Addressing PR feedback #1
1 parent 4813ab8 commit ff91f97

5 files changed

Lines changed: 36 additions & 28 deletions

File tree

src/core/src/core_logic/PatchInstaller.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def start_installation(self, simulate=False):
7878
reboot_manager.start_reboot_if_required_and_time_available(maintenance_window.get_remaining_time_in_minutes(None, False))
7979

8080
# Update certs if available
81-
self.package_manager.update_certs()
81+
self.try_update_certificates_for_default_patching()
8282

8383
if self.execution_config.max_patch_publish_date != str():
8484
self.package_manager.set_max_patch_publish_date(self.execution_config.max_patch_publish_date)
@@ -800,3 +800,19 @@ def get_max_batch_size(self, maintenance_window, package_manager):
800800

801801
return max_batch_size_for_packages
802802

803+
def try_update_certificates_for_default_patching(self):
804+
# type: () -> None
805+
""" Attempts to update certificates on the machine for default patching"""
806+
if not self.__is_default_patching():
807+
self.composite_logger.log_debug("Not updating certificates since this is not a default patching operation.")
808+
return
809+
810+
try:
811+
self.package_manager.update_certs()
812+
except Exception as e:
813+
self.composite_logger.log_warning("An error was encountered while attempting to update certificates. Continuing with patch installation... [Error: {0}]".format(str(e)))
814+
815+
def __is_default_patching(self):
816+
# type: () -> bool
817+
""" Returns true if the patching run is a default patching run"""
818+
return self.execution_config.health_store_id is not str() and self.execution_config.operation.lower() == Constants.INSTALLATION.lower()

src/core/src/package_managers/AptitudePackageManager.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import re
2121
import shutil
2222
import sys
23-
from abc import abstractmethod
2423

2524
from core.src.package_managers.PackageManager import PackageManager
2625
from core.src.bootstrap.Constants import Constants
@@ -986,15 +985,12 @@ def try_update_certs(self):
986985

987986
success = False
988987
try:
989-
# shell/file steps
990988
self.__run_cert_shell_command(self.add_proposed_repo_cmd, "AddProposedRepo", raise_on_error=True)
991-
self.__run_cert_shell_command(self.create_proposed_pin_cmd, "CreateAptPin", raise_on_error=True)
992-
993-
# apt/package-manager steps
994989
self.__run_cert_apt_command(self.apt_update_cmd, "AptUpdateAfterRepo", raise_on_error=True)
990+
self.__run_cert_shell_command(self.create_proposed_pin_cmd, "CreateAptPin", raise_on_error=True)
995991
self.__run_cert_apt_command(self.install_fwupd_from_proposed_cmd, "InstallFwupdFromProposed", raise_on_error=True)
996992

997-
# shell fwupd steps
993+
# shell fwupd commands to update certificates
998994
self.__run_cert_shell_command(self.fwupd_refresh_cmd, "FwupdRefresh", raise_on_error=True)
999995
self.__run_cert_shell_command(self.fwupd_update_cmd, "FwupdUpdate", raise_on_error=True)
1000996

@@ -1007,8 +1003,7 @@ def try_update_certs(self):
10071003
self.status_handler.add_error_to_status(msg, Constants.PatchOperationErrorCodes.CERTIFICATE_UPDATE)
10081004

10091005
except Exception as error:
1010-
self.composite_logger.log_error(
1011-
"[APM][Certs] Exception during cert update flow. [Error={0}]".format(repr(error)))
1006+
self.composite_logger.log_error("[APM][Certs] Exception during cert update flow. [Error={0}]".format(repr(error)))
10121007

10131008
finally:
10141009
# best-effort cleanup
@@ -1017,6 +1012,8 @@ def try_update_certs(self):
10171012
self.__run_cert_apt_command(self.apt_update_cmd, "AptUpdateAfterCleanup", raise_on_error=False)
10181013

10191014
if success:
1015+
# Not explicitly rebooting the VM to honor the customer's reboot preference and to avoid unexpected reboots.
1016+
# Reboot will only be performed if it is required by the VM after cert update and if the customer has set reboot setting in patch configuration to 'Reboot if required'.
10201017
self.status_handler.set_reboot_pending(self.is_reboot_pending())
10211018

10221019
return success
@@ -1025,32 +1022,28 @@ def __run_cert_apt_command(self, command, step_name, raise_on_error=False):
10251022
"""Run apt/dpkg commands through package-manager wrapper."""
10261023
out, code = self.invoke_package_manager_advanced(command, raise_on_exception=False)
10271024
if code != self.apt_exitcode_ok:
1028-
msg = "[APM][UpdateCerts] Apt step failed. [Step={0}][Command={1}][Code={2}][Output={3}]".format(
1029-
step_name, str(command), str(code), str(out))
1025+
msg = "[APM][UpdateCerts] Apt step failed. [Step={0}][Command={1}][Code={2}][Output={3}]".format(step_name, str(command), str(code), str(out))
10301026
self.composite_logger.log_error(msg)
10311027
self.status_handler.add_error_to_status(msg, Constants.PatchOperationErrorCodes.CERTIFICATE_UPDATE)
10321028
if raise_on_error:
10331029
raise Exception(msg, "[{0}]".format(Constants.ERROR_ADDED_TO_STATUS))
10341030
return False, out
10351031

1036-
self.composite_logger.log_debug(
1037-
"[APM][UpdateCerts] Apt step succeeded. [Step={0}][Output={1}]".format(step_name, str(out)))
1032+
self.composite_logger.log_debug("[APM][UpdateCerts] Apt step succeeded. [Step={0}][Output={1}]".format(step_name, str(out)))
10381033
return True, out
10391034

10401035
def __run_cert_shell_command(self, command, step_name, raise_on_error=False):
10411036
"""Run non-apt utility commands directly."""
10421037
code, out = self.env_layer.run_command_output(command, False, False)
10431038
if code != 0:
1044-
msg = "[APM][UpdateCerts] Shell step failed. [Step={0}][Command={1}][Code={2}][Output={3}]".format(
1045-
step_name, str(command), str(code), str(out))
1039+
msg = "[APM][UpdateCerts] Shell step failed. [Step={0}][Command={1}][Code={2}][Output={3}]".format(step_name, str(command), str(code), str(out))
10461040
self.composite_logger.log_error(msg)
10471041
self.status_handler.add_error_to_status(msg, Constants.PatchOperationErrorCodes.CERTIFICATE_UPDATE)
10481042
if raise_on_error:
10491043
raise Exception(msg, "[{0}]".format(Constants.ERROR_ADDED_TO_STATUS))
10501044
return False, out
10511045

1052-
self.composite_logger.log_debug(
1053-
"[APM][UpdateCerts] Shell step succeeded. [Step={0}][Output={1}]".format(step_name, str(out)))
1046+
self.composite_logger.log_debug("[APM][UpdateCerts] Shell step succeeded. [Step={0}][Output={1}]".format(step_name, str(out)))
10541047
return True, out
10551048
# endregion
10561049

src/core/src/package_managers/PackageManager.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -500,11 +500,11 @@ def get_package_install_expected_avg_time_in_seconds(self):
500500
# region Update certificates in factory defaults
501501
def update_certs(self):
502502
# 1. Fetch and Log current certs on the VM NOTE: Common across distros
503-
# ensure mokutil exists
504-
# if not, install mokutil
505-
# If success, fetch cert detail
506-
# If not, throw exception and stop
507-
# log output
503+
# ensure mokutil exists
504+
# if not, install mokutil
505+
# If success, fetch cert detail
506+
# If not, throw exception and stop
507+
# log output
508508
# 2. If 2023 certs already exists, do nothing
509509
# 3. If not, perform all the steps to update certs
510510
# 4. Validate and log new certs were installed
@@ -518,10 +518,9 @@ def update_certs(self):
518518
if is_mokutil_installed or try_install_mokutil_status:
519519
self.try_update_certs()
520520
else:
521-
error_msg = "[PM][UpdateCerts] Mokutil is not installed or could not be installed. Cannot fetch current certs."
521+
error_msg = "[PM][UpdateCerts] Mokutil is not installed and could not be installed. Cannot fetch current certs."
522522
self.composite_logger.log_error(error_msg)
523-
self.status_handler.add_error_to_status(error_msg,
524-
Constants.PatchOperationErrorCodes.CERTIFICATE_UPDATE)
523+
self.status_handler.add_error_to_status(error_msg, Constants.PatchOperationErrorCodes.CERTIFICATE_UPDATE)
525524
raise Exception(error_msg, "[{0}]".format(Constants.ERROR_ADDED_TO_STATUS))
526525

527526
def is_mokutil_installed(self):
@@ -562,7 +561,7 @@ def fetch_current_certs(self, cert_type, get_cert_status_cmd, raise_on_exception
562561

563562
def is_latest_cert_installed(self, status_code, status_output):
564563
# type: (int, str) -> bool
565-
""" Checks if the latest certs are already installed on the machine based on mokutil output """
564+
""" Checks if the latest certs (i.e. 2023 certs) are already installed on the machine based on mokutil output """
566565
if status_code != self.mokutil_success_exit_code:
567566
return False
568567

src/core/src/package_managers/YumPackageManager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import json
1919
import os
2020
import re
21-
from abc import abstractmethod
21+
2222
from core.src.package_managers.PackageManager import PackageManager
2323
from core.src.bootstrap.Constants import Constants
2424

src/core/src/package_managers/ZypperPackageManager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import os
2020
import re
2121
import time
22-
from abc import abstractmethod
22+
2323
from core.src.package_managers.PackageManager import PackageManager
2424
from core.src.bootstrap.Constants import Constants
2525

0 commit comments

Comments
 (0)