Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/core/src/core_logic/ConfigurePatchingProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@
""" Configure Patching """
from core.src.bootstrap.Constants import Constants

from core.src.bootstrap.EnvLayer import EnvLayer
from core.src.core_logic.ExecutionConfig import ExecutionConfig
from core.src.local_loggers.CompositeLogger import CompositeLogger
from core.src.service_interfaces.StatusHandler import StatusHandler
from core.src.package_managers.PackageManager import PackageManager
from core.src.core_logic.ServiceManager import ServiceManager
from core.src.core_logic.TimerManager import TimerManager


class ConfigurePatchingProcessor(object):
def __init__(self, env_layer, execution_config, composite_logger, telemetry_writer, status_handler, package_manager, auto_assess_service_manager, auto_assess_timer_manager, lifecycle_manager):
# type: (EnvLayer, ExecutionConfig, CompositeLogger, TelemetryWriter, StatusHandler, PackageManager, ServiceManager, TimerManager) -> None
self.env_layer = env_layer
self.execution_config = execution_config

Expand All @@ -40,7 +49,7 @@ def __init__(self, env_layer, execution_config, composite_logger, telemetry_writ
def start_configure_patching(self):
""" Start configure patching """
try:
self.composite_logger.log("\nStarting configure patching... [MachineId: " + self.env_layer.platform.vm_name() + "][ActivityId: " + self.execution_config.activity_id + "][StartTime: " + self.execution_config.start_time + "]")
self.composite_logger.log("[CPP] Starting configure patching... [MachineId: " + self.env_layer.platform.vm_name() + "][ActivityId: " + self.execution_config.activity_id + "][StartTime: " + self.execution_config.start_time + "]")
Comment thread
kjohn-msft marked this conversation as resolved.
self.status_handler.set_current_operation(Constants.CONFIGURE_PATCHING)
self.__raise_if_telemetry_unsupported()

Expand Down Expand Up @@ -73,6 +82,7 @@ def set_configure_patching_final_overall_status(self):
def __try_set_patch_mode(self):
""" Set the patch mode for the VM """
try:
self.composite_logger.log_verbose("[CPP] Processing patch mode configuration...")
self.status_handler.set_current_operation(Constants.CONFIGURE_PATCHING)
self.current_auto_os_patch_state = self.package_manager.get_current_auto_os_patch_state()

Expand All @@ -87,9 +97,9 @@ def __try_set_patch_mode(self):

if self.execution_config.patch_mode == Constants.PatchModes.AUTOMATIC_BY_PLATFORM and self.current_auto_os_patch_state == Constants.AutomaticOSPatchStates.UNKNOWN:
# NOTE: only sending details in error objects for customer visibility on why patch state is unknown, overall configurepatching status will remain successful
self.configure_patching_exception_error = "Could not disable one or more automatic OS update services. Please check if they are configured correctly"
self.configure_patching_exception_error = "Could not disable one or more automatic OS update services. Please check if they are configured correctly."

self.composite_logger.log_debug("Completed processing patch mode configuration.")
self.composite_logger.log_debug("[CPP] Completed processing patch mode configuration.")
except Exception as error:
self.composite_logger.log_error("Error while processing patch mode configuration. [Error={0}]".format(repr(error)))
self.configure_patching_exception_error = error
Expand All @@ -98,17 +108,21 @@ def __try_set_patch_mode(self):
def __try_set_auto_assessment_mode(self):
""" Sets the preferred auto-assessment mode for the VM """
try:
self.composite_logger.log_verbose("[CPP] Processing assessment mode configuration...")
self.status_handler.set_current_operation(Constants.CONFIGURE_PATCHING_AUTO_ASSESSMENT)
self.composite_logger.log_debug("Systemd information: {0}".format(str(self.auto_assess_service_manager.get_version()))) # proactive support telemetry

if self.execution_config.assessment_mode is None:
self.composite_logger.log_debug("No assessment mode config was present. No configuration changes will occur.")
elif self.execution_config.assessment_mode == Constants.AssessmentModes.AUTOMATIC_BY_PLATFORM:
self.composite_logger.log_debug("Enabling platform-based automatic assessment.")

if not self.auto_assess_service_manager.systemd_exists():
raise Exception("Systemd is not available on this system, and platform-based auto-assessment cannot be configured.")

self.auto_assess_service_manager.create_and_set_service_idem()
self.auto_assess_timer_manager.create_and_set_timer_idem()

self.current_auto_assessment_state = Constants.AutoAssessmentStates.ENABLED
elif self.execution_config.assessment_mode == Constants.AssessmentModes.IMAGE_DEFAULT:
self.composite_logger.log_debug("Disabling platform-based automatic assessment.")
Expand All @@ -119,7 +133,7 @@ def __try_set_auto_assessment_mode(self):
raise Exception("Unknown assessment mode specified. [AssessmentMode={0}]".format(self.execution_config.assessment_mode))

self.__report_consolidated_configure_patch_status()
self.composite_logger.log_debug("Completed processing automatic assessment mode configuration.")
self.composite_logger.log_debug("[CPP] Completed processing automatic assessment mode configuration.")
except Exception as error:
# deliberately not setting self.configure_patching_exception_error here as it does not feed into the parent object. Not a bug, if you're thinking about it.
self.composite_logger.log_error("Error while processing automatic assessment mode configuration. [Error={0}]".format(repr(error)))
Expand All @@ -131,8 +145,9 @@ def __try_set_auto_assessment_mode(self):
self.status_handler.set_current_operation(Constants.CONFIGURE_PATCHING)

def __report_consolidated_configure_patch_status(self, status=Constants.STATUS_TRANSITIONING, error=Constants.DEFAULT_UNSPECIFIED_VALUE):
""" Reports """
self.composite_logger.log_debug("Reporting consolidated current configure patch status. [OSPatchState={0}][AssessmentState={1}]".format(self.current_auto_os_patch_state, self.current_auto_assessment_state))
# type: (str, any) -> None
""" Reports the consolidated configure patching status """
self.composite_logger.log_debug("[CPP] Reporting consolidated current configure patch status. [OSPatchState={0}][AssessmentState={1}]".format(self.current_auto_os_patch_state, self.current_auto_assessment_state))

# report error if specified
if error != Constants.DEFAULT_UNSPECIFIED_VALUE:
Expand Down
1 change: 1 addition & 0 deletions src/core/src/core_logic/ServiceManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self, env_layer, execution_config, composite_logger, telemetry_writ

# region - Service Creation / Removal
def remove_service(self):
""" Remove the service if it exists """
service_path = self.__systemd_service_unit_path.format(self.service_name)
if os.path.exists(service_path):
self.stop_service()
Expand Down
Loading
Loading