66
77
88# Returns hash of filename
9- def get_hash (filename ):
10- hasher = hashlib .md5 ()
9+ def get_hash (filename , sles ):
10+ # SLES15 uses sha256
11+ if '15sp' in sles :
12+ hasher = hashlib .sha256 ()
13+ else :
14+ hasher = hashlib .md5 ()
15+
1116 with open (filename , 'rb' ) as f :
1217 hasher .update (f .read ())
1318
@@ -18,9 +23,10 @@ def get_hash(filename):
1823def test_sles_pallet_patched (host , report_output ):
1924 total_matched = []
2025 base_dir = '/export/stack/pallets/SLES/'
21- sles_flavors = os .listdir (base_dir )
22- if not sles_flavors :
26+ if not os .path .isdir (base_dir ):
2327 pytest .skip ('No SLES pallet found - skipping patch check' )
28+ sles_flavors = os .listdir (base_dir )
29+ assert sles_flavors
2430
2531 # Find out where is stack-sles*images*.rpm file(s)
2632 result = host .run ('find /export/stack/pallets/stacki/ -name "*stack-sles-*.rpm"' )
@@ -90,19 +96,16 @@ def test_sles_pallet_patched(host, report_output):
9096 file_to_check = this_list [0 ]
9197 assert os .path .exists (file_to_check )
9298 hash_value = this_list [3 ]
93- # Grab hash for this file in patch directory and compare against hash from img file. They should match
94- if get_hash (file_to_check ) == hash_value :
95- matched_list .append (file_to_check )
9699
97- # Grab hash for this file in SLES pallet directory and compare against hash from img file. They should match
100+ # Grab hash for this file in patch directory and SLES pallet directory and compare against hash from img file. They should match
98101 # Need to build the equivalent path first
99102 temp_path_list = file_to_check .split ('add-stacki-squashfs' )
100103 temp_path = sles_pallet_root + temp_path_list [1 ]
101- if get_hash (temp_path ) == hash_value :
104+ if get_hash (file_to_check , sles_flavor ) == hash_value and get_hash ( temp_path , sles_flavor ) == hash_value :
102105 matched_list .append (file_to_check )
103106
104- # Check if we found hash match as expected
105- if matched_list and len (matched_list ) == len ( patch_files ) * 2 :
107+ # Check if we found hash match as expected. Should be 4 files.
108+ if matched_list and len (matched_list ) == 4 :
106109 found_source = True
107110 # trim the string
108111 temp_path = rpm .split ('stacki/' )[1 ]
0 commit comments