Revision 56de025f
Added by Tomáš Strachota almost 6 years ago
test/models/compute_resources/ec2_test.rb | ||
---|---|---|
assert_includes(cr.capabilities, :key_pair)
|
||
end
|
||
end
|
||
|
||
describe '#normalize_vm_attrs' do
|
||
let(:cr) do
|
||
mock_cr(FactoryBot.build(:ec2_cr),
|
||
:subnets => [
|
||
stub(:subnet_id => 'sn1', :cidr_block => 'cidr blk 1'),
|
||
stub(:subnet_id => 'sn2', :cidr_block => 'cidr blk 2')
|
||
],
|
||
:security_groups => [
|
||
stub(:group_id => 'grp1', :name => 'group 1'),
|
||
stub(:group_id => 'grp2', :name => 'group 2')
|
||
],
|
||
:flavors => [
|
||
stub(:id => 'flvr1', :name => 'flavour 1'),
|
||
stub(:id => 'flvr2', :name => 'flavour 2')
|
||
]
|
||
)
|
||
end
|
||
|
||
test 'nilifies blank flavor_id' do
|
||
assert_blank_attr_nilified(cr, 'flavor_id')
|
||
end
|
||
|
||
test 'sets flavor_name' do
|
||
vm_attrs = {
|
||
'flavor_id' => 'flvr1'
|
||
}
|
||
normalized = cr.normalize_vm_attrs(vm_attrs)
|
||
|
||
assert_equal('flavour 1', normalized['flavor_name'])
|
||
end
|
||
|
||
test 'nilifies blank availability_zone' do
|
||
assert_blank_attr_nilified(cr, 'availability_zone')
|
||
end
|
||
|
||
test 'nilifies blank subnet_id' do
|
||
assert_blank_attr_nilified(cr, 'subnet_id')
|
||
end
|
||
|
||
test 'sets subnet_name' do
|
||
vm_attrs = {
|
||
'subnet_id' => 'sn1'
|
||
}
|
||
normalized = cr.normalize_vm_attrs(vm_attrs)
|
||
|
||
assert_equal('cidr blk 1', normalized['subnet_name'])
|
||
end
|
||
|
||
test 'sets image_name' do
|
||
cr = FactoryBot.create(:gce_cr, :with_images)
|
||
|
||
vm_attrs = {
|
||
'image_id' => cr.images.last.uuid
|
||
}
|
||
normalized = cr.normalize_vm_attrs(vm_attrs)
|
||
|
||
assert_equal(cr.images.last.name, normalized['image_name'])
|
||
end
|
||
|
||
test 'maps security_groups' do
|
||
vm_attrs = {
|
||
'security_group_ids' => ['', 'grp1']
|
||
}
|
||
expected_attrs = {
|
||
'0' => {
|
||
'id' => 'grp1',
|
||
'name' => 'group 1'
|
||
}
|
||
}
|
||
normalized = cr.normalize_vm_attrs(vm_attrs)
|
||
|
||
assert_equal(expected_attrs, normalized['security_groups'])
|
||
end
|
||
|
||
test 'correctly fills empty attributes' do
|
||
normalized = cr.normalize_vm_attrs({})
|
||
expected_attrs = {
|
||
'flavor_id' => nil,
|
||
'flavor_name' => nil,
|
||
'image_id' => nil,
|
||
'image_name' => nil,
|
||
'availability_zone' => nil,
|
||
'managed_ip' => nil,
|
||
'subnet_id' => nil,
|
||
'subnet_name' => nil,
|
||
'security_groups' => {}
|
||
}
|
||
|
||
assert_equal(expected_attrs.keys.sort, normalized.keys.sort)
|
||
assert_equal(expected_attrs, normalized)
|
||
end
|
||
|
||
test 'attribute names' do
|
||
check_vm_attribute_names(cr)
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|
Also available in: Unified diff
Fixes #21580 - normalize compute attributes (#4980)
Normalizes compute attributes in API show actions. For backwards
compatibility reasons this patch adds a new rabl node instead of
replacing 'vm_attrs'.