foreman_netbox 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +619 -0
- data/README.md +50 -0
- data/Rakefile +50 -0
- data/app/contracts/foreman_netbox/device_contract.rb +42 -0
- data/app/contracts/foreman_netbox/params/interface_params.rb +16 -0
- data/app/contracts/foreman_netbox/params/ip_address_params.rb +15 -0
- data/app/contracts/foreman_netbox/params/tenant_params.rb +13 -0
- data/app/contracts/foreman_netbox/virtual_machine_contract.rb +29 -0
- data/app/interactors/foreman_netbox/concerns/facts.rb +11 -0
- data/app/interactors/foreman_netbox/concerns/primary_ips.rb +25 -0
- data/app/interactors/foreman_netbox/delete_host/delete_device.rb +20 -0
- data/app/interactors/foreman_netbox/delete_host/delete_virtual_machine.rb +20 -0
- data/app/interactors/foreman_netbox/delete_host/organizer.rb +12 -0
- data/app/interactors/foreman_netbox/sync_host/organizer.rb +35 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/create.rb +36 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/find.rb +41 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/organizer.rb +30 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/save_netbox_url.rb +29 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/create.rb +32 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/find.rb +28 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/organizer.rb +20 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/create.rb +34 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/find.rb +28 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/organizer.rb +22 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/create.rb +34 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find.rb +40 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/organizer.rb +22 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/update.rb +33 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/create.rb +37 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/delete.rb +36 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find.rb +30 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/organizer.rb +23 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/create.rb +46 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete.rb +40 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find.rb +32 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/organizer.rb +24 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/update.rb +39 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update.rb +38 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_site/create.rb +32 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_site/find.rb +28 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_site/organizer.rb +25 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_site/update.rb +35 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/update.rb +85 -0
- data/app/interactors/foreman_netbox/sync_host/sync_device/validate.rb +25 -0
- data/app/interactors/foreman_netbox/sync_host/sync_tenant/create.rb +30 -0
- data/app/interactors/foreman_netbox/sync_host/sync_tenant/find.rb +26 -0
- data/app/interactors/foreman_netbox/sync_host/sync_tenant/organizer.rb +19 -0
- data/app/interactors/foreman_netbox/sync_host/sync_tenant/update.rb +33 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/create.rb +34 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/find.rb +34 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/organizer.rb +28 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/save_netbox_url.rb +31 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/create.rb +35 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/find.rb +28 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/organizer.rb +22 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/create.rb +34 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/find.rb +32 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/organizer.rb +22 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/update.rb +35 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/create.rb +33 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/delete.rb +36 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find.rb +30 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/organizer.rb +23 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/create.rb +46 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete.rb +40 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find.rb +28 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/organizer.rb +24 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/update.rb +39 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update.rb +38 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/update.rb +82 -0
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/validate.rb +25 -0
- data/app/jobs/foreman_netbox/sync_host_job.rb +19 -0
- data/app/lib/foreman_netbox/api.rb +12 -0
- data/app/models/concerns/foreman_netbox/host_extensions.rb +27 -0
- data/app/models/concerns/foreman_netbox/location_extensions.rb +13 -0
- data/app/models/concerns/foreman_netbox/nic/base_extensions.rb +23 -0
- data/app/models/concerns/foreman_netbox/user_usergroup_common_extensions.rb +18 -0
- data/app/models/foreman_netbox/netbox_facet.rb +34 -0
- data/app/models/orchestration/netbox.rb +64 -0
- data/app/models/setting/netbox.rb +32 -0
- data/app/services/foreman_netbox/cached_netbox_parameters.rb +103 -0
- data/app/services/foreman_netbox/netbox_parameters.rb +185 -0
- data/app/services/foreman_netbox/netbox_parameters_comparator.rb +96 -0
- data/app/views/hosts/_netbox_tab.html.erb +28 -0
- data/config/routes.rb +4 -0
- data/db/migrate/20200527135812_create_netbox_facet.rb +12 -0
- data/db/migrate/20200604141933_add_sync_info_to_netbox_facet.rb +8 -0
- data/db/migrate/20200708093607_add_raw_data_to_netbox_facet.rb +7 -0
- data/lib/foreman_netbox.rb +6 -0
- data/lib/foreman_netbox/engine.rb +64 -0
- data/lib/foreman_netbox/version.rb +5 -0
- data/lib/tasks/foreman_netbox_tasks.rake +67 -0
- data/test/factories/host.rb +17 -0
- data/test/factories/netbox_facet.rb +17 -0
- data/test/fixtures/facts/k8s_physical_host.json +328 -0
- data/test/fixtures/facts/rhel_physical_host.json +512 -0
- data/test/fixtures/facts/rhel_virtual_host.json +455 -0
- data/test/fixtures/netbox_device_raw_data.json +330 -0
- data/test/fixtures/netbox_virtual_machine_raw_data.json +241 -0
- data/test/integration/foreman_netbox/sync_k8s_physical_host_test.rb +81 -0
- data/test/integration/foreman_netbox/sync_rhel_physical_host_test.rb +81 -0
- data/test/integration/foreman_netbox/sync_rhel_virtual_host_test.rb +93 -0
- data/test/interactors/foreman_netbox/sync_host/organizer_test.rb +78 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/create_test.rb +65 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/find_test.rb +105 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/save_netbox_url_test.rb +39 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/create_test.rb +45 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/find_test.rb +58 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/create_test.rb +55 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/find_test.rb +63 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/create_test.rb +48 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find_test.rb +105 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/update_test.rb +54 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/create_test.rb +51 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/delete_test.rb +41 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find_test.rb +53 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/create_test.rb +80 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete_test.rb +72 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find_test.rb +51 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/update_test.rb +64 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update_test.rb +92 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/create_test.rb +51 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/find_test.rb +59 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/update_test.rb +54 -0
- data/test/interactors/foreman_netbox/sync_host/sync_device/update_test.rb +188 -0
- data/test/interactors/foreman_netbox/sync_host/sync_tenant/create_test.rb +50 -0
- data/test/interactors/foreman_netbox/sync_host/sync_tenant/find_test.rb +58 -0
- data/test/interactors/foreman_netbox/sync_host/sync_tenant/update_test.rb +59 -0
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/create_test.rb +74 -0
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/find_test.rb +77 -0
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/save_netbox_url_test.rb +39 -0
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/create_test.rb +54 -0
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/find_test.rb +58 -0
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/create_test.rb +50 -0
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/find_test.rb +65 -0
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/update_test.rb +54 -0
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/create_test.rb +53 -0
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/delete_test.rb +37 -0
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find_test.rb +53 -0
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/create_test.rb +80 -0
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete_test.rb +73 -0
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find_test.rb +51 -0
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/update_test.rb +64 -0
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update_test.rb +88 -0
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/update_test.rb +171 -0
- data/test/jobs/foreman_netbox/sync_host_job_test.rb +14 -0
- data/test/models/foreman_netbox/location_test.rb +42 -0
- data/test/models/foreman_netbox/netbox_facet_test.rb +219 -0
- data/test/models/foreman_netbox/nics/base_test.rb +81 -0
- data/test/models/foreman_netbox/usergroup_test.rb +23 -0
- data/test/models/host/managed_test.rb +63 -0
- data/test/services/foreman_netbox/netbox_attributes_test.rb +278 -0
- data/test/services/foreman_netbox/netbox_parameters_comparator_test.rb +136 -0
- data/test/test_plugin_helper.rb +25 -0
- metadata +343 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_plugin_helper'
|
4
|
+
|
5
|
+
module ForemanNetbox
|
6
|
+
module Nic
|
7
|
+
class BaseTest < ActiveSupport::TestCase
|
8
|
+
describe '#netbox_name' do
|
9
|
+
context 'with identifier' do
|
10
|
+
let(:nic) { FactoryBot.build_stubbed(:nic_base, identifier: 'eth1') }
|
11
|
+
|
12
|
+
it { assert_equal nic.identifier, nic.netbox_name }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with mac' do
|
16
|
+
let(:nic) { FactoryBot.build_stubbed(:nic_base, identifier: nil) }
|
17
|
+
|
18
|
+
it { assert_equal "Interface #{nic.mac}", nic.netbox_name }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'without identifier and mac' do
|
22
|
+
let(:nic) { FactoryBot.build_stubbed(:nic_base, identifier: nil, mac: nil) }
|
23
|
+
|
24
|
+
it { assert_nil nic.netbox_name }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#netbox_ip' do
|
29
|
+
let(:subnet) { FactoryBot.build_stubbed(:subnet_ipv4, mask: '255.255.0.0') }
|
30
|
+
let(:nic) { FactoryBot.build_stubbed(:nic_base, ip: '10.10.10.0', subnet: subnet) }
|
31
|
+
|
32
|
+
it { assert_equal '10.10.10.0/16', nic.netbox_ip }
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#netbox_ip6' do
|
36
|
+
let(:subnet6) { FactoryBot.build_stubbed(:subnet_ipv6, mask: 'ffff:ffff::') }
|
37
|
+
let(:nic) { FactoryBot.build_stubbed(:nic_base, ip6: '2001:db8::', subnet6: subnet6) }
|
38
|
+
|
39
|
+
it { assert_equal '2001:db8::/32', nic.netbox_ip6 }
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#netbox_ips' do
|
43
|
+
context 'with ip' do
|
44
|
+
let(:subnet) { FactoryBot.build_stubbed(:subnet_ipv4) }
|
45
|
+
let(:nic) { FactoryBot.build_stubbed(:nic_base, ip: '10.10.10.0', subnet: subnet) }
|
46
|
+
|
47
|
+
it { assert_equal [nic.netbox_ip], nic.netbox_ips }
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'with ip6' do
|
51
|
+
let(:subnet6) { FactoryBot.build_stubbed(:subnet_ipv6) }
|
52
|
+
let(:nic) { FactoryBot.build_stubbed(:nic_base, ip6: '2001:db8::', subnet6: subnet6) }
|
53
|
+
|
54
|
+
it { assert_equal [nic.netbox_ip6], nic.netbox_ips }
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'with ip and ip6' do
|
58
|
+
let(:subnet) { FactoryBot.build_stubbed(:subnet_ipv4) }
|
59
|
+
let(:subnet6) { FactoryBot.build_stubbed(:subnet_ipv6) }
|
60
|
+
let(:nic) do
|
61
|
+
FactoryBot.build_stubbed(
|
62
|
+
:nic_base,
|
63
|
+
ip: '10.10.10.0',
|
64
|
+
ip6: '2001:db8::',
|
65
|
+
subnet: subnet,
|
66
|
+
subnet6: subnet6
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
it { assert_equal [nic.netbox_ip, nic.netbox_ip6], nic.netbox_ips }
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'without ip and ip6' do
|
74
|
+
let(:nic) { FactoryBot.build_stubbed(:nic_base) }
|
75
|
+
|
76
|
+
it { assert_equal [], nic.netbox_ips }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_plugin_helper'
|
4
|
+
|
5
|
+
module ForemanNetbox
|
6
|
+
class UsergroupTest < ActiveSupport::TestCase
|
7
|
+
describe '#netbox_tenant_name' do
|
8
|
+
let(:usergroup) { FactoryBot.build_stubbed(:usergroup, id: 1, name: usergroup_name) }
|
9
|
+
|
10
|
+
context 'when name is longer than 30' do
|
11
|
+
let(:usergroup_name) { SecureRandom.hex(16) }
|
12
|
+
|
13
|
+
it { assert_equal "#{usergroup.name.truncate(28, omission: '')}-#{usergroup.id}", usergroup.netbox_tenant_name }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when name is shorter than 30' do
|
17
|
+
let(:usergroup_name) { 'Name' }
|
18
|
+
|
19
|
+
it { assert_equal usergroup.name, usergroup.netbox_tenant_name }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_plugin_helper'
|
4
|
+
|
5
|
+
module Host
|
6
|
+
class ManagedTest < ActiveSupport::TestCase
|
7
|
+
let(:host) { FactoryBot.build(:host, :managed) }
|
8
|
+
|
9
|
+
context 'a host with Netbox orchestration' do
|
10
|
+
setup do
|
11
|
+
disable_orchestration
|
12
|
+
setup_default_netbox_settings
|
13
|
+
end
|
14
|
+
|
15
|
+
test 'should post_queue Netbox sync' do
|
16
|
+
host.save
|
17
|
+
tasks = host.post_queue.all.map(&:name)
|
18
|
+
assert_includes tasks, "Push host #{host} to Netbox"
|
19
|
+
assert_equal 1, tasks.size
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'should queue Netbox destroy' do
|
23
|
+
assert_valid host
|
24
|
+
host.queue.clear
|
25
|
+
host.destroy
|
26
|
+
tasks = host.queue.all.map(&:name)
|
27
|
+
assert_includes tasks, "Delete host #{host} from Netbox"
|
28
|
+
assert_equal 1, tasks.size
|
29
|
+
end
|
30
|
+
|
31
|
+
# test '#set_netbox is called during orchestration' do
|
32
|
+
# host.stubs(:skip_orchestration_for_testing?).returns(false) # Explicitly enable orchestration
|
33
|
+
# host.expects(:set_netbox).returns(true)
|
34
|
+
# assert host.save
|
35
|
+
# end
|
36
|
+
|
37
|
+
test '#set_netbox' do
|
38
|
+
host.expects(:push_to_netbox_async)
|
39
|
+
host.send(:set_netbox)
|
40
|
+
end
|
41
|
+
|
42
|
+
test '#del_netbox' do
|
43
|
+
host.expects(:delete_from_netbox)
|
44
|
+
host.send(:del_netbox)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
test '#push_to_netbox_async' do
|
49
|
+
ForemanNetbox::SyncHostJob.expects(:perform_later).with(host.id)
|
50
|
+
host.push_to_netbox_async
|
51
|
+
end
|
52
|
+
|
53
|
+
test '#push_to_netbox' do
|
54
|
+
::ForemanNetbox::SyncHost::Organizer.expects(:call).with(host: host)
|
55
|
+
host.push_to_netbox
|
56
|
+
end
|
57
|
+
|
58
|
+
test '#delete_from_netbox' do
|
59
|
+
::ForemanNetbox::DeleteHost::Organizer.expects(:call).with(host: host)
|
60
|
+
host.delete_from_netbox
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,278 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_plugin_helper'
|
4
|
+
|
5
|
+
module ForemanNetbox
|
6
|
+
class NetboxParametersTest < ActiveSupport::TestCase
|
7
|
+
describe '#tenant' do
|
8
|
+
let(:host) do
|
9
|
+
FactoryBot.build_stubbed(
|
10
|
+
:host,
|
11
|
+
:managed,
|
12
|
+
owner: FactoryBot.build_stubbed(:usergroup, name: expected[:name])
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:expected) do
|
17
|
+
{
|
18
|
+
name: 'Tenant Name',
|
19
|
+
slug: 'tenant-name',
|
20
|
+
tags: ForemanNetbox::NetboxParameters::DEFAULT_TAGS
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
it { assert_equal expected, host.netbox_facet.netbox_params.fetch(:tenant) }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#device' do
|
28
|
+
let(:host) do
|
29
|
+
FactoryBot.build_stubbed(:host, :managed, hostname: expected[:name]).tap do |host|
|
30
|
+
host.stubs(:facts).returns({ serialnumber: expected[:serial] })
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:expected) do
|
35
|
+
{
|
36
|
+
name: 'device_name',
|
37
|
+
serial: 'abc123',
|
38
|
+
tags: ForemanNetbox::NetboxParameters::DEFAULT_TAGS
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
it { assert_equal expected, host.netbox_facet.netbox_params.fetch(:device) }
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#device_role' do
|
46
|
+
let(:host) { FactoryBot.build_stubbed(:host, :managed) }
|
47
|
+
|
48
|
+
let(:expected) do
|
49
|
+
{ name: 'SERVER', color: '9e9e9e', slug: 'server' }
|
50
|
+
end
|
51
|
+
|
52
|
+
it { assert_equal expected, host.netbox_facet.netbox_params.fetch(:device_role) }
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#device_type' do
|
56
|
+
subject { host.netbox_facet.netbox_params.fetch(:device_type) }
|
57
|
+
|
58
|
+
let(:host) do
|
59
|
+
FactoryBot.build_stubbed(:host, :managed).tap do |host|
|
60
|
+
host.stubs(:facts).returns({ productname: expected[:model] })
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
let(:expected) do
|
65
|
+
{
|
66
|
+
model: 'Product Name',
|
67
|
+
slug: 'product-name',
|
68
|
+
tags: ForemanNetbox::NetboxParameters::DEFAULT_TAGS
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
it { assert_equal expected, subject }
|
73
|
+
|
74
|
+
context 'unknown' do
|
75
|
+
let(:host) { FactoryBot.build_stubbed(:host, :managed) }
|
76
|
+
|
77
|
+
let(:expected) do
|
78
|
+
{
|
79
|
+
model: 'Unknown',
|
80
|
+
slug: 'unknown',
|
81
|
+
tags: ForemanNetbox::NetboxParameters::DEFAULT_TAGS
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
it { assert_equal expected, subject }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '#manufacturer' do
|
90
|
+
subject { host.netbox_facet.netbox_params.fetch(:manufacturer) }
|
91
|
+
|
92
|
+
let(:host) do
|
93
|
+
FactoryBot.build_stubbed(:host, :managed).tap do |host|
|
94
|
+
host.stubs(:facts).returns({ manufacturer: expected[:name] })
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
let(:expected) do
|
99
|
+
{ name: 'Manufacturer Name', slug: 'manufacturer-name' }
|
100
|
+
end
|
101
|
+
|
102
|
+
it { assert_equal expected, subject }
|
103
|
+
|
104
|
+
context 'unknown' do
|
105
|
+
let(:host) { FactoryBot.build_stubbed(:host, :managed) }
|
106
|
+
|
107
|
+
let(:expected) do
|
108
|
+
{ name: 'Unknown', slug: 'unknown' }
|
109
|
+
end
|
110
|
+
|
111
|
+
it { assert_equal expected, subject }
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe '#site' do
|
116
|
+
let(:host) do
|
117
|
+
FactoryBot.build_stubbed(
|
118
|
+
:host,
|
119
|
+
:managed,
|
120
|
+
location: FactoryBot.build_stubbed(:location, name: expected[:name])
|
121
|
+
)
|
122
|
+
end
|
123
|
+
|
124
|
+
let(:expected) do
|
125
|
+
{
|
126
|
+
name: 'Site Name',
|
127
|
+
slug: 'site-name',
|
128
|
+
tags: ForemanNetbox::NetboxParameters::DEFAULT_TAGS
|
129
|
+
}
|
130
|
+
end
|
131
|
+
|
132
|
+
it { assert_equal expected, host.netbox_facet.netbox_params.fetch(:site) }
|
133
|
+
end
|
134
|
+
|
135
|
+
describe '#interfaces' do
|
136
|
+
let(:host) do
|
137
|
+
FactoryBot.build_stubbed(
|
138
|
+
:host,
|
139
|
+
:managed,
|
140
|
+
interfaces: [
|
141
|
+
FactoryBot.build_stubbed(
|
142
|
+
:nic_base,
|
143
|
+
identifier: expected.first[:name],
|
144
|
+
mac: expected.first[:mac_address]
|
145
|
+
)
|
146
|
+
]
|
147
|
+
)
|
148
|
+
end
|
149
|
+
|
150
|
+
let(:expected) do
|
151
|
+
[
|
152
|
+
name: 'eth1',
|
153
|
+
mac_address: 'FE:13:C6:44:29:24',
|
154
|
+
type: {
|
155
|
+
value: 'virtual'
|
156
|
+
},
|
157
|
+
tags: ForemanNetbox::NetboxParameters::DEFAULT_TAGS
|
158
|
+
]
|
159
|
+
end
|
160
|
+
|
161
|
+
it { assert_equal expected, host.netbox_facet.netbox_params.fetch(:interfaces) }
|
162
|
+
end
|
163
|
+
|
164
|
+
describe '#ip_addresses' do
|
165
|
+
let(:host) do
|
166
|
+
FactoryBot.build_stubbed(
|
167
|
+
:host,
|
168
|
+
:managed,
|
169
|
+
interfaces: [
|
170
|
+
FactoryBot.build_stubbed(
|
171
|
+
:nic_base,
|
172
|
+
identifier: expected.first[:interface][:name],
|
173
|
+
ip: expected.first[:address].split('/').first,
|
174
|
+
subnet: FactoryBot.build_stubbed(
|
175
|
+
:subnet_ipv4,
|
176
|
+
cidr: expected.first[:address].split('/').second
|
177
|
+
)
|
178
|
+
),
|
179
|
+
FactoryBot.build_stubbed(
|
180
|
+
:nic_base,
|
181
|
+
identifier: expected.second[:interface][:name],
|
182
|
+
ip6: expected.second[:address].split('/').first,
|
183
|
+
subnet6: FactoryBot.build_stubbed(
|
184
|
+
:subnet_ipv6,
|
185
|
+
cidr: expected.second[:address].split('/').second
|
186
|
+
)
|
187
|
+
)
|
188
|
+
]
|
189
|
+
)
|
190
|
+
end
|
191
|
+
|
192
|
+
let(:expected) do
|
193
|
+
[
|
194
|
+
{
|
195
|
+
address: '10.0.0.1/24',
|
196
|
+
interface: {
|
197
|
+
name: 'eth1'
|
198
|
+
},
|
199
|
+
tags: ForemanNetbox::NetboxParameters::DEFAULT_TAGS
|
200
|
+
},
|
201
|
+
{
|
202
|
+
address: '1500:0:2d0:201::1/64',
|
203
|
+
interface: {
|
204
|
+
name: 'eth2'
|
205
|
+
},
|
206
|
+
tags: ForemanNetbox::NetboxParameters::DEFAULT_TAGS
|
207
|
+
}
|
208
|
+
]
|
209
|
+
end
|
210
|
+
|
211
|
+
it { assert_equal expected, host.netbox_facet.netbox_params.fetch(:ip_addresses) }
|
212
|
+
end
|
213
|
+
|
214
|
+
describe '#virtual_machine' do
|
215
|
+
let(:host) do
|
216
|
+
FactoryBot.build_stubbed(:host, :managed, hostname: expected[:name]).tap do |host|
|
217
|
+
host.stubs(:compute?).returns(true)
|
218
|
+
host.stubs(:compute_object).returns(
|
219
|
+
OpenStruct.new(
|
220
|
+
cpus: expected[:vcpus],
|
221
|
+
memory_mb: expected[:memory],
|
222
|
+
volumes: [
|
223
|
+
OpenStruct.new(size_gb: expected[:disk] / 2),
|
224
|
+
OpenStruct.new(size_gb: expected[:disk] / 2)
|
225
|
+
]
|
226
|
+
)
|
227
|
+
)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
let(:expected) do
|
232
|
+
{
|
233
|
+
name: 'virtual_machine_name',
|
234
|
+
vcpus: 2,
|
235
|
+
memory: 128,
|
236
|
+
disk: 20,
|
237
|
+
tags: ForemanNetbox::NetboxParameters::DEFAULT_TAGS
|
238
|
+
}
|
239
|
+
end
|
240
|
+
|
241
|
+
it { assert_equal expected, host.netbox_facet.netbox_params.fetch(:virtual_machine) }
|
242
|
+
end
|
243
|
+
|
244
|
+
describe '#cluster' do
|
245
|
+
let(:host) do
|
246
|
+
FactoryBot.build_stubbed(:host, :managed).tap do |host|
|
247
|
+
host.stubs(:compute?).returns(true)
|
248
|
+
host.stubs(:compute_object).returns(
|
249
|
+
OpenStruct.new(cluster: expected[:name])
|
250
|
+
)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
let(:expected) do
|
255
|
+
{ name: 'Cluster Name', tags: ForemanNetbox::NetboxParameters::DEFAULT_TAGS }
|
256
|
+
end
|
257
|
+
|
258
|
+
it { assert_equal expected, host.netbox_facet.netbox_params.fetch(:cluster) }
|
259
|
+
end
|
260
|
+
|
261
|
+
describe '#cluster_type' do
|
262
|
+
let(:host) do
|
263
|
+
FactoryBot.build_stubbed(:host, :managed).tap do |host|
|
264
|
+
host.stubs(:compute?).returns(true)
|
265
|
+
host.stubs(:compute_resource).returns(
|
266
|
+
OpenStruct.new(type: 'Foreman::Model::Vmware')
|
267
|
+
)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
let(:expected) do
|
272
|
+
{ name: 'VMware ESXi', slug: 'vmware-esxi' }
|
273
|
+
end
|
274
|
+
|
275
|
+
it { assert_equal expected, host.netbox_facet.netbox_params.fetch(:cluster_type) }
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|