foreman_ansible 2.2.14 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +2 -0
  3. data/app/controllers/ansible_roles_controller.rb +4 -11
  4. data/app/controllers/ansible_variables_controller.rb +80 -0
  5. data/app/controllers/api/v2/ansible_roles_controller.rb +2 -0
  6. data/app/controllers/api/v2/ansible_variables_controller.rb +68 -0
  7. data/app/controllers/concerns/foreman/controller/parameters/ansible_variable.rb +36 -0
  8. data/app/controllers/foreman_ansible/api/v2/hostgroups_controller_extensions.rb +2 -0
  9. data/app/controllers/foreman_ansible/api/v2/hostgroups_param_group_extensions.rb +2 -0
  10. data/app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb +2 -0
  11. data/app/controllers/foreman_ansible/api/v2/hosts_param_group_extensions.rb +2 -0
  12. data/app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb +2 -0
  13. data/app/controllers/foreman_ansible/concerns/hosts_controller_extensions.rb +2 -0
  14. data/app/controllers/foreman_ansible/concerns/import_controller_helper.rb +24 -0
  15. data/app/controllers/foreman_ansible/concerns/job_invocation_helper.rb +2 -0
  16. data/app/helpers/foreman_ansible/ansible_plugin_helper.rb +2 -0
  17. data/app/helpers/foreman_ansible/ansible_reports_helper.rb +6 -4
  18. data/app/helpers/foreman_ansible/ansible_roles_helper.rb +2 -0
  19. data/app/helpers/foreman_ansible/hosts_helper_extensions.rb +2 -0
  20. data/app/lib/actions/foreman_ansible/helpers/host_common.rb +2 -0
  21. data/app/lib/actions/foreman_ansible/helpers/play_roles_description.rb +2 -0
  22. data/app/lib/proxy_api/ansible.rb +16 -0
  23. data/app/models/ansible_role.rb +5 -0
  24. data/app/models/ansible_variable.rb +23 -0
  25. data/app/models/concerns/foreman_ansible/host_managed_extensions.rb +3 -1
  26. data/app/models/concerns/foreman_ansible/hostgroup_extensions.rb +2 -0
  27. data/app/models/foreman_ansible/ansible_provider.rb +2 -0
  28. data/app/models/foreman_ansible/fact_name.rb +2 -0
  29. data/app/models/host_ansible_role.rb +2 -0
  30. data/app/models/hostgroup_ansible_role.rb +2 -0
  31. data/app/models/setting/ansible.rb +7 -5
  32. data/app/overrides/ansible_roles_tab.rb +2 -0
  33. data/app/overrides/ansible_variables_edit.rb +15 -0
  34. data/app/overrides/hostgroup_ansible_roles_tab.rb +2 -0
  35. data/app/overrides/hostgroup_play_roles.rb +2 -0
  36. data/app/overrides/report_output.rb +2 -0
  37. data/app/services/foreman_ansible/ansible_report_importer.rb +15 -0
  38. data/app/services/foreman_ansible/ansible_report_scanner.rb +2 -0
  39. data/app/services/foreman_ansible/api_roles_importer.rb +2 -0
  40. data/app/services/foreman_ansible/fact_importer.rb +2 -0
  41. data/app/services/foreman_ansible/fact_parser.rb +13 -1
  42. data/app/services/foreman_ansible/fact_sparser.rb +2 -0
  43. data/app/services/foreman_ansible/insights_notification_builder.rb +2 -0
  44. data/app/services/foreman_ansible/insights_plan_runner.rb +3 -2
  45. data/app/services/foreman_ansible/inventory_creator.rb +0 -6
  46. data/app/services/foreman_ansible/operating_system_parser.rb +3 -1
  47. data/app/services/foreman_ansible/playbook_creator.rb +2 -0
  48. data/app/services/foreman_ansible/proxy_api.rb +24 -0
  49. data/app/services/foreman_ansible/renderer_methods.rb +2 -0
  50. data/app/services/foreman_ansible/roles_importer.rb +4 -17
  51. data/app/services/foreman_ansible/structured_fact_importer.rb +2 -0
  52. data/app/services/foreman_ansible/ui_roles_importer.rb +2 -0
  53. data/app/services/foreman_ansible/variables_importer.rb +100 -0
  54. data/app/views/ansible_roles/index.html.erb +13 -3
  55. data/app/views/ansible_variables/_ansible_roles_list.html.erb +15 -0
  56. data/app/views/ansible_variables/_validator_text.html.erb +5 -0
  57. data/app/views/ansible_variables/edit.html.erb +17 -0
  58. data/app/views/ansible_variables/import.html.erb +53 -0
  59. data/app/views/ansible_variables/index.html.erb +46 -0
  60. data/app/views/api/v2/ansible_roles/import.json.rabl +2 -0
  61. data/app/views/api/v2/ansible_roles/index.json.rabl +2 -0
  62. data/app/views/api/v2/ansible_roles/obsolete.json.rabl +2 -0
  63. data/app/views/api/v2/ansible_roles/show.json.rabl +2 -0
  64. data/app/views/api/v2/ansible_variables/import.json.rabl +3 -0
  65. data/app/views/api/v2/ansible_variables/index.json.rabl +3 -0
  66. data/app/views/api/v2/ansible_variables/obsolete.json.rabl +3 -0
  67. data/app/views/api/v2/ansible_variables/show.json.rabl +20 -0
  68. data/app/views/foreman_ansible/api/v2/ansible_roles/import.json.rabl +2 -0
  69. data/app/views/foreman_ansible/api/v2/ansible_roles/index.json.rabl +2 -0
  70. data/app/views/foreman_ansible/api/v2/ansible_roles/obsolete.json.rabl +2 -0
  71. data/app/views/foreman_ansible/api/v2/ansible_roles/show.json.rabl +2 -0
  72. data/config/routes.rb +17 -0
  73. data/db/migrate/20160705082036_create_ansible_role.rb +2 -0
  74. data/db/migrate/20160706074540_create_join_table_hosts_ansible_roles.rb +2 -0
  75. data/db/migrate/20160707195442_create_host_ansible_roles.rb +2 -0
  76. data/db/migrate/20160729094457_add_columns_to_ansible_role.rb +2 -0
  77. data/db/migrate/20160802153302_create_join_table_hostgroup_ansible_roles.rb +2 -0
  78. data/db/migrate/20160805094233_add_primary_key_hostgroup_ansible_roles.rb +2 -0
  79. data/db/migrate/20161122154057_automatically_set_role_timestamps.rb +2 -0
  80. data/db/migrate/20180410125416_rename_ansible_job_categories.rb +6 -3
  81. data/db/migrate/20180628125416_add_ansible_role_id_to_lookup_keys.rb +14 -0
  82. data/db/seeds.d/62_ansible_proxy_feature.rb +2 -0
  83. data/db/seeds.d/75_job_templates.rb +3 -1
  84. data/db/seeds.d/90_notification_blueprints.rb +2 -0
  85. data/lib/foreman_ansible.rb +2 -0
  86. data/lib/foreman_ansible/engine.rb +2 -0
  87. data/lib/foreman_ansible/register.rb +28 -1
  88. data/lib/foreman_ansible/remote_execution.rb +2 -0
  89. data/lib/foreman_ansible/version.rb +3 -1
  90. data/locale/action_names.rb +2 -2
  91. data/locale/de/LC_MESSAGES/foreman_ansible.mo +0 -0
  92. data/locale/de/foreman_ansible.edit.po +444 -0
  93. data/locale/de/foreman_ansible.po +56 -17
  94. data/locale/de/foreman_ansible.po.time_stamp +0 -0
  95. data/locale/en/LC_MESSAGES/foreman_ansible.mo +0 -0
  96. data/locale/en/foreman_ansible.edit.po +442 -0
  97. data/locale/en/foreman_ansible.po +56 -17
  98. data/locale/en/foreman_ansible.po.time_stamp +0 -0
  99. data/locale/es/LC_MESSAGES/foreman_ansible.mo +0 -0
  100. data/locale/es/foreman_ansible.edit.po +444 -0
  101. data/locale/es/foreman_ansible.po +56 -17
  102. data/locale/es/foreman_ansible.po.time_stamp +0 -0
  103. data/locale/foreman_ansible.pot +174 -93
  104. data/locale/fr/LC_MESSAGES/foreman_ansible.mo +0 -0
  105. data/locale/fr/foreman_ansible.edit.po +444 -0
  106. data/locale/fr/foreman_ansible.po +56 -17
  107. data/locale/fr/foreman_ansible.po.time_stamp +0 -0
  108. data/locale/it/LC_MESSAGES/foreman_ansible.mo +0 -0
  109. data/locale/it/foreman_ansible.edit.po +444 -0
  110. data/locale/it/foreman_ansible.po +56 -17
  111. data/locale/it/foreman_ansible.po.time_stamp +0 -0
  112. data/locale/ja/LC_MESSAGES/foreman_ansible.mo +0 -0
  113. data/locale/ja/foreman_ansible.edit.po +444 -0
  114. data/locale/ja/foreman_ansible.po +56 -17
  115. data/locale/ja/foreman_ansible.po.time_stamp +0 -0
  116. data/locale/ko/LC_MESSAGES/foreman_ansible.mo +0 -0
  117. data/locale/ko/foreman_ansible.edit.po +444 -0
  118. data/locale/ko/foreman_ansible.po +56 -17
  119. data/locale/ko/foreman_ansible.po.time_stamp +0 -0
  120. data/locale/pt_BR/LC_MESSAGES/foreman_ansible.mo +0 -0
  121. data/locale/pt_BR/foreman_ansible.edit.po +444 -0
  122. data/locale/pt_BR/foreman_ansible.po +56 -17
  123. data/locale/pt_BR/foreman_ansible.po.time_stamp +0 -0
  124. data/locale/ru/LC_MESSAGES/foreman_ansible.mo +0 -0
  125. data/locale/ru/foreman_ansible.edit.po +445 -0
  126. data/locale/ru/foreman_ansible.po +56 -17
  127. data/locale/ru/foreman_ansible.po.time_stamp +0 -0
  128. data/locale/zh_CN/LC_MESSAGES/foreman_ansible.mo +0 -0
  129. data/locale/zh_CN/foreman_ansible.edit.po +444 -0
  130. data/locale/zh_CN/foreman_ansible.po +56 -17
  131. data/locale/zh_CN/foreman_ansible.po.time_stamp +0 -0
  132. data/locale/zh_TW/LC_MESSAGES/foreman_ansible.mo +0 -0
  133. data/locale/zh_TW/foreman_ansible.edit.po +444 -0
  134. data/locale/zh_TW/foreman_ansible.po +56 -17
  135. data/locale/zh_TW/foreman_ansible.po.time_stamp +0 -0
  136. data/test/factories/ansible_proxy.rb +2 -0
  137. data/test/factories/ansible_roles.rb +2 -0
  138. data/test/factories/ansible_variables.rb +8 -0
  139. data/test/functional/ansible_roles_controller_test.rb +2 -0
  140. data/test/functional/ansible_variables_controller_test.rb +36 -0
  141. data/test/functional/api/v2/ansible_roles_controller_test.rb +21 -9
  142. data/test/functional/api/v2/ansible_variables_controller_test.rb +41 -0
  143. data/test/functional/api/v2/hostgroups_controller_test.rb +2 -0
  144. data/test/functional/api/v2/hosts_controller_test.rb +2 -0
  145. data/test/functional/hosts_controller_test.rb +2 -0
  146. data/test/test_plugin_helper.rb +2 -0
  147. data/test/unit/ansible_provider_test.rb +2 -0
  148. data/test/unit/ansible_role_test.rb +5 -9
  149. data/test/unit/ansible_variable_test.rb +14 -0
  150. data/test/unit/concerns/config_reports_extensions_test.rb +2 -0
  151. data/test/unit/concerns/host_managed_extensions_test.rb +2 -0
  152. data/test/unit/concerns/hostgroup_extensions_test.rb +2 -0
  153. data/test/unit/helpers/ansible_reports_helper_test.rb +2 -0
  154. data/test/unit/host_ansible_role_test.rb +2 -0
  155. data/test/unit/hostgroup_ansible_role_test.rb +2 -0
  156. data/test/unit/lib/foreman_ansible_core/command_creator_test.rb +2 -0
  157. data/test/unit/lib/foreman_ansible_core/playbook_runner_test.rb +2 -0
  158. data/test/unit/lib/proxy_api/ansible_test.rb +2 -0
  159. data/test/unit/services/ansible_report_importer_test.rb +15 -0
  160. data/test/unit/services/ansible_variables_importer_test.rb +39 -0
  161. data/test/unit/services/api_roles_importer_test.rb +2 -0
  162. data/test/unit/services/fact_importer_test.rb +2 -0
  163. data/test/unit/services/fact_parser_test.rb +47 -0
  164. data/test/unit/services/fact_sparser_test.rb +2 -0
  165. data/test/unit/services/insights_plan_runner_test.rb +2 -0
  166. data/test/unit/services/inventory_creator_test.rb +1 -13
  167. data/test/unit/services/roles_importer_test.rb +2 -0
  168. data/test/unit/services/structured_fact_importer_test.rb +2 -0
  169. data/test/unit/services/ui_roles_importer_test.rb +2 -0
  170. metadata +101 -42
  171. data/test/unit/lib/foreman_ansible_core/roles_reader_test.rb +0 -92
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.modify do
2
4
  factory :smart_proxy do
3
5
  trait :with_ansible do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.define do
2
4
  factory :ansible_role do
3
5
  sequence(:name) { |n| "ansible_role_#{n}" }
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :ansible_variable do
5
+ sequence(:key) { |n| "ansible_variable_#{n}" }
6
+ ansible_role
7
+ end
8
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
  # functional tests for AnsibleRolesController
3
5
  class AnsibleRolesControllerTest < ActionController::TestCase
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_plugin_helper'
4
+ # functional tests for AnsibleVariablesController
5
+ class AnsibleVariablesControllerTest < ActionController::TestCase
6
+ setup do
7
+ @model = FactoryBot.create(:ansible_variable)
8
+ end
9
+
10
+ basic_index_test
11
+ basic_edit_test @variable
12
+ basic_pagination_per_page_test
13
+ basic_pagination_rendered_test
14
+
15
+ test 'should destroy variable' do
16
+ assert_difference('AnsibleVariable.count', -1) do
17
+ delete :destroy,
18
+ :params => { :id => @model.id },
19
+ :session => set_session_user
20
+ end
21
+ assert_redirected_to ansible_variables_url
22
+ end
23
+
24
+ test 'there are no problems when the import hash is empty' do
25
+ ForemanAnsible::VariablesImporter.any_instance.
26
+ expects(:import_variable_names).returns({})
27
+ ForemanAnsible::UiRolesImporter.any_instance.
28
+ expects(:import_role_names).returns({})
29
+
30
+ proxy = FactoryBot.create(:smart_proxy, :with_ansible)
31
+ get :import,
32
+ :params => { :proxy => proxy.id },
33
+ :session => set_session_user
34
+ assert_response :success
35
+ end
36
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  module Api
@@ -23,16 +25,26 @@ module Api
23
25
  refute AnsibleRole.exists?(@role.id)
24
26
  end
25
27
 
26
- test 'should import' do
27
- put :import,
28
- :session => set_session_user
29
- assert_response :success
30
- end
28
+ context 'proxy API calls' do
29
+ setup do
30
+ roles = ['some_role.some_author', 'test_role.test_author']
31
+ ProxyAPI::Ansible.any_instance.expects(:roles).returns(roles)
32
+ @proxy = FactoryBot.create(:smart_proxy, :with_ansible)
33
+ end
31
34
 
32
- test 'should obsolete' do
33
- put :obsolete,
34
- :session => set_session_user
35
- assert_response :success
35
+ test 'should import' do
36
+ put :import, :params => {
37
+ :proxy_id => @proxy.id
38
+ }, :session => set_session_user
39
+ assert_response :success
40
+ end
41
+
42
+ test 'should obsolete' do
43
+ put :obsolete, :params => {
44
+ :proxy_id => @proxy.id
45
+ }, :session => set_session_user
46
+ assert_response :success
47
+ end
36
48
  end
37
49
 
38
50
  test 'should fetch' do
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_plugin_helper'
4
+
5
+ module Api
6
+ module V2
7
+ # Tests for the controller to CRUD Ansible Variables
8
+ class AnsibleVariablesControllerTest < ActionController::TestCase
9
+ setup do
10
+ @variable = FactoryBot.create(:ansible_variable)
11
+ end
12
+
13
+ test 'should get index' do
14
+ get :index, :session => set_session_user
15
+ response = JSON.parse(@response.body)
16
+ refute_empty response['results']
17
+ assert_response :success
18
+ end
19
+
20
+ test 'should destroy' do
21
+ delete :destroy,
22
+ :params => { :id => @variable.id },
23
+ :session => set_session_user
24
+ assert_response :ok
25
+ refute AnsibleVariable.exists?(@variable.id)
26
+ end
27
+
28
+ test 'should import' do
29
+ put :import,
30
+ :session => set_session_user
31
+ assert_response :success
32
+ end
33
+
34
+ test 'should obsolete' do
35
+ put :obsolete,
36
+ :session => set_session_user
37
+ assert_response :success
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
  require 'dynflow/testing'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  module Api
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
  require 'dynflow/testing'
3
5
  Mocha::Mock.send :include, Dynflow::Testing::Mimic
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
  require 'facets'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  # Tests for the behavior of Ansible Role, currently only validations
@@ -1,12 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
- # Tests for the behavior of Ansible Role, currently only validations
4
- class AnsibleRoleTest < ActiveSupport::TestCase
5
- should have_many(:host_ansible_roles)
6
- should have_many(:hosts).through(:host_ansible_roles).dependent(:destroy)
7
- should validate_presence_of(:name)
8
- context 'with new role' do
9
- subject { AnsibleRole.new(:name => 'foo') }
10
- should validate_uniqueness_of(:name)
11
- end
5
+ # Tests for the behavior of Ansible Variable, currently only validations
6
+ class AnsibleVariableTest < ActiveSupport::TestCase
7
+ should belong_to(:ansible_role)
12
8
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_plugin_helper'
4
+
5
+ # Tests for the behavior of Ansible Role, currently only validations
6
+ class AnsibleRoleTest < ActiveSupport::TestCase
7
+ should have_many(:host_ansible_roles)
8
+ should have_many(:hosts).through(:host_ansible_roles).dependent(:destroy)
9
+ should validate_presence_of(:name)
10
+ context 'with new role' do
11
+ subject { AnsibleRole.new(:name => 'foo') }
12
+ should validate_uniqueness_of(:name)
13
+ end
14
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  # Tests for the behavior of Host with roles, checks inheritance, etc
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: false
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  # Tests for the behavior of Host with roles, checks inheritance, etc
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  # Tests for the behavior of Hostgroup with roles, checks inheritance, etc
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class AnsibleReportsHelperTest < ActiveSupport::TestCase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  # Tests for validators and such of the join model between Host and
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  # Tests for validators and such of the join model between Hostgroup and
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  class CommandCreatorTest < ActiveSupport::TestCase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  # Playbook Runner - this class uses foreman_tasks_core
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
  # unit tests for ProxyAPI::Ansible
3
5
  class AnsibleTest < ActiveSupport::TestCase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
  # Unit tests for AnsibleReportImporter
3
5
  # This class is just meant to capture the config reports coming
@@ -18,4 +20,17 @@ class AnsibleReportImporterTest < ActiveSupport::TestCase
18
20
  ForemanAnsible::AnsibleReportScanner.expects(:ansible_report?).returns(true)
19
21
  assert @importer.host.new_record?
20
22
  end
23
+
24
+ test 'finds host when given partially qualified name' do
25
+ host = ::FactoryBot.create(:host, :hostname => 'ansible-host.example.com')
26
+ ForemanAnsible::AnsibleReportScanner.expects(:ansible_report?).returns(true)
27
+ assert_equal host, ::ConfigReportImporter.new({ 'host' => 'ansible-host' }).host
28
+ end
29
+
30
+ test 'creates a new host when multiple hosts for partially qualified name are found' do
31
+ ::FactoryBot.create(:host, :hostname => 'ansible-host.example.com')
32
+ ::FactoryBot.create(:host, :hostname => 'ansible-host.dummy.org')
33
+ ForemanAnsible::AnsibleReportScanner.expects(:ansible_report?).returns(true)
34
+ assert ::ConfigReportImporter.new({ 'host' => 'ansible-host' }).host.new_record?
35
+ end
21
36
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_plugin_helper'
4
+ # Unit tests for importing variables
5
+ # This service is meant to take in essentially a string coming from
6
+ # the proxy API, and parse that into AnsibleVariables.
7
+ class AnsibleVariablesImporterTest < ActiveSupport::TestCase
8
+ setup do
9
+ @importer = ForemanAnsible::VariablesImporter.new
10
+ end
11
+ test 'does not reimport already existing variables' do
12
+ already_existing = FactoryBot.create(:ansible_variable)
13
+ new_role = FactoryBot.create(:ansible_role)
14
+ api_response = {
15
+ new_role.name => ['new_var'],
16
+ already_existing.ansible_role.name => [already_existing.key]
17
+ }
18
+ changes = @importer.import_variables(api_response, [new_role.name])
19
+ assert_not_empty changes['new']
20
+ assert_equal 'new_var', changes['new'].first.key
21
+ assert_equal new_role, changes['new'].first.ansible_role
22
+ end
23
+
24
+ test "variables attempts to remove variables that don't exist anymore" do
25
+ obsolete_variable = FactoryBot.create(:ansible_variable)
26
+ changes = @importer.import_variables({}, [])
27
+ assert_not_empty changes['obsolete']
28
+ assert_equal obsolete_variable.key, changes['obsolete'].first.key
29
+ assert_equal(
30
+ obsolete_variable.ansible_role,
31
+ changes['obsolete'].first.ansible_role
32
+ )
33
+ end
34
+
35
+ test 'does not do anything if response is empty' do
36
+ changes = @importer.import_variables({}, [])
37
+ assert_equal({ 'new' => [], 'obsolete' => [] }, changes)
38
+ end
39
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
  # unit tests for ApiRolesImporter
3
5
  class ApiRolesImporterTest < ActiveSupport::TestCase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanAnsible
2
4
  # Test for the facts importer - only verify that given
3
5
  # a set of facts it's able to import them
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanAnsible
2
4
  # Checks sample Ansible facts to see if it can assign them to
3
5
  # Host properties
@@ -58,6 +60,51 @@ module ForemanAnsible
58
60
  end
59
61
  end
60
62
 
63
+ # Tests for Network parser
64
+ class NetworkFactParserTest < ActiveSupport::TestCase
65
+ setup do
66
+ @facts_parser = ForemanAnsible::FactParser.new(
67
+ HashWithIndifferentAccess.new(
68
+ '_type' => 'ansible',
69
+ '_timestamp' => '2018-10-29 20:01:51 +0100',
70
+ 'ansible_facts' =>
71
+ {
72
+ 'ansible_interfaces' => [
73
+ 'eth0'
74
+ ],
75
+ 'ansible_eth0' => {
76
+ 'active' => true,
77
+ 'device' => 'eth0',
78
+ "macaddress" => '52:54:00:04:55:37',
79
+ 'ipv4' => {
80
+ 'address' => '10.10.0.10',
81
+ 'netmask' => '255.255.0.0',
82
+ 'network' => '10.10.0.0'
83
+ },
84
+ 'ipv6' => [
85
+ {
86
+ 'address' => 'fd00::5054:00ff:fe04:5537',
87
+ 'prefix' => '64',
88
+ 'scope' => 'host'
89
+ }
90
+ ],
91
+ 'mtu' => 1500,
92
+ 'promisc' => false,
93
+ 'type' => 'ether'
94
+ }
95
+ }
96
+ )
97
+ )
98
+ end
99
+
100
+ test 'Parses IPv4 & IPv6 addresses correctly' do
101
+ iut = 'eth0'.dup
102
+ interface = @facts_parser.get_facts_for_interface(iut)
103
+ assert_equal '10.10.0.10', interface['ipaddress']
104
+ assert_equal 'fd00::5054:00ff:fe04:5537', interface['ipaddress6']
105
+ end
106
+ end
107
+
61
108
  # Tests for Debian parser
62
109
  class DebianFactParserTest < ActiveSupport::TestCase
63
110
  setup do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanAnsible
2
4
  # Tests for checking if FactSparser can sparse a hash and unsparse it
3
5
  class FactSparserTest < ActiveSupport::TestCase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  if defined? RedhatAccess
@@ -10,8 +10,7 @@ module ForemanAnsible
10
10
  setup do
11
11
  @host = FactoryBot.build(:host)
12
12
  @template_invocation = OpenStruct.new(
13
- :job_invocation => OpenStruct.new(:password => 'foobar',
14
- :sudo_password => 'foobar'),
13
+ :job_invocation => OpenStruct.new(:password => 'foobar'),
15
14
  :effective_user => 'foobar'
16
15
  )
17
16
  end
@@ -42,8 +41,6 @@ module ForemanAnsible
42
41
  returns('root').at_least_once
43
42
  Setting.expects(:[]).with('remote_execution_ssh_password').
44
43
  returns('asafepassword').at_least_once
45
- Setting.expects(:[]).with('remote_execution_sudo_password').
46
- returns('foobar').at_least_once
47
44
  Setting.expects(:[]).with('ansible_winrm_server_cert_validation').
48
45
  returns(true).at_least_once
49
46
  Setting.expects(:[]).with('ansible_connection').
@@ -72,8 +69,6 @@ module ForemanAnsible
72
69
  connection_params['ansible_port']
73
70
  assert_equal Setting['remote_execution_ssh_password'],
74
71
  connection_params['ansible_ssh_pass']
75
- assert_equal Setting['remote_execution_sudo_password'],
76
- connection_params['ansible_sudo_pass']
77
72
  assert_equal Setting['ansible_winrm_server_cert_validation'],
78
73
  connection_params['ansible_winrm_server_cert_validation']
79
74
  end
@@ -85,13 +80,6 @@ module ForemanAnsible
85
80
  inventory.rex_ssh_password(@host))
86
81
  end
87
82
 
88
- test 'job invocation sudo password is passed when available' do
89
- inventory = ForemanAnsible::InventoryCreator.new(@host,
90
- @template_invocation)
91
- assert_equal(@template_invocation.job_invocation.sudo_password,
92
- inventory.rex_sudo_password(@host))
93
- end
94
-
95
83
  test 'ssh private key is passed when available' do
96
84
  host = FactoryBot.build(:host)
97
85
  path_to_key = '/path/to/private/key'