Add unit tests for NFV-related functions
Add unit tests for the following functions: - nic_whitelist_to_json - nic_whitelist_to_mappings - filter_nodes_with_enabled_option Closes-bug: #1557974 Change-Id: Ia50c0e50d360b7557b19df3661ed980d8726c8c6
This commit is contained in:
parent
eb22a92462
commit
31b3acd084
@ -0,0 +1,70 @@
|
||||
require 'yaml'
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'filter_nodes_with_enabled_option' do
|
||||
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
||||
let(:compute_nodes) do
|
||||
YAML.load("
|
||||
---
|
||||
node-1:
|
||||
swift_zone: '1'
|
||||
uid: '1'
|
||||
fqdn: node-1.test.domain.local
|
||||
node_roles:
|
||||
- compute
|
||||
name: node-1
|
||||
nova_hugepages_enabled: true
|
||||
node-2:
|
||||
swift_zone: '1'
|
||||
uid: '2'
|
||||
fqdn: node-2.test.domain.local
|
||||
node_roles:
|
||||
- compute
|
||||
name: node-2
|
||||
nova_hugepages_enabled: true
|
||||
nova_cpu_pinning_enabled: true
|
||||
node-3:
|
||||
swift_zone: '1'
|
||||
uid: '3'
|
||||
fqdn: node-3.test.domain.local
|
||||
node_roles:
|
||||
- compute
|
||||
name: node-3
|
||||
nova_cpu_pinning_enabled: true
|
||||
")
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
puppet_debug_override()
|
||||
end
|
||||
|
||||
it 'should exist' do
|
||||
expect(Puppet::Parser::Functions.function('filter_nodes_with_enabled_option')).to eq('function_filter_nodes_with_enabled_option')
|
||||
end
|
||||
|
||||
it 'should fail if wrong argument count given' do
|
||||
expect{scope.function_filter_nodes_with_enabled_option([{'node-1'=>{'uid'=>'1'}}, 'nova_hugepages_enabled', 'eee'])}.to raise_error(Puppet::ParseError, /takes exactly 2 arguments/)
|
||||
expect{scope.function_filter_nodes_with_enabled_option([])}.to raise_error(Puppet::ParseError, /takes exactly 2 arguments/)
|
||||
end
|
||||
|
||||
it 'should fail if the first argument is not a hash' do
|
||||
expect{scope.function_filter_nodes_with_enabled_option([['node-1'],'eee'])}.to raise_error(Puppet::ParseError, /must be a hash/)
|
||||
end
|
||||
|
||||
it 'should fail if the second argument is not a string' do
|
||||
expect{scope.function_filter_nodes_with_enabled_option([{'node-1'=>{'uid'=>'1'}}, ['fqdn']])}.to raise_error(Puppet::ParseError, /must be a string/)
|
||||
end
|
||||
|
||||
it 'should return array of nodes fqdn with nova_hugepages_enabled' do
|
||||
expect(scope.function_filter_nodes_with_enabled_option([compute_nodes, 'nova_hugepages_enabled'])).to eq(['node-1.test.domain.local','node-2.test.domain.local'])
|
||||
end
|
||||
|
||||
it 'should return array of nodes fqdn with nova_cpu_pinning_enabled' do
|
||||
expect(scope.function_filter_nodes_with_enabled_option([compute_nodes, 'nova_cpu_pinning_enabled'])).to eq(['node-2.test.domain.local','node-3.test.domain.local'])
|
||||
end
|
||||
|
||||
it 'should return empty array when missing option is specified' do
|
||||
expect(scope.function_filter_nodes_with_enabled_option([compute_nodes, 'abc'])).to eq([])
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,32 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'nic_whitelist_to_json' do
|
||||
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
||||
let(:nic_whitelist) do
|
||||
[{"devname"=>"eth1", "physical_network"=>"physnet2"}]
|
||||
end
|
||||
let(:nic_whitelist_json) do
|
||||
"[{\"devname\":\"eth1\",\"physical_network\":\"physnet2\"}]"
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
puppet_debug_override()
|
||||
end
|
||||
|
||||
it 'should exist' do
|
||||
expect(Puppet::Parser::Functions.function('nic_whitelist_to_json')).to eq('function_nic_whitelist_to_json')
|
||||
end
|
||||
|
||||
it 'should fail if more then one argument given' do
|
||||
expect{scope.function_nic_whitelist_to_json([nic_whitelist, 'eee'])}.to raise_error(Puppet::ParseError, /one argument is allowed/)
|
||||
end
|
||||
|
||||
it 'should return without arguments' do
|
||||
expect(scope.function_nic_whitelist_to_json([])).to eq(nil)
|
||||
end
|
||||
|
||||
it 'should convert nic whitelist to json' do
|
||||
expect(scope.function_nic_whitelist_to_json([nic_whitelist])).to eq(nic_whitelist_json)
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,32 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'nic_whitelist_to_mappings' do
|
||||
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
||||
let(:nic_whitelist) do
|
||||
[{"devname"=>"eth1", "physical_network"=>"physnet2"}]
|
||||
end
|
||||
let(:physical_device_mappings) do
|
||||
["physnet2:eth1"]
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
puppet_debug_override()
|
||||
end
|
||||
|
||||
it 'should exist' do
|
||||
expect(Puppet::Parser::Functions.function('nic_whitelist_to_mappings')).to eq('function_nic_whitelist_to_mappings')
|
||||
end
|
||||
|
||||
it 'should fail if more then one argument given' do
|
||||
expect{scope.function_nic_whitelist_to_mappings([nic_whitelist, 'eee'])}.to raise_error(Puppet::ParseError, /one argument is allowed/)
|
||||
end
|
||||
|
||||
it 'should return without arguments' do
|
||||
expect(scope.function_nic_whitelist_to_mappings([])).to eq(nil)
|
||||
end
|
||||
|
||||
it 'should convert nic whitelist to device mappings' do
|
||||
expect(scope.function_nic_whitelist_to_mappings([nic_whitelist])).to eq(physical_device_mappings)
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user