package_version.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. """Check that available RPM packages match the required versions."""
  2. from openshift_checks import OpenShiftCheck
  3. from openshift_checks.mixins import NotContainerizedMixin
  4. class PackageVersion(NotContainerizedMixin, OpenShiftCheck):
  5. """Check that available RPM packages match the required versions."""
  6. name = "package_version"
  7. tags = ["preflight"]
  8. # NOTE: versions outside those specified are mapped to least/greatest
  9. openshift_to_ovs_version = {
  10. (3, 4): "2.4",
  11. (3, 5): ["2.6", "2.7"],
  12. (3, 6): ["2.6", "2.7", "2.8"],
  13. (3, 7): ["2.6", "2.7", "2.8"],
  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. def is_active(self):
  24. """Skip hosts that do not have package requirements."""
  25. group_names = self.get_var("group_names", default=[])
  26. master_or_node = 'oo_masters_to_config' in group_names or 'oo_nodes_to_config' in group_names
  27. return super(PackageVersion, self).is_active() and master_or_node
  28. def run(self):
  29. rpm_prefix = self.get_var("openshift_service_type")
  30. if self._templar is not None:
  31. rpm_prefix = self._templar.template(rpm_prefix)
  32. openshift_release = self.get_var("openshift_release", default='')
  33. deployment_type = self.get_var("openshift_deployment_type")
  34. check_multi_minor_release = deployment_type in ['openshift-enterprise']
  35. args = {
  36. "package_mgr": self.get_var("ansible_pkg_mgr"),
  37. "package_list": [
  38. {
  39. "name": "openvswitch",
  40. "version": self.get_required_ovs_version(),
  41. "check_multi": False,
  42. },
  43. {
  44. "name": "docker",
  45. "version": self.get_required_docker_version(),
  46. "check_multi": False,
  47. },
  48. {
  49. "name": "{}".format(rpm_prefix),
  50. "version": openshift_release,
  51. "check_multi": check_multi_minor_release,
  52. },
  53. {
  54. "name": "{}-master".format(rpm_prefix),
  55. "version": openshift_release,
  56. "check_multi": check_multi_minor_release,
  57. },
  58. {
  59. "name": "{}-node".format(rpm_prefix),
  60. "version": openshift_release,
  61. "check_multi": check_multi_minor_release,
  62. },
  63. ],
  64. }
  65. return self.execute_module_with_retries("aos_version", args)
  66. def get_required_ovs_version(self):
  67. """Return the correct Open vSwitch version(s) for the current OpenShift version."""
  68. return self.get_required_version("Open vSwitch", self.openshift_to_ovs_version)
  69. def get_required_docker_version(self):
  70. """Return the correct Docker version(s) for the current OpenShift version."""
  71. return self.get_required_version("Docker", self.openshift_to_docker_version)