foreman_ansible 4.0.3.5 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v2/ansible_inventories_controller.rb +9 -4
  3. data/app/controllers/api/v2/ansible_roles_controller.rb +2 -2
  4. data/app/controllers/api/v2/ansible_variables_controller.rb +1 -2
  5. data/app/controllers/foreman_ansible/api/v2/hostgroups_controller_extensions.rb +2 -2
  6. data/app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb +2 -2
  7. data/app/models/concerns/foreman_ansible/host_managed_extensions.rb +0 -4
  8. data/app/models/foreman_ansible/ansible_provider.rb +8 -0
  9. data/app/models/setting/ansible.rb +1 -5
  10. data/app/services/foreman_ansible/ansible_info.rb +1 -1
  11. data/app/services/foreman_ansible/insights_notification_builder.rb +0 -2
  12. data/app/services/foreman_ansible/operating_system_parser.rb +1 -5
  13. data/app/services/foreman_ansible/variables_importer.rb +9 -9
  14. data/app/views/ansible_variables/_fields.erb +1 -1
  15. data/app/views/foreman_ansible/job_templates/capsule_upgrade_-_ansible_default.erb +71 -0
  16. data/config/routes.rb +1 -3
  17. data/db/migrate/20160802153302_create_join_table_hostgroup_ansible_roles.rb +0 -2
  18. data/db/migrate/20200421201839_update_ansible_inv_template_name.rb +9 -0
  19. data/db/seeds.d/75_job_templates.rb +1 -1
  20. data/lib/foreman_ansible/engine.rb +22 -27
  21. data/lib/foreman_ansible/register.rb +1 -3
  22. data/lib/foreman_ansible/remote_execution.rb +11 -0
  23. data/lib/foreman_ansible/version.rb +1 -1
  24. data/locale/action_names.rb +3 -3
  25. data/locale/ca/LC_MESSAGES/foreman_ansible.mo +0 -0
  26. data/locale/ca/foreman_ansible.po +556 -0
  27. data/locale/cs_CZ/LC_MESSAGES/foreman_ansible.mo +0 -0
  28. data/locale/cs_CZ/foreman_ansible.po +556 -0
  29. data/locale/de/LC_MESSAGES/foreman_ansible.mo +0 -0
  30. data/locale/de/foreman_ansible.po +38 -33
  31. data/locale/en/LC_MESSAGES/foreman_ansible.mo +0 -0
  32. data/locale/en/foreman_ansible.po +38 -33
  33. data/locale/en_GB/LC_MESSAGES/foreman_ansible.mo +0 -0
  34. data/locale/en_GB/foreman_ansible.po +555 -0
  35. data/locale/es/LC_MESSAGES/foreman_ansible.mo +0 -0
  36. data/locale/es/foreman_ansible.po +38 -33
  37. data/locale/foreman_ansible.pot +96 -88
  38. data/locale/fr/LC_MESSAGES/foreman_ansible.mo +0 -0
  39. data/locale/fr/foreman_ansible.po +38 -33
  40. data/locale/gl/LC_MESSAGES/foreman_ansible.mo +0 -0
  41. data/locale/gl/foreman_ansible.po +553 -0
  42. data/locale/it/LC_MESSAGES/foreman_ansible.mo +0 -0
  43. data/locale/it/foreman_ansible.po +38 -33
  44. data/locale/ja/LC_MESSAGES/foreman_ansible.mo +0 -0
  45. data/locale/ja/foreman_ansible.po +38 -33
  46. data/locale/ko/LC_MESSAGES/foreman_ansible.mo +0 -0
  47. data/locale/ko/foreman_ansible.po +38 -33
  48. data/locale/nl_NL/LC_MESSAGES/foreman_ansible.mo +0 -0
  49. data/locale/nl_NL/foreman_ansible.po +559 -0
  50. data/locale/pl/LC_MESSAGES/foreman_ansible.mo +0 -0
  51. data/locale/pl/foreman_ansible.po +556 -0
  52. data/locale/pt_BR/LC_MESSAGES/foreman_ansible.mo +0 -0
  53. data/locale/pt_BR/foreman_ansible.po +38 -33
  54. data/locale/ru/LC_MESSAGES/foreman_ansible.mo +0 -0
  55. data/locale/ru/foreman_ansible.po +38 -33
  56. data/locale/sv_SE/LC_MESSAGES/foreman_ansible.mo +0 -0
  57. data/locale/sv_SE/foreman_ansible.po +556 -0
  58. data/locale/zh_CN/LC_MESSAGES/foreman_ansible.mo +0 -0
  59. data/locale/zh_CN/foreman_ansible.po +38 -33
  60. data/locale/zh_TW/LC_MESSAGES/foreman_ansible.mo +0 -0
  61. data/locale/zh_TW/foreman_ansible.po +38 -33
  62. data/package.json +14 -16
  63. data/test/factories/ansible_variables.rb +5 -0
  64. data/test/functional/api/v2/ansible_inventories_controller_test.rb +3 -3
  65. data/test/functional/api/v2/ansible_variables_controller_test.rb +12 -0
  66. data/test/unit/services/ansible_variables_importer_test.rb +68 -43
  67. data/test/unit/services/inventory_creator_test.rb +0 -4
  68. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.js +1 -0
  69. data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.js +5 -1
  70. data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.test.js +8 -1
  71. data/webpack/components/AnsibleRolesSwitcher/index.js +1 -4
  72. data/webpack/test_setup.js +2 -1
  73. metadata +54 -80
  74. data/locale/de/foreman_ansible.edit.po +0 -825
  75. data/locale/de/foreman_ansible.po.time_stamp +0 -0
  76. data/locale/en/foreman_ansible.edit.po +0 -714
  77. data/locale/en/foreman_ansible.po.time_stamp +0 -0
  78. data/locale/es/foreman_ansible.edit.po +0 -845
  79. data/locale/es/foreman_ansible.po.time_stamp +0 -0
  80. data/locale/fr/foreman_ansible.edit.po +0 -847
  81. data/locale/fr/foreman_ansible.po.time_stamp +0 -0
  82. data/locale/it/foreman_ansible.edit.po +0 -818
  83. data/locale/it/foreman_ansible.po.time_stamp +0 -0
  84. data/locale/ja/foreman_ansible.edit.po +0 -818
  85. data/locale/ja/foreman_ansible.po.time_stamp +0 -0
  86. data/locale/ko/foreman_ansible.edit.po +0 -804
  87. data/locale/ko/foreman_ansible.po.time_stamp +0 -0
  88. data/locale/pt_BR/foreman_ansible.edit.po +0 -845
  89. data/locale/pt_BR/foreman_ansible.po.time_stamp +0 -0
  90. data/locale/ru/foreman_ansible.edit.po +0 -819
  91. data/locale/ru/foreman_ansible.po.time_stamp +0 -0
  92. data/locale/zh_CN/foreman_ansible.edit.po +0 -813
  93. data/locale/zh_CN/foreman_ansible.po.time_stamp +0 -0
  94. data/locale/zh_TW/foreman_ansible.edit.po +0 -804
  95. data/locale/zh_TW/foreman_ansible.po.time_stamp +0 -0
@@ -5,7 +5,7 @@
5
5
  #
6
6
  msgid ""
7
7
  msgstr ""
8
- "Project-Id-Version: foreman_ansible 3.0.1\n"
8
+ "Project-Id-Version: foreman_ansible 5.0.1\n"
9
9
  "Report-Msgid-Bugs-To: \n"
10
10
  "PO-Revision-Date: 2018-03-12 12:24-0400\n"
11
11
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
@@ -131,6 +131,9 @@ msgstr ""
131
131
  msgid "Create an override value for a specific ansible variable"
132
132
  msgstr ""
133
133
 
134
+ msgid "Default Ansible inventory report template"
135
+ msgstr ""
136
+
134
137
  msgid "Default Behavior"
135
138
  msgstr ""
136
139
 
@@ -179,10 +182,13 @@ msgstr ""
179
182
  msgid "Foreman"
180
183
  msgstr ""
181
184
 
182
- msgid "Foreman will add the this level of verbosity for additional debugging output when running Ansible playbooks."
185
+ msgid "Foreman will add this level of verbosity for additional debugging output when running Ansible playbooks."
186
+ msgstr ""
187
+
188
+ msgid "Foreman will use this template to schedule the report with Ansible inventory"
183
189
  msgstr ""
184
190
 
185
- msgid "Foreman will run Ansible playbooks using this implementation"
191
+ msgid "Hash of input values of type input=>value"
186
192
  msgstr ""
187
193
 
188
194
  msgid "Hidden Value"
@@ -224,9 +230,6 @@ msgstr ""
224
230
  msgid "If checked, will raise an error if there is no default value and no matcher provide a value."
225
231
  msgstr ""
226
232
 
227
- msgid "Implementation for running Ansible"
228
- msgstr ""
229
-
230
233
  msgid "Import"
231
234
  msgstr ""
232
235
 
@@ -248,13 +251,6 @@ msgstr ""
248
251
  msgid "Import of roles successfully finished."
249
252
  msgstr ""
250
253
 
251
- msgid ""
252
- "Import of variables successfully finished.\n"
253
- "Added: #{results[:added].count} \n"
254
- " Removed: #{results[:obsolete].count} \n"
255
- "Updated: #{results[:updated].count}"
256
- msgstr ""
257
-
258
254
  msgid "Imported at"
259
255
  msgstr ""
260
256
 
@@ -383,69 +379,78 @@ msgstr ""
383
379
  msgid "Overriden"
384
380
  msgstr ""
385
381
 
386
- msgid "Play Ansible roles"
382
+ msgid "Post-provision timeout"
387
383
  msgstr ""
388
384
 
389
- msgid "Play Roles"
385
+ msgid "Prioritize Attribute Order"
390
386
  msgstr ""
391
387
 
392
- msgid "Playbook execution failed"
388
+ msgid "Private Key Path"
393
389
  msgstr ""
394
390
 
395
- msgid "Plays Ansible roles on a host"
391
+ msgid "Proxy not found"
396
392
  msgstr ""
397
393
 
398
- msgid "Plays Ansible roles on a hostgroup"
394
+ msgid "Remediation Plan"
399
395
  msgstr ""
400
396
 
401
- msgid "Plays Ansible roles on hostgroups"
397
+ msgid "Remote action:"
402
398
  msgstr ""
403
399
 
404
- msgid "Plays Ansible roles on hosts"
400
+ msgid "Remove"
405
401
  msgstr ""
406
402
 
407
- msgid "Post-provision timeout"
403
+ msgid "Remove duplicate values (only array type)"
408
404
  msgstr ""
409
405
 
410
- msgid "Prioritize Attribute Order"
406
+ msgid "Report format, defaults to '%s'"
411
407
  msgstr ""
412
408
 
413
- msgid "Private Key Path"
409
+ msgid "Role ID"
414
410
  msgstr ""
415
411
 
416
- msgid "Proxy not found"
412
+ msgid "Roles"
417
413
  msgstr ""
418
414
 
419
- msgid "Remediation Plan"
415
+ msgid "Role|Name"
420
416
  msgstr ""
421
417
 
422
- msgid "Remote action:"
418
+ msgid "Run Ansible roles"
423
419
  msgstr ""
424
420
 
425
- msgid "Remove"
421
+ msgid "Run all Ansible roles"
426
422
  msgstr ""
427
423
 
428
- msgid "Remove duplicate values (only array type)"
424
+ msgid "Run all Ansible roles on hosts belonging to this host group"
429
425
  msgstr ""
430
426
 
431
- msgid "Role ID"
427
+ msgid "Run an Ansible playbook against given hosts"
432
428
  msgstr ""
433
429
 
434
- msgid "Roles"
430
+ msgid "Run playbook"
435
431
  msgstr ""
436
432
 
437
- msgid "Role|Name"
433
+ msgid "Runs a given maintenance plan from Red Hat Access Insights given an ID."
438
434
  msgstr ""
439
435
 
440
- msgid "Run Ansible roles"
436
+ msgid "Runs all Ansible roles on a host"
441
437
  msgstr ""
442
438
 
443
- msgid "Runs a given maintenance plan from Red Hat Access Insights given an ID."
439
+ msgid "Runs all Ansible roles on a hostgroup"
440
+ msgstr ""
441
+
442
+ msgid "Runs all Ansible roles on hostgroups"
443
+ msgstr ""
444
+
445
+ msgid "Runs all Ansible roles on hosts"
444
446
  msgstr ""
445
447
 
446
448
  msgid "Runs an Ansible playbook which contains all the roles defined for a host"
447
449
  msgstr ""
448
450
 
451
+ msgid "Schedule generating of Ansible Inventory report"
452
+ msgstr ""
453
+
449
454
  msgid "Select the changes you want to realize in Foreman"
450
455
  msgstr ""
451
456
 
@@ -5,7 +5,7 @@
5
5
  #
6
6
  msgid ""
7
7
  msgstr ""
8
- "Project-Id-Version: foreman_ansible 3.0.1\n"
8
+ "Project-Id-Version: foreman_ansible 5.0.1\n"
9
9
  "Report-Msgid-Bugs-To: \n"
10
10
  "PO-Revision-Date: 2018-03-12 12:24-0400\n"
11
11
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
@@ -131,6 +131,9 @@ msgstr ""
131
131
  msgid "Create an override value for a specific ansible variable"
132
132
  msgstr ""
133
133
 
134
+ msgid "Default Ansible inventory report template"
135
+ msgstr ""
136
+
134
137
  msgid "Default Behavior"
135
138
  msgstr ""
136
139
 
@@ -179,10 +182,13 @@ msgstr ""
179
182
  msgid "Foreman"
180
183
  msgstr ""
181
184
 
182
- msgid "Foreman will add the this level of verbosity for additional debugging output when running Ansible playbooks."
185
+ msgid "Foreman will add this level of verbosity for additional debugging output when running Ansible playbooks."
186
+ msgstr ""
187
+
188
+ msgid "Foreman will use this template to schedule the report with Ansible inventory"
183
189
  msgstr ""
184
190
 
185
- msgid "Foreman will run Ansible playbooks using this implementation"
191
+ msgid "Hash of input values of type input=>value"
186
192
  msgstr ""
187
193
 
188
194
  msgid "Hidden Value"
@@ -224,9 +230,6 @@ msgstr ""
224
230
  msgid "If checked, will raise an error if there is no default value and no matcher provide a value."
225
231
  msgstr ""
226
232
 
227
- msgid "Implementation for running Ansible"
228
- msgstr ""
229
-
230
233
  msgid "Import"
231
234
  msgstr ""
232
235
 
@@ -248,13 +251,6 @@ msgstr ""
248
251
  msgid "Import of roles successfully finished."
249
252
  msgstr ""
250
253
 
251
- msgid ""
252
- "Import of variables successfully finished.\n"
253
- "Added: #{results[:added].count} \n"
254
- " Removed: #{results[:obsolete].count} \n"
255
- "Updated: #{results[:updated].count}"
256
- msgstr ""
257
-
258
254
  msgid "Imported at"
259
255
  msgstr ""
260
256
 
@@ -383,69 +379,78 @@ msgstr ""
383
379
  msgid "Overriden"
384
380
  msgstr ""
385
381
 
386
- msgid "Play Ansible roles"
382
+ msgid "Post-provision timeout"
387
383
  msgstr ""
388
384
 
389
- msgid "Play Roles"
385
+ msgid "Prioritize Attribute Order"
390
386
  msgstr ""
391
387
 
392
- msgid "Playbook execution failed"
388
+ msgid "Private Key Path"
393
389
  msgstr ""
394
390
 
395
- msgid "Plays Ansible roles on a host"
391
+ msgid "Proxy not found"
396
392
  msgstr ""
397
393
 
398
- msgid "Plays Ansible roles on a hostgroup"
394
+ msgid "Remediation Plan"
399
395
  msgstr ""
400
396
 
401
- msgid "Plays Ansible roles on hostgroups"
397
+ msgid "Remote action:"
402
398
  msgstr ""
403
399
 
404
- msgid "Plays Ansible roles on hosts"
400
+ msgid "Remove"
405
401
  msgstr ""
406
402
 
407
- msgid "Post-provision timeout"
403
+ msgid "Remove duplicate values (only array type)"
408
404
  msgstr ""
409
405
 
410
- msgid "Prioritize Attribute Order"
406
+ msgid "Report format, defaults to '%s'"
411
407
  msgstr ""
412
408
 
413
- msgid "Private Key Path"
409
+ msgid "Role ID"
414
410
  msgstr ""
415
411
 
416
- msgid "Proxy not found"
412
+ msgid "Roles"
417
413
  msgstr ""
418
414
 
419
- msgid "Remediation Plan"
415
+ msgid "Role|Name"
420
416
  msgstr ""
421
417
 
422
- msgid "Remote action:"
418
+ msgid "Run Ansible roles"
423
419
  msgstr ""
424
420
 
425
- msgid "Remove"
421
+ msgid "Run all Ansible roles"
426
422
  msgstr ""
427
423
 
428
- msgid "Remove duplicate values (only array type)"
424
+ msgid "Run all Ansible roles on hosts belonging to this host group"
429
425
  msgstr ""
430
426
 
431
- msgid "Role ID"
427
+ msgid "Run an Ansible playbook against given hosts"
432
428
  msgstr ""
433
429
 
434
- msgid "Roles"
430
+ msgid "Run playbook"
435
431
  msgstr ""
436
432
 
437
- msgid "Role|Name"
433
+ msgid "Runs a given maintenance plan from Red Hat Access Insights given an ID."
438
434
  msgstr ""
439
435
 
440
- msgid "Run Ansible roles"
436
+ msgid "Runs all Ansible roles on a host"
441
437
  msgstr ""
442
438
 
443
- msgid "Runs a given maintenance plan from Red Hat Access Insights given an ID."
439
+ msgid "Runs all Ansible roles on a hostgroup"
440
+ msgstr ""
441
+
442
+ msgid "Runs all Ansible roles on hostgroups"
443
+ msgstr ""
444
+
445
+ msgid "Runs all Ansible roles on hosts"
444
446
  msgstr ""
445
447
 
446
448
  msgid "Runs an Ansible playbook which contains all the roles defined for a host"
447
449
  msgstr ""
448
450
 
451
+ msgid "Schedule generating of Ansible Inventory report"
452
+ msgstr ""
453
+
449
454
  msgid "Select the changes you want to realize in Foreman"
450
455
  msgstr ""
451
456
 
@@ -6,31 +6,26 @@
6
6
  "directories": {
7
7
  "test": "test"
8
8
  },
9
+ "peerDependencies": {
10
+ "@theforeman/vendor": ">= 3.3.2"
11
+ },
9
12
  "dependencies": {
10
- "@theforeman/vendor": "^1.7.0",
11
13
  "react-json-tree": "^0.11.0"
12
14
  },
13
15
  "devDependencies": {
14
- "@theforeman/vendor-dev": "^1.7.0",
15
- "babel-eslint": "^8.2.1",
16
- "babel-plugin-transform-class-properties": "^6.24.1",
17
- "babel-plugin-transform-object-assign": "^6.22.0",
18
- "babel-plugin-transform-object-rest-spread": "^6.26.0",
19
- "babel-preset-env": "^1.6.0",
20
- "babel-preset-react": "^6.24.1",
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
21
  "enzyme": "^3.7.0",
22
22
  "enzyme-adapter-react-16": "^1.7.0",
23
23
  "enzyme-to-json": "^3.3.5",
24
- "eslint": "^4.18.1",
25
- "eslint-config-airbnb": "^16.0.0",
26
- "eslint-plugin-import": "^2.8.0",
27
- "eslint-plugin-jest": "^21.2.0",
28
- "eslint-plugin-jsx-a11y": "^6.0.2",
24
+ "eslint": "^6.0.0",
29
25
  "eslint-plugin-patternfly-react": "^0.2.1",
30
- "eslint-plugin-react": "^7.4.0",
31
26
  "identity-obj-proxy": "^3.0.0",
32
- "jest": "^23.6.0",
33
- "prettier": "^1.16.4",
27
+ "jest": "^24.9.0",
28
+ "prettier": "^1.19.0",
34
29
  "react-redux": "^5.0.7",
35
30
  "react-redux-test-utils": "^0.1.1",
36
31
  "redux": "^3.7.2",
@@ -57,6 +52,9 @@
57
52
  "node_modules",
58
53
  "webpack"
59
54
  ],
55
+ "transform": {
56
+ "^.+\\.js$": "babel-jest"
57
+ },
60
58
  "setupFiles": [
61
59
  "raf/polyfill",
62
60
  "./webpack/test_setup.js"
@@ -6,5 +6,10 @@ FactoryBot.define do
6
6
  sequence(:default_value) { |n| "default_value_#{n}" }
7
7
  ansible_role
8
8
  imported { true }
9
+ override { false }
10
+
11
+ after(:build) do |variable|
12
+ variable.key_type ||= ForemanAnsible::VariablesImporter::VARIABLE_TYPES[variable.default_value.class.to_s] || 'string'
13
+ end
9
14
  end
10
15
  end
@@ -34,10 +34,10 @@ module Api
34
34
 
35
35
  test 'schedule inventory by user' do
36
36
  report = FactoryBot.create(:report_template)
37
- setting = Setting::Ansible.create! :name => 'ansible_inventory_template', :value => report.name,
38
- :default => report.name, :description => 'inventory'
37
+ Setting::Ansible.create! :name => 'ansible_inventory_template', :value => report.name,
38
+ :default => report.name, :description => 'inventory'
39
39
  user = FactoryBot.create(:user)
40
- user.roles << Role.find_by_name('Ansible Tower Inventory Reader')
40
+ user.roles << Role.find_by(:name => 'Ansible Tower Inventory Reader')
41
41
  post :schedule, { :session => set_session_user(user) }
42
42
  assert_response :success
43
43
  end
@@ -46,6 +46,18 @@ module Api
46
46
  res = JSON.parse(@response.body)
47
47
  refute res['imported']
48
48
  end
49
+
50
+ test 'should update' do
51
+ variable = FactoryBot.create(:ansible_variable, :default_value => 'my default value')
52
+ new_value = 'changed default value'
53
+ post :update,
54
+ :params => { :id => variable.id, :default_value => new_value },
55
+ :session => set_session_user
56
+
57
+ assert_response :success
58
+ res = JSON.parse(@response.body)
59
+ assert_equal new_value, res['default_value']
60
+ end
49
61
  end
50
62
  end
51
63
  end
@@ -5,52 +5,77 @@ require 'test_plugin_helper'
5
5
  # This service is meant to take in essentially a string coming from
6
6
  # the proxy API, and parse that into AnsibleVariables.
7
7
  class AnsibleVariablesImporterTest < ActiveSupport::TestCase
8
- setup do
9
- @importer = ForemanAnsible::VariablesImporter.new
10
- end
11
- test 'does not reimport already existing variables' do
12
- already_existing = FactoryBot.create(:ansible_variable)
13
- new_role = FactoryBot.create(:ansible_role)
14
- api_response = {
15
- new_role.name => { 'new_var' => 'new value' },
16
- already_existing.ansible_role.name => { already_existing.key => already_existing.default_value }
17
- }
18
- changes = @importer.import_variables(api_response, [new_role.name])
19
- assert_not_empty changes['new']
20
- assert_equal 'new_var', changes['new'].first.key
21
- assert_equal new_role, changes['new'].first.ansible_role
22
- end
8
+ let(:importer) { ForemanAnsible::VariablesImporter.new }
23
9
 
24
- test "variables attempts to remove variables that don't exist anymore" do
25
- obsolete_variable = FactoryBot.create(:ansible_variable)
26
- changes = @importer.import_variables({}, [])
27
- assert_not_empty changes['obsolete']
28
- assert_equal obsolete_variable.key, changes['obsolete'].first.key
29
- assert_equal(
30
- obsolete_variable.ansible_role,
31
- changes['obsolete'].first.ansible_role
32
- )
33
- end
10
+ describe '#import_variables' do
11
+ test 'does not reimport already existing variables' do
12
+ already_existing = FactoryBot.create(:ansible_variable)
13
+ new_role = FactoryBot.create(:ansible_role)
14
+ api_response = {
15
+ new_role.name => { 'new_var' => 'new value' },
16
+ already_existing.ansible_role.name => { already_existing.key => already_existing.default_value }
17
+ }
18
+ changes = importer.import_variables(api_response, [new_role.name])
19
+ assert_empty changes['update']
20
+ assert_not_empty changes['new']
21
+ assert_equal 'new_var', changes['new'].first.key
22
+ assert_equal new_role, changes['new'].first.ansible_role
23
+ end
34
24
 
35
- test 'does not do anything if response is empty' do
36
- changes = @importer.import_variables({}, [])
37
- assert_equal({ 'new' => [], 'obsolete' => [], 'update' => [] }, changes)
38
- end
25
+ test "variables attempts to remove variables that don't exist anymore" do
26
+ obsolete_variable = FactoryBot.create(:ansible_variable)
27
+ changes = importer.import_variables({}, [])
28
+ assert_not_empty changes['obsolete']
29
+ assert_equal obsolete_variable.key, changes['obsolete'].first.key
30
+ assert_equal(
31
+ obsolete_variable.ansible_role,
32
+ changes['obsolete'].first.ansible_role
33
+ )
34
+ end
39
35
 
40
- test 'do not update changed defaults' do
41
- role = FactoryBot.create(:ansible_role)
42
- variable = FactoryBot.create(:ansible_variable, :default_value => 'default value', :ansible_role_id => role.id)
43
- api_response = {
44
- role.name => { variable.key => 'changed value', 'new_variable' => 'new value' }
45
- }
46
- changes = @importer.import_variables(api_response, [])
47
- assert_empty changes['update']
48
- assert_equal 'new_variable', changes['new'].first.key
49
- end
36
+ test 'does not do anything if response is empty' do
37
+ changes = importer.import_variables({}, [])
38
+ assert_equal({ 'new' => [], 'obsolete' => [], 'update' => [] }, changes)
39
+ end
40
+
41
+ test 'update changed defaults' do
42
+ role = FactoryBot.create(:ansible_role)
43
+ variable = FactoryBot.create(:ansible_variable, :default_value => 'default value', :ansible_role => role)
44
+ api_response = {
45
+ role.name => { variable.key => 'changed value' }
46
+ }
47
+ changes = importer.import_variables(api_response, [])
48
+ assert_not_empty changes['update']
49
+ assert_equal variable.key, changes['update'].first.key
50
+ end
51
+
52
+ test 'does not update overriden defaults' do
53
+ role = FactoryBot.create(:ansible_role)
54
+ variable = FactoryBot.create(:ansible_variable, :default_value => 'default value', :override => true, :ansible_role => role)
55
+ api_response = {
56
+ role.name => { variable.key => 'changed value' }
57
+ }
58
+ changes = importer.import_variables(api_response, [])
59
+ assert_empty changes['update']
60
+ end
61
+
62
+ test 'reimports variable with same key for different role' 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_equal 'new value', changes['new'].first.default_value
73
+ end
50
74
 
51
- test 'should ignore custom variables' do
52
- FactoryBot.create(:ansible_variable, :imported => false)
53
- changes = @importer.import_variables({}, [])
54
- assert_empty changes['obsolete']
75
+ test 'ignores custom variables' do
76
+ FactoryBot.create(:ansible_variable, :imported => false)
77
+ changes = importer.import_variables({}, [])
78
+ assert_empty changes['obsolete']
79
+ end
55
80
  end
56
81
  end