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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -6
  3. data/app/interactors/foreman_netbox/delete_host/delete_device.rb +1 -1
  4. data/app/interactors/foreman_netbox/delete_host/delete_virtual_machine.rb +1 -1
  5. data/app/interactors/foreman_netbox/sync_host/sync_device/create.rb +1 -1
  6. data/app/interactors/foreman_netbox/sync_host/sync_device/find.rb +3 -3
  7. data/app/interactors/foreman_netbox/sync_host/sync_device/organizer.rb +1 -1
  8. data/app/interactors/foreman_netbox/sync_host/sync_device/save_netbox_url.rb +1 -1
  9. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/create.rb +1 -1
  10. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/find.rb +1 -1
  11. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/create.rb +1 -1
  12. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/find.rb +1 -1
  13. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/create.rb +1 -1
  14. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find.rb +2 -2
  15. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/create.rb +1 -1
  16. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find.rb +1 -1
  17. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/create.rb +2 -2
  18. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find.rb +1 -1
  19. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update.rb +1 -3
  20. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_site/create.rb +1 -1
  21. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_site/find.rb +1 -1
  22. data/app/interactors/foreman_netbox/sync_host/sync_tags/create.rb +1 -1
  23. data/app/interactors/foreman_netbox/sync_host/sync_tags/find.rb +1 -1
  24. data/app/interactors/foreman_netbox/sync_host/sync_tenant/create.rb +1 -1
  25. data/app/interactors/foreman_netbox/sync_host/sync_tenant/find.rb +1 -1
  26. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/create.rb +1 -1
  27. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/find.rb +2 -2
  28. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/organizer.rb +1 -1
  29. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/save_netbox_url.rb +1 -1
  30. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/create.rb +1 -1
  31. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/find.rb +1 -1
  32. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/create.rb +1 -1
  33. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/find.rb +1 -1
  34. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/create.rb +8 -8
  35. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find.rb +1 -1
  36. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/create.rb +2 -2
  37. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete.rb +2 -4
  38. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find.rb +1 -1
  39. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update.rb +1 -3
  40. data/app/lib/foreman_netbox/api.rb +11 -2
  41. data/app/services/foreman_netbox/netbox_parameters.rb +2 -2
  42. data/app/services/foreman_netbox/netbox_parameters_comparator.rb +2 -2
  43. data/db/migrate/20230303095650_fix_netbox_settings_category_to_dsl.rb +0 -2
  44. data/lib/foreman_netbox/engine.rb +47 -40
  45. data/lib/foreman_netbox/version.rb +1 -1
  46. data/lib/tasks/foreman_netbox_tasks.rake +0 -48
  47. data/test/fixtures/netbox_device_raw_data.json +1 -1
  48. data/test/integration/foreman_netbox/sync_k8s_physical_host_test.rb +1 -1
  49. data/test/integration/foreman_netbox/sync_rhel_physical_host_test.rb +1 -1
  50. data/test/integration/foreman_netbox/sync_rhel_virtual_host_test.rb +1 -1
  51. data/test/interactors/foreman_netbox/sync_host/sync_device/create_test.rb +1 -1
  52. data/test/interactors/foreman_netbox/sync_host/sync_device/save_netbox_url_test.rb +2 -2
  53. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/update_test.rb +1 -1
  54. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/delete_test.rb +1 -1
  55. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete_test.rb +2 -2
  56. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/update_test.rb +1 -1
  57. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update_test.rb +2 -2
  58. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/update_test.rb +2 -2
  59. data/test/interactors/foreman_netbox/sync_host/sync_device/update_test.rb +2 -2
  60. data/test/interactors/foreman_netbox/sync_host/sync_tenant/update_test.rb +1 -1
  61. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/save_netbox_url_test.rb +2 -2
  62. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/update_test.rb +1 -1
  63. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/delete_test.rb +1 -1
  64. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete_test.rb +2 -2
  65. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/update_test.rb +1 -1
  66. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update_test.rb +1 -1
  67. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/update_test.rb +2 -2
  68. data/test/test_plugin_helper.rb +1 -1
  69. data/test/unit/foreman_netbox/api_test.rb +52 -0
  70. 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
- initializer 'foreman_netbox.register_plugin', before: :finisher_hook do |_app|
21
- Foreman::Plugin.register :foreman_netbox do
22
- requires_foreman '>= 3.1'
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
- # Netbox Facet
25
- register_facet(ForemanNetbox::NetboxFacet, :netbox_facet) do
26
- set_dependent_action :destroy
27
- end
24
+ # Netbox Facet
25
+ register_facet(ForemanNetbox::NetboxFacet, :netbox_facet) do
26
+ set_dependent_action :destroy
27
+ end
28
28
 
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
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
- settings do
38
- category(:netbox, N_('Netbox')) do
39
- setting 'netbox_url',
40
- type: :string,
41
- default: '-',
42
- full_name: N_('Netbox URL'),
43
- description: N_('URL where Netbox is reachable')
44
- setting 'netbox_api_token',
45
- type: :string,
46
- default: '-',
47
- full_name: N_('Netbox API token'),
48
- description: N_('API token to Netbox')
49
- setting 'netbox_orchestration_enabled',
50
- type: :boolean,
51
- default: false,
52
- full_name: N_('Netbox Orchestration'),
53
- description: N_('Enable Netbox Orchestration')
54
- setting 'netbox_skip_site_update',
55
- type: :boolean,
56
- default: false,
57
- full_name: N_('Skip Site Update'),
58
- description: N_('Skip updating Site attribute for Devices')
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
- logger :import, enabled: true
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForemanNetbox
4
- VERSION = '1.2.0'
4
+ VERSION = '2.0.0'
5
5
  end
@@ -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
@@ -327,4 +327,4 @@
327
327
  "created": "2020-07-13",
328
328
  "last_updated": "2020-07-14T12:02:37.622231Z"
329
329
  }
330
- }
330
+ }
@@ -42,7 +42,7 @@ class SyncK8sPhysicalHostTest < ActiveSupport::TestCase
42
42
  end
43
43
  end
44
44
 
45
- test 'sync host' do
45
+ test 'sync k8s host' do
46
46
  ForemanNetbox::NetboxFacet.any_instance.expects(:update).twice.returns(true)
47
47
 
48
48
  assert subject.success?
@@ -42,7 +42,7 @@ class SyncRhelPhysicalHostTest < ActiveSupport::TestCase
42
42
  end
43
43
  end
44
44
 
45
- test 'sync host' do
45
+ test 'sync physical host' do
46
46
  ForemanNetbox::NetboxFacet.any_instance.expects(:update).twice.returns(true)
47
47
 
48
48
  assert subject.success?
@@ -54,7 +54,7 @@ class SyncRhelVirtualHostTest < ActiveSupport::TestCase
54
54
  end
55
55
  end
56
56
 
57
- test 'sync host' do
57
+ test 'sync virtual host' do
58
58
  ForemanNetbox::NetboxFacet.any_instance.expects(:update).twice.returns(true)
59
59
 
60
60
  assert subject.success?
@@ -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::API.client::Extras::Tag.new(id: 1, name: 'foreman', slug: 'foreman')] }
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 SaveNetboxUrlDeviceTest < ActiveSupport::TestCase
5
+ class SaveNetboxURLDeviceTest < ActiveSupport::TestCase
6
6
  subject do
7
- ForemanNetbox::SyncHost::SyncDevice::SaveNetboxUrl.call(host: host, device: device)
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::API.client::DCIM::DeviceType.new(id: 1).tap do |device|
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::API.client::DCIM::Interfaces.new }
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::API.client.dcim.interfaces.filter(device_id: 1) }
13
- let(:ip_addresses) { ForemanNetbox::API.client.ipam.ip_addresses.filter(device_id: 1) }
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::API.client.ipam.ip_addresses.filter(device_id: 1) }
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::API.client::DCIM::Interfaces.new }
16
- let(:tags) { [ForemanNetbox::API.client::Extras::Tag.new(id: 1, name: 'foreman', slug: 'foreman')] }
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::API.client::Extras::Tag.new(id: 1, name: 'foreman', slug: 'foreman')] }
13
+ # let(:tags) { [ForemanNetbox::Api.client::Extras::Tag.new(id: 1, name: 'foreman', slug: 'foreman')] }
14
14
  let(:site) do
15
- ForemanNetbox::API.client::DCIM::Site.new(id: 1).tap do |site|
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::API.client::DCIM::Device.new(id: 1).tap do |device|
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::API.client.ipam.ip_addresses.filter(device_id: device.id) }
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::API.client::Tenancy::Tenant.new(id: 1).tap do |tenant|
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 SaveNetboxUrlVirtualMachineTest < ActiveSupport::TestCase
5
+ class SaveNetboxURLVirtualMachineTest < ActiveSupport::TestCase
6
6
  subject do
7
- ForemanNetbox::SyncHost::SyncVirtualMachine::SaveNetboxUrl.call(host: host, virtual_machine: virtual_machine)
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) }
@@ -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::API.client::Virtualization::Cluster.new(id: 1).tap do |cluster|
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 }
@@ -10,7 +10,7 @@ class DeleteVirtualMachineInterfacesTest < ActiveSupport::TestCase
10
10
  end
11
11
 
12
12
  let(:interface_id) { 1 }
13
- let(:interfaces) { ForemanNetbox::API.client::Virtualization::Interfaces.new }
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::API.client.virtualization.interfaces.filter(virtual_machine_id: 1) }
13
- let(:ip_addresses) { ForemanNetbox::API.client.ipam.ip_addresses.filter(virtual_machine_id: 1) }
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::API.client.ipam.ip_addresses.filter(virtual_machine_id: 1) }
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
  {
@@ -12,7 +12,7 @@ class UpdateVirtualMachineInterfacesTest < ActiveSupport::TestCase
12
12
  )
13
13
  end
14
14
 
15
- let(:interfaces) { ForemanNetbox::API.client::Virtualization::Interfaces.new }
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::API.client::Virtualization::VirtualMachine.new(id: 1).tap do |virtual_machine|
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::API.client.ipam.ip_addresses.filter(virtual_machine_id: virtual_machine.id) }
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,
@@ -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::API.client::Extras::Tag.new(id: id, name: tag[:name], slug: tag[:slug])
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