mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Accept network interface MAC addresses without colon delimiters
Commonly found in other Vagrant providers, a MAC address format without colon delimiters is now accepted for better cross-compatibility of Vagrantfiles.
This commit is contained in:
@@ -674,8 +674,14 @@ module VagrantPlugins
|
||||
end
|
||||
|
||||
machine.config.vm.networks.each do |_type, opts|
|
||||
if opts[:mac] && opts[:mac].downcase! && !(opts[:mac] =~ /\A([0-9a-f]{2}:){5}([0-9a-f]{2})\z/)
|
||||
errors << "Configured NIC MAC '#{opts[:mac]}' is not in 'xx:xx:xx:xx:xx:xx' format"
|
||||
if opts[:mac]
|
||||
opts[:mac].downcase!
|
||||
if opts[:mac] =~ /\A([0-9a-f]{12})\z/
|
||||
opts[:mac] = opts[:mac].scan(/../).join(':')
|
||||
end
|
||||
unless opts[:mac] =~ /\A([0-9a-f]{2}:){5}([0-9a-f]{2})\z/
|
||||
errors << "Configured NIC MAC '#{opts[:mac]}' is not in 'xx:xx:xx:xx:xx:xx' or 'xxxxxxxxxxxx' format"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -44,8 +44,15 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
||||
assert_valid
|
||||
end
|
||||
|
||||
it 'is valid with MAC containing no delimiters' do
|
||||
network = [:public, { mac: 'aabbccddeeff' }]
|
||||
expect(vm).to receive(:networks).and_return([network])
|
||||
assert_valid
|
||||
expect(network[1][:mac]).to eql('aa:bb:cc:dd:ee:ff')
|
||||
end
|
||||
|
||||
it 'should be invalid if MAC not formatted correctly' do
|
||||
expect(vm).to receive(:networks).and_return([[:public, { mac: 'aabbccddeeff' }]])
|
||||
expect(vm).to receive(:networks).and_return([[:public, { mac: 'aa/bb/cc/dd/ee/ff' }]])
|
||||
assert_invalid
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user