foreman_netbox 1.1.1 → 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 (112) 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/delete_host/organizer.rb +1 -1
  6. data/app/interactors/foreman_netbox/sync_host/organizer.rb +1 -1
  7. data/app/interactors/foreman_netbox/sync_host/sync_device/create.rb +1 -1
  8. data/app/interactors/foreman_netbox/sync_host/sync_device/find.rb +3 -5
  9. data/app/interactors/foreman_netbox/sync_host/sync_device/organizer.rb +10 -10
  10. data/app/interactors/foreman_netbox/sync_host/sync_device/save_netbox_url.rb +1 -1
  11. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/create.rb +1 -1
  12. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/find.rb +1 -1
  13. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/organizer.rb +1 -1
  14. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/create.rb +1 -1
  15. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/find.rb +1 -1
  16. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/organizer.rb +3 -3
  17. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/create.rb +1 -1
  18. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find.rb +4 -5
  19. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/organizer.rb +1 -1
  20. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/create.rb +1 -1
  21. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find.rb +2 -2
  22. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/organizer.rb +4 -4
  23. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/create.rb +2 -2
  24. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete.rb +3 -1
  25. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find.rb +2 -2
  26. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/organizer.rb +3 -3
  27. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_site/create.rb +1 -1
  28. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_site/find.rb +1 -1
  29. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_site/organizer.rb +2 -2
  30. data/app/interactors/foreman_netbox/sync_host/sync_tags/create.rb +1 -1
  31. data/app/interactors/foreman_netbox/sync_host/sync_tags/find.rb +1 -1
  32. data/app/interactors/foreman_netbox/sync_host/sync_tags/organizer.rb +2 -2
  33. data/app/interactors/foreman_netbox/sync_host/sync_tenant/create.rb +1 -1
  34. data/app/interactors/foreman_netbox/sync_host/sync_tenant/find.rb +1 -1
  35. data/app/interactors/foreman_netbox/sync_host/sync_tenant/organizer.rb +2 -2
  36. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/create.rb +1 -1
  37. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/find.rb +2 -4
  38. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/organizer.rb +8 -8
  39. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/save_netbox_url.rb +1 -1
  40. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/create.rb +1 -1
  41. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/find.rb +1 -1
  42. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/organizer.rb +3 -3
  43. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/create.rb +1 -1
  44. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/find.rb +1 -1
  45. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/organizer.rb +1 -1
  46. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/create.rb +8 -8
  47. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find.rb +2 -2
  48. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/organizer.rb +4 -4
  49. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/create.rb +2 -2
  50. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete.rb +3 -3
  51. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find.rb +2 -2
  52. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/organizer.rb +3 -3
  53. data/app/lib/foreman_netbox/api.rb +11 -2
  54. data/app/models/orchestration/netbox.rb +2 -4
  55. data/app/services/foreman_netbox/cached_netbox_parameters.rb +11 -11
  56. data/app/services/foreman_netbox/netbox_parameters.rb +29 -29
  57. data/app/services/foreman_netbox/netbox_parameters_comparator.rb +14 -8
  58. data/db/migrate/20230303095650_fix_netbox_settings_category_to_dsl.rb +0 -2
  59. data/lib/foreman_netbox/engine.rb +47 -40
  60. data/lib/foreman_netbox/version.rb +1 -1
  61. data/lib/tasks/foreman_netbox_tasks.rake +0 -50
  62. data/test/fixtures/netbox_device_raw_data.json +1 -1
  63. data/test/integration/foreman_netbox/sync_k8s_physical_host_test.rb +8 -8
  64. data/test/integration/foreman_netbox/sync_rhel_physical_host_test.rb +8 -8
  65. data/test/integration/foreman_netbox/sync_rhel_virtual_host_test.rb +8 -8
  66. data/test/interactors/foreman_netbox/sync_host/organizer_test.rb +9 -9
  67. data/test/interactors/foreman_netbox/sync_host/sync_device/create_test.rb +2 -2
  68. data/test/interactors/foreman_netbox/sync_host/sync_device/save_netbox_url_test.rb +2 -2
  69. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/create_test.rb +1 -1
  70. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/find_test.rb +4 -4
  71. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/create_test.rb +1 -1
  72. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/find_test.rb +4 -4
  73. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/create_test.rb +1 -1
  74. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find_test.rb +6 -6
  75. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/update_test.rb +2 -2
  76. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/create_test.rb +3 -3
  77. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/delete_test.rb +2 -2
  78. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find_test.rb +4 -4
  79. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/create_test.rb +5 -5
  80. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete_test.rb +7 -7
  81. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find_test.rb +3 -3
  82. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/update_test.rb +5 -5
  83. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update_test.rb +10 -10
  84. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/create_test.rb +1 -1
  85. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/find_test.rb +3 -3
  86. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/update_test.rb +3 -3
  87. data/test/interactors/foreman_netbox/sync_host/sync_device/update_test.rb +11 -11
  88. data/test/interactors/foreman_netbox/sync_host/sync_tenant/create_test.rb +1 -1
  89. data/test/interactors/foreman_netbox/sync_host/sync_tenant/find_test.rb +3 -3
  90. data/test/interactors/foreman_netbox/sync_host/sync_tenant/update_test.rb +2 -2
  91. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/create_test.rb +2 -2
  92. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/save_netbox_url_test.rb +2 -2
  93. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/create_test.rb +1 -1
  94. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/find_test.rb +2 -2
  95. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/find_test.rb +4 -4
  96. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/update_test.rb +2 -2
  97. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/create_test.rb +3 -3
  98. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/delete_test.rb +2 -2
  99. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find_test.rb +4 -4
  100. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/create_test.rb +5 -5
  101. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete_test.rb +7 -7
  102. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find_test.rb +3 -3
  103. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/update_test.rb +7 -7
  104. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update_test.rb +9 -9
  105. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/update_test.rb +10 -10
  106. data/test/models/foreman_netbox/netbox_facet_test.rb +1 -1
  107. data/test/models/foreman_netbox/nics/base_test.rb +1 -1
  108. data/test/services/foreman_netbox/netbox_attributes_test.rb +16 -16
  109. data/test/services/foreman_netbox/netbox_parameters_comparator_test.rb +31 -31
  110. data/test/test_plugin_helper.rb +1 -1
  111. data/test/unit/foreman_netbox/api_test.rb +52 -0
  112. metadata +88 -165
@@ -327,4 +327,4 @@
327
327
  "created": "2020-07-13",
328
328
  "last_updated": "2020-07-14T12:02:37.622231Z"
329
329
  }
330
- }
330
+ }
@@ -32,7 +32,7 @@ class SyncK8sPhysicalHostTest < ActiveSupport::TestCase
32
32
  mac: '45:E9:6A:83:02:20',
33
33
  ip6: '1600:0:2d0:202::17',
34
34
  subnet6: FactoryBot.build_stubbed(:subnet_ipv6, organizations: [], locations: [])
35
- )
35
+ ),
36
36
  ]
37
37
  ).tap do |host|
38
38
  host.stubs(:ip).returns(host.interfaces.find(&:ip).ip)
@@ -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?
@@ -71,15 +71,15 @@ class SyncK8sPhysicalHostTest < ActiveSupport::TestCase
71
71
  end
72
72
 
73
73
  expected_tag_ids = subject.tags.pluck('id')
74
- assert (expected_tag_ids - subject.device.tags.pluck('id')).empty?
75
- assert (expected_tag_ids - subject.device_type.tags.pluck('id')).empty?
76
- assert (expected_tag_ids - subject.site.tags.pluck('id')).empty?
77
- assert (expected_tag_ids - subject.tenant.tags.pluck('id')).empty?
74
+ assert_empty(expected_tag_ids - subject.device.tags.pluck('id'))
75
+ assert_empty(expected_tag_ids - subject.device_type.tags.pluck('id'))
76
+ assert_empty(expected_tag_ids - subject.site.tags.pluck('id'))
77
+ assert_empty(expected_tag_ids - subject.tenant.tags.pluck('id'))
78
78
  subject.interfaces.reload.each do |interface|
79
- assert (expected_tag_ids - interface.tags.pluck('id')).empty?
79
+ assert_empty(expected_tag_ids - interface.tags.pluck('id'))
80
80
  end
81
81
  subject.ip_addresses.reload.each do |interface|
82
- assert (expected_tag_ids - interface.tags.pluck('id')).empty?
82
+ assert_empty(expected_tag_ids - interface.tags.pluck('id'))
83
83
  end
84
84
  end
85
85
  end
@@ -32,7 +32,7 @@ class SyncRhelPhysicalHostTest < ActiveSupport::TestCase
32
32
  mac: '45:E9:6A:83:02:21',
33
33
  ip6: '1600:0:2d0:202::18',
34
34
  subnet6: FactoryBot.build_stubbed(:subnet_ipv6, organizations: [], locations: [])
35
- )
35
+ ),
36
36
  ]
37
37
  ).tap do |host|
38
38
  host.stubs(:ip).returns(host.interfaces.find(&:ip).ip)
@@ -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?
@@ -71,15 +71,15 @@ class SyncRhelPhysicalHostTest < ActiveSupport::TestCase
71
71
  end
72
72
 
73
73
  expected_tag_ids = subject.tags.pluck('id')
74
- assert (expected_tag_ids - subject.device.tags.pluck('id')).empty?
75
- assert (expected_tag_ids - subject.device_type.tags.pluck('id')).empty?
76
- assert (expected_tag_ids - subject.site.tags.pluck('id')).empty?
77
- assert (expected_tag_ids - subject.tenant.tags.pluck('id')).empty?
74
+ assert_empty(expected_tag_ids - subject.device.tags.pluck('id'))
75
+ assert_empty(expected_tag_ids - subject.device_type.tags.pluck('id'))
76
+ assert_empty(expected_tag_ids - subject.site.tags.pluck('id'))
77
+ assert_empty(expected_tag_ids - subject.tenant.tags.pluck('id'))
78
78
  subject.interfaces.reload.each do |interface|
79
- assert (expected_tag_ids - interface.tags.pluck('id')).empty?
79
+ assert_empty(expected_tag_ids - interface.tags.pluck('id'))
80
80
  end
81
81
  subject.ip_addresses.reload.each do |interface|
82
- assert (expected_tag_ids - interface.tags.pluck('id')).empty?
82
+ assert_empty(expected_tag_ids - interface.tags.pluck('id'))
83
83
  end
84
84
  end
85
85
  end
@@ -31,7 +31,7 @@ class SyncRhelVirtualHostTest < ActiveSupport::TestCase
31
31
  mac: '45:E9:6A:83:02:22',
32
32
  ip6: '1600:0:2d0:202::19',
33
33
  subnet6: FactoryBot.build_stubbed(:subnet_ipv6, organizations: [], locations: [])
34
- )
34
+ ),
35
35
  ]
36
36
  ).tap do |host|
37
37
  host.stubs(:ip).returns(host.interfaces.find(&:ip).ip)
@@ -46,7 +46,7 @@ class SyncRhelVirtualHostTest < ActiveSupport::TestCase
46
46
  cpus: 1,
47
47
  memory_mb: 1024,
48
48
  volumes: [
49
- OpenStruct.new(size_gb: 120)
49
+ OpenStruct.new(size_gb: 120),
50
50
  ]
51
51
  )
52
52
  )
@@ -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?
@@ -84,14 +84,14 @@ class SyncRhelVirtualHostTest < ActiveSupport::TestCase
84
84
  end
85
85
 
86
86
  expected_tag_ids = subject.tags.pluck('id')
87
- assert (expected_tag_ids - subject.virtual_machine.tags.pluck('id')).empty?
88
- assert (expected_tag_ids - subject.tenant.tags.pluck('id')).empty?
89
- assert (expected_tag_ids - subject.cluster.tags.pluck('id')).empty?
87
+ assert_empty(expected_tag_ids - subject.virtual_machine.tags.pluck('id'))
88
+ assert_empty(expected_tag_ids - subject.tenant.tags.pluck('id'))
89
+ assert_empty(expected_tag_ids - subject.cluster.tags.pluck('id'))
90
90
  subject.interfaces.reload.each do |interface|
91
- assert (expected_tag_ids - interface.tags.pluck('id')).empty?
91
+ assert_empty(expected_tag_ids - interface.tags.pluck('id'))
92
92
  end
93
93
  subject.ip_addresses.reload.each do |interface|
94
- assert (expected_tag_ids - interface.tags.pluck('id')).empty?
94
+ assert_empty(expected_tag_ids - interface.tags.pluck('id'))
95
95
  end
96
96
  end
97
97
  end
@@ -20,7 +20,7 @@ class SyncHostOrganizerTest < ActiveSupport::TestCase
20
20
  # rubocop:disable Layout/FirstArrayElementIndentation
21
21
  default_tags.each do |tag|
22
22
  stub_get_netbox_request("extras/tags.json?limit=50&slug=#{tag.slug}", results: [
23
- { id: tag.id, name: tag.name, slug: tag.slug }
23
+ { id: tag.id, name: tag.name, slug: tag.slug },
24
24
  ])
25
25
  stub_request(:get, "#{Setting[:netbox_url]}/api/extras/tags/#{tag.id}.json")
26
26
  .to_return(
@@ -28,27 +28,27 @@ class SyncHostOrganizerTest < ActiveSupport::TestCase
28
28
  body: {
29
29
  id: tag.id,
30
30
  name: tag.name,
31
- slug: tag.slug
31
+ slug: tag.slug,
32
32
  }.to_json
33
33
  )
34
34
  end
35
35
  stub_get_netbox_request('tenancy/tenants.json?limit=50&slug=admin-user', results: [
36
- { id: 1, name: host.owner.name, slug: host.owner.name.parameterize, tags: tags }
36
+ { id: 1, name: host.owner.name, slug: host.owner.name.parameterize, tags: tags },
37
37
  ])
38
38
  stub_get_netbox_request('dcim/sites.json?limit=50&slug=location-1', results: [
39
- { id: 1, name: host.location.netbox_site_name, slug: host.location.netbox_site_slug, tags: tags }
39
+ { id: 1, name: host.location.netbox_site_name, slug: host.location.netbox_site_slug, tags: tags },
40
40
  ])
41
41
  stub_get_netbox_request('dcim/device-roles.json?limit=50&slug=server', results: [
42
- { id: 1, name: 'Device Role', slug: 'server' }
42
+ { id: 1, name: 'Device Role', slug: 'server' },
43
43
  ])
44
44
  stub_get_netbox_request('dcim/manufacturers.json?limit=50&slug=unknown', results: [
45
- { id: 1, name: 'Unknown', slug: 'unknown' }
45
+ { id: 1, name: 'Unknown', slug: 'unknown' },
46
46
  ])
47
47
  stub_get_netbox_request('dcim/device-types.json?limit=50&slug=unknown', results: [
48
- { id: 1, name: 'Unknown', slug: 'unknown', tags: tags }
48
+ { id: 1, name: 'Unknown', slug: 'unknown', tags: tags },
49
49
  ])
50
50
  stub_get_netbox_request("dcim/devices.json?limit=50&serial=#{host.facts[:serialnumber]}", results: [
51
- { id: 1, name: host.name, serial: host.facts[:serialnumber], tags: tags }
51
+ { id: 1, name: host.name, serial: host.facts[:serialnumber], tags: tags },
52
52
  ])
53
53
  stub_get_netbox_request('dcim/interfaces.json?device_id=1&limit=50', results: [])
54
54
  stub_get_netbox_request('ipam/ip-addresses.json?device_id=1&limit=50', results: [])
@@ -87,7 +87,7 @@ class SyncHostOrganizerTest < ActiveSupport::TestCase
87
87
  status: 200, headers: { 'Content-Type': 'application/json' },
88
88
  body: {
89
89
  count: 1,
90
- results: results
90
+ results: results,
91
91
  }.to_json
92
92
  )
93
93
  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::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
@@ -45,7 +45,7 @@ class CreateDeviceTest < ActiveSupport::TestCase
45
45
  device_role: device_role.id,
46
46
  site: site.id,
47
47
  tenant: tenant.id,
48
- tags: tags.map(&:id)
48
+ tags: tags.map(&:id),
49
49
  }.to_json
50
50
  ).to_return(
51
51
  status: 201, headers: { 'Content-Type': 'application/json' },
@@ -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) }
@@ -23,7 +23,7 @@ class CreateDeviceRoleTest < ActiveSupport::TestCase
23
23
  body: {
24
24
  name: device_role_params[:name],
25
25
  color: device_role_params[:color],
26
- slug: device_role_params[:slug]
26
+ slug: device_role_params[:slug],
27
27
  }.to_json
28
28
  ).to_return(
29
29
  status: 201, headers: { 'Content-Type': 'application/json' },
@@ -28,9 +28,9 @@ class FindDeviceRoleTest < ActiveSupport::TestCase
28
28
  {
29
29
  id: 1,
30
30
  name: device_role_params[:name],
31
- slug: device_role_params[:slug]
32
- }
33
- ]
31
+ slug: device_role_params[:slug],
32
+ },
33
+ ],
34
34
  }.to_json
35
35
  )
36
36
 
@@ -47,7 +47,7 @@ class FindDeviceRoleTest < ActiveSupport::TestCase
47
47
  status: 200, headers: { 'Content-Type': 'application/json' },
48
48
  body: {
49
49
  count: 0,
50
- results: []
50
+ results: [],
51
51
  }.to_json
52
52
  )
53
53
 
@@ -34,7 +34,7 @@ class CreateDeviceTypeTest < ActiveSupport::TestCase
34
34
  model: host.netbox_facet.netbox_params.dig(:device_type, :model),
35
35
  slug: host.netbox_facet.netbox_params.dig(:device_type, :slug),
36
36
  manufacturer: manufacturer.id,
37
- tags: default_tags.map(&:id)
37
+ tags: default_tags.map(&:id),
38
38
  }.to_json
39
39
  ).to_return(
40
40
  status: 201, headers: { 'Content-Type': 'application/json' },
@@ -33,9 +33,9 @@ class FindDeviceTypeTest < ActiveSupport::TestCase
33
33
  {
34
34
  id: 1,
35
35
  name: host.facts.symbolize_keys.fetch(:'dmi::product::name'),
36
- slug: slug
37
- }
38
- ]
36
+ slug: slug,
37
+ },
38
+ ],
39
39
  }.to_json
40
40
  )
41
41
 
@@ -52,7 +52,7 @@ class FindDeviceTypeTest < ActiveSupport::TestCase
52
52
  status: 200, headers: { 'Content-Type': 'application/json' },
53
53
  body: {
54
54
  count: 0,
55
- results: []
55
+ results: [],
56
56
  }.to_json
57
57
  )
58
58
 
@@ -26,7 +26,7 @@ class CreateManufacturerTest < ActiveSupport::TestCase
26
26
  stub_post = stub_request(:post, "#{Setting[:netbox_url]}/api/dcim/manufacturers/").with(
27
27
  body: {
28
28
  name: host.netbox_facet.netbox_params.dig(:manufacturer, :name),
29
- slug: host.netbox_facet.netbox_params.dig(:manufacturer, :slug)
29
+ slug: host.netbox_facet.netbox_params.dig(:manufacturer, :slug),
30
30
  }.to_json
31
31
  ).to_return(
32
32
  status: 201, headers: { 'Content-Type': 'application/json' },
@@ -14,7 +14,7 @@ class FindManufacturerTest < ActiveSupport::TestCase
14
14
  host.stubs(:facts).returns(
15
15
  {
16
16
  'dmi::manufacturer' => 'Manufacturer',
17
- 'dmi::product::name' => 'device type 2'
17
+ 'dmi::product::name' => 'device type 2',
18
18
  }
19
19
  )
20
20
  end
@@ -34,7 +34,7 @@ class FindManufacturerTest < ActiveSupport::TestCase
34
34
  status: 200, headers: { 'Content-Type': 'application/json' },
35
35
  body: {
36
36
  count: 1,
37
- results: [netbox_params.fetch(:manufacturer).merge(id: 1)]
37
+ results: [netbox_params.fetch(:manufacturer).merge(id: 1)],
38
38
  }.to_json
39
39
  )
40
40
  stub_get_with_name = stub_request(:get, "#{Setting[:netbox_url]}/api/dcim/manufacturers.json").with(
@@ -55,7 +55,7 @@ class FindManufacturerTest < ActiveSupport::TestCase
55
55
  status: 200, headers: { 'Content-Type': 'application/json' },
56
56
  body: {
57
57
  count: 0,
58
- results: []
58
+ results: [],
59
59
  }.to_json
60
60
  )
61
61
  stub_get_with_name = stub_request(:get, "#{Setting[:netbox_url]}/api/dcim/manufacturers.json").with(
@@ -64,7 +64,7 @@ class FindManufacturerTest < ActiveSupport::TestCase
64
64
  status: 200, headers: { 'Content-Type': 'application/json' },
65
65
  body: {
66
66
  count: 1,
67
- results: [netbox_params.fetch(:manufacturer).merge(id: 1)]
67
+ results: [netbox_params.fetch(:manufacturer).merge(id: 1)],
68
68
  }.to_json
69
69
  )
70
70
 
@@ -83,7 +83,7 @@ class FindManufacturerTest < ActiveSupport::TestCase
83
83
  status: 200, headers: { 'Content-Type': 'application/json' },
84
84
  body: {
85
85
  count: 0,
86
- results: []
86
+ results: [],
87
87
  }.to_json
88
88
  )
89
89
 
@@ -93,7 +93,7 @@ class FindManufacturerTest < ActiveSupport::TestCase
93
93
  status: 200, headers: { 'Content-Type': 'application/json' },
94
94
  body: {
95
95
  count: 0,
96
- results: []
96
+ results: [],
97
97
  }.to_json
98
98
  )
99
99
 
@@ -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 }
@@ -32,7 +32,7 @@ class UpdateDeviceTypeTest < ActiveSupport::TestCase
32
32
  it 'updates device type' do
33
33
  stub_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/dcim/device-types/1.json").with(
34
34
  body: {
35
- tags: default_tags.map(&:id)
35
+ tags: default_tags.map(&:id),
36
36
  }.to_json
37
37
  ).to_return(
38
38
  status: 200, headers: { 'Content-Type': 'application/json' },
@@ -21,7 +21,7 @@ class CreateDeviceInterfacesTest < ActiveSupport::TestCase
21
21
  interfaces: [
22
22
  FactoryBot.build_stubbed(:nic_base, mac: 'FE:13:C6:44:29:24', ip: '10.0.0.1', ip6: '1500:0:2d0:201::1'),
23
23
  FactoryBot.build_stubbed(:nic_base, mac: 'FE:13:C6:44:29:22', ip: '10.0.0.2', ip6: '1500:0:2d0:201::2'),
24
- FactoryBot.build_stubbed(:nic_base, identifier: nil, mac: nil)
24
+ FactoryBot.build_stubbed(:nic_base, identifier: nil, mac: nil),
25
25
  ]
26
26
  )
27
27
  end
@@ -39,13 +39,13 @@ class CreateDeviceInterfacesTest < ActiveSupport::TestCase
39
39
  mac_address: host.interfaces.first.mac.upcase,
40
40
  type: ForemanNetbox::NetboxParameters::DEFAULT_INTERFACE_TYPE,
41
41
  device: device.id,
42
- tags: default_tags.map(&:id)
42
+ tags: default_tags.map(&:id),
43
43
  }.to_json
44
44
  ).to_return(
45
45
  status: 201, headers: { 'Content-Type': 'application/json' },
46
46
  body: {
47
47
  id: 1,
48
- name: host.interfaces.first.netbox_name
48
+ name: host.interfaces.first.netbox_name,
49
49
  }.to_json
50
50
  )
51
51
 
@@ -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
@@ -25,7 +25,7 @@ class DeleteDeviceInterfacesTest < ActiveSupport::TestCase
25
25
  status: 200, headers: { 'Content-Type': 'application/json' },
26
26
  body: {
27
27
  count: 1,
28
- results: [{ id: interface_id, name: 'eth0' }]
28
+ results: [{ id: interface_id, name: 'eth0' }],
29
29
  }.to_json
30
30
  )
31
31
  end
@@ -24,8 +24,8 @@ class FindDeviceInterfacesTest < ActiveSupport::TestCase
24
24
  body: {
25
25
  count: 1,
26
26
  results: [
27
- { id: 1 }
28
- ]
27
+ { id: 1 },
28
+ ],
29
29
  }.to_json
30
30
  )
31
31
 
@@ -42,11 +42,11 @@ class FindDeviceInterfacesTest < ActiveSupport::TestCase
42
42
  status: 200, headers: { 'Content-Type': 'application/json' },
43
43
  body: {
44
44
  count: 0,
45
- results: []
45
+ results: [],
46
46
  }.to_json
47
47
  )
48
48
 
49
- assert_equal [], subject.interfaces.map(&:id)
49
+ assert_empty subject.interfaces.map(&:id)
50
50
  assert_requested(stub_get)
51
51
  end
52
52
  end
@@ -26,7 +26,7 @@ class CreateDeviceIpAddressesTest < ActiveSupport::TestCase
26
26
  ip6: '1500:0:2d0:201::1',
27
27
  subnet: subnet,
28
28
  subnet6: subnet6
29
- )
29
+ ),
30
30
  ]
31
31
  )
32
32
  end
@@ -39,7 +39,7 @@ class CreateDeviceIpAddressesTest < ActiveSupport::TestCase
39
39
  status: 200, headers: { 'Content-Type': 'application/json' },
40
40
  body: {
41
41
  count: 0,
42
- results: []
42
+ results: [],
43
43
  }.to_json
44
44
  )
45
45
  stub_request(:get, "#{Setting[:netbox_url]}/api/ipam/ip-addresses.json").with(
@@ -48,7 +48,7 @@ class CreateDeviceIpAddressesTest < ActiveSupport::TestCase
48
48
  status: 200, headers: { 'Content-Type': 'application/json' },
49
49
  body: {
50
50
  count: 1,
51
- results: [{ id: 2 }]
51
+ results: [{ id: 2 }],
52
52
  }.to_json
53
53
  )
54
54
  end
@@ -59,7 +59,7 @@ class CreateDeviceIpAddressesTest < ActiveSupport::TestCase
59
59
  address: host.interfaces.first.netbox_ip,
60
60
  assigned_object_type: 'dcim.interface',
61
61
  assigned_object_id: interfaces.first.id,
62
- tags: default_tags.map(&:id)
62
+ tags: default_tags.map(&:id),
63
63
  }.to_json
64
64
  ).to_return(
65
65
  status: 201, headers: { 'Content-Type': 'application/json' },
@@ -71,7 +71,7 @@ class CreateDeviceIpAddressesTest < ActiveSupport::TestCase
71
71
  address: host.interfaces.first.netbox_ip6,
72
72
  assigned_object_type: 'dcim.interface',
73
73
  assigned_object_id: interfaces.first.id,
74
- tags: default_tags.map(&:id)
74
+ tags: default_tags.map(&:id),
75
75
  }.to_json
76
76
  ).to_return(
77
77
  status: 201, headers: { 'Content-Type': 'application/json' },
@@ -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,
@@ -19,7 +19,7 @@ class DeleteDeviceIpAddressesTest < ActiveSupport::TestCase
19
19
  :nic_base,
20
20
  ip: '10.0.0.1',
21
21
  subnet: FactoryBot.build_stubbed(:subnet_ipv4)
22
- )
22
+ ),
23
23
  ]
24
24
  )
25
25
  end
@@ -39,8 +39,8 @@ class DeleteDeviceIpAddressesTest < ActiveSupport::TestCase
39
39
  body: {
40
40
  count: 1,
41
41
  results: [
42
- { id: interface_id, name: host.interfaces.first.netbox_name }
43
- ]
42
+ { id: interface_id, name: host.interfaces.first.netbox_name },
43
+ ],
44
44
  }.to_json
45
45
  )
46
46
  stub_request(:get, "#{Setting[:netbox_url]}/api/ipam/ip-addresses.json").with(
@@ -51,8 +51,8 @@ class DeleteDeviceIpAddressesTest < ActiveSupport::TestCase
51
51
  count: 2,
52
52
  results: [
53
53
  { id: ip_addresses_v4_id, address: ip_addresses_v4, assigned_object_type: 'dcim.interface', assigned_object_id: interface_id },
54
- { id: ip_addresses_v6_id, address: ip_addresses_v6, assigned_object_type: 'dcim.interface', assigned_object_id: interface_id }
55
- ]
54
+ { id: ip_addresses_v6_id, address: ip_addresses_v6, assigned_object_type: 'dcim.interface', assigned_object_id: interface_id },
55
+ ],
56
56
  }.to_json
57
57
  )
58
58
  end
@@ -23,7 +23,7 @@ class FindDeviceIpAddressesTest < ActiveSupport::TestCase
23
23
  status: 200, headers: { 'Content-Type': 'application/json' },
24
24
  body: {
25
25
  count: 1,
26
- results: [{ id: 1 }]
26
+ results: [{ id: 1 }],
27
27
  }.to_json
28
28
  )
29
29
 
@@ -40,11 +40,11 @@ class FindDeviceIpAddressesTest < ActiveSupport::TestCase
40
40
  status: 200, headers: { 'Content-Type': 'application/json' },
41
41
  body: {
42
42
  count: 0,
43
- results: []
43
+ results: [],
44
44
  }.to_json
45
45
  )
46
46
 
47
- assert_equal [], subject.ip_addresses.map(&:id)
47
+ assert_empty subject.ip_addresses.map(&:id)
48
48
  assert_requested(stub_get)
49
49
  end
50
50
  end
@@ -11,12 +11,12 @@ 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
  [
18
18
  { id: 1, address: host.netbox_facet.netbox_params[:ip_addresses].first[:address], tags: tags_data },
19
- { id: 2, address: host.netbox_facet.netbox_params[:ip_addresses].second[:address], tags: [] }
19
+ { id: 2, address: host.netbox_facet.netbox_params[:ip_addresses].second[:address], tags: [] },
20
20
  ]
21
21
  end
22
22
  let(:host) do
@@ -30,7 +30,7 @@ class UpdateDeviceIpAddressesTest < ActiveSupport::TestCase
30
30
  ip6: '1600:0:2d0:202::17',
31
31
  subnet: FactoryBot.build_stubbed(:subnet_ipv4, organizations: [], locations: []),
32
32
  subnet6: FactoryBot.build_stubbed(:subnet_ipv6, organizations: [], locations: [])
33
- )
33
+ ),
34
34
  ]
35
35
  )
36
36
  end
@@ -43,7 +43,7 @@ class UpdateDeviceIpAddressesTest < ActiveSupport::TestCase
43
43
  status: 200, headers: { 'Content-Type': 'application/json' },
44
44
  body: {
45
45
  count: ip_addresses_data.count,
46
- results: ip_addresses_data
46
+ results: ip_addresses_data,
47
47
  }.to_json
48
48
  )
49
49
  end
@@ -52,7 +52,7 @@ class UpdateDeviceIpAddressesTest < ActiveSupport::TestCase
52
52
  stub_unexpected_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/ipam/ip-addresses/#{ip_addresses_data.first[:id]}.json")
53
53
  stub_expected_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/ipam/ip-addresses/#{ip_addresses_data.second[:id]}.json").with(
54
54
  body: {
55
- tags: default_tags.map(&:id)
55
+ tags: default_tags.map(&:id),
56
56
  }.to_json
57
57
  ).to_return(
58
58
  status: 200, headers: { 'Content-Type': 'application/json' },
@@ -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(
@@ -23,7 +23,7 @@ class UpdateDeviceInterfacesTest < ActiveSupport::TestCase
23
23
  :nic_base,
24
24
  identifier: 'eth1',
25
25
  mac: old_mac
26
- )
26
+ ),
27
27
  ]
28
28
  )
29
29
  end
@@ -47,15 +47,15 @@ class UpdateDeviceInterfacesTest < ActiveSupport::TestCase
47
47
  id: 1,
48
48
  name: host.interfaces.first.netbox_name,
49
49
  mac_address: new_mac.upcase,
50
- tags: []
51
- }
52
- ]
50
+ tags: [],
51
+ },
52
+ ],
53
53
  }.to_json
54
54
  )
55
55
  stub_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/dcim/interfaces/1.json").with(
56
56
  body: {
57
57
  mac_address: host.interfaces.first.mac.upcase,
58
- tags: tags.map(&:id)
58
+ tags: tags.map(&:id),
59
59
  }.to_json
60
60
  ).to_return(
61
61
  status: 200, headers: { 'Content-Type': 'application/json' },
@@ -81,9 +81,9 @@ class UpdateDeviceInterfacesTest < ActiveSupport::TestCase
81
81
  id: 1,
82
82
  name: host.interfaces.first.netbox_name,
83
83
  mac_address: old_mac,
84
- tags: tags.map { |t| { id: t.id, name: t.name, slug: t.slug } }
85
- }
86
- ]
84
+ tags: tags.map { |t| { id: t.id, name: t.name, slug: t.slug } },
85
+ },
86
+ ],
87
87
  }.to_json
88
88
  )
89
89
 
@@ -29,7 +29,7 @@ class CreateSiteTest < ActiveSupport::TestCase
29
29
  body: {
30
30
  name: host.location.netbox_site_name,
31
31
  slug: host.location.netbox_site_slug,
32
- tags: default_tags.map(&:id)
32
+ tags: default_tags.map(&:id),
33
33
  }.to_json
34
34
  ).to_return(
35
35
  status: 201, headers: { 'Content-Type': 'application/json' },