package_version.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. """Check that available RPM packages match the required versions."""
  2. import re
  3. from openshift_checks import OpenShiftCheck, OpenShiftCheckException
  4. from openshift_checks.mixins import NotContainerizedMixin
  5. class PackageVersion(NotContainerizedMixin, OpenShiftCheck):
  6. """Check that available RPM packages match the required versions."""
  7. name = "package_version"
  8. tags = ["preflight"]
  9. # NOTE: versions outside those specified are mapped to least/greatest
  10. openshift_to_ovs_version = {
  11. (3, 4): "2.4",
  12. (3, 5): ["2.6", "2.7"],
  13. (3, 6): ["2.6", "2.7", "2.8"],
  14. (3, 7): ["2.6", "2.7", "2.8"],
  15. }
  16. openshift_to_docker_version = {
  17. (3, 1): "1.8",
  18. (3, 2): "1.10",
  19. (3, 3): "1.10",
  20. (3, 4): "1.12",
  21. (3, 5): "1.12",
  22. (3, 6): "1.12",
  23. }
  24. # map major OpenShift release versions across releases to a common major version
  25. map_major_release_version = {
  26. 1: 3,
  27. }
  28. def is_active(self):
  29. """Skip hosts that do not have package requirements."""
  30. group_names = self.get_var("group_names", default=[])
  31. master_or_node = 'oo_masters_to_config' in group_names or 'oo_nodes_to_config' in group_names
  32. return super(PackageVersion, self).is_active() and master_or_node
  33. def run(self):
  34. rpm_prefix = self.get_var("openshift", "common", "service_type")
  35. openshift_release = self.get_var("openshift_release", default='')
  36. deployment_type = self.get_var("openshift_deployment_type")
  37. check_multi_minor_release = deployment_type in ['openshift-enterprise']
  38. args = {
  39. "package_mgr": self.get_var("ansible_pkg_mgr"),
  40. "package_list": [
  41. {
  42. "name": "openvswitch",
  43. "version": self.get_required_ovs_version(),
  44. "check_multi": False,
  45. },
  46. {
  47. "name": "docker",
  48. "version": self.get_required_docker_version(),
  49. "check_multi": False,
  50. },
  51. {
  52. "name": "{}".format(rpm_prefix),
  53. "version": openshift_release,
  54. "check_multi": check_multi_minor_release,
  55. },
  56. {
  57. "name": "{}-master".format(rpm_prefix),
  58. "version": openshift_release,
  59. "check_multi": check_multi_minor_release,
  60. },
  61. {
  62. "name": "{}-node".format(rpm_prefix),
  63. "version": openshift_release,
  64. "check_multi": check_multi_minor_release,
  65. },
  66. ],
  67. }
  68. return self.execute_module_with_retries("aos_version", args)
  69. def get_required_ovs_version(self):
  70. """Return the correct Open vSwitch version(s) for the current OpenShift version."""
  71. openshift_version = self.get_openshift_version_tuple()
  72. earliest = min(self.openshift_to_ovs_version)
  73. latest = max(self.openshift_to_ovs_version)
  74. if openshift_version < earliest:
  75. return self.openshift_to_ovs_version[earliest]
  76. if openshift_version > latest:
  77. return self.openshift_to_ovs_version[latest]
  78. ovs_version = self.openshift_to_ovs_version.get(openshift_version)
  79. if not ovs_version:
  80. msg = "There is no recommended version of Open vSwitch for the current version of OpenShift: {}"
  81. raise OpenShiftCheckException(msg.format(".".join(str(comp) for comp in openshift_version)))
  82. return ovs_version
  83. def get_required_docker_version(self):
  84. """Return the correct Docker version(s) for the current OpenShift version."""
  85. openshift_version = self.get_openshift_version_tuple()
  86. earliest = min(self.openshift_to_docker_version)
  87. latest = max(self.openshift_to_docker_version)
  88. if openshift_version < earliest:
  89. return self.openshift_to_docker_version[earliest]
  90. if openshift_version > latest:
  91. return self.openshift_to_docker_version[latest]
  92. docker_version = self.openshift_to_docker_version.get(openshift_version)
  93. if not docker_version:
  94. msg = "There is no recommended version of Docker for the current version of OpenShift: {}"
  95. raise OpenShiftCheckException(msg.format(".".join(str(comp) for comp in openshift_version)))
  96. return docker_version
  97. def get_openshift_version_tuple(self):
  98. """Return received image tag as a normalized (X, Y) minor version tuple."""
  99. version = self.get_var("openshift_image_tag")
  100. comps = [int(component) for component in re.findall(r'\d+', version)]
  101. if len(comps) < 2:
  102. msg = "An invalid version of OpenShift was found for this host: {}"
  103. raise OpenShiftCheckException(msg.format(version))
  104. comps[0] = self.map_major_release_version.get(comps[0], comps[0])
  105. return tuple(comps[0:2])