foreman_ansible 6.2.0 → 6.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) 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_roles_controller.rb +32 -11
  5. data/app/controllers/api/v2/ansible_variables_controller.rb +6 -4
  6. data/app/controllers/foreman_ansible/concerns/import_controller_helper.rb +3 -3
  7. data/app/helpers/foreman_ansible/ansible_reports_helper.rb +8 -0
  8. data/app/helpers/foreman_ansible/ansible_roles_data_preparations.rb +95 -0
  9. data/app/helpers/foreman_ansible/ansible_roles_helper.rb +20 -1
  10. data/app/jobs/sync_roles_and_variables.rb +20 -0
  11. data/app/models/concerns/foreman_ansible/host_managed_extensions.rb +7 -4
  12. data/app/models/concerns/foreman_ansible/hostgroup_extensions.rb +7 -4
  13. data/app/models/foreman_ansible/ansible_provider.rb +2 -1
  14. data/app/models/host_ansible_role.rb +1 -0
  15. data/app/models/hostgroup_ansible_role.rb +1 -0
  16. data/app/models/setting/ansible.rb +9 -0
  17. data/app/services/foreman_ansible/ansible_report_importer.rb +4 -0
  18. data/app/services/foreman_ansible/ansible_report_scanner.rb +15 -1
  19. data/app/services/foreman_ansible/api_roles_importer.rb +23 -11
  20. data/app/services/foreman_ansible/fact_parser.rb +21 -1
  21. data/app/services/foreman_ansible/import_roles_and_variables_error_notification.rb +31 -0
  22. data/app/services/foreman_ansible/import_roles_and_variables_success_notification.rb +26 -0
  23. data/app/services/foreman_ansible/inventory_creator.rb +3 -7
  24. data/app/services/foreman_ansible/roles_importer.rb +3 -2
  25. data/app/services/foreman_ansible/ui_roles_importer.rb +2 -2
  26. data/app/services/foreman_ansible/variables_importer.rb +32 -2
  27. data/app/views/ansible_roles/import.html.erb +10 -50
  28. data/app/views/ansible_variables/index.html.erb +1 -2
  29. data/app/views/api/v2/ansible_roles/sync.json.rabl +5 -0
  30. data/app/views/foreman_ansible/ansible_roles/_select_tab_content.html.erb +1 -2
  31. data/app/views/foreman_ansible/config_reports/_ansible.html.erb +13 -6
  32. data/app/views/foreman_ansible/job_templates/ansible_collections_-_install_from_galaxy.erb +28 -0
  33. data/app/views/foreman_ansible/job_templates/convert_to_rhel.erb +44 -0
  34. data/config/routes.rb +5 -4
  35. data/db/migrate/20210120150019_add_position_to_ansible_role.rb +27 -0
  36. data/db/seeds.d/100_common_parameters.rb +7 -0
  37. data/db/seeds.d/90_notification_blueprints.rb +19 -1
  38. data/lib/foreman_ansible/engine.rb +1 -0
  39. data/lib/foreman_ansible/register.rb +5 -5
  40. data/lib/foreman_ansible/version.rb +1 -1
  41. data/locale/ca/LC_MESSAGES/foreman_ansible.mo +0 -0
  42. data/locale/ca/foreman_ansible.po +1 -1
  43. data/locale/cs_CZ/LC_MESSAGES/foreman_ansible.mo +0 -0
  44. data/locale/cs_CZ/foreman_ansible.po +1 -1
  45. data/locale/de/LC_MESSAGES/foreman_ansible.mo +0 -0
  46. data/locale/de/foreman_ansible.po +1 -1
  47. data/locale/en/LC_MESSAGES/foreman_ansible.mo +0 -0
  48. data/locale/en/foreman_ansible.po +1 -1
  49. data/locale/en_GB/LC_MESSAGES/foreman_ansible.mo +0 -0
  50. data/locale/en_GB/foreman_ansible.po +1 -1
  51. data/locale/es/LC_MESSAGES/foreman_ansible.mo +0 -0
  52. data/locale/es/foreman_ansible.po +1 -1
  53. data/locale/fr/LC_MESSAGES/foreman_ansible.mo +0 -0
  54. data/locale/fr/foreman_ansible.po +1 -1
  55. data/locale/gl/LC_MESSAGES/foreman_ansible.mo +0 -0
  56. data/locale/gl/foreman_ansible.po +1 -1
  57. data/locale/it/LC_MESSAGES/foreman_ansible.mo +0 -0
  58. data/locale/it/foreman_ansible.po +1 -1
  59. data/locale/ja/LC_MESSAGES/foreman_ansible.mo +0 -0
  60. data/locale/ja/foreman_ansible.po +1 -1
  61. data/locale/ko/LC_MESSAGES/foreman_ansible.mo +0 -0
  62. data/locale/ko/foreman_ansible.po +1 -1
  63. data/locale/nl_NL/LC_MESSAGES/foreman_ansible.mo +0 -0
  64. data/locale/nl_NL/foreman_ansible.po +1 -1
  65. data/locale/pl/LC_MESSAGES/foreman_ansible.mo +0 -0
  66. data/locale/pl/foreman_ansible.po +1 -1
  67. data/locale/pt_BR/LC_MESSAGES/foreman_ansible.mo +0 -0
  68. data/locale/pt_BR/foreman_ansible.po +1 -1
  69. data/locale/ru/LC_MESSAGES/foreman_ansible.mo +0 -0
  70. data/locale/ru/foreman_ansible.po +1 -1
  71. data/locale/sv_SE/LC_MESSAGES/foreman_ansible.mo +0 -0
  72. data/locale/sv_SE/foreman_ansible.po +1 -1
  73. data/locale/zh_CN/LC_MESSAGES/foreman_ansible.mo +0 -0
  74. data/locale/zh_CN/foreman_ansible.po +1 -1
  75. data/locale/zh_TW/LC_MESSAGES/foreman_ansible.mo +0 -0
  76. data/locale/zh_TW/foreman_ansible.po +1 -1
  77. data/test/factories/ansible_roles.rb +12 -0
  78. data/test/factories/host_ansible_enhancements.rb +23 -0
  79. data/test/foreman_ansible/helpers/ansible_roles_helper_test.rb +45 -0
  80. data/test/functional/ansible_variables_controller_test.rb +0 -15
  81. data/test/functional/api/v2/ansible_roles_controller_test.rb +23 -0
  82. data/test/functional/api/v2/hostgroups_controller_test.rb +5 -4
  83. data/test/functional/api/v2/hosts_controller_test.rb +9 -8
  84. data/test/functional/hosts_controller_test.rb +10 -6
  85. data/test/unit/concerns/host_managed_extensions_test.rb +17 -3
  86. data/test/unit/concerns/hostgroup_extensions_test.rb +13 -7
  87. data/test/unit/host_ansible_role_test.rb +2 -1
  88. data/test/unit/hostgroup_ansible_role_test.rb +2 -1
  89. data/test/unit/ignore_roles_test.rb +43 -0
  90. data/test/unit/import_roles_and_variables.rb +60 -0
  91. data/test/unit/services/api_roles_importer_test.rb +22 -5
  92. data/test/unit/services/fact_parser_test.rb +16 -0
  93. data/test/unit/services/inventory_creator_test.rb +15 -7
  94. data/test/unit/services/ui_roles_importer_test.rb +2 -2
  95. data/webpack/__mocks__/foremanReact/common/helpers.js +13 -0
  96. data/webpack/__mocks__/foremanReact/components/common/forms/OrderableSelect/helpers.js +5 -0
  97. data/webpack/__mocks__/foremanReact/redux/API.js +7 -0
  98. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariables.js +178 -0
  99. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariables.scss +9 -0
  100. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesActions.js +39 -0
  101. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesConstants.js +4 -0
  102. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesHelpers.js +11 -0
  103. data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesHelpers.test.js +50 -0
  104. data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesImport.test.js +39 -0
  105. data/webpack/components/AnsibleRolesAndVariables/__test__/__snapshots__/AnsibleRolesAndVariablesImport.test.js.snap +177 -0
  106. data/webpack/components/AnsibleRolesAndVariables/index.js +31 -0
  107. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.js +14 -18
  108. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.scss +1 -1
  109. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js +6 -0
  110. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherConstants.js +1 -2
  111. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js +13 -8
  112. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js +8 -28
  113. data/webpack/components/AnsibleRolesSwitcher/__fixtures__/ansibleRolesSwitcherReducer.fixtures.js +1 -0
  114. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcher.test.js +2 -0
  115. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherReducer.test.js +0 -8
  116. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherSelectors.test.js +2 -15
  117. data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcher.test.js.snap +4 -9
  118. data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherReducer.test.js.snap +8 -97
  119. data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherSelectors.test.js.snap +5 -30
  120. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.js +5 -2
  121. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.js +43 -0
  122. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.test.js +19 -0
  123. data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.js +63 -51
  124. data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.test.js +3 -0
  125. data/webpack/components/AnsibleRolesSwitcher/components/OrderedRolesTooltip.js +23 -0
  126. data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AnsibleRoleInputs.test.js.snap +51 -0
  127. data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AssignedRolesList.test.js.snap +28 -28
  128. data/webpack/components/AnsibleRolesSwitcher/index.js +3 -7
  129. data/webpack/index.js +6 -0
  130. metadata +55 -9
  131. data/app/views/ansible_variables/import.html.erb +0 -56
@@ -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,8 +61,7 @@ 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'],
@@ -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
+ };
@@ -0,0 +1,178 @@
1
+ import React, { useState } from 'react';
2
+ import {
3
+ Table,
4
+ TableHeader,
5
+ TableBody,
6
+ cellWidth,
7
+ } from '@patternfly/react-table';
8
+ import {
9
+ Button,
10
+ Toolbar,
11
+ ToolbarGroup,
12
+ ToolbarContent,
13
+ ToolbarItem,
14
+ Checkbox,
15
+ Pagination,
16
+ } from '@patternfly/react-core';
17
+
18
+ import PropTypes from 'prop-types';
19
+ import { DEFAULT_PER_PAGE } from './AnsibleRolesAndVariablesConstants';
20
+ import './AnsibleRolesAndVariables.scss';
21
+
22
+ const ImportRolesAndVariablesTable = ({
23
+ columnsData,
24
+ rowsData,
25
+ proxy,
26
+ onSubmit,
27
+ onCancel,
28
+ }) => {
29
+ const columns = columnsData.map(col => ({
30
+ ...col,
31
+ transforms: [cellWidth(10)],
32
+ }));
33
+ const [rows, setRows] = useState(rowsData);
34
+
35
+ const [isChecked, setIsChecked] = useState(false);
36
+ const [selectedRowsCount, setSelectRowsCount] = useState(0);
37
+
38
+ const [page, setPage] = useState();
39
+ const [perPage, setPerPage] = useState(DEFAULT_PER_PAGE);
40
+ const [paginatedRows, setPaginatedRows] = useState(rows.slice(0, perPage));
41
+
42
+ const onSelect = (event, isSelected, rowId, row) => {
43
+ const selectableRowLength = rows.filter(
44
+ tempRow => tempRow.parent === undefined
45
+ ).length;
46
+ let rowsCount = selectedRowsCount;
47
+ const tempRows = rows.map(tempRow => {
48
+ if (rowId === -1) {
49
+ tempRow.selected = isSelected;
50
+ setIsChecked(isSelected);
51
+ setSelectRowsCount(isSelected ? selectableRowLength : 0);
52
+ } else if (tempRow.id === row.id) {
53
+ tempRow.selected = isSelected;
54
+ rowsCount = isSelected ? selectedRowsCount + 1 : selectedRowsCount - 1;
55
+ if (rowsCount > 0 && rowsCount === selectableRowLength) {
56
+ setIsChecked(true);
57
+ } else {
58
+ setIsChecked(false);
59
+ }
60
+ setSelectRowsCount(rowsCount);
61
+ }
62
+ return tempRow;
63
+ });
64
+ setRows(tempRows);
65
+ };
66
+
67
+ const SelectAll = checked => {
68
+ onSelect(null, checked, -1);
69
+ };
70
+
71
+ const handleSetPage = (event, newPage) => {
72
+ const startIdx = (newPage - 1) * perPage;
73
+ const endIdx =
74
+ rows.length < newPage * perPage ? rows.length : newPage * perPage;
75
+ setPage(newPage);
76
+ setPaginatedRows(rows.slice(startIdx, endIdx));
77
+ };
78
+
79
+ const handlePerPageSelect = (
80
+ event,
81
+ newPerPage,
82
+ newPage,
83
+ startIdx,
84
+ endIdx
85
+ ) => {
86
+ setPerPage(newPerPage);
87
+ setPage(newPage);
88
+ setPaginatedRows(rows.slice(startIdx, endIdx));
89
+ };
90
+
91
+ const renderPagination = (variant = 'top') => (
92
+ <Pagination
93
+ isCompact
94
+ itemCount={rows.length}
95
+ page={page}
96
+ perPage={perPage}
97
+ defaultToFullPage
98
+ onSetPage={handleSetPage}
99
+ onPerPageSelect={handlePerPageSelect}
100
+ perPageOptions={[
101
+ { title: '3', value: 3 },
102
+ { title: '5', value: 5 },
103
+ { title: '10', value: 10 },
104
+ ]}
105
+ titles={{
106
+ paginationTitle: `${variant} pagination`,
107
+ }}
108
+ />
109
+ );
110
+
111
+ const renderSelectAll = () => (
112
+ <Toolbar>
113
+ <ToolbarContent>
114
+ <ToolbarGroup variant="icon-button-group">
115
+ <ToolbarItem>
116
+ <Checkbox
117
+ isChecked={isChecked}
118
+ onChange={SelectAll}
119
+ aria-label="select all checkbox"
120
+ id="select-all"
121
+ name="select-all"
122
+ label={isChecked ? 'Deselect all' : 'Select all'}
123
+ />
124
+ </ToolbarItem>
125
+ </ToolbarGroup>
126
+ </ToolbarContent>
127
+ </Toolbar>
128
+ );
129
+
130
+ const renderSubmitAndCancel = () => (
131
+ <div className="submit-cancel-btns">
132
+ <br />
133
+ <br />
134
+ <Button variant="primary" onClick={() => onSubmit(rows, proxy)}>
135
+ Submit
136
+ </Button>
137
+ <Button variant="secondary" onClick={onCancel}>
138
+ Cancel
139
+ </Button>
140
+ </div>
141
+ );
142
+
143
+ return (
144
+ <div id="import-ansible-roles-variables">
145
+ {renderSelectAll()}
146
+ <Table
147
+ aria-label="import roles and variables"
148
+ onSelect={onSelect}
149
+ rows={paginatedRows}
150
+ cells={columns}
151
+ canSelectAll={false}
152
+ >
153
+ <TableHeader />
154
+ <TableBody />
155
+ </Table>
156
+ {renderPagination()}
157
+ {renderSubmitAndCancel()}
158
+ </div>
159
+ );
160
+ };
161
+
162
+ ImportRolesAndVariablesTable.defaultProps = {
163
+ columnsData: undefined,
164
+ rowsData: [],
165
+ proxy: undefined,
166
+ onSubmit: undefined,
167
+ onCancel: undefined,
168
+ };
169
+
170
+ ImportRolesAndVariablesTable.propTypes = {
171
+ columnsData: PropTypes.array,
172
+ rowsData: PropTypes.array,
173
+ proxy: PropTypes.number,
174
+ onSubmit: PropTypes.func,
175
+ onCancel: PropTypes.func,
176
+ };
177
+
178
+ export default ImportRolesAndVariablesTable;
@@ -0,0 +1,9 @@
1
+ #import-ansible-roles-variables {
2
+ .submit-cancel-btns {
3
+ padding-top: 20px;
4
+
5
+ button {
6
+ margin-right: 5px;
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+ import { translate as __ } from 'foremanReact/common/I18n';
3
+ import { post } from 'foremanReact/redux/API';
4
+ import { push } from 'connected-react-router';
5
+ import { prepareResult } from './AnsibleRolesAndVariablesHelpers';
6
+ import {
7
+ ANSIBLE_ROLE_CONFIRM_IMPORT_PATH,
8
+ ANSIBLE_ROLES_INDEX,
9
+ } from './AnsibleRolesAndVariablesConstants';
10
+
11
+ export const foremanUrl = path => `${window.URL_PREFIX}${path}`;
12
+
13
+ export const onSubmit = (rows, proxy) => dispatch => {
14
+ const params = prepareResult(rows);
15
+ dispatch(
16
+ post({
17
+ key: 'import_ansible_v_r',
18
+ url: ANSIBLE_ROLE_CONFIRM_IMPORT_PATH,
19
+ params: { changed: params, proxy },
20
+ handleSuccess: () => {
21
+ setTimeout(() => dispatch(push(ANSIBLE_ROLES_INDEX)), 500);
22
+ },
23
+ successToast: response => (
24
+ <span>
25
+ {__('Import roles and variables started: ')}
26
+ <a
27
+ target="_blank"
28
+ rel="noopener noreferrer"
29
+ href={foremanUrl(`/foreman_tasks/tasks/${response.data?.task?.id}`)}
30
+ >
31
+ {__('view the task in progress')}
32
+ </a>
33
+ </span>
34
+ ),
35
+ errorToast: error =>
36
+ `${__('Failed to import roles and variables ')} ${error}`,
37
+ })
38
+ );
39
+ };
@@ -0,0 +1,4 @@
1
+ export const ANSIBLE_ROLES_INDEX = '/ansible/ansible_roles';
2
+ export const ANSIBLE_ROLE_CONFIRM_IMPORT_PATH =
3
+ '/ansible/ansible_roles/confirm_import';
4
+ export const DEFAULT_PER_PAGE = 5;
@@ -0,0 +1,11 @@
1
+ export const prepareResult = rows => {
2
+ const result = {};
3
+ const selectRows = rows.filter(row => row.selected === true);
4
+ selectRows.forEach(row => {
5
+ result[row.kind] = {};
6
+ });
7
+ selectRows.forEach(row => {
8
+ result[row.kind][row.role.name] = row.role;
9
+ });
10
+ return result;
11
+ };
@@ -0,0 +1,50 @@
1
+ import { prepareResult } from '../AnsibleRolesAndVariablesHelpers';
2
+
3
+ const bennojoy = { created_at: null, id: null, name: 'bennojoy.ntp' };
4
+ const gitRole = { created_at: null, id: null, name: '0ta2.git_role' };
5
+ const jriguera = { created_at: null, id: null, name: 'jriguera.monit' };
6
+ const rows = [
7
+ {
8
+ cells: [
9
+ 'bennojoy.ntp',
10
+ 'Update Role Variables',
11
+ 'Add: 1 Remove: 2 ',
12
+ '',
13
+ '',
14
+ ],
15
+ kind: 'old',
16
+ id: 'bennojoy.ntp',
17
+ role: bennojoy,
18
+ selected: true,
19
+ },
20
+ {
21
+ cells: ['0ta2.git_role', 'Import Role ', 'Add: 5 ', '', ''],
22
+ kind: 'new',
23
+ id: '0ta2.git_role',
24
+ role: gitRole,
25
+ selected: true,
26
+ },
27
+ {
28
+ cells: ['jriguera.monit', 'Import Role ', 'Add: 12 ', '', ''],
29
+ kind: 'new',
30
+ id: 'jriguera.monit',
31
+ role: jriguera,
32
+ },
33
+ ];
34
+
35
+ const result = {
36
+ old: {
37
+ 'bennojoy.ntp': bennojoy,
38
+ },
39
+ new: {
40
+ '0ta2.git_role': gitRole,
41
+ },
42
+ };
43
+
44
+ describe('AnsibleRolesAndVariablesHelpers', () => {
45
+ describe('prepareResult', () => {
46
+ it('should return correct results', () => {
47
+ expect(prepareResult(rows)).toStrictEqual(result);
48
+ });
49
+ });
50
+ });