foreman_discovery 9.1.5 → 10.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v2/discovered_hosts_controller.rb +5 -4
  3. data/app/controllers/api/v2/discovery_rules_controller.rb +1 -1
  4. data/app/controllers/concerns/foreman/controller/parameters/discovered_host.rb +2 -9
  5. data/app/controllers/discovered_hosts_controller.rb +10 -21
  6. data/app/controllers/discovery_rules_controller.rb +1 -1
  7. data/app/controllers/foreman_discovery/concerns/hosts_controller_extensions.rb +1 -1
  8. data/app/helpers/discovered_hosts_helper.rb +2 -3
  9. data/app/models/discovery_attribute_set.rb +1 -1
  10. data/app/models/discovery_rule.rb +1 -1
  11. data/app/models/host/discovered.rb +23 -17
  12. data/app/models/host/managed_extensions.rb +2 -5
  13. data/app/services/foreman_discovery/host_converter.rb +0 -6
  14. data/app/services/foreman_discovery/node_api/power.rb +0 -8
  15. data/app/views/discovered_hosts/_discovered_host_modal.html.erb +12 -13
  16. data/app/views/discovered_hosts/_selected_hosts.html.erb +1 -1
  17. data/app/views/discovered_hosts/multiple_destroy.html.erb +5 -4
  18. data/app/views/discovered_hosts/show.html.erb +9 -1
  19. data/app/views/discovered_hosts/welcome.html.erb +10 -0
  20. data/db/migrate/20141223142759_fill_discovery_attribute_sets_for_existing_hosts.rb +1 -1
  21. data/db/migrate/20150714144500_review_discovery_permissions.rb +9 -7
  22. data/db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb +0 -3
  23. data/extra/discover-host +18 -11
  24. data/extra/discovery/rhel7-vlan.json +352 -0
  25. data/lib/foreman_discovery/engine.rb +2 -1
  26. data/lib/foreman_discovery/version.rb +1 -1
  27. data/locale/ca/LC_MESSAGES/foreman_discovery.mo +0 -0
  28. data/locale/ca/foreman_discovery.edit.po +1 -1
  29. data/locale/ca/foreman_discovery.po +1 -1
  30. data/locale/de/LC_MESSAGES/foreman_discovery.mo +0 -0
  31. data/locale/de/foreman_discovery.edit.po +2 -2
  32. data/locale/de/foreman_discovery.po +2 -2
  33. data/locale/en/LC_MESSAGES/foreman_discovery.mo +0 -0
  34. data/locale/en/foreman_discovery.edit.po +79 -75
  35. data/locale/en/foreman_discovery.po +13 -10
  36. data/locale/en_GB/LC_MESSAGES/foreman_discovery.mo +0 -0
  37. data/locale/en_GB/foreman_discovery.edit.po +1 -1
  38. data/locale/en_GB/foreman_discovery.po +1 -1
  39. data/locale/es/LC_MESSAGES/foreman_discovery.mo +0 -0
  40. data/locale/es/foreman_discovery.edit.po +2 -2
  41. data/locale/es/foreman_discovery.po +2 -2
  42. data/locale/foreman_discovery.pot +89 -81
  43. data/locale/fr/LC_MESSAGES/foreman_discovery.mo +0 -0
  44. data/locale/fr/foreman_discovery.edit.po +2 -2
  45. data/locale/fr/foreman_discovery.po +2 -2
  46. data/locale/gl/LC_MESSAGES/foreman_discovery.mo +0 -0
  47. data/locale/gl/foreman_discovery.edit.po +1 -1
  48. data/locale/gl/foreman_discovery.po +1 -1
  49. data/locale/it/LC_MESSAGES/foreman_discovery.mo +0 -0
  50. data/locale/it/foreman_discovery.edit.po +2 -2
  51. data/locale/it/foreman_discovery.po +2 -2
  52. data/locale/ja/LC_MESSAGES/foreman_discovery.mo +0 -0
  53. data/locale/ja/foreman_discovery.edit.po +2 -2
  54. data/locale/ja/foreman_discovery.po +2 -2
  55. data/locale/ko/LC_MESSAGES/foreman_discovery.mo +0 -0
  56. data/locale/ko/foreman_discovery.edit.po +2 -2
  57. data/locale/ko/foreman_discovery.po +2 -2
  58. data/locale/pt_BR/LC_MESSAGES/foreman_discovery.mo +0 -0
  59. data/locale/pt_BR/foreman_discovery.edit.po +2 -2
  60. data/locale/pt_BR/foreman_discovery.po +2 -2
  61. data/locale/ru/LC_MESSAGES/foreman_discovery.mo +0 -0
  62. data/locale/ru/foreman_discovery.edit.po +2 -2
  63. data/locale/ru/foreman_discovery.po +2 -2
  64. data/locale/sv_SE/LC_MESSAGES/foreman_discovery.mo +0 -0
  65. data/locale/sv_SE/foreman_discovery.edit.po +1 -1
  66. data/locale/sv_SE/foreman_discovery.po +1 -1
  67. data/locale/zh_CN/LC_MESSAGES/foreman_discovery.mo +0 -0
  68. data/locale/zh_CN/foreman_discovery.edit.po +2 -2
  69. data/locale/zh_CN/foreman_discovery.po +2 -2
  70. data/locale/zh_TW/LC_MESSAGES/foreman_discovery.mo +0 -0
  71. data/locale/zh_TW/foreman_discovery.edit.po +2 -2
  72. data/locale/zh_TW/foreman_discovery.po +2 -2
  73. data/test/functional/api/v2/discovered_hosts_controller_test.rb +16 -17
  74. data/test/functional/api/v2/discovery_rules_controller_test.rb +2 -3
  75. data/test/functional/api/v2/fact_value_extensions_test.rb +1 -1
  76. data/test/functional/discovered_hosts_controller_test.rb +102 -133
  77. data/test/functional/foreman_discovery/concerns/hosts_controller_extensions_test.rb +5 -6
  78. data/test/test_helper_discovery.rb +18 -0
  79. data/test/unit/discovered_extensions_test.rb +25 -33
  80. data/test/unit/discovery_attribute_set_test.rb +5 -8
  81. data/test/unit/discovery_taxonomy_extensions_test.rb +2 -2
  82. data/test/unit/host_discovered_test.rb +30 -30
  83. data/test/unit/managed_extensions_test.rb +0 -1
  84. metadata +6 -4
  85. data/app/services/foreman_discovery/node_api/power_legacy_direct_service.rb +0 -15
  86. data/app/services/foreman_discovery/node_api/power_legacy_proxied_service.rb +0 -12
@@ -7,16 +7,15 @@ module ForemanDiscovery
7
7
 
8
8
  context 'hosts controller requests from discovered_hosts url' do
9
9
  test 'get "host" params from "discovered_hosts" params' do
10
- architecture = FactoryGirl.create(:architecture)
10
+ os = FactoryGirl.create(:operatingsystem, :with_associations)
11
+ arch_id = os.architectures.first.id
11
12
  discovered_host_params = {
12
- 'discovered_host' => { 'architecture_id' => architecture.id }
13
+ 'discovered_host' => { 'architecture_id' => arch_id }
13
14
  }
14
15
 
15
- @request.stubs(:path).
16
- returns(architecture_selected_discovered_hosts_path)
17
-
16
+ @request.stubs(:path).returns(architecture_selected_discovered_hosts_path)
18
17
  post :architecture_selected, discovered_host_params, set_session_user
19
- assert assigns('architecture'), architecture
18
+ assert_match(/"#{os.id}"/, response.body)
20
19
  end
21
20
  end
22
21
  end
@@ -109,3 +109,21 @@ end
109
109
  def location_one
110
110
  Location.find_by_name('Location 1')
111
111
  end
112
+
113
+ def facts_simple_network100_42
114
+ {
115
+ "interfaces" => "lo,eth0,eth1",
116
+ "ipaddress" => "192.168.100.42",
117
+ "ipaddress_eth0" => "192.168.100.42",
118
+ "ipaddress_eth1" => "192.168.100.15",
119
+ "macaddress_eth0" => "AA:BB:CC:DD:EE:FF",
120
+ "macaddress_eth1" => "AA:BB:CC:DD:EE:F1",
121
+ "discovery_bootif" => "AA:BB:CC:DD:EE:FF",
122
+ }
123
+ end
124
+
125
+ def discover_host_from_facts(facts)
126
+ User.as_anonymous_admin do
127
+ Host::Discovered.import_host(facts)
128
+ end
129
+ end
@@ -4,38 +4,30 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
4
4
  include Foreman::Controller::DiscoveredExtensions
5
5
 
6
6
  setup do
7
- @facts = {
8
- "interfaces" => "lo,eth0,eth1",
9
- "ipaddress" => "192.168.100.42",
10
- "ipaddress_eth0" => "192.168.100.42",
11
- "ipaddress_eth1" => "192.168.100.15",
12
- "macaddress_eth0" => "AA:BB:CC:DD:EE:FF",
13
- "macaddress_eth1" => "AA:BB:CC:DD:EE:F1",
14
- "discovery_bootif" => "AA:BB:CC:DD:EE:FF",
15
- }
7
+ @facts = facts_simple_network100_42
16
8
  set_default_settings
17
9
  end
18
10
 
19
11
  test "no rule is found for empty rule set" do
20
- host = Host::Discovered.import_host(@facts)
12
+ host = discover_host_from_facts(@facts)
21
13
  refute find_discovery_rule(host)
22
14
  end
23
15
 
24
16
  test "no rule is found out of one for a discovered host with no facts" do
25
- host = Host::Discovered.import_host(@facts)
17
+ host = discover_host_from_facts(@facts)
26
18
  FactoryGirl.create(:discovery_rule, :search => "facts.foo = bar")
27
19
  refute find_discovery_rule(host)
28
20
  end
29
21
 
30
22
  test "no rule is found out of one for a discovered host with some facts" do
31
- host = Host::Discovered.import_host(@facts)
23
+ host = discover_host_from_facts(@facts)
32
24
  FactoryGirl.create(:discovery_rule, :search => "facts.foo = doesnotexist")
33
25
  refute find_discovery_rule(host)
34
26
  end
35
27
 
36
28
  test "no rule is found out of two for a discovered host" do
37
29
  facts = @facts.merge({"somefact" => "abc"})
38
- host = Host::Discovered.import_host(facts)
30
+ host = discover_host_from_facts(facts)
39
31
  FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = xxx")
40
32
  FactoryGirl.create(:discovery_rule, :priority => 2, :search => "facts.somefact = zzz")
41
33
  refute find_discovery_rule(host)
@@ -43,7 +35,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
43
35
 
44
36
  test "rule out of one is found for a discovered host" do
45
37
  facts = @facts.merge({"somefact" => "abc"})
46
- host = Host::Discovered.import_host(facts)
38
+ host = discover_host_from_facts(facts)
47
39
  r1 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
48
40
  :organizations => [host.organization], :locations => [host.location])
49
41
  assert_equal find_discovery_rule(host), r1
@@ -51,7 +43,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
51
43
 
52
44
  test "first rule out of two is found for a discovered host" do
53
45
  facts = @facts.merge({"somefact" => "abc"})
54
- host = Host::Discovered.import_host(facts)
46
+ host = discover_host_from_facts(facts)
55
47
  r1 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
56
48
  :organizations => [host.organization], :locations => [host.location])
57
49
  FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = x",
@@ -61,7 +53,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
61
53
 
62
54
  test "second rule out of two is found for a discovered host" do
63
55
  facts = @facts.merge({"somefact" => "abc"})
64
- host = Host::Discovered.import_host(facts)
56
+ host = discover_host_from_facts(facts)
65
57
  FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = x",
66
58
  :organizations => [host.organization], :locations => [host.location])
67
59
  r2 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
@@ -71,7 +63,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
71
63
 
72
64
  test "first rule out of two with different priorities is found for a discovered host" do
73
65
  facts = @facts.merge({"somefact" => "abc"})
74
- host = Host::Discovered.import_host(facts)
66
+ host = discover_host_from_facts(facts)
75
67
  r1 = FactoryGirl.create(:discovery_rule, :name => "A", :priority => 1, :search => "facts.somefact = abc",
76
68
  :organizations => [host.organization], :locations => [host.location])
77
69
  r2 = FactoryGirl.create(:discovery_rule, :name => "B", :priority => 2, :search => "facts.somefact = abc",
@@ -81,7 +73,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
81
73
 
82
74
  test "second rule out of two with different priorities is found for a discovered host" do
83
75
  facts = @facts.merge({"somefact" => "abc"})
84
- host = Host::Discovered.import_host(facts)
76
+ host = discover_host_from_facts(facts)
85
77
  r1 = FactoryGirl.create(:discovery_rule, :name => "A", :priority => 2, :search => "facts.somefact = abc",
86
78
  :organizations => [host.organization], :locations => [host.location])
87
79
  r2 = FactoryGirl.create(:discovery_rule, :name => "B", :priority => 1, :search => "facts.somefact = abc",
@@ -91,7 +83,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
91
83
 
92
84
  test "older rule out of two is found for a discovered host" do
93
85
  facts = @facts.merge({"somefact" => "abc"})
94
- host = Host::Discovered.import_host(facts)
86
+ host = discover_host_from_facts(facts)
95
87
  r1 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
96
88
  :organizations => [host.organization], :locations => [host.location])
97
89
  r2 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
@@ -102,7 +94,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
102
94
 
103
95
  test "drained rule does not match for a discovered host" do
104
96
  facts = @facts.merge({"somefact" => "abc"})
105
- host = Host::Discovered.import_host(facts)
97
+ host = discover_host_from_facts(facts)
106
98
  r1 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc", :max_count => 1,
107
99
  :organizations => [host.organization], :locations => [host.location])
108
100
  r2 = FactoryGirl.create(:discovery_rule, :priority => 2, :search => "facts.somefact = abc",
@@ -113,7 +105,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
113
105
 
114
106
  test "discovery rule is associated after auto provisioning" do
115
107
  facts = @facts.merge({"somefact" => "abc"})
116
- host = Host::Discovered.import_host(facts)
108
+ host = discover_host_from_facts(facts)
117
109
  r1 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
118
110
  :organizations => [host.organization], :locations => [host.location])
119
111
  perform_auto_provision host, r1
@@ -125,7 +117,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
125
117
 
126
118
  test "auto provisioning fails for rule without a hostgroup" do
127
119
  facts = @facts.merge({"somefact" => "abc"})
128
- host = Host::Discovered.import_host(facts)
120
+ host = discover_host_from_facts(facts)
129
121
  r1 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
130
122
  :organizations => [host.organization], :locations => [host.location])
131
123
  r1.hostgroup = nil
@@ -137,7 +129,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
137
129
 
138
130
  test "existing rule revent from hostgroup deletion" do
139
131
  facts = @facts.merge({"somefact" => "abc"})
140
- host = Host::Discovered.import_host(facts)
132
+ host = discover_host_from_facts(facts)
141
133
  r1 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
142
134
  :organizations => [host.organization], :locations => [host.location])
143
135
  assert_raises(ActiveRecord::RecordNotDestroyed) do
@@ -147,7 +139,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
147
139
 
148
140
  test "rules with incorrect syntax are skipped" do
149
141
  facts = @facts.merge({"somefact" => "abc"})
150
- host = Host::Discovered.import_host(facts)
142
+ host = discover_host_from_facts(facts)
151
143
  FactoryGirl.create(:discovery_rule, :priority => 1, :search => '=!^$#@?x',
152
144
  :organizations => [host.organization], :locations => [host.location])
153
145
  r2 = FactoryGirl.create(:discovery_rule, :priority => 2, :search => "facts.somefact = abc",
@@ -157,7 +149,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
157
149
 
158
150
  test "hostname is copied after auto provisioning" do
159
151
  facts = @facts.merge({"somefact" => "abc"})
160
- host = Host::Discovered.import_host(facts)
152
+ host = discover_host_from_facts(facts)
161
153
  r1 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc",
162
154
  :organizations => [host.organization], :locations => [host.location])
163
155
  perform_auto_provision host, r1
@@ -168,7 +160,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
168
160
  facts = @facts.merge({"somefact" => "abc"})
169
161
  domain = FactoryGirl.create(:domain)
170
162
  subnet = FactoryGirl.create(:subnet_ipv4, :tftp, :dhcp, :name => 'subnet_100', :network => '192.168.100.0', :organizations => [Organization.find_by_name("Organization 1")], :locations => [Location.find_by_name("Location 1")])
171
- host = Host::Discovered.import_host(facts)
163
+ host = discover_host_from_facts(facts)
172
164
  assert_equal subnet, host.subnet
173
165
  hostgroup = FactoryGirl.create(:hostgroup, :with_environment, :with_rootpass, :with_puppet_orchestration, :with_os, :pxe_loader => "PXELinux BIOS", :subnet => subnet, :domain => domain)
174
166
  r1 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc", :organizations => [host.organization], :locations => [host.location], :hostgroup => hostgroup)
@@ -196,7 +188,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
196
188
 
197
189
  test "attributes from hostgroup are copied after auto provisioning for host without subnet detected" do
198
190
  facts = @facts.merge({"somefact" => "abc"})
199
- host = Host::Discovered.import_host(facts)
191
+ host = discover_host_from_facts(facts)
200
192
  refute host.subnet
201
193
  domain = FactoryGirl.create(:domain)
202
194
  subnet = FactoryGirl.create(:subnet_ipv4, :tftp, :dhcp, :name => 'subnet_100', :network => '192.168.100.0', :organizations => [Organization.find_by_name("Organization 1")], :locations => [Location.find_by_name("Location 1")])
@@ -245,7 +237,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
245
237
  end
246
238
 
247
239
  test "hostname falls back to original name on empty response via #{renderer_name}" do
248
- host = Host::Discovered.import_host(@facts)
240
+ host = discover_host_from_facts(@facts)
249
241
  r1 = FactoryGirl.create(:discovery_rule,
250
242
  :search => "facts.somefact = abc",
251
243
  :hostname => '<%= "" %>',
@@ -256,7 +248,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
256
248
  end
257
249
 
258
250
  test "hostname is rendered after auto provisioning using #{renderer_name}" do
259
- host = Host::Discovered.import_host(@facts)
251
+ host = discover_host_from_facts(@facts)
260
252
  r1 = FactoryGirl.create(:discovery_rule,
261
253
  :search => "facts.somefact = abc",
262
254
  :hostname => 'x<%= 1+1 %>',
@@ -267,7 +259,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
267
259
  end
268
260
 
269
261
  test "function rand is renderer properly using #{renderer_name}" do
270
- host = Host::Discovered.import_host(@facts)
262
+ host = discover_host_from_facts(@facts)
271
263
  r1 = FactoryGirl.create(:discovery_rule,
272
264
  :search => "facts.somefact = abc",
273
265
  :hostname => 'x<%= rand(4) %>',
@@ -278,7 +270,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
278
270
  end
279
271
 
280
272
  test "hostname attribute name is renderer properly using #{renderer_name}" do
281
- host = Host::Discovered.import_host(@facts)
273
+ host = discover_host_from_facts(@facts)
282
274
  r1 = FactoryGirl.create(:discovery_rule,
283
275
  :search => "facts.somefact = abc",
284
276
  :hostname => 'x<%= @host.name %>',
@@ -289,7 +281,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
289
281
  end
290
282
 
291
283
  test "hostname attribute ip is renderer properly using #{renderer_name}" do
292
- host = Host::Discovered.import_host(@facts)
284
+ host = discover_host_from_facts(@facts)
293
285
  r1 = FactoryGirl.create(:discovery_rule,
294
286
  :search => "facts.somefact = abc",
295
287
  :hostname => 'x<%= @host.ip.gsub(".","-") %>',
@@ -301,7 +293,7 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
301
293
 
302
294
  test "hostname attribute facts_hash is renderer properly using #{renderer_name}" do
303
295
  facts = @facts.merge({"somefact" => "abc"})
304
- host = Host::Discovered.import_host(facts)
296
+ host = discover_host_from_facts(facts)
305
297
  r1 = FactoryGirl.create(:discovery_rule,
306
298
  :search => "facts.somefact = abc",
307
299
  :hostname => 'x<%= @host.facts["somefact"] %>',
@@ -3,6 +3,7 @@ require 'test_plugin_helper'
3
3
  class DiscoveryAttributeSetTest < ActiveSupport::TestCase
4
4
 
5
5
  setup do
6
+ @facts = parse_json_fixture('/facts.json')['facts']
6
7
  FactoryGirl.create(:setting,
7
8
  :name => 'discovery_hostname',
8
9
  :value => 'discovery_bootif',
@@ -14,8 +15,7 @@ class DiscoveryAttributeSetTest < ActiveSupport::TestCase
14
15
  end
15
16
 
16
17
  test "can search discovered hosts by cpu" do
17
- raw = parse_json_fixture('/facts.json')
18
- host = Host::Discovered.import_host(raw['facts'])
18
+ host = discover_host_from_facts(@facts)
19
19
  results = Host::Discovered.search_for("cpu_count = #{host.facts_hash['physicalprocessorcount'].to_i}")
20
20
  assert_equal 1, results.count
21
21
  results = Host::Discovered.search_for("cpu_count > #{host.facts_hash['physicalprocessorcount'].to_i}")
@@ -23,8 +23,7 @@ class DiscoveryAttributeSetTest < ActiveSupport::TestCase
23
23
  end
24
24
 
25
25
  test "can search discovered hosts by memory" do
26
- raw = parse_json_fixture('/facts.json')
27
- host = Host::Discovered.import_host(raw['facts'])
26
+ host = discover_host_from_facts(@facts)
28
27
  results = Host::Discovered.search_for("memory = #{host.facts_hash['memorysize_mb'].to_f.ceil}")
29
28
  assert_equal 1, results.count
30
29
  results = Host::Discovered.search_for("memory > #{host.facts_hash['memorysize_mb'].to_f.ceil}")
@@ -32,8 +31,7 @@ class DiscoveryAttributeSetTest < ActiveSupport::TestCase
32
31
  end
33
32
 
34
33
  test "can search discovered hosts by disk_count" do
35
- raw = parse_json_fixture('/facts.json')
36
- host = Host::Discovered.import_host(raw['facts'])
34
+ host = discover_host_from_facts(@facts)
37
35
  results = Host::Discovered.search_for("disk_count = 1")
38
36
  assert_equal 1, results.count
39
37
  results = Host::Discovered.search_for("disk_count = 3")
@@ -41,8 +39,7 @@ class DiscoveryAttributeSetTest < ActiveSupport::TestCase
41
39
  end
42
40
 
43
41
  test "can search discovered hosts by disks_size" do
44
- raw = parse_json_fixture('/facts.json')
45
- host = Host::Discovered.import_host(raw['facts'])
42
+ host = discover_host_from_facts(@facts)
46
43
  disks_size = (host.facts_hash['blockdevice_sda_size'].to_f / 1024 / 1024).ceil
47
44
  results = Host::Discovered.search_for("disks_size = #{disks_size}")
48
45
  assert_equal 1, results.count
@@ -2,14 +2,14 @@ require 'test_plugin_helper'
2
2
 
3
3
  class DiscoveryTaxonomyExtensionsTest < ActiveSupport::TestCase
4
4
  setup do
5
+ @facts = parse_json_fixture('/facts.json')['facts']
5
6
  set_default_settings
6
7
  end
7
8
 
8
9
  test 'deleting location does not hard fail if there is associated discovered host' do
9
10
  location = FactoryGirl.create(:location)
10
11
 
11
- raw = parse_json_fixture('/facts.json')
12
- assert (host = Host::Discovered.import_host(raw['facts']))
12
+ assert (host = discover_host_from_facts(@facts))
13
13
  host.location = location
14
14
  assert host.save
15
15
 
@@ -2,6 +2,7 @@ require 'test_plugin_helper'
2
2
 
3
3
  class HostDiscoveredTest < ActiveSupport::TestCase
4
4
  setup do
5
+ @facts = parse_json_fixture('/facts.json')['facts']
5
6
  set_default_settings
6
7
  end
7
8
 
@@ -11,8 +12,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
11
12
  end
12
13
 
13
14
  test "should import facts from yaml as Host::Discovered" do
14
- raw = parse_json_fixture('/facts.json')
15
- assert Host::Discovered.import_host(raw['facts'])
15
+ assert discover_host_from_facts(@facts)
16
16
  assert Host::Discovered.find_by_name('mace41f13cc3658')
17
17
  end
18
18
 
@@ -26,7 +26,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
26
26
  raw = parse_json_fixture('/facts.json')
27
27
  subnet = FactoryGirl.create(:subnet_ipv4, :name => 'Subnet99', :network => '10.35.27.0', :organizations => [organization_one], :locations => [location_one])
28
28
  Subnet.expects(:subnet_for).with('10.35.27.3').returns(subnet)
29
- host = Host::Discovered.import_host(raw['facts'])
29
+ host = discover_host_from_facts(@facts)
30
30
  assert_equal subnet, host.primary_interface.subnet
31
31
  end
32
32
 
@@ -38,7 +38,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
38
38
  raw = parse_json_fixture('/facts.json')
39
39
  subnet = FactoryGirl.create(:subnet_ipv4, :name => 'Subnet99', :network => '10.35.27.0', :organizations => [org], :locations => [loc])
40
40
  Subnet.expects(:subnet_for).with('10.35.27.3').returns(subnet)
41
- host = Host::Discovered.import_host(raw['facts'])
41
+ host = discover_host_from_facts(@facts)
42
42
  assert_equal subnet, host.primary_interface.subnet
43
43
  end
44
44
 
@@ -46,11 +46,11 @@ class HostDiscoveredTest < ActiveSupport::TestCase
46
46
  org = FactoryGirl.create(:organization, :name => "subnet_org_via_fact")
47
47
  loc = FactoryGirl.create(:location, :name => "subnet_loc_via_fact")
48
48
  raw = parse_json_fixture('/facts.json')
49
- raw['facts']['foreman_organization'] = org.name
50
- raw['facts']['foreman_location'] = loc.name
49
+ @facts['foreman_organization'] = org.name
50
+ @facts['foreman_location'] = loc.name
51
51
  subnet = FactoryGirl.create(:subnet_ipv4, :name => 'Subnet99', :network => '10.35.27.0', :organizations => [org], :locations => [loc])
52
52
  Subnet.expects(:subnet_for).with('10.35.27.3').returns(subnet)
53
- host = Host::Discovered.import_host(raw['facts'])
53
+ host = discover_host_from_facts(@facts)
54
54
  assert_equal subnet, host.primary_interface.subnet
55
55
  end
56
56
 
@@ -64,7 +64,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
64
64
  raw = parse_json_fixture('/facts.json')
65
65
  subnet = FactoryGirl.create(:subnet_ipv4, :name => 'Subnet99', :network => '10.35.27.0', :organizations => [org], :locations => [loc])
66
66
  Subnet.expects(:subnet_for).with('10.35.27.3').returns(subnet)
67
- host = Host::Discovered.import_host(raw['facts'])
67
+ host = discover_host_from_facts(@facts)
68
68
  assert_equal org, host.organization
69
69
  assert_equal loc, host.location
70
70
  end
@@ -73,7 +73,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
73
73
  raw = parse_json_fixture('/facts.json')
74
74
  Setting[:discovery_fact] = 'macaddress_foo'
75
75
  exception = assert_raises(::Foreman::Exception) do
76
- Host::Discovered.import_host(raw['facts'])
76
+ discover_host_from_facts(@facts)
77
77
  end
78
78
  assert_match(/Expected discovery_fact '\w+' is missing/, exception.message)
79
79
  end
@@ -81,15 +81,15 @@ class HostDiscoveredTest < ActiveSupport::TestCase
81
81
  test "should be able to refresh facts" do
82
82
  host = Host.create :name => "mydiscoveredhost", :ip => "1.2.3.4", :type => "Host::Discovered"
83
83
  raw = parse_json_fixture('/facts.json')
84
- ::ForemanDiscovery::NodeAPI::Inventory.any_instance.stubs(:facter).returns(raw['facts'])
84
+ ::ForemanDiscovery::NodeAPI::Inventory.any_instance.stubs(:facter).returns(@facts)
85
85
  assert host.refresh_facts
86
86
  end
87
87
 
88
88
  test "should create discovered host with hostname if a fact was supplied" do
89
89
  raw = parse_json_fixture('/facts.json')
90
90
  Setting[:discovery_hostname] = 'somefact'
91
- facts = raw['facts'].merge({"somefact" => "somename"})
92
- host = Host::Discovered.import_host(facts)
91
+ facts = @facts.merge({"somefact" => "somename"})
92
+ host = discover_host_from_facts(facts)
93
93
  assert_equal 'macsomename', host.name
94
94
  refute_equal 'e4:1f:13:cc:36:5a', host.mac
95
95
  end
@@ -115,7 +115,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
115
115
  :template => "test"
116
116
  )
117
117
  end
118
- assert Host::Discovered.import_host(raw['facts'])
118
+ assert discover_host_from_facts(@facts)
119
119
  assert Host::Discovered.find_by_name('mace41f13cc3658')
120
120
  refute Host::Managed.find_by_name('mace41f13cc3658')
121
121
  end
@@ -124,8 +124,8 @@ class HostDiscoveredTest < ActiveSupport::TestCase
124
124
  raw = parse_json_fixture('/facts.json')
125
125
  Setting[:discovery_fact] = 'somefact'
126
126
  Setting[:discovery_hostname] = 'somefact'
127
- facts = raw['facts'].merge({"somefact" => "E4:1F:13:CC:36:5A"})
128
- host = Host::Discovered.import_host(facts)
127
+ facts = @facts.merge({"somefact" => "E4:1F:13:CC:36:5A"})
128
+ host = discover_host_from_facts(facts)
129
129
  assert_equal 'mace41f13cc365a', host.name
130
130
  assert_equal 'e4:1f:13:cc:36:5a', host.mac
131
131
  end
@@ -134,7 +134,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
134
134
  raw = parse_json_fixture('/facts.json')
135
135
  Setting[:discovery_fact] = 'lsbdistcodename'
136
136
  exception = assert_raises(::Foreman::Exception) do
137
- Host::Discovered.import_host(raw['facts'])
137
+ discover_host_from_facts(@facts)
138
138
  end
139
139
  assert_match(/Unable to detect primary interface using MAC/, exception.message)
140
140
  end
@@ -143,7 +143,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
143
143
  FactoryGirl.create(:host, :mac => 'E4:1F:13:CC:36:58')
144
144
  raw = parse_json_fixture('/facts.json')
145
145
  exception = assert_raises(::Foreman::Exception) do
146
- Host::Discovered.import_host(raw['facts'])
146
+ discover_host_from_facts(@facts)
147
147
  end
148
148
  assert_match(/Host already exists as managed/, exception.message)
149
149
  end
@@ -151,14 +151,14 @@ class HostDiscoveredTest < ActiveSupport::TestCase
151
151
  test "should create discovered host with prefix" do
152
152
  raw = parse_json_fixture('/facts.json')
153
153
  Setting[:discovery_prefix] = 'test'
154
- host = Host::Discovered.import_host(raw['facts'])
154
+ host = discover_host_from_facts(@facts)
155
155
  assert_equal 'teste41f13cc3658', host.name
156
156
  end
157
157
 
158
158
  test "should create discovered host without prefix" do
159
159
  raw = parse_json_fixture('/facts.json')
160
160
  Setting[:discovery_prefix] = ''
161
- host = Host::Discovered.import_host(raw['facts'])
161
+ host = discover_host_from_facts(@facts)
162
162
  assert_equal 'e41f13cc3658',host.name
163
163
  end
164
164
 
@@ -166,8 +166,8 @@ class HostDiscoveredTest < ActiveSupport::TestCase
166
166
  raw = parse_json_fixture('/facts.json')
167
167
  interface = mock()
168
168
  interface.stubs(:host).returns(Host.create(:name => "xyz", :type => "Host::Discovered"))
169
- ::Nic::Managed.stubs(:where).with(:mac => raw['facts']['discovery_bootif'].downcase, :primary => true).returns([interface])
170
- host = Host::Discovered.import_host(raw['facts'])
169
+ ::Nic::Managed.stubs(:where).with(:mac => @facts['discovery_bootif'].downcase, :primary => true).returns([interface])
170
+ host = discover_host_from_facts(@facts)
171
171
  assert_equal 'xyz', host.name
172
172
  end
173
173
 
@@ -175,18 +175,18 @@ class HostDiscoveredTest < ActiveSupport::TestCase
175
175
  raw = parse_json_fixture('/facts.json')
176
176
  Setting[:discovery_hostname] = 'macaddress_foo'
177
177
  exception = assert_raises(::Foreman::Exception) do
178
- Host::Discovered.import_host(raw['facts'])
178
+ discover_host_from_facts(@facts)
179
179
  end
180
180
  assert_match(/Invalid facts: hash does not contain a valid value for any of the facts in the discovery_hostname setting:/, exception.message)
181
181
  end
182
182
 
183
183
  test "should raise when hostname cannot be computed due to normlization and no prefix" do
184
184
  raw = parse_json_fixture('/facts.json')
185
- raw['facts']['invalidhostnamefact'] = '...'
185
+ @facts['invalidhostnamefact'] = '...'
186
186
  Setting[:discovery_hostname] = 'invalidhostnamefact'
187
187
  Setting[:discovery_prefix] = ''
188
188
  exception = assert_raises(::Foreman::Exception) do
189
- Host::Discovered.import_host(raw['facts'])
189
+ discover_host_from_facts(@facts)
190
190
  end
191
191
  assert_match(/Invalid hostname: Could not normalize the hostname/, exception.message)
192
192
  end
@@ -222,7 +222,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
222
222
  Setting[:token_duration] = 30 #enable tokens so that we only test the CR
223
223
  raw = parse_json_fixture('/facts.json')
224
224
  Setting[:discovery_prefix] = '123'
225
- host = Host::Discovered.import_host(raw['facts'])
225
+ host = discover_host_from_facts(@facts)
226
226
  host.save
227
227
  h = ::ForemanDiscovery::HostConverter.to_managed(host)
228
228
  refute_valid h
@@ -236,7 +236,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
236
236
  'delete_me' => "content",
237
237
  'discovery_keep_me' => "content",
238
238
  })
239
- host = Host::Discovered.import_host(raw)
239
+ host = discover_host_from_facts(raw)
240
240
  host.save
241
241
  managed = ::ForemanDiscovery::HostConverter.to_managed(host)
242
242
  managed.clear_facts
@@ -250,7 +250,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
250
250
  'keep_me' => "content",
251
251
  'discovery_keep_me' => "content",
252
252
  })
253
- host = Host::Discovered.import_host(raw)
253
+ host = discover_host_from_facts(raw)
254
254
  host.save
255
255
  managed = ::ForemanDiscovery::HostConverter.to_managed(host)
256
256
  refute_nil managed.primary_interface
@@ -263,7 +263,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
263
263
  'keep_me' => "content",
264
264
  'discovery_keep_me' => "content",
265
265
  })
266
- host = Host::Discovered.import_host(raw)
266
+ host = discover_host_from_facts(raw)
267
267
  host.save
268
268
  managed = ::ForemanDiscovery::HostConverter.to_managed(host)
269
269
  refute_nil managed.provision_interface
@@ -276,7 +276,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
276
276
  'keep_me' => "content",
277
277
  'discovery_keep_me' => "content",
278
278
  })
279
- host = Host::Discovered.import_host(raw)
279
+ host = discover_host_from_facts(raw)
280
280
  host.save
281
281
  managed = ::ForemanDiscovery::HostConverter.to_managed(host)
282
282
  refute_nil managed.provision_interface
@@ -289,7 +289,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
289
289
  'keep_me' => "content",
290
290
  'discovery_keep_me' => "content",
291
291
  })
292
- host = Host::Discovered.import_host(raw)
292
+ host = discover_host_from_facts(raw)
293
293
  host.save
294
294
  managed = ::ForemanDiscovery::HostConverter.to_managed(host)
295
295
  managed.clear_facts