Skip to content

Commit

Permalink
Updated unit tests for increasing batch size from 3 to 6
Browse files Browse the repository at this point in the history
  • Loading branch information
GAURAVRAMRAKHYANI committed Nov 17, 2023
1 parent b3282e2 commit 8f0c38c
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 18 deletions.
33 changes: 18 additions & 15 deletions src/core/tests/Test_PatchInstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,15 @@ def test_dependency_installed_successfully(self):
runtime.set_legacy_test_type('DependencyInstallSuccessfully')
# As all the packages should get installed using batch patching, get_remaining_packages_to_install should return 0 packages
installed_update_count, update_run_successful, maintenance_window_exceeded = runtime.patch_installer.install_updates(runtime.maintenance_window, runtime.package_manager, simulate=True)
self.assertEqual(4, installed_update_count)
self.assertEqual(7, installed_update_count)
self.assertTrue(update_run_successful)
self.assertFalse(maintenance_window_exceeded)
runtime.stop()

def test_dependency_install_failed(self):
# exclusion list contains grub-efi-amd64-bin
# grub-efi-amd64-signed is dependent on grub-efi-amd64-bin, so grub-efi-amd64-signed should also get excluded
# so, out of 7 packages, only 5 packages are installed and 2 are excluded
current_time = datetime.datetime.utcnow()
td = datetime.timedelta(hours=0, minutes=20)
job_start_time = (current_time - td).strftime("%Y-%m-%dT%H:%M:%S.9999Z")
Expand All @@ -353,13 +356,13 @@ def test_dependency_install_failed(self):
# Path change
runtime.set_legacy_test_type('DependencyInstallFailed')
installed_update_count, update_run_successful, maintenance_window_exceeded = runtime.patch_installer.install_updates(runtime.maintenance_window, runtime.package_manager, simulate=True)
self.assertEqual(2, installed_update_count)
self.assertEqual(5, installed_update_count)
self.assertFalse(update_run_successful)
self.assertFalse(maintenance_window_exceeded)
runtime.stop()

def test_not_enough_time_for_batch_patching_dependency_installed_successfully(self):
# total packages to install is 3, reboot_setting is 'Never', so cutoff time for batch = 3*5 = 15
# total packages to install is 7, reboot_setting is 'Never', cutoff time for batch of 6 packages = (5*3) + (2*3) = 21
# window size is 60 minutes, let time remain = 14 minutes so that not enough time to install in batch
# So td = 60-14 = 46
current_time = datetime.datetime.utcnow()
Expand All @@ -373,13 +376,13 @@ def test_not_enough_time_for_batch_patching_dependency_installed_successfully(se
# Path change
runtime.set_legacy_test_type('DependencyInstallSuccessfully')
installed_update_count, update_run_successful, maintenance_window_exceeded = runtime.patch_installer.install_updates(runtime.maintenance_window, runtime.package_manager, simulate=True)
self.assertEqual(4, installed_update_count)
self.assertEqual(7, installed_update_count)
self.assertTrue(update_run_successful)
self.assertFalse(maintenance_window_exceeded)
runtime.stop()

def test_not_enough_time_for_batch_patching_dependency_install_failed(self):
# total packages to install is 3, reboot_setting is 'Never', so cutoff time for batch = 3*5 = 15
# total packages to install is 7, reboot_setting is 'Never', so cutoff time for batch = (5*3) + (2*3) = 21
# window size is 60 minutes, let time remain = 14 minutes so that not enough time to install in batch
# So td = 60-14 = 46
current_time = datetime.datetime.utcnow()
Expand All @@ -393,7 +396,7 @@ def test_not_enough_time_for_batch_patching_dependency_install_failed(self):
# Path change
runtime.set_legacy_test_type('DependencyInstallFailed')
installed_update_count, update_run_successful, maintenance_window_exceeded = runtime.patch_installer.install_updates(runtime.maintenance_window, runtime.package_manager, simulate=True)
self.assertEqual(2, installed_update_count)
self.assertEqual(5, installed_update_count)
self.assertFalse(update_run_successful)
self.assertFalse(maintenance_window_exceeded)
runtime.stop()
Expand Down Expand Up @@ -496,7 +499,7 @@ def test_skip_package_version_UA_ESM_REQUIRED(self):
def test_dependent_package_excluded(self):
# exclusion list contains grub-efi-amd64-bin
# grub-efi-amd64-signed is dependent on grub-efi-amd64-bin, so grub-efi-amd64-signed should also get excluded
# so, out of 4 packages, only 2 packages are installed and 2 are excluded
# so, out of 7 packages, only 5 packages are installed and 2 are excluded
current_time = datetime.datetime.utcnow()
td = datetime.timedelta(hours=0, minutes=20)
job_start_time = (current_time - td).strftime("%Y-%m-%dT%H:%M:%S.9999Z")
Expand All @@ -509,20 +512,20 @@ def test_dependent_package_excluded(self):
runtime.set_legacy_test_type('DependencyInstallSuccessfully')
# As all the packages should get installed using batch patching, get_remaining_packages_to_install should return 0 packages
installed_update_count, update_run_successful, maintenance_window_exceeded = runtime.patch_installer.install_updates(runtime.maintenance_window, runtime.package_manager, simulate=True)
self.assertEqual(2, installed_update_count)
self.assertEqual(5, installed_update_count)
self.assertTrue(update_run_successful)
self.assertFalse(maintenance_window_exceeded)
runtime.stop()

def test_dependent_package_excluded_and_not_enough_time_for_batch_patching(self):
# exclusion list contains grub-efi-amd64-bin
# grub-efi-amd64-signed is dependent on grub-efi-amd64-bin, so grub-efi-amd64-signed should also get excluded
# so, out of 4 packages, only 2 packages are installed and 2 are excluded.
# total packages to install is 2, reboot_setting is 'Never', so cutoff time for batch = 2*5 = 10
# window size is 60 minutes, let time remain = 9 minutes so that not enough time to install in batch
# So td = 60-9 = 51
# so, out of 7 packages, only 5 packages are installed and 2 are excluded.
# total packages to install is 7, reboot_setting is 'Never', so cutoff time for batch of 6 packages= (5*3) + (2*3) = 21
# window size is 60 minutes, let time remain = 16 minutes so that not enough time to install in batch
# So td = 60-16 = 44
current_time = datetime.datetime.utcnow()
td = datetime.timedelta(hours=0, minutes=51)
td = datetime.timedelta(hours=0, minutes=44)
job_start_time = (current_time - td).strftime("%Y-%m-%dT%H:%M:%S.9999Z")
argument_composer = ArgumentComposer()
argument_composer.patches_to_exclude = ["grub-efi-amd64-bin"]
Expand All @@ -532,7 +535,7 @@ def test_dependent_package_excluded_and_not_enough_time_for_batch_patching(self)
# Path change
runtime.set_legacy_test_type('DependencyInstallSuccessfully')
installed_update_count, update_run_successful, maintenance_window_exceeded = runtime.patch_installer.install_updates(runtime.maintenance_window, runtime.package_manager, simulate=True)
self.assertEqual(2, installed_update_count)
self.assertEqual(5, installed_update_count)
self.assertTrue(update_run_successful)
self.assertFalse(maintenance_window_exceeded)
runtime.stop()
Expand All @@ -549,7 +552,7 @@ def test_arch_dependency_install_success(self):
runtime.set_legacy_test_type('ArchDependency')
# As all the packages should get installed using batch patching, get_remaining_packages_to_install should return 0 packages
installed_update_count, update_run_successful, maintenance_window_exceeded = runtime.patch_installer.install_updates(runtime.maintenance_window, runtime.package_manager, simulate=True)
self.assertEqual(4, installed_update_count)
self.assertEqual(7, installed_update_count)
self.assertTrue(update_run_successful)
self.assertFalse(maintenance_window_exceeded)
runtime.stop()
Expand Down
57 changes: 54 additions & 3 deletions src/core/tests/library/LegacyEnvLayerExtensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ def run_command_output(self, cmd, no_output=False, chk_err=True):
output = "Error: Cannot retrieve repository metadata (repomd.xml) for repository: addons. Please verify its path and try again"
elif self.legacy_test_type == 'DependencyInstallSuccessfully':
if self.legacy_package_manager_name is Constants.APT:
# Total 4 packages: git-man, git, grub-efi-amd64-signed and grub-efi-amd64-bin
# Total 7 packages: git-man, git, grub-efi-amd64-signed, testPkg1, testPkg2, testPkg3 and grub-efi-amd64-bin
# grub-efi-amd64-signed is dependent on grub-efi-amd64-bin
# All packages installs successfully
if cmd.find("dist-upgrade") > -1:
Expand All @@ -994,16 +994,28 @@ def run_command_output(self, cmd, no_output=False, chk_err=True):
"Ubuntu:18.04/bionic-security [amd64])" \
"Inst grub-efi-amd64-signed [1.187.2~18.04.1+2.06-2ubuntu14] " \
"(1.187.3~18.04.1+2.06-2ubuntu14.1 Ubuntu:18.04/bionic-updates [amd64]) []" \
"Inst testPkg1 [1.187.2~18.04.1+2.06-2ubuntu14] " \
"(1.187.3~18.04.1+2.06-2ubuntu14.1 Ubuntu:18.04/bionic-updates [amd64]) []" \
"Inst testPkg2 [1.187.2~18.04.1+2.06-2ubuntu14] " \
"(1.187.3~18.04.1+2.06-2ubuntu14.1 Ubuntu:18.04/bionic-updates [amd64]) []" \
"Inst testPkg3 [1.187.2~18.04.1+2.06-2ubuntu14] " \
"(1.187.3~18.04.1+2.06-2ubuntu14.1 Ubuntu:18.04/bionic-updates [amd64]) []" \
"Inst grub-efi-amd64-bin [2.06-2ubuntu14] " \
"(2.06-2ubuntu14.1 Ubuntu:18.04/bionic-updates [amd64])"
elif cmd.find("apt-get -y --only-upgrade true -s install git-man git grub-efi-amd64-signed") > -1:
elif cmd.find("apt-get -y --only-upgrade true -s install git-man git grub-efi-amd64-signed testPkg1 testPkg2 testPkg3") > -1:
code = 0
output = "Inst git-man [1:2.17.1-1ubuntu0.15] (1:2.17.1-1ubuntu0.16 Ubuntu:18.04/bionic-updates, " \
"Ubuntu:18.04/bionic-security [all])" \
"Inst git [1:2.17.1-1ubuntu0.15] (1:2.17.1-1ubuntu0.16 Ubuntu:18.04/bionic-updates, " \
"Ubuntu:18.04/bionic-security [amd64])" \
"Inst grub-efi-amd64-signed [1.187.2~18.04.1+2.06-2ubuntu14] " \
"(1.187.3~18.04.1+2.06-2ubuntu14.1 Ubuntu:18.04/bionic-updates [amd64]) []" \
"Inst testPkg1 [1.187.2~18.04.1+2.06-2ubuntu14] " \
"(1.187.3~18.04.1+2.06-2ubuntu14.1 Ubuntu:18.04/bionic-updates [amd64]) []" \
"Inst testPkg2 [1.187.2~18.04.1+2.06-2ubuntu14] " \
"(1.187.3~18.04.1+2.06-2ubuntu14.1 Ubuntu:18.04/bionic-updates [amd64]) []" \
"Inst testPkg3 [1.187.2~18.04.1+2.06-2ubuntu14] " \
"(1.187.3~18.04.1+2.06-2ubuntu14.1 Ubuntu:18.04/bionic-updates [amd64]) []" \
"Inst grub-efi-amd64-bin [2.06-2ubuntu14] " \
"(2.06-2ubuntu14.1 Ubuntu:18.04/bionic-updates [amd64])"
elif cmd.find("apt-get -y --only-upgrade true -s install grub-efi-amd64-signed") > -1:
Expand All @@ -1024,6 +1036,18 @@ def run_command_output(self, cmd, no_output=False, chk_err=True):
code = 0
output = "Listing... Done\n" + \
"grub-efi-amd64-signed/bionic-updates,now 1.187.3~18.04.1+2.06-2ubuntu14.1 amd64 [installed]"
elif cmd.find("sudo apt list --installed testPkg1") > -1:
code = 0
output = "Listing... Done\n" + \
"testPkg1/bionic-updates,now 1.187.3~18.04.1+2.06-2ubuntu14.1 amd64 [installed]"
elif cmd.find("sudo apt list --installed testPkg2") > -1:
code = 0
output = "Listing... Done\n" + \
"testPkg2/bionic-updates,now 1.187.3~18.04.1+2.06-2ubuntu14.1 amd64 [installed]"
elif cmd.find("sudo apt list --installed testPkg3") > -1:
code = 0
output = "Listing... Done\n" + \
"testPkg3/bionic-updates,now 1.187.3~18.04.1+2.06-2ubuntu14.1 amd64 [installed]"
elif cmd.find("sudo apt list --installed grub-efi-amd64-bin") > -1:
code = 0
output = "Listing... Done\n" + \
Expand All @@ -1036,7 +1060,7 @@ def run_command_output(self, cmd, no_output=False, chk_err=True):
output = "Package sucessfully installed!"
elif self.legacy_test_type == 'DependencyInstallFailed':
if self.legacy_package_manager_name is Constants.APT:
# Total 4 packages: git-man, git, grub-efi-amd64-signed and grub-efi-amd64-bin
# Total 7 packages: git-man, git, grub-efi-amd64-signed, testPkg1, testPkg2, testPkg3 and grub-efi-amd64-bin
# grub-efi-amd64-signed is dependent on grub-efi-amd64-bin
# Installation of grub-efi-amd64-bin fails and as grub-efi-amd64-signed is dependent, it also failed
# Rest all packages install successfully
Expand All @@ -1048,6 +1072,12 @@ def run_command_output(self, cmd, no_output=False, chk_err=True):
"Ubuntu:18.04/bionic-security [amd64])" \
"Inst grub-efi-amd64-signed [1.187.2~18.04.1+2.06-2ubuntu14] " \
"(1.187.3~18.04.1+2.06-2ubuntu14.1 Ubuntu:18.04/bionic-updates [amd64]) []" \
"Inst testPkg1 [1.187.2~18.04.1+2.06-2ubuntu14] " \
"(1.187.3~18.04.1+2.06-2ubuntu14.1 Ubuntu:18.04/bionic-updates [amd64]) []" \
"Inst testPkg2 [1.187.2~18.04.1+2.06-2ubuntu14] " \
"(1.187.3~18.04.1+2.06-2ubuntu14.1 Ubuntu:18.04/bionic-updates [amd64]) []" \
"Inst testPkg3 [1.187.2~18.04.1+2.06-2ubuntu14] " \
"(1.187.3~18.04.1+2.06-2ubuntu14.1 Ubuntu:18.04/bionic-updates [amd64]) []" \
"Inst grub-efi-amd64-bin [2.06-2ubuntu14] " \
"(2.06-2ubuntu14.1 Ubuntu:18.04/bionic-updates [amd64])"
elif cmd.find("apt-get -y --only-upgrade true -s install git-man git grub-efi-amd64-signed") > -1:
Expand Down Expand Up @@ -1077,6 +1107,18 @@ def run_command_output(self, cmd, no_output=False, chk_err=True):
elif cmd.find("sudo apt list --installed grub-efi-amd64-signed") > -1:
code = 0
output = "Listing... Done\n"
elif cmd.find("sudo apt list --installed testPkg1") > -1:
code = 0
output = "Listing... Done\n" + \
"testPkg1/bionic-updates,now 1.187.3~18.04.1+2.06-2ubuntu14.1 amd64 [installed]"
elif cmd.find("sudo apt list --installed testPkg2") > -1:
code = 0
output = "Listing... Done\n" + \
"testPkg2/bionic-updates,now 1.187.3~18.04.1+2.06-2ubuntu14.1 amd64 [installed]"
elif cmd.find("sudo apt list --installed testPkg3") > -1:
code = 0
output = "Listing... Done\n" + \
"testPkg3/bionic-updates,now 1.187.3~18.04.1+2.06-2ubuntu14.1 amd64 [installed]"
elif cmd.find("sudo apt list --installed grub-efi-amd64-bin") > -1:
code = 0
output = "Listing... Done\n"
Expand Down Expand Up @@ -1132,6 +1174,15 @@ def run_command_output(self, cmd, no_output=False, chk_err=True):
"libgcc.i686 " + \
"4.8.5-28.el7 " + \
"rhui-rhel-7-server-rhui-rpms\n" + \
"testPkg1.i686 " + \
"4.8.5-28.el7 " + \
"rhui-rhel-7-server-rhui-rpms\n" + \
"testPkg2.i686 " + \
"4.8.5-28.el7 " + \
"rhui-rhel-7-server-rhui-rpms\n" + \
"testPkg3.i686 " + \
"4.8.5-28.el7 " + \
"rhui-rhel-7-server-rhui-rpms\n" + \
"libgcc.x86_64 " + \
"4.8.5-28.el7 " + \
"rhui-rhel-7-server-rhui-rpms\n"
Expand Down

0 comments on commit 8f0c38c

Please sign in to comment.