Skip to content

Commit 33c0386

Browse files
authored
Merge branch 'master' into kjohn-packager
2 parents b9e55a7 + da36d55 commit 33c0386

5 files changed

Lines changed: 490 additions & 116 deletions

File tree

src/core/src/core_logic/ConfigurePatchingProcessor.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,18 @@
1717
""" Configure Patching """
1818
from core.src.bootstrap.Constants import Constants
1919

20+
from core.src.bootstrap.EnvLayer import EnvLayer
21+
from core.src.core_logic.ExecutionConfig import ExecutionConfig
22+
from core.src.local_loggers.CompositeLogger import CompositeLogger
23+
from core.src.service_interfaces.StatusHandler import StatusHandler
24+
from core.src.package_managers.PackageManager import PackageManager
25+
from core.src.core_logic.ServiceManager import ServiceManager
26+
from core.src.core_logic.TimerManager import TimerManager
27+
2028

2129
class ConfigurePatchingProcessor(object):
2230
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):
31+
# type: (EnvLayer, ExecutionConfig, CompositeLogger, TelemetryWriter, StatusHandler, PackageManager, ServiceManager, TimerManager) -> None
2332
self.env_layer = env_layer
2433
self.execution_config = execution_config
2534

@@ -40,7 +49,7 @@ def __init__(self, env_layer, execution_config, composite_logger, telemetry_writ
4049
def start_configure_patching(self):
4150
""" Start configure patching """
4251
try:
43-
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 + "]")
52+
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 + "]")
4453
self.status_handler.set_current_operation(Constants.CONFIGURE_PATCHING)
4554
self.__raise_if_telemetry_unsupported()
4655

@@ -73,6 +82,7 @@ def set_configure_patching_final_overall_status(self):
7382
def __try_set_patch_mode(self):
7483
""" Set the patch mode for the VM """
7584
try:
85+
self.composite_logger.log_verbose("[CPP] Processing patch mode configuration...")
7686
self.status_handler.set_current_operation(Constants.CONFIGURE_PATCHING)
7787
self.current_auto_os_patch_state = self.package_manager.get_current_auto_os_patch_state()
7888

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

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

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

104115
if self.execution_config.assessment_mode is None:
105116
self.composite_logger.log_debug("No assessment mode config was present. No configuration changes will occur.")
106117
elif self.execution_config.assessment_mode == Constants.AssessmentModes.AUTOMATIC_BY_PLATFORM:
107118
self.composite_logger.log_debug("Enabling platform-based automatic assessment.")
119+
108120
if not self.auto_assess_service_manager.systemd_exists():
109121
raise Exception("Systemd is not available on this system, and platform-based auto-assessment cannot be configured.")
122+
110123
self.auto_assess_service_manager.create_and_set_service_idem()
111124
self.auto_assess_timer_manager.create_and_set_timer_idem()
125+
112126
self.current_auto_assessment_state = Constants.AutoAssessmentStates.ENABLED
113127
elif self.execution_config.assessment_mode == Constants.AssessmentModes.IMAGE_DEFAULT:
114128
self.composite_logger.log_debug("Disabling platform-based automatic assessment.")
@@ -119,7 +133,7 @@ def __try_set_auto_assessment_mode(self):
119133
raise Exception("Unknown assessment mode specified. [AssessmentMode={0}]".format(self.execution_config.assessment_mode))
120134

121135
self.__report_consolidated_configure_patch_status()
122-
self.composite_logger.log_debug("Completed processing automatic assessment mode configuration.")
136+
self.composite_logger.log_debug("[CPP] Completed processing automatic assessment mode configuration.")
123137
except Exception as error:
124138
# 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.
125139
self.composite_logger.log_error("Error while processing automatic assessment mode configuration. [Error={0}]".format(repr(error)))
@@ -131,8 +145,9 @@ def __try_set_auto_assessment_mode(self):
131145
self.status_handler.set_current_operation(Constants.CONFIGURE_PATCHING)
132146

133147
def __report_consolidated_configure_patch_status(self, status=Constants.STATUS_TRANSITIONING, error=Constants.DEFAULT_UNSPECIFIED_VALUE):
134-
""" Reports """
135-
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))
148+
# type: (str, any) -> None
149+
""" Reports the consolidated configure patching status """
150+
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))
136151

137152
# report error if specified
138153
if error != Constants.DEFAULT_UNSPECIFIED_VALUE:

src/core/src/core_logic/ServiceManager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def __init__(self, env_layer, execution_config, composite_logger, telemetry_writ
3636

3737
# region - Service Creation / Removal
3838
def remove_service(self):
39+
""" Remove the service if it exists """
3940
service_path = self.__systemd_service_unit_path.format(self.service_name)
4041
if os.path.exists(service_path):
4142
self.stop_service()

0 commit comments

Comments
 (0)