Skip to content

Commit f4fe6ac

Browse files
committed
Raise Exception for Azure Linux4 and RHEL10 not supoorted yet
1 parent 525a32f commit f4fe6ac

2 files changed

Lines changed: 69 additions & 2 deletions

File tree

src/core/src/bootstrap/EnvLayer.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def is_distro_azure_linux(distro_name):
4949

5050
def is_distro_azure_linux_3_or_beyond(self):
5151
# type: () -> bool
52-
""" Checks if the current distro is Azure Linux 3 """
52+
""" Checks if the current distro is Azure Linux 3 or beyond """
5353
if self.is_distro_azure_linux(self.platform.linux_distribution()):
5454
version = distro.os_release_attr('version')
5555
major = version.split('.')[0] if version else None
@@ -62,15 +62,33 @@ def get_package_manager(self):
6262
if platform.system() == 'Windows':
6363
return Constants.APT
6464

65+
version = distro.os_release_attr('version')
66+
major = version.split('.')[0] if version else None
67+
os_id = distro.id()
68+
69+
# Check for Azure Linux
6570
if self.is_distro_azure_linux(str(self.platform.linux_distribution())):
71+
# Azure Linux 4 not yet supported
72+
if major is not None and int(major) >= 4:
73+
error_msg = "Azure Linux 4 is not yet supported in your region. Please review aka.ms/LinuxPatchExtension for more information."
74+
print("Error: {0}".format(error_msg))
75+
raise Exception(error_msg)
76+
77+
# Azure Linux 3 and below use TDNF
6678
code, out = self.run_command_output('which tdnf', False, False)
6779
if code == 0:
6880
return Constants.TDNF
6981
else:
7082
print("Error: Expected package manager tdnf not found on this Azure Linux VM.")
7183
return str()
7284

73-
# choose default package manager
85+
# Check for RHEL 10 (not yet supported)
86+
if os_id == "rhel" and major is not None and int(major) >= 10:
87+
error_msg = "RHEL 10 is not yet supported in your region. Please review aka.ms/LinuxPatchExtension for more information."
88+
print("Error: {0}".format(error_msg))
89+
raise Exception(error_msg)
90+
91+
# Choose default package manager
7492
package_manager_map = (('apt-get', Constants.APT),
7593
('yum', Constants.YUM),
7694
('zypper', Constants.ZYPPER))

src/core/tests/Test_EnvLayer.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ def mock_distro_os_release_attr_return_azure_linux_2(self, attribute):
7171

7272
def mock_distro_os_release_attr_return_none(self, attribute):
7373
return None
74+
75+
def mock_distro_os_release_attr_return_azure_linux_4(self, attribute):
76+
return '4.0.2'
77+
78+
def mock_distro_os_release_attr_return_rhel_10(self, attribute):
79+
return '10.0'
80+
81+
def mock_linux_distribution_to_return_azure_linux_4(self):
82+
return ['Microsoft Azure Linux', '4.0', '']
83+
84+
def mock_distro_id_return_rhel(self):
85+
return 'rhel'
7486
# endregion
7587

7688
def test_get_package_manager(self):
@@ -139,6 +151,43 @@ def test_platform(self):
139151
self.envlayer.platform.cpu_arch()
140152
self.envlayer.platform.vm_name()
141153

154+
def test_get_package_manager_azure_linux_4_not_supported(self):
155+
"""Test that Azure Linux 4 raises an exception"""
156+
self.backup_linux_distribution = self.envlayer.platform.linux_distribution
157+
self.backup_distro_os_release_attr = distro.os_release_attr
158+
159+
platform.system = self.mock_platform_system
160+
self.envlayer.platform.linux_distribution = self.mock_linux_distribution_to_return_azure_linux_4
161+
distro.os_release_attr = self.mock_distro_os_release_attr_return_azure_linux_4
162+
163+
with self.assertRaises(Exception) as context:
164+
self.envlayer.get_package_manager()
165+
self.assertEqual(str(context.exception), "Azure Linux 4 is not yet supported in your region. Please review aka.ms/LinuxPatchExtension for more information.")
166+
167+
# restore
168+
distro.os_release_attr = self.backup_distro_os_release_attr
169+
self.envlayer.platform.linux_distribution = self.backup_linux_distribution
170+
171+
def test_get_package_manager_rhel_10_not_supported(self):
172+
"""Test that RHEL 10 raises an exception"""
173+
self.backup_linux_distribution = self.envlayer.platform.linux_distribution
174+
self.backup_distro_os_release_attr = distro.os_release_attr
175+
self.backup_distro_id = distro.id
176+
177+
platform.system = self.mock_platform_system
178+
self.envlayer.platform.linux_distribution = self.mock_linux_distribution
179+
distro.os_release_attr = self.mock_distro_os_release_attr_return_rhel_10
180+
distro.id = self.mock_distro_id_return_rhel
181+
182+
with self.assertRaises(Exception) as context:
183+
self.envlayer.get_package_manager()
184+
self.assertEqual(str(context.exception), "RHEL 10 is not yet supported in your region. Please review aka.ms/LinuxPatchExtension for more information.")
185+
186+
# restore
187+
distro.id = self.backup_distro_id
188+
distro.os_release_attr = self.backup_distro_os_release_attr
189+
self.envlayer.platform.linux_distribution = self.backup_linux_distribution
190+
142191

143192
if __name__ == '__main__':
144193
unittest.main()

0 commit comments

Comments
 (0)