diff --git a/common/src/stack/report-system/command/report/system/tests/test_sles_patch.py b/common/src/stack/report-system/command/report/system/tests/test_sles_patch.py index 9ec88a3ce..5d5f6c92f 100644 --- a/common/src/stack/report-system/command/report/system/tests/test_sles_patch.py +++ b/common/src/stack/report-system/command/report/system/tests/test_sles_patch.py @@ -6,8 +6,13 @@ # Returns hash of filename -def get_hash(filename): - hasher = hashlib.md5() +def get_hash(filename, sles): + # SLES15 uses sha256 + if '15sp' in sles: + hasher = hashlib.sha256() + else: + hasher = hashlib.md5() + with open(filename, 'rb') as f: hasher.update(f.read()) @@ -18,9 +23,10 @@ def get_hash(filename): def test_sles_pallet_patched(host, report_output): total_matched = [] base_dir = '/export/stack/pallets/SLES/' - sles_flavors = os.listdir(base_dir) - if not sles_flavors: + if not os.path.isdir(base_dir): pytest.skip('No SLES pallet found - skipping patch check') + sles_flavors = os.listdir(base_dir) + assert sles_flavors # Find out where is stack-sles*images*.rpm file(s) result = host.run('find /export/stack/pallets/stacki/ -name "*stack-sles-*.rpm"') @@ -90,19 +96,16 @@ def test_sles_pallet_patched(host, report_output): file_to_check = this_list[0] assert os.path.exists(file_to_check) hash_value = this_list[3] - # Grab hash for this file in patch directory and compare against hash from img file. They should match - if get_hash(file_to_check) == hash_value: - matched_list.append(file_to_check) - # Grab hash for this file in SLES pallet directory and compare against hash from img file. They should match + # Grab hash for this file in patch directory and SLES pallet directory and compare against hash from img file. They should match # Need to build the equivalent path first temp_path_list = file_to_check.split('add-stacki-squashfs') temp_path = sles_pallet_root + temp_path_list[1] - if get_hash(temp_path) == hash_value: + if get_hash(file_to_check,sles_flavor) == hash_value and get_hash(temp_path, sles_flavor) == hash_value: matched_list.append(file_to_check) - # Check if we found hash match as expected - if matched_list and len(matched_list) == len(patch_files)*2: + # Check if we found hash match as expected. Should be 4 files. + if matched_list and len(matched_list) == 4: found_source = True # trim the string temp_path = rpm.split('stacki/')[1]