Revision f6c83c4d
Added by Marek Hulán almost 8 years ago
app/models/nic/base.rb | ||
---|---|---|
validates :host, :presence => true, :if => Proc.new { |nic| nic.require_host? }
|
||
|
||
validates :identifier, :uniqueness => { :scope => :host_id },
|
||
:if => ->(nic) { nic.identifier && nic.host },
|
||
:unless => ->(nic) { nic.identifier_was.present? }
|
||
:if => ->(nic) { nic.identifier.present? && nic.host && !nic.identifier_was.present? }
|
||
|
||
validate :exclusive_primary_interface
|
||
validate :exclusive_provision_interface
|
test/unit/nics/base_test.rb | ||
---|---|---|
nic
|
||
end
|
||
|
||
let(:nic2) do
|
||
host.interfaces.build(:managed => true, :type => 'Nic::Managed')
|
||
end
|
||
|
||
test 'it is invalid because of conflicting identifier' do
|
||
refute nic.valid?
|
||
assert nic.errors.has_key?(:identifier)
|
||
end
|
||
|
||
test 'it ignores empty identifiers' do
|
||
nic.mac = '00:11:11:22:22:33'
|
||
nic2.mac = '00:11:11:22:22:34'
|
||
nic.identifier = nic2.identifier = ''
|
||
nic.save
|
||
# nic2.save
|
||
|
||
assert nic.valid?
|
||
assert nic2.valid?
|
||
end
|
||
end
|
||
end
|
||
end
|
Also available in: Unified diff
Fixes #15238 - ignore empty NIC identifiers
(cherry picked from commit 7e20cbac5951b858716268cce29f0fad16b71081)