win_installer.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # -*- coding: utf-8 -*-
  2. """
  3. :copyright: Copyright 2013-2017 by the SaltStack Team, see AUTHORS for more details.
  4. :license: Apache 2.0, see LICENSE for more details.
  5. tests.support.win_installer
  6. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. Fetches the binary Windows installer
  8. """
  9. from __future__ import absolute_import
  10. import hashlib
  11. import requests
  12. PREFIX = "Salt-Minion-"
  13. REPO = "https://repo.saltstack.com/windows"
  14. def latest_installer_name(arch="AMD64", **kwargs):
  15. """
  16. Create an installer file name
  17. """
  18. return "Salt-Minion-Latest-Py3-{}-Setup.exe".format(arch)
  19. def download_and_verify(fp, name, repo=REPO):
  20. """
  21. Download an installer and verify its contents.
  22. """
  23. md5 = "{}.md5".format(name)
  24. url = lambda x: "{}/{}".format(repo, x)
  25. resp = requests.get(url(md5))
  26. if resp.status_code != 200:
  27. raise Exception("Unable to fetch installer md5")
  28. installer_md5 = resp.text.strip().split()[0].lower()
  29. resp = requests.get(url(name), stream=True)
  30. if resp.status_code != 200:
  31. raise Exception("Unable to fetch installer")
  32. md5hsh = hashlib.md5()
  33. for chunk in resp.iter_content(chunk_size=1024):
  34. md5hsh.update(chunk)
  35. fp.write(chunk)
  36. if md5hsh.hexdigest() != installer_md5:
  37. raise Exception(
  38. "Installer's hash does not match {} != {}".format(
  39. md5hsh.hexdigest(), installer_md5
  40. )
  41. )