foreman_ansible 6.0.0 → 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v2/ansible_inventories_controller.rb +2 -2
  3. data/app/helpers/foreman_ansible/ansible_reports_helper.rb +2 -5
  4. data/app/models/concerns/foreman_ansible/host_managed_extensions.rb +3 -3
  5. data/app/models/concerns/foreman_ansible/hostgroup_extensions.rb +12 -0
  6. data/app/models/foreman_ansible/ansible_provider.rb +1 -9
  7. data/app/services/foreman_ansible/operating_system_parser.rb +8 -2
  8. data/app/services/foreman_ansible/variables_importer.rb +9 -4
  9. data/app/views/ansible_roles/welcome.html.erb +1 -1
  10. data/app/views/foreman_ansible/ansible_roles/_select_tab_content.html.erb +8 -16
  11. data/app/views/foreman_ansible/job_templates/ansible_roles_-_install_from_galaxy.erb +1 -1
  12. data/app/views/foreman_ansible/job_templates/capsule_upgrade_-_ansible_default.erb +2 -3
  13. data/app/views/foreman_ansible/job_templates/configure_cloud_connector_-_ansible_default.erb +1 -0
  14. data/app/views/foreman_ansible/job_templates/service_action_-_enable_web_console.erb +16 -0
  15. data/lib/foreman_ansible/remote_execution.rb +8 -1
  16. data/lib/foreman_ansible/version.rb +1 -1
  17. data/package.json +11 -42
  18. data/test/unit/ansible_provider_test.rb +1 -1
  19. data/test/unit/lib/foreman_ansible_core/ansible_runner_test.rb +3 -3
  20. data/test/unit/lib/foreman_ansible_core/playbook_runner_test.rb +3 -3
  21. data/test/unit/services/ansible_variables_importer_test.rb +13 -0
  22. data/test/unit/services/inventory_creator_test.rb +1 -1
  23. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.js +11 -9
  24. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js +14 -14
  25. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcher.test.js +4 -4
  26. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherReducer.test.js +1 -1
  27. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherSelectors.test.js +1 -1
  28. data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcher.test.js.snap +1 -0
  29. data/webpack/components/AnsibleRolesSwitcher/components/AnsiblePermissionDenied.test.js +1 -1
  30. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.test.js +1 -1
  31. data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.test.js +1 -1
  32. data/webpack/components/AnsibleRolesSwitcher/components/AvailableRolesList.test.js +1 -1
  33. data/webpack/components/AnsibleRolesSwitcher/index.js +1 -1
  34. data/webpack/index.js +0 -13
  35. metadata +20 -20
  36. data/webpack/test_setup.js +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ee1b4acb26925c919a3d2b3c8b9efe6bd355dc603d896d642a0150d9364f86b
4
- data.tar.gz: b5fb045a0cfddf957c238f311b29f97a56b0b5fc91999b56ca25ee3f4c0eeda4
3
+ metadata.gz: d95899e15050cbf3f25d75a8f3c9bc5a3059a9dd0ffa90f4690ce84cf49d3408
4
+ data.tar.gz: 466754ac90d1e80046fca70ca8db372e90d2b61a0d26a726f0807f7e81227728
5
5
  SHA512:
6
- metadata.gz: 529107a643fb300fc1755a3efe8bbb1bb94b726c822c93f568e3001d2acc71658499343952bce1191ca2e142d1abc3548525a3fdfbde2c8fe1a2f645923b366c
7
- data.tar.gz: 2874526de96c18b4aafd6fcaa29006c1d910ccb0e87b1f3326d64312c510cc496fc4e49fd176fafb3f465bded12a2b9c26768dfc0833b628c1538659279cd6a6
6
+ metadata.gz: 9f79b560e9e01e8719c6e705ff5fef6a9f9e7b91bc9ec1b9b79c81750b572c4de6929d2ab07049caefdf4f555a5087c31eb76543d52b87622038107a1e02ea63
7
+ data.tar.gz: 357b61ffdb94b61a37ecf87afba07f7e0c2158d4af14d39b701fb31152803692a8feaac09294bb2bc8c0ae8fe8d9daa66eb8eb6f0869c4901315dca688f06dab
@@ -72,8 +72,8 @@ module Api
72
72
  process_resource_error(:resource => @ansible_inventory)
73
73
  end
74
74
  rescue StandardError => e
75
- render_error 'standard_error', :status => :internal_error,
76
- :locals => { :exception => e }
75
+ render_error :custom_error, :status => :unprocessable_entity,
76
+ :locals => { :message => _("Scheduling Report template failed for: #{e.message}") }
77
77
  end
78
78
 
79
79
  def action_permission
@@ -42,10 +42,7 @@ module ForemanAnsible
42
42
  end
43
43
 
44
44
  def report_json_viewer(json)
45
- uid = "reportjson-viewer-#{json.object_id}"
46
- viewer = content_tag :div, '', :id => uid
47
- viewer << mount_react_component('ReportJsonViewer',
48
- "##{uid}", json.to_json)
45
+ react_component('ReportJsonViewer', data: json)
49
46
  end
50
47
 
51
48
  private
@@ -68,7 +65,7 @@ module ForemanAnsible
68
65
  prettyp.gsub!(/^(\[|\])/, '')
69
66
  prettyp.gsub!(/^[\s]*$\n/, '')
70
67
  paragraph_style = 'white-space:pre;padding: 2em 0'
71
- content_tag(:p, prettyp, :style => paragraph_style)
68
+ tag(:p, prettyp, :style => paragraph_style)
72
69
  end
73
70
 
74
71
  def hash_with_keys_removed(hash)
@@ -68,9 +68,9 @@ end
68
68
  module Host
69
69
  class Managed
70
70
  apipie :class do
71
- property :all_ansible_roles, array_of: 'AnsibleRole', desc: 'Returns all ansible roles assigned to the host, both its own and inherited'
72
- property :ansible_roles, array_of: 'AnsibleRole', desc: 'Returns ansible roles assigned to the host'
73
- property :inherited_ansible_roles, array_of: 'AnsibleRole', desc: 'Returns inherited ansible roles assigned to the host'
71
+ property :all_ansible_roles, array_of: 'AnsibleRole', desc: 'Returns all ansible roles assigned to the host, both its own and inherited from the host group and its parents'
72
+ property :ansible_roles, array_of: 'AnsibleRole', desc: 'Returns ansible roles directly assigned to the host'
73
+ property :inherited_ansible_roles, array_of: 'AnsibleRole', desc: 'Returns only ansible roles assigned to the host\'s host group and its parents'
74
74
  end
75
75
  # Methods to be allowed in any template with safemode enabled
76
76
  class Jail < Safemode::Jail
@@ -36,3 +36,15 @@ module ForemanAnsible
36
36
  end
37
37
  end
38
38
  end
39
+
40
+ class Hostgroup
41
+ apipie :class do
42
+ property :all_ansible_roles, array_of: 'AnsibleRole', desc: 'Returns all ansible roles assigned to the host group, both its own and inherited from parent host groups'
43
+ property :ansible_roles, array_of: 'AnsibleRole', desc: 'Returns ansible roles directly assigned to the host group'
44
+ property :inherited_ansible_roles, array_of: 'AnsibleRole', desc: 'Returns only the inherited ansible roles assigned to the host group\'s parents'
45
+ end
46
+ # Methods to be allowed in any template with safemode enabled
47
+ class Jail < Safemode::Jail
48
+ allow :all_ansible_roles, :ansible_roles, :inherited_ansible_roles
49
+ end
50
+ end
@@ -35,7 +35,7 @@ if defined? ForemanRemoteExecution
35
35
  {
36
36
  'per-host' => {
37
37
  host.name => {
38
- 'ansible_ssh_pass' => rex_ssh_password(host),
38
+ 'ansible_password' => rex_ssh_password(host),
39
39
  'ansible_become_password' => rex_effective_user_password(host)
40
40
  }
41
41
  }
@@ -66,14 +66,6 @@ if defined? ForemanRemoteExecution
66
66
  'ForemanAnsibleCore::TaskLauncher::Playbook::PlaybookRunnerAction'
67
67
  end
68
68
 
69
- def required_proxy_selector_for(template)
70
- if template.remote_execution_features.where(:label => 'ansible_run_capsule_upgrade').any?
71
- ::DefaultProxyProxySelector.new
72
- else
73
- super
74
- end
75
- end
76
-
77
69
  private
78
70
 
79
71
  def ansible_command?(template)
@@ -80,8 +80,14 @@ module ForemanAnsible
80
80
  facts[:ansible_os_name].tr(" \n\t", '') ||
81
81
  facts[:ansible_distribution].tr(" \n\t", '')
82
82
  else
83
- facts[:ansible_distribution] ||
84
- facts[:ansible_lsb] && facts[:ansible_lsb]['id']
83
+ distribution = facts[:ansible_lsb].try(:[], 'id') || facts[:ansible_distribution]
84
+
85
+ if distribution == 'RedHat' &&
86
+ facts[:ansible_lsb].try(:[], 'id') == 'RedHatEnterpriseWorkstation'
87
+ distribution += '_Workstation'
88
+ end
89
+
90
+ distribution
85
91
  end
86
92
  end
87
93
 
@@ -51,7 +51,8 @@ module ForemanAnsible
51
51
  :key => variable_name,
52
52
  :ansible_role_id => role.id
53
53
  )
54
- variable.assign_attributes(:default_value => variable_default,
54
+ variable.assign_attributes(:hidden_value => false,
55
+ :default_value => variable_default,
55
56
  :key_type => infer_key_type(variable_default))
56
57
  variable.imported = true if variable.new_record?
57
58
  variable.valid? ? variable : nil
@@ -78,8 +79,10 @@ module ForemanAnsible
78
79
  def create_new_variables(variables)
79
80
  iterate_over_variables(variables) do |role, memo, attrs|
80
81
  variable = AnsibleVariable.new(
81
- JSON.parse(attrs)['ansible_variable']
82
+ JSON.parse(attrs)
82
83
  )
84
+ # Make sure, newly created variables are not hidden
85
+ variable.hidden_value = false
83
86
  variable.ansible_role = ::AnsibleRole.find_by(:name => role)
84
87
  variable.save
85
88
  memo << variable
@@ -88,7 +91,9 @@ module ForemanAnsible
88
91
 
89
92
  def update_variables(variables)
90
93
  iterate_over_variables(variables) do |_role, memo, attrs|
91
- attributes = JSON.parse(attrs)['ansible_variable']
94
+ attributes = JSON.parse(attrs)
95
+ # Make sure to let the flag if a variable is hidden untouched
96
+ attributes.delete('hidden_value')
92
97
  var = AnsibleVariable.find attributes['id']
93
98
  var.update(attributes)
94
99
  memo << var
@@ -98,7 +103,7 @@ module ForemanAnsible
98
103
  def delete_old_variables(variables)
99
104
  iterate_over_variables(variables) do |_role, memo, attrs|
100
105
  variable = AnsibleVariable.find(
101
- JSON.parse(attrs)['ansible_variable']['id']
106
+ JSON.parse(attrs)['id']
102
107
  )
103
108
  memo << variable.key
104
109
  variable.destroy
@@ -4,7 +4,7 @@
4
4
  <%= icon_text("play", "", :kind => "fa") %>
5
5
  </div>
6
6
  <h1><%= _('Ansible Roles') %></h1>
7
- <p><%= _('No ansible roles were found in Foreman. If you want to assign roles to your hosts,
7
+ <p><%= _('No Ansible Roles were found in Foreman. If you want to assign roles to your hosts,
8
8
  you have to import them first.').html_safe %>
9
9
  </p>
10
10
  <p><%= link_to(_('Learn more about this in the documentation.'), documentation_url('#4.1ImportingRoles', :root_url => ansible_doc_url), target: '_blank') %></p>
@@ -4,20 +4,12 @@
4
4
  <div class='tab-pane' id='ansible_roles'>
5
5
  <% roles = f.object.is_a?(Hostgroup) ? roles_attrs(f.object.inherited_and_own_ansible_roles) : roles_attrs(f.object.all_ansible_roles) %>
6
6
  <% class_name = f.object.is_a?(Hostgroup) ? 'Hostgroup' : 'Host' %>
7
- <%= content_tag(:div, '',
8
- :id => 'ansible_roles_switcher',
9
- 'data-roles' => {
10
- :initialAssignedRoles => roles,
11
- :inheritedRoleIds => f.object.inherited_ansible_roles.map(&:id),
12
- :availableRolesUrl => ui_ansible_roles_path,
13
- :resourceId => f.object.id,
14
- :resourceName => class_name,
15
- :canView => User.current.can?(:view_ansible_roles)
16
- }.to_json
17
- ) %>
18
- <% unless request.xhr? %>
19
- <script type="text/javascript">
20
- tfm.initAnsibleRoleSwitcher();
21
- </script>
22
- <% end %>
7
+ <%= react_component('AnsibleRolesSwitcher', {
8
+ :initialAssignedRoles => roles,
9
+ :inheritedRoleIds => f.object.inherited_ansible_roles.map(&:id),
10
+ :availableRolesUrl => ui_ansible_roles_path,
11
+ :resourceId => f.object.id,
12
+ :resourceName => class_name,
13
+ :canView => User.current.can?(:view_ansible_roles)
14
+ }) %>
23
15
  </div>
@@ -25,7 +25,7 @@ model: JobTemplate
25
25
  ---
26
26
  - hosts: all
27
27
  tasks:
28
- - command: ansible-galaxy install {{ item }} <% "-p #{input('location')}" if input('location').present? %>
28
+ - command: ansible-galaxy install {{ item }} -p <%= input('location').present? ? input('location') : '/etc/ansible/roles' %>
29
29
  register: out
30
30
  with_items:
31
31
  - <%= input('ansible_roles_list') %>
@@ -34,11 +34,10 @@ feature: ansible_run_capsule_upgrade
34
34
  msg: "This playbook cannot be executed on a Satellite server. Use only on a Capsule server."
35
35
  when: "'satellite' in ansible_facts.packages"
36
36
 
37
- - name: Install satellite-maintain if not present
37
+ - name: Install|Update satellite-maintain if not present
38
38
  package:
39
39
  name: rubygem-foreman_maintain
40
- state: present
41
- when: "'rubygem-foreman_maintain' not in ansible_facts.packages"
40
+ state: latest
42
41
 
43
42
  - block:
44
43
  <%- whitelist_option = if input('whitelist_options').present?
@@ -26,6 +26,7 @@ job_category: Maintenance Operations
26
26
  description_format: "%{template_name}"
27
27
  provider_type: Ansible
28
28
  kind: job_template
29
+ feature: ansible_configure_cloud_connector
29
30
  %>
30
31
 
31
32
  ---
@@ -0,0 +1,16 @@
1
+ <%#
2
+ name: Service Action - Enable Web Console
3
+ job_category: Ansible Services
4
+ snippet: false
5
+ provider_type: Ansible
6
+ kind: job_template
7
+ model: JobTemplate
8
+ feature: ansible_enable_web_console
9
+ %>
10
+ ---
11
+ - hosts: all
12
+ tasks:
13
+ - name: ensure cockpit is installed
14
+ package:
15
+ name: "cockpit-system"
16
+ state: present
@@ -45,7 +45,14 @@ module ForemanAnsible
45
45
  RemoteExecutionFeature.register(
46
46
  :ansible_run_capsule_upgrade,
47
47
  N_('Upgrade Capsules on given hosts'),
48
- :description => N_('Upgrade Capsules on given Capsule server hosts')
48
+ :description => N_('Upgrade Capsules on given Capsule server hosts'),
49
+ :proxy_selector_override => ::RemoteExecutionProxySelector::INTERNAL_PROXY
50
+ )
51
+ RemoteExecutionFeature.register(
52
+ :ansible_configure_cloud_connector,
53
+ N_('Configure Cloud Connector on given hosts'),
54
+ :description => N_('Configure Cloud Connector on given hosts'),
55
+ :proxy_selector_override => ::RemoteExecutionProxySelector::INTERNAL_PROXY
49
56
  )
50
57
  end
51
58
  end
@@ -4,5 +4,5 @@
4
4
  # This way other parts of Foreman can just call ForemanAnsible::VERSION
5
5
  # and detect what version the plugin is running.
6
6
  module ForemanAnsible
7
- VERSION = '6.0.0'
7
+ VERSION = '6.2.0'
8
8
  end
data/package.json CHANGED
@@ -7,33 +7,24 @@
7
7
  "test": "test"
8
8
  },
9
9
  "peerDependencies": {
10
- "@theforeman/vendor": ">= 3.3.2"
10
+ "@theforeman/vendor": ">= 6.0.0"
11
11
  },
12
12
  "dependencies": {
13
13
  "react-json-tree": "^0.11.0"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@babel/core": "^7.7.0",
17
- "@theforeman/builder": "^4.0.2",
18
- "@theforeman/vendor-dev": "^3.3.2",
19
- "babel-eslint": "^10.0.0",
20
- "babel-jest": "^24.9.0",
21
- "enzyme": "^3.7.0",
22
- "enzyme-adapter-react-16": "^1.7.0",
23
- "enzyme-to-json": "^3.3.5",
24
- "eslint": "^6.0.0",
25
- "eslint-plugin-patternfly-react": "^0.2.1",
26
- "identity-obj-proxy": "^3.0.0",
27
- "jest": "^24.9.0",
28
- "prettier": "^1.19.0",
29
- "react-redux": "^5.0.7",
30
- "react-redux-test-utils": "^0.1.1",
31
- "redux": "^3.7.2",
32
- "redux-thunk": "^2.3.0"
17
+ "@theforeman/builder": "^6.0.0",
18
+ "@theforeman/eslint-plugin-foreman": "6.0.0",
19
+ "@theforeman/test": "^6.0.0",
20
+ "@theforeman/vendor-dev": "^6.0.0",
21
+ "babel-eslint": "^10.0.3",
22
+ "eslint": "^6.7.2",
23
+ "prettier": "^1.13.5"
33
24
  },
34
25
  "scripts": {
35
- "test": "node node_modules/.bin/jest webpack",
36
- "lint": "eslint ./webpack"
26
+ "test": "tfm-test --plugin",
27
+ "lint": "tfm-lint --plugin -d webpack"
37
28
  },
38
29
  "repository": {
39
30
  "type": "git",
@@ -44,27 +35,5 @@
44
35
  "bugs": {
45
36
  "url": "https://projects.theforeman.org/projects/ansible"
46
37
  },
47
- "homepage": "https://theforeman.org/plugins/foreman_ansible/",
48
- "jest": {
49
- "verbose": true,
50
- "moduleDirectories": [
51
- "node_modules/@theforeman/vendor-core/node_modules",
52
- "node_modules",
53
- "webpack"
54
- ],
55
- "transform": {
56
- "^.+\\.js$": "babel-jest"
57
- },
58
- "setupFiles": [
59
- "raf/polyfill",
60
- "./webpack/test_setup.js"
61
- ],
62
- "testPathIgnorePatterns": [
63
- "/node_modules/",
64
- "<rootDir>/foreman/"
65
- ],
66
- "moduleNameMapper": {
67
- "^.+\\.(css|scss)$": "identity-obj-proxy"
68
- }
69
- }
38
+ "homepage": "https://theforeman.org/plugins/foreman_ansible/"
70
39
  }
@@ -40,7 +40,7 @@ class AnsibleProviderTest < ActiveSupport::TestCase
40
40
  host.expects(:params).twice.returns(params)
41
41
  secrets = ForemanAnsible::AnsibleProvider.secrets(host)
42
42
  host_secrets = secrets['per-host'][host.name]
43
- assert_equal host_secrets['ansible_ssh_pass'], 'password'
43
+ assert_equal host_secrets['ansible_password'], 'password'
44
44
  assert_equal host_secrets['ansible_become_password'], 'letmein'
45
45
  end
46
46
  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)
@@ -69,7 +69,7 @@ module ForemanAnsible
69
69
  connection_params['ansible_winrm_server_cert_validation']
70
70
  assert_equal Setting['remote_execution_effective_user_method'],
71
71
  connection_params['ansible_become_method']
72
- refute connection_params.key?('ansible_ssh_pass')
72
+ refute connection_params.key?('ansible_password')
73
73
  refute connection_params.key?('ansible_become_password')
74
74
  end
75
75
 
@@ -17,7 +17,7 @@ class AnsibleRolesSwitcher extends React.Component {
17
17
  inheritedRoleIds,
18
18
  resourceId,
19
19
  resourceName,
20
- } = this.props.data;
20
+ } = this.props;
21
21
 
22
22
  this.props.getAnsibleRoles(
23
23
  availableRolesUrl,
@@ -52,7 +52,7 @@ class AnsibleRolesSwitcher extends React.Component {
52
52
  inheritedRoleIds,
53
53
  resourceId,
54
54
  resourceName,
55
- } = this.props.data;
55
+ } = this.props;
56
56
 
57
57
  const onListingChange = paginationArgs =>
58
58
  getAnsibleRoles(
@@ -104,13 +104,11 @@ class AnsibleRolesSwitcher extends React.Component {
104
104
  }
105
105
 
106
106
  AnsibleRolesSwitcher.propTypes = {
107
- data: PropTypes.shape({
108
- initialAssignedRoles: PropTypes.arrayOf(PropTypes.object),
109
- availableRolesUrl: PropTypes.string,
110
- inheritedRoleIds: PropTypes.arrayOf(PropTypes.number),
111
- resourceId: PropTypes.number,
112
- resourceName: PropTypes.string,
113
- }).isRequired,
107
+ initialAssignedRoles: PropTypes.arrayOf(PropTypes.object),
108
+ availableRolesUrl: PropTypes.string.isRequired,
109
+ inheritedRoleIds: PropTypes.arrayOf(PropTypes.number),
110
+ resourceId: PropTypes.number,
111
+ resourceName: PropTypes.string,
114
112
  getAnsibleRoles: PropTypes.func.isRequired,
115
113
  loading: PropTypes.bool.isRequired,
116
114
  pagination: PropTypes.shape({
@@ -137,6 +135,10 @@ AnsibleRolesSwitcher.propTypes = {
137
135
 
138
136
  AnsibleRolesSwitcher.defaultProps = {
139
137
  error: {},
138
+ resourceId: null,
139
+ resourceName: '',
140
+ initialAssignedRoles: [],
141
+ inheritedRoleIds: [],
140
142
  };
141
143
 
142
144
  export default AnsibleRolesSwitcher;
@@ -21,7 +21,7 @@ export const getAnsibleRoles = (
21
21
  resourceName,
22
22
  pagination,
23
23
  search
24
- ) => dispatch => {
24
+ ) => async dispatch => {
25
25
  dispatch({ type: ANSIBLE_ROLES_REQUEST });
26
26
 
27
27
  const params = {
@@ -30,19 +30,19 @@ export const getAnsibleRoles = (
30
30
  ...propsToSnakeCase({ resourceId, resourceName }),
31
31
  };
32
32
 
33
- return api
34
- .get(url, {}, params)
35
- .then(({ data }) =>
36
- dispatch({
37
- type: ANSIBLE_ROLES_SUCCESS,
38
- payload: {
39
- initialAssignedRoles,
40
- inheritedRoleIds,
41
- ...propsToCamelCase(data),
42
- },
43
- })
44
- )
45
- .catch(error => dispatch(errorHandler(ANSIBLE_ROLES_FAILURE, error)));
33
+ try {
34
+ const res = await api.get(url, {}, params);
35
+ return dispatch({
36
+ type: ANSIBLE_ROLES_SUCCESS,
37
+ payload: {
38
+ initialAssignedRoles,
39
+ inheritedRoleIds,
40
+ ...propsToCamelCase(res.data),
41
+ },
42
+ });
43
+ } catch (error) {
44
+ return dispatch(errorHandler(ANSIBLE_ROLES_FAILURE, error));
45
+ }
46
46
  };
47
47
 
48
48
  const errorHandler = (msg, err) => {
@@ -1,4 +1,4 @@
1
- import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
2
 
3
3
  import AnsibleRolesSwitcher from '../AnsibleRolesSwitcher';
4
4
 
@@ -19,10 +19,10 @@ const fixtures = {
19
19
  assignedRolesCount: 2,
20
20
  assignedRoles: [],
21
21
  unassignedRoles: [],
22
- data: {
23
- initialAssignedRoles: [],
24
- },
22
+ initialAssignedRoles: [],
25
23
  error: { statusText: '', errorMsg: '' },
24
+ allAssignedRoles: [],
25
+ availableRolesUrl: 'http://test/roles',
26
26
  },
27
27
  };
28
28
 
@@ -1,4 +1,4 @@
1
- import { testReducerSnapshotWithFixtures } from 'react-redux-test-utils';
1
+ import { testReducerSnapshotWithFixtures } from '@theforeman/test';
2
2
 
3
3
  import reducer, { initialState } from '../AnsibleRolesSwitcherReducer';
4
4
  import { ansibleRolesLong } from '../__fixtures__/ansibleRolesData.fixtures';
@@ -1,4 +1,4 @@
1
- import { testSelectorsSnapshotWithFixtures } from 'react-redux-test-utils';
1
+ import { testSelectorsSnapshotWithFixtures } from '@theforeman/test';
2
2
 
3
3
  import {
4
4
  selectUnassignedRoles,
@@ -61,6 +61,7 @@ exports[`AnsibleRolesSwitcher should render 1`] = `
61
61
  </h2>
62
62
  </div>
63
63
  <AssignedRolesList
64
+ allAssignedRoles={Array []}
64
65
  assignedRoles={Array []}
65
66
  itemCount={2}
66
67
  onPaginationChange={[Function]}
@@ -1,4 +1,4 @@
1
- import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
2
  import AnsiblePermissionDenied from './AnsiblePermissionDenied';
3
3
 
4
4
  jest.mock('foremanReact/components/common/EmptyState');
@@ -1,4 +1,4 @@
1
- import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
2
 
3
3
  import AnsibleRole from './AnsibleRole';
4
4
 
@@ -1,4 +1,4 @@
1
- import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
2
 
3
3
  import AssignedRolesList from './AssignedRolesList';
4
4
 
@@ -1,4 +1,4 @@
1
- import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
2
 
3
3
  import AvailableRolesList from './AvailableRolesList';
4
4
 
@@ -37,5 +37,5 @@ const mapDispatchToProps = dispatch =>
37
37
  export default withProtectedView(
38
38
  connect(mapStateToProps, mapDispatchToProps)(AnsibleRolesSwitcher),
39
39
  AnsiblePermissionDenied,
40
- props => props.data && props.data.canView
40
+ props => props.canView
41
41
  );
data/webpack/index.js CHANGED
@@ -1,12 +1,9 @@
1
- import $ from 'jquery';
2
1
  import componentRegistry from 'foremanReact/components/componentRegistry';
3
2
  import injectReducer from 'foremanReact/redux/reducers/registerReducer';
4
3
  import ReportJsonViewer from './components/ReportJsonViewer';
5
4
  import AnsibleRolesSwitcher from './components/AnsibleRolesSwitcher';
6
5
  import reducer from './reducer';
7
6
 
8
- const { tfm } = window;
9
-
10
7
  componentRegistry.register({
11
8
  name: 'ReportJsonViewer',
12
9
  type: ReportJsonViewer,
@@ -17,13 +14,3 @@ componentRegistry.register({
17
14
  });
18
15
 
19
16
  injectReducer('foremanAnsible', reducer);
20
-
21
- tfm.initAnsibleRoleSwitcher = () => {
22
- $(document).on('ContentLoad', evt => {
23
- tfm.reactMounter.mount(
24
- 'AnsibleRolesSwitcher',
25
- '#ansible_roles_switcher',
26
- $('#ansible_roles_switcher').data('roles')
27
- );
28
- });
29
- };
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_ansible
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Lobato Garcia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-01 00:00:00.000000000 Z
11
+ date: 2021-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: foreman_ansible_core
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 4.0.0
47
+ version: 4.2.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 4.0.0
54
+ version: 4.2.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: ipaddress
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -182,6 +182,7 @@ files:
182
182
  - app/views/foreman_ansible/job_templates/run_command_-_ansible_default.erb
183
183
  - app/views/foreman_ansible/job_templates/run_playbook-ansible_default.erb
184
184
  - app/views/foreman_ansible/job_templates/service_action_-_ansible_default.erb
185
+ - app/views/foreman_ansible/job_templates/service_action_-_enable_web_console.erb
185
186
  - app/views/ui_ansible_roles/index.json.rabl
186
187
  - app/views/ui_ansible_roles/main.json.rabl
187
188
  - app/views/ui_ansible_roles/show.json.rabl
@@ -327,7 +328,6 @@ files:
327
328
  - webpack/components/ReportJsonViewer.js
328
329
  - webpack/index.js
329
330
  - webpack/reducer.js
330
- - webpack/test_setup.js
331
331
  homepage: https://github.com/theforeman/foreman_ansible
332
332
  licenses:
333
333
  - GPL-3.0
@@ -347,28 +347,31 @@ required_rubygems_version: !ruby/object:Gem::Requirement
347
347
  - !ruby/object:Gem::Version
348
348
  version: '0'
349
349
  requirements: []
350
- rubygems_version: 3.0.3
350
+ rubygems_version: 3.1.2
351
351
  signing_key:
352
352
  specification_version: 4
353
353
  summary: Ansible integration with Foreman (theforeman.org)
354
354
  test_files:
355
355
  - test/factories/ansible_proxy.rb
356
- - test/factories/ansible_roles.rb
357
356
  - test/factories/ansible_variables.rb
357
+ - test/factories/ansible_roles.rb
358
358
  - test/fixtures/insights_playbook.yaml
359
- - test/fixtures/sample_facts.json
360
359
  - test/fixtures/report.json
360
+ - test/fixtures/sample_facts.json
361
+ - test/functional/ansible_roles_controller_test.rb
362
+ - test/functional/api/v2/ansible_inventories_controller_test.rb
361
363
  - test/functional/api/v2/ansible_roles_controller_test.rb
364
+ - test/functional/api/v2/ansible_variables_controller_test.rb
362
365
  - test/functional/api/v2/hostgroups_controller_test.rb
363
366
  - test/functional/api/v2/hosts_controller_test.rb
364
- - test/functional/api/v2/ansible_inventories_controller_test.rb
365
- - test/functional/api/v2/ansible_variables_controller_test.rb
366
- - test/functional/ansible_roles_controller_test.rb
367
- - test/functional/ansible_variables_controller_test.rb
368
367
  - test/functional/ui_ansible_roles_controller_test.rb
368
+ - test/functional/ansible_variables_controller_test.rb
369
369
  - test/functional/hosts_controller_test.rb
370
+ - test/test_plugin_helper.rb
370
371
  - test/unit/actions/run_ansible_job_test.rb
371
372
  - test/unit/actions/run_proxy_ansible_command_test.rb
373
+ - test/unit/ansible_role_test.rb
374
+ - test/unit/ansible_variable_test.rb
372
375
  - test/unit/concerns/config_reports_extensions_test.rb
373
376
  - test/unit/concerns/host_managed_extensions_test.rb
374
377
  - test/unit/concerns/hostgroup_extensions_test.rb
@@ -377,20 +380,17 @@ test_files:
377
380
  - test/unit/lib/foreman_ansible_core/ansible_runner_test.rb
378
381
  - test/unit/lib/foreman_ansible_core/playbook_runner_test.rb
379
382
  - test/unit/lib/proxy_api/ansible_test.rb
383
+ - test/unit/services/ansible_report_importer_test.rb
380
384
  - test/unit/services/api_roles_importer_test.rb
385
+ - test/unit/services/fact_importer_test.rb
386
+ - test/unit/services/fact_parser_test.rb
381
387
  - test/unit/services/fact_sparser_test.rb
382
388
  - test/unit/services/insights_plan_runner_test.rb
383
389
  - test/unit/services/roles_importer_test.rb
384
390
  - test/unit/services/structured_fact_importer_test.rb
385
- - test/unit/services/ui_roles_importer_test.rb
386
- - test/unit/services/ansible_report_importer_test.rb
387
- - test/unit/services/fact_importer_test.rb
388
- - test/unit/services/fact_parser_test.rb
389
391
  - test/unit/services/ansible_variables_importer_test.rb
390
392
  - test/unit/services/inventory_creator_test.rb
391
- - test/unit/ansible_role_test.rb
393
+ - test/unit/services/ui_roles_importer_test.rb
394
+ - test/unit/ansible_provider_test.rb
392
395
  - test/unit/host_ansible_role_test.rb
393
396
  - test/unit/hostgroup_ansible_role_test.rb
394
- - test/unit/ansible_variable_test.rb
395
- - test/unit/ansible_provider_test.rb
396
- - test/test_plugin_helper.rb
@@ -1,12 +0,0 @@
1
- import 'core-js/shim';
2
- import 'regenerator-runtime/runtime';
3
-
4
- import { configure } from 'enzyme';
5
- import Adapter from 'enzyme-adapter-react-16';
6
-
7
- configure({ adapter: new Adapter() });
8
-
9
- // Mocking translation function
10
- global.__ = str => str;
11
- global.n__ = str => str;
12
- global.Jed = { sprintf: str => str };