Skip to content

Commit 79ce7b4

Browse files
committed
Code Review comments
1 parent 1b64510 commit 79ce7b4

4 files changed

Lines changed: 11 additions & 27 deletions

File tree

src/core/src/bootstrap/EnvLayer.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ def is_distro_azure_linux_3(self, distro_name):
7171
""" Checks if the current distro is Azure Linux 3 """
7272
return self.__is_matching_distro_and_version(distro_name, Constants.AZURE_LINUX, version_to_match=3)
7373

74-
def is_distro_azure_linux_4(self, distro_name):
75-
# type: (str) -> bool
76-
""" Checks if the current distro is Azure Linux 4 """
77-
return self.__is_matching_distro_and_version(distro_name, Constants.AZURE_LINUX, version_to_match=4)
78-
7974
def is_distro_rhel_10(self, distro_name):
8075
# type: (str) -> bool
8176
""" Checks if the current distro is RHEL 10 """
@@ -92,7 +87,7 @@ def get_package_manager(self):
9287
os_name, os_version, os_code = self.platform.linux_distribution()
9388

9489
# Check for unsupported distros
95-
if self.is_distro_azure_linux_4(os_name) or self.is_distro_rhel_10(os_name):
90+
if self.is_distro_rhel_10(os_name):
9691
error_msg = "This distro is not yet supported in your region. Please review https://aka.ms/VMGuestPatchingCompatibility for more information. [Distro={0}][Version={1}][Code={2}]".format(str(os_name), os_version, os_code)
9792
print("Error: {0}".format(error_msg))
9893
return str()

src/core/src/package_managers/Dnf5PackageManager.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ def get_dependent_list(self, packages):
269269
self.composite_logger.log_verbose("[DNF5] Dependency simulation. [Command={0}][Code={1}]".format(cmd, str(code)))
270270
if code not in self.dnf5_simulation_valid_exit_codes:
271271
self.composite_logger.log_error("[DNF5] Unexpected failure. [Command={0}][Code={1}][Output={2}]".format(cmd, str(code), output))
272-
raise Exception("DNF5 dependency simulation failed")
272+
error_msg = "DNF5 dependency simulation failed. Investigate and resolve unexpected return code({0}) from package manager on command: {1} ".format(str(code), cmd)
273+
self.status_handler.add_error_to_status(error_msg, Constants.PatchOperationErrorCodes.DEFAULT_ERROR)
274+
raise Exception(error_msg, "[{0}]".format(Constants.ERROR_ADDED_TO_STATUS))
273275

274276
dependencies = self.extract_dependencies(output, packages)
275277
self.composite_logger.log_verbose("[DNF5] Resolved dependencies. [Command={0}][Packages={1}][DependencyCount={2}]".format(str(cmd), str(packages), len(dependencies)))
@@ -311,8 +313,6 @@ def extract_dependencies(self, output, packages):
311313
continue
312314

313315
# Remove input packages (support both pkg and pkg.arch)
314-
base_pkg = dependent_package_name.rsplit('.', 1)[0] if '.' in dependent_package_name else dependent_package_name
315-
316316
if len(dependent_package_name) != 0 and dependent_package_name not in packages and dependent_package_name not in dependencies:
317317
self.composite_logger.log_verbose("[DNF5] > Dependency detected: " + dependent_package_name)
318318
dependencies.append(dependent_package_name)
@@ -479,10 +479,8 @@ def is_service_set_to_enable_on_reboot(self, command):
479479
""" Checking if auto update is set to enable on reboot on the machine. An enable_on_reboot service will be activated (if currently inactive) on machine reboot """
480480
self.composite_logger.log_verbose("[DNF5] Checking if auto update service is set to enable on reboot. [Command={0}]".format(command))
481481
code, out = self.env_layer.run_command_output(command, False, False)
482-
#[inGuestLinux@vm-yashna-linux4 ~]$ systemctl is-enabled dnf5-automatic.timer
483-
# enabled
484-
is_enable_on_reboot = len(out.strip()) > 0 and code == 0 and out.strip() == "enabled"
485-
self.composite_logger.log_debug("[DNF5] Auto update service enable on reboot check completed. [Command={0}][Code={1}][EnabledOnReboot={2}]".format(command,str(code),str(is_enable_on_reboot)))
482+
is_enable_on_reboot = len(out.strip()) > 0 and code == 0 and out.strip().lower() == "enabled"
483+
self.composite_logger.log_debug("[DNF5] Auto update service enable on reboot check completed. [Command={0}][Code={1}][IsServiceSetToEnableOnReboot={2}]".format(command, str(code), str(is_enable_on_reboot)))
486484
return is_enable_on_reboot
487485

488486
def __get_extension_standard_value_for_apply_updates(self, apply_updates_value):
@@ -575,8 +573,8 @@ def backup_image_default_patch_configuration_if_not_exists(self):
575573
.format(str(image_default_patch_configuration_backup),self.image_default_patch_configuration_backup_path))
576574
self.env_layer.file_system.write_with_retry(self.image_default_patch_configuration_backup_path,'{0}'.format(json.dumps(image_default_patch_configuration_backup)),mode='w+')
577575
except Exception as error:
578-
self.composite_logger.log_error( "[DNF5] Exception during fetching and logging default auto update settings on the machine. [Exception={0}]".format(repr(error)))
579-
self.status_handler.add_error_to_status( "[DNF5] Exception during fetching and logging default auto update settings on the machine. [Exception={0}]".format(repr(error)), Constants.PatchOperationErrorCodes.DEFAULT_ERROR)
576+
self.composite_logger.log_error("[DNF5] Exception during fetching and logging default auto update settings on the machine. [Exception={0}]".format(repr(error)))
577+
self.status_handler.add_error_to_status("[DNF5] Exception during fetching and logging default auto update settings on the machine. [Exception={0}]".format(repr(error)), Constants.PatchOperationErrorCodes.DEFAULT_ERROR)
580578
raise
581579

582580
def is_image_default_patch_configuration_backup_valid(self, image_default_patch_configuration_backup):

src/core/tests/Test_Dnf5PackageManager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ def test_get_current_auto_os_patch_state_with_installed_services_and_state_enabl
187187
dnf5_automatic_os_patch_configuration_settings = 'apply_updates = yes\ndownload_updates = yes\n'
188188
self.runtime.write_to_file(package_manager.dnf5_automatic_configuration_file_path, dnf5_automatic_os_patch_configuration_settings)
189189

190+
is_enabled = package_manager.is_service_set_to_enable_on_reboot(package_manager.enable_on_reboot_check_cmd)
191+
self.assertFalse(is_enabled)
190192
current_auto_os_patch_state = package_manager.get_current_auto_os_patch_state()
191193

192194
self.assertFalse(package_manager.image_default_patch_configuration_backup_exists())
@@ -631,7 +633,6 @@ def test_disable_auto_os_update_on_reboot(self):
631633
command = "systemctl disable --now dnf5-automatic.timer"
632634

633635
package_manager.disable_auto_update_on_reboot(command)
634-
self.assertTrue(True) # method should NOT throw
635636

636637
self.runtime.set_legacy_test_type('AnotherSadPath')
637638
package_manager = self.container.get('package_manager')
@@ -722,8 +723,6 @@ def test_no_op_methods(self):
722723
package_manager.set_security_esm_package_status("op", [])
723724
package_manager.separate_out_esm_packages([], [])
724725

725-
self.assertTrue(True)
726-
727726
if __name__ == '__main__':
728727
unittest.main()
729728

src/core/tests/Test_EnvLayer.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@ def mock_distro_os_release_attr_return_azure_linux_2(self, attribute):
8080
def mock_distro_os_release_attr_return_none(self, attribute):
8181
return None
8282

83-
def mock_linux_distribution_to_return_azure_linux_4(self):
84-
return ['Microsoft Azure Linux', '4.0', '']
85-
86-
def mock_distro_os_release_attr_return_azure_linux_4(self, attribute):
87-
return '4.0.2'
88-
8983
def mock_linux_distribution_to_return_rhel_10(self):
9084
return ['Red Hat', '10.0', 'abc']
9185

@@ -159,17 +153,15 @@ def test_platform(self):
159153
self.envlayer.platform.vm_name()
160154

161155
def test_get_package_manager_azure_linux_4_and_rhel10_not_supported(self):
162-
"""Test that Azure Linux 4 and RHEL 10 log unsupported message"""
156+
"""Test for RHEL 10 log unsupported message"""
163157
self.backup_platform_system = platform.system
164158
self.backup_linux_distribution = self.envlayer.platform.linux_distribution
165159
self.backup_distro_os_release_attr = distro.os_release_attr
166160

167161
platform.system = self.mock_platform_system
168162
test_input_output_table = [
169-
[self.mock_linux_distribution_to_return_azure_linux_4, self.mock_distro_os_release_attr_return_azure_linux_4, "Error: This distro is not yet supported in your region. Please review https://aka.ms/VMGuestPatchingCompatibility for more information. [Distro=Microsoft Azure Linux][Version=4.0][Code=]\n"],
170163
[self.mock_linux_distribution_to_return_rhel_10, self.mock_distro_os_release_attr_return_rhel_10, "Error: This distro is not yet supported in your region. Please review https://aka.ms/VMGuestPatchingCompatibility for more information. [Distro=Red Hat][Version=10.0][Code=abc]\n"],
171164
]
172-
173165
for row in test_input_output_table:
174166
captured_output = StringIO()
175167
original_output = sys.stdout

0 commit comments

Comments
 (0)