foreman_ansible 6.4.1 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v2/ansible_inventories_controller.rb +1 -1
  3. data/app/graphql/mutations/ansible_variable_overrides/create.rb +26 -0
  4. data/app/graphql/mutations/ansible_variable_overrides/delete.rb +38 -0
  5. data/app/graphql/mutations/ansible_variable_overrides/update.rb +26 -0
  6. data/app/graphql/mutations/hosts/assign_ansible_roles.rb +37 -0
  7. data/app/graphql/presenters/ansible_role_presenter.rb +12 -0
  8. data/app/graphql/presenters/overriden_ansible_variable_presenter.rb +19 -0
  9. data/app/graphql/types/ansible_role.rb +9 -0
  10. data/app/graphql/types/ansible_variable.rb +23 -0
  11. data/app/graphql/types/ansible_variable_override.rb +9 -0
  12. data/app/graphql/types/inherited_ansible_role.rb +13 -0
  13. data/app/graphql/types/overriden_ansible_variable.rb +27 -0
  14. data/app/helpers/foreman_ansible/ansible_roles_data_preparations.rb +22 -22
  15. data/app/models/concerns/foreman_ansible/host_managed_extensions.rb +23 -4
  16. data/app/models/concerns/foreman_ansible/hostgroup_extensions.rb +2 -1
  17. data/app/models/foreman_ansible/ansible_provider.rb +7 -5
  18. data/app/services/foreman_ansible/ansible_report_importer.rb +2 -2
  19. data/app/services/foreman_ansible/inventory_creator.rb +1 -1
  20. data/app/services/foreman_ansible/override_resolver.rb +22 -0
  21. data/app/views/api/v2/ansible_override_values/index.json.rabl +3 -0
  22. data/app/views/api/v2/ansible_variables/show.json.rabl +1 -1
  23. data/app/views/foreman_ansible/ansible_roles/_hostgroup_ansible_roles_button.erb +3 -0
  24. data/app/views/foreman_ansible/job_templates/convert_to_rhel.erb +6 -2
  25. data/app/views/foreman_ansible/job_templates/run_openscap_scans_-_ansible_default.erb +20 -0
  26. data/config/routes.rb +3 -0
  27. data/db/migrate/20210818083407_fix_ansible_setting_category_to_dsl.rb +5 -0
  28. data/lib/foreman_ansible/engine.rb +0 -17
  29. data/lib/foreman_ansible/register.rb +115 -4
  30. data/lib/foreman_ansible/version.rb +1 -1
  31. data/package.json +4 -2
  32. data/test/functional/api/v2/ansible_inventories_controller_test.rb +1 -2
  33. data/test/graphql/mutations/hosts/assign_ansible_roles_mutation_test.rb +96 -0
  34. data/test/graphql/queries/ansible_roles_query_test.rb +35 -0
  35. data/test/unit/ansible_provider_test.rb +3 -6
  36. data/test/unit/concerns/host_managed_extensions_test.rb +8 -0
  37. data/test/unit/concerns/hostgroup_extensions_test.rb +6 -0
  38. data/test/unit/hostgroup_ansible_role_test.rb +13 -0
  39. data/test/unit/services/override_resolver_test.rb +34 -0
  40. data/webpack/components/AnsibleHostDetail/AnsibleHostDetail.js +51 -27
  41. data/webpack/components/AnsibleHostDetail/AnsibleHostDetail.test.js +12 -6
  42. data/webpack/components/AnsibleHostDetail/components/AnsibleHostInventory/AnsibleHostInventory.js +22 -0
  43. data/webpack/components/AnsibleHostDetail/components/AnsibleHostInventory/AnsibleHostInventory.scss +4 -0
  44. data/webpack/components/AnsibleHostDetail/components/AnsibleHostInventory/AnsibleHostInventory.test.js +104 -0
  45. data/webpack/components/AnsibleHostDetail/components/AnsibleHostInventory/index.js +38 -0
  46. data/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/AnsibleVariableOverrides.scss +3 -0
  47. data/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/AnsibleVariableOverridesTable.js +238 -0
  48. data/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/AnsibleVariableOverridesTableHelper.js +111 -0
  49. data/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableAction.js +161 -0
  50. data/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableAction.scss +7 -0
  51. data/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableActionHelper.js +49 -0
  52. data/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js +70 -0
  53. data/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValueHelper.js +35 -0
  54. data/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/__test__/AnsibleVariableOverrides.fixtures.js +429 -0
  55. data/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/__test__/AnsibleVariableOverrides.test.js +71 -0
  56. data/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/__test__/AnsibleVariableOverridesDelete.test.js +74 -0
  57. data/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/__test__/AnsibleVariableOverridesUpdate.test.js +188 -0
  58. data/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/index.js +58 -0
  59. data/webpack/components/AnsibleHostDetail/components/JobsTab/JobsTabHelper.js +79 -0
  60. data/webpack/components/AnsibleHostDetail/components/JobsTab/NewRecurringJobHelper.js +106 -0
  61. data/webpack/components/AnsibleHostDetail/components/JobsTab/NewRecurringJobModal.js +129 -0
  62. data/webpack/components/AnsibleHostDetail/components/JobsTab/NewRecurringJobModal.scss +7 -0
  63. data/webpack/components/AnsibleHostDetail/components/JobsTab/PreviousJobsTable.js +103 -0
  64. data/webpack/components/AnsibleHostDetail/components/JobsTab/RecurringJobsTable.js +96 -0
  65. data/webpack/components/AnsibleHostDetail/components/JobsTab/__test__/JobsTab.fixtures.js +184 -0
  66. data/webpack/components/AnsibleHostDetail/components/JobsTab/__test__/JobsTab.test.js +195 -0
  67. data/webpack/components/AnsibleHostDetail/components/JobsTab/index.js +88 -0
  68. data/webpack/components/AnsibleHostDetail/components/RolesTab/AllRolesModal/AllRolesTable.js +89 -0
  69. data/webpack/components/AnsibleHostDetail/components/RolesTab/AllRolesModal/index.js +80 -0
  70. data/webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesForm.js +90 -0
  71. data/webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModal.scss +3 -0
  72. data/webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js +40 -0
  73. data/webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/index.js +82 -0
  74. data/webpack/components/AnsibleHostDetail/components/RolesTab/RolesTable.js +129 -0
  75. data/webpack/components/AnsibleHostDetail/components/RolesTab/__test__/EditRoles.test.js +85 -0
  76. data/webpack/components/AnsibleHostDetail/components/RolesTab/__test__/RolesTab.fixtures.js +180 -0
  77. data/webpack/components/AnsibleHostDetail/components/RolesTab/__test__/RolesTab.test.js +75 -0
  78. data/webpack/components/AnsibleHostDetail/components/RolesTab/index.js +51 -0
  79. data/webpack/components/AnsibleHostDetail/components/SecondaryTabRoutes.js +60 -0
  80. data/webpack/components/AnsibleHostDetail/components/TabLayout.js +12 -0
  81. data/webpack/components/AnsibleHostDetail/constants.js +9 -0
  82. data/webpack/components/AnsibleHostDetail/helpers.js +4 -0
  83. data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesImport.test.js +15 -10
  84. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.js +29 -0
  85. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.test.js +3 -0
  86. data/webpack/components/AnsibleRolesSwitcher/components/AvailableRolesList.js +2 -1
  87. data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AnsibleRole.test.js.snap +3 -3
  88. data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AvailableRolesList.test.js.snap +4 -0
  89. data/webpack/components/DualList/DualList.scss +3 -0
  90. data/webpack/components/DualList/ListControls.js +65 -0
  91. data/webpack/components/DualList/ListHeader.js +16 -0
  92. data/webpack/components/DualList/ListItem.js +69 -0
  93. data/webpack/components/DualList/ListPane.js +95 -0
  94. data/webpack/components/DualList/SelectedStatus.js +21 -0
  95. data/webpack/components/DualList/index.js +103 -0
  96. data/webpack/components/ErrorState.js +16 -0
  97. data/webpack/components/withLoading.js +135 -0
  98. data/webpack/components/withPagination.js +0 -0
  99. data/webpack/formHelper.js +131 -0
  100. data/webpack/globalIdHelper.js +13 -0
  101. data/webpack/global_index.js +7 -1
  102. data/webpack/graphql/mutations/assignAnsibleRoles.gql +17 -0
  103. data/webpack/graphql/mutations/cancelRecurringLogic.gql +12 -0
  104. data/webpack/graphql/mutations/createAnsibleVariableOverride.gql +28 -0
  105. data/webpack/graphql/mutations/createJobInvocation.gql +11 -0
  106. data/webpack/graphql/mutations/deleteAnsibleVariableOverride.gql +17 -0
  107. data/webpack/graphql/mutations/updateAnsibleVariableOverride.gql +29 -0
  108. data/webpack/graphql/queries/allAnsibleRoles.gql +13 -0
  109. data/webpack/graphql/queries/ansibleRoles.gql +13 -0
  110. data/webpack/graphql/queries/currentUserAttributes.gql +11 -0
  111. data/webpack/graphql/queries/hostAnsibleRoles.gql +17 -0
  112. data/webpack/graphql/queries/hostAvailableAnsibleRoles.gql +11 -0
  113. data/webpack/graphql/queries/hostVariableOverrides.gql +39 -0
  114. data/webpack/graphql/queries/recurringJobs.gql +28 -0
  115. data/webpack/helpers/pageParamsHelper.js +40 -0
  116. data/webpack/helpers/paginationHelper.js +9 -0
  117. data/webpack/permissionsHelper.js +58 -0
  118. data/webpack/routes/HostgroupJobs/__test__/HostgroupJobs.fixtures.js +63 -0
  119. data/webpack/routes/HostgroupJobs/__test__/HostgroupJobs.test.js +112 -0
  120. data/webpack/routes/HostgroupJobs/index.js +26 -0
  121. data/webpack/routes/routes.js +10 -0
  122. data/webpack/testHelper.js +165 -0
  123. data/webpack/toastHelper.js +4 -0
  124. metadata +127 -54
  125. data/app/assets/images/foreman_ansible/Ansible.png +0 -0
  126. data/app/models/foreman_ansible/fact_name.rb +0 -16
  127. data/app/models/setting/ansible.rb +0 -106
  128. data/app/services/foreman_ansible/fact_importer.rb +0 -99
  129. data/app/services/foreman_ansible/fact_parser.rb +0 -126
  130. data/app/services/foreman_ansible/fact_sparser.rb +0 -37
  131. data/app/services/foreman_ansible/operating_system_parser.rb +0 -102
  132. data/app/services/foreman_ansible/structured_fact_importer.rb +0 -25
  133. data/test/unit/services/fact_importer_test.rb +0 -52
  134. data/test/unit/services/fact_parser_test.rb +0 -281
  135. data/test/unit/services/fact_sparser_test.rb +0 -24
  136. data/test/unit/services/structured_fact_importer_test.rb +0 -30
  137. data/webpack/components/AnsibleRolesAndVariables/__test__/__snapshots__/AnsibleRolesAndVariablesImport.test.js.snap +0 -177
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ForemanAnsible
4
- # See sparse and unsparse documentation
5
- class FactSparser
6
- class << self
7
- # Sparses facts, so that it converts a facts hash
8
- # { operatingsystem : { major: 20, name : 'fedora' }
9
- # into
10
- # { operatingsystem::major: 20,
11
- # operatingsystem::name: 'fedora' }
12
- def sparse(hash, options = {})
13
- hash.map do |k, v|
14
- prefix = options.fetch(:prefix, []) + [k]
15
- next sparse(v, options.merge(:prefix => prefix)) if v.is_a? Hash
16
- { prefix.join(options.fetch(:separator, FactName::SEPARATOR)) => v }
17
- end.reduce(:merge) || {}
18
- end
19
-
20
- # Unsparses facts, so that it converts a hash with facts
21
- # { operatingsystem::major: 20,
22
- # operatingsystem::name: 'fedora' }
23
- # into
24
- # { operatingsystem : { major: 20, name: 'fedora' } }
25
- def unsparse(facts_hash)
26
- ret = {}
27
- sparse(facts_hash).each do |full_name, value|
28
- current = ret
29
- fact_name = full_name.to_s.split(FactName::SEPARATOR)
30
- current = (current[fact_name.shift] ||= {}) until fact_name.size <= 1
31
- current[fact_name.first] = value
32
- end
33
- ret
34
- end
35
- end
36
- end
37
- end
@@ -1,102 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ForemanAnsible
4
- # Methods to parse facts related to the OS
5
- module OperatingSystemParser
6
- def operatingsystem
7
- args = { :name => os_name, :major => os_major, :minor => os_minor }
8
- args[:release_name] = os_release_name if os_name == 'Debian' || os_name == 'Ubuntu'
9
- return @local_os if local_os(args).present?
10
- return @new_os if new_os(args).present?
11
- logger.debug do
12
- 'Ansible facts parser: No OS could be created with '\
13
- "os_name='#{os_name}' os_major='#{os_major}' "\
14
- "os_minor='#{os_minor}': "\
15
- "#{@new_os.errors if @new_os.present?}"
16
- end
17
- nil
18
- end
19
-
20
- def local_os(args)
21
- @local_os = Operatingsystem.where(args).first
22
- end
23
-
24
- def new_os(args)
25
- return @new_os if @new_os.present?
26
- @new_os = Operatingsystem.new(args.merge(:description => os_description))
27
- @new_os if @new_os.valid? && @new_os.save
28
- end
29
-
30
- def debian_os_major_sid
31
- case facts[:ansible_distribution_major_version]
32
- when /wheezy/i
33
- '7'
34
- when /jessie/i
35
- '8'
36
- when /stretch/i
37
- '9'
38
- when /buster/i
39
- '10'
40
- end
41
- end
42
-
43
- def os_release_name
44
- return '' if os_name != 'Debian' && os_name != 'Ubuntu'
45
- facts[:ansible_distribution_release]
46
- end
47
-
48
- def os_major
49
- if os_name == 'Debian' &&
50
- facts[:ansible_distribution_major_version][%r{\/sid}i]
51
- debian_os_major_sid
52
- else
53
- facts[:ansible_distribution_major_version] ||
54
- facts[:ansible_lsb] && facts[:ansible_lsb]['major_release'] ||
55
- (facts[:version].split('R')[0] if os_name == 'junos')
56
- end
57
- end
58
-
59
- def os_release
60
- facts[:ansible_distribution_version] ||
61
- facts[:ansible_lsb] && facts[:ansible_lsb]['release']
62
- end
63
-
64
- def os_minor
65
- _, minor = os_release&.split('.', 2) ||
66
- (facts[:version].split('R') if os_name == 'junos')
67
- # Until Foreman supports os.minor as something that's not a number,
68
- # we should remove the extra dots in the version. E.g:
69
- # '6.1.7601.65536' becomes '6.1.760165536'
70
- if facts[:ansible_os_family] == 'Windows'
71
- minor, patch = minor.split('.', 2)
72
- patch.tr!('.', '')
73
- minor = "#{minor}.#{patch}"
74
- end
75
- minor || ''
76
- end
77
-
78
- def os_name
79
- if facts[:ansible_os_family] == 'Windows'
80
- facts[:ansible_os_name].tr(" \n\t", '') ||
81
- facts[:ansible_distribution].tr(" \n\t", '')
82
- else
83
- distribution = facts[:ansible_lsb].try(:[], 'id') || facts[:ansible_distribution]
84
-
85
- if distribution == 'RedHat' &&
86
- facts[:ansible_lsb].try(:[], 'id') == 'RedHatEnterpriseWorkstation'
87
- distribution += '_Workstation'
88
- end
89
-
90
- distribution
91
- end
92
- end
93
-
94
- def os_description
95
- if facts[:ansible_os_family] == 'Windows'
96
- facts[:ansible_os_name].strip || facts[:ansible_distribution].strip
97
- else
98
- facts[:ansible_lsb] && facts[:ansible_lsb]['description']
99
- end
100
- end
101
- end
102
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ForemanAnsible
4
- # On 1.13+ , use the parser for structured facts (like Facter 2) that comes
5
- # from core
6
- class StructuredFactImporter < ::StructuredFactImporter
7
- def fact_name_class
8
- ForemanAnsible::FactName
9
- end
10
-
11
- def self.authorized_smart_proxy_features
12
- 'Ansible'
13
- end
14
-
15
- def initialize(host, facts = {})
16
- # Try to assign these facts to the correct host as per the facts say
17
- # If that host isn't created yet, the host parameter will contain it
18
- @host = Host.find_by(:name => facts[:ansible_facts][:ansible_fqdn] ||
19
- facts[:ansible_facts][:fqdn]) ||
20
- host
21
- @facts = normalize(facts[:ansible_facts])
22
- @counters = {}
23
- end
24
- end
25
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_plugin_helper'
4
-
5
- module ForemanAnsible
6
- # Test for the facts importer - only verify that given
7
- # a set of facts it's able to import them
8
- class FactImporterTest < ActiveSupport::TestCase
9
- setup do
10
- @host = FactoryBot.build(:host)
11
- end
12
-
13
- test 'add new facts adds all fact names in the fixture' do
14
- @fact_importer = FactImporter.new(@host, facts_json)
15
- facts_to_be_added = FactSparser.sparse(facts_json[:ansible_facts]).keys +
16
- FactSparser.unsparse(facts_json[:ansible_facts]).keys
17
- @fact_importer.send(:add_new_facts)
18
- assert((facts_to_be_added - FactName.all.map(&:name)).empty?)
19
- end
20
-
21
- test 'missing_facts returns facts we do not have in the database' do
22
- @fact_importer = FactImporter.new(@host, facts_json)
23
- @fact_importer.expects(:host_fact_names).
24
- returns(['ansible_cmdline'])
25
- refute @fact_importer.send(:missing_facts).include?('ansible_cmdline')
26
- end
27
-
28
- describe '#add_fact_value' do
29
- setup do
30
- @fact_importer = FactImporter.new(@host, :ansible_facts => {})
31
- end
32
- test 'does not add existing facts' do
33
- existing_fact = FactoryBot.build(:fact_name)
34
- @fact_importer.expects(:missing_facts).returns([])
35
- assert_nil @fact_importer.send(:add_fact_value, nil, existing_fact)
36
- end
37
-
38
- test 'adds missing facts' do
39
- missing_fact = FactoryBot.build(:fact_name)
40
- @fact_importer.expects(:missing_facts).returns([missing_fact.name])
41
- @fact_importer.counters[:added] = 0
42
- assert_difference('@host.fact_values.count', 1) do
43
- @fact_importer.send(:add_fact_value, 'missing_value', missing_fact)
44
- @host.save
45
- # We have to save the host in order to ensure @host.fact_values.count
46
- # resolves properly (otherwise) :add_fact_value just won't save the
47
- # relation
48
- end
49
- end
50
- end
51
- end
52
- end
@@ -1,281 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_plugin_helper'
4
-
5
- module ForemanAnsible
6
- # Checks sample Ansible facts to see if it can assign them to
7
- # Host properties
8
- class FactParserTest < ActiveSupport::TestCase
9
- setup do
10
- @facts_parser = ForemanAnsible::FactParser.new(facts_json)
11
- end
12
-
13
- test 'finds facter domain even if ansible_domain is empty' do
14
- expect_where(Domain, @facts_parser.facts[:facter_domain])
15
- @facts_parser.domain
16
- end
17
-
18
- test 'finds model' do
19
- expect_where(Model, @facts_parser.facts[:ansible_product_name])
20
- @facts_parser.model
21
- end
22
-
23
- test 'finds architecture' do
24
- expect_where(Architecture, @facts_parser.facts[:ansible_architecture])
25
- @facts_parser.architecture
26
- end
27
-
28
- test 'does not set environment' do
29
- refute @facts_parser.environment
30
- end
31
-
32
- test 'calculates virtual reported data' do
33
- refute @facts_parser.virtual
34
- end
35
-
36
- test 'calculates ram reported data' do
37
- assert_equal 7899, @facts_parser.ram
38
- end
39
-
40
- test 'calculates sockets reported data' do
41
- assert_equal 1, @facts_parser.sockets
42
- end
43
-
44
- test 'calculates cores reported data' do
45
- assert_equal 2, @facts_parser.cores
46
- end
47
-
48
- test 'creates operatingsystem from operating system options' do
49
- sample_mock = mock
50
- major_fact = @facts_parser.facts['ansible_distribution_major_version']
51
- _, minor_fact = @facts_parser.
52
- facts['ansible_distribution_version'].split('.')
53
- Operatingsystem.expects(:where).
54
- with(:name => @facts_parser.facts['ansible_distribution'],
55
- :major => major_fact, :minor => minor_fact || '').
56
- returns(sample_mock)
57
- sample_mock.expects(:first)
58
- @facts_parser.operatingsystem
59
- end
60
-
61
- test 'does not fail if facts are not enough to create OS' do
62
- @facts_parser.expects(:os_name).returns('fakeos').at_least_once
63
- @facts_parser.expects(:os_major).returns('').at_least_once
64
- @facts_parser.expects(:os_minor).returns('').at_least_once
65
- @facts_parser.expects(:os_description).returns('').at_least_once
66
- Operatingsystem.any_instance.expects(:valid?).returns(false)
67
- assert_nil @facts_parser.operatingsystem
68
- end
69
-
70
- private
71
-
72
- def expect_where(model, fact_name)
73
- sample_mock = mock
74
- model.expects(:where).
75
- with(:name => fact_name).
76
- returns(sample_mock)
77
- sample_mock.expects(:first_or_create)
78
- end
79
- end
80
-
81
- # Tests for Network parser
82
- class NetworkFactParserTest < ActiveSupport::TestCase
83
- setup do
84
- @facts_parser = ForemanAnsible::FactParser.new(
85
- HashWithIndifferentAccess.new(
86
- '_type' => 'ansible',
87
- '_timestamp' => '2018-10-29 20:01:51 +0100',
88
- 'ansible_facts' =>
89
- {
90
- 'ansible_interfaces' => %w[eth0 eth1 eth2 bond0],
91
- 'ansible_eth0' => {
92
- 'active' => true,
93
- 'device' => 'eth0',
94
- 'macaddress' => '52:54:00:04:55:37',
95
- 'perm_macaddress' => '52:54:00:04:55:37',
96
- 'ipv4' => {
97
- 'address' => '10.10.0.10',
98
- 'netmask' => '255.255.0.0',
99
- 'network' => '10.10.0.0'
100
- },
101
- 'ipv6' => [
102
- {
103
- 'address' => 'fd00::5054:00ff:fe04:5537',
104
- 'prefix' => '64',
105
- 'scope' => 'host'
106
- }
107
- ],
108
- 'mtu' => 1500,
109
- 'promisc' => false,
110
- 'type' => 'ether'
111
- },
112
- 'ansible_eth1' => {
113
- 'active' => true,
114
- 'device' => 'eth1',
115
- 'macaddress' => '52:54:00:04:55:38',
116
- 'perm_macaddress' => '52:54:00:04:55:38',
117
- 'mtu' => 1500,
118
- 'promisc' => false,
119
- 'type' => 'ether'
120
- },
121
- 'ansible_eth2' => {
122
- 'active' => true,
123
- 'device' => 'eth2',
124
- 'macaddress' => '52:54:00:04:55:38',
125
- 'perm_macaddress' => '52:54:00:04:55:39',
126
- 'mtu' => 1500,
127
- 'promisc' => false,
128
- 'type' => 'ether'
129
- },
130
- 'ansible_bond0' => {
131
- 'active' => true,
132
- 'device' => 'bond0',
133
- 'macaddress' => '52:54:00:04:55:38',
134
- 'ipv4' => {
135
- 'address' => '10.10.0.11',
136
- 'netmask' => '255.255.0.0',
137
- 'network' => '10.10.0.0'
138
- },
139
- 'ipv6' => [
140
- {
141
- 'address' => 'fd00::5054:00ff:fe04:5538',
142
- 'prefix' => '64',
143
- 'scope' => 'host'
144
- }
145
- ],
146
- 'mtu' => 1500,
147
- 'promisc' => false,
148
- 'slaves' => %w[eth1 eth2],
149
- 'type' => 'bonding'
150
- }
151
- }
152
- )
153
- )
154
- end
155
-
156
- test 'Parses IPv4 & IPv6 addresses correctly' do
157
- iut = 'eth0'.dup
158
- interface = @facts_parser.get_facts_for_interface(iut)
159
- assert_equal '10.10.0.10', interface['ipaddress']
160
- assert_equal 'fd00::5054:00ff:fe04:5537', interface['ipaddress6']
161
- end
162
-
163
- test 'Parses MAC address correctly when bonded' do
164
- iut0 = 'eth0'.dup
165
- iut1 = 'eth1'.dup
166
- iut2 = 'eth2'.dup
167
- but0 = 'bond0'.dup
168
- interface_eth0 = @facts_parser.get_facts_for_interface(iut0)
169
- interface_eth1 = @facts_parser.get_facts_for_interface(iut1)
170
- interface_eth2 = @facts_parser.get_facts_for_interface(iut2)
171
- interface_bond0 = @facts_parser.get_facts_for_interface(but0)
172
- assert_equal '52:54:00:04:55:37', interface_eth0['macaddress']
173
- assert_equal '52:54:00:04:55:38', interface_eth1['macaddress']
174
- assert_equal '52:54:00:04:55:39', interface_eth2['macaddress']
175
- assert_equal '52:54:00:04:55:38', interface_bond0['macaddress']
176
- end
177
- end
178
-
179
- # Tests for Debian parser
180
- class DebianFactParserTest < ActiveSupport::TestCase
181
- setup do
182
- @facts_parser = ForemanAnsible::FactParser.new(
183
- HashWithIndifferentAccess.new(
184
- '_type' => 'ansible',
185
- '_timestamp' => '2015-10-29 20:01:51 +0100',
186
- 'ansible_facts' =>
187
- {
188
- "ansible_distribution" => "Debian",
189
- "ansible_distribution_file_parsed" => true,
190
- "ansible_distribution_file_path" => "/etc/os-release",
191
- "ansible_distribution_file_variety" => "Debian",
192
- "ansible_distribution_major_version" => "8",
193
- "ansible_distribution_release" => "jessie",
194
- "ansible_distribution_version" => "8.7"
195
- }
196
- )
197
- )
198
- end
199
-
200
- test 'Parses debian jessie correctly' do
201
- as_admin do
202
- os = @facts_parser.operatingsystem
203
-
204
- assert_equal '8', os.major
205
- assert_equal 'Debian', os.name
206
- end
207
- end
208
- end
209
-
210
- # Tests for Windows parser
211
- class WindowsFactParserTest < ActiveSupport::TestCase
212
- context 'Windows 7' do
213
- setup do
214
- @facts_parser = ForemanAnsible::FactParser.new(
215
- HashWithIndifferentAccess.new(
216
- '_type' => 'ansible',
217
- '_timestamp' => '2015-10-29 20:01:51 +0100',
218
- 'ansible_facts' => {
219
- 'ansible_architecture' => '32-Bit',
220
- 'ansible_distribution' => 'Microsoft Windows 7 Enterprise ',
221
- 'ansible_distribution_major_version' => '6',
222
- 'ansible_distribution_version' => '6.1.7601.65536',
223
- 'ansible_os_family' => 'Windows',
224
- 'ansible_os_name' => 'Microsoft Windows 7 Enterprise',
225
- 'ansible_product_name' => 'DS61',
226
- 'ansible_product_serial' => 'To be filled by O.E.M.',
227
- 'ansible_system' => 'Win32NT',
228
- 'ansible_win_rm_certificate_expires' => '2021-01-23 15:08:48',
229
- 'ansible_windows_domain' => 'example.com'
230
- }
231
- )
232
- )
233
- end
234
-
235
- test 'parses Windows 7 Enterprise correctly' do
236
- os = @facts_parser.operatingsystem
237
- assert_equal '6', os.major
238
- assert_equal '6.1.760165536', os.release
239
- assert_equal '1.760165536', os.minor
240
- assert_equal 'Windows', os.family
241
- assert_equal 'Microsoft Windows 7 Enterprise', os.description
242
- assert_equal 'MicrosoftWindows7Enterprise', os.name
243
- assert os.valid?
244
- end
245
- end
246
-
247
- context 'Windows Server 2016' do
248
- setup do
249
- @facts_parser = ForemanAnsible::FactParser.new(
250
- HashWithIndifferentAccess.new(
251
- '_type' => 'ansible',
252
- '_timestamp' => '2015-10-29 20:01:51 +0100',
253
- 'ansible_facts' => {
254
- 'ansible_architecture' => '64-Bit',
255
- 'ansible_distribution' => 'Microsoft Windows Server 2016 '\
256
- 'Standard',
257
- 'ansible_distribution_major_version' => '10',
258
- 'ansible_distribution_version' => '10.0.14393.0',
259
- 'ansible_os_family' => 'Windows',
260
- 'ansible_os_name' => 'Microsoft Windows Server 2016 Standard',
261
- 'ansible_system' => 'Win32NT',
262
- 'ansible_win_rm_certificate_expires' => '2021-01-23 15:08:48',
263
- 'ansible_windows_domain' => 'example.com'
264
- }
265
- )
266
- )
267
- end
268
-
269
- test 'parses Windows Server correctly' do
270
- os = @facts_parser.operatingsystem
271
- assert_equal '10', os.major
272
- assert_equal '10.0.143930', os.release
273
- assert_equal '0.143930', os.minor
274
- assert_equal 'Windows', os.family
275
- assert_equal 'Microsoft Windows Server 2016 Standard', os.description
276
- assert_equal 'MicrosoftWindowsServer2016Standard', os.name
277
- assert os.valid?
278
- end
279
- end
280
- end
281
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ForemanAnsible
4
- # Tests for checking if FactSparser can sparse a hash and unsparse it
5
- class FactSparserTest < ActiveSupport::TestCase
6
- setup do
7
- @original_os_facts = { 'operatingsystem' => { 'major' => 20, 'minor' => 1,
8
- 'name' => 'Fedora' } }
9
- @sparsed_os_facts = { 'operatingsystem::major' => 20,
10
- 'operatingsystem::minor' => 1,
11
- 'operatingsystem::name' => 'Fedora' }
12
- end
13
-
14
- test 'sparses simple hash' do
15
- assert_equal @sparsed_os_facts,
16
- ForemanAnsible::FactSparser.sparse(@original_os_facts)
17
- end
18
-
19
- test 'unsparse simple hash' do
20
- assert_equal @original_os_facts,
21
- ForemanAnsible::FactSparser.unsparse(@sparsed_os_facts)
22
- end
23
- end
24
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_plugin_helper'
4
-
5
- module ForemanAnsible
6
- # Test for the structured facts importer - its code mostly lives in Foreman
7
- # core, so only details have to be tested here.
8
- class StructuredFactImporterTest < ActiveSupport::TestCase
9
- test 'if host is not in Foreman, use hostname provided by call' do
10
- fake_host = Host.new(:name => 'fake')
11
- importer = ForemanAnsible::StructuredFactImporter.new(
12
- fake_host,
13
- facts_json
14
- )
15
- assert_equal fake_host, importer.send(:host)
16
- end
17
-
18
- test 'if host is in Foreman, use hostname provided by Ansible' do
19
- ansible_fqdn_host = FactoryBot.build(:host)
20
- ansible_fqdn_host.name = facts_json[:ansible_facts][:ansible_fqdn]
21
- ansible_fqdn_host.save
22
- importer = ForemanAnsible::StructuredFactImporter.new(
23
- Host.new(:name => 'fake'),
24
- facts_json
25
- )
26
-
27
- assert_equal ansible_fqdn_host, importer.send(:host)
28
- end
29
- end
30
- end