Skip to content

Commit

Permalink
Include Assessment when ConfigurePatching -> AutoAssessmentMode is Au…
Browse files Browse the repository at this point in the history
…tomaticByPlatform (#177)

* Include assessment with ConfigurePatching set to have auto-assessment

* Removed partial unnecessary comment
  • Loading branch information
kjohn-msft authored Mar 14, 2023
1 parent 938ab4c commit 7aadd1e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
5 changes: 3 additions & 2 deletions src/core/src/CoreMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ def __init__(self, argv):
if not execution_config.exec_auto_assess_only:
configure_patching_successful = configure_patching_processor.start_configure_patching()

# Assessment happens for an Auto Assessment request or for Non Auto Assessment operations, if the operation requested is not Configure Patching
if execution_config.exec_auto_assess_only or patch_operation_requested != Constants.CONFIGURE_PATCHING.lower():
# Assessment happens for an Auto Assessment request or for all Non Auto Assessment operations, except for ConfigurePatching iff AssessmentMode is set to AutomaticByPlatform
include_assessment_with_configure_patching = (patch_operation_requested == Constants.CONFIGURE_PATCHING.lower() and execution_config.assessment_mode == Constants.AssessmentModes.AUTOMATIC_BY_PLATFORM)
if execution_config.exec_auto_assess_only or patch_operation_requested != Constants.CONFIGURE_PATCHING.lower() or include_assessment_with_configure_patching:
patch_assessment_successful = patch_assessor.start_assessment()

# Patching + additional assessment occurs if the operation is 'Installation' and not Auto Assessment. Need to check both since operation_requested from prev run is preserved in Auto Assessment
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/service_interfaces/StatusHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ def add_error_to_status(self, message, error_code=Constants.PatchOperationErrorC
if self.__try_add_error(self.__configure_patching_errors, error_detail):
self.__configure_patching_top_level_error_count += 1

# retain previously set status, code, patchMode and M for configure patching substatus
# retain previously set status, code, patchMode and assessmentMode for configure patching substatus
if self.__configure_patching_substatus_json is not None:
automatic_os_patch_state = json.loads(self.__configure_patching_substatus_json["formattedMessage"]["message"])["automaticOSPatchState"]
auto_assessment_status = self.__json_try_get_key_value(self.__configure_patching_substatus_json["formattedMessage"]["message"],"autoAssessmentStatus","{}")
Expand Down
24 changes: 14 additions & 10 deletions src/core/tests/Test_ConfigurePatchingProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,16 @@ def test_configure_patching_with_assessment_mode_by_platform(self):
substatus_file_data = json.load(file_handle)[0]["status"]["substatus"]

# check status file for configure patching patch state
self.assertEqual(len(substatus_file_data), 1)
self.assertTrue(substatus_file_data[0]["name"] == Constants.CONFIGURE_PATCHING_SUMMARY)
self.assertTrue(substatus_file_data[0]["status"].lower() == Constants.STATUS_SUCCESS.lower())
message = json.loads(substatus_file_data[0]["formattedMessage"]["message"])
self.assertEqual(len(substatus_file_data), 2)
self.assertTrue(substatus_file_data[1]["name"] == Constants.CONFIGURE_PATCHING_SUMMARY)
self.assertTrue(substatus_file_data[1]["status"].lower() == Constants.STATUS_SUCCESS.lower())
message = json.loads(substatus_file_data[1]["formattedMessage"]["message"])
self.assertEqual(message["automaticOSPatchState"], Constants.AutomaticOSPatchStates.ENABLED) # no change is made on Auto OS updates for patch mode 'ImageDefault'
self.assertTrue(substatus_file_data[0]["name"] == Constants.PATCH_ASSESSMENT_SUMMARY)
self.assertTrue(substatus_file_data[0]["status"].lower() == Constants.STATUS_SUCCESS.lower())

# check status file for configure patching assessment state
message = json.loads(substatus_file_data[0]["formattedMessage"]["message"])
message = json.loads(substatus_file_data[1]["formattedMessage"]["message"])
self.assertEqual(message["autoAssessmentStatus"]["autoAssessmentState"], Constants.AutoAssessmentStates.ENABLED) # auto assessment is enabled

# stop test runtime
Expand Down Expand Up @@ -246,14 +248,16 @@ def test_configure_patching_with_patch_mode_and_assessment_mode_by_platform(self

# check status file for configure patching patch state
self.assertTrue(runtime.package_manager.image_default_patch_configuration_backup_exists())
self.assertEqual(len(substatus_file_data), 1)
self.assertTrue(substatus_file_data[0]["name"] == Constants.CONFIGURE_PATCHING_SUMMARY)
self.assertTrue(substatus_file_data[0]["status"].lower() == Constants.STATUS_SUCCESS.lower())
message = json.loads(substatus_file_data[0]["formattedMessage"]["message"])
self.assertEqual(len(substatus_file_data), 2)
self.assertTrue(substatus_file_data[1]["name"] == Constants.CONFIGURE_PATCHING_SUMMARY)
self.assertTrue(substatus_file_data[1]["status"].lower() == Constants.STATUS_SUCCESS.lower())
message = json.loads(substatus_file_data[1]["formattedMessage"]["message"])
self.assertEqual(message["automaticOSPatchState"], Constants.AutomaticOSPatchStates.DISABLED) # auto OS updates are disabled on patch mode 'AutomaticByPlatform'
self.assertTrue(substatus_file_data[0]["name"] == Constants.PATCH_ASSESSMENT_SUMMARY)
self.assertTrue(substatus_file_data[0]["status"].lower() == Constants.STATUS_SUCCESS.lower())

# check status file for configure patching assessment state
message = json.loads(substatus_file_data[0]["formattedMessage"]["message"])
message = json.loads(substatus_file_data[1]["formattedMessage"]["message"])
self.assertEqual(message["autoAssessmentStatus"]["autoAssessmentState"], Constants.AutoAssessmentStates.ENABLED) # auto assessment is enabled

# stop test runtime
Expand Down
22 changes: 10 additions & 12 deletions src/core/tests/Test_CoreMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,14 +540,14 @@ def test_auto_assessment_success_with_configure_patching_in_prev_operation_on_sa
status_file_data = json.load(file_handle)[0]["status"]
self.assertTrue(status_file_data["operation"] == Constants.CONFIGURE_PATCHING)
substatus_file_data = status_file_data["substatus"]
self.assertEqual(len(substatus_file_data), 1)
self.assertTrue(substatus_file_data[0]["name"] == Constants.CONFIGURE_PATCHING_SUMMARY)
self.assertTrue(substatus_file_data[0]["status"].lower() == Constants.STATUS_SUCCESS.lower())
self.assertEqual(len(substatus_file_data), 2)
self.assertTrue(substatus_file_data[1]["name"] == Constants.CONFIGURE_PATCHING_SUMMARY)
self.assertTrue(substatus_file_data[1]["status"].lower() == Constants.STATUS_SUCCESS.lower())
# check status file for configure patching auto updates state
message = json.loads(substatus_file_data[0]["formattedMessage"]["message"])
message = json.loads(substatus_file_data[1]["formattedMessage"]["message"])
self.assertEqual(message["automaticOSPatchState"], Constants.AutomaticOSPatchStates.DISABLED) # auto OS updates are disabled in RuntimeCompositor
# check status file for configure patching assessment state
message = json.loads(substatus_file_data[0]["formattedMessage"]["message"])
message = json.loads(substatus_file_data[1]["formattedMessage"]["message"])
self.assertEqual(message["autoAssessmentStatus"]["autoAssessmentState"], Constants.AutoAssessmentStates.ENABLED) # auto assessment is enabled

# operation #2: Auto Assessment
Expand Down Expand Up @@ -577,8 +577,6 @@ def test_auto_assessment_success_with_configure_patching_in_prev_operation_on_sa
self.assertTrue(substatus_file_data[1]["status"].lower() == Constants.STATUS_SUCCESS.lower())
message = json.loads(substatus_file_data[1]["formattedMessage"]["message"])
self.assertEqual(message["automaticOSPatchState"], Constants.AutomaticOSPatchStates.DISABLED) # auto OS updates are disabled in RuntimeCompositor
# check status file for configure patching assessment state
message = json.loads(substatus_file_data[1]["formattedMessage"]["message"])
self.assertEqual(message["autoAssessmentStatus"]["autoAssessmentState"], Constants.AutoAssessmentStates.ENABLED) # auto assessment is enabled

runtime.stop()
Expand All @@ -600,14 +598,14 @@ def test_auto_assessment_success_on_arc_with_configure_patching_in_prev_operatio
status_file_data = json.load(file_handle)[0]["status"]
self.assertTrue(status_file_data["operation"] == Constants.CONFIGURE_PATCHING)
substatus_file_data = status_file_data["substatus"]
self.assertEqual(len(substatus_file_data), 1)
self.assertTrue(substatus_file_data[0]["name"] == Constants.CONFIGURE_PATCHING_SUMMARY)
self.assertTrue(substatus_file_data[0]["status"].lower() == Constants.STATUS_SUCCESS.lower())
self.assertEqual(len(substatus_file_data), 2)
self.assertTrue(substatus_file_data[1]["name"] == Constants.CONFIGURE_PATCHING_SUMMARY)
self.assertTrue(substatus_file_data[1]["status"].lower() == Constants.STATUS_SUCCESS.lower())
# check status file for configure patching auto updates state
message = json.loads(substatus_file_data[0]["formattedMessage"]["message"])
message = json.loads(substatus_file_data[1]["formattedMessage"]["message"])
self.assertEqual(message["automaticOSPatchState"], Constants.AutomaticOSPatchStates.DISABLED) # auto OS updates are disabled in RuntimeCompositor
# check status file for configure patching assessment state
message = json.loads(substatus_file_data[0]["formattedMessage"]["message"])
message = json.loads(substatus_file_data[1]["formattedMessage"]["message"])
self.assertEqual(message["autoAssessmentStatus"]["autoAssessmentState"], Constants.AutoAssessmentStates.ENABLED) # auto assessment is enabled

# operation #2: Auto Assessment
Expand Down

0 comments on commit 7aadd1e

Please sign in to comment.