foreman_discovery 15.0.2 → 16.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v2/discovery_rules_controller.rb +1 -1
  3. data/app/controllers/concerns/foreman/controller/discovered_extensions.rb +4 -0
  4. data/app/controllers/discovered_hosts_controller.rb +6 -3
  5. data/app/controllers/discovery_rules_controller.rb +1 -1
  6. data/app/models/discovery_rule.rb +1 -1
  7. data/app/models/host/discovered.rb +49 -31
  8. data/app/models/host/managed_extensions.rb +2 -2
  9. data/app/models/setting/discovered.rb +28 -33
  10. data/app/services/foreman_discovery/fact_parser.rb +1 -1
  11. data/app/services/foreman_discovery/host_converter.rb +38 -2
  12. data/app/services/foreman_discovery/host_fact_importer.rb +10 -0
  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/foreman_discovery/debian_kexec.erb +3 -2
  17. data/app/views/foreman_discovery/redhat_kexec.erb +2 -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 +34 -14
  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 +122 -93
  27. data/locale/ca/foreman_discovery.po +31 -8
  28. data/locale/de/LC_MESSAGES/foreman_discovery.mo +0 -0
  29. data/locale/de/foreman_discovery.edit.po +125 -96
  30. data/locale/de/foreman_discovery.po +34 -11
  31. data/locale/en/LC_MESSAGES/foreman_discovery.mo +0 -0
  32. data/locale/en/foreman_discovery.edit.po +118 -88
  33. data/locale/en/foreman_discovery.po +27 -4
  34. data/locale/en_GB/LC_MESSAGES/foreman_discovery.mo +0 -0
  35. data/locale/en_GB/foreman_discovery.edit.po +125 -96
  36. data/locale/en_GB/foreman_discovery.po +34 -11
  37. data/locale/es/LC_MESSAGES/foreman_discovery.mo +0 -0
  38. data/locale/es/foreman_discovery.edit.po +124 -95
  39. data/locale/es/foreman_discovery.po +33 -10
  40. data/locale/foreman_discovery.pot +119 -89
  41. data/locale/fr/LC_MESSAGES/foreman_discovery.mo +0 -0
  42. data/locale/fr/foreman_discovery.edit.po +122 -93
  43. data/locale/fr/foreman_discovery.po +31 -8
  44. data/locale/gl/LC_MESSAGES/foreman_discovery.mo +0 -0
  45. data/locale/gl/foreman_discovery.edit.po +120 -91
  46. data/locale/gl/foreman_discovery.po +29 -6
  47. data/locale/it/LC_MESSAGES/foreman_discovery.mo +0 -0
  48. data/locale/it/foreman_discovery.edit.po +120 -91
  49. data/locale/it/foreman_discovery.po +29 -6
  50. data/locale/ja/LC_MESSAGES/foreman_discovery.mo +0 -0
  51. data/locale/ja/foreman_discovery.edit.po +123 -94
  52. data/locale/ja/foreman_discovery.po +32 -9
  53. data/locale/ko/LC_MESSAGES/foreman_discovery.mo +0 -0
  54. data/locale/ko/foreman_discovery.edit.po +122 -93
  55. data/locale/ko/foreman_discovery.po +31 -8
  56. data/locale/pt_BR/LC_MESSAGES/foreman_discovery.mo +0 -0
  57. data/locale/pt_BR/foreman_discovery.edit.po +123 -94
  58. data/locale/pt_BR/foreman_discovery.po +32 -9
  59. data/locale/ru/LC_MESSAGES/foreman_discovery.mo +0 -0
  60. data/locale/ru/foreman_discovery.edit.po +123 -94
  61. data/locale/ru/foreman_discovery.po +32 -9
  62. data/locale/sv_SE/LC_MESSAGES/foreman_discovery.mo +0 -0
  63. data/locale/sv_SE/foreman_discovery.edit.po +121 -92
  64. data/locale/sv_SE/foreman_discovery.po +30 -7
  65. data/locale/zh_CN/LC_MESSAGES/foreman_discovery.mo +0 -0
  66. data/locale/zh_CN/foreman_discovery.edit.po +122 -93
  67. data/locale/zh_CN/foreman_discovery.po +31 -8
  68. data/locale/zh_TW/LC_MESSAGES/foreman_discovery.mo +0 -0
  69. data/locale/zh_TW/foreman_discovery.edit.po +120 -91
  70. data/locale/zh_TW/foreman_discovery.po +29 -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/facts/only-ipv6.json +205 -0
  74. data/test/facts/skylake-ipv6.json +223 -0
  75. data/test/functional/api/v2/discovered_hosts_controller_test.rb +1 -0
  76. data/test/functional/api/v2/settings_controller_test.rb +2 -2
  77. data/test/functional/discovered_hosts_controller_test.rb +15 -6
  78. data/test/integration/discovered_hosts_test.rb +6 -11
  79. data/test/test_helper_discovery.rb +12 -0
  80. data/test/unit/discovered_extensions_test.rb +54 -0
  81. data/test/unit/discovery_attribute_set_test.rb +13 -10
  82. data/test/unit/discovery_rule_test.rb +1 -0
  83. data/test/unit/host_discovered_test.rb +32 -29
  84. data/test/unit/managed_extensions_test.rb +2 -0
  85. metadata +39 -28
@@ -0,0 +1,223 @@
1
+ {
2
+ "lib": "/usr/share/fdi/facts:/opt/extension/facts",
3
+ "processors": {
4
+ "models": [
5
+ "Intel Core Processor (Skylake, IBRS)",
6
+ "Intel Core Processor (Skylake, IBRS)"
7
+ ],
8
+ "count": 2,
9
+ "physicalcount": 2
10
+ },
11
+ "kernel": "Linux",
12
+ "ps": "ps -ef",
13
+ "partitions": {
14
+ "sda1": {
15
+ "size": "1228800",
16
+ "label": "EFI System Partition",
17
+ "filesystem": "vfat"
18
+ },
19
+ "sda2": {
20
+ "uuid": "825ebe27-ee98-4c32-8949-1ac200fc8b42",
21
+ "size": "2097152",
22
+ "filesystem": "xfs"
23
+ },
24
+ "sda3": {
25
+ "size": "38612992",
26
+ "filesystem": "LVM2_member"
27
+ }
28
+ },
29
+ "hostname": "fdi",
30
+ "blockdevice_sda_size": 21474836480,
31
+ "blockdevice_sda_vendor": "ATA",
32
+ "blockdevice_sda_model": "QEMU HARDDISK",
33
+ "blockdevices": "sda",
34
+ "architecture": "x86_64",
35
+ "hardwaremodel": "x86_64",
36
+ "operatingsystem": "CentOS",
37
+ "os": {
38
+ "name": "CentOS",
39
+ "family": "RedHat",
40
+ "release": {
41
+ "major": "7",
42
+ "minor": "8",
43
+ "full": "7.8.2003"
44
+ }
45
+ },
46
+ "processor0": "Intel Core Processor (Skylake, IBRS)",
47
+ "processor1": "Intel Core Processor (Skylake, IBRS)",
48
+ "processorcount": 2,
49
+ "uptime_days": 0,
50
+ "macaddress": "52:54:00:96:45:81",
51
+ "path": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/extension/bin",
52
+ "uptime_hours": 0,
53
+ "rubyplatform": "x86_64-linux",
54
+ "netmask": "255.0.0.0",
55
+ "ipaddress6": "fd00:aaaa:bbbb:cc:5054:ff:fe96:4581",
56
+ "osfamily": "RedHat",
57
+ "kernelrelease": "3.10.0-1127.18.2.el7.x86_64",
58
+ "system_uptime": {
59
+ "seconds": 264,
60
+ "hours": 0,
61
+ "days": 0,
62
+ "uptime": "0:04 hours"
63
+ },
64
+ "bios_vendor": "EFI Development Kit II / OVMF",
65
+ "bios_version": "0.0.0",
66
+ "bios_release_date": "02/06/2015",
67
+ "manufacturer": "QEMU",
68
+ "productname": "Standard PC (Q35 + ICH9, 2009)",
69
+ "serialnumber": "Not Specified",
70
+ "uuid": "34c5be4a-2d35-4524-9471-3f7c73d1fe89",
71
+ "type": "Other",
72
+ "operatingsystemrelease": "7.8.2003",
73
+ "uptime": "0:04 hours",
74
+ "hardwareisa": "x86_64",
75
+ "virtual": "kvm",
76
+ "is_virtual": true,
77
+ "rubysitedir": "/usr/local/share/ruby/site_ruby/",
78
+ "id": "root",
79
+ "filesystems": "ext2,ext3,ext4,iso9660,squashfs",
80
+ "timezone": "UTC",
81
+ "uniqueid": "007f0200",
82
+ "sshrsakey": "AAAAB3NzaC1yc2EAAAADAQABAAABAQCiuXQicGounSVTpAIPhRkAA5ovVuLAzziUpNngr2yhb54khyzKbH51s0WDlCDXDN72vmqOK2fAUhpdRZJes/q1PAUk9BUnwpTDI2LYUhj9E0QA7GM/GxqWhrDRt/vG5WkuuUEZVKI4lyuLgGJ5fOn9p22VSHRl7PSmMfSehDPExlQWjffqwi4aKGkndRIY28IuZCWHebLno4diSkKoExin5XMc2HyGNikmPH5vwTD2HwKsHivNvmwYybpPBDmHm4n6uNvwCjr0a24JygU1fy3kFT6W/EEgEV72+J38zWwoEgAeGzca0O4mJy37xv9WBVao6mvLk1vnZRT13r4qneU5",
83
+ "sshfp_rsa": "SSHFP 1 1 df8461ddddf423f915f06f06740dad52677a9289\nSSHFP 1 2 f7f453d2bc934e235af1eab0cf0ce18fb31326475de513e0f4634b753b5cb4e8",
84
+ "sshecdsakey": "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBDDMio789P5EtxntS/wCT/LzYaOEWJ3/TqvewlTzRYlf/zNOIlMGG12QTX1R8P2cus7K+fNWZzXZ3mdV5e/CQos=",
85
+ "sshfp_ecdsa": "SSHFP 3 1 7458744ef5488b42f08e9c506183eac9c9535ce4\nSSHFP 3 2 ee0568b1c150f62b72083674e1d88c5401156c592206ea9a16725d517f69b165",
86
+ "sshed25519key": "AAAAC3NzaC1lZDI1NTE5AAAAIGv5VKv1DuFxAWKvKozb0wYqUTESoCiOUUciHkgA6LFP",
87
+ "sshfp_ed25519": "SSHFP 4 1 4034bdf424c98467a9341f788baf11d31edf7852\nSSHFP 4 2 1c1da30f5991a573fc54ede288b53ff9494888e1eae5def0e2b3a76763a4fc46",
88
+ "network_lo": "127.0.0.0",
89
+ "physicalprocessorcount": 2,
90
+ "kernelmajversion": "3.10",
91
+ "fqdn": "fdi",
92
+ "kernelversion": "3.10.0",
93
+ "facterversion": "2.4.1",
94
+ "operatingsystemmajrelease": "7",
95
+ "interfaces": "eth0,lo",
96
+ "macaddress_eth0": "52:54:00:96:45:81",
97
+ "mtu_eth0": 1500,
98
+ "ipaddress_lo": "127.0.0.1",
99
+ "netmask_lo": "255.0.0.0",
100
+ "mtu_lo": 65536,
101
+ "gid": "root",
102
+ "memorysize": "1.95 GB",
103
+ "memoryfree": "1.74 GB",
104
+ "swapsize": "0.00 MB",
105
+ "swapfree": "0.00 MB",
106
+ "swapsize_mb": "0.00",
107
+ "swapfree_mb": "0.00",
108
+ "memorysize_mb": "1997.13",
109
+ "memoryfree_mb": "1784.67",
110
+ "selinux": false,
111
+ "rubyversion": "2.0.0",
112
+ "uptime_seconds": 264,
113
+ "efi": true,
114
+ "discovery_version": "3.6.5",
115
+ "discovery_release": "20200819.1",
116
+ "discovery_bootif": "52:54:00:96:45:81",
117
+ "link_eth0": "true",
118
+ "link_lo": "true",
119
+ "nmprimary_connection_id": "primary",
120
+ "nmprimary_connection_uuid": "d8651bb4-e2c3-11ea-816a-525400964581",
121
+ "nmprimary_connection_stable-id": "",
122
+ "nmprimary_connection_type": "802-3-ethernet",
123
+ "nmprimary_connection_interface-name": "",
124
+ "nmprimary_connection_autoconnect": "yes",
125
+ "nmprimary_connection_autoconnect-priority": "1",
126
+ "nmprimary_connection_autoconnect-retries": "-1",
127
+ "nmprimary_connection_multi-connect": "0",
128
+ "nmprimary_connection_auth-retries": "-1",
129
+ "nmprimary_connection_timestamp": "1597914143",
130
+ "nmprimary_connection_read-only": "no",
131
+ "nmprimary_connection_permissions": "",
132
+ "nmprimary_connection_zone": "",
133
+ "nmprimary_connection_master": "",
134
+ "nmprimary_connection_slave-type": "",
135
+ "nmprimary_connection_autoconnect-slaves": "-1",
136
+ "nmprimary_connection_secondaries": "",
137
+ "nmprimary_connection_gateway-ping-timeout": "0",
138
+ "nmprimary_connection_metered": "unknown",
139
+ "nmprimary_connection_lldp": "default",
140
+ "nmprimary_connection_mdns": "-1",
141
+ "nmprimary_connection_llmnr": "-1",
142
+ "nmprimary_802-3-ethernet_port": "",
143
+ "nmprimary_802-3-ethernet_speed": "0",
144
+ "nmprimary_802-3-ethernet_duplex": "",
145
+ "nmprimary_802-3-ethernet_auto-negotiate": "no",
146
+ "nmprimary_802-3-ethernet_mac-address": "52:54:00:96:45:81",
147
+ "nmprimary_802-3-ethernet_cloned-mac-address": "",
148
+ "nmprimary_802-3-ethernet_generate-mac-address-mask": "",
149
+ "nmprimary_802-3-ethernet_mac-address-blacklist": "",
150
+ "nmprimary_802-3-ethernet_mtu": "auto",
151
+ "nmprimary_802-3-ethernet_s390-subchannels": "",
152
+ "nmprimary_802-3-ethernet_s390-nettype": "",
153
+ "nmprimary_802-3-ethernet_s390-options": "",
154
+ "nmprimary_802-3-ethernet_wake-on-lan": "default",
155
+ "nmprimary_802-3-ethernet_wake-on-lan-password": "",
156
+ "nmprimary_ipv4_method": "auto",
157
+ "nmprimary_ipv4_dns": "",
158
+ "nmprimary_ipv4_dns-search": "",
159
+ "nmprimary_ipv4_dns-options": " ",
160
+ "nmprimary_ipv4_dns-priority": "0",
161
+ "nmprimary_ipv4_addresses": "",
162
+ "nmprimary_ipv4_gateway": "",
163
+ "nmprimary_ipv4_routes": "",
164
+ "nmprimary_ipv4_route-metric": "-1",
165
+ "nmprimary_ipv4_route-table": "0",
166
+ "nmprimary_ipv4_routing-rules": "",
167
+ "nmprimary_ipv4_ignore-auto-routes": "no",
168
+ "nmprimary_ipv4_ignore-auto-dns": "no",
169
+ "nmprimary_ipv4_dhcp-client-id": "",
170
+ "nmprimary_ipv4_dhcp-timeout": "300",
171
+ "nmprimary_ipv4_dhcp-send-hostname": "no",
172
+ "nmprimary_ipv4_dhcp-hostname": "",
173
+ "nmprimary_ipv4_dhcp-fqdn": "",
174
+ "nmprimary_ipv4_never-default": "no",
175
+ "nmprimary_ipv4_may-fail": "yes",
176
+ "nmprimary_ipv4_dad-timeout": "-1",
177
+ "nmprimary_ipv6_method": "auto",
178
+ "nmprimary_ipv6_dns": "",
179
+ "nmprimary_ipv6_dns-search": "",
180
+ "nmprimary_ipv6_dns-options": " ",
181
+ "nmprimary_ipv6_dns-priority": "0",
182
+ "nmprimary_ipv6_addresses": "",
183
+ "nmprimary_ipv6_gateway": "",
184
+ "nmprimary_ipv6_routes": "",
185
+ "nmprimary_ipv6_route-metric": "-1",
186
+ "nmprimary_ipv6_route-table": "0",
187
+ "nmprimary_ipv6_routing-rules": "",
188
+ "nmprimary_ipv6_ignore-auto-routes": "no",
189
+ "nmprimary_ipv6_ignore-auto-dns": "no",
190
+ "nmprimary_ipv6_never-default": "no",
191
+ "nmprimary_ipv6_may-fail": "yes",
192
+ "nmprimary_ipv6_ip6-privacy": "-1",
193
+ "nmprimary_ipv6_addr-gen-mode": "eui64",
194
+ "nmprimary_ipv6_dhcp-duid": "",
195
+ "nmprimary_ipv6_dhcp-send-hostname": "yes",
196
+ "nmprimary_ipv6_dhcp-hostname": "",
197
+ "nmprimary_ipv6_token": "",
198
+ "nmprimary_vlan_parent": "",
199
+ "nmprimary_vlan_id": "0",
200
+ "nmprimary_vlan_flags": "1",
201
+ "nmprimary_vlan_ingress-priority-map": "",
202
+ "nmprimary_vlan_egress-priority-map": "",
203
+ "nmprimary_proxy_method": "none",
204
+ "nmprimary_proxy_browser-only": "no",
205
+ "nmprimary_proxy_pac-url": "",
206
+ "nmprimary_proxy_pac-script": "",
207
+ "nmprimary_general_name": "primary",
208
+ "nmprimary_general_uuid": "d8651bb4-e2c3-11ea-816a-525400964581",
209
+ "nmprimary_general_devices": "eth0",
210
+ "nmprimary_general_state": "activated",
211
+ "nmprimary_general_default": "no",
212
+ "nmprimary_general_default6": "no",
213
+ "nmprimary_general_spec-object": "",
214
+ "nmprimary_general_vpn": "no",
215
+ "nmprimary_general_dbus-path": "/org/freedesktop/NetworkManager/ActiveConnection/1",
216
+ "nmprimary_general_con-path": "/org/freedesktop/NetworkManager/Settings/1",
217
+ "nmprimary_general_zone": "",
218
+ "nmprimary_general_master-path": "",
219
+ "nmprimary_ip6_address": "fd00:aaaa:bbbb:cc:5054:ff:fe96:4581/64",
220
+ "nmprimary_ip6_gateway": "",
221
+ "nmprimary_ip6_route": "dst = fd00:aaaa:bbbb:cc::/64, nh = ::, mt = 100",
222
+ "nmprimary_ip6_dns": "fe80::5054:ff:fe3a:6bd3"
223
+ }
@@ -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
@@ -6,10 +6,10 @@ class Api::V2::SettingsControllerTest < ActionController::TestCase
6
6
  end
7
7
 
8
8
  test_attributes :pid => '2c5ecb7e-87bc-4980-9620-7ae00e3f360e'
9
- test "should update hostname prefix without value" do
9
+ test "should not update hostname prefix without value" do
10
10
  setting = Setting.find_by_name("discovery_prefix")
11
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"
12
+ assert_nil JSON.parse(@response.body)['value']
13
13
  end
14
14
 
15
15
  test_attributes :pid => '4969994d-f934-4f0e-9a98-476b87eb0527'
@@ -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)
@@ -9,6 +9,8 @@ class DiscoveredHostsTest < IntegrationTestWithJavascript
9
9
  assert discovered_notification_blueprint
10
10
  discovered_host.save!
11
11
  visit discovered_hosts_path
12
+ page.evaluate_script("document.getElementById('fixedPropertiesSelector-#{discovered_host.id}').classList.remove('fade')")
13
+ ::ForemanDiscovery::HostConverter.stubs(:unused_ip_for_host)
12
14
  end
13
15
 
14
16
  teardown do
@@ -64,15 +66,14 @@ class DiscoveredHostsTest < IntegrationTestWithJavascript
64
66
 
65
67
  test 'and forwards to editing it' do
66
68
  create_host
67
- assert_equal edit_discovered_host_path(id: discovered_host),
68
- current_path
69
+ assert_current_path edit_discovered_host_path(id: discovered_host), ignore_query: true
69
70
  end
70
71
 
71
72
  context 'with a Hostgroup selected' do
72
73
  let(:discovery_hostgroup) { Hostgroup.first }
73
74
 
74
75
  test 'it passes it on' do
75
- select_from('host_hostgroup_id', discovery_hostgroup.id)
76
+ select2(discovery_hostgroup.name, from: 'host_hostgroup_id')
76
77
  create_host
77
78
  assert_param discovery_hostgroup.id.to_s,
78
79
  'host.hostgroup_id'
@@ -83,7 +84,7 @@ class DiscoveredHostsTest < IntegrationTestWithJavascript
83
84
  let(:discovery_location) { Location.first }
84
85
 
85
86
  test 'it passes it on' do
86
- select_from('host_location_id', discovery_location.id)
87
+ select2(discovery_location.name, from: 'host_location_id')
87
88
  create_host
88
89
  assert_param discovery_location.id.to_s,
89
90
  'host.location_id'
@@ -94,7 +95,7 @@ class DiscoveredHostsTest < IntegrationTestWithJavascript
94
95
  let(:discovery_organization) { Organization.first }
95
96
 
96
97
  test 'it passes it on' do
97
- select_from('host_organization_id', discovery_organization.id)
98
+ select2(discovery_organization.name, from: 'host_organization_id')
98
99
  create_host
99
100
  assert_param discovery_organization.id.to_s,
100
101
  'host.organization_id'
@@ -147,12 +148,6 @@ class DiscoveredHostsTest < IntegrationTestWithJavascript
147
148
  page.find("#host_ids_#{id}").click
148
149
  end
149
150
 
150
- def select_from(element_id, id)
151
- page.find_by_id(element_id, visible: false)
152
- .find("option[value='#{id}']", visible: false)
153
- .select_option
154
- end
155
-
156
151
  def create_host
157
152
  page.find("#fixedPropertiesSelector-#{discovered_host.id}")
158
153
  .find_button('Create Host').click
@@ -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)