Saltstack Official Chrony Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 satır
3.5KB

  1. # frozen_string_literal: true
  2. # system.rb -- InSpec resources for system values
  3. # Author: Daniel Dehennin <daniel.dehennin@ac-dijon.fr>
  4. # Copyright (C) 2020 Daniel Dehennin <daniel.dehennin@ac-dijon.fr>
  5. # rubocop:disable Metrics/ClassLength
  6. class SystemResource < Inspec.resource(1)
  7. name 'system'
  8. attr_reader :platform
  9. def initialize
  10. super
  11. @platform = build_platform
  12. end
  13. private
  14. def build_platform
  15. {
  16. family: build_platform_family,
  17. name: build_platform_name,
  18. release: build_platform_release,
  19. finger: build_platform_finger,
  20. codename: build_platform_codename
  21. }
  22. end
  23. def build_platform_family
  24. case inspec.platform[:name]
  25. when 'arch', 'gentoo'
  26. inspec.platform[:name]
  27. else
  28. inspec.platform[:family]
  29. end
  30. end
  31. def build_platform_name
  32. case inspec.platform[:name]
  33. when 'amazon', 'oracle', 'rocky'
  34. "#{inspec.platform[:name]}linux"
  35. when /^windows_/
  36. inspec.platform[:family]
  37. else
  38. inspec.platform[:name]
  39. end
  40. end
  41. # rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity
  42. def build_platform_release
  43. case inspec.platform[:name]
  44. when 'amazon'
  45. # `2018` relase is named `1` in `kitchen.yml`
  46. inspec.platform[:release].gsub(/2018.*/, '1')
  47. when 'arch'
  48. 'base-latest'
  49. when 'gentoo'
  50. "#{inspec.platform[:release].split('.')[0]}-#{derive_gentoo_init_system}"
  51. when 'mac_os_x'
  52. inspec.command('sw_vers -productVersion').stdout.to_s
  53. when 'opensuse'
  54. # rubocop:disable Style/NumericLiterals,Layout/LineLength
  55. inspec.platform[:release].to_i > 20210101 ? 'tumbleweed' : inspec.platform[:release]
  56. # rubocop:enable Style/NumericLiterals,Layout/LineLength
  57. when 'windows_8.1_pro'
  58. '8.1'
  59. when 'windows_server_2022_datacenter'
  60. '2022-server'
  61. when 'windows_server_2019_datacenter'
  62. '2019-server'
  63. when 'windows_server_2016_datacenter'
  64. '2016-server'
  65. else
  66. inspec.platform[:release]
  67. end
  68. end
  69. # rubocop:enable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity
  70. def derive_gentoo_init_system
  71. inspec.command('systemctl').exist? ? 'sysd' : 'sysv'
  72. end
  73. def build_platform_finger
  74. "#{build_platform_name}-#{build_finger_release}"
  75. end
  76. def build_finger_release
  77. case inspec.platform[:name]
  78. when 'ubuntu'
  79. build_platform_release.split('.').slice(0, 2).join('.')
  80. else
  81. build_platform_release.split('.')[0]
  82. end
  83. end
  84. # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity
  85. def build_platform_codename
  86. case build_platform_finger
  87. when 'ubuntu-20.04'
  88. 'focal'
  89. when 'ubuntu-18.04'
  90. 'bionic'
  91. when 'debian-11'
  92. 'bullseye'
  93. when 'debian-10'
  94. 'buster'
  95. when 'debian-9'
  96. 'stretch'
  97. when 'almalinux-8'
  98. "AlmaLinux #{build_platform_release} (Arctic Sphynx)"
  99. when 'amazonlinux-2'
  100. 'Amazon Linux 2'
  101. when 'arch-base-latest'
  102. 'Arch Linux'
  103. when 'centos-7'
  104. 'CentOS Linux 7 (Core)'
  105. when 'centos-8'
  106. 'CentOS Stream 8'
  107. when 'opensuse-tumbleweed'
  108. 'openSUSE Tumbleweed'
  109. when 'opensuse-15'
  110. "openSUSE Leap #{build_platform_release}"
  111. when 'oraclelinux-8', 'oraclelinux-7'
  112. "Oracle Linux Server #{build_platform_release}"
  113. when 'gentoo-2-sysd', 'gentoo-2-sysv'
  114. 'Gentoo/Linux'
  115. when 'rockylinux-8'
  116. "Rocky Linux #{build_platform_release} (Green Obsidian)"
  117. else
  118. ''
  119. end
  120. end
  121. # rubocop:enable Metrics/MethodLength,Metrics/CyclomaticComplexity
  122. end
  123. # rubocop:enable Metrics/ClassLength