foreman_discovery 12.0.2 → 13.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/mailers/discovered_mailer.rb +12 -1
- data/app/models/host/discovered.rb +20 -7
- data/app/models/setting/discovered.rb +2 -0
- data/app/services/foreman_discovery/fact_parser.rb +8 -2
- data/app/services/foreman_discovery/lldp_neighbors.rb +104 -0
- data/app/views/discovery_rules/index.html.erb +1 -1
- data/extra/discovery/pxeless-vlan.json +217 -0
- data/lib/foreman_discovery/engine.rb +1 -1
- data/lib/foreman_discovery/version.rb +1 -1
- data/locale/ca/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/ca/foreman_discovery.edit.po +143 -58
- data/locale/ca/foreman_discovery.po +4 -4
- data/locale/de/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/de/foreman_discovery.edit.po +145 -59
- data/locale/de/foreman_discovery.po +7 -7
- data/locale/en/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/en/foreman_discovery.edit.po +90 -58
- data/locale/en/foreman_discovery.po +28 -4
- data/locale/en_GB/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/en_GB/foreman_discovery.edit.po +151 -66
- data/locale/en_GB/foreman_discovery.po +12 -12
- data/locale/es/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/es/foreman_discovery.edit.po +155 -70
- data/locale/es/foreman_discovery.po +16 -16
- data/locale/foreman_discovery.pot +93 -59
- data/locale/fr/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/fr/foreman_discovery.edit.po +287 -200
- data/locale/fr/foreman_discovery.po +149 -148
- data/locale/gl/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/gl/foreman_discovery.edit.po +144 -59
- data/locale/gl/foreman_discovery.po +5 -5
- data/locale/it/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/it/foreman_discovery.edit.po +144 -59
- data/locale/it/foreman_discovery.po +5 -5
- data/locale/ja/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/ja/foreman_discovery.edit.po +153 -68
- data/locale/ja/foreman_discovery.po +16 -14
- data/locale/ko/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/ko/foreman_discovery.edit.po +143 -59
- data/locale/ko/foreman_discovery.po +5 -5
- data/locale/pt_BR/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/pt_BR/foreman_discovery.edit.po +155 -70
- data/locale/pt_BR/foreman_discovery.po +16 -16
- data/locale/ru/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/ru/foreman_discovery.edit.po +146 -63
- data/locale/ru/foreman_discovery.po +6 -6
- data/locale/sv_SE/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/sv_SE/foreman_discovery.edit.po +144 -59
- data/locale/sv_SE/foreman_discovery.po +5 -5
- data/locale/zh_CN/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/zh_CN/foreman_discovery.edit.po +150 -69
- data/locale/zh_CN/foreman_discovery.po +13 -15
- data/locale/zh_TW/LC_MESSAGES/foreman_discovery.mo +0 -0
- data/locale/zh_TW/foreman_discovery.edit.po +227 -144
- data/locale/zh_TW/foreman_discovery.po +88 -88
- data/test/functional/api/v2/discovery_rules_controller_test.rb +8 -0
- data/test/functional/api/v2/settings_controller_test.rb +2 -0
- data/test/test_helper_discovery.rb +2 -0
- data/test/unit/discovered_mailer_test.rb +14 -0
- data/test/unit/discovery_rule_test.rb +3 -0
- data/test/unit/facts_with_lldp.json +107 -0
- data/test/unit/facts_with_lldp_bond_candidate.json +107 -0
- data/test/unit/host_discovered_test.rb +72 -1
- data/test/unit/lldp_neighbors_test.rb +56 -0
- metadata +11 -2
@@ -31,6 +31,7 @@ class Api::V2::DiscoveryRulesControllerTest < ActionController::TestCase
|
|
31
31
|
assert_equal "Location 1", discovery_rule['locations'].first['name']
|
32
32
|
end
|
33
33
|
|
34
|
+
test_attributes :pid => '121e0a30-8a24-47d7-974d-998886ed1ea7'
|
34
35
|
test "should create discovery rule with taxonomy" do
|
35
36
|
hostgroup = FactoryBot.create(:hostgroup, :with_os, :with_rootpass, :organizations => [organization_one], :locations => [location_one])
|
36
37
|
valid_attributes = {
|
@@ -64,6 +65,7 @@ class Api::V2::DiscoveryRulesControllerTest < ActionController::TestCase
|
|
64
65
|
assert_response :success
|
65
66
|
end
|
66
67
|
|
68
|
+
test_attributes :pid => '769c0739-538b-4451-af7b-deb2ecd3dc0d'
|
67
69
|
test "should update discovery rule name" do
|
68
70
|
rule = FactoryBot.create(:discovery_rule)
|
69
71
|
new_name = 'new_rule_name'
|
@@ -79,6 +81,7 @@ class Api::V2::DiscoveryRulesControllerTest < ActionController::TestCase
|
|
79
81
|
assert_response :success
|
80
82
|
end
|
81
83
|
|
84
|
+
test_attributes :pid => '0f8ec302-f9de-4713-87b7-0f1aca515149'
|
82
85
|
test "should update taxonomies for discovery rule" do
|
83
86
|
min_required_attr = { :name => 'new_rule', :search => 'CPU_Count = 1', :hostgroup_id => hostgroups(:unusual).id }
|
84
87
|
rule = DiscoveryRule.new(min_required_attr)
|
@@ -97,6 +100,7 @@ class Api::V2::DiscoveryRulesControllerTest < ActionController::TestCase
|
|
97
100
|
assert_equal [location_one.id], rule.locations.map {|loc| loc.id}
|
98
101
|
end
|
99
102
|
|
103
|
+
test_attributes :pid => '2c5ecb7e-87bc-4980-9620-7ae00e3f360e'
|
100
104
|
test "should update search rule" do
|
101
105
|
rule = FactoryBot.create(:discovery_rule)
|
102
106
|
new_search = 'Location = Default_Location'
|
@@ -106,6 +110,7 @@ class Api::V2::DiscoveryRulesControllerTest < ActionController::TestCase
|
|
106
110
|
assert_equal new_search, rule.search
|
107
111
|
end
|
108
112
|
|
113
|
+
test_attributes :pid => '33084060-2866-46b9-bfab-23d91aea73d8'
|
109
114
|
test "should update host limit" do
|
110
115
|
rule = FactoryBot.create(:discovery_rule)
|
111
116
|
new_max_count = 150
|
@@ -116,6 +121,7 @@ class Api::V2::DiscoveryRulesControllerTest < ActionController::TestCase
|
|
116
121
|
assert_equal new_max_count, rule.max_count
|
117
122
|
end
|
118
123
|
|
124
|
+
test_attributes :pid => '330aa943-167b-46dd-b434-1a6e5fe8f283'
|
119
125
|
test "test_positive_disable" do
|
120
126
|
rule = FactoryBot.create(:discovery_rule)
|
121
127
|
assert rule.enabled
|
@@ -125,6 +131,7 @@ class Api::V2::DiscoveryRulesControllerTest < ActionController::TestCase
|
|
125
131
|
refute rule.enabled
|
126
132
|
end
|
127
133
|
|
134
|
+
test_attributes :pid => '9fdba953-dcc7-4532-9204-17a45b0d9e05'
|
128
135
|
test "should destroy discovery rule" do
|
129
136
|
rule = FactoryBot.create(:discovery_rule)
|
130
137
|
assert_difference('DiscoveryRule.unscoped.count', -1) do
|
@@ -134,6 +141,7 @@ class Api::V2::DiscoveryRulesControllerTest < ActionController::TestCase
|
|
134
141
|
refute DiscoveryRule.unscoped.exists?(rule.id)
|
135
142
|
end
|
136
143
|
|
144
|
+
test_attributes :pid => '415379b7-0134-40b9-adb1-2fe0adb1ac36'
|
137
145
|
test "should not create with too long name" do
|
138
146
|
assert_difference('DiscoveryRule.unscoped.count', 0) do
|
139
147
|
post :create, params: {:discovery_rule => {
|
@@ -5,12 +5,14 @@ class Api::V2::SettingsControllerTest < ActionController::TestCase
|
|
5
5
|
FactoryBot.create(:setting, :name => 'discovery_prefix', :value => 'mac', :category => 'Setting::Discovered')
|
6
6
|
end
|
7
7
|
|
8
|
+
test_attributes :pid => '2c5ecb7e-87bc-4980-9620-7ae00e3f360e'
|
8
9
|
test "should update hostname prefix without value" do
|
9
10
|
setting = Setting.find_by_name("discovery_prefix")
|
10
11
|
put :update, params: { :id => setting.id, :setting => { :value => '' } }
|
11
12
|
assert_equal JSON.parse(@response.body)['value'], '', "Can't update discovery_prefix setting with empty value"
|
12
13
|
end
|
13
14
|
|
15
|
+
test_attributes :pid => '4969994d-f934-4f0e-9a98-476b87eb0527'
|
14
16
|
test "should update hostname prefix" do
|
15
17
|
value = RFauxFactory.gen_alpha
|
16
18
|
setting = Setting.find_by_name("discovery_prefix")
|
@@ -67,6 +67,8 @@ def set_default_settings
|
|
67
67
|
FactoryBot.create(:setting, :name => 'discovery_pxegrub2_lock_template', :value => 'pxegrub2_discovery', :category => 'Setting::Discovered')
|
68
68
|
FactoryBot.create(:setting, :name => 'discovery_always_rebuild_dns', :value => true, :category => 'Setting::Discovered')
|
69
69
|
FactoryBot.create(:setting, :name => 'discovery_error_on_existing', :value => false, :category => 'Setting::Discovered')
|
70
|
+
FactoryBot.create(:setting, :name => 'discovery_naming', :value => 'Fact', :category => 'Setting::Discovered')
|
71
|
+
FactoryBot.create(:setting, :name => 'discovery_auto_bond', :value => false, :category => 'Setting::Discovered')
|
70
72
|
end
|
71
73
|
|
72
74
|
def setup_hostgroup(host)
|
@@ -41,4 +41,18 @@ class DiscoveredMailerTest < ActiveSupport::TestCase
|
|
41
41
|
refute(@email.body.parts.first.body.raw_source.start_with?('<!DOCTYPE')) # text email
|
42
42
|
assert(@email.body.parts.last.body.raw_source.start_with?('<!DOCTYPE')) # html email
|
43
43
|
end
|
44
|
+
|
45
|
+
test 'discovery mailer sends email when user object is used' do
|
46
|
+
assert MailNotification[:discovered_summary].deliver(user: @user)
|
47
|
+
end
|
48
|
+
|
49
|
+
test 'discovery mailer sends email when user id is used' do
|
50
|
+
assert MailNotification[:discovered_summary].deliver(user: @user.id)
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'discovery mailer must raise exception when sending email to an unknown user type' do
|
54
|
+
assert_raises Foreman::Exception do
|
55
|
+
MailNotification[:discovered_summary].deliver(user: @user.mail)
|
56
|
+
end
|
57
|
+
end
|
44
58
|
end
|
@@ -55,6 +55,7 @@ class DiscoveryRuleTest < ActiveSupport::TestCase
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
+
test_attributes :pid => 'b8ae7a80-b9a8-4924-808c-482a2b4102c4'
|
58
59
|
test "should create discovery rule with name and minimum required attributes" do
|
59
60
|
rule = DiscoveryRule.new(:name => 'new_rule', :search => 'cpu_count = 1', :hostgroup_id => hostgroups(:unusual).id)
|
60
61
|
assert_valid rule
|
@@ -100,6 +101,7 @@ class DiscoveryRuleTest < ActiveSupport::TestCase
|
|
100
101
|
assert_equal "must be present.", rule.errors[:hostgroup].first
|
101
102
|
end
|
102
103
|
|
104
|
+
test_attributes :pid => '4ec7d76a-22ba-4c3e-952c-667a6f0a5728'
|
103
105
|
test "should not create with invalid priority type" do
|
104
106
|
rule = DiscoveryRule.new(
|
105
107
|
:name => 'new_rule',
|
@@ -123,6 +125,7 @@ class DiscoveryRuleTest < ActiveSupport::TestCase
|
|
123
125
|
assert_equal "must be less than 2147483648", rule.errors[:priority].first
|
124
126
|
end
|
125
127
|
|
128
|
+
test_attributes :pid => '84503d8d-86f6-49bf-ab97-eff418d3e3d0'
|
126
129
|
test "should not create with invalid max count type" do
|
127
130
|
rule = DiscoveryRule.new(
|
128
131
|
:name => 'new_rule',
|
@@ -0,0 +1,107 @@
|
|
1
|
+
{
|
2
|
+
"name": "sinn1636.lan",
|
3
|
+
"facts": {
|
4
|
+
"processor3": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
|
5
|
+
"productname": "IBM System x -[7870K4G]-",
|
6
|
+
"kernelmajversion": "2.6",
|
7
|
+
"kernelversion": "2.6.32",
|
8
|
+
"macaddress_vnet0": "FE:54:00:1E:45:13",
|
9
|
+
"macaddress_br181": "E4:1F:13:CC:36:58",
|
10
|
+
"macaddress_usb0": "E6:1F:13:D0:43:A3",
|
11
|
+
"macaddress_vnet1": "FE:54:00:45:E5:3E",
|
12
|
+
"rubysitedir": "/usr/lib/ruby/site_ruby/1.8",
|
13
|
+
"macaddress_br182": "E4:1F:13:CC:36:58",
|
14
|
+
"processor4": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
|
15
|
+
"macaddress_vnet2": "FE:54:00:93:F5:56",
|
16
|
+
"macaddress_br183": "E4:1F:13:CC:36:58",
|
17
|
+
"ps": "ps -ef",
|
18
|
+
"processor5": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
|
19
|
+
"macaddress_vnet10": "FE:54:00:7D:F8:24",
|
20
|
+
"uniqueid": "230a021b",
|
21
|
+
"macaddress_vnet3": "FE:54:00:05:49:DE",
|
22
|
+
"lsbdistcodename": "Santiago",
|
23
|
+
"hardwareisa": "x86_64",
|
24
|
+
"lsbdistrelease": "6.2",
|
25
|
+
"processor6": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
|
26
|
+
"serialnumber": "abcdefg",
|
27
|
+
"processor7": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
|
28
|
+
"macaddress_vnet4": "FE:54:00:62:53:67",
|
29
|
+
"hostname": "h02",
|
30
|
+
"osfamily": "RedHat",
|
31
|
+
"gateway_if": "br180",
|
32
|
+
"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
|
+
"kernelrelease": "2.6.32-131.12.1.el6.x86_64",
|
34
|
+
"kernel": "Linux",
|
35
|
+
"facterversion": "1.6.2",
|
36
|
+
"uptime_seconds": "13651752",
|
37
|
+
"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",
|
39
|
+
"macaddress_vnet7": "FE:54:00:D8:F9:38",
|
40
|
+
"netmask_br180": "255.255.255.192",
|
41
|
+
"macaddress_eth0": "E4:1F:13:CC:36:58",
|
42
|
+
"is_virtual": "false",
|
43
|
+
"macaddress": "E4:1F:13:CC:36:58",
|
44
|
+
"sshdsakey": "AAAAB3NzaC1kc3MAAACBAIbK60jlhYKSd4Nx6LCQPMUZcq/P1lTY3sQVrwpmfbF7d4JOGed2RWSoTBAzP3/Tjwlf+8DZ3Jd8a6Yhd6WuBzinE+owym8LXo2gDTvelhnzOVrTytM8hAi8uFEiBTGbnN1zka2y7qCPVxEu+kV20qC3mPODGxpV6y/4KOZ5Y4SHAAAAFQCyjeF+Jy9CDhiD2tfnmtMGAn1xzQAAAIBwtnUhhkB0r3ivPdQZgVy6qha8AJQG94I9FU9FnGJJEjkkfqlgNrj9SxV6Cg9EcrntnAKxZxk7PQhgvDesx69Lap9PAx3Ffb5Pl47cd7ilOXv2RJGKuxZQHNdKUF2445POwNjxSuhEkIB3/zpFXBB/zPMRfqUtlXJEwP9m6z9UFgAAAIAQDBpmcGChFP7i8T2RdMZo3hSMnU4y5lpEGhmwfbODoLSAX37wWQwUmwRP8byTEqFL0+5bp3hRbt/67EoD1O6n39/We19g/UqHkbUdZQqLqFjJfyzqfepq4HXtIIT8GbqW+FGJkH9x2fY5gtQrn9nVdmPDTwERFS98qU9glufbIw==",
|
45
|
+
"uptime": "158 days",
|
46
|
+
"manufacturer": "IBM",
|
47
|
+
"macaddress_eth1": "E4:1F:13:CC:36:5A",
|
48
|
+
"timezone": "GMT",
|
49
|
+
"fqdn": "a.server.b.domain",
|
50
|
+
"ipaddress_br180": "10.35.27.2",
|
51
|
+
"ipaddress_eth0": "10.35.27.3",
|
52
|
+
"ipaddress_eth1": "10.35.27.4",
|
53
|
+
"puppetversion": "2.6.12",
|
54
|
+
"path": "/root/.gem/bin:/root/.gem/ruby/1.8/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/sbin:/usr/sbin:/root/scripts",
|
55
|
+
"hardwaremodel": "x86_64",
|
56
|
+
"macaddress_eth0_181": "E4:1F:13:CC:36:58",
|
57
|
+
"netmask_lo": "255.0.0.0",
|
58
|
+
"uptime_days": "158",
|
59
|
+
"virtual": "physical",
|
60
|
+
"operatingsystemrelease": "6.2",
|
61
|
+
"processorcount": "8",
|
62
|
+
"sshrsakey": "AAAAB3NzaC1xcEabbAABIwAAAQEAwXfnuA0+6C6G152kzCbSZvTyUBrMwc0PGnmZgFpC3x4SkcMgRmtayPNqmY1vyYwyka1lNUoyU9u3TXOUkd7WrodoNYBbDQXWCAVpUci5099zUuZ8RVLcokKwNmQO0d1URgSLt2TtuLiUDB7JU2mHkoOuW9n7ODq+UzYsd2wf+/TQrvgsuyi25MROH2Z3WfMO+fmsj77h34gkuaavwB4e6lNRynjZLuEc4POFvDEW6kGCYm1g/8kRwUlB/Z1Cu0egxtxnTjILFFwfYFQu2Ksig020q1gLX3o4YL9X/YZz+JQuAOLGpK3F0owQUL7Ie3vokDsVmz2AweuLDFeh54i2Bw==",
|
63
|
+
"macaddress_eth0_182": "E4:1F:13:CC:36:58",
|
64
|
+
"memorysize": "15.57 GB",
|
65
|
+
"ipaddress": "10.35.27.2",
|
66
|
+
"rubyversion": "1.8.7",
|
67
|
+
"macaddress_eth0_183": "E4:1F:13:CC:36:58",
|
68
|
+
"physicalprocessorcount": "1",
|
69
|
+
"network_lo": "127.0.0.0",
|
70
|
+
"gateway": "10.35.27.62",
|
71
|
+
"lsbdistid": "RedHatEnterpriseServer",
|
72
|
+
"network_br180": "10.35.27.0",
|
73
|
+
"lsbdistdescription": "Red Hat Enterprise Linux Server release 6.2 (Santiago)",
|
74
|
+
"swapsize": "17.70 GB",
|
75
|
+
"processor0": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
|
76
|
+
"processor1": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
|
77
|
+
"macaddress_br180": "E4:1F:13:CC:36:58",
|
78
|
+
"selinux": "false",
|
79
|
+
"domain": "server.b.domain",
|
80
|
+
"architecture": "x86_64",
|
81
|
+
"uptime_hours": "3792",
|
82
|
+
"memoryfree": "6.87 GB",
|
83
|
+
"augeasversion": "0.9.0",
|
84
|
+
"operatingsystem": "RedHat",
|
85
|
+
"ipaddress_lo": "127.0.0.1",
|
86
|
+
"processor2": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
|
87
|
+
"type": "Main Server Chassis",
|
88
|
+
"id": "root",
|
89
|
+
"vlans": "181,182,183",
|
90
|
+
"lsbmajdistrelease": "6",
|
91
|
+
"swapfree": "16.72 GB",
|
92
|
+
"netmask": "255.255.255.192",
|
93
|
+
"discovery_bootif": "E4:1F:13:CC:36:58",
|
94
|
+
"memorysize_mb": "742.13",
|
95
|
+
"blockdevice_sda_size": "214749184",
|
96
|
+
"lldp_neighbor_chassisID_eth1": "0c:27:24:2c:c5:04",
|
97
|
+
"lldp_neighbor_portID_eth1": "Eth170/1/3",
|
98
|
+
"lldp_neighbor_sysName_eth1": "DC2-A03-DR-01",
|
99
|
+
"lldp_neighbor_mngAddr_ipv4_eth1": "192.0.2.13",
|
100
|
+
"lldp_neighbor_PVID_eth1": "184",
|
101
|
+
"lldp_neighbor_chassisID_eth2": "e0:d1:73:38:5a:84",
|
102
|
+
"lldp_neighbor_portID_eth2": "Eth171/1/3",
|
103
|
+
"lldp_neighbor_sysName_eth2": "DC2-A04-DR-03",
|
104
|
+
"lldp_neighbor_mngAddr_ipv4_eth2": "192.0.2.13",
|
105
|
+
"lldp_neighbor_PVID_eth2": "182"
|
106
|
+
}
|
107
|
+
}
|
@@ -0,0 +1,107 @@
|
|
1
|
+
{
|
2
|
+
"name": "sinn1636.lan",
|
3
|
+
"facts": {
|
4
|
+
"processor3": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
|
5
|
+
"productname": "IBM System x -[7870K4G]-",
|
6
|
+
"kernelmajversion": "2.6",
|
7
|
+
"kernelversion": "2.6.32",
|
8
|
+
"macaddress_vnet0": "FE:54:00:1E:45:13",
|
9
|
+
"macaddress_br181": "E4:1F:13:CC:36:58",
|
10
|
+
"macaddress_usb0": "E6:1F:13:D0:43:A3",
|
11
|
+
"macaddress_vnet1": "FE:54:00:45:E5:3E",
|
12
|
+
"rubysitedir": "/usr/lib/ruby/site_ruby/1.8",
|
13
|
+
"macaddress_br182": "E4:1F:13:CC:36:58",
|
14
|
+
"processor4": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
|
15
|
+
"macaddress_vnet2": "FE:54:00:93:F5:56",
|
16
|
+
"macaddress_br183": "E4:1F:13:CC:36:58",
|
17
|
+
"ps": "ps -ef",
|
18
|
+
"processor5": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
|
19
|
+
"macaddress_vnet10": "FE:54:00:7D:F8:24",
|
20
|
+
"uniqueid": "230a021b",
|
21
|
+
"macaddress_vnet3": "FE:54:00:05:49:DE",
|
22
|
+
"lsbdistcodename": "Santiago",
|
23
|
+
"hardwareisa": "x86_64",
|
24
|
+
"lsbdistrelease": "6.2",
|
25
|
+
"processor6": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
|
26
|
+
"serialnumber": "abcdefg",
|
27
|
+
"processor7": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
|
28
|
+
"macaddress_vnet4": "FE:54:00:62:53:67",
|
29
|
+
"hostname": "h02",
|
30
|
+
"osfamily": "RedHat",
|
31
|
+
"gateway_if": "br180",
|
32
|
+
"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
|
+
"kernelrelease": "2.6.32-131.12.1.el6.x86_64",
|
34
|
+
"kernel": "Linux",
|
35
|
+
"facterversion": "1.6.2",
|
36
|
+
"uptime_seconds": "13651752",
|
37
|
+
"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",
|
39
|
+
"macaddress_vnet7": "FE:54:00:D8:F9:38",
|
40
|
+
"netmask_br180": "255.255.255.192",
|
41
|
+
"macaddress_eth0": "E4:1F:13:CC:36:58",
|
42
|
+
"is_virtual": "false",
|
43
|
+
"macaddress": "E4:1F:13:CC:36:58",
|
44
|
+
"sshdsakey": "AAAAB3NzaC1kc3MAAACBAIbK60jlhYKSd4Nx6LCQPMUZcq/P1lTY3sQVrwpmfbF7d4JOGed2RWSoTBAzP3/Tjwlf+8DZ3Jd8a6Yhd6WuBzinE+owym8LXo2gDTvelhnzOVrTytM8hAi8uFEiBTGbnN1zka2y7qCPVxEu+kV20qC3mPODGxpV6y/4KOZ5Y4SHAAAAFQCyjeF+Jy9CDhiD2tfnmtMGAn1xzQAAAIBwtnUhhkB0r3ivPdQZgVy6qha8AJQG94I9FU9FnGJJEjkkfqlgNrj9SxV6Cg9EcrntnAKxZxk7PQhgvDesx69Lap9PAx3Ffb5Pl47cd7ilOXv2RJGKuxZQHNdKUF2445POwNjxSuhEkIB3/zpFXBB/zPMRfqUtlXJEwP9m6z9UFgAAAIAQDBpmcGChFP7i8T2RdMZo3hSMnU4y5lpEGhmwfbODoLSAX37wWQwUmwRP8byTEqFL0+5bp3hRbt/67EoD1O6n39/We19g/UqHkbUdZQqLqFjJfyzqfepq4HXtIIT8GbqW+FGJkH9x2fY5gtQrn9nVdmPDTwERFS98qU9glufbIw==",
|
45
|
+
"uptime": "158 days",
|
46
|
+
"manufacturer": "IBM",
|
47
|
+
"macaddress_eth1": "E4:1F:13:CC:36:5A",
|
48
|
+
"timezone": "GMT",
|
49
|
+
"fqdn": "a.server.b.domain",
|
50
|
+
"ipaddress_br180": "10.35.27.2",
|
51
|
+
"ipaddress_eth0": "10.35.27.3",
|
52
|
+
"ipaddress_eth1": "10.35.27.4",
|
53
|
+
"puppetversion": "2.6.12",
|
54
|
+
"path": "/root/.gem/bin:/root/.gem/ruby/1.8/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/sbin:/usr/sbin:/root/scripts",
|
55
|
+
"hardwaremodel": "x86_64",
|
56
|
+
"macaddress_eth0_181": "E4:1F:13:CC:36:58",
|
57
|
+
"netmask_lo": "255.0.0.0",
|
58
|
+
"uptime_days": "158",
|
59
|
+
"virtual": "physical",
|
60
|
+
"operatingsystemrelease": "6.2",
|
61
|
+
"processorcount": "8",
|
62
|
+
"sshrsakey": "AAAAB3NzaC1xcEabbAABIwAAAQEAwXfnuA0+6C6G152kzCbSZvTyUBrMwc0PGnmZgFpC3x4SkcMgRmtayPNqmY1vyYwyka1lNUoyU9u3TXOUkd7WrodoNYBbDQXWCAVpUci5099zUuZ8RVLcokKwNmQO0d1URgSLt2TtuLiUDB7JU2mHkoOuW9n7ODq+UzYsd2wf+/TQrvgsuyi25MROH2Z3WfMO+fmsj77h34gkuaavwB4e6lNRynjZLuEc4POFvDEW6kGCYm1g/8kRwUlB/Z1Cu0egxtxnTjILFFwfYFQu2Ksig020q1gLX3o4YL9X/YZz+JQuAOLGpK3F0owQUL7Ie3vokDsVmz2AweuLDFeh54i2Bw==",
|
63
|
+
"macaddress_eth0_182": "E4:1F:13:CC:36:58",
|
64
|
+
"memorysize": "15.57 GB",
|
65
|
+
"ipaddress": "10.35.27.2",
|
66
|
+
"rubyversion": "1.8.7",
|
67
|
+
"macaddress_eth0_183": "E4:1F:13:CC:36:58",
|
68
|
+
"physicalprocessorcount": "1",
|
69
|
+
"network_lo": "127.0.0.0",
|
70
|
+
"gateway": "10.35.27.62",
|
71
|
+
"lsbdistid": "RedHatEnterpriseServer",
|
72
|
+
"network_br180": "10.35.27.0",
|
73
|
+
"lsbdistdescription": "Red Hat Enterprise Linux Server release 6.2 (Santiago)",
|
74
|
+
"swapsize": "17.70 GB",
|
75
|
+
"processor0": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
|
76
|
+
"processor1": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
|
77
|
+
"macaddress_br180": "E4:1F:13:CC:36:58",
|
78
|
+
"selinux": "false",
|
79
|
+
"domain": "server.b.domain",
|
80
|
+
"architecture": "x86_64",
|
81
|
+
"uptime_hours": "3792",
|
82
|
+
"memoryfree": "6.87 GB",
|
83
|
+
"augeasversion": "0.9.0",
|
84
|
+
"operatingsystem": "RedHat",
|
85
|
+
"ipaddress_lo": "127.0.0.1",
|
86
|
+
"processor2": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
|
87
|
+
"type": "Main Server Chassis",
|
88
|
+
"id": "root",
|
89
|
+
"vlans": "181,182,183",
|
90
|
+
"lsbmajdistrelease": "6",
|
91
|
+
"swapfree": "16.72 GB",
|
92
|
+
"netmask": "255.255.255.192",
|
93
|
+
"discovery_bootif": "E4:1F:13:CC:36:58",
|
94
|
+
"memorysize_mb": "742.13",
|
95
|
+
"blockdevice_sda_size": "214749184",
|
96
|
+
"lldp_neighbor_chassisID_eth1": "0c:27:24:2c:c5:04",
|
97
|
+
"lldp_neighbor_portID_eth1": "Eth170/1/3",
|
98
|
+
"lldp_neighbor_sysName_eth1": "DC2-A03-DR-01",
|
99
|
+
"lldp_neighbor_mngAddr_ipv4_eth1": "192.0.2.13",
|
100
|
+
"lldp_neighbor_PVID_eth1": "182",
|
101
|
+
"lldp_neighbor_chassisID_eth0": "e0:d1:73:38:5a:84",
|
102
|
+
"lldp_neighbor_portID_eth0": "Eth171/1/3",
|
103
|
+
"lldp_neighbor_sysName_eth0": "DC2-A04-DR-03",
|
104
|
+
"lldp_neighbor_mngAddr_ipv4_eth0": "192.0.2.13",
|
105
|
+
"lldp_neighbor_PVID_eth0": "182"
|
106
|
+
}
|
107
|
+
}
|
@@ -19,6 +19,19 @@ class HostDiscoveredTest < ActiveSupport::TestCase
|
|
19
19
|
assert Host::Discovered.find_by_name('mace41f13cc3658')
|
20
20
|
end
|
21
21
|
|
22
|
+
test "should import facts from yaml with MAC-based generator as Host::Discovered" do
|
23
|
+
Setting[:discovery_naming] = "MAC-name"
|
24
|
+
host = discover_host_from_facts(@facts)
|
25
|
+
assert_equal "myrna-katie-wesly-maslyn", host.name
|
26
|
+
end
|
27
|
+
|
28
|
+
test "should import facts from yaml with random based generator as Host::Discovered" do
|
29
|
+
Setting[:discovery_naming] = "Random-name"
|
30
|
+
Rails.cache.stubs(:fetch).with("name_generator_register").returns(1305)
|
31
|
+
host = discover_host_from_facts(@facts)
|
32
|
+
assert_equal "velma-startin", host.name
|
33
|
+
end
|
34
|
+
|
22
35
|
test 'fact value association is set accordingly' do
|
23
36
|
discovered_host = FactoryBot.create(:discovered_host, :with_facts, :fact_count => 1)
|
24
37
|
fact_value = discovered_host.fact_values.first
|
@@ -32,6 +45,14 @@ class HostDiscoveredTest < ActiveSupport::TestCase
|
|
32
45
|
assert_equal subnet, host.primary_interface.subnet
|
33
46
|
end
|
34
47
|
|
48
|
+
test "should setup subnet when update_subnets_from_facts is true" do
|
49
|
+
Setting[:update_subnets_from_facts] = true
|
50
|
+
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)
|
52
|
+
host = discover_host_from_facts(@facts)
|
53
|
+
assert_equal subnet, host.primary_interface.subnet
|
54
|
+
end
|
55
|
+
|
35
56
|
test "should setup subnet with org and loc set via settings" do
|
36
57
|
org = FactoryBot.create(:organization, :name => "subnet_org")
|
37
58
|
loc = FactoryBot.create(:location, :name => "subnet_loc")
|
@@ -357,7 +378,57 @@ class HostDiscoveredTest < ActiveSupport::TestCase
|
|
357
378
|
end
|
358
379
|
end
|
359
380
|
|
381
|
+
test "primary interface isn't touched with no LLDP facts" do
|
382
|
+
Setting[:discovery_auto_bond] = true
|
383
|
+
raw = parse_json_fixture('/facts.json')['facts']
|
384
|
+
host = discover_host_from_facts(raw)
|
385
|
+
refute_nil host.primary_interface
|
386
|
+
assert_equal "eth0", host.primary_interface.identifier
|
387
|
+
end
|
388
|
+
|
389
|
+
test "provision_interface isn't touched with no peer on the same VLAN" do
|
390
|
+
Setting[:discovery_auto_bond] = true
|
391
|
+
raw = parse_json_fixture('/facts_with_lldp.json')['facts']
|
392
|
+
host = discover_host_from_facts(raw)
|
393
|
+
refute_nil host.primary_interface
|
394
|
+
assert_equal "eth0", host.primary_interface.identifier
|
395
|
+
end
|
396
|
+
|
397
|
+
test "provision_interface is switched to bond0 with more than one interface on the same VLAN" do
|
398
|
+
Setting[:discovery_auto_bond] = true
|
399
|
+
raw = parse_json_fixture('/facts_with_lldp_bond_candidate.json')['facts']
|
400
|
+
host = discover_host_from_facts(raw)
|
401
|
+
refute_nil host.primary_interface
|
402
|
+
assert_equal "bond0", host.primary_interface.identifier
|
403
|
+
end
|
404
|
+
|
405
|
+
test "provision_interface is not switched to bond0 if disabled" do
|
406
|
+
Setting[:discovery_auto_bond] = false
|
407
|
+
raw = parse_json_fixture('/facts_with_lldp_bond_candidate.json')['facts']
|
408
|
+
host = discover_host_from_facts(raw)
|
409
|
+
refute_nil host.primary_interface
|
410
|
+
assert_equal "eth0", host.primary_interface.identifier
|
411
|
+
end
|
412
|
+
|
413
|
+
test "former provision_interface is cleanup up after switching to bond0" do
|
414
|
+
Setting[:discovery_auto_bond] = true
|
415
|
+
raw = parse_json_fixture('/facts_with_lldp_bond_candidate.json')['facts']
|
416
|
+
host = discover_host_from_facts(raw)
|
417
|
+
refute_nil host.primary_interface
|
418
|
+
|
419
|
+
former_interface = nil
|
420
|
+
host.interfaces.each do |interface|
|
421
|
+
former_interface = interface if interface.identifier == 'eth0'
|
422
|
+
end
|
423
|
+
|
424
|
+
refute_nil former_interface
|
425
|
+
assert_instance_of ::Nic::Managed, former_interface
|
426
|
+
assert_nil former_interface.ip
|
427
|
+
assert_nil former_interface.name
|
428
|
+
assert_equal false, former_interface.primary
|
429
|
+
end
|
430
|
+
|
360
431
|
def parse_json_fixture(relative_path)
|
361
|
-
|
432
|
+
JSON.parse(File.read(File.expand_path(File.dirname(__FILE__) + relative_path)))
|
362
433
|
end
|
363
434
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class LldpNeighborsTest < ActiveSupport::TestCase
|
4
|
+
test "#get_neighbors_by_interface gives nothing with no LLDP facts" do
|
5
|
+
assert_nil simple_facts.get_neighbors_by_interface('eth0')
|
6
|
+
end
|
7
|
+
|
8
|
+
test "#get_neighbors_by_interface gives nothing with unmatching PVID in LLDP facts" do
|
9
|
+
assert_nil lldp_facts.get_neighbors_by_interface('eth0')
|
10
|
+
end
|
11
|
+
|
12
|
+
test "#get_neighbors_by_interface gives a valid pair for LLDP facts with matching PVID" do
|
13
|
+
assert_equal %w(eth0 eth1), bond_facts.get_neighbors_by_interface('eth0')
|
14
|
+
assert_equal %w(eth0 eth1), bond_facts.get_neighbors_by_interface('eth1')
|
15
|
+
assert_nil bond_facts.get_neighbors_by_interface('br182')
|
16
|
+
end
|
17
|
+
|
18
|
+
test "#list_by_pvid gives an empty Hash without LLDP facts" do
|
19
|
+
assert_equal({}, simple_facts.list_by_pvid)
|
20
|
+
assert_equal({}, ForemanDiscovery::LldpNeighbors.from_facts({}).list_by_pvid)
|
21
|
+
end
|
22
|
+
|
23
|
+
test "#list_by_pvid gives an empty Hash without LLDP facts" do
|
24
|
+
assert_equal({'182' => %w(eth2), '184' => %w(eth1)}, lldp_facts.list_by_pvid)
|
25
|
+
end
|
26
|
+
|
27
|
+
test "#list_by_pvid pairs interfaces by PVID" do
|
28
|
+
assert_equal({'182' => %w(eth0 eth1)}, bond_facts.list_by_pvid)
|
29
|
+
end
|
30
|
+
|
31
|
+
test "#list_by_pvid supports multiple PVIDs" do
|
32
|
+
assert_equal({'182' => %w(eth2), '184' => %w(eth1)}, lldp_facts.list_by_pvid)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def simple_facts
|
38
|
+
neighbors 'facts'
|
39
|
+
end
|
40
|
+
|
41
|
+
def lldp_facts
|
42
|
+
neighbors 'facts_with_lldp'
|
43
|
+
end
|
44
|
+
|
45
|
+
def bond_facts
|
46
|
+
neighbors 'facts_with_lldp_bond_candidate'
|
47
|
+
end
|
48
|
+
|
49
|
+
def neighbors(name)
|
50
|
+
ForemanDiscovery::LldpNeighbors.from_facts(get_facts name)
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_facts(name)
|
54
|
+
JSON.parse(File.read(File.expand_path(File.dirname(__FILE__) + "/#{name}.json")))['facts']
|
55
|
+
end
|
56
|
+
end
|