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.
- 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/delete_host/organizer.rb +1 -1
- data/app/interactors/foreman_netbox/sync_host/organizer.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 -5
- data/app/interactors/foreman_netbox/sync_host/sync_device/organizer.rb +10 -10
- 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_role/organizer.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/organizer.rb +3 -3
- 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 +4 -5
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/organizer.rb +1 -1
- 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 +2 -2
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/organizer.rb +4 -4
- 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/delete.rb +3 -1
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find.rb +2 -2
- data/app/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/organizer.rb +3 -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_device/sync_site/organizer.rb +2 -2
- 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_tags/organizer.rb +2 -2
- 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_tenant/organizer.rb +2 -2
- 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 -4
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/organizer.rb +8 -8
- 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/organizer.rb +3 -3
- 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_cluster/sync_cluster_type/organizer.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 +2 -2
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/organizer.rb +4 -4
- 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 +3 -3
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find.rb +2 -2
- data/app/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/organizer.rb +3 -3
- data/app/lib/foreman_netbox/api.rb +11 -2
- data/app/models/orchestration/netbox.rb +2 -4
- data/app/services/foreman_netbox/cached_netbox_parameters.rb +11 -11
- data/app/services/foreman_netbox/netbox_parameters.rb +29 -29
- data/app/services/foreman_netbox/netbox_parameters_comparator.rb +14 -8
- 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 -50
- data/test/fixtures/netbox_device_raw_data.json +1 -1
- data/test/integration/foreman_netbox/sync_k8s_physical_host_test.rb +8 -8
- data/test/integration/foreman_netbox/sync_rhel_physical_host_test.rb +8 -8
- data/test/integration/foreman_netbox/sync_rhel_virtual_host_test.rb +8 -8
- data/test/interactors/foreman_netbox/sync_host/organizer_test.rb +9 -9
- data/test/interactors/foreman_netbox/sync_host/sync_device/create_test.rb +2 -2
- 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_role/create_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_role/find_test.rb +4 -4
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/create_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/find_test.rb +4 -4
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/create_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/sync_manufacturer/find_test.rb +6 -6
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_device_type/update_test.rb +2 -2
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/create_test.rb +3 -3
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/delete_test.rb +2 -2
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/find_test.rb +4 -4
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/create_test.rb +5 -5
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/delete_test.rb +7 -7
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/find_test.rb +3 -3
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/sync_ip_addresses/update_test.rb +5 -5
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_interfaces/update_test.rb +10 -10
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/create_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/find_test.rb +3 -3
- data/test/interactors/foreman_netbox/sync_host/sync_device/sync_site/update_test.rb +3 -3
- data/test/interactors/foreman_netbox/sync_host/sync_device/update_test.rb +11 -11
- data/test/interactors/foreman_netbox/sync_host/sync_tenant/create_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_tenant/find_test.rb +3 -3
- data/test/interactors/foreman_netbox/sync_host/sync_tenant/update_test.rb +2 -2
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/create_test.rb +2 -2
- 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/create_test.rb +1 -1
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/find_test.rb +2 -2
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/sync_cluster_type/find_test.rb +4 -4
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/update_test.rb +2 -2
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/create_test.rb +3 -3
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/delete_test.rb +2 -2
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find_test.rb +4 -4
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/create_test.rb +5 -5
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/delete_test.rb +7 -7
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/find_test.rb +3 -3
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/sync_ip_addresses/update_test.rb +7 -7
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update_test.rb +9 -9
- data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/update_test.rb +10 -10
- data/test/models/foreman_netbox/netbox_facet_test.rb +1 -1
- data/test/models/foreman_netbox/nics/base_test.rb +1 -1
- data/test/services/foreman_netbox/netbox_attributes_test.rb +16 -16
- data/test/services/foreman_netbox/netbox_parameters_comparator_test.rb +31 -31
- data/test/test_plugin_helper.rb +1 -1
- data/test/unit/foreman_netbox/api_test.rb +52 -0
- metadata +88 -165
@@ -30,8 +30,8 @@ class FindSiteTest < ActiveSupport::TestCase
|
|
30
30
|
body: {
|
31
31
|
count: 1,
|
32
32
|
results: [
|
33
|
-
{ id: 1, name: host.location.netbox_site_name, slug: host.location.netbox_site_slug }
|
34
|
-
]
|
33
|
+
{ id: 1, name: host.location.netbox_site_name, slug: host.location.netbox_site_slug },
|
34
|
+
],
|
35
35
|
}.to_json
|
36
36
|
)
|
37
37
|
|
@@ -48,7 +48,7 @@ class FindSiteTest < ActiveSupport::TestCase
|
|
48
48
|
status: 200, headers: { 'Content-Type': 'application/json' },
|
49
49
|
body: {
|
50
50
|
count: 0,
|
51
|
-
results: []
|
51
|
+
results: [],
|
52
52
|
}.to_json
|
53
53
|
)
|
54
54
|
|
@@ -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 }
|
@@ -30,7 +30,7 @@ class UpdateSiteTest < ActiveSupport::TestCase
|
|
30
30
|
it 'updates site' do
|
31
31
|
stub_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/dcim/sites/1.json").with(
|
32
32
|
body: {
|
33
|
-
tags: default_tags.map(&:id)
|
33
|
+
tags: default_tags.map(&:id),
|
34
34
|
}.to_json
|
35
35
|
).to_return(
|
36
36
|
status: 200, headers: { 'Content-Type': 'application/json' },
|
@@ -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
|
{
|
@@ -32,14 +32,14 @@ class UpdateDeviceTest < ActiveSupport::TestCase
|
|
32
32
|
'primary_ip4' => {
|
33
33
|
'id' => 1,
|
34
34
|
'family' => 4,
|
35
|
-
'address' => '10.0.0.8/24'
|
35
|
+
'address' => '10.0.0.8/24',
|
36
36
|
},
|
37
37
|
'primary_ip6' => {
|
38
38
|
'id' => 2,
|
39
39
|
'family' => 6,
|
40
|
-
'address' => '1600:0:2d0:202::18/64'
|
40
|
+
'address' => '1600:0:2d0:202::18/64',
|
41
41
|
},
|
42
|
-
'tags' => device_tags
|
42
|
+
'tags' => device_tags,
|
43
43
|
}
|
44
44
|
)
|
45
45
|
end
|
@@ -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,
|
@@ -90,8 +90,8 @@ class UpdateDeviceTest < ActiveSupport::TestCase
|
|
90
90
|
count: 2,
|
91
91
|
results: [
|
92
92
|
{ id: primary_ip4.id, address: primary_ip4.address.address },
|
93
|
-
{ id: primary_ip6.id, address: primary_ip6.address.address }
|
94
|
-
]
|
93
|
+
{ id: primary_ip6.id, address: primary_ip6.address.address },
|
94
|
+
],
|
95
95
|
}.to_json
|
96
96
|
)
|
97
97
|
end
|
@@ -109,7 +109,7 @@ class UpdateDeviceTest < ActiveSupport::TestCase
|
|
109
109
|
body: {
|
110
110
|
id: t['id'],
|
111
111
|
name: t['name'],
|
112
|
-
slug: t['slug']
|
112
|
+
slug: t['slug'],
|
113
113
|
}.to_json
|
114
114
|
)
|
115
115
|
end
|
@@ -163,7 +163,7 @@ class UpdateDeviceTest < ActiveSupport::TestCase
|
|
163
163
|
site: site.id,
|
164
164
|
tenant: tenant.id,
|
165
165
|
serial: serialnumber,
|
166
|
-
tags: default_tags.map(&:id)
|
166
|
+
tags: default_tags.map(&:id),
|
167
167
|
}.to_json
|
168
168
|
).to_return(
|
169
169
|
status: 200, headers: { 'Content-Type': 'application/json' },
|
@@ -187,7 +187,7 @@ class UpdateDeviceTest < ActiveSupport::TestCase
|
|
187
187
|
primary_ip6: primary_ip6.id,
|
188
188
|
site: site.id,
|
189
189
|
tenant: tenant.id,
|
190
|
-
tags: default_tags.map(&:id)
|
190
|
+
tags: default_tags.map(&:id),
|
191
191
|
}.to_json
|
192
192
|
).to_return(
|
193
193
|
status: 200, headers: { 'Content-Type': 'application/json' },
|
@@ -219,7 +219,7 @@ class UpdateDeviceTest < ActiveSupport::TestCase
|
|
219
219
|
body: {
|
220
220
|
id: t['id'],
|
221
221
|
name: t['name'],
|
222
|
-
slug: t['slug']
|
222
|
+
slug: t['slug'],
|
223
223
|
}.to_json
|
224
224
|
)
|
225
225
|
end
|
@@ -28,7 +28,7 @@ class CreateTenantTest < ActiveSupport::TestCase
|
|
28
28
|
body: {
|
29
29
|
name: host.owner.name,
|
30
30
|
slug: host.owner.name.parameterize,
|
31
|
-
tags: default_tags.map(&:id)
|
31
|
+
tags: default_tags.map(&:id),
|
32
32
|
}.to_json
|
33
33
|
).to_return(
|
34
34
|
status: 201, headers: { 'Content-Type': 'application/json' },
|
@@ -29,8 +29,8 @@ class FindTenantTest < ActiveSupport::TestCase
|
|
29
29
|
body: {
|
30
30
|
count: 1,
|
31
31
|
results: [
|
32
|
-
{ id: 1, name: host.owner.name, slug: host.owner.name.parameterize }
|
33
|
-
]
|
32
|
+
{ id: 1, name: host.owner.name, slug: host.owner.name.parameterize },
|
33
|
+
],
|
34
34
|
}.to_json
|
35
35
|
)
|
36
36
|
|
@@ -47,7 +47,7 @@ class FindTenantTest < 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
|
|
@@ -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 }
|
@@ -34,7 +34,7 @@ class UpdateTenantTest < ActiveSupport::TestCase
|
|
34
34
|
it 'updates tenant' do
|
35
35
|
stub_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/tenancy/tenants/1.json").with(
|
36
36
|
body: {
|
37
|
-
tags: default_tags.map(&:id)
|
37
|
+
tags: default_tags.map(&:id),
|
38
38
|
}.to_json
|
39
39
|
).to_return(
|
40
40
|
status: 200, headers: { 'Content-Type': 'application/json' },
|
@@ -26,7 +26,7 @@ class CreateVirtualMachineTest < ActiveSupport::TestCase
|
|
26
26
|
cpus: 2,
|
27
27
|
memory_mb: 512,
|
28
28
|
volumes: [
|
29
|
-
OpenStruct.new(size_gb: 128)
|
29
|
+
OpenStruct.new(size_gb: 128),
|
30
30
|
]
|
31
31
|
)
|
32
32
|
)
|
@@ -53,7 +53,7 @@ class CreateVirtualMachineTest < ActiveSupport::TestCase
|
|
53
53
|
name: netbox_virtual_machine_params[:name],
|
54
54
|
cluster: cluster.id,
|
55
55
|
tenant: tenant.id,
|
56
|
-
tags: default_tags.map(&:id)
|
56
|
+
tags: default_tags.map(&:id),
|
57
57
|
}.to_json
|
58
58
|
).to_return(
|
59
59
|
status: 201, headers: { 'Content-Type': 'application/json' },
|
@@ -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/create_test.rb
CHANGED
@@ -36,7 +36,7 @@ class CreateClusterTest < ActiveSupport::TestCase
|
|
36
36
|
body: {
|
37
37
|
name: host.netbox_facet.netbox_params.dig(:cluster, :name),
|
38
38
|
type: cluster_type.id,
|
39
|
-
tags: default_tags.map(&:id)
|
39
|
+
tags: default_tags.map(&:id),
|
40
40
|
}.to_json
|
41
41
|
).to_return(
|
42
42
|
status: 201, headers: { 'Content-Type': 'application/json' },
|
data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_cluster/find_test.rb
CHANGED
@@ -30,7 +30,7 @@ class FindClusterTest < ActiveSupport::TestCase
|
|
30
30
|
status: 200, headers: { 'Content-Type': 'application/json' },
|
31
31
|
body: {
|
32
32
|
count: 1,
|
33
|
-
results: [{ id: 1, name: host.compute_object.cluster }]
|
33
|
+
results: [{ id: 1, name: host.compute_object.cluster }],
|
34
34
|
}.to_json
|
35
35
|
)
|
36
36
|
|
@@ -47,7 +47,7 @@ class FindClusterTest < 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
|
|
@@ -35,9 +35,9 @@ class FindClusterTypeTest < ActiveSupport::TestCase
|
|
35
35
|
{
|
36
36
|
id: 1,
|
37
37
|
name: cluster_type_params[:name],
|
38
|
-
slug: cluster_type_params[:slug]
|
39
|
-
}
|
40
|
-
]
|
38
|
+
slug: cluster_type_params[:slug],
|
39
|
+
},
|
40
|
+
],
|
41
41
|
}.to_json
|
42
42
|
)
|
43
43
|
|
@@ -54,7 +54,7 @@ class FindClusterTypeTest < ActiveSupport::TestCase
|
|
54
54
|
status: 200, headers: { 'Content-Type': 'application/json' },
|
55
55
|
body: {
|
56
56
|
count: 0,
|
57
|
-
results: []
|
57
|
+
results: [],
|
58
58
|
}.to_json
|
59
59
|
)
|
60
60
|
|
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 }
|
@@ -29,7 +29,7 @@ class UpdateClusterTest < ActiveSupport::TestCase
|
|
29
29
|
it 'updates cluster' do
|
30
30
|
stub_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/virtualization/clusters/1.json").with(
|
31
31
|
body: {
|
32
|
-
tags: default_tags.map(&:id)
|
32
|
+
tags: default_tags.map(&:id),
|
33
33
|
}.to_json
|
34
34
|
).to_return(
|
35
35
|
status: 200, headers: { 'Content-Type': 'application/json' },
|
data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/create_test.rb
CHANGED
@@ -21,7 +21,7 @@ class CreateVirtualMachineInterfacesTest < 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
|
@@ -38,13 +38,13 @@ class CreateVirtualMachineInterfacesTest < ActiveSupport::TestCase
|
|
38
38
|
name: host.interfaces.first.netbox_name,
|
39
39
|
mac_address: host.interfaces.first.mac.upcase,
|
40
40
|
virtual_machine: virtual_machine.id,
|
41
|
-
tags: default_tags.map(&:id)
|
41
|
+
tags: default_tags.map(&:id),
|
42
42
|
}.to_json
|
43
43
|
).to_return(
|
44
44
|
status: 201, headers: { 'Content-Type': 'application/json' },
|
45
45
|
body: {
|
46
46
|
id: 1,
|
47
|
-
name: host.interfaces.first.netbox_name
|
47
|
+
name: host.interfaces.first.netbox_name,
|
48
48
|
}.to_json
|
49
49
|
)
|
50
50
|
|
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
|
@@ -21,7 +21,7 @@ class DeleteVirtualMachineInterfacesTest < ActiveSupport::TestCase
|
|
21
21
|
status: 200, headers: { 'Content-Type': 'application/json' },
|
22
22
|
body: {
|
23
23
|
count: 1,
|
24
|
-
results: [{ id: interface_id, name: 'eth0' }]
|
24
|
+
results: [{ id: interface_id, name: 'eth0' }],
|
25
25
|
}.to_json
|
26
26
|
)
|
27
27
|
end
|
data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/find_test.rb
CHANGED
@@ -24,8 +24,8 @@ class FindVirtualMachineInterfacesTest < 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 FindVirtualMachineInterfacesTest < 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
|
-
|
49
|
+
assert_empty subject.interfaces.map(&:id)
|
50
50
|
assert_requested(stub_get)
|
51
51
|
end
|
52
52
|
end
|
@@ -23,7 +23,7 @@ class CreateVirtualMachineIpAddressesTest < ActiveSupport::TestCase
|
|
23
23
|
ip6: '1500:0:2d0:201::1',
|
24
24
|
subnet: subnet,
|
25
25
|
subnet6: subnet6
|
26
|
-
)
|
26
|
+
),
|
27
27
|
]
|
28
28
|
)
|
29
29
|
end
|
@@ -36,7 +36,7 @@ class CreateVirtualMachineIpAddressesTest < ActiveSupport::TestCase
|
|
36
36
|
status: 200, headers: { 'Content-Type': 'application/json' },
|
37
37
|
body: {
|
38
38
|
count: 0,
|
39
|
-
results: []
|
39
|
+
results: [],
|
40
40
|
}.to_json
|
41
41
|
)
|
42
42
|
stub_request(:get, "#{Setting[:netbox_url]}/api/ipam/ip-addresses.json").with(
|
@@ -45,7 +45,7 @@ class CreateVirtualMachineIpAddressesTest < ActiveSupport::TestCase
|
|
45
45
|
status: 200, headers: { 'Content-Type': 'application/json' },
|
46
46
|
body: {
|
47
47
|
count: 1,
|
48
|
-
results: [{ id: 2 }]
|
48
|
+
results: [{ id: 2 }],
|
49
49
|
}.to_json
|
50
50
|
)
|
51
51
|
end
|
@@ -56,7 +56,7 @@ class CreateVirtualMachineIpAddressesTest < ActiveSupport::TestCase
|
|
56
56
|
address: host.interfaces.first.netbox_ip,
|
57
57
|
assigned_object_type: 'virtualization.vminterface',
|
58
58
|
assigned_object_id: interfaces.first.id,
|
59
|
-
tags: default_tags.map(&:id)
|
59
|
+
tags: default_tags.map(&:id),
|
60
60
|
}.to_json
|
61
61
|
).to_return(
|
62
62
|
status: 201, headers: { 'Content-Type': 'application/json' },
|
@@ -68,7 +68,7 @@ class CreateVirtualMachineIpAddressesTest < ActiveSupport::TestCase
|
|
68
68
|
address: host.interfaces.first.netbox_ip6,
|
69
69
|
assigned_object_type: 'virtualization.vminterface',
|
70
70
|
assigned_object_id: interfaces.first.id,
|
71
|
-
tags: default_tags.map(&:id)
|
71
|
+
tags: default_tags.map(&:id),
|
72
72
|
}.to_json
|
73
73
|
).to_return(
|
74
74
|
status: 201, headers: { 'Content-Type': 'application/json' },
|
@@ -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(
|
@@ -20,7 +20,7 @@ class DeleteVirtualMachineIpAddressesTest < ActiveSupport::TestCase
|
|
20
20
|
:nic_base,
|
21
21
|
ip: '10.0.0.1',
|
22
22
|
subnet: FactoryBot.build_stubbed(:subnet_ipv4)
|
23
|
-
)
|
23
|
+
),
|
24
24
|
]
|
25
25
|
)
|
26
26
|
end
|
@@ -40,8 +40,8 @@ class DeleteVirtualMachineIpAddressesTest < ActiveSupport::TestCase
|
|
40
40
|
body: {
|
41
41
|
count: 1,
|
42
42
|
results: [
|
43
|
-
{ id: interface_id, name: host.interfaces.first.netbox_name }
|
44
|
-
]
|
43
|
+
{ id: interface_id, name: host.interfaces.first.netbox_name },
|
44
|
+
],
|
45
45
|
}.to_json
|
46
46
|
)
|
47
47
|
stub_request(:get, "#{Setting[:netbox_url]}/api/ipam/ip-addresses.json").with(
|
@@ -52,8 +52,8 @@ class DeleteVirtualMachineIpAddressesTest < ActiveSupport::TestCase
|
|
52
52
|
count: 2,
|
53
53
|
results: [
|
54
54
|
{ id: ip_addresses_v4_id, address: ip_addresses_v4, assigned_object_type: 'virtualization.vminterface', assigned_object_id: interface_id },
|
55
|
-
{ id: ip_addresses_v6_id, address: ip_addresses_v6, assigned_object_type: 'virtualization.vminterface', assigned_object_id: interface_id }
|
56
|
-
]
|
55
|
+
{ id: ip_addresses_v6_id, address: ip_addresses_v6, assigned_object_type: 'virtualization.vminterface', assigned_object_id: interface_id },
|
56
|
+
],
|
57
57
|
}.to_json
|
58
58
|
)
|
59
59
|
end
|
@@ -23,7 +23,7 @@ class FindVirtualMachineIpAddressesTest < 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 FindVirtualMachineIpAddressesTest < 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
|
-
|
47
|
+
assert_empty subject.ip_addresses.map(&:id)
|
48
48
|
assert_requested(stub_get)
|
49
49
|
end
|
50
50
|
end
|
@@ -11,19 +11,19 @@ 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
|
{
|
18
18
|
id: 1,
|
19
19
|
address: host.netbox_facet.netbox_params[:ip_addresses].first[:address],
|
20
|
-
tags: default_tags.map { |t| { id: t.id, name: t.name, slug: t.slug } }
|
20
|
+
tags: default_tags.map { |t| { id: t.id, name: t.name, slug: t.slug } },
|
21
21
|
},
|
22
22
|
{
|
23
23
|
id: 2,
|
24
24
|
address: host.netbox_facet.netbox_params[:ip_addresses].second[:address],
|
25
|
-
tags: []
|
26
|
-
}
|
25
|
+
tags: [],
|
26
|
+
},
|
27
27
|
]
|
28
28
|
end
|
29
29
|
let(:host) do
|
@@ -37,7 +37,7 @@ class UpdateVirtualMachineIpAddressesTest < ActiveSupport::TestCase
|
|
37
37
|
ip6: '1600:0:2d0:202::17',
|
38
38
|
subnet: FactoryBot.build_stubbed(:subnet_ipv4, organizations: [], locations: []),
|
39
39
|
subnet6: FactoryBot.build_stubbed(:subnet_ipv6, organizations: [], locations: [])
|
40
|
-
)
|
40
|
+
),
|
41
41
|
]
|
42
42
|
)
|
43
43
|
end
|
@@ -50,7 +50,7 @@ class UpdateVirtualMachineIpAddressesTest < ActiveSupport::TestCase
|
|
50
50
|
status: 200, headers: { 'Content-Type': 'application/json' },
|
51
51
|
body: {
|
52
52
|
count: ip_addresses_data.count,
|
53
|
-
results: ip_addresses_data
|
53
|
+
results: ip_addresses_data,
|
54
54
|
}.to_json
|
55
55
|
)
|
56
56
|
end
|
@@ -59,7 +59,7 @@ class UpdateVirtualMachineIpAddressesTest < ActiveSupport::TestCase
|
|
59
59
|
stub_unexpected_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/ipam/ip-addresses/#{ip_addresses_data.first[:id]}.json")
|
60
60
|
stub_expected_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/ipam/ip-addresses/#{ip_addresses_data.second[:id]}.json").with(
|
61
61
|
body: {
|
62
|
-
tags: default_tags.map(&:id)
|
62
|
+
tags: default_tags.map(&:id),
|
63
63
|
}.to_json
|
64
64
|
).to_return(
|
65
65
|
status: 200, headers: { 'Content-Type': 'application/json' },
|
data/test/interactors/foreman_netbox/sync_host/sync_virtual_machine/sync_interfaces/update_test.rb
CHANGED
@@ -12,13 +12,13 @@ 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(
|
19
19
|
:host,
|
20
20
|
interfaces: [
|
21
|
-
FactoryBot.build_stubbed(:nic_base, mac: old_mac)
|
21
|
+
FactoryBot.build_stubbed(:nic_base, mac: old_mac),
|
22
22
|
]
|
23
23
|
)
|
24
24
|
end
|
@@ -42,15 +42,15 @@ class UpdateVirtualMachineInterfacesTest < ActiveSupport::TestCase
|
|
42
42
|
id: 1,
|
43
43
|
name: host.interfaces.first.netbox_name,
|
44
44
|
mac_address: new_mac,
|
45
|
-
tags: []
|
46
|
-
}
|
47
|
-
]
|
45
|
+
tags: [],
|
46
|
+
},
|
47
|
+
],
|
48
48
|
}.to_json
|
49
49
|
)
|
50
50
|
stub_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/virtualization/interfaces/1.json").with(
|
51
51
|
body: {
|
52
52
|
mac_address: host.interfaces.first.mac.upcase,
|
53
|
-
tags: default_tags.map(&:id)
|
53
|
+
tags: default_tags.map(&:id),
|
54
54
|
}.to_json
|
55
55
|
).to_return(
|
56
56
|
status: 200, headers: { 'Content-Type': 'application/json' },
|
@@ -78,9 +78,9 @@ class UpdateVirtualMachineInterfacesTest < ActiveSupport::TestCase
|
|
78
78
|
mac_address: old_mac,
|
79
79
|
tags: default_tags.map do |tag|
|
80
80
|
{ id: tag.id }
|
81
|
-
end
|
82
|
-
}
|
83
|
-
]
|
81
|
+
end,
|
82
|
+
},
|
83
|
+
],
|
84
84
|
}.to_json
|
85
85
|
)
|
86
86
|
stub_patch = stub_request(:patch, "#{Setting[:netbox_url]}/api/virtualization/interfaces/1.json")
|
@@ -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
|
{
|
@@ -30,14 +30,14 @@ class UpdateVirtualMachineTest < ActiveSupport::TestCase
|
|
30
30
|
'primary_ip4' => {
|
31
31
|
'id' => 1,
|
32
32
|
'family' => 4,
|
33
|
-
'address' => '10.0.0.1/24'
|
33
|
+
'address' => '10.0.0.1/24',
|
34
34
|
},
|
35
35
|
'primary_ip6' => {
|
36
36
|
'id' => 2,
|
37
37
|
'family' => 6,
|
38
|
-
'address' => '1600:0:2d0:201::18/64'
|
38
|
+
'address' => '1600:0:2d0:201::18/64',
|
39
39
|
},
|
40
|
-
'tags' => virtual_machine_tags
|
40
|
+
'tags' => virtual_machine_tags,
|
41
41
|
}
|
42
42
|
)
|
43
43
|
end
|
@@ -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,
|
@@ -78,7 +78,7 @@ class UpdateVirtualMachineTest < ActiveSupport::TestCase
|
|
78
78
|
cpus: virtual_machine_data[:vcpus],
|
79
79
|
memory_mb: virtual_machine_data[:memory],
|
80
80
|
volumes: [
|
81
|
-
OpenStruct.new(size_gb: virtual_machine_data[:disk])
|
81
|
+
OpenStruct.new(size_gb: virtual_machine_data[:disk]),
|
82
82
|
]
|
83
83
|
)
|
84
84
|
)
|
@@ -95,8 +95,8 @@ class UpdateVirtualMachineTest < ActiveSupport::TestCase
|
|
95
95
|
count: 2,
|
96
96
|
results: [
|
97
97
|
{ id: primary_ip4.id, address: primary_ip4.address.address },
|
98
|
-
{ id: primary_ip6.id, address: primary_ip6.address.address }
|
99
|
-
]
|
98
|
+
{ id: primary_ip6.id, address: primary_ip6.address.address },
|
99
|
+
],
|
100
100
|
}.to_json
|
101
101
|
)
|
102
102
|
end
|
@@ -142,7 +142,7 @@ class UpdateVirtualMachineTest < ActiveSupport::TestCase
|
|
142
142
|
cpus: 4,
|
143
143
|
memory_mb: 256,
|
144
144
|
volumes: [
|
145
|
-
OpenStruct.new(size_gb: 1024)
|
145
|
+
OpenStruct.new(size_gb: 1024),
|
146
146
|
]
|
147
147
|
)
|
148
148
|
)
|
@@ -160,7 +160,7 @@ class UpdateVirtualMachineTest < ActiveSupport::TestCase
|
|
160
160
|
primary_ip6: primary_ip6.id,
|
161
161
|
tenant: tenant.id,
|
162
162
|
vcpus: host.compute_object.cpus,
|
163
|
-
tags: virtual_machine_tags.map { |t| t['id'] } | default_tags.map(&:id)
|
163
|
+
tags: virtual_machine_tags.map { |t| t['id'] } | default_tags.map(&:id),
|
164
164
|
}.to_json
|
165
165
|
).to_return(
|
166
166
|
status: 200, headers: { 'Content-Type': 'application/json' },
|