foreman_discovery 11.0.0 → 12.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +5 -5
  2. data/app/controllers/api/v2/discovered_hosts_controller.rb +1 -2
  3. data/app/controllers/concerns/foreman/controller/discovered_extensions.rb +1 -1
  4. data/app/controllers/discovered_hosts_controller.rb +21 -11
  5. data/app/controllers/foreman_discovery/concerns/hosts_controller_extensions.rb +1 -1
  6. data/app/helpers/discovered_hosts_helper.rb +9 -11
  7. data/app/models/discovery_rule.rb +3 -0
  8. data/app/models/host/discovered.rb +59 -19
  9. data/app/models/setting/discovered.rb +1 -0
  10. data/app/services/foreman_discovery/fact_parser.rb +6 -2
  11. data/app/services/foreman_discovery/ui_notifications/new_host.rb +3 -1
  12. data/app/views/dashboard/_discovery_widget_host_list.html.erb +1 -1
  13. data/app/views/discovered_hosts/_discovered_hosts_list.html.erb +2 -3
  14. data/app/views/discovered_hosts/_selected_hosts.html.erb +1 -1
  15. data/app/views/discovered_hosts/index.html.erb +0 -2
  16. data/app/views/discovered_hosts/multiple_auto_provision.html.erb +4 -0
  17. data/app/views/discovered_hosts/multiple_reboot.html.erb +4 -0
  18. data/app/views/discovered_hosts/show.html.erb +27 -15
  19. data/app/views/discovery_rules/_form.html.erb +9 -3
  20. data/app/views/discovery_rules/edit.html.erb +1 -1
  21. data/app/views/discovery_rules/index.html.erb +2 -2
  22. data/app/views/foreman_discovery/debian_kexec.erb +1 -1
  23. data/app/views/foreman_discovery/redhat_kexec.erb +1 -1
  24. data/config/as_deprecation_whitelist.yaml +395 -0
  25. data/config/routes.rb +7 -5
  26. data/db/migrate/20171222120314_add_constraints_on_discovery_rules_hostgroups.rb +10 -0
  27. data/db/migrate/20180412124505_add_priority_score_to_discovery_rules.rb +24 -0
  28. data/extra/discover-host +7 -5
  29. data/extra/discovery/simple-bond.json +167 -0
  30. data/lib/foreman_discovery/engine.rb +9 -3
  31. data/lib/foreman_discovery/version.rb +1 -1
  32. data/locale/ca/LC_MESSAGES/foreman_discovery.mo +0 -0
  33. data/locale/ca/foreman_discovery.edit.po +148 -221
  34. data/locale/ca/foreman_discovery.po +25 -19
  35. data/locale/de/LC_MESSAGES/foreman_discovery.mo +0 -0
  36. data/locale/de/foreman_discovery.edit.po +147 -221
  37. data/locale/de/foreman_discovery.po +26 -20
  38. data/locale/en/foreman_discovery.edit.po +106 -98
  39. data/locale/en/foreman_discovery.po +24 -18
  40. data/locale/en_GB/LC_MESSAGES/foreman_discovery.mo +0 -0
  41. data/locale/en_GB/foreman_discovery.edit.po +149 -222
  42. data/locale/en_GB/foreman_discovery.po +26 -20
  43. data/locale/es/LC_MESSAGES/foreman_discovery.mo +0 -0
  44. data/locale/es/foreman_discovery.edit.po +149 -222
  45. data/locale/es/foreman_discovery.po +26 -20
  46. data/locale/foreman_discovery.pot +115 -103
  47. data/locale/fr/LC_MESSAGES/foreman_discovery.mo +0 -0
  48. data/locale/fr/foreman_discovery.edit.po +147 -221
  49. data/locale/fr/foreman_discovery.po +26 -20
  50. data/locale/gl/foreman_discovery.edit.po +147 -220
  51. data/locale/gl/foreman_discovery.po +24 -18
  52. data/locale/it/LC_MESSAGES/foreman_discovery.mo +0 -0
  53. data/locale/it/foreman_discovery.edit.po +148 -221
  54. data/locale/it/foreman_discovery.po +25 -19
  55. data/locale/ja/LC_MESSAGES/foreman_discovery.mo +0 -0
  56. data/locale/ja/foreman_discovery.edit.po +149 -222
  57. data/locale/ja/foreman_discovery.po +26 -20
  58. data/locale/ko/LC_MESSAGES/foreman_discovery.mo +0 -0
  59. data/locale/ko/foreman_discovery.edit.po +149 -221
  60. data/locale/ko/foreman_discovery.po +26 -20
  61. data/locale/pt_BR/LC_MESSAGES/foreman_discovery.mo +0 -0
  62. data/locale/pt_BR/foreman_discovery.edit.po +149 -222
  63. data/locale/pt_BR/foreman_discovery.po +26 -20
  64. data/locale/ru/LC_MESSAGES/foreman_discovery.mo +0 -0
  65. data/locale/ru/foreman_discovery.edit.po +152 -223
  66. data/locale/ru/foreman_discovery.po +26 -20
  67. data/locale/sv_SE/LC_MESSAGES/foreman_discovery.mo +0 -0
  68. data/locale/sv_SE/foreman_discovery.edit.po +147 -220
  69. data/locale/sv_SE/foreman_discovery.po +24 -18
  70. data/locale/zh_CN/LC_MESSAGES/foreman_discovery.mo +0 -0
  71. data/locale/zh_CN/foreman_discovery.edit.po +155 -224
  72. data/locale/zh_CN/foreman_discovery.po +26 -20
  73. data/locale/zh_TW/LC_MESSAGES/foreman_discovery.mo +0 -0
  74. data/locale/zh_TW/foreman_discovery.edit.po +151 -222
  75. data/locale/zh_TW/foreman_discovery.po +26 -20
  76. data/test/functional/api/v2/discovered_hosts_controller_test.rb +2 -0
  77. data/test/functional/api/v2/discovery_rules_controller_test.rb +96 -9
  78. data/test/functional/api/v2/settings_controller_test.rb +22 -0
  79. data/test/functional/discovered_hosts_controller_test.rb +20 -21
  80. data/test/functional/discovery_rules_controller_test.rb +5 -4
  81. data/test/integration/discovered_hosts_test.rb +20 -10
  82. data/test/models/setting_test.rb +11 -0
  83. data/test/test_helper_discovery.rb +1 -0
  84. data/test/unit/discovered_extensions_test.rb +2 -13
  85. data/test/unit/discovery_rule_test.rb +87 -1
  86. data/test/unit/fact_parser_test.rb +2 -2
  87. data/test/unit/host_discovered_test.rb +60 -28
  88. data/test/unit/ui_notifications/destroy_host_test.rb +14 -4
  89. data/test/unit/ui_notifications/new_host_test.rb +8 -1
  90. metadata +22 -4
@@ -44,9 +44,6 @@ msgstr ""
44
44
  msgid "Auto Provision"
45
45
  msgstr "自動佈建"
46
46
 
47
- msgid "Auto Provision All"
48
- msgstr "自動佈建全部"
49
-
50
47
  msgid "Auto provisioning"
51
48
  msgstr ""
52
49
 
@@ -74,6 +71,9 @@ msgstr ""
74
71
  msgid "Clean all reported facts during provisioning (except discovery facts)"
75
72
  msgstr ""
76
73
 
74
+ msgid "Collapse All"
75
+ msgstr ""
76
+
77
77
  msgid "Could not get facts from proxy %{url}: %{error}"
78
78
  msgstr "無法由協定 %{url} 取得詳細資料:%{error}"
79
79
 
@@ -95,6 +95,9 @@ msgstr ""
95
95
  msgid "DHCP filename option (Grub2 or PXELinux by default)"
96
96
  msgstr ""
97
97
 
98
+ msgid "Delete"
99
+ msgstr ""
100
+
98
101
  msgid "Delete %s?"
99
102
  msgstr "刪除 %s?"
100
103
 
@@ -104,9 +107,6 @@ msgstr "刪除發現的主機"
104
107
  msgid "Delete a rule"
105
108
  msgstr "刪除規則"
106
109
 
107
- msgid "Delete hosts"
108
- msgstr "刪除主機"
109
-
110
110
  msgid "Delete rule '%s'?"
111
111
  msgstr ""
112
112
 
@@ -125,6 +125,9 @@ msgstr ""
125
125
  msgid "Discovered Hosts"
126
126
  msgstr ""
127
127
 
128
+ msgid "Discovered host '%{host}' has all NICs filtered out, filter: %{filter}"
129
+ msgstr ""
130
+
128
131
  msgid "Discovered host: %s"
129
132
  msgstr "發現的主機:%s"
130
133
 
@@ -155,6 +158,9 @@ msgstr ""
155
158
  msgid "Discovery Rules"
156
159
  msgstr "搜尋規則"
157
160
 
161
+ msgid "Discovery fact parser does not work with non-discovery host '%{host}'"
162
+ msgstr ""
163
+
158
164
  msgid "Discovery location"
159
165
  msgstr ""
160
166
 
@@ -188,11 +194,14 @@ msgstr ""
188
194
  msgid "Disks size"
189
195
  msgstr "磁碟大小"
190
196
 
197
+ msgid "Do not allow to discover existing managed host matching MAC of a provisioning NIC (errors out early)"
198
+ msgstr ""
199
+
191
200
  msgid "Domain will be appended automatically. A hostname based on MAC address will be used when left blank."
192
201
  msgstr ""
193
202
 
194
- msgid "Edit Discovery Rule"
195
- msgstr "編輯搜尋規則"
203
+ msgid "Edit %s"
204
+ msgstr ""
196
205
 
197
206
  msgid "Enable"
198
207
  msgstr "啟用"
@@ -200,6 +209,9 @@ msgstr "啟用"
200
209
  msgid "Enable rule '%s'?"
201
210
  msgstr ""
202
211
 
212
+ msgid "Error on existing NIC"
213
+ msgstr ""
214
+
203
215
  msgid "Errors during auto provisioning: %s"
204
216
  msgstr "進行自動佈建時發生了錯誤:%s"
205
217
 
@@ -212,9 +224,6 @@ msgstr "針對於一部發現的主機執行規則"
212
224
  msgid "Execute rules against all currently discovered hosts"
213
225
  msgstr "針對於所有目前已發現的主機執行規則"
214
226
 
215
- msgid "Expand All"
216
- msgstr "全部展開"
217
-
218
227
  msgid "Expected discovery_fact '%s' is missing, unable to detect primary interface and set hostname"
219
228
  msgstr "沒有預期的 discovery_fact '%s',無法偵測主介面並設定主機名稱"
220
229
 
@@ -507,9 +516,6 @@ msgstr "佈建一部已發現的主機"
507
516
  msgid "Reboot"
508
517
  msgstr "重新開機"
509
518
 
510
- msgid "Reboot All"
511
- msgstr "全部重新開機"
512
-
513
519
  msgid "Rebooting %s"
514
520
  msgstr "重新啟動 %s"
515
521
 
@@ -642,15 +648,12 @@ msgstr "種類"
642
648
  msgid "UUID to track orchestration tasks status, GET /api/orchestration/:UUID/tasks"
643
649
  msgstr "用來追蹤協調流程任務狀態的 UUID,GET /api/orchestration/:UUID/tasks"
644
650
 
645
- msgid "Unable to assign subnet, primary interface is missing IP address"
646
- msgstr "無法指定子網路,主介面沒有 IP 位址"
647
-
648
- msgid "Unable to detect primary interface using MAC '%{mac}' specified by discovery_fact '%{fact}'"
649
- msgstr "無法偵測使用 MAC '%{mac}' 的主介面,由 discovery_fact '%{fact}' 所指定"
650
-
651
651
  msgid "Unable to find a discovery rule, no host provided (check permissions)"
652
652
  msgstr "找不到探索規則,未提供主機(檢查權限)"
653
653
 
654
+ msgid "Unable to find primary NIC with %{mac} specified via '%{fact}', NIC filter: %{filter}"
655
+ msgstr ""
656
+
654
657
  msgid "Unable to perform kexec on %{name} via %{url}: %{msg}"
655
658
  msgstr "無法透過 %{url} 在 %{name} 上執行 kexec:%{msg}"
656
659
 
@@ -693,6 +696,9 @@ msgstr "已選取項目。反選以清除"
693
696
  msgid "location ID for provisioned hosts"
694
697
  msgstr ""
695
698
 
699
+ msgid "must be present."
700
+ msgstr ""
701
+
696
702
  msgid "must start with a letter or ERB."
697
703
  msgstr "必須以字母或是 ERB 作為起始。"
698
704
 
@@ -1,6 +1,8 @@
1
1
  require 'test_plugin_helper'
2
2
 
3
3
  class Api::V2::DiscoveredHostsControllerTest < ActionController::TestCase
4
+ include FactImporterIsolation
5
+ allow_transactions_for_any_importer
4
6
 
5
7
  def switch_controller(klass)
6
8
  old_controller = @controller
@@ -31,20 +31,32 @@ class Api::V2::DiscoveryRulesControllerTest < ActionController::TestCase
31
31
  assert_equal "Location 1", discovery_rule['locations'].first['name']
32
32
  end
33
33
 
34
+ test_attributes :pid => '121e0a30-8a24-47d7-974d-998886ed1ea7'
34
35
  test "should create discovery rule with taxonomy" do
36
+ hostgroup = FactoryBot.create(:hostgroup, :with_os, :with_rootpass, :organizations => [organization_one], :locations => [location_one])
37
+ valid_attributes = {
38
+ :name => "foo",
39
+ :search => "bar",
40
+ :hostgroup_id => hostgroup.id,
41
+ :organization_ids => [organization_one.id],
42
+ :location_ids => [location_one.id],
43
+ :hostname => "",
44
+ :priority => 1
45
+ }
35
46
  assert_difference('DiscoveryRule.unscoped.count') do
36
- hostgroup = FactoryBot.create(:hostgroup, :with_os, :with_rootpass, :organizations => [organization_one], :locations => [location_one])
37
- post :create, params: {:discovery_rule => {
38
- :name => "foo",
39
- :search => "bar",
40
- :hostgroup_id => hostgroup.id,
41
- :organization_ids => [organization_one.id],
42
- :location_ids => [location_one.id],
43
- :hostname => "",
44
- :priority => 1}}
47
+ post :create, params: { :discovery_rule => valid_attributes }
45
48
  refute_match /error/, response.body
46
49
  end
47
50
  assert_response :success
51
+ response = JSON.parse(@response.body)
52
+ assert %w[id name hostgroup_id search].all? { |needed_key| response.key?(needed_key) }
53
+ assert_equal valid_attributes[:name], response['name']
54
+ assert_equal valid_attributes[:hostgroup_id], response['hostgroup_id']
55
+ assert_equal valid_attributes[:search], response['search']
56
+ discovery_rule = DiscoveryRule.unscoped.find(response['id'])
57
+ refute discovery_rule.nil?
58
+ assert_equal organization_one.id, discovery_rule.organizations.first.id
59
+ assert_equal location_one.id, discovery_rule.locations.first.id
48
60
  end
49
61
 
50
62
  test "should update discovery rule" do
@@ -53,17 +65,92 @@ class Api::V2::DiscoveryRulesControllerTest < ActionController::TestCase
53
65
  assert_response :success
54
66
  end
55
67
 
68
+ test_attributes :pid => '769c0739-538b-4451-af7b-deb2ecd3dc0d'
69
+ test "should update discovery rule name" do
70
+ rule = FactoryBot.create(:discovery_rule)
71
+ new_name = 'new_rule_name'
72
+ put :update, params: { :id => rule.to_param, :discovery_rule => { :name => new_name } }
73
+ assert_response :success
74
+ rule.reload
75
+ assert_equal new_name, rule.name
76
+ end
77
+
56
78
  test "should update taxonomy for discovery rule" do
57
79
  rule = FactoryBot.create(:discovery_rule)
58
80
  put :update, params: { :id => rule.to_param, :discovery_rule => { :organization_ids => [rule.organizations.first.id] } }
59
81
  assert_response :success
60
82
  end
61
83
 
84
+ test_attributes :pid => '0f8ec302-f9de-4713-87b7-0f1aca515149'
85
+ test "should update taxonomies for discovery rule" do
86
+ min_required_attr = { :name => 'new_rule', :search => 'CPU_Count = 1', :hostgroup_id => hostgroups(:unusual).id }
87
+ rule = DiscoveryRule.new(min_required_attr)
88
+ assert rule.save
89
+ assert rule.organizations.empty?
90
+ assert rule.locations.empty?
91
+ hostgroup = FactoryBot.create(:hostgroup, :with_os, :with_rootpass, :organizations => [organization_one], :locations => [location_one])
92
+ put :update, params: { :id => rule.to_param, :discovery_rule => {
93
+ :organization_ids => [organization_one.id],
94
+ :location_ids => [location_one.id],
95
+ :hostgroup_id => hostgroup.id
96
+ }}
97
+ assert_response :success
98
+ rule.reload
99
+ assert_equal [organization_one.id], rule.organizations.map {|org| org.id}
100
+ assert_equal [location_one.id], rule.locations.map {|loc| loc.id}
101
+ end
102
+
103
+ test_attributes :pid => '2c5ecb7e-87bc-4980-9620-7ae00e3f360e'
104
+ test "should update search rule" do
105
+ rule = FactoryBot.create(:discovery_rule)
106
+ new_search = 'Location = Default_Location'
107
+ put :update, params: { :id => rule.to_param, :discovery_rule => { :search => new_search } }
108
+ assert_response :success
109
+ rule.reload
110
+ assert_equal new_search, rule.search
111
+ end
112
+
113
+ test_attributes :pid => '33084060-2866-46b9-bfab-23d91aea73d8'
114
+ test "should update host limit" do
115
+ rule = FactoryBot.create(:discovery_rule)
116
+ new_max_count = 150
117
+ assert_not_equal new_max_count, rule.max_count
118
+ put :update, params: { :id => rule.to_param, :discovery_rule => { :max_count => new_max_count } }
119
+ assert_response :success
120
+ rule.reload
121
+ assert_equal new_max_count, rule.max_count
122
+ end
123
+
124
+ test_attributes :pid => '330aa943-167b-46dd-b434-1a6e5fe8f283'
125
+ test "test_positive_disable" do
126
+ rule = FactoryBot.create(:discovery_rule)
127
+ assert rule.enabled
128
+ put :update, params: { :id => rule.to_param, :discovery_rule => { :enabled => false } }
129
+ assert_response :success
130
+ rule.reload
131
+ refute rule.enabled
132
+ end
133
+
134
+ test_attributes :pid => '9fdba953-dcc7-4532-9204-17a45b0d9e05'
62
135
  test "should destroy discovery rule" do
63
136
  rule = FactoryBot.create(:discovery_rule)
64
137
  assert_difference('DiscoveryRule.unscoped.count', -1) do
65
138
  delete :destroy, params: { :id => rule.to_param }
66
139
  end
67
140
  assert_response :success
141
+ refute DiscoveryRule.unscoped.exists?(rule.id)
142
+ end
143
+
144
+ test_attributes :pid => '415379b7-0134-40b9-adb1-2fe0adb1ac36'
145
+ test "should not create with too long name" do
146
+ assert_difference('DiscoveryRule.unscoped.count', 0) do
147
+ post :create, params: {:discovery_rule => {
148
+ :name => RFauxFactory.gen_alpha(256),
149
+ :search => 'CPU_Count = 1',
150
+ :hostgroup_id => hostgroups(:unusual).id
151
+ }}
152
+ end
153
+ assert_response :unprocessable_entity
154
+ assert_include @response.body, 'Name is too long (maximum is 255 characters)'
68
155
  end
69
156
  end
@@ -0,0 +1,22 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class Api::V2::SettingsControllerTest < ActionController::TestCase
4
+ setup do
5
+ FactoryBot.create(:setting, :name => 'discovery_prefix', :value => 'mac', :category => 'Setting::Discovered')
6
+ end
7
+
8
+ test_attributes :pid => '2c5ecb7e-87bc-4980-9620-7ae00e3f360e'
9
+ test "should update hostname prefix without value" do
10
+ setting = Setting.find_by_name("discovery_prefix")
11
+ put :update, params: { :id => setting.id, :setting => { :value => '' } }
12
+ assert_equal JSON.parse(@response.body)['value'], '', "Can't update discovery_prefix setting with empty value"
13
+ end
14
+
15
+ test_attributes :pid => '4969994d-f934-4f0e-9a98-476b87eb0527'
16
+ test "should update hostname prefix" do
17
+ value = RFauxFactory.gen_alpha
18
+ setting = Setting.find_by_name("discovery_prefix")
19
+ put :update, params: { :id => setting.id, :setting => { :value => value } }
20
+ assert_equal JSON.parse(@response.body)['value'], value, "Can't update discovery_prefix setting with valid value #{value}"
21
+ end
22
+ end
@@ -103,7 +103,7 @@ class DiscoveredHostsControllerTest < ActionController::TestCase
103
103
  assert managed_host.build
104
104
  assert_redirected_to host_url(managed_host)
105
105
  assert_equal hostgroup.id, managed_host.hostgroup_id
106
- assert_match /Successfully/, flash[:notice]
106
+ assert_match(/Successfully/, flash[:success])
107
107
  end
108
108
  end
109
109
 
@@ -178,7 +178,7 @@ class DiscoveredHostsControllerTest < ActionController::TestCase
178
178
  post :reboot, params: { :id => host.id }, session: set_session_user_default_manager
179
179
  assert_redirected_to discovered_hosts_url
180
180
  assert_nil flash[:error]
181
- assert_equal "Rebooting host #{host.name}", flash[:notice]
181
+ assert_equal "Rebooting host #{host.name}", flash[:success]
182
182
  end
183
183
 
184
184
  def test_reboot_failure
@@ -208,7 +208,7 @@ class DiscoveredHostsControllerTest < ActionController::TestCase
208
208
  post :auto_provision, params: { :id => host.id }, session: set_session_user(User.current)
209
209
  assert_response :redirect
210
210
  assert_nil flash[:error]
211
- assert_match(/^Host macaabbccddeeff.* was provisioned/, flash[:notice])
211
+ assert_match(/^Host macaabbccddeeff.* was provisioned/, flash[:success])
212
212
  managed_host = Host.find(host.id)
213
213
  assert managed_host.build
214
214
  end
@@ -220,10 +220,10 @@ class DiscoveredHostsControllerTest < ActionController::TestCase
220
220
  post :auto_provision, params: { :id => host.id }, session: set_session_user(User.current)
221
221
  assert_response :redirect
222
222
  assert_nil flash[:error]
223
- assert_equal "No rule found for host macaabbccddeeff", flash[:notice]
223
+ assert_equal "No rule found for host macaabbccddeeff", flash[:success]
224
224
  end
225
225
 
226
- def test_auto_provision_all_success
226
+ def test_multiple_auto_provision_success
227
227
  disable_orchestration
228
228
  facts = @facts.merge({"somefact" => "abc"})
229
229
  host = discover_host_from_facts(facts)
@@ -235,13 +235,13 @@ class DiscoveredHostsControllerTest < ActionController::TestCase
235
235
  :hostgroup => hostgroup,
236
236
  :organizations => [host.organization], :locations => [host.location]
237
237
  )
238
- post :auto_provision_all, params: {}, session: set_session_user(User.current)
238
+ post :submit_multiple_auto_provision, params: {:host_ids => host.id}, session: set_session_user(User.current)
239
239
  assert_response :redirect
240
240
  assert_nil flash[:error]
241
- assert_equal "Discovered hosts are provisioning now", flash[:notice]
241
+ assert_equal "Discovered hosts are provisioning now", flash[:success]
242
242
  end
243
243
 
244
- def test_auto_provision_all_no_rule_success
244
+ def test_multiple_auto_provision_no_rule_success
245
245
  disable_orchestration
246
246
  facts = @facts.merge({"somefact" => "abc"})
247
247
  host = discover_host_from_facts(facts)
@@ -253,41 +253,40 @@ class DiscoveredHostsControllerTest < ActionController::TestCase
253
253
  :hostgroup => hostgroup,
254
254
  :organizations => [host.organization], :locations => [host.location]
255
255
  )
256
- post :auto_provision_all, params: {}, session: set_session_user(User.current)
256
+ post :submit_multiple_auto_provision, params: {:host_ids => host.id}, session: set_session_user(User.current)
257
257
  assert_response :redirect
258
258
  assert_nil flash[:error]
259
- assert_equal "Discovered hosts are provisioning now", flash[:notice]
259
+ assert_equal "Discovered hosts are provisioning now", flash[:success]
260
260
  end
261
261
 
262
- def test_reboot_all_success
262
+ def test_multiple_reboot_success
263
263
  @request.env["HTTP_REFERER"] = discovered_hosts_url
264
264
  host = discover_host_from_facts(@facts)
265
265
  ::ForemanDiscovery::NodeAPI::PowerService.any_instance.expects(:reboot).returns(true)
266
- post :reboot, params: { :id => host.id }, session: set_session_user_default_manager
266
+ post :submit_multiple_reboot, params: {:host_ids => host.id}, session: set_session_user(User.current)
267
267
  assert_redirected_to discovered_hosts_url
268
- assert_equal "Rebooting host #{host.name}", flash[:notice]
269
268
  assert_nil flash[:error]
270
- assert_equal "Rebooting host macaabbccddeeff", flash[:notice]
269
+ assert_equal "Discovered hosts are rebooting now", flash[:success]
271
270
  end
272
271
 
273
- def test_reboot_all_failure
272
+ def test_multiple_reboot_failure
274
273
  @request.env["HTTP_REFERER"] = discovered_hosts_url
275
274
  host = discover_host_from_facts(@facts)
276
275
  ::ForemanDiscovery::NodeAPI::PowerService.any_instance.expects(:reboot).returns(false)
277
- post :reboot_all, params: { }, session: set_session_user_default_manager
276
+ post :submit_multiple_reboot, params: {:host_ids => host.id}, session: set_session_user(User.current)
278
277
  assert_redirected_to discovered_hosts_url
279
278
  assert_equal "Errors during reboot: #{host.name}: failed to reboot", flash[:error]
280
- assert_nil flash[:notice]
279
+ assert_nil flash[:success]
281
280
  end
282
281
 
283
- def test_reboot_all_error
282
+ def test_multiple_reboot_error
284
283
  @request.env["HTTP_REFERER"] = discovered_hosts_url
285
- discover_host_from_facts(@facts)
284
+ host = discover_host_from_facts(@facts)
286
285
  ::ForemanDiscovery::NodeAPI::PowerService.any_instance.expects(:reboot).raises("request failed")
287
- post :reboot_all, params: { }, session: set_session_user_default_manager
286
+ post :submit_multiple_reboot, params: {:host_ids => host.id}, session: set_session_user(User.current)
288
287
  assert_redirected_to discovered_hosts_url
289
288
  assert_match(/ERF50-4973/, flash[:error])
290
- assert_nil flash[:notice]
289
+ assert_nil flash[:success]
291
290
  end
292
291
 
293
292
  def test_no_dns_rebuild_if_dns_pending
@@ -19,17 +19,18 @@ class DiscoveryRulesControllerTest < ActionController::TestCase
19
19
  assert_response :success
20
20
  end
21
21
 
22
- test "should create discovery rule without taxonomy" do
23
- assert_difference('DiscoveryRule.unscoped.count') do
22
+ test "should not create discovery rule without taxonomy" do
23
+ assert_difference('DiscoveryRule.unscoped.count', 0) do
24
+ DiscoveryRule.any_instance.stubs(:set_current_taxonomy).returns(true)
24
25
  post :create, params: {:discovery_rule => {
25
26
  :name => "foo",
26
27
  :search => "cpu_count = 42",
27
28
  :hostgroup_id => 1,
28
29
  :hostname => "",
29
30
  :priority => 1}}, session: set_session_user_default_manager
30
- assert_empty(extract_form_errors(response))
31
+ assert_not_empty(extract_form_errors(response))
31
32
  end
32
- assert_redirected_to discovery_rules_path
33
+ assert_template :new
33
34
  end
34
35
 
35
36
  test "should create discovery rule with taxonomy" do
@@ -5,8 +5,6 @@ class DiscoveredHostsTest < IntegrationTestWithJavascript
5
5
  let(:discovered_host) { FactoryBot.create(:discovered_host, :with_facts) }
6
6
  let(:discovered_hosts) { Host::Discovered.all }
7
7
 
8
- extend Minitest::OptionalRetry
9
-
10
8
  setup do
11
9
  assert discovered_notification_blueprint
12
10
  discovered_host.save!
@@ -17,20 +15,28 @@ class DiscoveredHostsTest < IntegrationTestWithJavascript
17
15
  Host::Discovered.destroy_all
18
16
  end
19
17
 
20
- describe 'Reboot all' do
18
+ describe 'Multiple host Reboot' do
21
19
  test 'triggers reboot on all discovered_hosts' do
22
20
  Host::Discovered.any_instance
23
21
  .expects(:reboot)
24
22
  .at_least(discovered_hosts.count)
25
- select_all_hosts
26
- page.find_link('Reboot All').click
23
+ select_host_checkbox(discovered_host.id)
24
+ page.find_link('Select Action').click
25
+ page.find_link('Reboot').click
26
+ wait_for_ajax
27
+ assert page.has_text?('The following hosts are about to be changed')
28
+ page.find_button('Submit').click
27
29
  end
28
30
  end
29
31
 
30
- describe 'Autoprovision all' do
32
+ describe 'Multiple host Autoprovision' do
31
33
  test 'converts all discovered to managed hosts' do
32
- select_all_hosts
33
- page.find_link('Auto Provision All').click
34
+ select_host_checkbox(discovered_host.id)
35
+ page.find_link('Select Action').click
36
+ page.find_link('Auto Provision').click
37
+ wait_for_ajax
38
+ assert page.has_text?('The following hosts are about to be changed')
39
+ page.find_button('Submit').click
34
40
  wait_for_ajax
35
41
  assert page.has_text?('Discovered hosts are provisioning now')
36
42
  end
@@ -38,9 +44,9 @@ class DiscoveredHostsTest < IntegrationTestWithJavascript
38
44
 
39
45
  describe 'Delete hosts' do
40
46
  test 'it removes all hosts' do
41
- select_all_hosts
47
+ select_host_checkbox(discovered_host.id)
42
48
  page.find_link('Select Action').click
43
- page.find_link('Delete hosts').click
49
+ page.find_link('Delete').click
44
50
  wait_for_ajax
45
51
  assert page.has_text?('The following hosts are about to be changed')
46
52
  page.find_button('Submit').click
@@ -137,6 +143,10 @@ class DiscoveredHostsTest < IntegrationTestWithJavascript
137
143
  page.find('#check_all').click
138
144
  end
139
145
 
146
+ def select_host_checkbox(id)
147
+ page.find("#host_ids_#{id}").click
148
+ end
149
+
140
150
  def select_from(element_id, id)
141
151
  page.find_by_id(element_id, visible: false)
142
152
  .find("option[value='#{id}']", visible: false)