-
Notifications
You must be signed in to change notification settings - Fork 17
Address Pending Comments from Dnf5 Original PR #355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
5898393
ae0cbce
735c1c9
b8c8fec
8adaa58
1c9c1ff
e8dd90b
3f55363
460f146
0ebb826
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,9 @@ def mock_platform_system_windows(self): | |
| def mock_linux_distribution(self): | ||
| return ['test', 'test', 'test'] | ||
|
|
||
| def mock_linux_distribution_to_return_azure_linux_4(self): | ||
| return ['Microsoft Azure Linux', '4.0', ''] | ||
|
|
||
| def mock_linux_distribution_to_return_azure_linux_3(self): | ||
| return ['Microsoft Azure Linux', '3.0', ''] | ||
|
|
||
|
|
@@ -71,6 +74,14 @@ def mock_run_command_for_tdnf(self, cmd, no_output=False, chk_err=False): | |
| return 0, '' | ||
| return -1, '' | ||
|
|
||
| def mock_run_command_for_dnf5(self, cmd, no_output=False, chk_err=False): | ||
| if cmd.find("dnf --version") > -1: | ||
| return 0, '5.2.0' | ||
| return -1, '' | ||
|
Comment on lines
+77
to
+82
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is a mock, no need for actual path. Keeping it as is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added path for which dnf command |
||
|
|
||
| def mock_distro_os_release_attr_return_azure_linux_4(self, attribute): | ||
| return '4.0.0' | ||
|
|
||
| def mock_distro_os_release_attr_return_azure_linux_3(self, attribute): | ||
| return '3.0.0' | ||
|
|
||
|
|
@@ -96,18 +107,20 @@ def test_get_package_manager(self): | |
| self.backup_distro_os_release_attr = distro.os_release_attr | ||
|
|
||
| test_input_output_table = [ | ||
| [self.mock_run_command_for_apt, self.mock_linux_distribution, Constants.APT], | ||
| [self.mock_run_command_for_tdnf, self.mock_linux_distribution_to_return_azure_linux_3, Constants.TDNF], | ||
| [self.mock_run_command_for_yum, self.mock_linux_distribution_to_return_azure_linux_3, str()], # check for Azure Linux machine which does not have tdnf | ||
| [self.mock_run_command_for_tdnf, self.mock_linux_distribution_to_return_azure_linux_2, Constants.TDNF], | ||
| [self.mock_run_command_for_yum, self.mock_linux_distribution, Constants.YUM], | ||
| [self.mock_run_command_for_zypper, self.mock_linux_distribution, Constants.ZYPPER], | ||
| [lambda cmd, no_output, chk_err: (-1, ''), self.mock_linux_distribution, str()], # no matches for any package manager | ||
| [self.mock_run_command_for_apt, self.mock_linux_distribution, Constants.APT, self.mock_distro_os_release_attr_return_none], | ||
| [self.mock_run_command_for_dnf5, self.mock_linux_distribution_to_return_azure_linux_4, Constants.DNF5, self.mock_distro_os_release_attr_return_azure_linux_4], | ||
| [self.mock_run_command_for_tdnf, self.mock_linux_distribution_to_return_azure_linux_3, Constants.TDNF, self.mock_distro_os_release_attr_return_azure_linux_3], | ||
| [self.mock_run_command_for_yum, self.mock_linux_distribution_to_return_azure_linux_3, str(), self.mock_distro_os_release_attr_return_none], # check for Azure Linux machine which does not have tdnf | ||
| [self.mock_run_command_for_tdnf, self.mock_linux_distribution_to_return_azure_linux_2, Constants.TDNF, self.mock_distro_os_release_attr_return_azure_linux_3], | ||
|
Copilot marked this conversation as resolved.
Outdated
|
||
| [self.mock_run_command_for_yum, self.mock_linux_distribution, Constants.YUM, self.mock_distro_os_release_attr_return_none], | ||
| [self.mock_run_command_for_zypper, self.mock_linux_distribution, Constants.ZYPPER, self.mock_distro_os_release_attr_return_none], | ||
| [lambda cmd, no_output, chk_err: (-1, ''), self.mock_linux_distribution, str(), self.mock_distro_os_release_attr_return_none], # no matches for any package manager | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added 4th column to address the following issue:
|
||
| ] | ||
|
|
||
| for row in test_input_output_table: | ||
| self.envlayer.run_command_output = row[0] | ||
| self.envlayer.platform.linux_distribution = row[1] | ||
| distro.os_release_attr = row[3] | ||
| package_manager = self.envlayer.get_package_manager() | ||
| self.assertTrue(package_manager is row[2]) | ||
|
Copilot marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
@@ -118,6 +131,7 @@ def test_get_package_manager(self): | |
| # restore original methods | ||
| self.envlayer.run_command_output = self.backup_run_command_output | ||
| self.envlayer.platform.linux_distribution = self.backup_linux_distribution | ||
| distro.os_release_attr = self.backup_distro_os_release_attr | ||
| platform.system = self.backup_platform_system | ||
|
|
||
| def test_is_distro_azure_linux_3(self): | ||
|
|
@@ -138,6 +152,23 @@ def test_is_distro_azure_linux_3(self): | |
| # restore original methods | ||
| distro.os_release_attr = self.backup_envlayer_distro_os_release_attr | ||
|
|
||
| def test_is_distro_azure_linux_4(self): | ||
| self.backup_envlayer_distro_os_release_attr = distro.os_release_attr | ||
|
|
||
| test_input_output_table = [ | ||
| [self.mock_linux_distribution_to_return_azure_linux_4, self.mock_distro_os_release_attr_return_azure_linux_4, True], | ||
| [self.mock_linux_distribution_to_return_azure_linux_4, self.mock_distro_os_release_attr_return_none, False] | ||
| ] | ||
|
|
||
| for row in test_input_output_table: | ||
| distro_name = row[0]()[0] # Extract distro name from tuple (first element) | ||
| distro.os_release_attr = row[1] | ||
| result = self.envlayer.is_distro_azure_linux_4(distro_name) | ||
| self.assertEqual(result, row[2]) | ||
|
|
||
| # restore original methods | ||
| distro.os_release_attr = self.backup_envlayer_distro_os_release_attr | ||
|
|
||
| def test_filesystem(self): | ||
| # only validates if these invocable without exceptions | ||
| backup_retry_count = Constants.MAX_FILE_OPERATION_RETRY_COUNT | ||
|
|
@@ -152,7 +183,7 @@ def test_platform(self): | |
| self.envlayer.platform.cpu_arch() | ||
| self.envlayer.platform.vm_name() | ||
|
|
||
| def test_get_package_manager_azure_linux_4_and_rhel10_not_supported(self): | ||
| def test_get_package_manager_rhel10_not_supported(self): | ||
| """Test for RHEL 10 log unsupported message""" | ||
| self.backup_platform_system = platform.system | ||
| self.backup_linux_distribution = self.envlayer.platform.linux_distribution | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combined which dnf + version check into one. Currently we have a separate check for dnf4 use-case( RHEL 10) in our case. Keeping this as is. If there is no dnf present it will error out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not diagnosable as-is in the error condition. If we see this error line provided to you: "Error: Expected package manager dnf5 not found on this Azure Linux4 VM." -- without getting access to the VM, what do we know about what went wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense. I've made changes to separate the check and add logging for easier diagnosis without having access o the VM.