Commit b6d39571 authored by Łukasz Nowak's avatar Łukasz Nowak

kvm: Fix endless promise failing loop

The problem has been introduced in 5da9c082
"kvm: Improve boot image url handling".

Note the internal usage of md5sum value as image name in the download config
creator.
parent 06a2c5e7
...@@ -79,11 +79,11 @@ md5sum = 438192aab9f11e40dc521b46a4854dcf ...@@ -79,11 +79,11 @@ md5sum = 438192aab9f11e40dc521b46a4854dcf
[image-download-controller] [image-download-controller]
filename = template/image-download-controller.py filename = template/image-download-controller.py
md5sum = 4d48b3da5bc611fc6533335b5953c840 md5sum = 3cc10323fd4d2db4cfbac536b66eae7c
[image-download-config-creator] [image-download-config-creator]
filename = template/image-download-config-creator.py filename = template/image-download-config-creator.py
md5sum = 8fbe05c4175a7f31b6bffced9ad4e91d md5sum = 22ed19d9b8f7b983c97c52caa686bcd7
[whitelist-firewall-download-controller] [whitelist-firewall-download-controller]
filename = template/whitelist-firewall-download-controller.py filename = template/whitelist-firewall-download-controller.py
......
...@@ -49,6 +49,10 @@ if __name__ == "__main__": ...@@ -49,6 +49,10 @@ if __name__ == "__main__":
image_list.append({ image_list.append({
'md5sum': md5sum, 'md5sum': md5sum,
'url': url, 'url': url,
# Note: The destination here it's the waneted md5sum on purpose, as
# it allows to assume, that correctly downloaded and hashed
# image stored at this filename matches the md5sum, so it does
# not have to be hashed on each download run.
'destination': md5sum, 'destination': md5sum,
'destination-tmp': md5sum + '_tmp', 'destination-tmp': md5sum + '_tmp',
'image-number': '%03i' % (image_number,), 'image-number': '%03i' % (image_number,),
......
...@@ -68,13 +68,17 @@ if __name__ == "__main__": ...@@ -68,13 +68,17 @@ if __name__ == "__main__":
destination = os.path.join( destination = os.path.join(
config['destination-directory'], image['destination']) config['destination-directory'], image['destination'])
if os.path.exists(destination): if os.path.exists(destination):
if md5Checksum(destination) == image['md5sum']: # Note: There is no need to recheck md5sum here
# The image name is its md5sum, so if it exists, it means it has
# correct md5sum
# Calculating md5sum of big images takes more time than processing
# of the partition and running promises and this leads to endless
# loop of never ending promise failures
# Of course, someone nasty can come to the partition and damage
# this image, but it's another story, and shall not be fixed
# during download phase.
print('INF: %s : already downloaded' % (image['url'],)) print('INF: %s : already downloaded' % (image['url'],))
continue continue
else:
print('INF: %s : Removed, as expected checksum does not match %s' % (
image['url'], image['md5sum']))
os.remove(destination)
# key is str, as the dict is dumped to JSON which does not accept tuples # key is str, as the dict is dumped to JSON which does not accept tuples
md5sum_state_key = '%s#%s' % (image['url'], image['md5sum']) md5sum_state_key = '%s#%s' % (image['url'], image['md5sum'])
md5sum_state_amount = md5sum_state_dict.get(md5sum_state_key, 0) md5sum_state_amount = md5sum_state_dict.get(md5sum_state_key, 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment