package_version.py 4.9 KB

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