6
6
7
7
8
8
# 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
+
11
16
with open (filename , 'rb' ) as f :
12
17
hasher .update (f .read ())
13
18
@@ -18,9 +23,10 @@ def get_hash(filename):
18
23
def test_sles_pallet_patched (host , report_output ):
19
24
total_matched = []
20
25
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 ):
23
27
pytest .skip ('No SLES pallet found - skipping patch check' )
28
+ sles_flavors = os .listdir (base_dir )
29
+ assert sles_flavors
24
30
25
31
# Find out where is stack-sles*images*.rpm file(s)
26
32
result = host .run ('find /export/stack/pallets/stacki/ -name "*stack-sles-*.rpm"' )
@@ -90,19 +96,16 @@ def test_sles_pallet_patched(host, report_output):
90
96
file_to_check = this_list [0 ]
91
97
assert os .path .exists (file_to_check )
92
98
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 )
96
99
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
98
101
# Need to build the equivalent path first
99
102
temp_path_list = file_to_check .split ('add-stacki-squashfs' )
100
103
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 :
102
105
matched_list .append (file_to_check )
103
106
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 :
106
109
found_source = True
107
110
# trim the string
108
111
temp_path = rpm .split ('stacki/' )[1 ]
0 commit comments