Skip to content

Commit a945096

Browse files
committed
Azure Linux support: Addressing feedback #2
1 parent 4d46503 commit a945096

File tree

3 files changed

+91
-4
lines changed

3 files changed

+91
-4
lines changed

src/core/src/bootstrap/EnvLayer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class EnvLayer(object):
3737
def __init__(self, real_record_path=None, recorder_enabled=False, emulator_enabled=False):
3838
# Recorder / emulator storage
3939
self.__real_record_path = real_record_path
40-
self.__real_record_pointer_path = real_record_path + ".pt"
40+
self.__real_record_pointer_path = real_record_path + ".pt" if real_record_path is not None else None
4141
self.__real_record_handle = None
4242
self.__real_record_pointer = 0
4343

@@ -55,7 +55,7 @@ def __init__(self, real_record_path=None, recorder_enabled=False, emulator_enabl
5555
self.platform = self.Platform(recorder_enabled, emulator_enabled, self.__write_record, self.__read_record)
5656
self.datetime = self.DateTime(recorder_enabled, emulator_enabled, self.__write_record, self.__read_record)
5757
self.file_system = self.FileSystem(recorder_enabled, emulator_enabled, self.__write_record, self.__read_record,
58-
emulator_root_path=os.path.dirname(self.__real_record_path))
58+
emulator_root_path=os.path.dirname(self.__real_record_path) if self.__real_record_path is not None else self.__real_record_path)
5959

6060
# Constant paths
6161
self.etc_environment_file_path = "/etc/environment"

src/core/src/package_managers/TdnfPackageManager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(self, env_layer, execution_config, composite_logger, telemetry_writ
3131
super(TdnfPackageManager, self).__init__(env_layer, execution_config, composite_logger, telemetry_writer, status_handler)
3232
# Repo refresh
3333
self.cmd_clean_cache = "sudo tdnf clean expire-cache"
34-
self.cmd_repo_refresh_template = "sudo tdnf -q list updates"
34+
self.cmd_repo_refresh = "sudo tdnf -q list updates"
3535

3636
# Support to get updates and their dependencies
3737
self.tdnf_check = 'sudo tdnf -q list updates'
@@ -87,7 +87,7 @@ def __init__(self, env_layer, execution_config, composite_logger, telemetry_writ
8787
def refresh_repo(self):
8888
self.composite_logger.log("[TDNF] Refreshing local repo...")
8989
self.invoke_package_manager(self.cmd_clean_cache)
90-
self.invoke_package_manager(self.cmd_repo_refresh_template)
90+
self.invoke_package_manager(self.cmd_repo_refresh)
9191

9292
# region Get Available Updates
9393
def invoke_package_manager_advanced(self, command, raise_on_exception=True):

src/core/tests/Test_EnvLayer.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Copyright 2025 Microsoft Corporation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# Requires Python 2.7+
16+
import platform
17+
import unittest
18+
from core.src.bootstrap.EnvLayer import EnvLayer
19+
from core.src.bootstrap.Constants import Constants
20+
21+
22+
class TestExecutionConfig(unittest.TestCase):
23+
def setUp(self):
24+
self.envlayer = EnvLayer()
25+
26+
def tearDown(self):
27+
pass
28+
29+
# region setup mocks
30+
def mock_platform_system(self):
31+
return 'Linux'
32+
33+
def mock_linux_distribution(self):
34+
return ['test', 'test', 'test']
35+
36+
def mock_linux_distribution_to_return_azure_linux(self):
37+
return ['Microsoft Azure Linux', '3.0', '']
38+
39+
def mock_run_command_for_apt(self, cmd, no_output=False, chk_err=False):
40+
if cmd.find("which apt-get") > -1:
41+
return 0, ''
42+
return -1, ''
43+
44+
def mock_run_command_for_yum(self, cmd, no_output=False, chk_err=False):
45+
if cmd.find("which yum") > -1:
46+
return 0, ''
47+
return -1, ''
48+
49+
def mock_run_command_for_zypper(self, cmd, no_output=False, chk_err=False):
50+
if cmd.find("which zypper") > -1:
51+
return 0, ''
52+
return -1, ''
53+
54+
def mock_run_command_for_tdnf(self, cmd, no_output=False, chk_err=False):
55+
if cmd.find("which tdnf") > -1:
56+
return 0, ''
57+
return -1, ''
58+
# endregion
59+
60+
def test_get_package_manager(self):
61+
self.backup_platform_system = platform.system()
62+
platform.system = self.mock_platform_system
63+
self.backup_linux_distribution = self.envlayer.platform.linux_distribution
64+
self.envlayer.platform.linux_distribution = self.mock_linux_distribution
65+
self.backup_run_command_output = self.envlayer.run_command_output
66+
67+
test_input_output_table = [
68+
[self.mock_run_command_for_apt, self.mock_linux_distribution, Constants.APT],
69+
[self.mock_run_command_for_tdnf, self.mock_linux_distribution_to_return_azure_linux, Constants.TDNF],
70+
[self.mock_run_command_for_yum, self.mock_linux_distribution_to_return_azure_linux, None], # check for Azure Linux machine which does not have tdnf
71+
[self.mock_run_command_for_yum, self.mock_linux_distribution, Constants.YUM],
72+
[self.mock_run_command_for_zypper, self.mock_linux_distribution, Constants.ZYPPER],
73+
]
74+
75+
for row in test_input_output_table:
76+
self.envlayer.run_command_output = row[0]
77+
self.envlayer.platform.linux_distribution = row[1]
78+
package_manager = self.envlayer.get_package_manager()
79+
self.assertTrue(package_manager is row[2])
80+
81+
self.envlayer.run_command_output = self.backup_run_command_output
82+
self.envlayer.platform.linux_distribution = self.backup_linux_distribution
83+
platform.system = self.backup_platform_system
84+
85+
86+
if __name__ == '__main__':
87+
unittest.main()

0 commit comments

Comments
 (0)