package_version.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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_service_type")
  35. if self._templar is not None:
  36. rpm_prefix = self._templar.template(rpm_prefix)
  37. openshift_release = self.get_var("openshift_release", default='')
  38. deployment_type = self.get_var("openshift_deployment_type")
  39. check_multi_minor_release = deployment_type in ['openshift-enterprise']
  40. args = {
  41. "package_mgr": self.get_var("ansible_pkg_mgr"),
  42. "package_list": [
  43. {
  44. "name": "openvswitch",
  45. "version": self.get_required_ovs_version(),
  46. "check_multi": False,
  47. },
  48. {
  49. "name": "docker",
  50. "version": self.get_required_docker_version(),
  51. "check_multi": False,
  52. },
  53. {
  54. "name": "{}".format(rpm_prefix),
  55. "version": openshift_release,
  56. "check_multi": check_multi_minor_release,
  57. },
  58. {
  59. "name": "{}-master".format(rpm_prefix),
  60. "version": openshift_release,
  61. "check_multi": check_multi_minor_release,
  62. },
  63. {
  64. "name": "{}-node".format(rpm_prefix),
  65. "version": openshift_release,
  66. "check_multi": check_multi_minor_release,
  67. },
  68. ],
  69. }
  70. return self.execute_module_with_retries("aos_version", args)
  71. def get_required_ovs_version(self):
  72. """Return the correct Open vSwitch version(s) for the current OpenShift version."""
  73. openshift_version = self.get_openshift_version_tuple()
  74. earliest = min(self.openshift_to_ovs_version)
  75. latest = max(self.openshift_to_ovs_version)
  76. if openshift_version < earliest:
  77. return self.openshift_to_ovs_version[earliest]
  78. if openshift_version > latest:
  79. return self.openshift_to_ovs_version[latest]
  80. ovs_version = self.openshift_to_ovs_version.get(openshift_version)
  81. if not ovs_version:
  82. msg = "There is no recommended version of Open vSwitch for the current version of OpenShift: {}"
  83. raise OpenShiftCheckException(msg.format(".".join(str(comp) for comp in openshift_version)))
  84. return ovs_version
  85. def get_required_docker_version(self):
  86. """Return the correct Docker version(s) for the current OpenShift version."""
  87. openshift_version = self.get_openshift_version_tuple()
  88. earliest = min(self.openshift_to_docker_version)
  89. latest = max(self.openshift_to_docker_version)
  90. if openshift_version < earliest:
  91. return self.openshift_to_docker_version[earliest]
  92. if openshift_version > latest:
  93. return self.openshift_to_docker_version[latest]
  94. docker_version = self.openshift_to_docker_version.get(openshift_version)
  95. if not docker_version:
  96. msg = "There is no recommended version of Docker for the current version of OpenShift: {}"
  97. raise OpenShiftCheckException(msg.format(".".join(str(comp) for comp in openshift_version)))
  98. return docker_version
  99. def get_openshift_version_tuple(self):
  100. """Return received image tag as a normalized (X, Y) minor version tuple."""
  101. version = self.get_var("openshift_image_tag")
  102. comps = [int(component) for component in re.findall(r'\d+', version)]
  103. if len(comps) < 2:
  104. msg = "An invalid version of OpenShift was found for this host: {}"
  105. raise OpenShiftCheckException(msg.format(version))
  106. comps[0] = self.map_major_release_version.get(comps[0], comps[0])
  107. return tuple(comps[0:2])