From 2ac92c8e2f13de9b71abfbfa91eefa5ec2864cf2 Mon Sep 17 00:00:00 2001 From: Andres Pozo Date: Tue, 17 Sep 2024 15:49:47 +0200 Subject: [PATCH 1/6] Removes the base_product check from `is_suma` functions --- usr/share/lib/img_proof/tests/conftest.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/usr/share/lib/img_proof/tests/conftest.py b/usr/share/lib/img_proof/tests/conftest.py index 0907ff1..fa16776 100644 --- a/usr/share/lib/img_proof/tests/conftest.py +++ b/usr/share/lib/img_proof/tests/conftest.py @@ -146,31 +146,27 @@ def f(): @pytest.fixture() -def is_suma_server(host, get_baseproduct): +def is_suma_server(host): def f(): suma_server_product = '/etc/products.d/SUSE-Manager-Server.prod' suma_server = host.file(suma_server_product) - base_product = get_baseproduct() return all([ suma_server.exists, - suma_server.is_file, - base_product == suma_server_product + suma_server.is_file ]) return f @pytest.fixture() -def is_suma_proxy(host, get_baseproduct): +def is_suma_proxy(host): def f(): suma_proxy_product = '/etc/products.d/SUSE-Manager-Proxy.prod' suma_proxy = host.file(suma_proxy_product) - base_product = get_baseproduct() return all([ suma_proxy.exists, - suma_proxy.is_file, - base_product == suma_proxy_product + suma_proxy.is_file ]) return f From 3a3c4740ee7978b6f71c5836e08cb1f5cd93fe20 Mon Sep 17 00:00:00 2001 From: Andres Pozo Date: Wed, 18 Sep 2024 11:23:47 +0200 Subject: [PATCH 2/6] Includes condition on suma version to check baseproduct for suma 4.X --- usr/share/lib/img_proof/tests/conftest.py | 51 +++++++++++++++++++---- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/usr/share/lib/img_proof/tests/conftest.py b/usr/share/lib/img_proof/tests/conftest.py index fa16776..96e7837 100644 --- a/usr/share/lib/img_proof/tests/conftest.py +++ b/usr/share/lib/img_proof/tests/conftest.py @@ -1,5 +1,6 @@ import json import pytest +import xml.etree.ElementTree as ET from susepubliccloudinfoclient import infoserverrequests @@ -146,27 +147,47 @@ def f(): @pytest.fixture() -def is_suma_server(host): +def is_suma_server(host, get_baseproduct, get_suma_version): def f(): suma_server_product = '/etc/products.d/SUSE-Manager-Server.prod' suma_server = host.file(suma_server_product) - + base_product = get_baseproduct() + suma_version = get_suma_version(suma_server_product) + + if suma_version and suma_version.startswith('4'): + # For suma 4.3 baseproduct HAS to be SUMA proxy + return all([ + suma_server.exists, + suma_server.is_file, + base_product == suma_server_product + ]) + # For suma >=5 baseproduct is Micro and suma is an additional product return all([ - suma_server.exists, - suma_server.is_file + suma_server.exists, + suma_server.is_file, ]) return f @pytest.fixture() -def is_suma_proxy(host): +def is_suma_proxy(host, get_baseproduct, get_suma_version): def f(): suma_proxy_product = '/etc/products.d/SUSE-Manager-Proxy.prod' suma_proxy = host.file(suma_proxy_product) - + base_product = get_baseproduct() + suma_version = get_suma_version(suma_proxy_product) + + if suma_version and suma_version.startswith('4'): + # For suma 4.3 baseproduct HAS to be SUMA proxy + return all([ + suma_proxy.exists, + suma_proxy.is_file, + base_product == suma_proxy_product + ]) + # For suma >=5 baseproduct is Micro and suma is an additional product return all([ - suma_proxy.exists, - suma_proxy.is_file + suma_proxy.exists, + suma_proxy.is_file, ]) return f @@ -178,6 +199,20 @@ def f(): return f +@pytest.fixture() +def get_suma_version(host): + def f(product_file): + version = '' + try: + suma_product = host.file(product_file) + xmlroot = ET.fromstring(suma_product.content_string) + version = xmlroot.find('./version').text + except Exception: + pass + return version + return f + + @pytest.fixture() def is_sles_sapcal(host): def f(): From 8e59fc3e8a2756e3c20619ad4dfb78f1ba01b8a2 Mon Sep 17 00:00:00 2001 From: Andres Pozo Date: Wed, 18 Sep 2024 14:31:13 +0200 Subject: [PATCH 3/6] Fix misleading comment --- usr/share/lib/img_proof/tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/share/lib/img_proof/tests/conftest.py b/usr/share/lib/img_proof/tests/conftest.py index 96e7837..1c071b4 100644 --- a/usr/share/lib/img_proof/tests/conftest.py +++ b/usr/share/lib/img_proof/tests/conftest.py @@ -155,7 +155,7 @@ def f(): suma_version = get_suma_version(suma_server_product) if suma_version and suma_version.startswith('4'): - # For suma 4.3 baseproduct HAS to be SUMA proxy + # For suma 4.3 baseproduct HAS to be SUMA server return all([ suma_server.exists, suma_server.is_file, From 1b08e70a48a3bfeb570c3159a17c3a687883208f Mon Sep 17 00:00:00 2001 From: Andres Pozo Date: Thu, 19 Sep 2024 10:39:41 +0200 Subject: [PATCH 4/6] Include the baseproduct check for SUMA >=5 --- usr/share/lib/img_proof/tests/conftest.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/usr/share/lib/img_proof/tests/conftest.py b/usr/share/lib/img_proof/tests/conftest.py index 1c071b4..e449cfa 100644 --- a/usr/share/lib/img_proof/tests/conftest.py +++ b/usr/share/lib/img_proof/tests/conftest.py @@ -161,10 +161,13 @@ def f(): suma_server.is_file, base_product == suma_server_product ]) - # For suma >=5 baseproduct is Micro and suma is an additional product + # For suma >=5 baseproduct has to be Micro + # SUMA is included as an additional product + sle_micro_product = '/etc/products.d/SLE-Micro.prod' return all([ suma_server.exists, suma_server.is_file, + base_product == sle_micro_product ]) return f @@ -184,10 +187,13 @@ def f(): suma_proxy.is_file, base_product == suma_proxy_product ]) - # For suma >=5 baseproduct is Micro and suma is an additional product + # For suma >=5 baseproduct has to be Micro + # SUMA is included as an additional product + sle_micro_product = '/etc/products.d/SLE-Micro.prod' return all([ suma_proxy.exists, suma_proxy.is_file, + base_product == sle_micro_product ]) return f From 2f5a2e89c5a83fa0c556474569181c0bdbd3dcc0 Mon Sep 17 00:00:00 2001 From: Andres Pozo Date: Thu, 19 Sep 2024 10:47:19 +0200 Subject: [PATCH 5/6] Fix format --- usr/share/lib/img_proof/tests/conftest.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/usr/share/lib/img_proof/tests/conftest.py b/usr/share/lib/img_proof/tests/conftest.py index e449cfa..0653df2 100644 --- a/usr/share/lib/img_proof/tests/conftest.py +++ b/usr/share/lib/img_proof/tests/conftest.py @@ -165,9 +165,9 @@ def f(): # SUMA is included as an additional product sle_micro_product = '/etc/products.d/SLE-Micro.prod' return all([ - suma_server.exists, - suma_server.is_file, - base_product == sle_micro_product + suma_server.exists, + suma_server.is_file, + base_product == sle_micro_product ]) return f @@ -191,9 +191,9 @@ def f(): # SUMA is included as an additional product sle_micro_product = '/etc/products.d/SLE-Micro.prod' return all([ - suma_proxy.exists, - suma_proxy.is_file, - base_product == sle_micro_product + suma_proxy.exists, + suma_proxy.is_file, + base_product == sle_micro_product ]) return f From 46e4d720a29dc0e99d8563959fdea1246db2928c Mon Sep 17 00:00:00 2001 From: Andres Pozo Date: Thu, 19 Sep 2024 18:07:45 +0200 Subject: [PATCH 6/6] Code simplification --- usr/share/lib/img_proof/tests/conftest.py | 32 ++++++++++------------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/usr/share/lib/img_proof/tests/conftest.py b/usr/share/lib/img_proof/tests/conftest.py index 0653df2..7f622ef 100644 --- a/usr/share/lib/img_proof/tests/conftest.py +++ b/usr/share/lib/img_proof/tests/conftest.py @@ -156,18 +156,16 @@ def f(): if suma_version and suma_version.startswith('4'): # For suma 4.3 baseproduct HAS to be SUMA server - return all([ - suma_server.exists, - suma_server.is_file, - base_product == suma_server_product - ]) - # For suma >=5 baseproduct has to be Micro - # SUMA is included as an additional product - sle_micro_product = '/etc/products.d/SLE-Micro.prod' + expected_product = suma_server_product + else: + # For suma >=5 baseproduct has to be Micro + # SUMA is included as an additional product + expected_product = '/etc/products.d/SLE-Micro.prod' + return all([ suma_server.exists, suma_server.is_file, - base_product == sle_micro_product + base_product == expected_product ]) return f @@ -182,18 +180,16 @@ def f(): if suma_version and suma_version.startswith('4'): # For suma 4.3 baseproduct HAS to be SUMA proxy - return all([ - suma_proxy.exists, - suma_proxy.is_file, - base_product == suma_proxy_product - ]) - # For suma >=5 baseproduct has to be Micro - # SUMA is included as an additional product - sle_micro_product = '/etc/products.d/SLE-Micro.prod' + expected_product = suma_proxy_product + else: + # For suma >=5 baseproduct has to be Micro + # SUMA is included as an additional product + expected_product = '/etc/products.d/SLE-Micro.prod' + return all([ suma_proxy.exists, suma_proxy.is_file, - base_product == sle_micro_product + base_product == expected_product ]) return f