Change-Id: I8c3cc1e3233cb073f60e88e0fbcf284a4ca6c972
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/3454
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Sharath George
| ... | ... |
@@ -7,12 +7,13 @@ import tarfile |
| 7 | 7 |
import fileinput |
| 8 | 8 |
from optparse import OptionParser |
| 9 | 9 |
from utils import Utils |
| 10 |
+import json |
|
| 10 | 11 |
|
| 11 | 12 |
def create_ova_image(raw_image_name, tools_path, build_scripts_path, config): |
| 12 | 13 |
output_path = os.path.dirname(os.path.realpath(raw_image_name)) |
| 13 | 14 |
utils = Utils() |
| 14 | 15 |
# Remove older artifacts |
| 15 |
- files = os.listdir(output_path) |
|
| 16 |
+ files = os.listdir(output_path) |
|
| 16 | 17 |
for file in files: |
| 17 | 18 |
if file.endswith(".vmdk"):
|
| 18 | 19 |
os.remove(os.path.join(output_path, file)) |
| ... | ... |
@@ -56,14 +57,14 @@ def create_ova_image(raw_image_name, tools_path, build_scripts_path, config): |
| 56 | 56 |
for name in ["photon-ova.ovf", "photon-ova.mf", "photon-ova-disk1.vmdk"]: |
| 57 | 57 |
ovatar.add(name, arcname=os.path.basename(name)) |
| 58 | 58 |
ovatar.close() |
| 59 |
- os.remove(vmx_path) |
|
| 59 |
+ os.remove(vmx_path) |
|
| 60 | 60 |
os.remove(mf_path) |
| 61 | 61 |
|
| 62 | 62 |
if 'additionalhwversion' in config: |
| 63 | 63 |
for addlversion in config['additionalhwversion']: |
| 64 | 64 |
new_ovf_path = output_path + "/photon-ova-hw{}.ovf".format(addlversion)
|
| 65 | 65 |
mf_path = output_path + "/photon-ova-hw{}.mf".format(addlversion)
|
| 66 |
- utils.replaceandsaveasnewfile(ovf_path, new_ovf_path, "vmx-.*<", "vmx-{}<".format(addlversion))
|
|
| 66 |
+ utils.replaceandsaveasnewfile(ovf_path, new_ovf_path, "vmx-.*<", "vmx-{}<".format(addlversion))
|
|
| 67 | 67 |
out = utils.runshellcommand("openssl sha1 photon-ova-disk1.vmdk photon-ova-hw{}.ovf".format(addlversion))
|
| 68 | 68 |
with open(mf_path, "w") as source: |
| 69 | 69 |
source.write(out) |
| ... | ... |
@@ -78,13 +79,13 @@ def create_ova_image(raw_image_name, tools_path, build_scripts_path, config): |
| 78 | 78 |
|
| 79 | 79 |
os.remove(new_ovf_path) |
| 80 | 80 |
os.remove(mf_path) |
| 81 |
- os.chdir(cwd) |
|
| 81 |
+ os.chdir(cwd) |
|
| 82 | 82 |
os.remove(ovf_path) |
| 83 | 83 |
os.remove(vmdk_path) |
| 84 |
- files = os.listdir(output_path) |
|
| 84 |
+ files = os.listdir(output_path) |
|
| 85 | 85 |
for file in files: |
| 86 | 86 |
if file.endswith(".vmdk"):
|
| 87 |
- os.remove(os.path.join(output_path, file)) |
|
| 87 |
+ os.remove(os.path.join(output_path, file)) |
|
| 88 | 88 |
|
| 89 | 89 |
|
| 90 | 90 |
if __name__ == '__main__': |
| ... | ... |
@@ -215,10 +216,13 @@ if __name__ == '__main__': |
| 215 | 215 |
tgzout.add(raw_image, arcname=os.path.basename(raw_image)) |
| 216 | 216 |
tgzout.close() |
| 217 | 217 |
elif config['artifacttype'] == 'vhd': |
| 218 |
- imgconverter = options.tools_bin_path + '/imgconverter' |
|
| 219 | 218 |
vhdname = img_path + '/photon-' + options.image_name + '-' + photon_release_ver + '-' + photon_build_num + '.vhd' |
| 220 | 219 |
print "Converting raw disk to vhd ..." |
| 221 |
- utils.runshellcommand("{} -i {} -v vhd -o {}".format(imgconverter, raw_image, vhdname))
|
|
| 220 |
+ info_output=utils.runshellcommand("docker run -v /:/mnt:rw anishs/qemu-img info -f raw --output json {}".format('/mnt' + raw_image))
|
|
| 221 |
+ mbsize = 1024 * 1024 |
|
| 222 |
+ mbroundedsize = (int(json.loads(info_output)["virtual-size"])/mbsize + 1) * mbsize |
|
| 223 |
+ utils.runshellcommand("docker run -v /:/mnt:rw anishs/qemu-img resize -f raw {} {}".format('/mnt' + raw_image, mbroundedsize))
|
|
| 224 |
+ utils.runshellcommand("docker run -v /:/mnt:rw anishs/qemu-img convert {} -O vpc -o subformat=fixed {}".format('/mnt' + raw_image, '/mnt' + vhdname))
|
|
| 222 | 225 |
elif config['artifacttype'] == 'ova': |
| 223 | 226 |
create_ova_image(raw_image, options.tools_bin_path, options.build_scripts_path + '/' + options.image_name, config) |
| 224 | 227 |
if 'customartifacts' in config: |
| ... | ... |
@@ -259,7 +263,7 @@ if __name__ == '__main__': |
| 259 | 259 |
raw_image = raw_image_custom |
| 260 | 260 |
index = index + 1 |
| 261 | 261 |
|
| 262 |
- shutil.rmtree(custom_path) |
|
| 262 |
+ shutil.rmtree(custom_path) |
|
| 263 | 263 |
|
| 264 | 264 |
else: |
| 265 | 265 |
raise ValueError("Unknown output format")
|