Skip to content

Commit

Permalink
Obsolete packages should not be attempted to install (#212)
Browse files Browse the repository at this point in the history
* Obsolete packages should not be attempted to install

* Remove non required changes from test code.

* Using strip() to remove leading and trailing spaces

---------

Co-authored-by: Koshy John <[email protected]>
  • Loading branch information
GAURAVRAMRAKHYANI and kjohn-msft authored Sep 19, 2023
1 parent 5d83323 commit 37d1596
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/src/package_managers/YumPackageManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ def is_package(chunk):
lines = output.strip().split('\n')

for line_index in range(0, len(lines)):
# Do not install Obsoleting Packages. The obsoleting packages list comes towards end in the output.
if lines[line_index].strip().startswith("Obsoleting Packages"):
break

line = re.split(r'\s+', lines[line_index].strip())
next_line = []

Expand Down
9 changes: 9 additions & 0 deletions src/core/tests/Test_YumPackageManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,15 @@ def test_is_reboot_pending_return_true_when_exception_raised(self):

package_manager.do_processes_require_restart = backup_do_process_require_restart

def test_obsolete_packages_should_not_considered_in_available_updates(self):
self.runtime.set_legacy_test_type('ObsoletePackages')
package_manager = self.container.get('package_manager')
package_filter = self.container.get('package_filter')
available_updates, package_versions = package_manager.get_available_updates(package_filter)
self.assertEqual(len(available_updates), 1)
self.assertEqual(len(package_versions), 1)
self.assertTrue(available_updates[0] == "grub2-tools.x86_64")
self.assertTrue(package_versions[0] == "1:2.02-142.el8")

if __name__ == '__main__':
unittest.main()
15 changes: 15 additions & 0 deletions src/core/tests/library/LegacyEnvLayerExtensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,21 @@ def run_command_output(self, cmd, no_output=False, chk_err=True):
entry = template.replace('<PACKAGE>', package)
entry = entry.replace('<VERSION>', version)
output += entry
elif self.legacy_test_type == 'ObsoletePackages':
if self.legacy_package_manager_name is Constants.YUM:
if cmd.find("check-update") > -1:
code = 100
output = "\n" + \
"grub2-tools.x86_64 " + \
"1:2.02-142.el8 " + \
"rhel-8-baseos-rhui-rpms\n" + \
"Obsoleting Packages\n" + \
"grub2-tools.x86_64 " + \
"1:2.02-123.el8_6.8 " + \
"rhel-8-baseos-rhui-rpms\n" + \
" grub2-tools.x86_64 " + \
"1:2.02-123.el8 " + \
"@System\n"

major_version = self.get_python_major_version()
if major_version == 2:
Expand Down

0 comments on commit 37d1596

Please sign in to comment.