Skip to content

Commit

Permalink
fix: Fix network interface capitalize issue and add test to flatten nic
Browse files Browse the repository at this point in the history
  • Loading branch information
Manisha15 committed Jul 30, 2024
1 parent 00d7974 commit 2748290
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/models/foreman_fog_proxmox/proxmox_interfaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def dhcp?(nic_compute_attributes, v6 = false)
def set_mac(nic_compute_attributes, mac, type)
mac_attr_name = { 'qemu' => :macaddr, 'lxc' => :hwaddr }
mac_key = mac_attr_name[type] || 'mac'
nic_compute_attributes[mac_key] = Net::Validations.normalize_mac(mac)
nic_compute_attributes[mac_key] = Net::Validations.normalize_mac(mac).upcase
end

def host_interfaces_attrs(host)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,43 @@ class ProxmoxContainerHelperTest < ActiveSupport::TestCase
} }
end

let(:host_edit) do
{ 'vmid' => '123',
'node_id' => 'proxmox-noris',
'config_attributes' => {
'ostype' => 'alpine',
'hostname' => 'test-container.example.com',
'arch' => 'amd64',
'cores' => '1',
'memory' => '1024',
'swap' => '512',
},
'ostemplate_storage' => 'local',
'ostemplate_file' => 'local:vztmpl/alpine_amd64.tar.xz',
'volumes_attributes' => {
'0' => {
'storage' => 'local',
'size' => '8',
'id' => 'rootfs',
'volid' => 'local:123/vm-123-disk-0.raw',
},
},
'interfaces_attributes' => {
'0' => {
'id' => 'net0',
'name' => 'eth0',
'firewall' => '0',
'bridge' => 'vmbr0',
'hwaddr' => '8E:96:2A:D3:42:80',
'ip' => 'dhcp',
'ip6' => '',
},
},
'name' => 'test-container.example.com',
'provision_method' => 'build',
'firmware_type' => :bios }
end

let(:container) do
{ 'vmid' => '100',
:vmid => '100',
Expand Down Expand Up @@ -183,6 +220,15 @@ class ProxmoxContainerHelperTest < ActiveSupport::TestCase
nics[0][:net0]
end

test '#interface with name eth0 and bridge in host edit' do
deletes = []
nics = []
add_or_delete_typed_interface(host_edit['interfaces_attributes']['0'], deletes, nics, type)
assert 1, nics.length
assert nics[0].key?(:net0)
assert_equal 'hwaddr=8E:96:2A:D3:42:80,bridge=vmbr0,name=eth0,ip=dhcp,firewall=0', nics[0][:net0]
end

test '#interface with name eth1 and bridge' do
deletes = []
nics = []
Expand Down
4 changes: 2 additions & 2 deletions test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ProxmoxInterfacesTest < ActiveSupport::TestCase

it 'sets interface identifier with server compute id, ip and ip6 and mac adress' do
ip = '192.168.56.100'
mac_address = '36:25:8c:53:0c:50'
mac_address = '36:25:8C:53:0C:50'
ip6 = Array.new(4) { format('%<x>s', x: rand(16**4)) }.join(':') + '::1'
compute_attributes = ActiveSupport::HashWithIndifferentAccess.new({ 'id' => 'net0' })
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6,
Expand Down Expand Up @@ -131,7 +131,7 @@ class ProxmoxInterfacesTest < ActiveSupport::TestCase

it 'sets container compute ip DHCP, mac adress and firewall' do
ip = '192.168.56.100'
mac_address = '36:25:8c:53:0c:50'
mac_address = '36:25:8C:53:0C:50'
ip6 = '2001:0:1234::c1c0:abcd:876'
firewall = '1'
compute_attributes = ActiveSupport::HashWithIndifferentAccess.new({ 'id' => 'net0', 'dhcp' => '1',
Expand Down

0 comments on commit 2748290

Please sign in to comment.