Skip to content

Commit

Permalink
Mitigation mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kjohn-msft committed Nov 5, 2024
1 parent 3f23065 commit dae10b7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
26 changes: 22 additions & 4 deletions src/core/src/core_logic/ExecutionConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,36 @@ def __get_max_patch_publish_date(self, health_store_id):
return max_patch_publish_date

def __get_max_patch_publish_date_from_inclusions(self, included_package_name_mask_list):
# type (str) -> str
# This is for AzGPS mitigation mode execution for Strict safe-deployment of patches.
mitigation_mode_flag = False
candidate = str()

for i in range(0, len(included_package_name_mask_list)):
if not included_package_name_mask_list[i].startswith("*="):
if mitigation_mode_flag and candidate != str():
break

Check warning on line 125 in src/core/src/core_logic/ExecutionConfig.py

View check run for this annotation

Codecov / codecov/patch

src/core/src/core_logic/ExecutionConfig.py#L125

Added line #L125 was not covered by tests

if included_package_name_mask_list[i] == "AzGPS_Mitigation_Mode_No_SLA":
mitigation_mode_flag = True
continue

if candidate != str():
continue

Check warning on line 132 in src/core/src/core_logic/ExecutionConfig.py

View check run for this annotation

Codecov / codecov/patch

src/core/src/core_logic/ExecutionConfig.py#L132

Added line #L132 was not covered by tests

if not included_package_name_mask_list[i].startswith("MaxPatchPublishDate="):
self.composite_logger.log_verbose("[EC] Ignored [MaxPatchPublishDate={0}]".format(str(included_package_name_mask_list[i])))
continue

candidate = included_package_name_mask_list[i].replace("*=", "")
candidate = included_package_name_mask_list[i].replace("MaxPatchPublishDate=", "")
candidate_split = candidate.split("T")
if len(candidate) == 16 and len(candidate_split) == 2 and candidate_split[0].isdigit() and candidate_split[1].endswith("Z"):
self.composite_logger.log_debug("[EC] Discovered effective MaxPatchPublishDate in patch inclusions. [MaxPatchPublishDate={0}]".format(str(candidate)))
return candidate
else:
self.composite_logger.log_debug("[EC] Invalid match on MaxPatchPublishDate in patch inclusions. [MaxPatchPublishDate={0}]".format(str(candidate)))

Check warning on line 143 in src/core/src/core_logic/ExecutionConfig.py

View check run for this annotation

Codecov / codecov/patch

src/core/src/core_logic/ExecutionConfig.py#L143

Added line #L143 was not covered by tests

self.composite_logger.log_debug("[EC] Invalid match on MaxPatchPublishDate in patch inclusions. [MaxPatchPublishDate={0}]".format(str(candidate)))
if mitigation_mode_flag and candidate != str():
self.composite_logger.log_warning("AzGPS Mitigation Mode: There is no support or SLA for execution in this mode without explicit direction from AzGPS engineering.")
return candidate

return str()

Expand Down
12 changes: 7 additions & 5 deletions src/core/tests/Test_AptitudePackageManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,22 +588,24 @@ def test_eula_not_accepted_for_patches(self):
self.assertTrue("ACCEPT_EULA=Y" not in package_manager_for_test.single_package_dependency_resolution_template)
self.assertTrue("ACCEPT_EULA=Y" not in package_manager_for_test.single_package_upgrade_cmd)

def test_maxpatchpublishdate(self):
def test_maxpatchpublishdate_mitigation_mode(self):
self.runtime.set_legacy_test_type('HappyPath')
package_manager = self.container.get('package_manager')
self.assertIsNotNone(package_manager)
self.runtime.stop()

argument_composer = ArgumentComposer()
argument_composer.classifications_to_include = [Constants.PackageClassification.CRITICAL]
argument_composer.patches_to_include = ["*=20230101T010101Z"]
argument_composer.patches_to_include = ["AzGPS_Mitigation_Mode_No_SLA", "MaxPatchPublishDate=20250101T010203Z"]
self.runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.APT)
container = self.runtime.container
execution_config = container.get('execution_config')
self.assertEqual(execution_config.max_patch_publish_date, "20230101T010101Z")

self.assertEqual(execution_config.max_patch_publish_date, "20250101T010203Z")
self.runtime.stop()
argument_composer.patches_to_include = ["*=20230101"]

argument_composer = ArgumentComposer()
argument_composer.classifications_to_include = [Constants.PackageClassification.CRITICAL]
argument_composer.patches_to_include = ["MaxPatchPublishDate=20250101T010203Z"]
self.runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.APT)
container = self.runtime.container
execution_config = container.get('execution_config')
Expand Down

0 comments on commit dae10b7

Please sign in to comment.