foreman_discovery 15.1.0 → 16.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v2/discovered_hosts_controller.rb +10 -3
  3. data/app/controllers/api/v2/discovery_rules_controller.rb +1 -1
  4. data/app/controllers/concerns/foreman/controller/discovered_extensions.rb +4 -0
  5. data/app/controllers/discovered_hosts_controller.rb +1 -0
  6. data/app/controllers/discovery_rules_controller.rb +1 -1
  7. data/app/models/discovery_rule.rb +1 -1
  8. data/app/models/host/discovered.rb +39 -17
  9. data/app/models/host/managed_extensions.rb +2 -2
  10. data/app/models/setting/discovered.rb +26 -33
  11. data/app/services/foreman_discovery/fact_parser.rb +1 -1
  12. data/app/services/foreman_discovery/host_converter.rb +38 -2
  13. data/app/services/foreman_discovery/import_hooks/subnet_and_taxonomy.rb +6 -14
  14. data/app/services/foreman_discovery/node_api/node_resource.rb +1 -0
  15. data/app/services/foreman_discovery/subnet_suggestion.rb +26 -0
  16. data/app/views/discovered_hosts/_discovered_host_modal.html.erb +2 -0
  17. data/app/views/foreman_discovery/debian_kexec.erb +1 -1
  18. data/config/routes.rb +2 -0
  19. data/db/migrate/20150512150432_remove_old_discovery_reader_permissions.rb +1 -1
  20. data/db/migrate/20151023144501_regenerate_red_hat_kexec.rb +1 -1
  21. data/db/migrate/20180412124505_add_priority_score_to_discovery_rules.rb +1 -1
  22. data/extra/discover-host +21 -7
  23. data/lib/foreman_discovery/engine.rb +4 -4
  24. data/lib/foreman_discovery/version.rb +1 -1
  25. data/locale/ca/LC_MESSAGES/foreman_discovery.mo +0 -0
  26. data/locale/ca/foreman_discovery.edit.po +226 -263
  27. data/locale/ca/foreman_discovery.po +28 -8
  28. data/locale/de/LC_MESSAGES/foreman_discovery.mo +0 -0
  29. data/locale/de/foreman_discovery.edit.po +229 -265
  30. data/locale/de/foreman_discovery.po +31 -11
  31. data/locale/en/LC_MESSAGES/foreman_discovery.mo +0 -0
  32. data/locale/en/foreman_discovery.edit.po +169 -119
  33. data/locale/en/foreman_discovery.po +24 -4
  34. data/locale/en_GB/LC_MESSAGES/foreman_discovery.mo +0 -0
  35. data/locale/en_GB/foreman_discovery.edit.po +237 -266
  36. data/locale/en_GB/foreman_discovery.po +31 -11
  37. data/locale/es/LC_MESSAGES/foreman_discovery.mo +0 -0
  38. data/locale/es/foreman_discovery.edit.po +236 -265
  39. data/locale/es/foreman_discovery.po +30 -10
  40. data/locale/foreman_discovery.pot +110 -84
  41. data/locale/fr/LC_MESSAGES/foreman_discovery.mo +0 -0
  42. data/locale/fr/foreman_discovery.edit.po +230 -262
  43. data/locale/fr/foreman_discovery.po +28 -8
  44. data/locale/gl/LC_MESSAGES/foreman_discovery.mo +0 -0
  45. data/locale/gl/foreman_discovery.edit.po +221 -261
  46. data/locale/gl/foreman_discovery.po +26 -6
  47. data/locale/it/LC_MESSAGES/foreman_discovery.mo +0 -0
  48. data/locale/it/foreman_discovery.edit.po +221 -261
  49. data/locale/it/foreman_discovery.po +26 -6
  50. data/locale/ja/LC_MESSAGES/foreman_discovery.mo +0 -0
  51. data/locale/ja/foreman_discovery.edit.po +235 -264
  52. data/locale/ja/foreman_discovery.po +29 -9
  53. data/locale/ko/LC_MESSAGES/foreman_discovery.mo +0 -0
  54. data/locale/ko/foreman_discovery.edit.po +223 -262
  55. data/locale/ko/foreman_discovery.po +28 -8
  56. data/locale/pt_BR/LC_MESSAGES/foreman_discovery.mo +0 -0
  57. data/locale/pt_BR/foreman_discovery.edit.po +233 -264
  58. data/locale/pt_BR/foreman_discovery.po +29 -9
  59. data/locale/ru/LC_MESSAGES/foreman_discovery.mo +0 -0
  60. data/locale/ru/foreman_discovery.edit.po +227 -265
  61. data/locale/ru/foreman_discovery.po +29 -9
  62. data/locale/sv_SE/LC_MESSAGES/foreman_discovery.mo +0 -0
  63. data/locale/sv_SE/foreman_discovery.edit.po +222 -262
  64. data/locale/sv_SE/foreman_discovery.po +27 -7
  65. data/locale/zh_CN/LC_MESSAGES/foreman_discovery.mo +0 -0
  66. data/locale/zh_CN/foreman_discovery.edit.po +234 -263
  67. data/locale/zh_CN/foreman_discovery.po +28 -8
  68. data/locale/zh_TW/LC_MESSAGES/foreman_discovery.mo +0 -0
  69. data/locale/zh_TW/foreman_discovery.edit.po +223 -261
  70. data/locale/zh_TW/foreman_discovery.po +26 -6
  71. data/test/facts/bond0-eth0-eth1-active-passive.json +128 -0
  72. data/test/facts/facts_with_lldp_bond_candidate.json +2 -9
  73. data/test/functional/api/v2/discovered_hosts_controller_test.rb +1 -0
  74. data/test/functional/discovered_hosts_controller_test.rb +15 -6
  75. data/test/integration/discovered_hosts_test.rb +1 -0
  76. data/test/test_helper_discovery.rb +12 -0
  77. data/test/unit/discovered_extensions_test.rb +54 -0
  78. data/test/unit/discovery_attribute_set_test.rb +1 -0
  79. data/test/unit/discovery_rule_test.rb +1 -0
  80. data/test/unit/host_discovered_test.rb +32 -13
  81. data/test/unit/managed_extensions_test.rb +2 -0
  82. metadata +36 -31
@@ -5,10 +5,10 @@
5
5
  # Translators:
6
6
  msgid ""
7
7
  msgstr ""
8
- "Project-Id-Version: foreman_discovery 15.0.0\n"
8
+ "Project-Id-Version: foreman_discovery 16.0.1\n"
9
9
  "Report-Msgid-Bugs-To: \n"
10
- "PO-Revision-Date: 2019-04-18 19:36+0000\n"
11
- "Last-Translator: Lukáš Zapletal\n"
10
+ "PO-Revision-Date: 2020-05-26 17:21+0000\n"
11
+ "Last-Translator: Transifex Bot <>\n"
12
12
  "Language-Team: Chinese (Taiwan) (http://www.transifex.com/foreman/foreman/lang"
13
13
  "uage/zh_TW/)\n"
14
14
  "MIME-Version: 1.0\n"
@@ -32,6 +32,9 @@ msgstr ""
32
32
  msgid "A summary of discovered hosts"
33
33
  msgstr ""
34
34
 
35
+ msgid "Action with sub plans"
36
+ msgstr ""
37
+
35
38
  msgid "Actions"
36
39
  msgstr "動作"
37
40
 
@@ -134,6 +137,11 @@ msgstr "停用"
134
137
  msgid "Disable rule '%s'?"
135
138
  msgstr ""
136
139
 
140
+ msgid "Discovered Host"
141
+ msgid_plural "Discovered Hosts"
142
+ msgstr[0] ""
143
+ msgstr[1] ""
144
+
137
145
  msgid "Discovered Hosts"
138
146
  msgstr ""
139
147
 
@@ -345,6 +353,9 @@ msgstr "IP 位址"
345
353
  msgid "IP address"
346
354
  msgstr "IP 位址"
347
355
 
356
+ msgid "IPAM must be configured for subnet '%s'"
357
+ msgstr ""
358
+
348
359
  msgid "IPMI"
349
360
  msgstr "IPMI"
350
361
 
@@ -360,6 +371,12 @@ msgstr ""
360
371
  msgid "Image API returned HTTP/%{code} with '%{body}"
361
372
  msgstr ""
362
373
 
374
+ msgid "Import Puppet classes"
375
+ msgstr ""
376
+
377
+ msgid "Import facts"
378
+ msgstr ""
379
+
363
380
  msgid "In addition to @host attribute function rand for random integers is available. Examples:"
364
381
  msgstr ""
365
382
 
@@ -576,6 +593,9 @@ msgstr ""
576
593
  msgid "Reloading kernel on %s"
577
594
  msgstr ""
578
595
 
596
+ msgid "Remote action:"
597
+ msgstr ""
598
+
579
599
  msgid "Reported in the last 7 days"
580
600
  msgstr ""
581
601
 
@@ -675,13 +695,13 @@ msgstr ""
675
695
  msgid "Unable to find primary NIC with %{mac} specified via '%{fact}', NIC filter: %{filter}"
676
696
  msgstr ""
677
697
 
678
- msgid "Unable to perform kexec on %{name} via %{url}: %{msg}"
698
+ msgid "Unable to perform kexec on %{name} (%{url}): %{msg}"
679
699
  msgstr ""
680
700
 
681
- msgid "Unable to provision %{host}: %{errors}"
701
+ msgid "Unable to perform reboot on %{name} (%{url}): %{msg}"
682
702
  msgstr ""
683
703
 
684
- msgid "Unable to reboot %{name} via %{url}: %{msg}"
704
+ msgid "Unable to provision %{host}: %{errors}"
685
705
  msgstr ""
686
706
 
687
707
  msgid "Update a rule"
@@ -0,0 +1,128 @@
1
+ {
2
+ "uptime_seconds": 206,
3
+ "architecture": "x86_64",
4
+ "virtual": "kvm",
5
+ "is_virtual": true,
6
+ "kernel": "Linux",
7
+ "blockdevice_vda_size": 6442450944,
8
+ "blockdevice_vda_vendor": "0x1af4",
9
+ "blockdevices": "vda",
10
+ "dhcp_servers": {
11
+ "system": "192.168.122.1",
12
+ "bond0": "192.168.122.1"
13
+ },
14
+ "domain": "nat.lan",
15
+ "hardwaremodel": "x86_64",
16
+ "operatingsystem": "CentOS",
17
+ "os": {
18
+ "name": "CentOS",
19
+ "family": "RedHat",
20
+ "release": {
21
+ "major": "7",
22
+ "minor": "6",
23
+ "full": "7.6.1810"
24
+ }
25
+ },
26
+ "facterversion": "2.4.1",
27
+ "filesystems": "xfs",
28
+ "fqdn": "localhost.nat.lan",
29
+ "gid": "root",
30
+ "hardwareisa": "x86_64",
31
+ "hostname": "localhost",
32
+ "id": "root",
33
+ "interfaces": "bond0,eth0,eth1,lo",
34
+ "ipaddress_bond0": "192.168.122.7",
35
+ "macaddress_bond0": "52:54:00:fd:1e:62",
36
+ "netmask_bond0": "255.255.255.0",
37
+ "mtu_bond0": 1500,
38
+ "macaddress_eth0": "52:54:00:FD:1E:62",
39
+ "mtu_eth0": 1500,
40
+ "macaddress_eth1": "52:54:00:7C:84:DA",
41
+ "mtu_eth1": 1500,
42
+ "ipaddress_lo": "127.0.0.1",
43
+ "netmask_lo": "255.0.0.0",
44
+ "mtu_lo": 65536,
45
+ "ipaddress": "192.168.122.7",
46
+ "kernelmajversion": "3.10",
47
+ "kernelrelease": "3.10.0-957.el7.x86_64",
48
+ "kernelversion": "3.10.0",
49
+ "rubyplatform": "x86_64-linux",
50
+ "macaddress": "52:54:00:fd:1e:62",
51
+ "bios_vendor": "SeaBIOS",
52
+ "bios_version": "1.12.0-2.fc30",
53
+ "bios_release_date": "04/01/2014",
54
+ "manufacturer": "QEMU",
55
+ "productname": "Standard PC (Q35 + ICH9, 2009)",
56
+ "serialnumber": "Not Specified",
57
+ "uuid": "d1e61ef9-663e-4195-b256-f64b9f8cc8ae",
58
+ "type": "Other",
59
+ "memorysize": "8.41 GB",
60
+ "memoryfree": "8.20 GB",
61
+ "swapsize": "615.00 MB",
62
+ "swapfree": "615.00 MB",
63
+ "swapsize_mb": "615.00",
64
+ "swapfree_mb": "615.00",
65
+ "memorysize_mb": "8615.46",
66
+ "memoryfree_mb": "8395.15",
67
+ "netmask": "255.255.255.0",
68
+ "network_bond0": "192.168.122.0",
69
+ "network_lo": "127.0.0.0",
70
+ "uptime_hours": 0,
71
+ "operatingsystemmajrelease": "7",
72
+ "rubysitedir": "/usr/local/share/ruby/site_ruby/",
73
+ "operatingsystemrelease": "7.6.1810",
74
+ "osfamily": "RedHat",
75
+ "partitions": {
76
+ "vda1": {
77
+ "size": "2048"
78
+ },
79
+ "vda2": {
80
+ "uuid": "1f259325-5eb4-4334-81f3-699ace4a28ff",
81
+ "size": "2097152",
82
+ "mount": "/boot",
83
+ "filesystem": "xfs"
84
+ },
85
+ "vda3": {
86
+ "uuid": "6639b5c4-1ba1-41d6-a4a0-6253eeaaae05",
87
+ "size": "1259520",
88
+ "filesystem": "swap"
89
+ },
90
+ "vda4": {
91
+ "uuid": "09aced65-5b86-4efe-9da0-c86a3311e1b8",
92
+ "size": "9220096",
93
+ "mount": "/",
94
+ "filesystem": "xfs"
95
+ }
96
+ },
97
+ "path": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin",
98
+ "rubyversion": "2.0.0",
99
+ "physicalprocessorcount": 2,
100
+ "processors": {
101
+ "models": [
102
+ "AMD EPYC Processor (with IBPB)",
103
+ "AMD EPYC Processor (with IBPB)"
104
+ ],
105
+ "count": 2,
106
+ "physicalcount": 2
107
+ },
108
+ "processor0": "AMD EPYC Processor (with IBPB)",
109
+ "processor1": "AMD EPYC Processor (with IBPB)",
110
+ "processorcount": 2,
111
+ "ps": "ps -ef",
112
+ "selinux": true,
113
+ "selinux_enforced": true,
114
+ "selinux_policyversion": "31",
115
+ "selinux_current_mode": "enforcing",
116
+ "selinux_config_mode": "enforcing",
117
+ "selinux_config_policy": "unknown",
118
+ "system_uptime": {
119
+ "seconds": 206,
120
+ "hours": 0,
121
+ "days": 0,
122
+ "uptime": "0:03 hours"
123
+ },
124
+ "timezone": "EDT",
125
+ "uniqueid": "007f0100",
126
+ "uptime": "0:03 hours",
127
+ "uptime_days": 0
128
+ }
@@ -6,14 +6,11 @@
6
6
  "kernelmajversion": "2.6",
7
7
  "kernelversion": "2.6.32",
8
8
  "macaddress_vnet0": "FE:54:00:1E:45:13",
9
- "macaddress_br181": "E4:1F:13:CC:36:58",
10
9
  "macaddress_usb0": "E6:1F:13:D0:43:A3",
11
10
  "macaddress_vnet1": "FE:54:00:45:E5:3E",
12
11
  "rubysitedir": "/usr/lib/ruby/site_ruby/1.8",
13
- "macaddress_br182": "E4:1F:13:CC:36:58",
14
12
  "processor4": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
15
13
  "macaddress_vnet2": "FE:54:00:93:F5:56",
16
- "macaddress_br183": "E4:1F:13:CC:36:58",
17
14
  "ps": "ps -ef",
18
15
  "processor5": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
19
16
  "macaddress_vnet10": "FE:54:00:7D:F8:24",
@@ -28,16 +25,15 @@
28
25
  "macaddress_vnet4": "FE:54:00:62:53:67",
29
26
  "hostname": "h02",
30
27
  "osfamily": "RedHat",
31
- "gateway_if": "br180",
28
+ "gateway_if": "eth0",
32
29
  "lsbrelease": ":core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch",
33
30
  "kernelrelease": "2.6.32-131.12.1.el6.x86_64",
34
31
  "kernel": "Linux",
35
32
  "facterversion": "1.6.2",
36
33
  "uptime_seconds": "13651752",
37
34
  "macaddress_vnet5": "FE:54:00:01:B9:9C",
38
- "interfaces": "br180,br181,br182,br183,eth0,eth0_181,eth0_182,eth0_183,eth1,lo,usb0,vnet0,vnet1,vnet2,vnet3,vnet4,vnet5,vnet7,vnet10",
35
+ "interfaces": "eth0,eth0_181,eth0_182,eth0_183,eth1,lo,usb0,vnet0,vnet1,vnet2,vnet3,vnet4,vnet5,vnet7,vnet10",
39
36
  "macaddress_vnet7": "FE:54:00:D8:F9:38",
40
- "netmask_br180": "255.255.255.192",
41
37
  "macaddress_eth0": "E4:1F:13:CC:36:58",
42
38
  "is_virtual": "false",
43
39
  "macaddress": "E4:1F:13:CC:36:58",
@@ -47,7 +43,6 @@
47
43
  "macaddress_eth1": "E4:1F:13:CC:36:5A",
48
44
  "timezone": "GMT",
49
45
  "fqdn": "a.server.b.domain",
50
- "ipaddress_br180": "10.35.27.2",
51
46
  "ipaddress_eth0": "10.35.27.3",
52
47
  "ipaddress_eth1": "10.35.27.4",
53
48
  "puppetversion": "2.6.12",
@@ -69,12 +64,10 @@
69
64
  "network_lo": "127.0.0.0",
70
65
  "gateway": "10.35.27.62",
71
66
  "lsbdistid": "RedHatEnterpriseServer",
72
- "network_br180": "10.35.27.0",
73
67
  "lsbdistdescription": "Red Hat Enterprise Linux Server release 6.2 (Santiago)",
74
68
  "swapsize": "17.70 GB",
75
69
  "processor0": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
76
70
  "processor1": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
77
- "macaddress_br180": "E4:1F:13:CC:36:58",
78
71
  "selinux": "false",
79
72
  "domain": "server.b.domain",
80
73
  "architecture": "x86_64",
@@ -25,6 +25,7 @@ class Api::V2::DiscoveredHostsControllerTest < ActionController::TestCase
25
25
  }
26
26
  set_default_settings
27
27
  ::ForemanDiscovery::NodeAPI::PowerService.any_instance.stubs(:reboot).returns(true)
28
+ ::ForemanDiscovery::HostConverter.stubs(:unused_ip_for_host)
28
29
  end
29
30
 
30
31
  def test_get_index
@@ -8,7 +8,7 @@ class DiscoveredHostsControllerTest < ActionController::TestCase
8
8
  setup do
9
9
  assert discovered_notification_blueprint
10
10
  @request.env['HTTP_REFERER'] = '/discovery_rules'
11
- FactoryBot.create(:subnet, :network => "192.168.100.1", :mask => "255.255.255.0", :locations => [location_one], :organizations => [organization_one])
11
+ FactoryBot.create(:subnet, :dhcp, :network => "192.168.100.1", :mask => "255.255.255.0", :locations => [location_one], :organizations => [organization_one])
12
12
  @facts = {
13
13
  "interfaces" => "lo,eth0",
14
14
  "ipaddress" => "192.168.100.42",
@@ -115,7 +115,7 @@ class DiscoveredHostsControllerTest < ActionController::TestCase
115
115
  } }, session: set_session_user_default_manager
116
116
  # all inherit buttons are pressed
117
117
  assert_select('button[name=is_overridden_btn]') do |e|
118
- e.attribute("class") =~ /active/
118
+ e.attribute("class").to_s =~ /active/
119
119
  end
120
120
  # particular fields are set
121
121
  assert_select '#host_hostgroup_id [selected]' do |e|
@@ -140,6 +140,7 @@ class DiscoveredHostsControllerTest < ActionController::TestCase
140
140
 
141
141
  def test_update_inheritance
142
142
  host = discover_host_from_facts(@facts)
143
+ ForemanDiscovery::HostConverter.stubs(:unused_ip_for_subnet).returns(host.ip)
143
144
  hostgroup = setup_hostgroup(host)
144
145
  put :update, params: {
145
146
  commit: 'Update',
@@ -186,7 +187,7 @@ class DiscoveredHostsControllerTest < ActionController::TestCase
186
187
  ::ForemanDiscovery::NodeAPI::PowerService.any_instance.expects(:reboot).returns(false)
187
188
  post :reboot, params: { :id => host.id }, session: set_session_user_default_manager
188
189
  assert_redirected_to discovered_hosts_url
189
- assert_equal "Failed to reboot host #{host.name}", flash[:error]
190
+ assert_match(/ERF42-4036/, flash[:error])
190
191
  end
191
192
 
192
193
  def test_reboot_error
@@ -195,7 +196,7 @@ class DiscoveredHostsControllerTest < ActionController::TestCase
195
196
  ::ForemanDiscovery::NodeAPI::PowerService.any_instance.expects(:reboot).raises("request failed")
196
197
  post :reboot, params: { :id => host.id }, session: set_session_user_default_manager
197
198
  assert_redirected_to discovered_hosts_url
198
- assert_match(/ERF50-4973/, flash[:error])
199
+ assert_match(/ERF42-4036/, flash[:error])
199
200
  end
200
201
 
201
202
  def test_auto_provision_success
@@ -274,7 +275,7 @@ class DiscoveredHostsControllerTest < ActionController::TestCase
274
275
  ::ForemanDiscovery::NodeAPI::PowerService.any_instance.expects(:reboot).returns(false)
275
276
  post :submit_multiple_reboot, params: {:host_ids => host.id}, session: set_session_user(User.current)
276
277
  assert_redirected_to discovered_hosts_url
277
- assert_equal "Errors during reboot: #{host.name}: failed to reboot", flash[:error]
278
+ assert_match(/ERF42-4036/, flash[:error])
278
279
  assert_nil flash[:success]
279
280
  end
280
281
 
@@ -284,12 +285,15 @@ class DiscoveredHostsControllerTest < ActionController::TestCase
284
285
  ::ForemanDiscovery::NodeAPI::PowerService.any_instance.expects(:reboot).raises("request failed")
285
286
  post :submit_multiple_reboot, params: {:host_ids => host.id}, session: set_session_user(User.current)
286
287
  assert_redirected_to discovered_hosts_url
287
- assert_match(/ERF50-4973/, flash[:error])
288
+ assert_match(/ERF42-4036/, flash[:error])
288
289
  assert_nil flash[:success]
289
290
  end
290
291
 
291
292
  def test_no_dns_rebuild_if_dns_pending
292
293
  host = discover_host_from_facts(@facts)
294
+ ForemanDiscovery::HostConverter.stubs(:unused_ip_for_subnet).returns(host.ip)
295
+ Nic::Managed.any_instance.stubs(:dhcp_update_required?).returns(false)
296
+ Net::DHCP::Record.any_instance.stubs(:conflicting?).returns(false)
293
297
  hostgroup = prepare_hostgroup_for_dns_rebuild(host)
294
298
  Nic::Managed.any_instance.expects(:rebuild_dns).never
295
299
  Host::Managed.any_instance.stubs(:skip_orchestration?).returns(false)
@@ -306,6 +310,9 @@ class DiscoveredHostsControllerTest < ActionController::TestCase
306
310
 
307
311
  def test_dns_rebuild
308
312
  host = prepare_host_for_dns_rebuild
313
+ ForemanDiscovery::HostConverter.stubs(:unused_ip_for_subnet).returns(host.ip)
314
+ Nic::Managed.any_instance.stubs(:dhcp_update_required?).returns(false)
315
+ Net::DHCP::Record.any_instance.stubs(:conflicting?).returns(false)
309
316
  hostgroup = prepare_hostgroup_for_dns_rebuild(host)
310
317
  Nic::Managed.any_instance.expects(:rebuild_dns)
311
318
  Host::Managed.any_instance.stubs(:skip_orchestration?).returns(false)
@@ -319,6 +326,8 @@ class DiscoveredHostsControllerTest < ActionController::TestCase
319
326
 
320
327
  def test_dns_rebuild_with_auto_provision
321
328
  host = prepare_host_for_dns_rebuild
329
+ ForemanDiscovery::HostConverter.stubs(:unused_ip_for_subnet).returns(host.ip)
330
+ Nic::Managed.any_instance.stubs(:dhcp_update_required?).returns(false)
322
331
  hostgroup = prepare_hostgroup_for_dns_rebuild(host)
323
332
  Nic::Managed.any_instance.expects(:rebuild_dns)
324
333
  Host::Managed.any_instance.stubs(:skip_orchestration?).returns(false)
@@ -10,6 +10,7 @@ class DiscoveredHostsTest < IntegrationTestWithJavascript
10
10
  discovered_host.save!
11
11
  visit discovered_hosts_path
12
12
  page.evaluate_script("document.getElementById('fixedPropertiesSelector-#{discovered_host.id}').classList.remove('fade')")
13
+ ::ForemanDiscovery::HostConverter.stubs(:unused_ip_for_host)
13
14
  end
14
15
 
15
16
  teardown do
@@ -133,6 +133,18 @@ def facts_simple_network100_42
133
133
  }
134
134
  end
135
135
 
136
+ def facts_network_2001_db8
137
+ {
138
+ "interfaces" => "lo,eth0,eth1",
139
+ "ipaddress6" => "2001:db8::1",
140
+ "ipaddress6_eth0" => "2001:db8::1",
141
+ "ipaddress6_eth1" => "2001:db9::1",
142
+ "macaddress_eth0" => "AA:BB:CC:DD:EE:FA",
143
+ "macaddress_eth1" => "AA:BB:CC:DD:EE:FB",
144
+ "discovery_bootif" => "AA:BB:CC:DD:EE:FA",
145
+ }
146
+ end
147
+
136
148
  def discover_host_from_facts(facts)
137
149
  User.as_anonymous_admin do
138
150
  Host::Discovered.import_host(facts)
@@ -7,7 +7,10 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
7
7
 
8
8
  setup do
9
9
  @facts = facts_simple_network100_42
10
+ @facts_ipv6 = facts_network_2001_db8
10
11
  set_default_settings
12
+ ProxyAPI::DHCP.any_instance.stubs(:record).returns(nil)
13
+ ::ForemanDiscovery::HostConverter.stubs(:unused_ip_for_host)
11
14
  end
12
15
 
13
16
  test "no rule is found for empty rule set" do
@@ -179,6 +182,57 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
179
182
  assert_equal hostgroup.puppet_ca_proxy, managed_host.puppet_ca_proxy
180
183
  end
181
184
 
185
+ class StubIPAM
186
+ def suggest_ip
187
+ "192.168.101.13"
188
+ end
189
+ end
190
+
191
+ test "subnet is changed and unused_ip called" do
192
+ ::ForemanDiscovery::HostConverter.unstub(:unused_ip_for_host)
193
+ facts = @facts.merge({"somefact" => "abc"})
194
+ domain = FactoryBot.create(:domain)
195
+ subnet = FactoryBot.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")])
196
+ subnet2 = FactoryBot.create(:subnet_ipv4, :tftp, :dhcp, :name => 'subnet_101', :network => '192.168.101.0', :organizations => [Organization.find_by_name("Organization 1")], :locations => [Location.find_by_name("Location 1")])
197
+ host = discover_host_from_facts(facts)
198
+ assert_equal subnet, host.subnet
199
+ hostgroup = FactoryBot.create(:hostgroup, :with_environment, :with_rootpass, :with_puppet_orchestration, :with_os, :pxe_loader => "PXELinux BIOS", :subnet => subnet2, :domain => domain)
200
+ r1 = FactoryBot.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc", :organizations => [host.organization], :locations => [host.location], :hostgroup => hostgroup)
201
+ Subnet.any_instance.expects(:unused_ip).with(host.mac).returns(StubIPAM.new)
202
+ host.primary_interface.stubs(:queue_tftp)
203
+ host.primary_interface.stubs(:queue_dhcp)
204
+ managed_host = perform_auto_provision(host, r1)
205
+ assert_empty host.errors
206
+ assert managed_host
207
+ assert_empty managed_host.errors
208
+ refute_nil hostgroup.subnet
209
+ refute_nil managed_host.subnet
210
+ assert_equal hostgroup.subnet, managed_host.subnet
211
+ assert_equal "192.168.101.13", managed_host.ip
212
+ end
213
+
214
+ test "subnet6 is changed and unused_ip called" do
215
+ ::ForemanDiscovery::HostConverter.unstub(:unused_ip_for_host)
216
+ facts = @facts_ipv6.merge({"somefact" => "abc"})
217
+ domain = FactoryBot.create(:domain)
218
+ subnet = FactoryBot.create(:subnet_ipv6, :tftp, :dhcp, :network => "2001:db8::/32", :mask => "ffff:ffff::", :name => "ipv6_discovered", :ipam => IPAM::MODES[:eui64], :organizations => [Organization.find_by_name("Organization 1")], :locations => [Location.find_by_name("Location 1")])
219
+ subnet2 = FactoryBot.create(:subnet_ipv6, :tftp, :dhcp, :network => "2001:db9::/32", :mask => "ffff:ffff::", :name => "ipv6_provision", :ipam => IPAM::MODES[:eui64], :organizations => [Organization.find_by_name("Organization 1")], :locations => [Location.find_by_name("Location 1")])
220
+ host = discover_host_from_facts(facts)
221
+ assert_equal subnet, host.subnet6
222
+ hostgroup = FactoryBot.create(:hostgroup, :with_environment, :with_rootpass, :with_puppet_orchestration, :with_os, :pxe_loader => "PXELinux BIOS", :subnet6 => subnet2, :domain => domain)
223
+ r1 = FactoryBot.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc", :organizations => [host.organization], :locations => [host.location], :hostgroup => hostgroup)
224
+ host.primary_interface.stubs(:queue_tftp)
225
+ host.primary_interface.stubs(:queue_dhcp)
226
+ managed_host = perform_auto_provision(host, r1)
227
+ assert_empty host.errors
228
+ assert managed_host
229
+ assert_empty managed_host.errors
230
+ refute_nil hostgroup.subnet6
231
+ refute_nil managed_host.subnet6
232
+ assert_equal hostgroup.subnet6, managed_host.subnet6
233
+ assert_equal "2001:db9::a8bb:ccff:fedd:eefa", managed_host.ip6
234
+ end
235
+
182
236
  test "attributes from hostgroup are copied after auto provisioning for host without subnet detected" do
183
237
  facts = @facts.merge({"somefact" => "abc"})
184
238
  host = discover_host_from_facts(facts)