foreman_netbox 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/app/interactors/foreman_netbox/delete_host/organizer.rb +1 -1
  3. data/app/interactors/foreman_netbox/sync_host/organizer.rb +1 -1
  4. data/app/interactors/foreman_netbox/sync_host/sync_device/find.rb +0 -2
  5. data/app/interactors/foreman_netbox/sync_host/sync_device/organizer.rb +10 -10
  6. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/organizer.rb +1 -1
  7. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/organizer.rb +3 -3
  8. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find.rb +2 -3
  9. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/organizer.rb +1 -1
  10. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find.rb +1 -1
  11. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/organizer.rb +4 -4
  12. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete.rb +3 -1
  13. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find.rb +1 -1
  14. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/organizer.rb +3 -3
  15. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update.rb +3 -1
  16. data/app/interactors/foreman_netbox/sync_host/sync_device/sync_site/organizer.rb +2 -2
  17. data/app/interactors/foreman_netbox/sync_host/sync_tags/organizer.rb +2 -2
  18. data/app/interactors/foreman_netbox/sync_host/sync_tenant/organizer.rb +2 -2
  19. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/find.rb +0 -2
  20. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/organizer.rb +8 -8
  21. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/organizer.rb +3 -3
  22. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/organizer.rb +1 -1
  23. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find.rb +1 -1
  24. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/organizer.rb +4 -4
  25. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete.rb +3 -1
  26. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find.rb +1 -1
  27. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/organizer.rb +3 -3
  28. data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update.rb +3 -1
  29. data/app/models/orchestration/netbox.rb +2 -4
  30. data/app/services/foreman_netbox/cached_netbox_parameters.rb +11 -11
  31. data/app/services/foreman_netbox/netbox_parameters.rb +27 -27
  32. data/app/services/foreman_netbox/netbox_parameters_comparator.rb +12 -6
  33. data/lib/foreman_netbox/engine.rb +20 -20
  34. data/lib/foreman_netbox/version.rb +1 -1
  35. data/lib/tasks/foreman_netbox_tasks.rake +0 -2
  36. data/test/integration/foreman_netbox/sync_k8s_physical_host_test.rb +7 -7
  37. data/test/integration/foreman_netbox/sync_rhel_physical_host_test.rb +7 -7
  38. data/test/integration/foreman_netbox/sync_rhel_virtual_host_test.rb +7 -7
  39. data/test/interactors/foreman_netbox/sync_host/organizer_test.rb +9 -9
  40. data/test/interactors/foreman_netbox/sync_host/sync_device/create_test.rb +1 -1
  41. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/create_test.rb +1 -1
  42. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/find_test.rb +4 -4
  43. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/create_test.rb +1 -1
  44. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/find_test.rb +4 -4
  45. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/create_test.rb +1 -1
  46. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find_test.rb +6 -6
  47. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/update_test.rb +1 -1
  48. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/create_test.rb +3 -3
  49. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/delete_test.rb +1 -1
  50. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find_test.rb +4 -4
  51. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/create_test.rb +5 -5
  52. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete_test.rb +5 -5
  53. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find_test.rb +3 -3
  54. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/update_test.rb +4 -4
  55. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update_test.rb +8 -8
  56. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/create_test.rb +1 -1
  57. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/find_test.rb +3 -3
  58. data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/update_test.rb +1 -1
  59. data/test/interactors/foreman_netbox/sync_host/sync_device/update_test.rb +9 -9
  60. data/test/interactors/foreman_netbox/sync_host/sync_tenant/create_test.rb +1 -1
  61. data/test/interactors/foreman_netbox/sync_host/sync_tenant/find_test.rb +3 -3
  62. data/test/interactors/foreman_netbox/sync_host/sync_tenant/update_test.rb +1 -1
  63. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/create_test.rb +2 -2
  64. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/create_test.rb +1 -1
  65. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/find_test.rb +2 -2
  66. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/find_test.rb +4 -4
  67. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/update_test.rb +1 -1
  68. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/create_test.rb +3 -3
  69. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/delete_test.rb +1 -1
  70. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find_test.rb +4 -4
  71. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/create_test.rb +5 -5
  72. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete_test.rb +5 -5
  73. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find_test.rb +3 -3
  74. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/update_test.rb +6 -6
  75. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update_test.rb +8 -8
  76. data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/update_test.rb +8 -8
  77. data/test/models/foreman_netbox/netbox_facet_test.rb +1 -1
  78. data/test/models/foreman_netbox/nics/base_test.rb +1 -1
  79. data/test/services/foreman_netbox/netbox_attributes_test.rb +16 -16
  80. data/test/services/foreman_netbox/netbox_parameters_comparator_test.rb +31 -31
  81. metadata +33 -111
@@ -32,22 +32,27 @@ module ForemanNetbox
32
32
  def keys_diff
33
33
  result = {}
34
34
 
35
- result[:added] = added_keys.each_with_object({}) { |key, memo| memo[key] = new_hash[key] } if added_keys.any?
36
- result[:removed] = removed_keys.each_with_object({}) { |key, memo| memo[key] = old_hash[key] } if removed_keys.any?
35
+ result[:added] = added_keys.index_with { |key| new_hash[key] } if added_keys.any?
36
+ if removed_keys.any?
37
+ result[:removed] = removed_keys.index_with do |key|
38
+ old_hash[key]
39
+ end
40
+ end
37
41
 
38
42
  result
39
43
  end
40
44
 
41
45
  def diff_old
42
46
  old_hash.except(*removed_keys).each_with_object({}) do |(key, old_value), memo|
43
- if old_value.is_a?(Hash)
47
+ case old_value
48
+ when Hash
44
49
  new_value = new_hash.fetch(key, {})
45
50
  diff = ForemanNetbox::NetboxParametersComparator.call(old_value, new_value)
46
51
 
47
52
  next unless diff.keys.any?
48
53
 
49
54
  memo[key] = diff
50
- elsif old_value.is_a?(Array)
55
+ when Array
51
56
  next if new_hash[key]
52
57
 
53
58
  memo[key] = { added: [], removed: old_value }
@@ -64,7 +69,8 @@ module ForemanNetbox
64
69
  # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
65
70
  def diff_new
66
71
  new_hash.except(*added_keys).each_with_object({}) do |(key, new_value), memo|
67
- if new_value.is_a?(Hash)
72
+ case new_value
73
+ when Hash
68
74
  old_value = old_hash.fetch(key, {})
69
75
 
70
76
  next if old_value == new_value
@@ -74,7 +80,7 @@ module ForemanNetbox
74
80
  next unless diff.keys.any?
75
81
 
76
82
  memo[key] = diff
77
- elsif new_value.is_a?(Array)
83
+ when Array
78
84
  old_value = old_hash.fetch(key, [])
79
85
  added = new_value.reject { |item| old_value.find { |x| x == item } }
80
86
  removed = old_value.reject { |item| new_value.find { |x| x == item } }
@@ -17,7 +17,7 @@ module ForemanNetbox
17
17
  end
18
18
  end
19
19
 
20
- initializer 'foreman_netbox.register_plugin', :before => :finisher_hook do |_app|
20
+ initializer 'foreman_netbox.register_plugin', before: :finisher_hook do |_app|
21
21
  Foreman::Plugin.register :foreman_netbox do
22
22
  requires_foreman '>= 3.1'
23
23
 
@@ -29,33 +29,33 @@ module ForemanNetbox
29
29
  # extend host show page
30
30
  extend_page('hosts/show') do |context|
31
31
  context.add_pagelet :main_tabs,
32
- name: N_('Netbox'),
33
- partial: 'hosts/netbox_tab',
34
- onlyif: proc { |host| host.netbox_facet.synchronized_at }
32
+ name: N_('Netbox'),
33
+ partial: 'hosts/netbox_tab',
34
+ onlyif: proc { |host| host.netbox_facet.synchronized_at }
35
35
  end
36
36
 
37
37
  settings do
38
38
  category(:netbox, N_('Netbox')) do
39
39
  setting 'netbox_url',
40
- type: :string,
41
- default: '-',
42
- full_name: N_('Netbox URL'),
43
- description: N_('URL where Netbox is reachable')
40
+ type: :string,
41
+ default: '-',
42
+ full_name: N_('Netbox URL'),
43
+ description: N_('URL where Netbox is reachable')
44
44
  setting 'netbox_api_token',
45
- type: :string,
46
- default: '-',
47
- full_name: N_('Netbox API token'),
48
- description: N_('API token to Netbox')
45
+ type: :string,
46
+ default: '-',
47
+ full_name: N_('Netbox API token'),
48
+ description: N_('API token to Netbox')
49
49
  setting 'netbox_orchestration_enabled',
50
- type: :boolean,
51
- default: false,
52
- full_name: N_('Netbox Orchestration'),
53
- description: N_('Enable Netbox Orchestration')
50
+ type: :boolean,
51
+ default: false,
52
+ full_name: N_('Netbox Orchestration'),
53
+ description: N_('Enable Netbox Orchestration')
54
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')
55
+ type: :boolean,
56
+ default: false,
57
+ full_name: N_('Skip Site Update'),
58
+ description: N_('Skip updating Site attribute for Devices')
59
59
  end
60
60
  end
61
61
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForemanNetbox
4
- VERSION = '1.1.1'
4
+ VERSION = '1.2.0'
5
5
  end
@@ -60,8 +60,6 @@ Rake::Task[:test].enhance ['test:foreman_netbox']
60
60
 
61
61
  load 'tasks/jenkins.rake'
62
62
 
63
- # rubocop:disable Style/IfUnlessModifier
64
63
  if Rake::Task.task_defined?(:'jenkins:unit')
65
64
  Rake::Task['jenkins:unit'].enhance ['test:foreman_netbox', 'foreman_netbox:rubocop']
66
65
  end
67
- # rubocop:enable Style/IfUnlessModifier
@@ -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)
@@ -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)
@@ -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
  )
@@ -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
@@ -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' },
@@ -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
 
@@ -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
 
@@ -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' },
@@ -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
@@ -16,7 +16,7 @@ class UpdateDeviceIpAddressesTest < ActiveSupport::TestCase
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' },