foreman_ansible 6.0.1 → 6.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/ansible_roles_controller.rb +12 -8
  3. data/app/controllers/ansible_variables_controller.rb +4 -0
  4. data/app/controllers/api/v2/ansible_inventories_controller.rb +2 -2
  5. data/app/controllers/api/v2/ansible_roles_controller.rb +32 -11
  6. data/app/controllers/api/v2/ansible_variables_controller.rb +6 -4
  7. data/app/controllers/foreman_ansible/concerns/import_controller_helper.rb +3 -3
  8. data/app/helpers/foreman_ansible/ansible_reports_helper.rb +10 -5
  9. data/app/helpers/foreman_ansible/ansible_roles_data_preparations.rb +95 -0
  10. data/app/helpers/foreman_ansible/ansible_roles_helper.rb +20 -1
  11. data/app/jobs/sync_roles_and_variables.rb +20 -0
  12. data/app/models/concerns/foreman_ansible/host_managed_extensions.rb +10 -7
  13. data/app/models/concerns/foreman_ansible/hostgroup_extensions.rb +19 -4
  14. data/app/models/foreman_ansible/ansible_provider.rb +3 -2
  15. data/app/models/host_ansible_role.rb +1 -0
  16. data/app/models/hostgroup_ansible_role.rb +1 -0
  17. data/app/models/setting/ansible.rb +9 -0
  18. data/app/services/foreman_ansible/ansible_report_importer.rb +4 -0
  19. data/app/services/foreman_ansible/ansible_report_scanner.rb +15 -1
  20. data/app/services/foreman_ansible/api_roles_importer.rb +23 -11
  21. data/app/services/foreman_ansible/fact_parser.rb +21 -1
  22. data/app/services/foreman_ansible/import_roles_and_variables_error_notification.rb +31 -0
  23. data/app/services/foreman_ansible/import_roles_and_variables_success_notification.rb +26 -0
  24. data/app/services/foreman_ansible/inventory_creator.rb +3 -7
  25. data/app/services/foreman_ansible/operating_system_parser.rb +8 -2
  26. data/app/services/foreman_ansible/roles_importer.rb +3 -2
  27. data/app/services/foreman_ansible/ui_roles_importer.rb +2 -2
  28. data/app/services/foreman_ansible/variables_importer.rb +36 -1
  29. data/app/views/ansible_roles/import.html.erb +10 -50
  30. data/app/views/ansible_variables/index.html.erb +1 -2
  31. data/app/views/api/v2/ansible_roles/sync.json.rabl +5 -0
  32. data/app/views/foreman_ansible/ansible_roles/_select_tab_content.html.erb +8 -17
  33. data/app/views/foreman_ansible/config_reports/_ansible.html.erb +13 -6
  34. data/app/views/foreman_ansible/job_templates/ansible_collections_-_install_from_galaxy.erb +28 -0
  35. data/app/views/foreman_ansible/job_templates/ansible_roles_-_install_from_galaxy.erb +1 -1
  36. data/app/views/foreman_ansible/job_templates/capsule_upgrade_-_ansible_default.erb +2 -3
  37. data/app/views/foreman_ansible/job_templates/convert_to_rhel.erb +44 -0
  38. data/config/routes.rb +5 -4
  39. data/db/migrate/20210120150019_add_position_to_ansible_role.rb +27 -0
  40. data/db/seeds.d/100_common_parameters.rb +7 -0
  41. data/db/seeds.d/90_notification_blueprints.rb +19 -1
  42. data/lib/foreman_ansible/engine.rb +1 -0
  43. data/lib/foreman_ansible/register.rb +5 -5
  44. data/lib/foreman_ansible/version.rb +1 -1
  45. data/locale/ca/LC_MESSAGES/foreman_ansible.mo +0 -0
  46. data/locale/ca/foreman_ansible.po +1 -1
  47. data/locale/cs_CZ/LC_MESSAGES/foreman_ansible.mo +0 -0
  48. data/locale/cs_CZ/foreman_ansible.po +1 -1
  49. data/locale/de/LC_MESSAGES/foreman_ansible.mo +0 -0
  50. data/locale/de/foreman_ansible.po +1 -1
  51. data/locale/en/LC_MESSAGES/foreman_ansible.mo +0 -0
  52. data/locale/en/foreman_ansible.po +1 -1
  53. data/locale/en_GB/LC_MESSAGES/foreman_ansible.mo +0 -0
  54. data/locale/en_GB/foreman_ansible.po +1 -1
  55. data/locale/es/LC_MESSAGES/foreman_ansible.mo +0 -0
  56. data/locale/es/foreman_ansible.po +1 -1
  57. data/locale/fr/LC_MESSAGES/foreman_ansible.mo +0 -0
  58. data/locale/fr/foreman_ansible.po +1 -1
  59. data/locale/gl/LC_MESSAGES/foreman_ansible.mo +0 -0
  60. data/locale/gl/foreman_ansible.po +1 -1
  61. data/locale/it/LC_MESSAGES/foreman_ansible.mo +0 -0
  62. data/locale/it/foreman_ansible.po +1 -1
  63. data/locale/ja/LC_MESSAGES/foreman_ansible.mo +0 -0
  64. data/locale/ja/foreman_ansible.po +1 -1
  65. data/locale/ko/LC_MESSAGES/foreman_ansible.mo +0 -0
  66. data/locale/ko/foreman_ansible.po +1 -1
  67. data/locale/nl_NL/LC_MESSAGES/foreman_ansible.mo +0 -0
  68. data/locale/nl_NL/foreman_ansible.po +1 -1
  69. data/locale/pl/LC_MESSAGES/foreman_ansible.mo +0 -0
  70. data/locale/pl/foreman_ansible.po +1 -1
  71. data/locale/pt_BR/LC_MESSAGES/foreman_ansible.mo +0 -0
  72. data/locale/pt_BR/foreman_ansible.po +1 -1
  73. data/locale/ru/LC_MESSAGES/foreman_ansible.mo +0 -0
  74. data/locale/ru/foreman_ansible.po +1 -1
  75. data/locale/sv_SE/LC_MESSAGES/foreman_ansible.mo +0 -0
  76. data/locale/sv_SE/foreman_ansible.po +1 -1
  77. data/locale/zh_CN/LC_MESSAGES/foreman_ansible.mo +0 -0
  78. data/locale/zh_CN/foreman_ansible.po +1 -1
  79. data/locale/zh_TW/LC_MESSAGES/foreman_ansible.mo +0 -0
  80. data/locale/zh_TW/foreman_ansible.po +1 -1
  81. data/package.json +11 -42
  82. data/test/factories/ansible_roles.rb +12 -0
  83. data/test/factories/host_ansible_enhancements.rb +23 -0
  84. data/test/foreman_ansible/helpers/ansible_roles_helper_test.rb +45 -0
  85. data/test/functional/ansible_variables_controller_test.rb +0 -15
  86. data/test/functional/api/v2/ansible_roles_controller_test.rb +23 -0
  87. data/test/functional/api/v2/hostgroups_controller_test.rb +5 -4
  88. data/test/functional/api/v2/hosts_controller_test.rb +9 -8
  89. data/test/functional/hosts_controller_test.rb +10 -6
  90. data/test/unit/ansible_provider_test.rb +1 -1
  91. data/test/unit/concerns/host_managed_extensions_test.rb +17 -3
  92. data/test/unit/concerns/hostgroup_extensions_test.rb +13 -7
  93. data/test/unit/host_ansible_role_test.rb +2 -1
  94. data/test/unit/hostgroup_ansible_role_test.rb +2 -1
  95. data/test/unit/ignore_roles_test.rb +43 -0
  96. data/test/unit/import_roles_and_variables.rb +60 -0
  97. data/test/unit/lib/foreman_ansible_core/ansible_runner_test.rb +3 -3
  98. data/test/unit/lib/foreman_ansible_core/playbook_runner_test.rb +3 -3
  99. data/test/unit/services/ansible_variables_importer_test.rb +13 -0
  100. data/test/unit/services/api_roles_importer_test.rb +22 -5
  101. data/test/unit/services/fact_parser_test.rb +16 -0
  102. data/test/unit/services/inventory_creator_test.rb +16 -8
  103. data/test/unit/services/ui_roles_importer_test.rb +2 -2
  104. data/webpack/__mocks__/foremanReact/common/helpers.js +13 -0
  105. data/webpack/__mocks__/foremanReact/components/common/forms/OrderableSelect/helpers.js +5 -0
  106. data/webpack/__mocks__/foremanReact/redux/API.js +7 -0
  107. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariables.js +178 -0
  108. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariables.scss +9 -0
  109. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesActions.js +39 -0
  110. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesConstants.js +4 -0
  111. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesHelpers.js +11 -0
  112. data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesHelpers.test.js +50 -0
  113. data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesImport.test.js +39 -0
  114. data/webpack/components/AnsibleRolesAndVariables/__test__/__snapshots__/AnsibleRolesAndVariablesImport.test.js.snap +177 -0
  115. data/webpack/components/AnsibleRolesAndVariables/index.js +31 -0
  116. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.js +25 -27
  117. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.scss +1 -1
  118. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js +20 -14
  119. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherConstants.js +1 -2
  120. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js +13 -8
  121. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js +8 -28
  122. data/webpack/components/AnsibleRolesSwitcher/__fixtures__/ansibleRolesSwitcherReducer.fixtures.js +1 -0
  123. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcher.test.js +6 -4
  124. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherReducer.test.js +1 -9
  125. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherSelectors.test.js +3 -16
  126. data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcher.test.js.snap +4 -8
  127. data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherReducer.test.js.snap +8 -97
  128. data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherSelectors.test.js.snap +5 -30
  129. data/webpack/components/AnsibleRolesSwitcher/components/AnsiblePermissionDenied.test.js +1 -1
  130. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.js +5 -2
  131. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.test.js +1 -1
  132. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.js +43 -0
  133. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.test.js +19 -0
  134. data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.js +63 -51
  135. data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.test.js +4 -1
  136. data/webpack/components/AnsibleRolesSwitcher/components/AvailableRolesList.test.js +1 -1
  137. data/webpack/components/AnsibleRolesSwitcher/components/OrderedRolesTooltip.js +23 -0
  138. data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AnsibleRoleInputs.test.js.snap +51 -0
  139. data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AssignedRolesList.test.js.snap +28 -28
  140. data/webpack/components/AnsibleRolesSwitcher/index.js +4 -8
  141. data/webpack/index.js +6 -13
  142. metadata +60 -15
  143. data/app/views/ansible_variables/import.html.erb +0 -56
  144. data/webpack/test_setup.js +0 -12
@@ -9,8 +9,8 @@ class HostManagedExtensionsTest < ActiveSupport::TestCase
9
9
  @role2 = FactoryBot.create(:ansible_role)
10
10
  @role3 = FactoryBot.create(:ansible_role)
11
11
 
12
- @hostgroup_parent = FactoryBot.create(:hostgroup,
13
- :ansible_roles => [@role2])
12
+ @hostgroup_parent = FactoryBot.create(:hostgroup)
13
+ FactoryBot.create(:hostgroup_ansible_role, hostgroup_id: @hostgroup_parent.id, ansible_role_id: @role2.id)
14
14
  @hostgroup = FactoryBot.create(:hostgroup, :parent => @hostgroup_parent)
15
15
  @host = FactoryBot.build_stubbed(:host, :ansible_roles => [@role1])
16
16
  @another_host = FactoryBot.build_stubbed(:host, :ansible_roles => [@role3])
@@ -23,7 +23,7 @@ class HostManagedExtensionsTest < ActiveSupport::TestCase
23
23
 
24
24
  test 'returns assigned and inherited roles for host with a hostgroup' do
25
25
  @host.hostgroup = @hostgroup
26
- @host.all_ansible_roles.must_equal [@role1, @role2]
26
+ @host.all_ansible_roles.must_equal [@role2, @role1]
27
27
  end
28
28
  end
29
29
 
@@ -48,4 +48,18 @@ class HostManagedExtensionsTest < ActiveSupport::TestCase
48
48
  assert Host::Managed.import_host('192.168.128.27').new_record?
49
49
  end
50
50
  end
51
+
52
+ test 'should correctly order roles for host' do
53
+ host = FactoryBot.create(:host)
54
+ FactoryBot.create(:host_ansible_role, :ansible_role_id => @role1.id, :position => 1, :host_id => host.id)
55
+ FactoryBot.create(:host_ansible_role, :ansible_role_id => @role2.id, :position => 2, :host_id => host.id)
56
+ FactoryBot.create(:host_ansible_role, :ansible_role_id => @role3.id, :position => 0, :host_id => host.id)
57
+ host.ansible_roles.must_equal [@role3, @role1, @role2]
58
+ end
59
+
60
+ test 'should order hostgroup roles before host roles' do
61
+ host = FactoryBot.create(:host, :hostgroup => @hostgroup)
62
+ FactoryBot.create(:host_ansible_role, :ansible_role_id => @role1.id, :position => 0, :host_id => host.id)
63
+ host.all_ansible_roles.must_equal [@role2, @role1]
64
+ end
51
65
  end
@@ -9,22 +9,23 @@ class HostgroupExtensionsTest < ActiveSupport::TestCase
9
9
  @role2 = FactoryBot.create(:ansible_role)
10
10
  @role3 = FactoryBot.create(:ansible_role)
11
11
 
12
- @hostgroup_parent = FactoryBot.create(:hostgroup,
13
- :ansible_roles => [@role2])
14
- @hostgroup = FactoryBot.create(:hostgroup, :ansible_roles => [@role1])
15
- @host = FactoryBot.create(:host,
16
- :ansible_roles => [@role3],
17
- :hostgroup => @hostgroup)
12
+ @hostgroup_parent = FactoryBot.create(:hostgroup)
13
+ FactoryBot.create(:hostgroup_ansible_role, :hostgroup_id => @hostgroup_parent.id, :ansible_role_id => @role2.id, :position => 1)
14
+ @hostgroup = FactoryBot.create(:hostgroup)
15
+ FactoryBot.create(:hostgroup_ansible_role, :hostgroup_id => @hostgroup.id, :ansible_role_id => @role1.id, :position => 10)
16
+ @host = FactoryBot.create(:host, :hostgroup => @hostgroup)
17
+ FactoryBot.create(:host_ansible_role, :host_id => @host.id, :ansible_role_id => @role3.id)
18
18
  end
19
19
 
20
20
  describe '#all_ansible_roles' do
21
21
  test 'returns assigned roles without any parent hostgroup' do
22
+ @hostgroup.host_ansible_roles
22
23
  @hostgroup.all_ansible_roles.must_equal [@role1, @role3]
23
24
  end
24
25
 
25
26
  test 'returns assigned and inherited roles with from parent hostgroup' do
26
27
  @hostgroup.parent = @hostgroup_parent
27
- @hostgroup.all_ansible_roles.must_equal [@role1, @role2, @role3]
28
+ @hostgroup.all_ansible_roles.must_equal [@role2, @role1, @role3]
28
29
  end
29
30
  end
30
31
 
@@ -49,4 +50,9 @@ class HostgroupExtensionsTest < ActiveSupport::TestCase
49
50
  @hostgroup.inherited_and_own_ansible_roles.must_equal [@role2, @role1]
50
51
  end
51
52
  end
53
+
54
+ test 'should return ordered roles for hostgroup' do
55
+ @hostgroup.parent = @hostgroup_parent
56
+ @hostgroup.inherited_and_own_ansible_roles.must_equal [@role2, @role1]
57
+ end
52
58
  end
@@ -12,7 +12,8 @@ class HostAnsibleRoleTest < ActiveSupport::TestCase
12
12
  describe 'uniqueness' do
13
13
  subject do
14
14
  HostAnsibleRole.new(:host => FactoryBot.build(:host),
15
- :ansible_role => FactoryBot.build(:ansible_role))
15
+ :ansible_role => FactoryBot.build(:ansible_role),
16
+ :position => 0)
16
17
  end
17
18
  should validate_uniqueness_of(:ansible_role_id).scoped_to(:host_id)
18
19
  end
@@ -13,7 +13,8 @@ class HostgroupAnsibleRoleTest < ActiveSupport::TestCase
13
13
  subject do
14
14
  HostgroupAnsibleRole.new(
15
15
  :hostgroup => FactoryBot.build(:hostgroup),
16
- :ansible_role => FactoryBot.build(:ansible_role)
16
+ :ansible_role => FactoryBot.build(:ansible_role),
17
+ :position => 0
17
18
  )
18
19
  end
19
20
  should validate_uniqueness_of(:ansible_role_id).scoped_to(:hostgroup_id)
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_plugin_helper'
4
+
5
+ # Tests for testing the ignore list
6
+ class IgnoreRolesTest < ActiveSupport::TestCase
7
+ include ForemanAnsible::AnsibleRolesDataPreparations
8
+
9
+ role1 = AnsibleRole.new(:name => 'foo')
10
+ role2 = AnsibleRole.new(:name => 'bar')
11
+ role3 = AnsibleRole.new(:name => 'hello.txt')
12
+ role4 = AnsibleRole.new(:name => 'hello.yml')
13
+ role5 = AnsibleRole.new(:name => 'foo.yml')
14
+
15
+ describe 'It should Ignore Role' do
16
+ test 'If role starts with h' do
17
+ Setting.stubs(:[]).with(:ansible_roles_to_ignore).returns(['h*'])
18
+ assert_not role_match_excluded_roles(role1.name)
19
+ assert_not role_match_excluded_roles(role2.name)
20
+ assert role_match_excluded_roles(role3.name)
21
+ assert role_match_excluded_roles(role4.name)
22
+ assert_not role_match_excluded_roles(role5.name)
23
+ end
24
+
25
+ test 'If role ends with .yml' do
26
+ Setting.stubs(:[]).with(:ansible_roles_to_ignore).returns(['*.yml'])
27
+ assert_not role_match_excluded_roles(role1.name)
28
+ assert_not role_match_excluded_roles(role2.name)
29
+ assert_not role_match_excluded_roles(role3.name)
30
+ assert role_match_excluded_roles(role4.name)
31
+ assert role_match_excluded_roles(role5.name)
32
+ end
33
+
34
+ test 'If role have o char in the middle' do
35
+ Setting.stubs(:[]).with(:ansible_roles_to_ignore).returns(['*o*'])
36
+ assert role_match_excluded_roles(role1.name)
37
+ assert_not role_match_excluded_roles(role2.name)
38
+ assert role_match_excluded_roles(role3.name)
39
+ assert role_match_excluded_roles(role4.name)
40
+ assert role_match_excluded_roles(role5.name)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_plugin_helper'
4
+
5
+ # Tests for testing the ignore list
6
+ class ImportRolesAndVariables < ActiveSupport::TestCase
7
+ include ForemanAnsible::AnsibleRolesDataPreparations
8
+
9
+ # existing Roles -> should be updated
10
+ role1 = AnsibleRole.new(:name => 'ntp', :id => 10)
11
+ role2 = AnsibleRole.new(:name => 'bar', :id => 11)
12
+
13
+ # New Roles -> Should be imported
14
+ role3 = AnsibleRole.new(:name => 'foo', :id => nil)
15
+ role4 = AnsibleRole.new(:name => 'world', :id => nil)
16
+
17
+ # Existing Role -> should be removed
18
+ role5 = AnsibleRole.new(:name => 'h', :id => 12)
19
+
20
+ # role1 variables -> add
21
+ variable1 = AnsibleVariable.new(:key => 'ntp_statistics', :ansible_role_id => 10, :id => nil)
22
+ variable2 = AnsibleVariable.new(:key => 'ntp_broadcast', :ansible_role_id => 10, :id => nil)
23
+
24
+ # role1 variables -> update
25
+ variable3 = AnsibleVariable.new(:key => 'ntp_statistics', :ansible_role_id => 10, :id => 4)
26
+ variable4 = AnsibleVariable.new(:key => 'ntp_crypto', :ansible_role_id => 10, :id => 5)
27
+
28
+ # role1 variables -> obsolete
29
+ variable5 = AnsibleVariable.new(:key => 'ntp_controlkey', :ansible_role_id => 10, :id => 6)
30
+ variable6 = AnsibleVariable.new(:key => 'ntp_key', :ansible_role_id => 10, :id => 7)
31
+
32
+ # role2 variable -> Update
33
+ variable7 = AnsibleVariable.new(:key => 'bar_key', :ansible_role_id => 11, :id => 7, :override => false, :hidden_value => true)
34
+ changed = { 'old' => [role1, role2], 'new' => [role3, role4], 'obsolete' => [role5] }
35
+ old_roles_variables = { 'new' => [variable1, variable2], 'update' => [variable3, variable4, variable7], 'obsolete' => [variable5, variable6] }
36
+
37
+ describe 'It should prepare the rows correctly' do
38
+ setup do
39
+ @variables_importer = mock('mock_variables_importer')
40
+ end
41
+
42
+ test 'prepare 5 rows' do
43
+ expected = [{ :cells => [role1.name, 'Update Role Variables', 'Add: 2, Remove: 2, Update: 2', '', ''],
44
+ :role => role1, :kind => 'old', :id => role1.name },
45
+ { :cells => [role2.name, 'Update Role Variables', 'Update: 1', '', ''], :role => role2, :kind => 'old', :id => role2.name },
46
+ { :cells => [role3.name, 'Import Role', 'Add: 3', '', ''], :role => role3, :kind => 'new', :id => role3.name },
47
+ { :cells => [role4.name, 'Import Role', 'Add: 2', '', ''], :role => role4, :kind => 'new', :id => role4.name },
48
+ { :cells => [role5.name, 'Remove Role', '', 0, 0], :role => role5, :kind => 'obsolete', :id => role5.name }]
49
+ # role3 and role4 importing new variables
50
+ @variables_importer.expects(:get_variables_names).with(role3.name).returns({ 'a' => true, 'b' => false, 'c' => [] })
51
+ @variables_importer.expects(:get_variables_names).with(role4.name).returns({ 'd' => true, 'e' => false })
52
+
53
+ @variables_importer.expects(:import_variable_names).with([role3, role4]).returns(old_roles_variables)
54
+ @variables_importer.expects(:import_variable_names).with([role1, role2]).returns(old_roles_variables)
55
+ @variables_importer.expects(:import_variable_names).with([role5]).returns(old_roles_variables)
56
+ result = prepare_ansible_import_rows(changed, @variables_importer)
57
+ assert_equal result, expected
58
+ end
59
+ end
60
+ end
@@ -24,7 +24,7 @@ module ForemanAnsibleCore
24
24
  '_meta' => { 'hostvars' => { 'foreman.example.com' => {} } } }
25
25
  end
26
26
  let(:input) do
27
- host_secrets = { 'ansible_ssh_pass' => 'letmein', 'ansible_become_password' => 'iamroot' }
27
+ host_secrets = { 'ansible_password' => 'letmein', 'ansible_become_password' => 'iamroot' }
28
28
  secrets = { 'per-host' => { 'foreman.example.com' => host_secrets } }
29
29
  host_input = { 'input' => { 'action_input' => { 'secrets' => secrets } } }
30
30
  { 'foreman.example.com' => host_input }
@@ -35,14 +35,14 @@ module ForemanAnsibleCore
35
35
  test_inventory = inventory.merge('ssh_password' => 'sshpass', 'effective_user_password' => 'mypass')
36
36
  rebuilt = runner.send(:rebuild_secrets, test_inventory, input)
37
37
  host_vars = rebuilt.dig('_meta', 'hostvars', 'foreman.example.com')
38
- assert_equal 'sshpass', host_vars['ansible_ssh_pass']
38
+ assert_equal 'sshpass', host_vars['ansible_password']
39
39
  assert_equal 'mypass', host_vars['ansible_become_password']
40
40
  end
41
41
 
42
42
  test 'host secrets are used when not overriden by inventory secrest' do
43
43
  rebuilt = runner.send(:rebuild_secrets, inventory, input)
44
44
  host_vars = rebuilt.dig('_meta', 'hostvars', 'foreman.example.com')
45
- assert_equal 'letmein', host_vars['ansible_ssh_pass']
45
+ assert_equal 'letmein', host_vars['ansible_password']
46
46
  assert_equal 'iamroot', host_vars['ansible_become_password']
47
47
  end
48
48
  end
@@ -87,7 +87,7 @@ class PlaybookRunnerTest < ActiveSupport::TestCase
87
87
  '_meta' => { 'hostvars' => { 'foreman.example.com' => {} } } }
88
88
  end
89
89
  let(:secrets) do
90
- host_secrets = { 'ansible_ssh_pass' => 'letmein', 'ansible_become_password' => 'iamroot' }
90
+ host_secrets = { 'ansible_password' => 'letmein', 'ansible_become_password' => 'iamroot' }
91
91
  { 'per-host' => { 'foreman.example.com' => host_secrets } }
92
92
  end
93
93
  let(:runner) { ForemanAnsibleCore::Runner::Playbook.allocate }
@@ -96,14 +96,14 @@ class PlaybookRunnerTest < ActiveSupport::TestCase
96
96
  test_inventory = inventory.merge('ssh_password' => 'sshpass', 'effective_user_password' => 'mypass')
97
97
  rebuilt = runner.send(:rebuild_secrets, test_inventory, secrets)
98
98
  host_vars = rebuilt.dig('_meta', 'hostvars', 'foreman.example.com')
99
- assert_equal 'sshpass', host_vars['ansible_ssh_pass']
99
+ assert_equal 'sshpass', host_vars['ansible_password']
100
100
  assert_equal 'mypass', host_vars['ansible_become_password']
101
101
  end
102
102
 
103
103
  test 'host secrets are used when not overriden by inventory secrest' do
104
104
  rebuilt = runner.send(:rebuild_secrets, inventory, secrets)
105
105
  host_vars = rebuilt.dig('_meta', 'hostvars', 'foreman.example.com')
106
- assert_equal 'letmein', host_vars['ansible_ssh_pass']
106
+ assert_equal 'letmein', host_vars['ansible_password']
107
107
  assert_equal 'iamroot', host_vars['ansible_become_password']
108
108
  end
109
109
  end
@@ -59,6 +59,19 @@ class AnsibleVariablesImporterTest < ActiveSupport::TestCase
59
59
  assert_empty changes['update']
60
60
  end
61
61
 
62
+ test 'sets hidden value to false by default' do
63
+ role = FactoryBot.create(:ansible_role)
64
+ variable = FactoryBot.create(:ansible_variable)
65
+ api_response = {
66
+ role.name => { variable.key => 'new value' }
67
+ }
68
+ changes = importer.import_variables(api_response, [role.name])
69
+ assert_empty changes['update']
70
+ assert_not_empty changes['new']
71
+ assert_equal variable.key, changes['new'].first.key
72
+ assert_not changes['new'].first.hidden_value?
73
+ end
74
+
62
75
  test 'reimports variable with same key for different role' do
63
76
  role = FactoryBot.create(:ansible_role)
64
77
  variable = FactoryBot.create(:ansible_variable)
@@ -12,11 +12,28 @@ class ApiRolesImporterTest < ActiveSupport::TestCase
12
12
  end
13
13
 
14
14
  test 'should import roles' do
15
- @importer.stubs(:import_role_names).returns(:new => @test_roles)
16
- res = @importer.import!
17
- assert_equal 2, res.count
18
- assert AnsibleRole.find_by :name => @test_roles.first.name
19
- assert AnsibleRole.find_by :name => @test_roles.last.name
15
+ @importer.stubs(:prepare_ansible_import_rows).returns(
16
+ [{
17
+ :name => 'test_user.test_name',
18
+ :id => nil,
19
+ :role_action => 'Import Role',
20
+ :variables => 'Add: 7',
21
+ :hosts_count => '',
22
+ :hostgroup_count => '',
23
+ :kind => 'new'
24
+ },
25
+ {
26
+ :name => 'some_user.some_role',
27
+ :id => nil,
28
+ :role_action => 'Import Role',
29
+ :variables => 'Add: 3',
30
+ :hosts_count => '',
31
+ :hostgroup_count => '',
32
+ :kind => 'new'
33
+ }]
34
+ )
35
+ res = @importer.import!([@test_roles.first.name, @test_roles.last.name])
36
+ assert_equal 2, res['changed']['new'].count
20
37
  end
21
38
 
22
39
  test 'should obsolete roles' do
@@ -29,6 +29,22 @@ module ForemanAnsible
29
29
  refute @facts_parser.environment
30
30
  end
31
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
+
32
48
  test 'creates operatingsystem from operating system options' do
33
49
  sample_mock = mock
34
50
  major_fact = @facts_parser.facts['ansible_distribution_major_version']
@@ -61,15 +61,14 @@ module ForemanAnsible
61
61
  connection_params['ansible_user']
62
62
  refute_equal Setting['remote_execution_ssh_port'],
63
63
  connection_params['ansible_port']
64
- assert_equal ForemanRemoteExecutionCore.settings[:ssh_identity_key_file],
65
- connection_params['ansible_ssh_private_key_file']
64
+ assert_nil connection_params['ansible_ssh_private_key_file']
66
65
  assert_equal extra_options['ansible_port'],
67
66
  connection_params['ansible_port']
68
67
  assert_equal Setting['ansible_winrm_server_cert_validation'],
69
68
  connection_params['ansible_winrm_server_cert_validation']
70
69
  assert_equal Setting['remote_execution_effective_user_method'],
71
70
  connection_params['ansible_become_method']
72
- refute connection_params.key?('ansible_ssh_pass')
71
+ refute connection_params.key?('ansible_password')
73
72
  refute connection_params.key?('ansible_become_password')
74
73
  end
75
74
 
@@ -128,11 +127,15 @@ module ForemanAnsible
128
127
  end
129
128
 
130
129
  test 'ansible_roles are passed as top-level "hostvars"' do
130
+ host = FactoryBot.create(:host)
131
131
  roles = [].tap do |array|
132
- 2.times { array << FactoryBot.create(:ansible_role) }
132
+ 2.times do |idx|
133
+ role = FactoryBot.create(:ansible_role)
134
+ FactoryBot.create(:host_ansible_role, :host_id => host.id, :ansible_role_id => role.id, :position => idx)
135
+ array << role
136
+ end
133
137
  end
134
138
 
135
- host = FactoryBot.create(:host, :ansible_roles => roles)
136
139
  inventory = ForemanAnsible::InventoryCreator.new([host]).to_hash
137
140
  inventory_roles = inventory['_meta']['hostvars'][host.name]['foreman_ansible_roles']
138
141
  assert_equal 2, inventory_roles.count
@@ -156,7 +159,9 @@ module ForemanAnsible
156
159
  end
157
160
  end
158
161
 
159
- host = FactoryBot.create(:host, :ansible_roles => [role])
162
+ host = FactoryBot.create(:host)
163
+ FactoryBot.create(:host_ansible_role, :host_id => host.id, :ansible_role_id => role.id, :position => 0)
164
+
160
165
  inventory = ForemanAnsible::InventoryCreator.new([host]).to_hash
161
166
  host_inventory = inventory['_meta']['hostvars'][host.name]
162
167
  assert host_inventory[variables.first.key]
@@ -174,7 +179,9 @@ module ForemanAnsible
174
179
  end
175
180
  end
176
181
 
177
- host = FactoryBot.create(:host, :ansible_roles => [role])
182
+ host = FactoryBot.create(:host)
183
+ FactoryBot.create(:host_ansible_role, :host_id => host.id, :ansible_role_id => role.id, :position => 0)
184
+
178
185
  inventory = ForemanAnsible::InventoryCreator.new([host]).to_hash
179
186
  inventory_roles = inventory['_meta']['hostvars'][host.name]['foreman']
180
187
  refute inventory_roles[variables.first.key]
@@ -188,7 +195,8 @@ module ForemanAnsible
188
195
  :ansible_role_id => role.id,
189
196
  :default_value => "variable value",
190
197
  :override => true)
191
- host = FactoryBot.create(:host, :ansible_roles => [role])
198
+ host = FactoryBot.create(:host)
199
+ FactoryBot.create(:host_ansible_role, :host_id => host.id, :ansible_role_id => role.id, :position => 0)
192
200
  host.expects(:host_params).returns('test_var' => 'param value').at_least_once
193
201
  inventory = ForemanAnsible::InventoryCreator.new([host]).to_hash
194
202
  assert_equal 'variable value', inventory['_meta']['hostvars'][host.name]['test_var']
@@ -26,7 +26,7 @@ class UiRolesImporterTest < ActiveSupport::TestCase
26
26
  @role = FactoryBot.create(:ansible_role)
27
27
  new_role_name = 'test_role.foreman'
28
28
  @new_role = { :id => nil, :name => new_role_name }
29
- @changes = { 'new' => { 'test_role.foreman' => @new_role.to_json },
30
- 'obsolete' => { @role.name => @role.to_json } }
29
+ @changes = { 'new' => { 'test_role.foreman' => @new_role },
30
+ 'obsolete' => { @role.name => @role } }
31
31
  end
32
32
  end
@@ -0,0 +1,13 @@
1
+ import { camelCase } from 'lodash';
2
+
3
+ export const propsToCamelCase = ob =>
4
+ propsToCase(camelCase, 'propsToCamelCase only takes objects', ob);
5
+
6
+ const propsToCase = (casingFn, errorMsg, ob) => {
7
+ if (typeof ob !== 'object') throw Error(errorMsg);
8
+
9
+ return Object.keys(ob).reduce((memo, key) => {
10
+ memo[casingFn(key)] = ob[key];
11
+ return memo;
12
+ }, {});
13
+ };
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+
3
+ export const orderable = (Component, orderableProps) => props => (
4
+ <Component {...orderableProps} {...props} />
5
+ );
@@ -0,0 +1,7 @@
1
+ export const API = {
2
+ get: jest.fn(),
3
+ put: jest.fn(),
4
+ post: jest.fn(),
5
+ delete: jest.fn(),
6
+ patch: jest.fn(),
7
+ };