Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/core/src/bootstrap/ConfigurationFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

from core.src.package_managers.AptitudePackageManager import AptitudePackageManager
from core.src.package_managers.AzL3TdnfPackageManager import AzL3TdnfPackageManager
from core.src.package_managers.DnfPackageManager import DnfPackageManager
from core.src.package_managers.Dnf5PackageManager import Dnf5PackageManager
from core.src.package_managers.YumPackageManager import YumPackageManager
from core.src.package_managers.ZypperPackageManager import ZypperPackageManager
Expand Down Expand Up @@ -72,20 +73,23 @@ def __init__(self, log_file_path, events_folder, telemetry_supported):

self.configurations = {
'apt_prod_config': self.new_prod_configuration(Constants.APT, AptitudePackageManager),
'dnf5_prod_config': self.new_prod_configuration(Constants.DNF5, Dnf5PackageManager),
'tdnf_prod_config': self.new_prod_configuration(Constants.TDNF, AzL3TdnfPackageManager),
'dnf_prod_config': self.new_prod_configuration(Constants.DNF, DnfPackageManager),
'dnf5_prod_config': self.new_prod_configuration(Constants.DNF5, Dnf5PackageManager),
'tdnf_prod_config': self.new_prod_configuration(Constants.TDNF, AzL3TdnfPackageManager),
'yum_prod_config': self.new_prod_configuration(Constants.YUM, YumPackageManager),
'zypper_prod_config': self.new_prod_configuration(Constants.ZYPPER, ZypperPackageManager),

'apt_dev_config': self.new_dev_configuration(Constants.APT, AptitudePackageManager),
'dnf5_dev_config': self.new_dev_configuration(Constants.DNF5, Dnf5PackageManager),
'tdnf_dev_config': self.new_dev_configuration(Constants.TDNF, AzL3TdnfPackageManager),
'dnf_dev_config': self.new_dev_configuration(Constants.DNF, DnfPackageManager),
'dnf5_dev_config': self.new_dev_configuration(Constants.DNF5, Dnf5PackageManager),
'tdnf_dev_config': self.new_dev_configuration(Constants.TDNF, AzL3TdnfPackageManager),
'yum_dev_config': self.new_dev_configuration(Constants.YUM, YumPackageManager),
'zypper_dev_config': self.new_dev_configuration(Constants.ZYPPER, ZypperPackageManager),

'apt_test_config': self.new_test_configuration(Constants.APT, AptitudePackageManager),
'dnf5_test_config': self.new_test_configuration(Constants.DNF5, Dnf5PackageManager),
'tdnf_test_config': self.new_test_configuration(Constants.TDNF, AzL3TdnfPackageManager),
'dnf_test_config': self.new_test_configuration(Constants.DNF, DnfPackageManager),
'dnf5_test_config': self.new_test_configuration(Constants.DNF5, Dnf5PackageManager),
'tdnf_test_config': self.new_test_configuration(Constants.TDNF, AzL3TdnfPackageManager),

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.

nit: Indentations are still not consistent in all configs

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

'yum_test_config': self.new_test_configuration(Constants.YUM, YumPackageManager),
'zypper_test_config': self.new_test_configuration(Constants.ZYPPER, ZypperPackageManager)
}
Expand Down Expand Up @@ -121,7 +125,7 @@ def get_configuration(self, env, package_manager_name):
print ("Error: Environment configuration not supported - " + str(env))
return None

if str(package_manager_name) not in [Constants.APT, Constants.DNF5, Constants.TDNF, Constants.YUM, Constants.ZYPPER]:
if str(package_manager_name) not in [Constants.APT, Constants.DNF, Constants.DNF5, Constants.TDNF, Constants.YUM, Constants.ZYPPER]:
print ("Error: Package manager configuration not supported - " + str(package_manager_name))
return None

Expand Down
1 change: 1 addition & 0 deletions src/core/src/bootstrap/Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ class StatusTruncationConfig(EnumBackport):

# Package Managers
APT = 'apt'
DNF = 'dnf'
DNF5 = 'dnf5'
TDNF = 'tdnf'
YUM = 'yum'
Expand Down
61 changes: 40 additions & 21 deletions src/core/src/bootstrap/EnvLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,30 @@ def is_distro_azure_linux_4(self, distro_name):

def is_distro_rhel_10(self, distro_name):
# type: (str) -> bool
""" Checks if the current distro is RHEL 10 """
""" Checks if the current distro is RHEL 10"""
return self.__is_matching_distro_and_version(distro_name, Constants.RED_HAT, version_to_match=10)

def __get_dnf_version(self):
code, out = self.run_command_output('dnf --version', False, False)
# Output : dnf5 version 5.2.18.0
def __get_dnf_version(self, package_name='dnf'):
"""Fetches the major version of the dnf package installed on the VM using rpm query."""
# Output example:
# $[inGuestLinux@yashna-linux4 ~]$ rpm -q --queryformat '%{VERSION}' dnf5
# 5.2.18.0

# [inGuestLinux@yashna-linux4 ~]$ rpm - q - -queryformat '%{VERSION}' dnf
# package dnf is not installed

# inGuestLinux@yashna-rhel10-auto:~$ rpm -q --queryformat '%{VERSION}' dnf
# 4.20.0
code, out = self.run_command_output("rpm -q --queryformat '%{{VERSION}}' {0}".format(package_name), False, False)
if code != 0 or not out:
return code, out, None
version = str(out).split()[-1].split('.')[0]
return code, out, version

version_str = str(out).strip()
if not version_str or not version_str[0].isdigit():
return code, out, None

major_version = version_str.split('.')[0]
return code, out, major_version

def get_package_manager(self):
# type: () -> str
Expand All @@ -99,22 +113,27 @@ def get_package_manager(self):
# Example: ['Azure Linux', '4.0', '']
os_name, os_version, os_code = self.platform.linux_distribution()

# Check for unsupported distros
if self.is_distro_rhel_10(os_name):
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)
print("Error: {0}".format(error_msg))
return str()

# Check for Azure Linux 4 or Above( uses dnf5)
if self.is_distro_azure_linux_4(str(os_name)):
code, out, version = self.__get_dnf_version()
if code == 0 and version == '5':
return Constants.DNF5
elif code == 0 and version != '5':
print("Error: Expected dnf version not found on this Azure Linux4 VM. [Expected={0}][Found={1}]".format("5", str(version)))
# Check for RHEL 10 (uses dnf4) or Azure Linux 4 (uses dnf5)
if self.is_distro_rhel_10(os_name) or self.is_distro_azure_linux_4(str(os_name)):
pkg_name = 'dnf5' if self.is_distro_azure_linux_4(str(os_name)) else 'dnf'
code, out, version = self.__get_dnf_version(pkg_name)

if self.is_distro_rhel_10(os_name):
if code == 0 and version == '4':
return Constants.DNF
elif code == 0:
print("Error: Expected dnf version not found on this RHEL 10 VM. [Expected={0}][Found={1}]".format("4", str(version)))
else:
print("Error: Expected package manager dnf not found on this RHEL 10 VM. [Code={0}][Output={1}]".format(str(code), str(out)))
return str()
else:
print("Error: Expected package manager dnf5 not found on this Azure Linux4 VM")

if self.is_distro_azure_linux_4(str(os_name)):
if code == 0 and version == '5':
return Constants.DNF5
elif code == 0:
print("Error: Expected dnf version not found on this Azure Linux4 VM. [Expected={0}][Found={1}]".format("5", str(version)))
else:
print("Error: Expected package manager dnf5 not found on this Azure Linux4 VM. [Code={0}][Output={1}]".format(str(code), str(out)))
return str()

# Check for Azure Linux (3 and below use TDNF)
Expand Down
Loading
Loading