1717"""Dnf5PackageManager for Azure Linux 4 or above and RHEL"""
1818import json
1919import re
20- from abc import ABCMeta , abstractmethod
2120
22- from core . src . bootstrap . Constants import Constants
21+ from abc import ABCMeta , abstractmethod
2322from core .src .core_logic .VersionComparator import VersionComparator
23+ from core .src .bootstrap .Constants import Constants
2424from core .src .package_managers .PackageManager import PackageManager
2525
2626
@@ -41,14 +41,12 @@ def __init__(self, env_layer, execution_config, composite_logger, telemetry_writ
4141
4242 # Install update
4343 self .single_package_upgrade_cmd = 'sudo dnf5 -y upgrade'
44-
4544 # Support to check if reboot is required
4645 # dnf-utils not required (needs-restarting is built into dnf5)
4746 self .needs_restarting_with_flag = 'sudo LANG=en_US.UTF8 dnf5 needs-restarting -r'
4847
4948 # DNF5 exit codes
5049 self .dnf_exitcode_ok = [0 , 100 ]
51-
5250 # DNF5 valid exit codes for simulation commands
5351 self .dnf5_simulation_valid_exit_codes = [0 , 1 ]
5452 self .dnf5_dependency_failure_text = ["Skipping packages with broken dependencies" , "Nothing to do." ]
@@ -469,10 +467,6 @@ def __init_constants_for_dnf5_automatic(self):
469467 self .dnf5_automatic_config_pattern_match_text = ' = (no|yes)'
470468 self .dnf5_automatic_download_updates_identifier_text = "download_updates"
471469 self .dnf5_automatic_apply_updates_identifier_text = "apply_updates"
472- # ExecStart flag identifiers
473- self .dnf5_automatic_download_updates_flag = '--downloadupdates'
474- self .dnf5_automatic_apply_updates_flag = '--installupdates'
475-
476470 self .dnf5_automatic_enable_on_reboot_identifier_text = "enable_on_reboot"
477471 self .dnf5_automatic_installation_state_identifier_text = "installation_state"
478472 self .dnf5_auto_os_update_service = "dnf5-automatic"
@@ -534,7 +528,13 @@ def __get_current_auto_os_updates_setting_on_machine(self):
534528 return is_service_installed , enable_on_reboot_value , download_updates_value , apply_updates_value
535529
536530 code , service_output = self .env_layer .run_command_output (self .dnf5_automatic_configuration_service , False , False )
537- self .composite_logger .log_debug ("[DNF5] dnf5-automatic ExecStart details. [Command={0}][Code={1}][Output={2}]" .format (self .dnf5_automatic_configuration_service , str (code ), service_output ))
531+ exec_start_line = ""
532+ #Only print ExecStart details
533+ for line in service_output .splitlines ():
534+ if line .strip ().startswith ("ExecStart" ):
535+ exec_start_line = line .strip ()
536+ break
537+ self .composite_logger .log_debug ("[DNF5] dnf5-automatic ExecStart details. [Command={0}][Code={1}][Output={2}]" .format (self .dnf5_automatic_configuration_service , str (code ), exec_start_line ))
538538
539539 is_service_installed = True
540540 enable_on_reboot_value = self .is_service_set_to_enable_on_reboot (self .enable_on_reboot_check_cmd )
@@ -670,7 +670,6 @@ def backup_image_default_patch_configuration_if_not_exists(self):
670670 self .installation_state_identifier_text : is_service_installed
671671 }
672672 }
673-
674673 image_default_patch_configuration_backup .update (backup_image_default_patch_configuration_json_to_add )
675674
676675 self .composite_logger .log_debug ("[DNF5] Logging default system configuration settings for auto OS updates. " "[Settings={0}] [Log file path={1}]" .format (str (image_default_patch_configuration_backup ),self .image_default_patch_configuration_backup_path ))
@@ -701,8 +700,7 @@ def update_os_patch_configuration_sub_setting(self, patch_configuration_sub_sett
701700 # note: adding space between the patch_configuration_sub_setting and value since, we will have to do that if we have to add a patch_configuration_sub_setting that did not exist before
702701 self .composite_logger .log_debug ("[DNF5] Updating system configuration settings for auto OS updates. [Patch Configuration Sub Setting={0}] [Value={1}]" .format (
703702 str (patch_configuration_sub_setting ), value ))
704- os_patch_configuration_settings = self .env_layer .file_system .read_with_retry (
705- self .os_patch_configuration_settings_file_path )
703+ os_patch_configuration_settings = self .env_layer .file_system .read_with_retry (self .os_patch_configuration_settings_file_path )
706704 patch_configuration_sub_setting_to_update = patch_configuration_sub_setting + ' = ' + value
707705 patch_configuration_sub_setting_found_in_file = False
708706 updated_patch_configuration_sub_setting = ""
@@ -720,9 +718,7 @@ def update_os_patch_configuration_sub_setting(self, patch_configuration_sub_sett
720718 if not patch_configuration_sub_setting_found_in_file :
721719 updated_patch_configuration_sub_setting += patch_configuration_sub_setting_to_update + "\n "
722720
723- self .env_layer .file_system .write_with_retry (self .os_patch_configuration_settings_file_path ,
724- '{0}' .format (updated_patch_configuration_sub_setting .lstrip ()),
725- mode = 'w+' )
721+ self .env_layer .file_system .write_with_retry (self .os_patch_configuration_settings_file_path ,'{0}' .format (updated_patch_configuration_sub_setting .lstrip ()),mode = 'w+' )
726722 except Exception as error :
727723 error_msg = "[DNF5] Error occurred while updating system configuration settings for auto OS updates. [Patch Configuration={0}] [Error={1}]" .format (
728724 str (patch_configuration_sub_setting ), repr (error ))
@@ -789,8 +785,7 @@ def __get_image_default_patch_configuration_backup(self):
789785 # read existing backup since it also contains backup from other update services. We need to preserve any existing data within the backup file
790786 if self .image_default_patch_configuration_backup_exists ():
791787 try :
792- image_default_patch_configuration_backup = json .loads (
793- self .env_layer .file_system .read_with_retry (self .image_default_patch_configuration_backup_path ))
788+ image_default_patch_configuration_backup = json .loads (self .env_layer .file_system .read_with_retry (self .image_default_patch_configuration_backup_path ))
794789 except Exception as error :
795790 self .composite_logger .log_error ("[DNF5] Unable to read backup for default patch state. Will attempt to re-write. [Exception={0}]" .format (repr (error )))
796791 return image_default_patch_configuration_backup
0 commit comments