foreman_discovery 15.1.0 → 16.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/foreman/controller/discovered_extensions.rb +4 -0
  3. data/app/controllers/discovered_hosts_controller.rb +1 -0
  4. data/app/models/setting/discovered.rb +26 -33
  5. data/app/services/foreman_discovery/fact_parser.rb +1 -1
  6. data/app/services/foreman_discovery/host_converter.rb +29 -1
  7. data/app/services/foreman_discovery/import_hooks/subnet_and_taxonomy.rb +6 -14
  8. data/app/services/foreman_discovery/subnet_suggestion.rb +26 -0
  9. data/app/views/discovered_hosts/_discovered_host_modal.html.erb +2 -0
  10. data/config/routes.rb +2 -0
  11. data/extra/discover-host +21 -7
  12. data/lib/foreman_discovery/engine.rb +2 -2
  13. data/lib/foreman_discovery/version.rb +1 -1
  14. data/locale/ca/LC_MESSAGES/foreman_discovery.mo +0 -0
  15. data/locale/ca/foreman_discovery.edit.po +111 -91
  16. data/locale/ca/foreman_discovery.po +17 -2
  17. data/locale/de/LC_MESSAGES/foreman_discovery.mo +0 -0
  18. data/locale/de/foreman_discovery.edit.po +113 -93
  19. data/locale/de/foreman_discovery.po +19 -4
  20. data/locale/en/LC_MESSAGES/foreman_discovery.mo +0 -0
  21. data/locale/en/foreman_discovery.edit.po +98 -78
  22. data/locale/en/foreman_discovery.po +16 -1
  23. data/locale/en_GB/LC_MESSAGES/foreman_discovery.mo +0 -0
  24. data/locale/en_GB/foreman_discovery.edit.po +113 -93
  25. data/locale/en_GB/foreman_discovery.po +19 -4
  26. data/locale/es/LC_MESSAGES/foreman_discovery.mo +0 -0
  27. data/locale/es/foreman_discovery.edit.po +112 -92
  28. data/locale/es/foreman_discovery.po +18 -3
  29. data/locale/foreman_discovery.pot +99 -79
  30. data/locale/fr/LC_MESSAGES/foreman_discovery.mo +0 -0
  31. data/locale/fr/foreman_discovery.edit.po +112 -92
  32. data/locale/fr/foreman_discovery.po +18 -3
  33. data/locale/gl/LC_MESSAGES/foreman_discovery.mo +0 -0
  34. data/locale/gl/foreman_discovery.edit.po +111 -91
  35. data/locale/gl/foreman_discovery.po +17 -2
  36. data/locale/it/LC_MESSAGES/foreman_discovery.mo +0 -0
  37. data/locale/it/foreman_discovery.edit.po +112 -92
  38. data/locale/it/foreman_discovery.po +18 -3
  39. data/locale/ja/LC_MESSAGES/foreman_discovery.mo +0 -0
  40. data/locale/ja/foreman_discovery.edit.po +113 -93
  41. data/locale/ja/foreman_discovery.po +19 -4
  42. data/locale/ko/LC_MESSAGES/foreman_discovery.mo +0 -0
  43. data/locale/ko/foreman_discovery.edit.po +112 -92
  44. data/locale/ko/foreman_discovery.po +18 -3
  45. data/locale/pt_BR/LC_MESSAGES/foreman_discovery.mo +0 -0
  46. data/locale/pt_BR/foreman_discovery.edit.po +113 -93
  47. data/locale/pt_BR/foreman_discovery.po +19 -4
  48. data/locale/ru/LC_MESSAGES/foreman_discovery.mo +0 -0
  49. data/locale/ru/foreman_discovery.edit.po +113 -93
  50. data/locale/ru/foreman_discovery.po +19 -4
  51. data/locale/sv_SE/LC_MESSAGES/foreman_discovery.mo +0 -0
  52. data/locale/sv_SE/foreman_discovery.edit.po +112 -92
  53. data/locale/sv_SE/foreman_discovery.po +18 -3
  54. data/locale/zh_CN/LC_MESSAGES/foreman_discovery.mo +0 -0
  55. data/locale/zh_CN/foreman_discovery.edit.po +112 -92
  56. data/locale/zh_CN/foreman_discovery.po +18 -3
  57. data/locale/zh_TW/LC_MESSAGES/foreman_discovery.mo +0 -0
  58. data/locale/zh_TW/foreman_discovery.edit.po +112 -92
  59. data/locale/zh_TW/foreman_discovery.po +18 -3
  60. data/test/facts/bond0-eth0-eth1-active-passive.json +128 -0
  61. data/test/facts/facts_with_lldp_bond_candidate.json +2 -9
  62. data/test/functional/api/v2/discovered_hosts_controller_test.rb +1 -0
  63. data/test/integration/discovered_hosts_test.rb +1 -0
  64. data/test/test_helper_discovery.rb +12 -0
  65. data/test/unit/discovered_extensions_test.rb +49 -0
  66. data/test/unit/discovery_attribute_set_test.rb +1 -0
  67. data/test/unit/discovery_rule_test.rb +1 -0
  68. data/test/unit/host_discovered_test.rb +32 -13
  69. data/test/unit/managed_extensions_test.rb +1 -0
  70. metadata +5 -2
@@ -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 15.1.0\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: 2019-10-22 20:43+0000\n"
11
+ "Last-Translator: Bryan Kearney <bryan.kearney@gmail.com>\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
 
@@ -345,6 +348,9 @@ msgstr "IP 位址"
345
348
  msgid "IP address"
346
349
  msgstr "IP 位址"
347
350
 
351
+ msgid "IPAM must be configured for subnet '%s'"
352
+ msgstr ""
353
+
348
354
  msgid "IPMI"
349
355
  msgstr "IPMI"
350
356
 
@@ -360,6 +366,12 @@ msgstr ""
360
366
  msgid "Image API returned HTTP/%{code} with '%{body}"
361
367
  msgstr ""
362
368
 
369
+ msgid "Import Puppet classes"
370
+ msgstr "匯入 Puppet 類別"
371
+
372
+ msgid "Import facts"
373
+ msgstr "匯入詳情"
374
+
363
375
  msgid "In addition to @host attribute function rand for random integers is available. Examples:"
364
376
  msgstr ""
365
377
 
@@ -576,6 +588,9 @@ msgstr ""
576
588
  msgid "Reloading kernel on %s"
577
589
  msgstr ""
578
590
 
591
+ msgid "Remote action:"
592
+ msgstr "遠端動作:"
593
+
579
594
  msgid "Reported in the last 7 days"
580
595
  msgstr ""
581
596
 
@@ -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
@@ -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,9 @@ 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
+ ::ForemanDiscovery::HostConverter.stubs(:unused_ip_for_host)
11
13
  end
12
14
 
13
15
  test "no rule is found for empty rule set" do
@@ -179,6 +181,53 @@ class DiscoveredExtensionsTest < ActiveSupport::TestCase
179
181
  assert_equal hostgroup.puppet_ca_proxy, managed_host.puppet_ca_proxy
180
182
  end
181
183
 
184
+ class StubIPAM
185
+ def suggest_ip
186
+ "192.168.101.13"
187
+ end
188
+ end
189
+
190
+ test "subnet is changed and unused_ip called" do
191
+ ::ForemanDiscovery::HostConverter.unstub(:unused_ip_for_host)
192
+ facts = @facts.merge({"somefact" => "abc"})
193
+ domain = FactoryBot.create(:domain)
194
+ 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")])
195
+ 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")])
196
+ host = discover_host_from_facts(facts)
197
+ assert_equal subnet, host.subnet
198
+ hostgroup = FactoryBot.create(:hostgroup, :with_environment, :with_rootpass, :with_puppet_orchestration, :with_os, :pxe_loader => "PXELinux BIOS", :subnet => subnet2, :domain => domain)
199
+ r1 = FactoryBot.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc", :organizations => [host.organization], :locations => [host.location], :hostgroup => hostgroup)
200
+ Subnet.any_instance.expects(:unused_ip).with(host.mac).returns(StubIPAM.new)
201
+ host.primary_interface.stubs(:queue_tftp)
202
+ host.primary_interface.stubs(:queue_dhcp)
203
+ managed_host = perform_auto_provision(host, r1)
204
+ assert_empty host.errors
205
+ assert managed_host
206
+ assert_empty managed_host.errors
207
+ assert_equal hostgroup.subnet, managed_host.subnet
208
+ assert_equal "192.168.101.13", managed_host.ip
209
+ end
210
+
211
+ test "subnet6 is changed and unused_ip called" do
212
+ ::ForemanDiscovery::HostConverter.unstub(:unused_ip_for_host)
213
+ facts = @facts_ipv6.merge({"somefact" => "abc"})
214
+ domain = FactoryBot.create(:domain)
215
+ 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")])
216
+ 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")])
217
+ host = discover_host_from_facts(facts)
218
+ assert_equal subnet, host.subnet6
219
+ hostgroup = FactoryBot.create(:hostgroup, :with_environment, :with_rootpass, :with_puppet_orchestration, :with_os, :pxe_loader => "PXELinux BIOS", :subnet6 => subnet2, :domain => domain)
220
+ r1 = FactoryBot.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc", :organizations => [host.organization], :locations => [host.location], :hostgroup => hostgroup)
221
+ host.primary_interface.stubs(:queue_tftp)
222
+ host.primary_interface.stubs(:queue_dhcp)
223
+ managed_host = perform_auto_provision(host, r1)
224
+ assert_empty host.errors
225
+ assert managed_host
226
+ assert_empty managed_host.errors
227
+ assert_equal hostgroup.subnet, managed_host.subnet
228
+ assert_equal "2001:db9::a8bb:ccff:fedd:eefa", managed_host.ip6
229
+ end
230
+
182
231
  test "attributes from hostgroup are copied after auto provisioning for host without subnet detected" do
183
232
  facts = @facts.merge({"somefact" => "abc"})
184
233
  host = discover_host_from_facts(facts)
@@ -14,6 +14,7 @@ class DiscoveryAttributeSetTest < ActiveSupport::TestCase
14
14
  :name => 'discovery_prefix',
15
15
  :value => 'mac',
16
16
  :category => 'Setting::Discovered')
17
+ ::ForemanDiscovery::HostConverter.stubs(:unused_ip_for_host)
17
18
  end
18
19
 
19
20
  test "can search discovered hosts by cpu" do
@@ -3,6 +3,7 @@ require_relative '../test_plugin_helper'
3
3
  class DiscoveryRuleTest < ActiveSupport::TestCase
4
4
  setup do
5
5
  @hostgroup = FactoryBot.create(:hostgroup)
6
+ ::ForemanDiscovery::HostConverter.stubs(:unused_ip_for_host)
6
7
  end
7
8
 
8
9
  should allow_values(*valid_name_list).for(:name)
@@ -7,6 +7,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
7
7
  setup do
8
8
  @facts = parse_json_fixture('regular_host', true)
9
9
  set_default_settings
10
+ ::ForemanDiscovery::HostConverter.stubs(:unused_ip_for_host)
10
11
  end
11
12
 
12
13
  test "should be able to create Host::Discovered objects" do
@@ -38,9 +39,20 @@ class HostDiscoveredTest < ActiveSupport::TestCase
38
39
  assert_equal discovered_host.id, fact_value.host.id
39
40
  end
40
41
 
42
+ test "should detect bridge as the primary" do
43
+ # Detected primary should be the bridge (.2)
44
+ # "ipaddress_br180": "10.35.27.2"
45
+ # "ipaddress_eth0": "10.35.27.3"
46
+ # "ipaddress": "10.35.27.2"
47
+ subnet = FactoryBot.create(:subnet_ipv4, :name => 'Subnet99', :network => '10.35.27.0', :organizations => [organization_one], :locations => [location_one])
48
+ Subnet.expects(:subnet_for).with('10.35.27.2').returns(subnet)
49
+ host = discover_host_from_facts(@facts)
50
+ assert_equal '10.35.27.2', host.primary_interface.ip
51
+ end
52
+
41
53
  test "should setup subnet" do
42
54
  subnet = FactoryBot.create(:subnet_ipv4, :name => 'Subnet99', :network => '10.35.27.0', :organizations => [organization_one], :locations => [location_one])
43
- Subnet.expects(:subnet_for).with('10.35.27.3').returns(subnet)
55
+ Subnet.expects(:subnet_for).with('10.35.27.2').returns(subnet)
44
56
  host = discover_host_from_facts(@facts)
45
57
  assert_equal subnet, host.primary_interface.subnet
46
58
  end
@@ -48,7 +60,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
48
60
  test "should setup subnet when update_subnets_from_facts is true" do
49
61
  Setting[:update_subnets_from_facts] = true
50
62
  subnet = FactoryBot.create(:subnet_ipv4, :name => 'Subnet99', :network => '10.35.27.0', :organizations => [organization_one], :locations => [location_one])
51
- Subnet.expects(:subnet_for).with('10.35.27.3').returns(subnet)
63
+ Subnet.expects(:subnet_for).with('10.35.27.2').returns(subnet)
52
64
  host = discover_host_from_facts(@facts)
53
65
  assert_equal subnet, host.primary_interface.subnet
54
66
  end
@@ -59,7 +71,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
59
71
  Setting['discovery_organization'] = org.name
60
72
  Setting['discovery_location'] = loc.name
61
73
  subnet = FactoryBot.create(:subnet_ipv4, :name => 'Subnet99', :network => '10.35.27.0', :organizations => [org], :locations => [loc])
62
- Subnet.expects(:subnet_for).with('10.35.27.3').returns(subnet)
74
+ Subnet.expects(:subnet_for).with('10.35.27.2').returns(subnet)
63
75
  host = discover_host_from_facts(@facts)
64
76
  assert_equal subnet, host.primary_interface.subnet
65
77
  assert_equal org, host.organization
@@ -74,7 +86,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
74
86
  Setting['discovery_organization'] = nil
75
87
  Setting['discovery_location'] = nil
76
88
  subnet = FactoryBot.create(:subnet_ipv4, :name => 'Subnet99', :network => '10.35.27.0', :organizations => [org, org2], :locations => [loc, loc2])
77
- Subnet.expects(:subnet_for).with('10.35.27.3').returns(subnet)
89
+ Subnet.expects(:subnet_for).with('10.35.27.2').returns(subnet)
78
90
  host = discover_host_from_facts(@facts)
79
91
  assert_equal subnet, host.primary_interface.subnet
80
92
  assert host.organization
@@ -92,7 +104,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
92
104
  Setting['discovery_organization'] = org.name
93
105
  Setting['discovery_location'] = loc.name
94
106
  subnet = FactoryBot.create(:subnet_ipv4, :name => 'Subnet99', :network => '10.35.27.0', :organizations => [org], :locations => [loc])
95
- Subnet.expects(:subnet_for).with('10.35.27.3').returns(subnet)
107
+ Subnet.expects(:subnet_for).with('10.35.27.2').returns(subnet)
96
108
  host = discover_host_from_facts(@facts.merge("test_org" => bad_org.title, "test_loc" => bad_loc.title))
97
109
  assert_equal subnet, host.primary_interface.subnet
98
110
  assert_equal org, host.organization
@@ -111,7 +123,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
111
123
  Setting['discovery_organization'] = org.name
112
124
  Setting['discovery_location'] = loc.name
113
125
  subnet = FactoryBot.create(:subnet_ipv4, :name => 'Subnet99', :network => '10.35.27.0', :organizations => [org, bad_org], :locations => [loc, bad_loc])
114
- Subnet.expects(:subnet_for).with('10.35.27.3').returns(subnet)
126
+ Subnet.expects(:subnet_for).with('10.35.27.2').returns(subnet)
115
127
  host = discover_host_from_facts(@facts.merge("foreman_organization" => bad_org.title, "foreman_location" => bad_loc.title))
116
128
  assert_equal subnet, host.primary_interface.subnet
117
129
  assert_equal org, host.organization
@@ -129,7 +141,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
129
141
  Setting['discovery_organization'] = org.name
130
142
  Setting['discovery_location'] = loc.name
131
143
  subnet = FactoryBot.create(:subnet_ipv4, :name => 'Subnet99', :network => '10.35.27.0', :organizations => [org, bad_org], :locations => [loc, bad_loc])
132
- Subnet.expects(:subnet_for).with('10.35.27.3').returns(subnet)
144
+ Subnet.expects(:subnet_for).with('10.35.27.2').returns(subnet)
133
145
  host = discover_host_from_facts(@facts)
134
146
  assert_equal subnet, host.primary_interface.subnet
135
147
  assert_equal org, host.organization
@@ -148,7 +160,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
148
160
  Setting['discovery_organization'] = org.name
149
161
  Setting['discovery_location'] = loc.name
150
162
  subnet = FactoryBot.create(:subnet_ipv4, :name => 'Subnet99', :network => '10.35.27.0', :organizations => [org], :locations => [loc])
151
- Subnet.expects(:subnet_for).with('10.35.27.3').returns(subnet)
163
+ Subnet.expects(:subnet_for).with('10.35.27.2').returns(subnet)
152
164
  host = discover_host_from_facts(@facts)
153
165
  assert_equal org, host.organization
154
166
  assert_equal loc, host.location
@@ -188,7 +200,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
188
200
  :organizations => [organization_one],
189
201
  :locations => [location_one]
190
202
  )
191
- Subnet.expects(:subnet_for).with('10.35.27.3').returns(subnet)
203
+ Subnet.expects(:subnet_for).with('10.35.27.2').returns(subnet)
192
204
  ProxyAPI::TFTP.any_instance.expects(:set).with(anything, 'e4:1f:13:cc:36:58', anything).returns(true).times(3)
193
205
  TemplateKind::PXE.each do |kind|
194
206
  ProvisioningTemplate.where(:name => "#{kind.downcase}_discovery").first_or_create(
@@ -259,14 +271,14 @@ class HostDiscoveredTest < ActiveSupport::TestCase
259
271
  assert_equal 'mace41f13cc3658', host1.name
260
272
  assert_equal 'IBM System x -[7870K4G]-', host1.facts["productname"]
261
273
  assert_equal 1, Host::Discovered.where(:name => 'mace41f13cc3658').count
262
- assert_equal '10.35.27.3', host1.ip
274
+ assert_equal '10.35.27.2', host1.ip
263
275
 
264
276
  @facts["ipaddress_eth0"] = "1.2.3.4"
265
277
  @facts["productname"] = "Dishwasher DW400"
266
278
  host2 = discover_host_from_facts(@facts)
267
279
  assert_equal 'mace41f13cc3658', host2.name
268
280
  assert_equal 'Dishwasher DW400', host2.facts["productname"]
269
- assert_equal '1.2.3.4', host2.ip
281
+ assert_equal '10.35.27.2', host2.ip
270
282
  assert_equal 1, Host::Discovered.where(:name => 'mace41f13cc3658').count
271
283
  end
272
284
 
@@ -438,12 +450,19 @@ class HostDiscoveredTest < ActiveSupport::TestCase
438
450
  end
439
451
  end
440
452
 
453
+ test "primary interface via tagged VLAN is discovered with an IP" do
454
+ raw = parse_json_fixture('rhel7-vlan')
455
+ host = discover_host_from_facts(raw)
456
+ assert_equal "192.168.1.16", host.ip
457
+ assert_equal "eno49.444", host.primary_interface.identifier
458
+ end
459
+
441
460
  test "primary interface isn't touched with no LLDP facts" do
442
461
  Setting[:discovery_auto_bond] = true
443
462
  raw = parse_json_fixture('regular_host', true)
444
463
  host = discover_host_from_facts(raw)
445
464
  refute_nil host.primary_interface
446
- assert_equal "eth0", host.primary_interface.identifier
465
+ assert_equal "br180", host.primary_interface.identifier
447
466
  end
448
467
 
449
468
  test "provision_interface isn't touched with no peer on the same VLAN" do
@@ -451,7 +470,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
451
470
  raw = parse_json_fixture('facts_with_lldp', true)
452
471
  host = discover_host_from_facts(raw)
453
472
  refute_nil host.primary_interface
454
- assert_equal "eth0", host.primary_interface.identifier
473
+ assert_equal "br180", host.primary_interface.identifier
455
474
  end
456
475
 
457
476
  test "provision_interface is switched to bond0 with more than one interface on the same VLAN" do