Commit a23a1d2e authored by Julien Muchembled's avatar Julien Muchembled

kvm: fix bootstrap-script-url with Python 3

parent 384a3cb9
......@@ -15,11 +15,11 @@
[template]
filename = instance.cfg.in
md5sum = 399b398a8eabfa6126d2a521dc779f9b
md5sum = 0d34ff81779115bf899f7bc752877b70
[template-kvm]
filename = instance-kvm.cfg.jinja2
md5sum = 704b6ac6bf42837bcd8f4582c5a746c0
md5sum = 4c5d8c723b6adb96fcac9690c0c900f7
[template-kvm-cluster]
filename = instance-kvm-cluster.cfg.jinja2.in
......@@ -73,10 +73,6 @@ md5sum = 752c91a4a6b72f5cf8226d6b940015f8
filename = template/qemu-is-ready.in
md5sum = fb330a796fadb6cd5c85217f80a42af3
[file-download-script]
filename = template/download_file.in
md5sum = 599dbbbd438fe7801e3f8642ae9e9a78
[template-httpd]
filename = instance-kvm-http.cfg.in
md5sum = d657884d02105deffddee0edae4b50a6
......
......@@ -19,19 +19,12 @@
{% set whitelist_domains = slapparameter_dict.get('whitelist-domains', '') -%}
{% set boot_image_url_list_enabled = 'boot-image-url-list' in slapparameter_dict %}
{% set boot_image_url_select_enabled = 'boot-image-url-select' in slapparameter_dict %}
{% set bootstrap_script_url = slapparameter_dict.get('bootstrap-script-url') -%}
{% set cpu_max_count = dumps(slapparameter_dict.get('cpu-max-count', int(slapparameter_dict.get('cpu-count', 1)) + 1)) %}
{% set ram_max_size = dumps(slapparameter_dict.get('ram-max-size', int(slapparameter_dict.get('ram-size', 1024)) + 512)) %}
{% set extends_list = [] -%}
{% set part_list = [] -%}
{% set bootstrap_url = '' -%}
{% set bootstrap_url_md5sum = '' -%}
{% if slapparameter_dict.get('bootstrap-script-url', '') -%}
{% set url_info_list = slapparameter_dict['bootstrap-script-url'].split('#') -%}
{% set bootstrap_url = url_info_list[0] -%}
{% set bootstrap_url_md5sum = url_info_list[1] -%}
{% endif -%}
{% if instance_type == 'cluster' -%}
{% set nat_rule_list = slapparameter_dict.get('nat-rules', '') %}
{% endif -%}
......@@ -897,12 +890,18 @@ module = check_command_execute
name = ansible_{{ name }}.py
config-command = ${ansible-vm-bin:rendered}
{% if bootstrap_script_url -%}
[download-bootstrap-script]
recipe = plone.recipe.command
file-location = ${directory:public}/vm-bootstrap
command = {{ python_executable }} {{ file_download_script }} {{ bootstrap_url }} {{ bootstrap_url_md5sum }} ${:file-location}
update-command =
stop-on-error = true
recipe = slapos.recipe.build
location = ${directory:public}/vm-bootstrap
install =
from zc.buildout.download import check_md5sum, urlretrieve, ChecksumError
url, md5sum = {{ repr(bootstrap_script_url) }}.split('#')
urlretrieve(url, location)
if not check_md5sum(location, md5sum):
os.remove(location)
raise ChecksumError
{% endif -%}
[logrotate-vm-bootstrap]
< = logrotate-entry-base
......@@ -1002,7 +1001,7 @@ keyboard-layout-language = fr
{% if slapparameter_dict.get('authorized-key', '') and slapparameter_dict.get('type', '') == 'cluster' %}
{% do part_list.append('get-authorized-key') -%}
{% endif -%}
{% if slapparameter_dict.get('bootstrap-script-url', '') -%}
{% if bootstrap_script_url -%}
{% do part_list.append('download-bootstrap-script') -%}
{% endif -%}
{% if slapparameter_dict.get('document-port', '') -%}
......
......@@ -83,7 +83,6 @@ extra-context =
raw dnsresolver_executable ${buildout:bin-directory}/dnsresolver
raw dcron_executable_location ${dcron:location}/sbin/crond
raw debian_amd64_netinst_location ${debian-amd64-netinst.iso:location}/${debian-amd64-netinst.iso:filename}
raw file_download_script ${file-download-script:location}/${file-download-script:filename}
raw whitelist_domains_default ${whitelist-domains-default:location}/${whitelist-domains-default:filename}
raw whitelist_firewall_download_controller ${whitelist-firewall-download-controller:target}
raw image_download_controller ${image-download-controller:target}
......
......@@ -175,12 +175,6 @@ on-update = true
filename = qemu-is-ready.in
on-update = true
[file-download-script]
<= download-template-base
path = download_file.in
filename = download_file
on-update = true
[whitelist-domains-default]
<= download-template-base
filename = whitelist-domains-default
......
#!/usr/bin/env python
import os
import urllib
import hashlib
import sys
def md5Checksum(file_path):
with open(file_path, 'rb') as fh:
m = hashlib.md5()
while True:
data = fh.read(8192)
if not data:
break
m.update(data)
return m.hexdigest()
if __name__ == "__main__":
url, md5sum, destination_path = sys.argv[1:]
urllib.urlretrieve (url, destination_path)
computed_md5sum = md5Checksum(destination_path)
if computed_md5sum != md5sum:
os.remove(destination_path)
raise Exception('MD5 mismatch. MD5 of downloaded file is %s, Specified MD5 is %s.' % (
computed_md5sum, md5sum))
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