Skip to content

Feature: Adding Azure Linux 4.0 Base Support using dnf5 package manager#343

Open
yashnap wants to merge 9 commits into
masterfrom
37454066_dnf5_packageManager_support
Open

Feature: Adding Azure Linux 4.0 Base Support using dnf5 package manager#343
yashnap wants to merge 9 commits into
masterfrom
37454066_dnf5_packageManager_support

Conversation

@yashnap
Copy link
Copy Markdown
Contributor

@yashnap yashnap commented May 11, 2026

Implemented DnfPackageManager by extending PackageManager instead of TdnfPackageManager.
DNF5 behavior (output, classification, dependency resolution) differs from Tdnf making reuse unsafe. This approach keeps the implementation clean with dnf5 capabilities.

  • Added ConfigurationFactory, EnvLayer and Constants change needed across the board for all operations

FIRST ITERATION ( Enablement/Disablement)

  • Added changes to support detection, enablement and disablement.

Implemented the below methods:

  • get_current_auto_os_patch_state,

  • disable_auto_os_update,

  • disable_auto_os_update_for_dnf5_automatic,

  • disable_auto_update_on_reboot,

  • is_auto_update_service_installed,

  • is_service_set_to_enable_on_reboot,

  • enable_auto_update_on_reboot

  • Added few UT's to cover the implementation(more to follow)

TESTING

  • Tested it on Linux 4 VM by creating a helper script to detect, disable and enable OS update using dnf5-automatic

ARM ID : /subscriptions/6acc8a91-e2b0-4041-a069-c2932ab42fd9/resourceGroups/rg-yashna-linux4-test-wus2/providers/Microsoft.Compute/virtualMachines/vm-yashna-linux4

Enablement_Disablement

<--------------------ITERATION2------------------------->

  • Automatic assessment (configuring, running, reporting, disablement)

output.txt

<------------------ITERATION3---------------->

  • Assess, Install and Reboot Detection
  1. Install Update package available
    output.txt

  2. All packages are upto date and already installed
    output_alreadyUptoDate.txt

Copilot AI review requested due to automatic review settings May 11, 2026 20:48
@yashnap yashnap force-pushed the 37454066_dnf5_packageManager_support branch from 7ddf13b to c615038 Compare May 11, 2026 20:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Introduces an Azure Linux 4–specific DNF (dnf5) package manager implementation and wires it into distro/package-manager detection so Azure Linux 4 selects DNF instead of TDNF.

Changes:

  • Added AzL4DnfPackageManager skeleton class extending PackageManager.
  • Updated Azure Linux package manager detection to choose DNF for Azure Linux 4+ and TDNF for Azure Linux 3.
  • Added Constants.DNF and registered DNF configurations in ConfigurationFactory.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/core/src/package_managers/AzL4DnfPackageManager.py Adds a new (currently stubbed) DNF-based package manager for Azure Linux 4.
src/core/src/bootstrap/EnvLayer.py Selects DNF for Azure Linux 4+ and keeps TDNF for Azure Linux 3.
src/core/src/bootstrap/Constants.py Introduces a DNF constant used by configuration selection.
src/core/src/bootstrap/ConfigurationFactory.py Registers DNF configs and maps them to AzL4DnfPackageManager.
Comments suppressed due to low confidence (1)

src/core/src/bootstrap/EnvLayer.py:1

  • This error path drops useful diagnostics. Consider including the command result (out) and/or the checked path in the message so failures are actionable (e.g., when dnf is installed but not on PATH). Also, returning str() (empty string) makes it hard to distinguish 'not found' vs 'unknown'; consider returning None or a dedicated sentinel, depending on existing conventions in this module.
# Copyright 2020 Microsoft Corporation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +34 to +40
def refresh_repo(self):
"""Refreshes the DNF repository cache and lists available updates by cleaning expired cache entries
Commands:
- sudo dnf clean expire-cache (cleans expired cache entries)
- sudo dnf -q check-update (checks for available updates)
"""
pass
Comment on lines +54 to +76
def get_all_updates(self, cached=False):
"""Gets all missing updates available for the system and returns the cached updates list and versions list
Cache Check Logic:
- If cached=True and cache has data, return cached updates and versions immediately (high performance reuse)
- If cache miss or cached=False, execute the DNF command to get fresh updates and populate cache
Command:
- sudo dnf -q check-update (checks for all available updates)
1. If cached=True and cache has data, return cached results
2. Execute command, parse output, cache results
3. Return all_updates_cached and all_update_versions_cached
"""
return [], []

# AssessPatch method
def get_security_updates(self):
"""Gets all missing security updates available for the system and returns packages and versions list
Command:
- sudo dnf -q check-update --security (checks for available security updates only)
Returns:
- List of security package names
- List of corresponding security package versions
"""
pass
Comment thread src/core/src/bootstrap/EnvLayer.py Outdated
if major is not None and int(major) >= 4:
code, out = self.run_command_output('which dnf', False, False)
if code == 0:
return 'dnf'
"""
return [], []

def set_max_patch_publish_date(self, max_patch_publish_date=str()):
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

❌ Patch coverage is 62.84047% with 191 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.99%. Comparing base (6f0af88) to head (43cf0fa).

Files with missing lines Patch % Lines
...rc/core/src/package_managers/Dnf5PackageManager.py 53.82% 187 Missing ⚠️
src/core/tests/Test_Dnf5PackageManager.py 96.22% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #343      +/-   ##
==========================================
- Coverage   93.84%   92.99%   -0.85%     
==========================================
  Files         105      107       +2     
  Lines       18218    18731     +513     
==========================================
+ Hits        17096    17419     +323     
- Misses       1122     1312     +190     
Flag Coverage Δ
python27 92.99% <62.84%> (-0.85%) ⬇️
python312 92.99% <62.84%> (-0.85%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@yashnap yashnap force-pushed the 37454066_dnf5_packageManager_support branch from b081d06 to 1b80cf7 Compare May 19, 2026 17:33
Comment thread src/core/src/package_managers/DnfPackageManager.py Fixed
Comment thread src/core/tests/Test_DnfPackageManager.py Fixed
Comment thread src/core/tests/Test_DnfPackageManager.py Fixed
@yashnap yashnap force-pushed the 37454066_dnf5_packageManager_support branch from 0a05123 to 9b9fd31 Compare May 20, 2026 18:43
@yashnap yashnap changed the title Skeleton PR for dnf5 linux4 implementation Feature: Adding Azure Linux 4.0 Base Support using dnf5 package manager May 20, 2026
@yashnap yashnap force-pushed the 37454066_dnf5_packageManager_support branch from 6fdc513 to d42304e Compare May 21, 2026 22:41
@yashnap yashnap force-pushed the 37454066_dnf5_packageManager_support branch from d42304e to b950de5 Compare May 21, 2026 22:42
Comment thread src/core/src/package_managers/DnfPackageManager.py Fixed
Comment thread src/core/tests/Test_Dnf5PackageManager.py Fixed
@rane-rajasi
Copy link
Copy Markdown
Contributor

rane-rajasi commented May 26, 2026

Implemented DnfPackageManager by extending PackageManager instead of TdnfPackageManager. DNF5 behavior (output, classification, dependency resolution) differs from Tdnf making reuse unsafe. This approach keeps the implementation clean with dnf5 capabilities.

  • Added ConfigurationFactory, EnvLayer and Constants change needed across the board for all operations

FIRST ITERATION ( Enablement/Disablement)

  • Added changes to support detection, enablement and disablement.

Implemented the below methods:

  • get_current_auto_os_patch_state,
  • disable_auto_os_update,
  • disable_auto_os_update_for_dnf5_automatic,
  • disable_auto_update_on_reboot,
  • is_auto_update_service_installed,
  • is_service_set_to_enable_on_reboot,
  • enable_auto_update_on_reboot
  • Added few UT's to cover the implementation(more to follow)

TESTING

  • Tested it on Linux 4 VM by creating a helper script to detect, disable and enable OS update using dnf5-automatic

ARM ID : /subscriptions/6acc8a91-e2b0-4041-a069-c2932ab42fd9/resourceGroups/rg-yashna-linux4-test-wus2/providers/Microsoft.Compute/virtualMachines/vm-yashna-linux4

Enablement_Disablement <--------------------ITERATION2------------------------->
  • Automatic assessment (configuring, running, reporting, disablement)

output.txt

"Implemented DnfPackageManager by extending PackageManager instead of TdnfPackageManager.
DNF5 behavior (output, classification, dependency resolution) differs from Tdnf making reuse unsafe. This approach keeps the implementation clean with dnf5 capabilities."

You are adding dnf5 support to AzLinux4 and not replacing Tdnf in this PR. TdnfPackageManager will still be used in AzLinux3 post this PR.


from core.src.package_managers.AptitudePackageManager import AptitudePackageManager
from core.src.package_managers.AzL3TdnfPackageManager import AzL3TdnfPackageManager
from core.src.package_managers.DnfPackageManager import DnfPackageManager
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dnf5PackageManager

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated naming everywhere with dnf5


self.configurations = {
'apt_prod_config': self.new_prod_configuration(Constants.APT, AptitudePackageManager),
'dnf_prod_config': self.new_prod_configuration(Constants.DNF, DnfPackageManager),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use dnf5 everywhere

Comment thread src/core/src/bootstrap/Constants.py Outdated

# Package Managers
APT = 'apt'
DNF = 'dnf'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dnf5

#
# Requires Python 2.7+

"""DnfPackageManager for Azure Linux L4 and RHEL 10"""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not mention the image restrictions within packagemanager. Restrictions would only come from the places where it is set/invoked and not within the package manager implementation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed image restrictions.



class DnfPackageManager(PackageManager):
"""Implementation of Azure Linux L4/RHEL 10 DNF5 package management operations"""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as on line 17

return Constants.AutomaticOSPatchStates.DISABLED

if enable_on_reboot_value:
return Constants.AutomaticOSPatchStates.ENABLED
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if apply_updates_value is enabled?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above


if enable_on_reboot_value:
return Constants.AutomaticOSPatchStates.ENABLED

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you map out a matrix on all the possible values of: is_service_installed, enable_on_reboot_value, download_updates_value, apply_updates_value and how it affects auto_os_patch_state_for_dnf5_automatic?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in the document

enable_on_reboot_value = self.is_service_set_to_enable_on_reboot(self.enable_on_reboot_check_cmd)

self.composite_logger.log_debug(
"[DNF] Checking if auto updates are currently enabled...")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

except Exception as error:
raise Exception(
"[DNF] Error occurred in fetching current auto OS update settings from the machine (dnf5). [Exception={0}]".format(
repr(error)))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enabling and disabling Auto OS updates is slightly more involved than what is implemented here. There's more checks and balances that are missed. Will try to cover it in offline sync.

But a suggestion here is, try to closely follow what is already implemented in tdnf, it will be same or very similar for dnf. Create an AzL3 VM, see how auto OS update works in it, you can try running the cmds in it to understand what is happening and then re-create the process for AzL4

package_manager.get_current_auto_os_patch_state = self.runtime.backup_get_current_auto_os_patch_state

# Mock the systemctl cat output with enabled flags
systemctl_cat_output = '''[Unit]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refer existing UTs on how mocks are implemented within the code base

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am adding UTs to cover all scenarios . Will review the existing code on how it done.

self.install_check_cmd = self.dnf5_automatic_install_check_cmd
self.current_auto_os_update_service = self.dnf5_auto_os_update_service

def __get_current_auto_os_updates_setting_on_machine(self):
def test_refresh_repo(self):
self.runtime.set_legacy_test_type('HappyPath')
package_manager = self.container.get('package_manager')
self.assertTrue(package_manager is not None)
@yashnap
Copy link
Copy Markdown
Contributor Author

yashnap commented May 26, 2026

Note: Renamed the DNfPackageManager file to DNF5 =PackageManager along with code updates, which caused Git to show it as a delete + add. The logic changes are incremental, but previous comments may appear outdated due to this artifact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants