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.

135 lines
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 'opensuse'
  52. # rubocop:disable Style/NumericLiterals,Layout/LineLength
  53. inspec.platform[:release].to_i > 20210101 ? 'tumbleweed' : inspec.platform[:release]
  54. # rubocop:enable Style/NumericLiterals,Layout/LineLength
  55. when 'windows_8.1_pro'
  56. '8.1'
  57. when 'windows_server_2022_datacenter'
  58. '2022-server'
  59. when 'windows_server_2019_datacenter'
  60. '2019-server'
  61. when 'windows_server_2016_datacenter'
  62. '2016-server'
  63. else
  64. inspec.platform[:release]
  65. end
  66. end
  67. # rubocop:enable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity
  68. def derive_gentoo_init_system
  69. inspec.command('systemctl').exist? ? 'sysd' : 'sysv'
  70. end
  71. def build_platform_finger
  72. "#{build_platform_name}-#{build_finger_release}"
  73. end
  74. def build_finger_release
  75. case inspec.platform[:name]
  76. when 'ubuntu'
  77. build_platform_release.split('.').slice(0, 2).join('.')
  78. else
  79. build_platform_release.split('.')[0]
  80. end
  81. end
  82. # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity
  83. def build_platform_codename
  84. case build_platform_finger
  85. when 'ubuntu-20.04'
  86. 'focal'
  87. when 'ubuntu-18.04'
  88. 'bionic'
  89. when 'debian-11'
  90. 'bullseye'
  91. when 'debian-10'
  92. 'buster'
  93. when 'debian-9'
  94. 'stretch'
  95. when 'almalinux-8'
  96. "AlmaLinux #{build_platform_release} (Arctic Sphynx)"
  97. when 'amazonlinux-2'
  98. 'Amazon Linux 2'
  99. when 'arch-base-latest'
  100. 'Arch Linux'
  101. when 'centos-7'
  102. 'CentOS Linux 7 (Core)'
  103. when 'centos-8'
  104. 'CentOS Stream 8'
  105. when 'opensuse-tumbleweed'
  106. 'openSUSE Tumbleweed'
  107. when 'opensuse-15'
  108. "openSUSE Leap #{build_platform_release}"
  109. when 'oraclelinux-8', 'oraclelinux-7'
  110. "Oracle Linux Server #{build_platform_release}"
  111. when 'gentoo-2-sysd', 'gentoo-2-sysv'
  112. 'Gentoo/Linux'
  113. when 'rockylinux-8'
  114. "Rocky Linux #{build_platform_release} (Green Obsidian)"
  115. else
  116. ''
  117. end
  118. end
  119. # rubocop:enable Metrics/MethodLength,Metrics/CyclomaticComplexity
  120. end
  121. # rubocop:enable Metrics/ClassLength