foreman_netbox 1.2.0 → 2.0.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.
- checksums.yaml +4 -4
- data/README.md +7 -6
- data/app/interactors/foreman_netbox/delete_host/delete_device.rb +1 -1
- data/app/interactors/foreman_netbox/delete_host/delete_virtual_machine.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/create.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/find.rb +3 -3
- data/app/interactors/foreman_netbox/sync_host/sync_device/organizer.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/save_netbox_url.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/create.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/find.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/create.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/find.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/create.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find.rb +2 -2
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/create.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/create.rb +2 -2
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update.rb +1 -3
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_site/create.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_site/find.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_tags/create.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_tags/find.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_tenant/create.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_tenant/find.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/create.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/find.rb +2 -2
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/organizer.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/save_netbox_url.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/create.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/find.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/create.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/find.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/create.rb +8 -8
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/create.rb +2 -2
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete.rb +2 -4
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update.rb +1 -3
- data/app/lib/foreman_netbox/api.rb +11 -2
- data/app/services/foreman_netbox/netbox_parameters.rb +2 -2
- data/app/services/foreman_netbox/netbox_parameters_comparator.rb +2 -2
- data/db/migrate/20230303095650_fix_netbox_settings_category_to_dsl.rb +0 -2
- data/lib/foreman_netbox/engine.rb +47 -40
- data/lib/foreman_netbox/version.rb +1 -1
- data/lib/tasks/foreman_netbox_tasks.rake +0 -48
- data/test/fixtures/netbox_device_raw_data.json +1 -1
- data/test/integration/foreman_netbox/sync_k8s_physical_host_test.rb +1 -1
- data/test/integration/foreman_netbox/sync_rhel_physical_host_test.rb +1 -1
- data/test/integration/foreman_netbox/sync_rhel_virtual_host_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_device/create_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_device/save_netbox_url_test.rb +2 -2
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/update_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/delete_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete_test.rb +2 -2
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/update_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update_test.rb +2 -2
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/update_test.rb +2 -2
- data/test/interactors/foreman_netbox/sync_host/sync_device/update_test.rb +2 -2
- data/test/interactors/foreman_netbox/sync_host/sync_tenant/update_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/save_netbox_url_test.rb +2 -2
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/update_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/delete_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete_test.rb +2 -2
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/update_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/update_test.rb +2 -2
- data/test/test_plugin_helper.rb +1 -1
- data/test/unit/foreman_netbox/api_test.rb +52 -0
- metadata +57 -56
@@ -8,8 +8,6 @@ module ForemanNetbox
|
|
8
8
|
class Engine < ::Rails::Engine
|
9
9
|
engine_name 'foreman_netbox'
|
10
10
|
|
11
|
-
config.autoload_paths += Dir["#{config.root}/app/interactors"]
|
12
|
-
|
13
11
|
# Add any db migrations
|
14
12
|
initializer 'foreman_netbox.load_app_instance_data' do |app|
|
15
13
|
ForemanNetbox::Engine.paths['db/migrate'].existent.each do |path|
|
@@ -17,51 +15,60 @@ module ForemanNetbox
|
|
17
15
|
end
|
18
16
|
end
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
# rubocop:disable Metrics/BlockLength
|
19
|
+
initializer 'foreman_netbox.register_plugin', before: :finisher_hook do |app|
|
20
|
+
app.reloader.to_prepare do
|
21
|
+
Foreman::Plugin.register :foreman_netbox do
|
22
|
+
requires_foreman '>= 3.13'
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
# Netbox Facet
|
25
|
+
register_facet(ForemanNetbox::NetboxFacet, :netbox_facet) do
|
26
|
+
set_dependent_action :destroy
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
# extend host show page
|
30
|
+
extend_page('hosts/show') do |context|
|
31
|
+
context.add_pagelet :main_tabs,
|
32
|
+
name: N_('Netbox'),
|
33
|
+
partial: 'hosts/netbox_tab',
|
34
|
+
onlyif: proc { |host| host.netbox_facet.synchronized_at }
|
35
|
+
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
37
|
+
settings do
|
38
|
+
category(:netbox, N_('Netbox')) do
|
39
|
+
setting 'netbox_url',
|
40
|
+
type: :string,
|
41
|
+
default: '-',
|
42
|
+
full_name: N_('Netbox UI URL'),
|
43
|
+
description: N_('URL where Netbox UI is reachable')
|
44
|
+
setting 'netbox_api_url',
|
45
|
+
type: :string,
|
46
|
+
default: '-',
|
47
|
+
full_name: N_('Netbox API URL'),
|
48
|
+
description: N_('URL where Netbox API is reachable, in case it is different than Netbox UI')
|
49
|
+
setting 'netbox_api_token',
|
50
|
+
type: :string,
|
51
|
+
default: '-',
|
52
|
+
full_name: N_('Netbox API token'),
|
53
|
+
description: N_('API token to Netbox')
|
54
|
+
setting 'netbox_orchestration_enabled',
|
55
|
+
type: :boolean,
|
56
|
+
default: false,
|
57
|
+
full_name: N_('Netbox Orchestration'),
|
58
|
+
description: N_('Enable Netbox Orchestration')
|
59
|
+
setting 'netbox_skip_site_update',
|
60
|
+
type: :boolean,
|
61
|
+
default: false,
|
62
|
+
full_name: N_('Skip Site Update'),
|
63
|
+
description: N_('Skip updating Site attribute for Devices')
|
64
|
+
end
|
59
65
|
end
|
60
|
-
end
|
61
66
|
|
62
|
-
|
67
|
+
logger :import, enabled: true
|
68
|
+
end
|
63
69
|
end
|
64
70
|
end
|
71
|
+
# rubocop:enable Metrics/BlockLength
|
65
72
|
|
66
73
|
config.to_prepare do
|
67
74
|
::Host::Managed.include(ForemanNetbox::HostExtensions)
|
@@ -2,31 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'rake/testtask'
|
4
4
|
|
5
|
-
namespace :foreman_netbox do
|
6
|
-
namespace :sync do
|
7
|
-
desc 'Example Task'
|
8
|
-
task full: :environment do
|
9
|
-
User.as_anonymous_admin do
|
10
|
-
Host::Managed.where(managed: true).each do |host|
|
11
|
-
unless host.netbox_facet.netbox_params_diff.empty?
|
12
|
-
puts "Nothing to push for #{host.name}"
|
13
|
-
next
|
14
|
-
end
|
15
|
-
|
16
|
-
puts "Pushing #{host.name} to Netbox"
|
17
|
-
result = host.push_to_netbox
|
18
|
-
|
19
|
-
if result.success?
|
20
|
-
puts "#{host.name} pushed"
|
21
|
-
else
|
22
|
-
puts "Failed to push #{host.name}: #{result.error}"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
5
|
# Tests
|
31
6
|
namespace :test do
|
32
7
|
desc 'Test ForemanNetbox'
|
@@ -39,27 +14,4 @@ namespace :test do
|
|
39
14
|
end
|
40
15
|
end
|
41
16
|
|
42
|
-
namespace :foreman_netbox do
|
43
|
-
task rubocop: :environment do
|
44
|
-
begin
|
45
|
-
require 'rubocop/rake_task'
|
46
|
-
RuboCop::RakeTask.new(:rubocop_foreman_netbox) do |task|
|
47
|
-
task.patterns = ["#{ForemanNetbox::Engine.root}/app/**/*.rb",
|
48
|
-
"#{ForemanNetbox::Engine.root}/lib/**/*.rb",
|
49
|
-
"#{ForemanNetbox::Engine.root}/test/**/*.rb"]
|
50
|
-
end
|
51
|
-
rescue StandardError
|
52
|
-
puts 'Rubocop not loaded.'
|
53
|
-
end
|
54
|
-
|
55
|
-
Rake::Task['rubocop_foreman_netbox'].invoke
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
17
|
Rake::Task[:test].enhance ['test:foreman_netbox']
|
60
|
-
|
61
|
-
load 'tasks/jenkins.rake'
|
62
|
-
|
63
|
-
if Rake::Task.task_defined?(:'jenkins:unit')
|
64
|
-
Rake::Task['jenkins:unit'].enhance ['test:foreman_netbox', 'foreman_netbox:rubocop']
|
65
|
-
end
|
@@ -27,7 +27,7 @@ class CreateDeviceTest < ActiveSupport::TestCase
|
|
27
27
|
let(:site) { OpenStruct.new(id: 1) }
|
28
28
|
let(:tenant) { OpenStruct.new(id: 1) }
|
29
29
|
let(:netbox_device_params) { host.netbox_facet.netbox_params.fetch(:device) }
|
30
|
-
let(:tags) { [ForemanNetbox::
|
30
|
+
let(:tags) { [ForemanNetbox::Api.client::Extras::Tag.new(id: 1, name: 'foreman', slug: 'foreman')] }
|
31
31
|
|
32
32
|
setup do
|
33
33
|
setup_default_netbox_settings
|
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'test_plugin_helper'
|
4
4
|
|
5
|
-
class
|
5
|
+
class SaveNetboxURLDeviceTest < ActiveSupport::TestCase
|
6
6
|
subject do
|
7
|
-
ForemanNetbox::SyncHost::SyncDevice::
|
7
|
+
ForemanNetbox::SyncHost::SyncDevice::SaveNetboxURL.call(host: host, device: device)
|
8
8
|
end
|
9
9
|
|
10
10
|
let(:device) { OpenStruct.new(id: 1) }
|
@@ -14,7 +14,7 @@ class UpdateDeviceTypeTest < ActiveSupport::TestCase
|
|
14
14
|
|
15
15
|
let(:host) { FactoryBot.build_stubbed(:host) }
|
16
16
|
let(:device_type) do
|
17
|
-
ForemanNetbox::
|
17
|
+
ForemanNetbox::Api.client::DCIM::DeviceType.new(id: 1).tap do |device|
|
18
18
|
device.instance_variable_set(
|
19
19
|
:@data,
|
20
20
|
{ 'id' => 1, 'tags' => device_type_tags }
|
@@ -12,7 +12,7 @@ class DeleteDeviceInterfacesTest < ActiveSupport::TestCase
|
|
12
12
|
end
|
13
13
|
|
14
14
|
let(:interface_id) { 1 }
|
15
|
-
let(:interfaces) { ForemanNetbox::
|
15
|
+
let(:interfaces) { ForemanNetbox::Api.client::DCIM::Interfaces.new }
|
16
16
|
let(:host) do
|
17
17
|
FactoryBot.build_stubbed(:host, interfaces: [])
|
18
18
|
end
|
@@ -9,8 +9,8 @@ class DeleteDeviceIpAddressesTest < ActiveSupport::TestCase
|
|
9
9
|
)
|
10
10
|
end
|
11
11
|
|
12
|
-
let(:interfaces) { ForemanNetbox::
|
13
|
-
let(:ip_addresses) { ForemanNetbox::
|
12
|
+
let(:interfaces) { ForemanNetbox::Api.client.dcim.interfaces.filter(device_id: 1) }
|
13
|
+
let(:ip_addresses) { ForemanNetbox::Api.client.ipam.ip_addresses.filter(device_id: 1) }
|
14
14
|
let(:host) do
|
15
15
|
FactoryBot.build_stubbed(
|
16
16
|
:host,
|
@@ -11,7 +11,7 @@ class UpdateDeviceIpAddressesTest < ActiveSupport::TestCase
|
|
11
11
|
)
|
12
12
|
end
|
13
13
|
|
14
|
-
let(:ip_addresses) { ForemanNetbox::
|
14
|
+
let(:ip_addresses) { ForemanNetbox::Api.client.ipam.ip_addresses.filter(device_id: 1) }
|
15
15
|
let(:tags_data) { default_tags.map { |t| { id: t.id, name: t.name, slug: t.slug } } }
|
16
16
|
let(:ip_addresses_data) do
|
17
17
|
[
|
@@ -12,8 +12,8 @@ class UpdateDeviceInterfacesTest < ActiveSupport::TestCase
|
|
12
12
|
)
|
13
13
|
end
|
14
14
|
|
15
|
-
let(:interfaces) { ForemanNetbox::
|
16
|
-
let(:tags) { [ForemanNetbox::
|
15
|
+
let(:interfaces) { ForemanNetbox::Api.client::DCIM::Interfaces.new }
|
16
|
+
let(:tags) { [ForemanNetbox::Api.client::Extras::Tag.new(id: 1, name: 'foreman', slug: 'foreman')] }
|
17
17
|
let(:old_mac) { 'FE:13:C6:44:29:22' }
|
18
18
|
let(:host) do
|
19
19
|
FactoryBot.build_stubbed(
|
@@ -10,9 +10,9 @@ class UpdateSiteTest < ActiveSupport::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
let(:host) { FactoryBot.build_stubbed(:host) }
|
13
|
-
# let(:tags) { [ForemanNetbox::
|
13
|
+
# let(:tags) { [ForemanNetbox::Api.client::Extras::Tag.new(id: 1, name: 'foreman', slug: 'foreman')] }
|
14
14
|
let(:site) do
|
15
|
-
ForemanNetbox::
|
15
|
+
ForemanNetbox::Api.client::DCIM::Site.new(id: 1).tap do |site|
|
16
16
|
site.instance_variable_set(
|
17
17
|
:@data,
|
18
18
|
{ 'id' => 1, 'tags' => site_tags }
|
@@ -18,7 +18,7 @@ class UpdateDeviceTest < ActiveSupport::TestCase
|
|
18
18
|
end
|
19
19
|
|
20
20
|
let(:device) do
|
21
|
-
ForemanNetbox::
|
21
|
+
ForemanNetbox::Api.client::DCIM::Device.new(id: 1).tap do |device|
|
22
22
|
device.instance_variable_set(
|
23
23
|
:@data,
|
24
24
|
{
|
@@ -68,7 +68,7 @@ class UpdateDeviceTest < ActiveSupport::TestCase
|
|
68
68
|
)
|
69
69
|
end
|
70
70
|
let(:serialnumber) { device_data[:serial] }
|
71
|
-
let(:ip_addresses) { ForemanNetbox::
|
71
|
+
let(:ip_addresses) { ForemanNetbox::Api.client.ipam.ip_addresses.filter(device_id: device.id) }
|
72
72
|
let(:host) do
|
73
73
|
FactoryBot.build_stubbed(
|
74
74
|
:host,
|
@@ -10,7 +10,7 @@ class UpdateTenantTest < ActiveSupport::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
let(:tenant) do
|
13
|
-
ForemanNetbox::
|
13
|
+
ForemanNetbox::Api.client::Tenancy::Tenant.new(id: 1).tap do |tenant|
|
14
14
|
tenant.instance_variable_set(
|
15
15
|
:@data,
|
16
16
|
{ 'id' => 1, 'tags' => tenant_tags }
|
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'test_plugin_helper'
|
4
4
|
|
5
|
-
class
|
5
|
+
class SaveNetboxURLVirtualMachineTest < ActiveSupport::TestCase
|
6
6
|
subject do
|
7
|
-
ForemanNetbox::SyncHost::SyncVirtualMachine::
|
7
|
+
ForemanNetbox::SyncHost::SyncVirtualMachine::SaveNetboxURL.call(host: host, virtual_machine: virtual_machine)
|
8
8
|
end
|
9
9
|
|
10
10
|
let(:virtual_machine) { OpenStruct.new(id: 1) }
|
data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/update_test.rb
CHANGED
@@ -11,7 +11,7 @@ class UpdateClusterTest < ActiveSupport::TestCase
|
|
11
11
|
|
12
12
|
let(:host) { FactoryBot.build_stubbed(:host).tap { |h| h.stubs(:compute?).returns(true) } }
|
13
13
|
let(:cluster) do
|
14
|
-
ForemanNetbox::
|
14
|
+
ForemanNetbox::Api.client::Virtualization::Cluster.new(id: 1).tap do |cluster|
|
15
15
|
cluster.instance_variable_set(
|
16
16
|
:@data,
|
17
17
|
{ 'id' => 1, 'tags' => cluster_tags }
|
data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/delete_test.rb
CHANGED
@@ -10,7 +10,7 @@ class DeleteVirtualMachineInterfacesTest < ActiveSupport::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
let(:interface_id) { 1 }
|
13
|
-
let(:interfaces) { ForemanNetbox::
|
13
|
+
let(:interfaces) { ForemanNetbox::Api.client::Virtualization::Interfaces.new }
|
14
14
|
let(:host) { FactoryBot.build_stubbed(:host, interfaces: []) }
|
15
15
|
|
16
16
|
setup do
|
@@ -9,8 +9,8 @@ class DeleteVirtualMachineIpAddressesTest < ActiveSupport::TestCase
|
|
9
9
|
)
|
10
10
|
end
|
11
11
|
|
12
|
-
let(:interfaces) { ForemanNetbox::
|
13
|
-
let(:ip_addresses) { ForemanNetbox::
|
12
|
+
let(:interfaces) { ForemanNetbox::Api.client.virtualization.interfaces.filter(virtual_machine_id: 1) }
|
13
|
+
let(:ip_addresses) { ForemanNetbox::Api.client.ipam.ip_addresses.filter(virtual_machine_id: 1) }
|
14
14
|
|
15
15
|
let(:host) do
|
16
16
|
FactoryBot.build_stubbed(
|
@@ -11,7 +11,7 @@ class UpdateVirtualMachineIpAddressesTest < ActiveSupport::TestCase
|
|
11
11
|
)
|
12
12
|
end
|
13
13
|
|
14
|
-
let(:ip_addresses) { ForemanNetbox::
|
14
|
+
let(:ip_addresses) { ForemanNetbox::Api.client.ipam.ip_addresses.filter(virtual_machine_id: 1) }
|
15
15
|
let(:ip_addresses_data) do
|
16
16
|
[
|
17
17
|
{
|
data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update_test.rb
CHANGED
@@ -12,7 +12,7 @@ class UpdateVirtualMachineInterfacesTest < ActiveSupport::TestCase
|
|
12
12
|
)
|
13
13
|
end
|
14
14
|
|
15
|
-
let(:interfaces) { ForemanNetbox::
|
15
|
+
let(:interfaces) { ForemanNetbox::Api.client::Virtualization::Interfaces.new }
|
16
16
|
let(:old_mac) { 'FE:13:C6:44:29:22' }
|
17
17
|
let(:host) do
|
18
18
|
FactoryBot.build_stubbed(
|
@@ -16,7 +16,7 @@ class UpdateVirtualMachineTest < ActiveSupport::TestCase
|
|
16
16
|
end
|
17
17
|
|
18
18
|
let(:virtual_machine) do
|
19
|
-
ForemanNetbox::
|
19
|
+
ForemanNetbox::Api.client::Virtualization::VirtualMachine.new(id: 1).tap do |virtual_machine|
|
20
20
|
virtual_machine.instance_variable_set(
|
21
21
|
:@data,
|
22
22
|
{
|
@@ -64,7 +64,7 @@ class UpdateVirtualMachineTest < ActiveSupport::TestCase
|
|
64
64
|
)
|
65
65
|
)
|
66
66
|
end
|
67
|
-
let(:ip_addresses) { ForemanNetbox::
|
67
|
+
let(:ip_addresses) { ForemanNetbox::Api.client.ipam.ip_addresses.filter(virtual_machine_id: virtual_machine.id) }
|
68
68
|
let(:host) do
|
69
69
|
FactoryBot.build_stubbed(
|
70
70
|
:host,
|
data/test/test_plugin_helper.rb
CHANGED
@@ -27,6 +27,6 @@ end
|
|
27
27
|
|
28
28
|
def default_tags
|
29
29
|
ForemanNetbox::SyncHost::SyncTags::Organizer::DEFAULT_TAGS.map.with_index(1) do |tag, id|
|
30
|
-
ForemanNetbox::
|
30
|
+
ForemanNetbox::Api.client::Extras::Tag.new(id: id, name: tag[:name], slug: tag[:slug])
|
31
31
|
end
|
32
32
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_plugin_helper'
|
4
|
+
|
5
|
+
module ForemanNetbox
|
6
|
+
class ApiTest < ActiveSupport::TestCase
|
7
|
+
describe '.netbox_api_url' do
|
8
|
+
subject { described_class.netbox_api_url }
|
9
|
+
|
10
|
+
let(:netbox1_url) { 'https://netbox1.com' }
|
11
|
+
let(:netbox1_api_url) { "#{netbox1_url}/api" }
|
12
|
+
let(:netbox2_api_url) { 'https://netbox1.com/api' }
|
13
|
+
|
14
|
+
context 'when only the netbox_url setting is set' do
|
15
|
+
setup do
|
16
|
+
Setting[:netbox_url] = netbox1_url
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'returns the URL to the Netbox API' do
|
20
|
+
assert_equal netbox1_api_url, subject
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when only the netbox_api_url setting is set' do
|
25
|
+
setup do
|
26
|
+
Setting[:netbox_api_url] = netbox2_api_url
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns the URL to the Netbox API' do
|
30
|
+
assert_equal netbox2_api_url, subject
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when both netbox_url and netbox_api_url setting are set' do
|
35
|
+
setup do
|
36
|
+
Setting[:netbox_url] = netbox1_api_url
|
37
|
+
Setting[:netbox_api_url] = netbox2_api_url
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns the URL to the Netbox API from netbox_api_url setting' do
|
41
|
+
assert_equal netbox2_api_url, subject
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when neither setting netbox_url nor netbox_api_url is set' do
|
46
|
+
it 'raises exception' do
|
47
|
+
assert_raises(Foreman::Exception) { subject }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|