foreman_ansible 6.0.2 → 6.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/ansible_roles_controller.rb +12 -8
- data/app/controllers/ansible_variables_controller.rb +4 -0
- data/app/controllers/api/v2/ansible_inventories_controller.rb +2 -2
- data/app/controllers/api/v2/ansible_roles_controller.rb +32 -11
- data/app/controllers/api/v2/ansible_variables_controller.rb +6 -4
- data/app/controllers/foreman_ansible/concerns/import_controller_helper.rb +3 -3
- data/app/helpers/foreman_ansible/ansible_reports_helper.rb +42 -56
- data/app/helpers/foreman_ansible/ansible_roles_data_preparations.rb +95 -0
- data/app/helpers/foreman_ansible/ansible_roles_helper.rb +20 -1
- data/app/jobs/sync_roles_and_variables.rb +20 -0
- data/app/models/concerns/foreman_ansible/host_managed_extensions.rb +10 -7
- data/app/models/concerns/foreman_ansible/hostgroup_extensions.rb +19 -4
- data/app/models/foreman_ansible/ansible_provider.rb +52 -2
- data/app/models/host_ansible_role.rb +1 -0
- data/app/models/hostgroup_ansible_role.rb +1 -0
- data/app/models/setting/ansible.rb +9 -0
- data/app/services/foreman_ansible/ansible_report_importer.rb +4 -0
- data/app/services/foreman_ansible/ansible_report_scanner.rb +15 -1
- data/app/services/foreman_ansible/api_roles_importer.rb +23 -11
- data/app/services/foreman_ansible/fact_parser.rb +21 -1
- data/app/services/foreman_ansible/import_roles_and_variables_error_notification.rb +31 -0
- data/app/services/foreman_ansible/import_roles_and_variables_success_notification.rb +26 -0
- data/app/services/foreman_ansible/inventory_creator.rb +3 -7
- data/app/services/foreman_ansible/operating_system_parser.rb +8 -2
- data/app/services/foreman_ansible/roles_importer.rb +3 -2
- data/app/services/foreman_ansible/ui_roles_importer.rb +2 -2
- data/app/services/foreman_ansible/variables_importer.rb +36 -1
- data/app/views/ansible_roles/import.html.erb +10 -50
- data/app/views/ansible_variables/index.html.erb +1 -2
- data/app/views/api/v2/ansible_roles/sync.json.rabl +5 -0
- data/app/views/foreman_ansible/ansible_roles/_select_tab_content.html.erb +8 -17
- data/app/views/foreman_ansible/config_reports/_ansible.html.erb +24 -8
- data/app/views/foreman_ansible/job_templates/ansible_collections_-_install_from_galaxy.erb +28 -0
- data/app/views/foreman_ansible/job_templates/ansible_roles_-_ansible_default.erb +4 -0
- data/app/views/foreman_ansible/job_templates/ansible_roles_-_install_from_galaxy.erb +1 -1
- data/app/views/foreman_ansible/job_templates/capsule_upgrade_-_ansible_default.erb +2 -3
- data/app/views/foreman_ansible/job_templates/convert_to_rhel.erb +44 -0
- data/config/routes.rb +5 -4
- data/db/migrate/20210120150019_add_position_to_ansible_role.rb +27 -0
- data/db/seeds.d/100_common_parameters.rb +7 -0
- data/db/seeds.d/90_notification_blueprints.rb +19 -1
- data/lib/foreman_ansible/engine.rb +1 -1
- data/lib/foreman_ansible/register.rb +7 -5
- data/lib/foreman_ansible/version.rb +1 -1
- data/locale/ca/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/ca/foreman_ansible.po +1 -1
- data/locale/cs_CZ/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/cs_CZ/foreman_ansible.po +1 -1
- data/locale/de/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/de/foreman_ansible.po +1 -1
- data/locale/en/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/en/foreman_ansible.po +1 -1
- data/locale/en_GB/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/en_GB/foreman_ansible.po +1 -1
- data/locale/es/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/es/foreman_ansible.po +1 -1
- data/locale/fr/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/fr/foreman_ansible.po +1 -1
- data/locale/gl/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/gl/foreman_ansible.po +1 -1
- data/locale/it/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/it/foreman_ansible.po +1 -1
- data/locale/ja/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/ja/foreman_ansible.po +1 -1
- data/locale/ko/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/ko/foreman_ansible.po +1 -1
- data/locale/nl_NL/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/nl_NL/foreman_ansible.po +1 -1
- data/locale/pl/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/pl/foreman_ansible.po +1 -1
- data/locale/pt_BR/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/pt_BR/foreman_ansible.po +1 -1
- data/locale/ru/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/ru/foreman_ansible.po +1 -1
- data/locale/sv_SE/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/sv_SE/foreman_ansible.po +1 -1
- data/locale/zh_CN/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/zh_CN/foreman_ansible.po +1 -1
- data/locale/zh_TW/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/zh_TW/foreman_ansible.po +1 -1
- data/package.json +13 -42
- data/test/factories/ansible_roles.rb +12 -0
- data/test/factories/host_ansible_enhancements.rb +23 -0
- data/test/foreman_ansible/helpers/ansible_roles_helper_test.rb +45 -0
- data/test/functional/ansible_variables_controller_test.rb +0 -15
- data/test/functional/api/v2/ansible_roles_controller_test.rb +23 -0
- data/test/functional/api/v2/hostgroups_controller_test.rb +5 -4
- data/test/functional/api/v2/hosts_controller_test.rb +9 -8
- data/test/functional/hosts_controller_test.rb +10 -6
- data/test/unit/concerns/host_managed_extensions_test.rb +17 -3
- data/test/unit/concerns/hostgroup_extensions_test.rb +13 -7
- data/test/unit/helpers/ansible_reports_helper_test.rb +4 -30
- data/test/unit/host_ansible_role_test.rb +2 -1
- data/test/unit/hostgroup_ansible_role_test.rb +2 -1
- data/test/unit/ignore_roles_test.rb +43 -0
- data/test/unit/import_roles_and_variables.rb +60 -0
- data/test/unit/services/ansible_variables_importer_test.rb +13 -0
- data/test/unit/services/api_roles_importer_test.rb +22 -5
- data/test/unit/services/fact_parser_test.rb +16 -0
- data/test/unit/services/inventory_creator_test.rb +15 -7
- data/test/unit/services/ui_roles_importer_test.rb +2 -2
- data/webpack/components/AnsibleHostDetail/AnsibleHostDetail.js +35 -0
- data/webpack/components/AnsibleHostDetail/AnsibleHostDetail.scss +6 -0
- data/webpack/components/AnsibleHostDetail/AnsibleHostDetail.test.js +14 -0
- data/webpack/components/AnsibleHostDetail/index.js +6 -0
- data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariables.js +178 -0
- data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariables.scss +9 -0
- data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesActions.js +39 -0
- data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesConstants.js +4 -0
- data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesHelpers.js +11 -0
- data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesHelpers.test.js +50 -0
- data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesImport.test.js +39 -0
- data/webpack/components/AnsibleRolesAndVariables/__test__/__snapshots__/AnsibleRolesAndVariablesImport.test.js.snap +177 -0
- data/webpack/components/AnsibleRolesAndVariables/index.js +31 -0
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.js +25 -27
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.scss +1 -1
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js +20 -14
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherConstants.js +1 -2
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js +13 -8
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js +8 -28
- data/webpack/components/AnsibleRolesSwitcher/__fixtures__/ansibleRolesSwitcherReducer.fixtures.js +1 -0
- data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcher.test.js +6 -4
- data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherReducer.test.js +1 -9
- data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherSelectors.test.js +3 -16
- data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcher.test.js.snap +4 -8
- data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherReducer.test.js.snap +8 -97
- data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherSelectors.test.js.snap +5 -30
- data/webpack/components/AnsibleRolesSwitcher/components/AnsiblePermissionDenied.test.js +1 -1
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.js +5 -2
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.test.js +1 -1
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.js +43 -0
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.test.js +19 -0
- data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.js +63 -51
- data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.test.js +4 -1
- data/webpack/components/AnsibleRolesSwitcher/components/AvailableRolesList.test.js +1 -1
- data/webpack/components/AnsibleRolesSwitcher/components/OrderedRolesTooltip.js +23 -0
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AnsiblePermissionDenied.test.js.snap +2 -0
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AnsibleRoleInputs.test.js.snap +51 -0
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AssignedRolesList.test.js.snap +28 -28
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AvailableRolesList.test.js.snap +5 -0
- data/webpack/components/AnsibleRolesSwitcher/index.js +4 -8
- data/webpack/global_index.js +12 -0
- data/webpack/index.js +6 -13
- metadata +54 -30
- data/app/views/ansible_variables/import.html.erb +0 -56
- data/test/unit/lib/foreman_ansible_core/ansible_runner_test.rb +0 -51
- data/test/unit/lib/foreman_ansible_core/command_creator_test.rb +0 -64
- data/test/unit/lib/foreman_ansible_core/playbook_runner_test.rb +0 -110
- data/webpack/__mocks__/foremanReact/common/I18n.js +0 -1
- data/webpack/__mocks__/foremanReact/components/Pagination/PaginationWrapper.js +0 -2
- data/webpack/__mocks__/foremanReact/components/common/EmptyState.js +0 -5
- data/webpack/test_setup.js +0 -12
@@ -45,7 +45,30 @@ module Api
|
|
45
45
|
}, :session => set_session_user
|
46
46
|
assert_response :success
|
47
47
|
end
|
48
|
+
|
48
49
|
test 'should fetch' do
|
50
|
+
@controller = Api::V2::AnsibleRolesController.new
|
51
|
+
@controller.stubs(:prepare_ansible_import_rows).returns(
|
52
|
+
[{
|
53
|
+
:name => 'test_user.test_name',
|
54
|
+
:id => nil,
|
55
|
+
:role_action => 'Import Role',
|
56
|
+
:variables => 'Add: 7',
|
57
|
+
:hosts_count => '',
|
58
|
+
:hostgroup_count => '',
|
59
|
+
:kind => 'new'
|
60
|
+
},
|
61
|
+
{
|
62
|
+
:name => 'some_user.some_role',
|
63
|
+
:id => nil,
|
64
|
+
:role_action => 'Import Role',
|
65
|
+
:variables => 'Add: 3',
|
66
|
+
:hosts_count => '',
|
67
|
+
:hostgroup_count => '',
|
68
|
+
:kind => 'new'
|
69
|
+
}]
|
70
|
+
)
|
71
|
+
|
49
72
|
get :fetch, :params => {
|
50
73
|
:proxy_id => @proxy.id
|
51
74
|
}, :session => set_session_user
|
@@ -9,6 +9,7 @@ module Api
|
|
9
9
|
class HostgroupsControllerTest < ActionController::TestCase
|
10
10
|
setup do
|
11
11
|
@ansible_role1 = FactoryBot.create(:ansible_role)
|
12
|
+
@ansible_role2 = FactoryBot.create(:ansible_role)
|
12
13
|
@host1 = FactoryBot.create(:host, :with_hostgroup)
|
13
14
|
@host2 = FactoryBot.create(:host, :with_hostgroup)
|
14
15
|
@host3 = FactoryBot.create(:host, :with_hostgroup)
|
@@ -44,23 +45,23 @@ module Api
|
|
44
45
|
end
|
45
46
|
|
46
47
|
test 'should list ansible roles for a host group' do
|
47
|
-
@host3.hostgroup.
|
48
|
+
FactoryBot.create(:hostgroup_ansible_role, hostgroup_id: @host3.hostgroup.id, ansible_role_id: @ansible_role1.id, position: 0)
|
48
49
|
get :ansible_roles, :params => { :id => @host3.hostgroup.id }
|
49
50
|
response = JSON.parse(@response.body)
|
50
51
|
assert_equal @ansible_role1.id, response.first['id']
|
51
52
|
end
|
52
53
|
|
53
|
-
test 'should assign a role to a hostgroup' do
|
54
|
+
test 'should assign a role to a hostgroup with a correct ordering' do
|
54
55
|
hostgroup = FactoryBot.create(:hostgroup,
|
55
56
|
:ansible_role_ids => [])
|
56
57
|
post :assign_ansible_roles,
|
57
58
|
:params => {
|
58
59
|
:id => hostgroup.id,
|
59
|
-
:ansible_role_ids => [@ansible_role1.id]
|
60
|
+
:ansible_role_ids => [@ansible_role2.id, @ansible_role1.id]
|
60
61
|
},
|
61
62
|
:session => set_session_user
|
62
63
|
assert_response :success
|
63
|
-
|
64
|
+
assert_equal assigns('hostgroup').ansible_roles, [@ansible_role2, @ansible_role1]
|
64
65
|
end
|
65
66
|
end
|
66
67
|
end
|
@@ -53,9 +53,9 @@ module Api
|
|
53
53
|
end
|
54
54
|
|
55
55
|
test 'should update a host with ansible_role_ids param' do
|
56
|
-
host = FactoryBot.create(:host,
|
57
|
-
|
58
|
-
|
56
|
+
host = FactoryBot.create(:host, :managed => false)
|
57
|
+
FactoryBot.create(:host_ansible_role, :host_id => host.id, :ansible_role_id => @ansible_role1.id, :position => 0)
|
58
|
+
|
59
59
|
post :update,
|
60
60
|
:params => {
|
61
61
|
:id => host.id,
|
@@ -63,28 +63,29 @@ module Api
|
|
63
63
|
},
|
64
64
|
:session => set_session_user
|
65
65
|
assert_response :success
|
66
|
-
|
66
|
+
host.reload
|
67
|
+
assert_equal host.ansible_roles, [@ansible_role2]
|
67
68
|
end
|
68
69
|
|
69
70
|
test 'should list ansible roles for a host' do
|
70
|
-
@host3.
|
71
|
+
FactoryBot.create(:host_ansible_role, :host_id => @host3.id, :ansible_role_id => @ansible_role1.id, :position => 0)
|
71
72
|
get :ansible_roles, :params => { :id => @host3.id }
|
72
73
|
response = JSON.parse(@response.body)
|
73
74
|
assert_equal @ansible_role1.id, response.first['id']
|
74
75
|
end
|
75
76
|
|
76
|
-
test 'should assign a role to a host' do
|
77
|
+
test 'should assign a role to a host with a correct ordering' do
|
77
78
|
host = FactoryBot.create(:host,
|
78
79
|
:managed => false,
|
79
80
|
:ansible_role_ids => [])
|
80
81
|
post :assign_ansible_roles,
|
81
82
|
:params => {
|
82
83
|
:id => host.id,
|
83
|
-
:ansible_role_ids => [@ansible_role1.id]
|
84
|
+
:ansible_role_ids => [@ansible_role2.id, @ansible_role1.id]
|
84
85
|
},
|
85
86
|
:session => set_session_user
|
86
87
|
assert_response :success
|
87
|
-
|
88
|
+
assert_equal assigns('host').ansible_roles, [@ansible_role2, @ansible_role1]
|
88
89
|
end
|
89
90
|
end
|
90
91
|
end
|
@@ -16,7 +16,9 @@ class HostsControllerExtensionsTest < ActionController::TestCase
|
|
16
16
|
test 'create a host with ansible roles' do
|
17
17
|
host = { :name => 'foo',
|
18
18
|
:managed => false,
|
19
|
-
:
|
19
|
+
:host_ansible_roles_attributes => {
|
20
|
+
0 => { :ansible_role_id => @role.id, :position => 0 }
|
21
|
+
} }
|
20
22
|
post :create, :params => { :host => host }, :session => set_session_user
|
21
23
|
assert_redirected_to host_url(assigns('host'))
|
22
24
|
assert assigns('host').ansible_roles, [@role]
|
@@ -27,17 +29,19 @@ class HostsControllerExtensionsTest < ActionController::TestCase
|
|
27
29
|
post :update,
|
28
30
|
:params => {
|
29
31
|
:id => host.id,
|
30
|
-
:host => { :
|
32
|
+
:host => { :host_ansible_roles_attributes => {
|
33
|
+
0 => { :ansible_role_id => @role.id, :position => 0 }
|
34
|
+
} }
|
31
35
|
},
|
32
36
|
:session => set_session_user
|
33
37
|
assert_redirected_to host_url(assigns('host'))
|
34
|
-
|
38
|
+
assert_equal assigns('host').ansible_roles, [@role]
|
35
39
|
end
|
36
40
|
|
37
41
|
test 'delete a host with ansible roles' do
|
38
|
-
host = FactoryBot.create(:host,
|
39
|
-
|
40
|
-
|
42
|
+
host = FactoryBot.create(:host, :managed => false)
|
43
|
+
FactoryBot.create(:host_ansible_role, host_id: host.id, ansible_role_id: @role.id, position: 0)
|
44
|
+
|
41
45
|
assert_include @role.hosts, host
|
42
46
|
delete :destroy,
|
43
47
|
:params => { :id => host.id },
|
@@ -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
|
-
|
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 [@
|
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
|
-
|
14
|
-
@hostgroup = FactoryBot.create(:hostgroup
|
15
|
-
|
16
|
-
|
17
|
-
|
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 [@
|
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
|
@@ -6,43 +6,17 @@ class AnsibleReportsHelperTest < ActiveSupport::TestCase
|
|
6
6
|
include ForemanAnsible::AnsibleReportsHelper
|
7
7
|
include ActionView::Helpers::TagHelper
|
8
8
|
|
9
|
-
test '
|
9
|
+
test 'module message extraction' do
|
10
10
|
log_value = <<-ANSIBLELOG.strip_heredoc
|
11
|
-
|
11
|
+
{"msg": "Nothing to do", "changed": false, "results": [], "rc": 0, "invocation": {"module_args": {"name": ["openssh"], "state": "present", "allow_downgrade": false, "autoremove": false, "bugfix": false, "disable_gpg_check": false, "disable_plugin": [], "disablerepo": [], "download_only": false, "enable_plugin": [], "enablerepo": [], "exclude": [], "installroot": "/", "install_repoquery": true, "install_weak_deps": true, "security": false, "skip_broken": false, "update_cache": false, "update_only": false, "validate_certs": true, "lock_timeout": 30, "conf_file": null, "disable_excludes": null, "download_dir": null, "list": null, "releasever": null}}, "_ansible_no_log": false, "failed": false, "module": "package"}
|
12
12
|
ANSIBLELOG
|
13
13
|
message = FactoryBot.build(:message)
|
14
14
|
message.value = log_value
|
15
15
|
log = FactoryBot.build(:log)
|
16
16
|
log.message = message
|
17
17
|
assert_match(
|
18
|
-
/
|
19
|
-
|
20
|
-
)
|
21
|
-
end
|
22
|
-
|
23
|
-
test 'pretty print is able to print a hash' do
|
24
|
-
hash = {
|
25
|
-
'allow_downgrade' => false,
|
26
|
-
'name' => ['ntp'],
|
27
|
-
'list' => nil,
|
28
|
-
'disable_gpg_check' => false,
|
29
|
-
'conf_file' => nil,
|
30
|
-
'install_repoquery' => true,
|
31
|
-
'state' => 'installed',
|
32
|
-
'disablerepo' => nil,
|
33
|
-
'update_cache' => false,
|
34
|
-
'enablerepo' => nil,
|
35
|
-
'exclude' => nil,
|
36
|
-
'security' => false,
|
37
|
-
'validate_certs' => true,
|
38
|
-
'installroot' => '/',
|
39
|
-
'skip_broken' => false
|
40
|
-
}
|
41
|
-
assert_equal(
|
42
|
-
hash,
|
43
|
-
remove_keys(
|
44
|
-
hash
|
45
|
-
)
|
18
|
+
/Nothing to do/,
|
19
|
+
ansible_module_message(log).to_s
|
46
20
|
)
|
47
21
|
end
|
48
22
|
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
|
@@ -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(:
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|