From cde402d0070780519e6beb10ab49ed467347d02d Mon Sep 17 00:00:00 2001 From: Adarsh Dubey Date: Wed, 29 Nov 2023 15:35:32 +0530 Subject: [PATCH 1/4] Test Coverage for FDI version verification --- tests/upgrades/test_discovery.py | 79 ++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tests/upgrades/test_discovery.py diff --git a/tests/upgrades/test_discovery.py b/tests/upgrades/test_discovery.py new file mode 100644 index 00000000000..41b1d310d44 --- /dev/null +++ b/tests/upgrades/test_discovery.py @@ -0,0 +1,79 @@ +"""Test Discovery Plugin related Upgrade Scenario's + +:Requirement: UpgradedSatellite + +:CaseAutomation: Automated + +:CaseLevel: Acceptance + +:CaseComponent: DiscoveryImage + +:Team: Rocket + +:TestType: Functional + +:CaseImportance: High + +:Upstream: No +""" +import re + +from packaging import version +import pytest + + +class TestDiscoveryImage: + """Pre-upgrade and post-upgrade scenarios to test Foreman Discovery Image version. + + Test Steps: + 1. Before Satellite upgrade, Check the FDI version on the Discovered host + 2. Upgrade satellite. + 3. Check the FDI version on the Discovered host, after upgrade to make sure its same or greater. + """ + + @pytest.mark.pre_upgrade + def test_pre_upgrade_fdi_version(self, target_sat, save_test_data): + """Test FDI version before upgrade. + + :id: preupgrade-8c94841c-6791-4af0-aa9c-e54c8d8b9a92 + + :steps: + 1. Check installed version of FDI + + :expectedresults: Version should be saved and checked post-upgrade + """ + target_sat.register_to_cdn() + target_sat.execute( + 'yum -y --disableplugin=foreman-protector install foreman-discovery-image' + ) + target_sat.unregister() + fdi_version = target_sat.execute('rpm -qa *foreman-discovery-image*') + # Note: The regular exp takes care of format digit.digit.digit or digit.digit.digit-digit in the output + pre_upgrade_version = re.search(r'\d+\.\d+\.\d+(-\d+)?', fdi_version.stdout).group() + pre_upgrade_version = version.parse(pre_upgrade_version) + save_test_data({'pre_upgrade_version': pre_upgrade_version}) + target_sat.execute('yum -y remove foreman-discovery-image') + + @pytest.mark.post_upgrade(depend_on=test_pre_upgrade_fdi_version) + def test_post_upgrade_fdi_version(self, target_sat, pre_upgrade_data): + """Test FDI version post upgrade. + + :id: postugrade-38bdecaa-2b50-434b-90b1-4aa2b600d04e + + :steps: + 1. Check installed version of FDI + + :expectedresults: Version should be greater than or equal to pre_upgrade version + """ + pre_upgrade_version = pre_upgrade_data.get('pre_upgrade_version') + target_sat.register_to_cdn() + target_sat.execute( + 'yum -y --disableplugin=foreman-protector install foreman-discovery-image' + ) + target_sat.unregister() + fdi_version = target_sat.execute('rpm -qa *foreman-discovery-image*') + # Note: The regular exp takes care of format digit.digit.digit or digit.digit.digit-digit in the output + post_upgrade_version = re.search(r'\d+\.\d+\.\d+(-\d+)?', fdi_version.stdout).group() + post_upgrade_version = version.parse(post_upgrade_version) + assert post_upgrade_version >= pre_upgrade_version + target_sat.execute('yum -y remove foreman-discovery-image') From a86255d5cf8ae50f0b2a8385da401219e3d8c551 Mon Sep 17 00:00:00 2001 From: Adarsh Dubey Date: Tue, 5 Dec 2023 16:08:51 +0530 Subject: [PATCH 2/4] Removed unwanted code --- tests/upgrades/test_discovery.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/tests/upgrades/test_discovery.py b/tests/upgrades/test_discovery.py index 41b1d310d44..766c2f8d037 100644 --- a/tests/upgrades/test_discovery.py +++ b/tests/upgrades/test_discovery.py @@ -26,9 +26,9 @@ class TestDiscoveryImage: """Pre-upgrade and post-upgrade scenarios to test Foreman Discovery Image version. Test Steps: - 1. Before Satellite upgrade, Check the FDI version on the Discovered host + 1. Before Satellite upgrade, Check the FDI version on the Satellite 2. Upgrade satellite. - 3. Check the FDI version on the Discovered host, after upgrade to make sure its same or greater. + 3. Check the FDI version on the Satellite after upgrade to make sure its same or greater. """ @pytest.mark.pre_upgrade @@ -46,13 +46,11 @@ def test_pre_upgrade_fdi_version(self, target_sat, save_test_data): target_sat.execute( 'yum -y --disableplugin=foreman-protector install foreman-discovery-image' ) - target_sat.unregister() fdi_version = target_sat.execute('rpm -qa *foreman-discovery-image*') # Note: The regular exp takes care of format digit.digit.digit or digit.digit.digit-digit in the output pre_upgrade_version = re.search(r'\d+\.\d+\.\d+(-\d+)?', fdi_version.stdout).group() pre_upgrade_version = version.parse(pre_upgrade_version) save_test_data({'pre_upgrade_version': pre_upgrade_version}) - target_sat.execute('yum -y remove foreman-discovery-image') @pytest.mark.post_upgrade(depend_on=test_pre_upgrade_fdi_version) def test_post_upgrade_fdi_version(self, target_sat, pre_upgrade_data): @@ -66,14 +64,9 @@ def test_post_upgrade_fdi_version(self, target_sat, pre_upgrade_data): :expectedresults: Version should be greater than or equal to pre_upgrade version """ pre_upgrade_version = pre_upgrade_data.get('pre_upgrade_version') - target_sat.register_to_cdn() - target_sat.execute( - 'yum -y --disableplugin=foreman-protector install foreman-discovery-image' - ) - target_sat.unregister() fdi_version = target_sat.execute('rpm -qa *foreman-discovery-image*') # Note: The regular exp takes care of format digit.digit.digit or digit.digit.digit-digit in the output post_upgrade_version = re.search(r'\d+\.\d+\.\d+(-\d+)?', fdi_version.stdout).group() post_upgrade_version = version.parse(post_upgrade_version) assert post_upgrade_version >= pre_upgrade_version - target_sat.execute('yum -y remove foreman-discovery-image') + target_sat.unregister() From 7a87d83e5b1a5fdd3ae4b7358531da40ee92d9c6 Mon Sep 17 00:00:00 2001 From: Adarsh Dubey Date: Wed, 6 Dec 2023 16:07:31 +0530 Subject: [PATCH 3/4] Using foreman-maintain for installation --- tests/upgrades/test_discovery.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/upgrades/test_discovery.py b/tests/upgrades/test_discovery.py index 766c2f8d037..00170c820f6 100644 --- a/tests/upgrades/test_discovery.py +++ b/tests/upgrades/test_discovery.py @@ -32,7 +32,7 @@ class TestDiscoveryImage: """ @pytest.mark.pre_upgrade - def test_pre_upgrade_fdi_version(self, target_sat, save_test_data): + def test_pre_upgrade_fdi_version(self, target_sat, save_test_data, request): """Test FDI version before upgrade. :id: preupgrade-8c94841c-6791-4af0-aa9c-e54c8d8b9a92 @@ -43,13 +43,10 @@ def test_pre_upgrade_fdi_version(self, target_sat, save_test_data): :expectedresults: Version should be saved and checked post-upgrade """ target_sat.register_to_cdn() - target_sat.execute( - 'yum -y --disableplugin=foreman-protector install foreman-discovery-image' - ) + target_sat.execute('foreman-maintain packages install -y foreman-discovery-image') fdi_version = target_sat.execute('rpm -qa *foreman-discovery-image*') # Note: The regular exp takes care of format digit.digit.digit or digit.digit.digit-digit in the output pre_upgrade_version = re.search(r'\d+\.\d+\.\d+(-\d+)?', fdi_version.stdout).group() - pre_upgrade_version = version.parse(pre_upgrade_version) save_test_data({'pre_upgrade_version': pre_upgrade_version}) @pytest.mark.post_upgrade(depend_on=test_pre_upgrade_fdi_version) @@ -63,10 +60,12 @@ def test_post_upgrade_fdi_version(self, target_sat, pre_upgrade_data): :expectedresults: Version should be greater than or equal to pre_upgrade version """ + pre_upgrade_version = pre_upgrade_data.get('pre_upgrade_version') fdi_version = target_sat.execute('rpm -qa *foreman-discovery-image*') # Note: The regular exp takes care of format digit.digit.digit or digit.digit.digit-digit in the output post_upgrade_version = re.search(r'\d+\.\d+\.\d+(-\d+)?', fdi_version.stdout).group() + pre_upgrade_version = version.parse(pre_upgrade_version) post_upgrade_version = version.parse(post_upgrade_version) assert post_upgrade_version >= pre_upgrade_version target_sat.unregister() From c3d9e23f9e94460cf4e7b53405231ff92d8bb331 Mon Sep 17 00:00:00 2001 From: Adarsh Dubey Date: Thu, 7 Dec 2023 15:09:41 +0530 Subject: [PATCH 4/4] Using Version --- tests/upgrades/test_discovery.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/upgrades/test_discovery.py b/tests/upgrades/test_discovery.py index 00170c820f6..157b04cc4b8 100644 --- a/tests/upgrades/test_discovery.py +++ b/tests/upgrades/test_discovery.py @@ -18,7 +18,7 @@ """ import re -from packaging import version +from packaging.version import Version import pytest @@ -44,9 +44,9 @@ def test_pre_upgrade_fdi_version(self, target_sat, save_test_data, request): """ target_sat.register_to_cdn() target_sat.execute('foreman-maintain packages install -y foreman-discovery-image') - fdi_version = target_sat.execute('rpm -qa *foreman-discovery-image*') + fdi_package = target_sat.execute('rpm -qa *foreman-discovery-image*').stdout # Note: The regular exp takes care of format digit.digit.digit or digit.digit.digit-digit in the output - pre_upgrade_version = re.search(r'\d+\.\d+\.\d+(-\d+)?', fdi_version.stdout).group() + pre_upgrade_version = Version(re.search(r'\d+\.\d+\.\d+(-\d+)?', fdi_package).group()) save_test_data({'pre_upgrade_version': pre_upgrade_version}) @pytest.mark.post_upgrade(depend_on=test_pre_upgrade_fdi_version) @@ -60,12 +60,9 @@ def test_post_upgrade_fdi_version(self, target_sat, pre_upgrade_data): :expectedresults: Version should be greater than or equal to pre_upgrade version """ - pre_upgrade_version = pre_upgrade_data.get('pre_upgrade_version') - fdi_version = target_sat.execute('rpm -qa *foreman-discovery-image*') + fdi_package = target_sat.execute('rpm -qa *foreman-discovery-image*').stdout # Note: The regular exp takes care of format digit.digit.digit or digit.digit.digit-digit in the output - post_upgrade_version = re.search(r'\d+\.\d+\.\d+(-\d+)?', fdi_version.stdout).group() - pre_upgrade_version = version.parse(pre_upgrade_version) - post_upgrade_version = version.parse(post_upgrade_version) + post_upgrade_version = Version(re.search(r'\d+\.\d+\.\d+(-\d+)?', fdi_package).group()) assert post_upgrade_version >= pre_upgrade_version target_sat.unregister()